test_AdcSampleScaler.cxx
Go to the documentation of this file.
1 // test_AdcSampleScaler.cxx
2 //
3 // David Adams
4 // March 2019
5 //
6 // Test AdcSampleScaler.
7 
8 #include <string>
9 #include <iostream>
10 #include <fstream>
11 #include <iomanip>
14 #include "TRandom.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;
24 using std::setw;
26 
27 using Vector = std::vector<float>;
28 using Index = unsigned int;
29 
30 //**********************************************************************
31 
32 int test_AdcSampleScaler(bool useExistingFcl, float qsig, float ped, float noise) {
33  const string myname = "test_AdcSampleScaler: ";
34 #ifdef NDEBUG
35  cout << myname << "NDEBUG must be off." << endl;
36  abort();
37 #endif
38  string line = "-----------------------------";
39 
40  cout << myname << line << endl;
41  string fclfile = "test_AdcSampleScaler.fcl";
42  if ( ! useExistingFcl ) {
43  cout << myname << "Creating top-level FCL." << endl;
44  ofstream fout(fclfile.c_str());
45  fout << "tools: {" << endl;
46  fout << " mytool: {" << endl;
47  fout << " tool_type: AdcSampleScaler" << endl;
48  fout << " LogLevel: 1" << endl;
49  fout << " ScaleFactor: 100" << endl;
50  fout << " OutputUnit: \"e\"" << endl;
51  fout << " InputUnit: \"ADC\"" << endl;
52  fout << " }" << endl;
53  fout << "}" << endl;
54  fout.close();
55  } else {
56  cout << myname << "Using existing top-level FCL." << endl;
57  }
58 
59  cout << myname << line << endl;
60  cout << myname << "Fetching tool manager." << endl;
62  assert ( ptm != nullptr );
63  DuneToolManager& tm = *ptm;
64  tm.print();
65  assert( tm.toolNames().size() == 1 );
66 
67  cout << myname << line << endl;
68  cout << myname << "Fetching tool." << endl;
69  auto ptoo = tm.getPrivate<TpcDataTool>("mytool");
70  assert( ptoo != nullptr );
71 
72  cout << myname << line << endl;
73  cout << myname << "Create data." << endl;
74  Index nsam = 50;
75  Vector qsams(nsam, 0.0);
76  Vector qexps(nsam, 99.);
77  for ( Index isam=0; isam<nsam; ++isam ) {
78  float qsam = 200 + isam + 0.1*(isam%10);
79  qsams[isam] = qsam;
80  qexps[isam] = 100*qsam;
81  }
82  AdcChannelData acd;
83  acd.setEventInfo(123, 456);
84  acd.setChannelInfo(12345);
85  acd.samples = qsams;
86  acd.sampleUnit = "ADC";
87  assert ( qsams.size() == nsam );
88 
89  cout << myname << line << endl;
90  cout << myname << "Call tool." << endl;
91  DataMap ret = ptoo->update(acd);
92  assert( ! ret );
93  assert( ret.getInt("ascUnitCheck") == 0 );
94 
95  cout << myname << line << endl;
96  cout << myname << "Check samples." << endl;
97  for ( Index isam=0; isam<nsam; ++isam ) {
98  float qsam = acd.samples[isam];
99  float qexp = qexps[isam];
100  float qdif = fabs(qsam - qexp);
101  assert( qdif < 1.e-5 );
102  }
103 
104  cout << myname << line << endl;
105  cout << myname << "Done." << endl;
106  return 0;
107 }
108 
109 //**********************************************************************
110 
111 int main(int argc, char* argv[]) {
112  bool useExistingFcl = false;
113  float qsig = 500.0;
114  float ped = 2.0;
115  float noise = 0.0;
116  if ( argc > 1 ) {
117  string sarg(argv[1]);
118  if ( sarg == "-h" ) {
119  cout << "Usage: " << argv[0] << " [ARG [qsig [ped [noise]]]]" << endl;
120  cout << " If ARG = true, existing FCL file is used." << endl;
121  return 0;
122  }
123  useExistingFcl = sarg == "true" || sarg == "1";
124  }
125  if ( argc > 2 ) {
126  string sarg(argv[2]);
127  istringstream ssarg(sarg);
128  ssarg >> qsig;
129  }
130  if ( argc > 3 ) {
131  string sarg(argv[3]);
132  istringstream ssarg(sarg);
133  ssarg >> ped;
134  }
135  if ( argc > 4 ) {
136  string sarg(argv[4]);
137  istringstream ssarg(sarg);
138  ssarg >> noise;
139  }
140  return test_AdcSampleScaler(useExistingFcl, qsig, ped, noise);
141 }
142 
143 //**********************************************************************
int test_AdcSampleScaler(bool useExistingFcl, float qsig, float ped, float noise)
int main(int argc, char *argv[])
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
void setChannelInfo(ChannelInfoPtr pchi)
const double e
size_t size
Definition: lodepng.cpp:55
void setEventInfo(EventInfoPtr pevi)
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
std::unique_ptr< T > getPrivate(std::string name)
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)