test_ProtoduneOnlineChannel.cxx
Go to the documentation of this file.
1 // test_ProtoduneOnlineChannel.cxx
2 //
3 // David Adams
4 // May 2018
5 //
6 // Test ProtoduneOnlineChannel.
7 
8 #include <string>
9 #include <iostream>
10 #include <fstream>
11 #include <sstream>
12 #include <iomanip>
16 #include "TH1F.h"
17 
18 #undef NDEBUG
19 #include <cassert>
20 
21 using std::string;
22 using std::cout;
23 using std::endl;
24 using std::ofstream;
25 using std::istringstream;
26 using std::setw;
29 using IndexVector = std::vector<Index>;
30 
31 //**********************************************************************
32 
33 int test_ProtoduneOnlineChannel(bool useExistingFcl =false, Index nshow =64) {
34  const string myname = "test_ProtoduneOnlineChannel: ";
35 #ifdef NDEBUG
36  cout << myname << "NDEBUG must be off." << endl;
37  abort();
38 #endif
39  string line = "-----------------------------";
40 
41  cout << myname << line << endl;
42  string fclfile = "test_ProtoduneOnlineChannel.fcl";
43  if ( ! useExistingFcl ) {
44  cout << myname << "Creating top-level FCL." << endl;
45  ofstream fout(fclfile.c_str());
46  fout << "tools: {" << endl;
47  fout << " mytool: {" << endl;
48  fout << " tool_type: ProtoduneOnlineChannel" << endl;
49  fout << " }" << endl;
50  fout << "}" << endl;
51  fout.close();
52  } else {
53  cout << myname << "Using existing top-level FCL." << endl;
54  }
55 
56  cout << myname << line << endl;
57  cout << myname << "Fetching tool manager." << endl;
59  assert ( ptm != nullptr );
60  DuneToolManager& tm = *ptm;
61  tm.print();
62  assert( tm.toolNames().size() >= 1 );
63 
64  cout << myname << line << endl;
65  cout << myname << "Fetching tool." << endl;
66  auto cma = tm.getPrivate<IndexMapTool>("mytool");
67  assert( cma != nullptr );
68 
70 
71  cout << myname << line << endl;
72  cout << myname << "Check some good values." << endl;
73  for ( Index ichaOff : { 0, 102, 1234, 1407, 3967, 15359 } ) {
74  Index ichaOn = cma->get(ichaOff);
75  cout << myname << ichaOff << " --> " << ichaOn << endl;
76  assert( ichaOff != badIndex );
77  }
78 
79  cout << myname << line << endl;
80  cout << myname << "Check some bad values." << endl;
81  for ( Index ichaOff : { -1, 15360, 20000 } ) {
82  Index ichaOn = cma->get(ichaOff);
83  cout << myname << ichaOff << " --> " << ichaOn << endl;
84  assert( ichaOn == badIndex );
85  }
86 
87  cout << myname << line << endl;
88  cout << myname << "Check each online index appears exactly once." << endl;
89  const Index ncha = 15360;
90  IndexVector onlineCounts(ncha);
91  IndexVector offlineChannel(ncha, badIndex);
92  ProtoduneChannelHelper chh(false);
93  for ( Index ichaOff=0; ichaOff<ncha; ++ichaOff ) {
94  Index ichaOn = cma->get(ichaOff);
95  Index irem = ichaOn;
96  Index itps = irem/2560;
97  irem = irem%2560;
98  Index ifmb = irem/128 + 1;
99  irem = irem%128;
100  Index iasc = irem/16 + 1;
101  Index iach = irem%16;
102  if ( nshow*(ichaOff/nshow) == ichaOff || ichaOn >= ncha ) {
103  cout << myname << " " << setw(4) << ichaOff << " --> " << setw(4) << ichaOn
104  << " (" << itps << ", " << setw(2) << ifmb << ", "
105  << iasc << ", " << setw(2) << iach << ")" << endl;
106  }
107  assert( itps == chh.tpcSet(ichaOn) );
108  assert( ifmb == chh.femb(ichaOn) );
109  assert( iasc == chh.asic(ichaOn) );
110  assert( iach == chh.asicChannel(ichaOn) );
111  assert( ichaOn < ncha );
112  if ( offlineChannel[ichaOn] != badIndex ) {
113  cout << myname << "ERROR: Online channel " << ichaOn
114  << " is mapped to two offline channels:" << endl;
115  cout << " " << offlineChannel[ichaOn] << endl;
116  cout << " " << ichaOff << endl;
117  assert( false );
118  }
119  assert( onlineCounts[ichaOn] == 0 );
120  onlineCounts[ichaOn] += 1;
121  offlineChannel[ichaOn] = ichaOff;
122  }
123  for ( Index ichaOn=0; ichaOn<ncha; ++ichaOn ) {
124  assert( onlineCounts[ichaOn] == 1 );
125  assert( offlineChannel[ichaOn] != badIndex );
126  }
127 
128  cout << myname << line << endl;
129  cout << myname << "Done." << endl;
130  return 0;
131 }
132 
133 //**********************************************************************
134 
135 int main(int argc, char* argv[]) {
136  bool useExistingFcl = false;
137  Index nshow = 64;
138  if ( argc > 1 ) {
139  string sarg(argv[1]);
140  if ( sarg == "-h" ) {
141  cout << "Usage: " << argv[0] << " [keepFCL] [NSHOW]" << endl;
142  cout << " keepFCL [false]: If true, existing FCL file is used." << endl;
143  cout << " NSHOW [64]: Every nshow'th channels will be displayed in log." << endl;
144  return 0;
145  }
146  useExistingFcl = sarg == "true" || sarg == "1";
147  }
148  if ( argc > 2 ) {
149  string sarg(argv[2]);
150  nshow = std::stoi(sarg);
151  }
152  return test_ProtoduneOnlineChannel(useExistingFcl, nshow);
153 }
154 
155 //**********************************************************************
std::vector< Index > IndexVector
Index badIndex
int test_ProtoduneOnlineChannel(bool useExistingFcl=false, Index nshow=64)
const std::vector< std::string > & toolNames() const
std::string string
Definition: nybbler.cc:12
void print() const
unsigned int Index
tm
Definition: demo.py:21
static Index femb(Index chan, bool isOff)
static Index asicChannel(Index chan, bool isOff)
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
std::unique_ptr< T > getPrivate(std::string name)
unsigned int Index
Definition: IndexMapTool.h:16
int main(int argc, char *argv[])
static Index badIndex()
Definition: IndexMapTool.h:18
void line(double t, double *p, double &x, double &y, double &z)
static Index asic(Index chan, bool isOff)
static Index tpcSet(Index chan, bool isOff)
static DuneToolManager * instance(std::string fclname="", int dbg=1)
QTextStream & endl(QTextStream &s)