Typedefs | Functions
test_ProtoduneOnlineChannel.cxx File Reference
#include <string>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include "dunecore/ArtSupport/DuneToolManager.h"
#include "dunecore/DuneInterface/Tool/IndexMapTool.h"
#include "duneprototypes/Protodune/singlephase/Utility/ProtoduneChannelHelper.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

int test_ProtoduneOnlineChannel (bool useExistingFcl=false, Index nshow=64)
 
int main (int argc, char *argv[])
 

Typedef Documentation

Definition at line 28 of file test_ProtoduneOnlineChannel.cxx.

Definition at line 29 of file test_ProtoduneOnlineChannel.cxx.

Function Documentation

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

Definition at line 135 of file test_ProtoduneOnlineChannel.cxx.

135  {
136  bool useExistingFcl = false;
137  Index nshow = 64;
138  if ( argc > 1 ) {
139  string sarg(argv[1]);
140  if ( sarg == "-h" ) {
141  cout << "Usage: " << argv[0] << " [keepFCL] [NSHOW]" << endl;
142  cout << " keepFCL [false]: If true, existing FCL file is used." << endl;
143  cout << " NSHOW [64]: Every nshow'th channels will be displayed in log." << endl;
144  return 0;
145  }
146  useExistingFcl = sarg == "true" || sarg == "1";
147  }
148  if ( argc > 2 ) {
149  string sarg(argv[2]);
150  nshow = std::stoi(sarg);
151  }
152  return test_ProtoduneOnlineChannel(useExistingFcl, nshow);
153 }
int test_ProtoduneOnlineChannel(bool useExistingFcl=false, Index nshow=64)
unsigned int Index
QTextStream & endl(QTextStream &s)
int test_ProtoduneOnlineChannel ( bool  useExistingFcl = false,
Index  nshow = 64 
)

Definition at line 33 of file test_ProtoduneOnlineChannel.cxx.

33  {
34  const string myname = "test_ProtoduneOnlineChannel: ";
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_ProtoduneOnlineChannel.fcl";
43  if ( ! useExistingFcl ) {
44  cout << myname << "Creating top-level FCL." << endl;
45  ofstream fout(fclfile.c_str());
46  fout << "tools: {" << endl;
47  fout << " mytool: {" << endl;
48  fout << " tool_type: ProtoduneOnlineChannel" << endl;
49  fout << " }" << endl;
50  fout << "}" << endl;
51  fout.close();
52  } else {
53  cout << myname << "Using existing top-level FCL." << endl;
54  }
55 
56  cout << myname << line << endl;
57  cout << myname << "Fetching tool manager." << endl;
59  assert ( ptm != nullptr );
60  DuneToolManager& tm = *ptm;
61  tm.print();
62  assert( tm.toolNames().size() >= 1 );
63 
64  cout << myname << line << endl;
65  cout << myname << "Fetching tool." << endl;
66  auto cma = tm.getPrivate<IndexMapTool>("mytool");
67  assert( cma != nullptr );
68 
70 
71  cout << myname << line << endl;
72  cout << myname << "Check some good values." << endl;
73  for ( Index ichaOff : { 0, 102, 1234, 1407, 3967, 15359 } ) {
74  Index ichaOn = cma->get(ichaOff);
75  cout << myname << ichaOff << " --> " << ichaOn << endl;
76  assert( ichaOff != badIndex );
77  }
78 
79  cout << myname << line << endl;
80  cout << myname << "Check some bad values." << endl;
81  for ( Index ichaOff : { -1, 15360, 20000 } ) {
82  Index ichaOn = cma->get(ichaOff);
83  cout << myname << ichaOff << " --> " << ichaOn << endl;
84  assert( ichaOn == badIndex );
85  }
86 
87  cout << myname << line << endl;
88  cout << myname << "Check each online index appears exactly once." << endl;
89  const Index ncha = 15360;
90  IndexVector onlineCounts(ncha);
91  IndexVector offlineChannel(ncha, badIndex);
92  ProtoduneChannelHelper chh(false);
93  for ( Index ichaOff=0; ichaOff<ncha; ++ichaOff ) {
94  Index ichaOn = cma->get(ichaOff);
95  Index irem = ichaOn;
96  Index itps = irem/2560;
97  irem = irem%2560;
98  Index ifmb = irem/128 + 1;
99  irem = irem%128;
100  Index iasc = irem/16 + 1;
101  Index iach = irem%16;
102  if ( nshow*(ichaOff/nshow) == ichaOff || ichaOn >= ncha ) {
103  cout << myname << " " << setw(4) << ichaOff << " --> " << setw(4) << ichaOn
104  << " (" << itps << ", " << setw(2) << ifmb << ", "
105  << iasc << ", " << setw(2) << iach << ")" << endl;
106  }
107  assert( itps == chh.tpcSet(ichaOn) );
108  assert( ifmb == chh.femb(ichaOn) );
109  assert( iasc == chh.asic(ichaOn) );
110  assert( iach == chh.asicChannel(ichaOn) );
111  assert( ichaOn < ncha );
112  if ( offlineChannel[ichaOn] != badIndex ) {
113  cout << myname << "ERROR: Online channel " << ichaOn
114  << " is mapped to two offline channels:" << endl;
115  cout << " " << offlineChannel[ichaOn] << endl;
116  cout << " " << ichaOff << endl;
117  assert( false );
118  }
119  assert( onlineCounts[ichaOn] == 0 );
120  onlineCounts[ichaOn] += 1;
121  offlineChannel[ichaOn] = ichaOff;
122  }
123  for ( Index ichaOn=0; ichaOn<ncha; ++ichaOn ) {
124  assert( onlineCounts[ichaOn] == 1 );
125  assert( offlineChannel[ichaOn] != badIndex );
126  }
127 
128  cout << myname << line << endl;
129  cout << myname << "Done." << endl;
130  return 0;
131 }
std::vector< Index > IndexVector
Index badIndex
const std::vector< std::string > & toolNames() const
void print() const
unsigned int Index
tm
Definition: demo.py:21
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)