test_ProtoduneChannelHelper.cxx
Go to the documentation of this file.
1 // test_ProtoduneChannelHelper.cxx
2 //
3 // David Adams
4 // May 2018
5 //
6 // Test ProtoduneChannelHelper.
7 
8 #include <string>
9 #include <iostream>
10 #include <fstream>
11 #include <sstream>
12 #include <iomanip>
14 #include "TH1F.h"
15 
16 #undef NDEBUG
17 #include <cassert>
18 
19 using std::string;
20 using std::cout;
21 using std::endl;
22 using std::ofstream;
23 using std::istringstream;
24 using std::setw;
26 using IndexVector = std::vector<Index>;
27 
28 //**********************************************************************
29 
31  const string myname = "test_ProtoduneChannelHelper: ";
32 #ifdef NDEBUG
33  cout << myname << "NDEBUG must be off." << endl;
34  abort();
35 #endif
36  string line = "-----------------------------";
37 
38  cout << myname << line << endl;
39 
40  ProtoduneChannelHelper chh(false);
41  Index badIndex = chh.badIndex();
42 
43  cout << myname << "Check some good values." << endl;
44  for ( Index ichaOff : { 0, 102, 1234, 1407, 3967, 15359 } ) {
45  Index ichaOn = chh.onlineChannel(ichaOff);
46  cout << myname << ichaOff << " --> " << ichaOn << endl;
47  assert( ichaOff != badIndex );
48  }
49 
50  cout << myname << line << endl;
51  cout << myname << "Check some bad values." << endl;
52  for ( Index ichaOff : { -1, 15360, 20000 } ) {
53  Index ichaOn = chh.onlineChannel(ichaOff);
54  cout << myname << ichaOff << " --> " << ichaOn << endl;
55  assert( ichaOn == badIndex );
56  }
57 
58  cout << myname << line << endl;
59  cout << myname << "Check each online index appears exactly once." << endl;
60  const Index ncha = 15360;
61  IndexVector onlineCounts(ncha);
62  IndexVector offlineChannel(ncha, badIndex);
63  for ( Index ichaOff=0; ichaOff<ncha; ++ichaOff ) {
64  Index ichaOn = chh.onlineChannel(ichaOff);
65  Index irem = ichaOn;
66  Index itps = irem/2560;
67  irem = irem%2560;
68  Index ifmb = irem/128 + 1;
69  irem = irem%128;
70  Index iasc = irem/16 + 1;
71  Index iach = irem%16;
72  if ( nshow*(ichaOff/nshow) == ichaOff || ichaOn >= ncha ) {
73  cout << myname << " " << setw(4) << ichaOff << " --> " << setw(4) << ichaOn
74  << " (" << itps << ", " << setw(2) << ifmb << ", "
75  << iasc << ", " << setw(2) << iach << ")" << endl;
76  }
77  assert( itps == chh.tpcSet(ichaOn) );
78  assert( ifmb == chh.femb(ichaOn) );
79  assert( iasc == chh.asic(ichaOn) );
80  assert( iach == chh.asicChannel(ichaOn) );
81  assert( ichaOn < ncha );
82  if ( offlineChannel[ichaOn] != badIndex ) {
83  cout << myname << "ERROR: Online channel " << ichaOn
84  << " is mapped to two offline channels:" << endl;
85  cout << " " << offlineChannel[ichaOn] << endl;
86  cout << " " << ichaOff << endl;
87  assert( false );
88  }
89  assert( onlineCounts[ichaOn] == 0 );
90  onlineCounts[ichaOn] += 1;
91  offlineChannel[ichaOn] = ichaOff;
92  }
93  for ( Index ichaOn=0; ichaOn<ncha; ++ichaOn ) {
94  assert( onlineCounts[ichaOn] == 1 );
95  assert( offlineChannel[ichaOn] != badIndex );
96  }
97 
98  cout << myname << line << endl;
99  cout << myname << "Done." << endl;
100  return 0;
101 }
102 
103 //**********************************************************************
104 
105 int main(int argc, char* argv[]) {
106  Index nshow = 64;
107  if ( argc > 1 ) {
108  string sarg(argv[1]);
109  if ( sarg == "-h" ) {
110  cout << "Usage: " << argv[0] << "[NSHOW]" << endl;
111  cout << " NSHOW [64]: Every nshow'th channels will be displayed in log." << endl;
112  return 0;
113  }
114  nshow = std::stoi(sarg);
115  }
116  return test_ProtoduneChannelHelper(nshow);
117 }
118 
119 //**********************************************************************
int main(int argc, char *argv[])
static Index onlineChannel(Index chanOff, Index dbg=0)
std::vector< Index > IndexVector
Index badIndex
int test_ProtoduneChannelHelper(Index nshow=64)
std::string string
Definition: nybbler.cc:12
unsigned int Index
static Index femb(Index chan, bool isOff)
static Index asicChannel(Index chan, bool isOff)
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
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)
QTextStream & endl(QTextStream &s)