test_AdcSampleFiller.cxx
Go to the documentation of this file.
1 // test_AdcSampleFiller.cxx
2 //
3 // David Adams
4 // April 2017
5 //
6 // Test AdcSampleFiller.
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::ofstream;
22 
23 //**********************************************************************
24 
25 int test_AdcSampleFiller(bool useExistingFcl =false) {
26  const string myname = "test_AdcSampleFiller: ";
27 #ifdef NDEBUG
28  cout << myname << "NDEBUG must be off." << endl;
29  abort();
30 #endif
31  string line = "-----------------------------";
32 
33  cout << myname << line << endl;
34  string fclfile = "test_AdcSampleFiller.fcl";
35  if ( ! useExistingFcl ) {
36  cout << myname << "Creating top-level FCL." << endl;
37  ofstream fout(fclfile.c_str());
38  fout << "tools: {" << endl;
39  fout << " mytool: {" << endl;
40  fout << " tool_type: AdcSampleFiller" << endl;
41  fout << " LogLevel: 1" << endl;
42  fout << " AdcUnderflow: 0" << endl;
43  fout << " AdcOverflow: 4095" << 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 pasf = tm.getPrivate<TpcDataTool>("mytool");
62  assert( pasf != nullptr );
63  auto pasfmod = tm.getPrivate<TpcDataTool>("mytool");
64  assert( pasfmod != nullptr );
65 
66  cout << myname << line << endl;
67  cout << myname << "Create data and call tool." << endl;
69  for ( AdcIndex itic=0; itic<60; ++itic ) {
70  AdcIndex adc = 100*itic;
71  data.raw.push_back(adc);
72  }
73  assert( data.raw.size() == 60 );
74  assert( data.samples.size() == 0 );
75  assert( data.signal.size() == 0 );
76  assert( data.rois.size() == 0 );
77 
78  cout << myname << line << endl;
79  cout << myname << "Running tool without pedestal." << endl;
80  DataMap resmodBad = pasfmod->update(data);
81  resmodBad.print();
82  assert( resmodBad != 0 );
83 
84  cout << myname << line << endl;
85  cout << myname << "Running tool." << endl;
86  data.pedestal = 1000.0;
87  DataMap resmod = pasfmod->update(data);
88  resmod.print();
89 
90  cout << myname << line << endl;
91  cout << myname << "Checking results." << endl;
92  assert( resmod == 0 );
93  assert( !resmod );
94  assert( resmod.getInt("nUnderflow") == 1 );
95  assert( resmod.getInt("nOverflow") == 19 );
96  assert( resmod.getInt("nOutOfRange") == 19 );
97  assert( data.raw.size() == 60 );
98  assert( data.samples.size() == 60 );
99  assert( data.signal.size() == 0 );
100 
101  cout << myname << line << endl;
102  cout << myname << "Done." << endl;
103  return 0;
104 }
105 
106 //**********************************************************************
107 
108 int main(int argc, char* argv[]) {
109  bool useExistingFcl = false;
110  if ( argc > 1 ) {
111  string sarg(argv[1]);
112  if ( sarg == "-h" ) {
113  cout << "Usage: " << argv[0] << " [ARG]" << endl;
114  cout << " If ARG = true, existing FCL file is used." << endl;
115  return 0;
116  }
117  useExistingFcl = sarg == "true" || sarg == "1";
118  }
119  return test_AdcSampleFiller(useExistingFcl);
120 }
121 
122 //**********************************************************************
const std::vector< std::string > & toolNames() const
std::string string
Definition: nybbler.cc:12
int16_t adc
Definition: CRTFragment.hh:202
void print() const
void print(std::ostream *pout) const
Definition: DataMap.h:245
tm
Definition: demo.py:21
AdcRoiVector rois
int main(int argc, char *argv[])
AdcCountVector raw
unsigned int AdcIndex
Definition: AdcTypes.h:15
int test_AdcSampleFiller(bool useExistingFcl=false)
std::unique_ptr< T > getPrivate(std::string name)
AdcSignal pedestal
AdcFilterVector signal
int getInt(Name name, int def=0) const
Definition: DataMap.h:218
void line(double t, double *p, double &x, double &y, double &z)
static DuneToolManager * instance(std::string fclname="", int dbg=1)
AdcSignalVector samples
QTextStream & endl(QTextStream &s)