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