test_ProtoDuneChannelRanges.cxx
Go to the documentation of this file.
1 // test_ProtoDuneChannelRanges.cxx
2 //
3 // David Adams
4 // July 2018
5 //
6 // Test ProtoDuneChannelRanges.
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::setfill;
28 using std::vector;
30 using Index = unsigned int;
31 using IndexVector = std::vector<Index>;
32 
33 //**********************************************************************
34 
35 int test_ProtoDuneChannelRanges(bool useExistingFcl =false, int show =1) {
36  const string myname = "test_ProtoDuneChannelRanges: ";
37 #ifdef NDEBUG
38  cout << myname << "NDEBUG must be off." << endl;
39  abort();
40 #endif
41  string line = "-----------------------------";
42 
43  cout << myname << line << endl;
44  string fclfile = "test_ProtoDuneChannelRanges.fcl";
45  if ( ! useExistingFcl ) {
46  cout << myname << "Creating top-level FCL." << endl;
47  ofstream fout(fclfile.c_str());
48  fout << "tools: {" << endl;
49  fout << " mytool: {" << endl;
50  fout << " tool_type: ProtoDuneChannelRanges" << endl;
51  fout << " LogLevel: 2" << endl;
52  fout << " ExtraRanges: \"\"" << endl;
53  fout << " }" << endl;
54  fout << "}" << endl;
55  fout.close();
56  } else {
57  cout << myname << "Using existing top-level FCL." << endl;
58  }
59 
60  cout << myname << line << endl;
61  cout << myname << "Fetching tool manager." << endl;
63  assert ( ptm != nullptr );
64  DuneToolManager& tm = *ptm;
65  tm.print();
66  assert( tm.toolNames().size() >= 1 );
67 
68  cout << myname << line << endl;
69  cout << myname << "Fetching tool." << endl;
70  auto irt = tm.getPrivate<IndexRangeTool>("mytool");
71  assert( irt != nullptr );
72 
73  cout << myname << line << endl;
74  cout << myname << "Fetching TPC ranges." << endl;
75  int nbad = 0;
76  vector<string> namSufs = { "", "u", "v", "z", "c", "x", "i"};
77  vector<string> namPres = {"tps", "tpp", "tpp", "tpp", "tpp", "tpp", "tpp"};
78  for ( Index inam=0; inam<namPres.size(); ++inam ) {
79  for ( Index itps=0; itps<6; ++itps ) {
80  string stps = std::to_string(itps);
81  string nam = namPres[inam] + stps + namSufs[inam];
82  IndexRange ir = irt->get(nam);
83  if ( ! ir.isValid() ) {
84  cout << myname << "Invalid range: " << nam << endl;
85  ++nbad;
86  } else {
87  cout << myname << setw(10) << ir.name << setw(20) << ir.rangeString()
88  << " " << ir.label();
89  for ( Index ilab=1; ilab<ir.labels.size(); ++ilab ) cout << ", " << ir.label(ilab);
90  cout << endl;
91  assert( ir.name == nam );
92  }
93  }
94  }
95  assert( nbad == 0 );
96 
97  cout << myname << line << endl;
98  cout << myname << "Fetching APA ranges." << endl;
99  nbad = 0;
100  vector<string> namPresApa = {"apa", "apa", "apa", "apa", "apa", "apa", "apa"};
101  for ( Index inam=0; inam<namPres.size(); ++inam ) {
102  for ( Index iapa=1; iapa<=6; ++iapa ) {
103  string stps = std::to_string(iapa);
104  string nam = namPresApa[inam] + stps + namSufs[inam];
105  IndexRange ir = irt->get(nam);
106  if ( ! ir.isValid() ) {
107  cout << myname << "Invalid range: " << nam << endl;
108  ++nbad;
109  } else {
110  cout << myname << setw(10) << ir.name << setw(20) << ir.rangeString()
111  << " " << ir.label();
112  for ( Index ilab=1; ilab<ir.labels.size(); ++ilab ) cout << ", " << ir.label(ilab);
113  cout << endl;
114  assert( ir.name == nam );
115  }
116  }
117  }
118  assert( nbad == 0 );
119 
120  bool showFembBlocks = show > 1;
121  if ( showFembBlocks ) {
122  cout << myname << line << endl;
123  cout << myname << "Fetching FEMB block ranges." << endl;
124  nbad = 0;
125  IndexVector chk(15360, 0);
126  for ( Index iapa=1; iapa<=6; ++iapa ) {
127  for ( string view : {"u", "v", "x"} ) {
128  for ( Index ifmb=1; ifmb<=20; ++ifmb ) {
129  ostringstream ssnam;
130  ssnam << "femb" << iapa << setfill('0') << setw(2) << ifmb << view;
131  string nam = ssnam.str();
132  IndexRange ir = irt->get(nam);
133  if ( ! ir.isValid() ) {
134  cout << myname << "Invalid range: " << nam << endl;
135  ++nbad;
136  } else {
137  cout << myname << setw(10) << ir.name << setw(20) << ir.rangeString()
138  << " " << ir.label();
139  for ( Index ilab=1; ilab<ir.labels.size(); ++ilab ) cout << ", " << ir.label(ilab);
140  for ( Index icha=ir.begin; icha<ir.end; ++icha ) chk[icha] += 1;
141  cout << endl;
142  }
143  }
144  }
145  }
146  for ( Index icha=0; icha<15360; ++icha ) {
147  assert( chk[icha] == 1 );
148  }
149  }
150  assert( nbad == 0 );
151 
152  cout << myname << line << endl;
153  cout << "Fetch bad range" << endl;
154  IndexRange irb = irt->get("rangebad");
155  cout << irb.rangeString() << endl;
156  assert( ! irb.isValid() );
157 
158  cout << myname << line << endl;
159  cout << myname << "Done." << endl;
160  return 0;
161 }
162 
163 //**********************************************************************
164 
165 int main(int argc, char* argv[]) {
166  bool useExistingFcl = false;
167  int show = 1;
168  if ( argc > 1 ) {
169  string sarg(argv[1]);
170  if ( sarg == "-h" ) {
171  cout << "Usage: " << argv[0] << " [keepFCL] [SHOW]" << endl;
172  cout << " If keepFCL = true, existing FCL file is used." << endl;
173  cout << " SHOW > 1 also shows the 480 FEMB blocks." << endl;
174  return 0;
175  }
176  useExistingFcl = sarg == "true" || sarg == "1";
177  }
178  if ( argc > 2 ) {
179  string sarg(argv[2]);
180  show = std::stoi(sarg);
181  }
182  return test_ProtoDuneChannelRanges(useExistingFcl, show);
183 }
184 
185 //**********************************************************************
std::vector< Index > IndexVector
NameVector labels
Definition: IndexRange.h:33
const std::vector< std::string > & toolNames() const
std::string string
Definition: nybbler.cc:12
Index begin
Definition: IndexRange.h:34
struct vector vector
void print() const
unsigned int Index
bool isValid() const
Definition: IndexRange.h:94
Index end
Definition: IndexRange.h:35
tm
Definition: demo.py:21
int main(int argc, char *argv[])
Name name
Definition: IndexRange.h:32
Name label(Index ilab=0) const
Definition: IndexRange.h:106
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
int test_ProtoDuneChannelRanges(bool useExistingFcl=false, int show=1)
std::unique_ptr< T > getPrivate(std::string name)
void line(double t, double *p, double &x, double &y, double &z)
std::string rangeString() const
Definition: IndexRange.h:97
Q_EXPORT QTSManip setfill(int f)
Definition: qtextstream.h:337
std::string to_string(ModuleType const mt)
Definition: ModuleType.h:34
static DuneToolManager * instance(std::string fclname="", int dbg=1)
QTextStream & endl(QTextStream &s)