test_IcebergOnlineChannel.cxx
Go to the documentation of this file.
1 // test_IcebergOnlineChannel.cxx
2 //
3 // David Adams
4 // May 2018
5 //
6 // Test IcebergOnlineChannel.
7 
8 #include <string>
9 #include <iostream>
10 #include <fstream>
11 #include <sstream>
16 #include "TH1F.h"
17 
18 #undef NDEBUG
19 #include <cassert>
20 
21 using std::string;
22 using std::cout;
23 using std::endl;
24 using std::ofstream;
25 using std::istringstream;
28 using IndexVector = std::vector<Index>;
29 
30 //**********************************************************************
31 
32 int test_IcebergOnlineChannel(bool useExistingFcl =false) {
33  const string myname = "test_IcebergOnlineChannel: ";
34 #ifdef NDEBUG
35  cout << myname << "NDEBUG must be off." << endl;
36  abort();
37 #endif
38  string line = "-----------------------------";
39 
40  cout << myname << line << endl;
41  string fclfile = "test_IcebergOnlineChannel.fcl";
42  if (useExistingFcl) {
43  cout << myname << "Using existing top-level FCL." << endl;
44  } else {
45  cout << myname << "Creating top-level FCL." << endl;
46  ofstream fout(fclfile.c_str());
47  fout << "#include \"IcebergChannelMapService.fcl\"" << endl;
48  fout << "services: { IcebergChannelMapService: @local::icebergchannelmap }" << endl;
49  fout << "tools: {" << endl;
50  fout << " mytool: {" << endl;
51  fout << " tool_type: IcebergOnlineChannel" << endl;
52  fout << " LogLevel: 2" << endl;
53  fout << " Ordering: \"FEMB\"" << endl;
54  fout << " }" << endl;
55  fout << " reftool: {" << endl;
56  fout << " tool_type: ProtoduneOnlineChannel" << endl;
57  fout << " LogLevel: 1" << endl;
58  fout << " }" << endl;
59  fout << "}" << endl;
60  fout.close();
61  }
62 
63  cout << myname << line << endl;
64  cout << myname << "Fetching tool manager." << endl;
66  assert ( ptm != nullptr );
67  DuneToolManager& tm = *ptm;
68  tm.print();
69  assert( tm.toolNames().size() >= 1 );
70 
71  std::ifstream config{fclfile};
73 
74  cout << myname << line << endl;
75  cout << myname << "Fetching tool." << endl;
76  auto cma = tm.getPrivate<IndexMapTool>("mytool");
77  assert( cma != nullptr );
78 
80 
81  cout << myname << line << endl;
82  cout << myname << "Check some good values." << endl;
83  Index ichaOff = 0;
84  while ( ichaOff < 1240 ) {
85  Index ichaOn = cma->get(ichaOff);
86  cout << myname << ichaOff << " --> " << ichaOn << endl;
87  assert( ichaOff != badIndex );
88  ++ichaOff;
89  ichaOn = cma->get(ichaOff);
90  cout << myname << ichaOff << " --> " << ichaOn << endl;
91  assert( ichaOff != badIndex );
92  ichaOff += (ichaOff < 800 ? 40 : 48) - 1;
93  }
94 
95  cout << myname << line << endl;
96  cout << myname << "Check some bad values." << endl;
97  cout << myname << "Bad index: " << badIndex << endl;
98  for ( Index ichaOff : { -1, 1280, 20000 } ) {
99  Index ichaOn = cma->get(ichaOff);
100  cout << myname << ichaOff << " --> " << ichaOn << endl;
101  assert( ichaOn == badIndex );
102  }
103 
104  cout << myname << line << endl;
105  cout << myname << "Check each online index appears exactly once." << endl;
106  const Index ncha = 1280;
107  IndexVector onlineCounts(ncha);
108  IndexVector offlineChannel(ncha, badIndex);
109  Index nshow = 64;
110  for ( Index ichaOff=0; ichaOff<ncha; ++ichaOff ) {
111  Index ichaOn = cma->get(ichaOff);
112  if ( nshow*(ichaOff/nshow) == ichaOff || ichaOn >= ncha )
113  cout << myname << " " << ichaOff << " --> " << ichaOn << endl;
114  assert( ichaOn < ncha );
115  if ( offlineChannel[ichaOn] != badIndex ) {
116  cout << myname << "ERROR: Online channel " << ichaOn
117  << " is mapped to two offline channels:" << endl;
118  cout << " " << offlineChannel[ichaOn] << endl;
119  cout << " " << ichaOff << endl;
120  assert( false );
121  }
122  assert( onlineCounts[ichaOn] == 0 );
123  onlineCounts[ichaOn] += 1;
124  offlineChannel[ichaOn] = ichaOff;
125  }
126  for ( Index ichaOn=0; ichaOn<ncha; ++ichaOn ) {
127  assert( onlineCounts[ichaOn] == 1 );
128  assert( offlineChannel[ichaOn] != badIndex );
129  }
130 
131  cout << myname << line << endl;
132  cout << myname << "Done." << endl;
133  return 0;
134 }
135 
136 //**********************************************************************
137 
138 int main(int argc, char* argv[]) {
139  bool useExistingFcl = false;
140  if ( argc > 1 ) {
141  string sarg(argv[1]);
142  if ( sarg == "-h" ) {
143  cout << "Usage: " << argv[0] << " [keepFCL] [RUN]" << endl;
144  cout << " If keepFCL = true, existing FCL file is used." << endl;
145  cout << " If RUN is nonzero, the data for that run are displayed." << endl;
146  return 0;
147  }
148  useExistingFcl = sarg == "true" || sarg == "1";
149  }
150  return test_IcebergOnlineChannel(useExistingFcl);
151 }
152 
153 //**********************************************************************
std::vector< Index > IndexVector
Index badIndex
const std::vector< std::string > & toolNames() const
std::string string
Definition: nybbler.cc:12
int test_IcebergOnlineChannel(bool useExistingFcl=false)
void print() const
unsigned int Index
static void load_services(std::string const &config)
tm
Definition: demo.py:21
static Config * config
Definition: config.cpp:1054
std::unique_ptr< T > getPrivate(std::string name)
unsigned int Index
Definition: IndexMapTool.h:16
static Index badIndex()
Definition: IndexMapTool.h:18
void line(double t, double *p, double &x, double &y, double &z)
int main(int argc, char *argv[])
static DuneToolManager * instance(std::string fclname="", int dbg=1)
QTextStream & endl(QTextStream &s)