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