test_ChannelStatusConfigTool.cxx
Go to the documentation of this file.
1 // test_ChannelStatusConfigTool.cxx
2 //
3 // David Adams
4 // April 2020
5 //
6 // Test ChannelStatusConfigTool.
7 
11 #include "TH1F.h"
12 #include <string>
13 #include <iostream>
14 #include <fstream>
15 #include <sstream>
16 #include <iomanip>
17 
18 #undef NDEBUG
19 #include <cassert>
20 
21 using std::string;
22 using std::cout;
23 using std::endl;
24 using std::ofstream;
25 using std::istringstream;
26 using std::setw;
27 using std::vector;
29 using Index = unsigned int;
30 
31 //**********************************************************************
32 
33 int test_ChannelStatusConfigTool(bool useExistingFcl =false) {
34  const string myname = "test_ChannelStatusConfigTool: ";
35 #ifdef NDEBUG
36  cout << myname << "NDEBUG must be off." << endl;
37  abort();
38 #endif
39  string line = "-----------------------------";
40 
41  cout << myname << line << endl;
42  string fclfile = "test_ChannelStatusConfigTool.fcl";
43  if ( ! useExistingFcl ) {
44  cout << myname << "Creating top-level FCL." << endl;
45  ofstream fout(fclfile.c_str());
46  fout << "tools: {" << endl;
47  fout << " mytool: {" << endl;
48  fout << " tool_type: ChannelStatusConfigTool" << endl;
49  fout << " LogLevel: 1" << endl;
50  fout << " DefaultIndex: 99" << endl;
51  fout << " IndexVectors: [" << endl;
52  fout << " [ 0, 1, 2]," << endl;
53  fout << " [ 10, 11, 12]," << endl;
54  fout << " [ 20, 21, 22]" << endl;
55  fout << " ]" << endl;
56  fout << " }" << endl;
57  fout << "}" << endl;
58  fout.close();
59  } else {
60  cout << myname << "Using existing top-level FCL." << endl;
61  }
62 
63  cout << myname << line << endl;
64  cout << myname << "Fetching tool manager." << endl;
66  assert ( ptm != nullptr );
67  DuneToolManager& tm = *ptm;
68  tm.print();
69  assert( tm.toolNames().size() >= 1 );
70 
71  cout << myname << line << endl;
72  cout << myname << "Fetching tool." << endl;
73  auto pcs = tm.getPrivate<IndexMapTool>("mytool");
74  assert( pcs != nullptr );
75 
76  cout << myname << line << endl;
77  cout << "Check some channels." << endl;
78  vector<Index> chks(30, 99);
79  chks[ 0] = 0;
80  chks[ 1] = 0;
81  chks[ 2] = 0;
82  chks[10] = 1;
83  chks[11] = 1;
84  chks[12] = 1;
85  chks[20] = 2;
86  chks[21] = 2;
87  chks[22] = 2;
88  for ( Index icha=0; icha<chks.size(); ++icha ) {
89  Index chanStat = pcs->get(icha);
90  cout << setw(8) << icha << ": " << setw(2) << chanStat << endl;
91  assert( chanStat == chks[icha] );
92  }
93 
94  cout << myname << line << endl;
95  cout << myname << "Done." << endl;
96  return 0;
97 }
98 
99 //**********************************************************************
100 
101 int main(int argc, char* argv[]) {
102  bool useExistingFcl = false;
103  if ( argc > 1 ) {
104  string sarg(argv[1]);
105  if ( sarg == "-h" ) {
106  cout << "Usage: " << argv[0] << " [keepFCL]" << endl;
107  cout << " If keepFCL = true, existing FCL file is used." << endl;
108  return 0;
109  }
110  useExistingFcl = sarg == "true" || sarg == "1";
111  }
112  return test_ChannelStatusConfigTool(useExistingFcl);
113 }
114 
115 //**********************************************************************
const std::vector< std::string > & toolNames() const
std::string string
Definition: nybbler.cc:12
struct vector vector
void print() const
unsigned int Index
tm
Definition: demo.py:21
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)
int test_ChannelStatusConfigTool(bool useExistingFcl=false)
static DuneToolManager * instance(std::string fclname="", int dbg=1)
QTextStream & endl(QTextStream &s)