test_TimingRawDecoderOffsetTool.cxx
Go to the documentation of this file.
1 // test_TimingRawDecoderOffsetTool.cxx
2 //
3 // David Adams
4 // May 2018
5 //
6 // Test TimingRawDecoderOffsetTool.
7 
8 #include <string>
9 #include <iostream>
10 #include <fstream>
11 #include <sstream>
14 #include "TH1F.h"
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 using std::istringstream;
25 using Index = unsigned int;
26 
27 //**********************************************************************
28 
29 int test_TimingRawDecoderOffsetTool(bool useExistingFcl =false) {
30  const string myname = "test_TimingRawDecoderOffsetTool: ";
31 #ifdef NDEBUG
32  cout << myname << "NDEBUG must be off." << endl;
33  abort();
34 #endif
35  string line = "-----------------------------";
36 
37  cout << myname << line << endl;
38  string fclfile = "test_TimingRawDecoderOffsetTool.fcl";
39  if ( ! useExistingFcl ) {
40  cout << myname << "Creating top-level FCL." << endl;
41  ofstream fout(fclfile.c_str());
42  fout << "tools: {" << endl;
43  fout << " mytool: {" << endl;
44  fout << " tool_type: TimingRawDecoderOffsetTool" << endl;
45  fout << " LogLevel: 2" << endl;
46  fout << " TpcTickPhase: 0" << endl;
47  fout << " Unit: \"tick\"" << endl;
48  fout << " FembScaleIds: []" << endl;
49  fout << " FembScaleValues: []" << endl;
50  fout << " RunDataTool: \"\"" << endl;
51  fout << " }" << endl;
52  fout << "}" << endl;
53  fout.close();
54  } else {
55  cout << myname << "Using existing top-level FCL." << endl;
56  }
57 
58  cout << myname << line << endl;
59  cout << myname << "Fetching tool manager." << endl;
61  assert ( ptm != nullptr );
62  DuneToolManager& tm = *ptm;
63  tm.print();
64  assert( tm.toolNames().size() >= 1 );
65 
66  cout << myname << line << endl;
67  cout << myname << "Create time offset file." << endl;
68  Index run = 123;
69  Index evt = 2468;
70  Index daqVal = 369258;
71 
72  cout << myname << line << endl;
73  cout << myname << "Fetching tool." << endl;
74  auto tot = tm.getPrivate<TimeOffsetTool>("mytool");
75  assert( tot != nullptr );
76 
77  cout << myname << line << endl;
78  cout << "Fetch the time offset in ticks." << endl;
80  dat.run = run;
81  dat.event = evt;
82  dat.triggerClock = daqVal;
83  TimeOffsetTool::Offset off = tot->offset(dat);
84  assert( off.isValid() );
85  assert( off.value == daqVal/25 );
86  assert( off.unit == "tick" );
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] << " [keepFCL] [RUN]" << endl;
101  cout << " If keepFCL = true, existing FCL file is used." << endl;
102  cout << " If RUN is nonzero, the data for that run are displayed." << endl;
103  return 0;
104  }
105  useExistingFcl = sarg == "true" || sarg == "1";
106  }
107  return test_TimingRawDecoderOffsetTool(useExistingFcl);
108 }
109 
110 //**********************************************************************
const std::vector< std::string > & toolNames() const
std::string string
Definition: nybbler.cc:12
void print() const
unsigned int Index
tm
Definition: demo.py:21
int main(int argc, char *argv[])
int test_TimingRawDecoderOffsetTool(bool useExistingFcl=false)
std::unique_ptr< T > getPrivate(std::string name)
void line(double t, double *p, double &x, double &y, double &z)
TCEvent evt
Definition: DataStructs.cxx:7
static DuneToolManager * instance(std::string fclname="", int dbg=1)
QTextStream & endl(QTextStream &s)