Typedefs | Functions
test_VDColdboxOnlineChannel.cxx File Reference
#include <string>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include "art/Framework/Services/Registry/ServiceHandle.h"
#include "dunecore/ArtSupport/DuneToolManager.h"
#include "dunecore/DuneInterface/Tool/IndexMapTool.h"
#include "dunecore/ArtSupport/ArtServiceHelper.h"
#include "TH1F.h"
#include <cassert>

Go to the source code of this file.

Typedefs

using Index = IndexMapTool::Index
 
using IndexVector = std::vector< Index >
 

Functions

string sonline (Index ichaOn)
 
int test_VDColdboxOnlineChannel (bool useExistingFcl=false, Index nshow=64)
 
int main (int argc, char *argv[])
 

Typedef Documentation

Definition at line 30 of file test_VDColdboxOnlineChannel.cxx.

Definition at line 31 of file test_VDColdboxOnlineChannel.cxx.

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 154 of file test_VDColdboxOnlineChannel.cxx.

154  {
155  bool useExistingFcl = false;
156  Index nshow = 1; // Every nshow'th value is displayed in log.
157  if ( argc > 1 ) {
158  string sarg(argv[1]);
159  if ( sarg == "-h" ) {
160  cout << "Usage: " << argv[0] << " [keepFCL] [NSHOW]" << endl;
161  cout << " keepFCL [false]: If true, existing FCL file is used." << endl;
162  cout << " NSHOW [64]: Every nshow'th channels will be displayed in log." << endl;
163  return 0;
164  }
165  useExistingFcl = sarg == "true" || sarg == "1";
166  }
167  if ( argc > 2 ) {
168  string sarg(argv[2]);
169  nshow = std::stoi(sarg);
170  }
171  return test_VDColdboxOnlineChannel(useExistingFcl, nshow);
172 }
unsigned int Index
QTextStream & endl(QTextStream &s)
int test_VDColdboxOnlineChannel(bool useExistingFcl=false, Index nshow=64)
string sonline ( Index  ichaOn)

Definition at line 33 of file test_VDColdboxOnlineChannel.cxx.

33  {
34  ostringstream ssout;
35  Index irem = ichaOn;
36  Index ifmb = irem/128;
37  irem = irem%128;
38  Index iasc = irem/16 + 1;
39  Index iach = irem%16;
40  ssout << (ifmb<10 ? "0" : "") << ifmb << "-" << iasc << "-" << (iach<10 ? "0" : "") << iach;
41  return ssout.str();
42 }
unsigned int Index
int test_VDColdboxOnlineChannel ( bool  useExistingFcl = false,
Index  nshow = 64 
)

Definition at line 46 of file test_VDColdboxOnlineChannel.cxx.

46  {
47  const string myname = "test_VDColdboxOnlineChannel: ";
48 #ifdef NDEBUG
49  cout << myname << "NDEBUG must be off." << endl;
50  abort();
51 #endif
52  string line = "-----------------------------";
53 
54  cout << myname << line << endl;
55  string fclfile = "test_VDColdboxOnlineChannel.fcl";
56  if (useExistingFcl) {
57  cout << myname << "Using existing top-level FCL." << endl;
58  } else {
59  cout << myname << "Creating top-level FCL." << endl;
60  ofstream fout(fclfile.c_str());
61  fout << "#include \"VDColdboxChannelMapService.fcl\"" << endl;
62  fout << "services: { VDColdboxChannelMapService: @local::vdcoldboxchannelmap }" << endl;
63  fout << "tools: {" << endl;
64  fout << " mytool: {" << endl;
65  fout << " tool_type: VDColdboxOnlineChannel" << endl;
66  fout << " LogLevel: 1" << endl;
67  fout << " }" << endl;
68  fout << "}" << endl;
69  fout.close();
70  }
71 
72  cout << myname << line << endl;
73  cout << myname << "Fetching tool manager." << endl;
75  assert ( ptm != nullptr );
76  DuneToolManager& tm = *ptm;
77  tm.print();
78  assert( tm.toolNames().size() == 1 );
79 
80  std::ifstream config{fclfile};
82 
83  cout << myname << line << endl;
84  cout << myname << "Fetching tool." << endl;
85  auto cma = tm.getPrivate<IndexMapTool>("mytool");
86  assert( cma != nullptr );
87 
89 
90  cout << myname << line << endl;
91  cout << myname << "Check some good values." << endl;
92  for ( Index ichaOff : { 1600, 1700, 3199, 3200, 3391 } ) {
93  Index ichaOn = cma->get(ichaOff);
94  cout << myname << setw(5) << ichaOff << " --> " << setw(5) << ichaOn << endl;
95  assert( ichaOff != badIndex );
96  }
97 
98  cout << myname << line << endl;
99  cout << myname << "Check some bad values." << endl;
100  for ( Index ichaOff : { -1, 0, 100, 1599, 3392, 4000 } ) {
101  Index ichaOn = cma->get(ichaOff);
102  cout << myname << ichaOff << " --> " << ichaOn << endl;
103  assert( ichaOn == badIndex );
104  }
105 
106  cout << myname << line << endl;
107  cout << myname << "Check each online index appears exactly once." << endl;
108  const Index nchaOn = 14*128;
109  const Index ichaOn1 = 128;
110  const Index ichaOn2 = ichaOn1 + nchaOn;
111  const Index ichaOff1 = 1600;
112  const Index ichaOff2 = ichaOff1 + nchaOn;
113  IndexVector offlineChannel(ichaOn2, badIndex);
114  IndexVector onlineCounts(ichaOn2, 0);
115  Index ndup = 0;
116  for ( Index ichaOff=ichaOff1; ichaOff<ichaOff2; ++ichaOff ) {
117  Index ichaOn = cma->get(ichaOff);
118  if ( nshow*(ichaOff/nshow) == ichaOff ) {
119  cout << myname << " " << setw(4) << ichaOff << " --> " << setw(4) << ichaOn
120  << " (" << sonline(ichaOn) << ")" << endl;
121  }
122  assert( ichaOn >= ichaOn1 );
123  assert( ichaOn < ichaOn2 );
124  if ( offlineChannel[ichaOn] != badIndex ) {
125  cout << myname << "ERROR: Online channel " << setw(4) << ichaOn
126  << " (" << sonline(ichaOn) << ")"
127  << " is mapped to two offline channels: "
128  << offlineChannel[ichaOn]
129  << " " << ichaOff << endl;
130  ++ndup;
131  }
132  onlineCounts[ichaOn] += 1;
133  offlineChannel[ichaOn] = ichaOff;
134  }
135  Index nbadOn = 0;
136  Index nbadOff = 0;
137  for ( Index ichaOn=ichaOn1; ichaOn<ichaOn2; ++ichaOn ) {
138  if ( onlineCounts[ichaOn] != 1 ) {
139  cout << "ERROR: Map count for online channel " << ichaOn << " is " << onlineCounts[ichaOn] << endl;;
140  ++nbadOn;
141  } else if ( offlineChannel[ichaOn] == badIndex ) {
142  cout << "ERROR: Online channel " << ichaOn << " is not mapped." << endl;
143  }
144  }
145  assert( ndup + nbadOn + nbadOff == 0 );
146 
147  cout << myname << line << endl;
148  cout << myname << "Done." << endl;
149  return 0;
150 }
std::vector< Index > IndexVector
Index badIndex
const std::vector< std::string > & toolNames() const
string sonline(Index ichaOn)
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
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
std::unique_ptr< T > getPrivate(std::string name)
static Index badIndex()
Definition: IndexMapTool.h:18
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)