test_StandardAdcChannelStringTool.cxx
Go to the documentation of this file.
1 // test_StandardAdcChannelStringTool.cxx
2 //
3 // David Adams
4 // April 2017
5 //
6 // Test StandardAdcChannelStringTool.
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;
21 using std::vector;
23 using Index = unsigned int;
24 
25 //**********************************************************************
26 
27 int test_StandardAdcChannelStringTool(bool useExistingFcl =false) {
28  const string myname = "test_StandardAdcChannelStringTool: ";
29 #ifdef NDEBUG
30  cout << myname << "NDEBUG must be off." << endl;
31  abort();
32 #endif
33  string line = "-----------------------------";
34 
35  cout << myname << line << endl;
36  string fclfile = "test_StandardAdcChannelStringTool.fcl";
37  if ( ! useExistingFcl ) {
38  cout << myname << "Creating top-level FCL." << endl;
39  ofstream fout(fclfile.c_str());
40  fout << "tools: {" << endl;
41  fout << " mytool: {" << endl;
42  fout << " tool_type: StandardAdcChannelStringTool" << endl;
43  fout << " LogLevel: 2" << endl;
44  fout << " RunWidth: 4" << endl;
45  fout << " SubRunWidth: 3" << endl;
46  fout << " EventWidth: 6" << endl;
47  fout << " ChannelWidth: 5" << endl;
48  fout << " CountWidth: 6" << endl;
49  fout << " FembWidth: 3" << endl;
50  fout << " TriggerWidth: 2" << endl;
51  fout << " TrigNames: [unknown]" << 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 past = tm.getPrivate<AdcChannelStringTool>("mytool");
70  assert( past != nullptr );
71 
72  cout << myname << line << endl;
73  cout << myname << "Create data." << endl;
74  AdcChannelData acd;
75  acd.setEventInfo(123, 246, 45, 1847483647, 123456789);
76  acd.setChannelInfo(1357, 24);
77  acd.sampleUnit = "my units";
78 
79  cout << myname << line << endl;
80  cout << myname << "Call tool." << endl;
81  vector<string> rawNames = {
82  "run%RUN%",
83  "srun%SUBRUN%",
84  "run%RUN%_srun%XXBRUN%",
85  "run%RUN%_srun%SUBRUN%",
86  "data_run%RUN%-%SUBRUN%_ev%EVENT%_ch%CHAN%_%COUNT%.dat",
87  "data_run%5RUN%-%5SUBRUN%_ev%5EVENT%_ch%5CHAN%_%5COUNT%.dat",
88  "data_run%0RUN%-%0SUBRUN%_ev%0EVENT%_ch%0CHAN%_%0COUNT%.dat",
89  "data_run%0RUN%_run%8RUN%.dat",
90  "Units are %SUNIT%",
91  "Units are %(SUNIT)%",
92  "Units are %((SUNIT))%",
93  "Units are% ((SUNIT))%",
94  "FEMB is %FEMB%",
95  "femb%4FEMB%",
96  "femb%0FEMB%",
97  "date: %UTCTIME%",
98  "time: %UTCTIME9%"
99  };
100  vector<string> expNames = {
101  "run123",
102  "srun45",
103  "run123_srun%XXBRUN%",
104  "run123_srun45",
105  "data_run123-45_ev246_ch1357_23.dat",
106  "data_run00123-00045_ev00246_ch01357_00023.dat",
107  "data_run0123-045_ev000246_ch01357_000023.dat",
108  "data_run0123_run00000123.dat",
109  "Units are my units",
110  "Units are (my units)",
111  "Units are (my units)",
112  "Units are (my units)",
113  "FEMB is 24",
114  "femb0024",
115  "femb024",
116  "date: 2028-07-17 21:54:07",
117  "time: 2028-07-17 21:54:07.123456789"
118  };
119  DataMap dm;
120  dm.setInt("count", 23);
121  assert( dm.haveInt("count") );
122 
123  for ( Index inam=0; inam<rawNames.size(); ++inam ) {
124  string rawName = rawNames[inam];
125  string expName = expNames[inam];
126  string outName = past->build(acd, dm, rawName);
127  cout << myname << " Raw name: " << rawName << endl;
128  cout << myname << " Exp name: " << expName << endl;
129  cout << myname << " Out name: " << outName << endl;
130  assert( outName == expName );
131  }
132 
133  cout << myname << line << endl;
134  cout << myname << "Done." << endl;
135  return 0;
136 }
137 
138 //**********************************************************************
139 
140 int main(int argc, char* argv[]) {
141  bool useExistingFcl = false;
142  if ( argc > 1 ) {
143  string sarg(argv[1]);
144  if ( sarg == "-h" ) {
145  cout << "Usage: " << argv[0] << " [ARG]" << endl;
146  cout << " If ARG = true, existing FCL file is used." << endl;
147  return 0;
148  }
149  useExistingFcl = sarg == "true" || sarg == "1";
150  }
151  return test_StandardAdcChannelStringTool(useExistingFcl);
152 }
153 
154 //**********************************************************************
const std::vector< std::string > & toolNames() const
std::string string
Definition: nybbler.cc:12
struct vector vector
bool haveInt(Name name) const
Definition: DataMap.h:207
void print() const
unsigned int Index
int test_StandardAdcChannelStringTool(bool useExistingFcl=false)
tm
Definition: demo.py:21
void setChannelInfo(ChannelInfoPtr pchi)
void setEventInfo(EventInfoPtr pevi)
void setInt(Name name, int val)
Definition: DataMap.h:131
std::unique_ptr< T > getPrivate(std::string name)
void line(double t, double *p, double &x, double &y, double &z)
static DuneToolManager * instance(std::string fclname="", int dbg=1)
QTextStream & endl(QTextStream &s)
int main(int argc, char *argv[])