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