test_AdcResultDumper.cxx
Go to the documentation of this file.
1 // test_AdcResultDumper.cxx
2 //
3 // David Adams
4 // April 2018
5 //
6 // Test AdcResultDumper.
7 
8 #include <string>
9 #include <iostream>
10 #include <fstream>
11 #include <sstream>
12 #include <vector>
15 
16 #undef NDEBUG
17 #include <cassert>
18 
19 using std::string;
20 using std::cout;
21 using std::endl;
22 using std::ofstream;
23 
24 //**********************************************************************
25 
26 int test_AdcResultDumper(bool useExistingFcl =false) {
27  const string myname = "test_AdcResultDumper: ";
28 #ifdef NDEBUG
29  cout << myname << "NDEBUG must be off." << endl;
30  abort();
31 #endif
32  string line = "-----------------------------";
33 
34  cout << myname << line << endl;
35  string fclfile = "test_AdcResultDumper.fcl";
36  string gname = "protodune_geo";
37  if ( ! useExistingFcl ) {
38  cout << myname << "Creating top-level FCL." << endl;
39  ofstream fout(fclfile.c_str());
40  fout << "tools: {" << endl;
41  fout << " mytool1: {" << endl;
42  fout << " tool_type: AdcResultDumper" << endl;
43  fout << " LogLevel: 2" << endl;
44  fout << " Tool: \"NoSuchTool\"" << endl;
45  fout << " }" << endl;
46  fout << " mytool2: {" << endl;
47  fout << " tool_type: AdcResultDumper" << endl;
48  fout << " LogLevel: 2" << endl;
49  fout << " Tool: \"mytool1\"" << endl;
50  fout << " }" << endl;
51  fout << "}" << endl;
52  fout.close();
53  } else {
54  cout << myname << "Using existing top-level FCL." << endl;
55  }
56 
57  cout << myname << line << endl;
58  cout << myname << "Fetching tool manager." << endl;
60  assert ( ptm != nullptr );
61  DuneToolManager& tm = *ptm;
62  tm.print();
63  assert( tm.toolNames().size() == 2 );
64 
65  cout << myname << line << endl;
66  cout << myname << "Fetching tool 1." << endl;
67  auto pard1 = tm.getPrivate<TpcDataTool>("mytool1");
68  assert( pard1 != nullptr );
69 
70  cout << myname << line << endl;
71  cout << myname << "Fetching tool 2." << endl;
72  auto pard2 = tm.getPrivate<TpcDataTool>("mytool2");
73  assert( pard2 != nullptr );
74 
75  cout << myname << line << endl;
76  cout << myname << "Calling tool 1." << endl;
77  AdcChannelData acd;
78  DataMap dm1 = pard1->view(acd);
79  dm1.print();
80  assert( dm1.status() == 101 );
81 
82  cout << myname << line << endl;
83  cout << myname << "Calling tool 2." << endl;
84  DataMap dm2 = pard2->view(acd);
85  dm2.print();
86  assert( dm2.status() == 101 );
87 
88  cout << myname << line << endl;
89  cout << myname << "Done." << endl;
90  return 0;
91 }
92 
93 //**********************************************************************
94 
95 int main(int argc, char* argv[]) {
96  bool useExistingFcl = false;
97  if ( argc > 1 ) {
98  string sarg(argv[1]);
99  if ( sarg == "-h" ) {
100  cout << "Usage: " << argv[0] << " [ARG]" << endl;
101  cout << " If ARG = true, existing FCL file is used." << endl;
102  return 0;
103  }
104  useExistingFcl = sarg == "true" || sarg == "1";
105  }
106  return test_AdcResultDumper(useExistingFcl);
107 }
108 
109 //**********************************************************************
const std::vector< std::string > & toolNames() const
std::string string
Definition: nybbler.cc:12
void print() const
void print(std::ostream *pout) const
Definition: DataMap.h:245
tm
Definition: demo.py:21
int status() const
Definition: DataMap.h:202
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)
int test_AdcResultDumper(bool useExistingFcl=false)
static DuneToolManager * instance(std::string fclname="", int dbg=1)
QTextStream & endl(QTextStream &s)