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

Go to the source code of this file.

Typedefs

using Index = unsigned int
 

Functions

int test_BlockIndexMapTool (bool useExistingFcl=false)
 
int main (int argc, char *argv[])
 

Typedef Documentation

using Index = unsigned int

Definition at line 28 of file test_BlockIndexMapTool.cxx.

Function Documentation

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

Definition at line 97 of file test_BlockIndexMapTool.cxx.

97  {
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 }
int test_BlockIndexMapTool(bool useExistingFcl=false)
QTextStream & endl(QTextStream &s)
int test_BlockIndexMapTool ( bool  useExistingFcl = false)

Definition at line 32 of file test_BlockIndexMapTool.cxx.

32  {
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 }
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)
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)