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