test_VDColdboxChannelRanges.cxx
Go to the documentation of this file.
1 // test_VDColdboxChannelRanges.cxx
2 //
3 // David Adams
4 // May 2018
5 //
6 // Test VDColdboxChannelRanges.
7 
8 #include <string>
9 #include <iostream>
10 #include <fstream>
11 #include <sstream>
12 #include <iomanip>
15 #include "TH1F.h"
16 
17 #undef NDEBUG
18 #include <cassert>
19 
20 using std::string;
21 using std::cout;
22 using std::endl;
23 using std::ofstream;
24 using std::istringstream;
25 using std::ostringstream;
26 using std::setw;
29 using IndexVector = std::vector<Index>;
30 
31 Index checkran(const IndexRangeTool& rm, string sran, Index nexp =0, bool chkvalid =true) {
32  const string myname = "checkran: ";
33  IndexRange ran = rm.get(sran);
34  if ( ran.isValid() ) cout << ran << endl;
35  if ( chkvalid && ! ran.isValid() ) {
36  cout << myname << "Unable to find range " << sran << endl;
37  assert(false);
38  }
39  if ( nexp ) assert( ran.size() == nexp );
40  return ran.size();
41 }
42 
43 //**********************************************************************
44 
45 int test_VDColdboxChannelRanges(bool useExistingFcl =false) {
46  const string myname = "test_VDColdboxChannelRanges: ";
47 #ifdef NDEBUG
48  cout << myname << "NDEBUG must be off." << endl;
49  abort();
50 #endif
51  string line = "-----------------------------";
52 
53  cout << myname << line << endl;
54  string fclfile = "test_VDColdboxChannelRanges.fcl";
55  if (useExistingFcl) {
56  cout << myname << "Using existing top-level FCL." << endl;
57  } else {
58  cout << myname << "Creating top-level FCL." << endl;
59  ofstream fout(fclfile.c_str());
60  fout << "tools: {" << endl;
61  fout << " mytool: {" << endl;
62  fout << " tool_type: VDColdboxChannelRanges" << endl;
63  fout << " LogLevel: 1" << endl;
64  fout << " GhostRange: [3200, 3392]" << endl;
65  fout << " }" << endl;
66  fout << "}" << endl;
67  fout.close();
68  }
69 
70  cout << myname << line << endl;
71  cout << myname << "Fetching tool manager." << endl;
73  assert ( ptm != nullptr );
74  DuneToolManager& tm = *ptm;
75  tm.print();
76  assert( tm.toolNames().size() == 1 );
77 
78  cout << myname << line << endl;
79  cout << myname << "Fetching tool." << endl;
80  auto cma = tm.getPrivate<IndexRangeTool>("mytool");
81  assert( cma != nullptr );
82 
83  cout << myname << line << endl;
84  cout << myname << "Check detector." << endl;
85  checkran(*cma, "cru", 3200);
86  checkran(*cma, "crt", 1600);
87  checkran(*cma, "crb", 1600);
88  checkran(*cma, "crtu", 384);
89  checkran(*cma, "crty", 640);
90  checkran(*cma, "crtz", 576);
91  Index nchu = checkran(*cma, "crbu", 384);
92  assert(nchu);
93  Index nchy = checkran(*cma, "crby", 640);
94  assert(nchy);
95  Index nchz = checkran(*cma, "crbz", 576);
96  assert(nchz);
97 
98  cout << myname << line << endl;
99  cout << myname << "Check U FEMBs." << endl;
100  Index nchuf = 0;
101  for ( string sran : { "femb01u", "femb02u", "femb03u", "femb04u", "femb05u",
102  "femb06u", "femb07u", "femb08u", "femb09u", "femb10u", "femb11u" } ) {
103  nchuf += checkran(*cma, sran, 0);
104  }
105  cout << myname << " Checking " << nchuf << " == " << nchu << endl;
106  assert( nchuf == nchu );
107 
108  cout << myname << line << endl;
109  cout << myname << "Check Y FEMBs." << endl;
110  Index nchyf = 0;
111  for ( string sran : { "femb01y", "femb02y", "femb03y", "femb04y",
112  "femb11y", "femb12y", "femb13y" } ) {
113  nchyf += checkran(*cma, sran, 0);
114  }
115  cout << myname << " Checking " << nchyf << " == " << nchy << endl;
116  assert( nchyf == nchy );
117 
118  cout << myname << line << endl;
119  cout << myname << "Check Z FEMBs." << endl;
120  Index nchzf = 0;
121  for ( string sran : { "femb04z", "femb05z", "femb06z", "femb07z",
122  "femb08z", "femb09z", "femb10z", "femb11z" } ) {
123  nchzf += checkran(*cma, sran, 0);
124  }
125  cout << myname << " Checking " << nchzf << " == " << nchz << endl;
126  assert( nchzf == nchz );
127 
128  cout << myname << line << endl;
129  cout << myname << "Check each FEMB." << endl;
130  Index ntot = 0;
131  for ( Index ifmb=1; ifmb<=13; ++ifmb ) {
132  string sbas = string("femb") + (ifmb<10 ? "0" : "") + std::to_string(ifmb);
133  Index nchf = 0;
134  for ( string spla : {"u", "y", "z"} ) {
135  nchf += checkran(*cma, sbas + spla, 0, false);
136  }
137  cout << "*** " << sbas << " count is " << nchf << endl;
138  assert( nchf <= 128 );
139  ntot += nchf;
140  }
141  cout << myname << "*** FEMB total is " << ntot << endl;
142  assert( ntot == 1600 );
143 
144  cout << myname << line << endl;
145  cout << myname << "Done." << endl;
146  return 0;
147 }
148 
149 //**********************************************************************
150 
151 int main(int argc, char* argv[]) {
152  bool useExistingFcl = false;
153  if ( argc > 1 ) {
154  string sarg(argv[1]);
155  if ( sarg == "-h" ) {
156  cout << "Usage: " << argv[0] << " [keepFCL] [NSHOW]" << endl;
157  cout << " keepFCL [false]: If true, existing FCL file is used." << endl;
158  cout << " NSHOW [64]: Every nshow'th channels will be displayed in log." << endl;
159  return 0;
160  }
161  useExistingFcl = sarg == "true" || sarg == "1";
162  }
163  return test_VDColdboxChannelRanges(useExistingFcl);
164 }
165 
166 //**********************************************************************
std::vector< Index > IndexVector
int main(int argc, char *argv[])
const std::vector< std::string > & toolNames() const
std::string string
Definition: nybbler.cc:12
Index size() const
Definition: IndexRange.h:88
void print() const
unsigned int Index
bool isValid() const
Definition: IndexRange.h:94
tm
Definition: demo.py:21
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
std::unique_ptr< T > getPrivate(std::string name)
unsigned int Index
Definition: IndexRange.h:27
int test_VDColdboxChannelRanges(bool useExistingFcl=false)
void line(double t, double *p, double &x, double &y, double &z)
Index checkran(const IndexRangeTool &rm, string sran, Index nexp=0, bool chkvalid=true)
int ntot
Definition: train_cnn.py:133
std::string to_string(ModuleType const mt)
Definition: ModuleType.h:34
static DuneToolManager * instance(std::string fclname="", int dbg=1)
QTextStream & endl(QTextStream &s)
virtual IndexRange get(Name nam) const =0