test_AdcChannelSplitter.cxx
Go to the documentation of this file.
1 // test_AdcChannelSplitter.cxx
2 //
3 // David Adams
4 // September 2019
5 //
6 // Test AdcChannelSplitter.
7 
8 #include <string>
9 #include <iostream>
10 #include <fstream>
11 #include <sstream>
12 #include <vector>
15 #include <TRandom.h>
16 
17 #undef NDEBUG
18 #include <cassert>
19 
20 using std::string;
21 using std::cout;
22 using std::endl;
23 using std::ostringstream;
24 using std::ofstream;
26 using std::vector;
27 
28 using Name = string;
29 using Index = unsigned int;
30 
31 //**********************************************************************
32 
33 int test_AdcChannelSplitter(bool useExistingFcl =false) {
34  const string myname = "test_AdcChannelSplitter: ";
35 #ifdef NDEBUG
36  cout << myname << "NDEBUG must be off." << endl;
37  abort();
38 #endif
39  string line = "-----------------------------";
40 
41  cout << myname << line << endl;
42  string fclfile = "test_AdcChannelSplitter.fcl";
43  if ( ! useExistingFcl ) {
44  cout << myname << "Creating top-level FCL." << endl;
45  ofstream fout(fclfile.c_str());
46  fout << "#include \"dataprep_tools.fcl\"" << endl;
47  fout << "tools.mytool: {" << endl;
48  fout << " tool_type: AdcChannelSplitter" << endl;
49  fout << " LogLevel: 2" << endl;
50  fout << " Length: 8" << endl;
51  fout << " DataPath: \"\"" << endl;
52  fout << " DataView: split" << endl;
53  fout << "}" << endl;
54  fout << "tools.mytool2: @local::tools.mytool" << endl;
55  fout << "tools.mytool2.Length: 3 " << endl;
56  fout << "tools.mytool2.DataPath: \"split\"" << endl;
57  fout << "tools.mytool2.DataView: \"split2\"" << endl;
58  fout << "" << endl;
59  fout.close();
60  } else {
61  cout << myname << "Using existing top-level FCL." << endl;
62  }
63 
64  cout << myname << line << endl;
65  cout << myname << "Fetching tool manager." << endl;
67  assert ( ptm != nullptr );
68  DuneToolManager& tm = *ptm;
69  tm.print();
70  assert( tm.toolNames().size() >= 1 );
71 
72  cout << myname << line << endl;
73  cout << myname << "Fetching tools." << endl;
74  auto ptoo = tm.getPrivate<TpcDataTool>("mytool");
75  auto ptoo2 = tm.getPrivate<TpcDataTool>("mytool2");
76  assert(ptoo);
77  assert(ptoo2);
78 
79  cout << myname << line << endl;
80  cout << myname << "Create data." << endl;
81  AdcChannelData acd;
82  acd.setChannelInfo(100123);
83  acd.setEventInfo(123, 2468, 45);
84  acd.sampleUnit = "fC";
85  acd.raw.resize(20);
86  acd.samples.resize(20);
87  for ( Index isam=0; isam<acd.samples.size(); ++isam ) {
88  acd.raw[isam] = 10 + isam;
89  acd.samples[isam] = 100 + isam;
90  }
91  assert( acd.samples.size() == 20 );
92 
93  cout << myname << line << endl;
94  cout << myname << "Split the top data." << endl;
95  DataMap dmv = ptoo->update(acd);
96  dmv.print();
97  assert( dmv == 0 );
98  assert( dmv.getInt("splitInputCount") == 1 );
99  assert( dmv.getInt("splitOutputCount") == 2);
100  assert( dmv.getInt("splitRawCopyCount") == 16);
101  assert( dmv.getInt("splitSampleCopyCount") == 16);
102  cout << myname << "Data view names:";
103  for ( Name vnam : acd.viewNames() ) cout << " " << vnam;
104  cout << endl;
105  assert( acd.viewSize("split") == 2 );
106  assert( acd.viewSize("split2") == 0 );
107  for ( Name vnam : acd.viewNames() ) {
108  for ( const AdcChannelData& acv : acd.view(vnam) ) {
109  assert( acv.viewParent != nullptr );
110  assert( acv.viewParent == &acd );
111  }
112  }
113 
114  cout << myname << line << endl;
115  cout << myname << "Split the split." << endl;
116  dmv = ptoo2->update(acd);
117  dmv.print();
118  assert( dmv == 0 );
119  assert( dmv.getInt("splitInputCount") == 2 );
120  assert( dmv.getInt("splitOutputCount") == 4);
121  assert( dmv.getInt("splitRawCopyCount") == 12);
122  assert( dmv.getInt("splitSampleCopyCount") == 12);
123  assert( acd.viewSize("split") == 2 );
124  assert( acd.viewSize("split/split") == 0 );
125  assert( acd.viewSize("split/split2") == 4 );
126 
127  cout << myname << line << endl;
128  cout << myname << "Done." << endl;
129  return 0;
130 }
131 
132 //**********************************************************************
133 
134 int main(int argc, char* argv[]) {
135  bool useExistingFcl = false;
136  if ( argc > 1 ) {
137  string sarg(argv[1]);
138  if ( sarg == "-h" ) {
139  cout << "Usage: " << argv[0] << " [ARG]" << endl;
140  cout << " If ARG = true, existing FCL file is used." << endl;
141  return 0;
142  }
143  useExistingFcl = sarg == "true" || sarg == "1";
144  }
145  return test_AdcChannelSplitter(useExistingFcl);
146 }
147 
148 //**********************************************************************
const std::vector< std::string > & toolNames() const
std::string string
Definition: nybbler.cc:12
struct vector vector
ChannelGroupService::Name Name
void print() const
unsigned int Index
int main(int argc, char *argv[])
void print(std::ostream *pout) const
Definition: DataMap.h:245
tm
Definition: demo.py:21
virtual DataMap update(AdcChannelData &) const
void setChannelInfo(ChannelInfoPtr pchi)
int test_AdcChannelSplitter(bool useExistingFcl=false)
NameVector viewNames() const
void setEventInfo(EventInfoPtr pevi)
AdcCountVector raw
const View & view(Name vnam) const
std::unique_ptr< T > getPrivate(std::string name)
int getInt(Name name, int def=0) const
Definition: DataMap.h:218
void line(double t, double *p, double &x, double &y, double &z)
size_t viewSize() const
static DuneToolManager * instance(std::string fclname="", int dbg=1)
AdcSignalVector samples
QTextStream & endl(QTextStream &s)