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