test_FclIndexVectorMapTool.cxx
Go to the documentation of this file.
1 // test_FclIndexVectorMapTool.cxx
2 //
3 // David Adams
4 // April 2017
5 //
6 // Test FclIndexVectorMapTool.
7 
8 #include <string>
9 #include <iostream>
10 #include <fstream>
11 #include <sstream>
14 #include "TH1F.h"
15 
16 #undef NDEBUG
17 #include <cassert>
18 
19 using std::string;
20 using std::cout;
21 using std::endl;
22 using std::ofstream;
23 using std::istringstream;
25 using Index = unsigned int;
26 using IndexVector = std::vector<Index>;
27 
28 //**********************************************************************
29 
30 int test_FclIndexVectorMapTool(bool useExistingFcl =false, Index runin =0) {
31  const string myname = "test_FclIndexVectorMapTool: ";
32 #ifdef NDEBUG
33  cout << myname << "NDEBUG must be off." << endl;
34  abort();
35 #endif
36  string line = "-----------------------------";
37 
38  cout << myname << line << endl;
39  string fclfile = "test_FclIndexVectorMapTool.fcl";
40  if ( ! useExistingFcl ) {
41  cout << myname << "Creating top-level FCL." << endl;
42  ofstream fout(fclfile.c_str());
43  if ( runin == 0 ) {
44  fout << "tools: {" << endl;
45  fout << " mytool: {" << endl;
46  fout << " tool_type: FclIndexVectorMapTool" << endl;
47  fout << " LogLevel: 3" << endl;
48  fout << " Entries: [ [100, 2, 3], [101, 12] ]" << endl;
49  fout << " }" << endl;
50  fout << "}" << endl;
51  }
52  fout.close();
53  } else {
54  cout << myname << "Using existing top-level FCL." << endl;
55  }
56 
57  cout << myname << line << endl;
58  cout << myname << "Fetching tool manager." << endl;
60  assert ( ptm != nullptr );
61  DuneToolManager& tm = *ptm;
62  tm.print();
63  assert( tm.toolNames().size() >= 1 );
64 
65  cout << myname << line << endl;
66  cout << myname << "Fetching tool." << endl;
67  auto pvm = ptm->getPrivate<IndexVectorMapTool>("mytool");
68  assert( pvm != nullptr );
69 
70  cout << myname << line << endl;
71  cout << myname << "Check get." << endl;
72  const IndexVector& vec0 = pvm->get(100);
73  assert( vec0.size() == 2 );
74  const IndexVector& vec1 = pvm->get(101);
75  assert( vec1.size() == 1 );
76  const IndexVector& vec2 = pvm->get(102);
77  assert( vec2.size() == 0 );
78 
79  cout << myname << line << endl;
80  cout << myname << "Check contains." << endl;
81  assert( pvm->contains(100, 2) );
82  assert( pvm->contains(100, 3) );
83  assert( ! pvm->contains(100, 4) );
84  assert( pvm->contains(101, 12) );
85  assert( ! pvm->contains(101, 4) );
86  assert( ! pvm->contains(102, 4) );
87 
88  cout << myname << line << endl;
89  cout << myname << "Done." << endl;
90  return 0;
91 }
92 
93 //**********************************************************************
94 
95 int main(int argc, char* argv[]) {
96  bool useExistingFcl = false;
97  Index run = 0;
98  if ( argc > 1 ) {
99  string sarg(argv[1]);
100  if ( sarg == "-h" ) {
101  cout << "Usage: " << argv[0] << " [keepFCL] [RUN]" << endl;
102  cout << " If keepFCL = true, existing FCL file is used." << endl;
103  cout << " If RUN is nonzero, the data for that run are displayed." << endl;
104  return 0;
105  }
106  useExistingFcl = sarg == "true" || sarg == "1";
107  }
108  if ( argc > 2 ) {
109  string sarg(argv[2]);
110  istringstream ssarg(argv[2]);
111  ssarg >> run;
112  }
113  return test_FclIndexVectorMapTool(useExistingFcl, run);
114 }
115 
116 //**********************************************************************
std::vector< Index > IndexVector
int test_FclIndexVectorMapTool(bool useExistingFcl=false, Index runin=0)
const std::vector< std::string > & toolNames() const
std::string string
Definition: nybbler.cc:12
virtual IndexVector get(Index idx) const =0
void print() const
unsigned int Index
tm
Definition: demo.py:21
int main(int argc, char *argv[])
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)