test_BlockIndexMapTool.cxx
Go to the documentation of this file.
1 // test_BlockIndexMapTool.cxx
2 //
3 // David Adams
4 // April 2020
5 //
6 // Test BlockIndexMapTool.
7 
10 #include "TH1F.h"
11 #include <string>
12 #include <iostream>
13 #include <fstream>
14 #include <sstream>
15 #include <iomanip>
16 
17 #undef NDEBUG
18 #include <cassert>
19 
20 using std::string;
21 using std::cout;
22 using std::endl;
23 using std::ofstream;
24 using std::istringstream;
25 using std::setw;
26 using std::map;
28 using Index = unsigned int;
29 
30 //**********************************************************************
31 
32 int test_BlockIndexMapTool(bool useExistingFcl =false) {
33  const string myname = "test_BlockIndexMapTool: ";
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_BlockIndexMapTool.fcl";
42  if ( ! useExistingFcl ) {
43  cout << myname << "Creating top-level FCL." << endl;
44  ofstream fout(fclfile.c_str());
45  fout << "tools: {" << endl;
46  fout << " mytool: {" << endl;
47  fout << " tool_type: BlockIndexMapTool" << endl;
48  fout << " LogLevel: 1" << endl;
49  fout << " Starts: [20, 10, 30]" << endl;
50  fout << " Values: [ 2, 1, 3]" << endl;
51  fout << " Period: 100" << endl;
52  fout << " }" << endl;
53  fout << "}" << endl;
54  fout.close();
55  } else {
56  cout << myname << "Using existing top-level FCL." << endl;
57  }
58 
59  cout << myname << line << endl;
60  cout << myname << "Fetching tool manager." << endl;
62  assert ( ptm != nullptr );
63  DuneToolManager& tm = *ptm;
64  tm.print();
65  assert( tm.toolNames().size() >= 1 );
66 
67  cout << myname << line << endl;
68  cout << myname << "Fetching tool." << endl;
69  auto ptoo = tm.getPrivate<IndexMapTool>("mytool");
70  assert( ptoo != nullptr );
71 
72  cout << myname << line << endl;
73  map<Index, Index> chk;
74  for ( Index idx= 0; idx< 10; ++idx ) chk[idx] = 0;
75  for ( Index idx= 10; idx< 20; ++idx ) chk[idx] = 1;
76  for ( Index idx= 20; idx< 30; ++idx ) chk[idx] = 2;
77  for ( Index idx= 30; idx<100; ++idx ) chk[idx] = 3;
78  for ( Index idx=100; idx<110; ++idx ) chk[idx] = 0;
79  for ( Index idx=110; idx<120; ++idx ) chk[idx] = 1;
80  for ( Index idx=120; idx<130; ++idx ) chk[idx] = 2;
81  for ( Index idx=130; idx<200; ++idx ) chk[idx] = 3;
82  for ( auto kchk : chk ) {
83  Index idx = kchk.first;
84  Index chkval = kchk.second;
85  Index val = ptoo->get(idx);
86  cout << myname << setw(10) << idx << ": " << setw(5) << val << endl;
87  assert( val == chkval );
88  }
89 
90  cout << myname << line << endl;
91  cout << myname << "Done." << endl;
92  return 0;
93 }
94 
95 //**********************************************************************
96 
97 int main(int argc, char* argv[]) {
98  bool useExistingFcl = false;
99  if ( argc > 1 ) {
100  string sarg(argv[1]);
101  if ( sarg == "-h" ) {
102  cout << "Usage: " << argv[0] << " [keepFCL]" << endl;
103  cout << " If keepFCL = true, existing FCL file is used." << endl;
104  return 0;
105  }
106  useExistingFcl = sarg == "true" || sarg == "1";
107  }
108  return test_BlockIndexMapTool(useExistingFcl);
109 }
110 
111 //**********************************************************************
const std::vector< std::string > & toolNames() const
std::string string
Definition: nybbler.cc:12
void print() const
unsigned int Index
tm
Definition: demo.py:21
int main(int argc, char *argv[])
int test_BlockIndexMapTool(bool useExistingFcl=false)
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
std::unique_ptr< T > getPrivate(std::string name)
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)