test_AdcEventViewer.cxx
Go to the documentation of this file.
1 // test_AdcEventViewer.cxx
2 //
3 // David Adams
4 // October 2017
5 //
6 // Test AdcEventViewer.
7 
8 #include <string>
9 #include <iostream>
10 #include <fstream>
13 #include "TRandom.h"
14 
15 #undef NDEBUG
16 #include <cassert>
17 
18 using std::string;
19 using std::cout;
20 using std::endl;
21 using std::ofstream;
22 using std::vector;
24 
25 using Index = unsigned int;
26 
27 //**********************************************************************
28 
29 int test_AdcEventViewer(bool useExistingFcl =false) {
30  const string myname = "test_AdcEventViewer: ";
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_AdcEventViewer.fcl";
39  if ( ! useExistingFcl ) {
40  cout << myname << "Creating top-level FCL." << endl;
41  ofstream fout(fclfile.c_str());
42  fout << "#include \"dataprep_tools.fcl\"" << endl;
43  fout << "tools.mytool: {" << endl;
44  fout << " tool_type: AdcEventViewer" << endl;
45  fout << " LogLevel: 1" << endl;
46  fout << " EventHists: []" << endl;
47  fout << " EventGraphs: []" << endl;
48  fout << " ChannelRanges: []" << endl;
49  fout << " ChannelRangeLabel: \"\"" << endl;
50  fout << " ClockUnit: Mtick" << endl;
51  fout << " ClockRate: 50000000" << 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() >= 2 );
65 
66  cout << myname << line << endl;
67  cout << myname << "Fetching tool." << endl;
68  auto ptoo = tm.getPrivate<TpcDataTool>("mytool");
69  assert( ptoo != nullptr );
70 
71  cout << myname << line << endl;
72  cout << myname << "Create test data." << endl;
73  AdcChannelDataMap acds;
74  vector<float> pulse = { 2.0, -3.0, 0.0, 5.0, 24.0, 56.0, 123.0, 71.0, 52.1, 26.3,
75  12.5, 8.1, 4.5, 2.0, -1.0, 3.2, 1.1, -2.2, 0.1, -0.1};
76  Index npul = 100;
77  for ( Index icha=250; icha<270; ++icha ) {
78  AdcChannelData& acd = acds[icha];
79  acd.setEventInfo(111, 123);
80  acd.setChannelInfo(icha);
81  acd.samples.resize(npul*pulse.size());
82  acd.sampleUnit = "ADC count";
83  double sigma = 5.0;
84  Index itck = 0;
85  for ( Index ipul=0; ipul<npul; ++ipul ) {
86  Index itck0 = itck;
87  for ( Index ismp=0; ismp<pulse.size(); ++ismp, ++itck ) {
88  acd.samples[itck] = pulse[ismp] + gRandom->Gaus(0.0, sigma);
89  }
90  acd.rois.emplace_back( itck0+2, itck-2);
91  }
92  assert( acd.rois.size() == npul );
93  }
94 
95  cout << myname << line << endl;
96 
97  cout << myname << line << endl;
98  cout << myname << "Call tool for channel map." << endl;
99  DataMap res;
100  res = ptoo->viewMap(acds);
101  res = ptoo->viewMap(acds);
102  res = ptoo->viewMap(acds);
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  if ( argc > 1 ) {
114  string sarg(argv[1]);
115  if ( sarg == "-h" ) {
116  cout << "Usage: " << argv[0] << " [ARG]" << endl;
117  cout << " If ARG = true, existing FCL file is used." << endl;
118  return 0;
119  }
120  useExistingFcl = sarg == "true" || sarg == "1";
121  }
122  return test_AdcEventViewer(useExistingFcl);
123 }
124 
125 //**********************************************************************
const std::vector< std::string > & toolNames() const
std::string string
Definition: nybbler.cc:12
struct vector vector
void print() const
unsigned int Index
tm
Definition: demo.py:21
void setChannelInfo(ChannelInfoPtr pchi)
AdcRoiVector rois
int test_AdcEventViewer(bool useExistingFcl=false)
size_t size
Definition: lodepng.cpp:55
void setEventInfo(EventInfoPtr pevi)
std::unique_ptr< T > getPrivate(std::string name)
void line(double t, double *p, double &x, double &y, double &z)
int main(int argc, char *argv[])
std::map< AdcChannel, AdcChannelData > AdcChannelDataMap
static DuneToolManager * instance(std::string fclname="", int dbg=1)
AdcSignalVector samples
QTextStream & endl(QTextStream &s)