test_FclStickyCodeFlagger.cxx
Go to the documentation of this file.
1 // test_FclStickyCodeFlagger.cxx
2 //
3 // David Adams
4 // April 2017
5 //
6 // Test FclStickyCodeFlagger.
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 using Index = unsigned int;
23 
24 //**********************************************************************
25 
26 int test_FclStickyCodeFlagger(bool useExistingFcl =false) {
27  const string myname = "test_FclStickyCodeFlagger: ";
28 #ifdef NDEBUG
29  cout << myname << "NDEBUG must be off." << endl;
30  abort();
31 #endif
32  string line = "-----------------------------";
33 
34  cout << myname << line << endl;
35  string fclfile = "test_FclStickyCodeFlagger.fcl";
36  if ( ! useExistingFcl ) {
37  cout << myname << "Creating top-level FCL." << endl;
38  ofstream fout(fclfile.c_str());
39  fout << "tools: {" << endl;
40  fout << " mytool: {" << endl;
41  fout << " tool_type: FclStickyCodeFlagger" << endl;
42  fout << " LogLevel: 3" << endl;
43  fout << " StickyCode: 8" << endl;
44  fout << " StickyCodes: {" << endl;
45  fout << " chan012: [105, 110]" << endl;
46  fout << " chan012x: [109]" << endl;
47  fout << " }" << endl;
48  fout << " StickyRanges: {" << endl;
49  fout << " chan014: [110, 111]" << endl;
50  fout << " chan014x: [119, 119]" << endl;
51  fout << " }" << 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 padv = tm.getPrivate<TpcDataTool>("mytool");
70  assert( padv != nullptr );
71 
72  cout << myname << line << endl;
73  cout << myname << "Create data and call tool." << endl;
74  AdcIndex nevt = 2;
75  for ( AdcIndex ievt=0; ievt<nevt; ++ievt ) {
76  cout << myname << "Event " << ievt << endl;
77  AdcChannelDataMap datamap;
78  AdcIndex ncha = 20;
79  for ( AdcIndex icha=0; icha<ncha; ++icha ) {
80  std::pair<AdcChannelDataMap::iterator, bool> kdat = datamap.emplace(icha, AdcChannelData());
81  assert(kdat.second);
82  AdcChannelDataMap::iterator idat = kdat.first;
83  AdcChannelData& data = idat->second;
84  float ped = 100.0;
85  data.setEventInfo(new AdcChannelData::EventInfo(101, ievt, 23));
86  data.setChannelInfo(icha);
87  data.pedestal = ped;
88  for ( AdcIndex itic=0; itic<20; ++itic ) {
89  AdcCount iadc = ped + itic;
90  data.raw.push_back(iadc);
91  data.flags.push_back(0);
92  }
93  DataMap dm = padv->update(datamap[icha]);
94  assert( dm == 0 );
95  dm.print();
96  if ( data.channel() == 12 ) {
97  for ( Index isam=0; isam<data.raw.size(); ++isam ) {
98  cout << myname << " " << data.raw[isam] << " " << data.flags[isam] << endl;
99  if ( data.raw[isam] == 105 || data.raw[isam] == 109 || data.raw[isam] == 110 ) assert( data.flags[isam] == 8 );
100  else assert( data.flags[isam] == 0 );
101  }
102  }
103  if ( data.channel() == 14 ) {
104  for ( Index isam=0; isam<data.raw.size(); ++isam ) {
105  cout << myname << " " << data.raw[isam] << " " << data.flags[isam] << endl;
106  if ( data.raw[isam] == 110 || data.raw[isam] == 111 || data.raw[isam] == 119 ) assert( data.flags[isam] == 8 );
107  else assert( data.flags[isam] == 0 );
108  }
109  }
110  }
111  }
112 
113  cout << myname << line << endl;
114  cout << myname << "Done." << endl;
115  return 0;
116 }
117 
118 //**********************************************************************
119 
120 int main(int argc, char* argv[]) {
121  bool useExistingFcl = false;
122  if ( argc > 1 ) {
123  string sarg(argv[1]);
124  if ( sarg == "-h" ) {
125  cout << "Usage: " << argv[0] << " [ARG]" << endl;
126  cout << " If ARG = true, existing FCL file is used." << endl;
127  return 0;
128  }
129  useExistingFcl = sarg == "true" || sarg == "1";
130  }
131  return test_FclStickyCodeFlagger(useExistingFcl);
132 }
133 
134 //**********************************************************************
intermediate_table::iterator iterator
const std::vector< std::string > & toolNames() const
std::string string
Definition: nybbler.cc:12
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)
int test_FclStickyCodeFlagger(bool useExistingFcl=false)
void setEventInfo(EventInfoPtr pevi)
AdcCountVector raw
unsigned int AdcIndex
Definition: AdcTypes.h:15
std::unique_ptr< T > getPrivate(std::string name)
Channel channel() const
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)
QTextStream & endl(QTextStream &s)
AdcFlagVector flags