test_AdcRoiToTree.cxx
Go to the documentation of this file.
1 // test_AdcRoiToTree.cxx
2 //
3 // David Adams
4 // October 2017
5 //
6 // Test AdcRoiToTree.
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_AdcRoiToTree(bool useExistingFcl =false) {
30  const string myname = "test_AdcRoiToTree: ";
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_AdcRoiToTree.fcl";
39  if ( ! useExistingFcl ) {
40  cout << myname << "Creating top-level FCL." << endl;
41  ofstream fout(fclfile.c_str());
42  fout << "tools.mytool: {" << endl;
43  fout << " tool_type: AdcRoiToTree" << endl;
44  fout << " LogLevel: 4" << endl;
45  fout << " OutFile: \"adcrois.root\"" << endl;
46  fout << " MetadataFields: [\"runevt\", \"xcha\"]" << endl;
47  fout << "}" << endl;
48  fout.close();
49  } else {
50  cout << myname << "Using existing top-level FCL." << endl;
51  }
52 
53  cout << myname << line << endl;
54  cout << myname << "Fetching tool manager." << endl;
56  assert ( ptm != nullptr );
57  DuneToolManager& tm = *ptm;
58  tm.print();
59  assert( tm.toolNames().size() == 1 );
60 
61  cout << myname << line << endl;
62  cout << myname << "Fetching tool." << endl;
63  auto ptoo = tm.getPrivate<TpcDataTool>("mytool");
64  assert( ptoo != nullptr );
65 
66  cout << myname << line << endl;
67  cout << myname << "Create test data." << endl;
68  Index irun = 123;
69  Index ievt = 456;
70  float runevt = 1000*irun + ievt;
71  AdcChannelDataMap acds;
72  Index ncha = 4;
73  Index icha1 = 100;
74  Index icha2 = icha1 + ncha;
75  for ( Index icha=icha1; icha<icha2; ++icha ) {
76  AdcChannelData& acd = acds[icha];
77  acd.setEventInfo(irun, ievt);
78  acd.setMetadata("runevt", runevt);
79  float xcha = 5*(icha%100); // Wire posn in mm.
80  acd.setMetadata("xcha", xcha);
81  acd.setChannelInfo(icha);
82  acd.samples.resize(1000, icha);
83  Index nroi = icha - icha1 + 1;
84  for ( Index iroi=0; iroi<nroi; ++iroi ) {
85  Index isam1 = 100*iroi;
86  Index isam2 = isam1 + iroi;
87  acd.rois.emplace_back(isam1, isam2);
88  }
89  }
90 
91  cout << myname << line << endl;
92  cout << myname << "Call tool." << endl;
93  DataMap res = ptoo->viewMap(acds);
94  res.print();
95 
96  cout << myname << line << endl;
97  cout << myname << "Done." << endl;
98  return 0;
99 }
100 
101 //**********************************************************************
102 
103 int main(int argc, char* argv[]) {
104  bool useExistingFcl = false;
105  if ( argc > 1 ) {
106  string sarg(argv[1]);
107  if ( sarg == "-h" ) {
108  cout << "Usage: " << argv[0] << " [ARG]" << endl;
109  cout << " If ARG = true, existing FCL file is used." << endl;
110  return 0;
111  }
112  useExistingFcl = sarg == "true" || sarg == "1";
113  }
114  return test_AdcRoiToTree(useExistingFcl);
115 }
116 
117 //**********************************************************************
const std::vector< std::string > & toolNames() const
std::string string
Definition: nybbler.cc:12
int test_AdcRoiToTree(bool useExistingFcl=false)
struct vector vector
void print() const
unsigned int Index
void print(std::ostream *pout) const
Definition: DataMap.h:245
tm
Definition: demo.py:21
int main(int argc, char *argv[])
void setChannelInfo(ChannelInfoPtr pchi)
AdcRoiVector rois
void setEventInfo(EventInfoPtr pevi)
std::unique_ptr< T > getPrivate(std::string name)
void line(double t, double *p, double &x, double &y, double &z)
void setMetadata(Name mname, float val)
std::map< AdcChannel, AdcChannelData > AdcChannelDataMap
static DuneToolManager * instance(std::string fclname="", int dbg=1)
AdcSignalVector samples
QTextStream & endl(QTextStream &s)