Typedefs | Functions
test_ProtoDuneChannelGroups.cxx File Reference
#include <string>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include "dunecore/ArtSupport/DuneToolManager.h"
#include "dunecore/DuneInterface/Tool/IndexRangeGroupTool.h"
#include "TH1F.h"
#include <cassert>

Go to the source code of this file.

Typedefs

using Index = unsigned int
 
using IndexVector = std::vector< Index >
 
using Name = std::string
 

Functions

int test_ProtoDuneChannelGroups (bool useExistingFcl=false, int show=1)
 
int main (int argc, char *argv[])
 

Typedef Documentation

using Index = unsigned int

Definition at line 30 of file test_ProtoDuneChannelGroups.cxx.

Definition at line 31 of file test_ProtoDuneChannelGroups.cxx.

using Name = std::string

Definition at line 32 of file test_ProtoDuneChannelGroups.cxx.

Function Documentation

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

Definition at line 171 of file test_ProtoDuneChannelGroups.cxx.

171  {
172  bool useExistingFcl = false;
173  int show = 1;
174  if ( argc > 1 ) {
175  string sarg(argv[1]);
176  if ( sarg == "-h" ) {
177  cout << "Usage: " << argv[0] << " [keepFCL] [SHOW]" << endl;
178  cout << " If keepFCL = true, existing FCL file is used." << endl;
179  cout << " SHOW > 1 also shows the 480 FEMB blocks." << endl;
180  return 0;
181  }
182  useExistingFcl = sarg == "true" || sarg == "1";
183  }
184  if ( argc > 2 ) {
185  string sarg(argv[2]);
186  show = std::stoi(sarg);
187  }
188  return test_ProtoDuneChannelGroups(useExistingFcl, show);
189 }
int test_ProtoDuneChannelGroups(bool useExistingFcl=false, int show=1)
QTextStream & endl(QTextStream &s)
int test_ProtoDuneChannelGroups ( bool  useExistingFcl = false,
int  show = 1 
)

Definition at line 36 of file test_ProtoDuneChannelGroups.cxx.

36  {
37  const string myname = "test_ProtoDuneChannelGroups: ";
38 #ifdef NDEBUG
39  cout << myname << "NDEBUG must be off." << endl;
40  abort();
41 #endif
42  string line = "-----------------------------";
43 
44  cout << myname << line << endl;
45  string fclfile = "test_ProtoDuneChannelGroups.fcl";
46  if ( ! useExistingFcl ) {
47  cout << myname << "Creating top-level FCL." << endl;
48  ofstream fout(fclfile.c_str());
49  fout << "tools: {" << endl;
50  fout << " crtool: {" << endl;
51  fout << " tool_type: ProtoDuneChannelRanges" << endl;
52  fout << " LogLevel: 2" << endl;
53  fout << " ExtraRanges: \"\"" << endl;
54  fout << " }" << endl;
55  fout << " mytool: {" << endl;
56  fout << " tool_type: ProtoDuneChannelGroups" << endl;
57  fout << " LogLevel: 2" << endl;
58  fout << " IndexRangeTool: crtool" << endl;
59  fout << " }" << endl;
60  fout << "}" << endl;
61  fout.close();
62  } else {
63  cout << myname << "Using existing top-level FCL." << endl;
64  }
65 
66  cout << myname << line << endl;
67  cout << myname << "Fetching tool manager." << endl;
69  assert ( ptm != nullptr );
70  DuneToolManager& tm = *ptm;
71  tm.print();
72  assert( tm.toolNames().size() >= 1 );
73 
74  cout << myname << line << endl;
75  cout << myname << "Fetching tool." << endl;
76  auto pcgt = tm.getPrivate<IndexRangeGroupTool>("mytool");
77  assert( pcgt != nullptr );
78 
79  cout << myname << line << endl;
80  cout << myname << "Fetch invalid." << endl;
81  IndexRangeGroup chg = pcgt->get("bad");
82  cout << chg << endl;
83  assert( ! chg.isValid() );
84 
85  vector<string> expApas = {"apa1", "apa2", "apa3", "apa4", "apa5", "apa6"};
86  vector<string> expTpss = {"tps0", "tps1", "tps2", "tps3", "tps4", "tps5"};
87 
88  cout << myname << line << endl;
89  cout << myname << "Check apas." << endl;
90  chg = pcgt->get("apas");
91  cout << myname << chg << endl;
92  assert( chg.isValid() );
93  assert( chg.name == "apas" );
94  Index nran = chg.ranges.size();
95  assert( nran == expApas.size() );
96  for ( Index iran=0; iran<nran; ++iran ) {
97  IndexRange ran = chg.range(iran);
98  cout << myname << setw(5) << iran << ": " << ran << endl;
99  assert( ran.name == expApas[iran] );
100  }
101 
102  cout << myname << line << endl;
103  cout << myname << "Check tpss." << endl;
104  chg = pcgt->get("tpss");
105  cout << myname << chg << endl;
106  assert( chg.isValid() );
107  assert( chg.name == "tpss" );
108  nran = chg.ranges.size();
109  assert( nran == expTpss.size() );
110  for ( Index iran=0; iran<nran; ++iran ) {
111  IndexRange ran = chg.range(iran);
112  cout << myname << setw(5) << iran << ": " << ran << endl;
113  assert( ran.name == expTpss[iran] );
114  }
115 
116  // Check plane groups: tpszs, apaus, ...
117  for ( Name sapt : {"apa", "tps"} ) {
118  Name rbas = sapt;
119  if ( sapt == "tps" ) rbas = "tpp";
120  for ( Name sori : {"z", "c", "u", "v"} ) {
121  vector<string> rnams;
122  if ( sapt == "apa" ) {
123  for ( Name sapa : { "1", "2", "3", "4", "5", "6" } ) rnams.push_back(rbas + sapa + sori);
124  } else {
125  for ( Name stps : { "0", "1", "2", "3", "4", "5" } ) rnams.push_back(rbas + stps + sori);
126  }
127  Name gnam = rbas + sori + "s";
128  cout << myname << line << endl;
129  cout << myname << "Check " << gnam << "." << endl;
130  chg = pcgt->get(gnam);
131  cout << myname << chg << endl;
132  assert( chg.isValid() );
133  assert( chg.name == gnam );
134  Index nran = chg.ranges.size();
135  assert( nran == rnams.size() );
136  for ( Index iran=0; iran<nran; ++iran ) {
137  IndexRange ran = chg.range(iran);
138  cout << myname << setw(5) << iran << ": " << ran << endl;
139  assert( ran.name == rnams[iran] );
140  }
141  }
142  }
143 
144  // Check FEMBs.
145  cout << myname << "Checking FEMBs" << endl;
146  for ( Name sapa : { "1", "2", "3", "4", "5", "6" } ) {
147  for ( Name sfmb : { "01", "02", "03", "04", "05", "06", "07", "08", "09", "10",
148  "11", "12", "13", "14", "15", "16", "17", "18", "19", "20" } ) {
149  Name gnam = "femb" + sapa + sfmb;
150  chg = pcgt->get(gnam);
151  assert( chg.isValid() );
152  assert( chg.name == gnam );
153  Index nran = chg.ranges.size();
154  assert( nran == 3 );
155  cout << myname << " " << gnam << ": ";
156  for ( Index iran=0; iran<nran; ++iran ) {
157  if ( iran ) cout << ",";
158  cout << " " << chg.ranges[iran].name;
159  }
160  cout << endl;
161  }
162  }
163 
164  cout << myname << line << endl;
165  cout << myname << "Done." << endl;
166  return 0;
167 }
const std::vector< std::string > & toolNames() const
ChannelGroupService::Name Name
void print() const
unsigned int Index
IndexRange range(Index iran) const
tm
Definition: demo.py:21
Name name
Definition: IndexRange.h:32
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
std::unique_ptr< T > getPrivate(std::string name)
RangeVector ranges
void line(double t, double *p, double &x, double &y, double &z)
bool isValid() const
static DuneToolManager * instance(std::string fclname="", int dbg=1)
QTextStream & endl(QTextStream &s)