test_AdcChannelTrimmer.cxx
Go to the documentation of this file.
1 // test_AdcChannelTrimmer.cxx
2 //
3 // David Adams
4 // April 2017
5 //
6 // Test AdcChannelTrimmer.
7 
8 #include <string>
9 #include <iostream>
10 #include <fstream>
11 #include <sstream>
12 #include <vector>
15 #include <TRandom.h>
16 
17 #undef NDEBUG
18 #include <cassert>
19 
20 using std::string;
21 using std::cout;
22 using std::endl;
23 using std::ostringstream;
24 using std::ofstream;
26 using std::vector;
27 
28 using Index = unsigned int;
29 
30 //**********************************************************************
31 
32 int test_AdcChannelTrimmer(bool useExistingFcl =false) {
33  const string myname = "test_AdcChannelTrimmer: ";
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_AdcChannelTrimmer.fcl";
42  if ( ! useExistingFcl ) {
43  cout << myname << "Creating top-level FCL." << endl;
44  ofstream fout(fclfile.c_str());
45  fout << "#include \"dataprep_tools.fcl\"" << endl;
46  fout << "tools.mytool: {" << endl;
47  fout << " tool_type: AdcChannelTrimmer" << endl;
48  fout << " LogLevel: 2" << endl;
49  fout << " Length: 20" << endl;
50  fout << " MaxTrim: 10" << 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 << "Fetching tool." << endl;
68  auto ptoo = tm.getPrivate<TpcDataTool>("mytool");
69 
70  cout << myname << line << endl;
71  cout << myname << "Create data." << endl;
72  AdcChannelData acd;
73  acd.setEventInfo(123, 2468, 45);
74  acd.setChannelInfo(100123);
75  acd.sampleUnit = "fC";
76  acd.samples.resize(15);
77  for ( Index isam=0; isam<acd.samples.size(); ++isam ) {
78  acd.samples[isam] = 1.0 + 0.01*isam;
79  }
80  assert( acd.samples.size() == 15 );
81 
82  cout << myname << line << endl;
83  cout << myname << "Call tool view." << endl;
84  DataMap dmv = ptoo->view(acd);
85  dmv.print();
86  assert( dmv == 0 );
87  assert( dmv.getInt("trimAction") == -1 );
88  assert( dmv.getInt("trimLength") == -5 );
89  assert( acd.samples.size() == 15 );
90 
91  cout << myname << line << endl;
92  cout << myname << "Call tool update." << endl;
93  Index len1 = acd.samples.size();
94  DataMap dmu = ptoo->update(acd);
95  Index len2 = acd.samples.size();
96  dmu.print();
97  assert( dmu == 0 );
98  assert( dmu.getInt("trimAction") == 1 );
99  assert( dmu.getInt("trimLength") == -5 );
100  assert( len1 == 15 );
101  assert( len2 == 20 );
102  for ( Index isam=len1; isam<len2; ++isam ) {
103  float qsam = acd.samples[isam];
104  float qchk = acd.samples[isam-len1];
105  assert( fabs(qsam-qchk) < 1.e-6 );
106  }
107 
108  cout << myname << line << endl;
109  cout << myname << "Done." << endl;
110  return 0;
111 }
112 
113 //**********************************************************************
114 
115 int main(int argc, char* argv[]) {
116  bool useExistingFcl = false;
117  if ( argc > 1 ) {
118  string sarg(argv[1]);
119  if ( sarg == "-h" ) {
120  cout << "Usage: " << argv[0] << " [ARG]" << endl;
121  cout << " If ARG = true, existing FCL file is used." << endl;
122  return 0;
123  }
124  useExistingFcl = sarg == "true" || sarg == "1";
125  }
126  return test_AdcChannelTrimmer(useExistingFcl);
127 }
128 
129 //**********************************************************************
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
unsigned int Index
void print(std::ostream *pout) const
Definition: DataMap.h:245
tm
Definition: demo.py:21
void setChannelInfo(ChannelInfoPtr pchi)
const double e
void setEventInfo(EventInfoPtr pevi)
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)
int test_AdcChannelTrimmer(bool useExistingFcl=false)
static DuneToolManager * instance(std::string fclname="", int dbg=1)
AdcSignalVector samples
QTextStream & endl(QTextStream &s)