test_AdcChannelDumper.cxx
Go to the documentation of this file.
1 // test_AdcChannelDumper.cxx
2 //
3 // David Adams
4 // April 2017
5 //
6 // Test AdcChannelDumper.
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_AdcChannelDumper(bool useExistingFcl =false) {
26  const string myname = "test_AdcChannelDumper: ";
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_AdcChannelDumper.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: AdcChannelDumper" << endl;
41  fout << " FileName: \"\"" << endl;
42  fout << " NewFile: false" << endl;
43  fout << " Prefix: \"ADC dump: \"" << endl;
44  fout << " MaxSample: 80" << endl;
45  fout << " }" << endl;
46  fout << "}" << endl;
47  fout.close();
48  } else {
49  cout << myname << "Using existing top-level FCL." << endl;
50  }
51 
52  cout << myname << line << endl;
53  cout << myname << "Fetching tool manager." << endl;
55  assert ( ptm != nullptr );
56  DuneToolManager& tm = *ptm;
57  tm.print();
58  assert( tm.toolNames().size() == 1 );
59 
60  cout << myname << line << endl;
61  cout << myname << "Fetching tool." << endl;
62  auto padv = tm.getPrivate<TpcDataTool>("mytool");
63  assert( padv != nullptr );
64 
65  cout << myname << line << endl;
66  cout << myname << "Create data and call too." << endl;
67  AdcIndex nevt = 2;
68  string lab = "plane 3u";
69  float peds[10] = {701.1, 711.2, 733.3, 690.4, 688.5, 703.6, 720.7, 720.8, 695.9, 702.0};
70  for ( AdcIndex ievt=0; ievt<nevt; ++ievt ) {
71  cout << myname << "Event " << ievt << endl;
72  AdcChannelDataMap datamap;
73  AdcIndex ncha = 10;
74  for ( AdcIndex icha=0; icha<ncha; ++icha ) {
75  std::pair<AdcChannelDataMap::iterator, bool> kdat = datamap.emplace(icha, AdcChannelData());
76  assert(kdat.second);
77  AdcChannelDataMap::iterator idat = kdat.first;
78  AdcChannelData& data = idat->second;
79  float ped = peds[icha];
80  data.setEventInfo(101, ievt, 23);
81  data.setChannelInfo(icha);
82  data.pedestal = ped;
83  for ( AdcIndex itic=0; itic<100; ++itic ) {
84  float xadc = ped + rand()%20 - 10.0;
85  AdcIndex iticeff = itic - 3*icha;
86  if ( iticeff > 20 && iticeff < 40 ) xadc +=600;
87  AdcCount iadc = xadc;
88  data.raw.push_back(iadc);
89  data.flags.push_back(0);
90  data.samples.push_back(iadc - ped);
91  data.signal.push_back(xadc - ped > 300.0 );
92  }
93  AdcIndex tp = 10*ievt + 60 - 2.3*icha;
94  AdcIndex tm = tp - 8;
95  data.raw[tp] += 100;
96  data.samples[tp] += 100;
97  data.raw[tm] -= 100;
98  data.samples[tm] -= 100;
99  data.flags[tm] = 4;
100  data.roisFromSignal();
101  assert( padv->view(datamap[icha]) == 0 );
102  }
103  }
104 
105  cout << myname << line << endl;
106  cout << myname << "Done." << endl;
107  return 0;
108 }
109 
110 //**********************************************************************
111 
112 int main(int argc, char* argv[]) {
113  bool useExistingFcl = false;
114  if ( argc > 1 ) {
115  string sarg(argv[1]);
116  if ( sarg == "-h" ) {
117  cout << "Usage: " << argv[0] << " [ARG]" << endl;
118  cout << " If ARG = true, existing FCL file is used." << endl;
119  return 0;
120  }
121  useExistingFcl = sarg == "true" || sarg == "1";
122  }
123  return test_AdcChannelDumper(useExistingFcl);
124 }
125 
126 //**********************************************************************
intermediate_table::iterator iterator
const std::vector< std::string > & toolNames() const
std::string string
Definition: nybbler.cc:12
int test_AdcChannelDumper(bool useExistingFcl=false)
int main(int argc, char *argv[])
void print() const
tm
Definition: demo.py:21
void setChannelInfo(ChannelInfoPtr pchi)
void setEventInfo(EventInfoPtr pevi)
AdcCountVector raw
unsigned int AdcIndex
Definition: AdcTypes.h:15
std::unique_ptr< T > getPrivate(std::string name)
AdcSignal pedestal
AdcFilterVector signal
void line(double t, double *p, double &x, double &y, double &z)
std::map< AdcChannel, AdcChannelData > AdcChannelDataMap
short AdcCount
Definition: AdcTypes.h:18
static DuneToolManager * instance(std::string fclname="", int dbg=1)
AdcSignalVector samples
QTextStream & endl(QTextStream &s)
AdcFlagVector flags