test_ProtoDuneChannelGroups.cxx
Go to the documentation of this file.
1 // test_ProtoDuneChannelGroups.cxx
2 //
3 // David Adams
4 // July 2018
5 //
6 // Test ProtoDuneChannelGroups.
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 using Name = std::string;
33 
34 //**********************************************************************
35 
36 int test_ProtoDuneChannelGroups(bool useExistingFcl =false, int show =1) {
37  const string myname = "test_ProtoDuneChannelGroups: ";
38 #ifdef NDEBUG
39  cout << myname << "NDEBUG must be off." << endl;
40  abort();
41 #endif
42  string line = "-----------------------------";
43 
44  cout << myname << line << endl;
45  string fclfile = "test_ProtoDuneChannelGroups.fcl";
46  if ( ! useExistingFcl ) {
47  cout << myname << "Creating top-level FCL." << endl;
48  ofstream fout(fclfile.c_str());
49  fout << "tools: {" << endl;
50  fout << " crtool: {" << endl;
51  fout << " tool_type: ProtoDuneChannelRanges" << endl;
52  fout << " LogLevel: 2" << endl;
53  fout << " ExtraRanges: \"\"" << endl;
54  fout << " }" << endl;
55  fout << " mytool: {" << endl;
56  fout << " tool_type: ProtoDuneChannelGroups" << endl;
57  fout << " LogLevel: 2" << endl;
58  fout << " IndexRangeTool: crtool" << endl;
59  fout << " }" << endl;
60  fout << "}" << endl;
61  fout.close();
62  } else {
63  cout << myname << "Using existing top-level FCL." << endl;
64  }
65 
66  cout << myname << line << endl;
67  cout << myname << "Fetching tool manager." << endl;
69  assert ( ptm != nullptr );
70  DuneToolManager& tm = *ptm;
71  tm.print();
72  assert( tm.toolNames().size() >= 1 );
73 
74  cout << myname << line << endl;
75  cout << myname << "Fetching tool." << endl;
76  auto pcgt = tm.getPrivate<IndexRangeGroupTool>("mytool");
77  assert( pcgt != nullptr );
78 
79  cout << myname << line << endl;
80  cout << myname << "Fetch invalid." << endl;
81  IndexRangeGroup chg = pcgt->get("bad");
82  cout << chg << endl;
83  assert( ! chg.isValid() );
84 
85  vector<string> expApas = {"apa1", "apa2", "apa3", "apa4", "apa5", "apa6"};
86  vector<string> expTpss = {"tps0", "tps1", "tps2", "tps3", "tps4", "tps5"};
87 
88  cout << myname << line << endl;
89  cout << myname << "Check apas." << endl;
90  chg = pcgt->get("apas");
91  cout << myname << chg << endl;
92  assert( chg.isValid() );
93  assert( chg.name == "apas" );
94  Index nran = chg.ranges.size();
95  assert( nran == expApas.size() );
96  for ( Index iran=0; iran<nran; ++iran ) {
97  IndexRange ran = chg.range(iran);
98  cout << myname << setw(5) << iran << ": " << ran << endl;
99  assert( ran.name == expApas[iran] );
100  }
101 
102  cout << myname << line << endl;
103  cout << myname << "Check tpss." << endl;
104  chg = pcgt->get("tpss");
105  cout << myname << chg << endl;
106  assert( chg.isValid() );
107  assert( chg.name == "tpss" );
108  nran = chg.ranges.size();
109  assert( nran == expTpss.size() );
110  for ( Index iran=0; iran<nran; ++iran ) {
111  IndexRange ran = chg.range(iran);
112  cout << myname << setw(5) << iran << ": " << ran << endl;
113  assert( ran.name == expTpss[iran] );
114  }
115 
116  // Check plane groups: tpszs, apaus, ...
117  for ( Name sapt : {"apa", "tps"} ) {
118  Name rbas = sapt;
119  if ( sapt == "tps" ) rbas = "tpp";
120  for ( Name sori : {"z", "c", "u", "v"} ) {
121  vector<string> rnams;
122  if ( sapt == "apa" ) {
123  for ( Name sapa : { "1", "2", "3", "4", "5", "6" } ) rnams.push_back(rbas + sapa + sori);
124  } else {
125  for ( Name stps : { "0", "1", "2", "3", "4", "5" } ) rnams.push_back(rbas + stps + sori);
126  }
127  Name gnam = rbas + sori + "s";
128  cout << myname << line << endl;
129  cout << myname << "Check " << gnam << "." << endl;
130  chg = pcgt->get(gnam);
131  cout << myname << chg << endl;
132  assert( chg.isValid() );
133  assert( chg.name == gnam );
134  Index nran = chg.ranges.size();
135  assert( nran == rnams.size() );
136  for ( Index iran=0; iran<nran; ++iran ) {
137  IndexRange ran = chg.range(iran);
138  cout << myname << setw(5) << iran << ": " << ran << endl;
139  assert( ran.name == rnams[iran] );
140  }
141  }
142  }
143 
144  // Check FEMBs.
145  cout << myname << "Checking FEMBs" << endl;
146  for ( Name sapa : { "1", "2", "3", "4", "5", "6" } ) {
147  for ( Name sfmb : { "01", "02", "03", "04", "05", "06", "07", "08", "09", "10",
148  "11", "12", "13", "14", "15", "16", "17", "18", "19", "20" } ) {
149  Name gnam = "femb" + sapa + sfmb;
150  chg = pcgt->get(gnam);
151  assert( chg.isValid() );
152  assert( chg.name == gnam );
153  Index nran = chg.ranges.size();
154  assert( nran == 3 );
155  cout << myname << " " << gnam << ": ";
156  for ( Index iran=0; iran<nran; ++iran ) {
157  if ( iran ) cout << ",";
158  cout << " " << chg.ranges[iran].name;
159  }
160  cout << endl;
161  }
162  }
163 
164  cout << myname << line << endl;
165  cout << myname << "Done." << endl;
166  return 0;
167 }
168 
169 //**********************************************************************
170 
171 int main(int argc, char* argv[]) {
172  bool useExistingFcl = false;
173  int show = 1;
174  if ( argc > 1 ) {
175  string sarg(argv[1]);
176  if ( sarg == "-h" ) {
177  cout << "Usage: " << argv[0] << " [keepFCL] [SHOW]" << endl;
178  cout << " If keepFCL = true, existing FCL file is used." << endl;
179  cout << " SHOW > 1 also shows the 480 FEMB blocks." << endl;
180  return 0;
181  }
182  useExistingFcl = sarg == "true" || sarg == "1";
183  }
184  if ( argc > 2 ) {
185  string sarg(argv[2]);
186  show = std::stoi(sarg);
187  }
188  return test_ProtoDuneChannelGroups(useExistingFcl, show);
189 }
190 
191 //**********************************************************************
std::vector< Index > IndexVector
const std::vector< std::string > & toolNames() const
std::string string
Definition: nybbler.cc:12
struct vector vector
ChannelGroupService::Name Name
int main(int argc, char *argv[])
void print() const
unsigned int Index
IndexRange range(Index iran) const
tm
Definition: demo.py:21
Name name
Definition: IndexRange.h:32
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
std::unique_ptr< T > getPrivate(std::string name)
RangeVector ranges
int test_ProtoDuneChannelGroups(bool useExistingFcl=false, int show=1)
void line(double t, double *p, double &x, double &y, double &z)
bool isValid() const
Q_EXPORT QTSManip setfill(int f)
Definition: qtextstream.h:337
static DuneToolManager * instance(std::string fclname="", int dbg=1)
QTextStream & endl(QTextStream &s)