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