ChannelStatusConfigTool_tool.cc
Go to the documentation of this file.
1 // ChannelStatusConfigTool_tool.cc
2 
9 
10 #include <iostream>
11 #include <iomanip>
12 
13 using std::cout;
14 using std::endl;
15 using std::setw;
16 using Name = std::string;
18 
19 //**********************************************************************
20 
22 : m_LogLevel(ps.get<Index>("LogLevel")),
23  m_DefaultIndex(ps.get<Index>("DefaultIndex")),
24  m_IndexVectors(ps.get<IndexVectorVector>("IndexVectors")) {
25  const Name myname = "ChannelStatusConfigTool::ctor: ";
26  if ( m_LogLevel >= 1 ) {
27  cout << myname << " LogLevel: " << m_LogLevel << endl;
28  Index nidx = m_IndexVectors.size();
29  Index nsho = 0;
30  for ( Index iidx=0; iidx<nidx; ++iidx ) {
31  const IndexVector& vals = m_IndexVectors[iidx];
32  Index nval = vals.size();
33  if ( nval == 0 ) continue;
34  if ( nsho == 0 ) {
35  cout << myname << " Index Count" << endl;
36  }
37  ++nsho;
38  cout << myname << setw(7) << iidx << setw(7) << nval << endl;
39  }
40  }
41  // Build the map.
42  Index idxSize = 0;
43  for ( const IndexVector& vec : m_IndexVectors ) {
44  for ( Index idx : vec ) {
45  if ( idx >= idxSize ) idxSize = idx + 1;
46  }
47  }
48  m_vals.resize(idxSize, m_DefaultIndex);
49  Index ivec = m_IndexVectors.size();
50  IndexVector counts(idxSize, 0);
51  while ( ivec ) {
52  const IndexVector& vec = m_IndexVectors[--ivec];
53  for ( Index idx : vec ) {
54  m_vals[idx] = ivec;
55  ++counts[idx];
56  }
57  }
58  if ( m_LogLevel == 2 ) {
59  Index ndup = 0;
60  for ( Index idx=0; idx<idxSize; ++idx ) {
61  if ( counts[idx] > 1 ) {
62  if ( ndup >= 20 ) {
63  cout << ", ...";
64  break;
65  }
66  if ( ndup == 0 ) {
67  cout << myname << "Found indices with duplicate entries: ";
68  } else {
69  cout << ", ";
70  }
71  cout << idx;
72  ++ndup;
73  }
74  }
75  if ( ndup == 0 ) {
76  cout << myname << "No duplicate entries.";
77  }
78  cout << endl;
79  }
80 }
81 
82 //**********************************************************************
83 
85  const Name myname = "ChannelStatusConfigTool::get: ";
86  if ( icha < m_vals.size() ) return m_vals[icha];
87  return m_DefaultIndex;
88 }
89 
90 //**********************************************************************
91 
#define DEFINE_ART_CLASS_TOOL(tool)
Definition: ToolMacros.h:42
std::string string
Definition: nybbler.cc:12
std::vector< IndexVector > IndexVectorVector
ChannelGroupService::Name Name
unsigned int Index
ChannelStatusConfigTool(fhicl::ParameterSet const &ps)
counts_as<> counts
Number of ADC counts, represented by signed short int.
Definition: electronics.h:116
Index get(Index icha) const override
static constexpr double ps
Definition: Units.h:99
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
Interface for experiment-specific channel quality info provider.
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115
Interface for experiment-specific service for channel quality info.
QTextStream & endl(QTextStream &s)
std::vector< Index > IndexVector