test_AdcRoiShifter.cxx
Go to the documentation of this file.
1 // test_AdcRoiShifter.cxx
2 //
3 // David Adams
4 // March 2019
5 //
6 // Test AdcRoiShifter.
7 
8 #include <string>
9 #include <iostream>
10 #include <fstream>
13 
14 #undef NDEBUG
15 #include <cassert>
16 
17 using std::string;
18 using std::cout;
19 using std::endl;
20 using std::vector;
21 using std::ofstream;
23 
24 //**********************************************************************
25 
26 int test_AdcRoiShifter(bool useExistingFcl =false) {
27  const string myname = "test_AdcRoiShifter: ";
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_AdcRoiShifter.fcl";
36  if ( ! useExistingFcl ) {
37  cout << myname << "Creating top-level FCL." << endl;
38  ofstream fout(fclfile.c_str());
39  fout << "tools: {" << endl;
40  fout << " mytool: {" << endl;
41  fout << " tool_type: AdcRoiShifter" << endl;
42  fout << " LogLevel: 1" << endl;
43  fout << " BinOffset: 3" << endl;
44  fout << " }" << endl;
45  fout << "}" << endl;
46  fout.close();
47  } else {
48  cout << myname << "Using existing top-level FCL." << endl;
49  }
50 
51  cout << myname << line << endl;
52  cout << myname << "Fetching tool manager." << endl;
54  assert ( ptm != nullptr );
55  DuneToolManager& tm = *ptm;
56  tm.print();
57  assert( tm.toolNames().size() == 1 );
58 
59  cout << myname << line << endl;
60  cout << myname << "Fetching tool." << endl;
61  auto psgf = tm.getPrivate<TpcDataTool>("mytool");
62  assert( psgf != nullptr );
63  auto psgfmod = tm.getPrivate<TpcDataTool>("mytool");
64  assert( psgfmod != nullptr );
65 
66  cout << myname << line << endl;
67  cout << myname << "Create data and call tool." << endl;
69  vector<bool> sigdat = {false, true, false, false, true, false, false, false, true};
70  vector<bool> sigchk = {false, false, false, false, true, false, false, true, false};
71  data.signal = sigdat;
72  assert( data.signal == sigdat );
73  assert( data.signal != sigchk );
74 
75  cout << myname << line << endl;
76  cout << myname << "Running tool." << endl;
77  DataMap resmod = psgfmod->update(data);
78  resmod.print();
79 
80  cout << myname << line << endl;
81  cout << myname << "Checking results." << endl;
82  assert( resmod == 0 );
83  assert( data.signal != sigdat );
84  assert( data.signal == sigchk );
85 
86  cout << myname << line << endl;
87  cout << myname << "Done." << endl;
88  return 0;
89 }
90 
91 //**********************************************************************
92 
93 int main(int argc, char* argv[]) {
94  bool useExistingFcl = false;
95  if ( argc > 1 ) {
96  string sarg(argv[1]);
97  if ( sarg == "-h" ) {
98  cout << "Usage: " << argv[0] << " [ARG]" << endl;
99  cout << " If ARG = true, existing FCL file is used." << endl;
100  return 0;
101  }
102  useExistingFcl = sarg == "true" || sarg == "1";
103  }
104  return test_AdcRoiShifter(useExistingFcl);
105 }
106 
107 //**********************************************************************
const std::vector< std::string > & toolNames() const
std::string string
Definition: nybbler.cc:12
struct vector vector
int main(int argc, char *argv[])
void print() const
void print(std::ostream *pout) const
Definition: DataMap.h:245
tm
Definition: demo.py:21
std::unique_ptr< T > getPrivate(std::string name)
AdcFilterVector signal
void line(double t, double *p, double &x, double &y, double &z)
int test_AdcRoiShifter(bool useExistingFcl=false)
static DuneToolManager * instance(std::string fclname="", int dbg=1)
QTextStream & endl(QTextStream &s)