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

Go to the source code of this file.

Typedefs

using Index = unsigned int
 

Functions

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

Typedef Documentation

using Index = unsigned int

Definition at line 27 of file test_FclFileFloatArray.cxx.

Function Documentation

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

Definition at line 120 of file test_FclFileFloatArray.cxx.

120  {
121  bool useExistingFcl = false;
122  if ( argc > 1 ) {
123  string sarg(argv[1]);
124  if ( sarg == "-h" ) {
125  cout << "Usage: " << argv[0] << " [keepFCL] [RUN]" << endl;
126  cout << " If keepFCL = true, existing FCL file is used." << endl;
127  return 0;
128  }
129  useExistingFcl = sarg == "true" || sarg == "1";
130  }
131  return test_FclFileFloatArray(useExistingFcl);
132 }
int test_FclFileFloatArray(bool useExistingFcl=false)
QTextStream & endl(QTextStream &s)
int test_FclFileFloatArray ( bool  useExistingFcl = false)

Definition at line 31 of file test_FclFileFloatArray.cxx.

31  {
32  const string myname = "test_FclFileFloatArray: ";
33 #ifdef NDEBUG
34  cout << myname << "NDEBUG must be off." << endl;
35  abort();
36 #endif
37  string line = "-----------------------------";
38 
39  cout << myname << line << endl;
40  if ( ! useExistingFcl ) {
41  cout << myname << "Creating float array FCL." << endl;
42  {
43  ofstream fout("test_FclFileFloatArray_arr1.fcl");
44  fout << " tool_type: FclFloatArray" << endl;
45  fout << " LogLevel: 2" << endl;
46  fout << " DefaultValue: -1" << endl;
47  fout << " Offset: 10" << endl;
48  fout << " Label: arr1" << endl;
49  fout << " Unit: cm" << endl;
50  fout << " Values: [ 110, 111, 112, 113, 114, 115, 116, 117, 118, 119 ]" << endl;
51  fout.close();
52  }
53  {
54  ofstream fout("test_FclFileFloatArray_arr3.fcl");
55  fout << " tool_type: FclFloatArray" << endl;
56  fout << " LogLevel: 2" << endl;
57  fout << " DefaultValue: -1" << endl;
58  fout << " Offset: 30" << endl;
59  fout << " Label: arr3" << endl;
60  fout << " Unit: cm" << endl;
61  fout << " Values: [ 130, 131, 132, 133, 134, 135, 136, 137, 138, 139 ]" << endl;
62  fout.close();
63  }
64  }
65  string fclfile = "test_FclFileFloatArray.fcl";
66  if ( ! useExistingFcl ) {
67  cout << myname << "Creating top-level FCL." << endl;
68  ofstream fout(fclfile.c_str());
69  fout << "tools: {" << endl;
70  fout << " mytool: {" << endl;
71  fout << " tool_type: FclFileFloatArray" << endl;
72  fout << " LogLevel: 3" << endl;
73  fout << " FileNames: [\"test_FclFileFloatArray_arr1.fcl\", \"test_FclFileFloatArray_arr3.fcl\"]" << endl;
74  fout << " DefaultValue: 999" << endl;
75  fout << " }" << endl;
76  fout << "}" << endl;
77  fout.close();
78  } else {
79  cout << myname << "Using existing top-level FCL." << endl;
80  }
81 
82  cout << myname << line << endl;
83  cout << myname << "Fetching tool manager." << endl;
85  assert ( ptm != nullptr );
86  DuneToolManager& tm = *ptm;
87  tm.print();
88  assert( tm.toolNames().size() >= 1 );
89 
90  cout << myname << line << endl;
91  cout << myname << "Fetching tool." << endl;
92  auto ptoo = tm.getPrivate<FloatArrayTool>("mytool");
93  assert( ptoo != nullptr );
94 
95  cout << myname << line << endl;
96  cout << "size = " << ptoo->size() << endl;
97  assert( ptoo->size() == 40 );
98 
99  cout << myname << line << endl;
100  cout << "Unit = " << ptoo->unit() << endl;
101  assert( ptoo->unit() == "cm" );
102 
103  cout << myname << line << endl;
104  cout << myname << "Check values." << endl;
105  FloatArrayTool::FloatVector exp(40, 999);
106  for ( int ival=10; ival<20; ++ival ) exp[ival] = 100 + ival;
107  for ( int ival=30; ival<40; ++ival ) exp[ival] = 100 + ival;
108  for ( Index ival=0; ival<ptoo->size(); ++ival ) {
109  cout << setw(4) << ival << ": " << ptoo->value(ival) << endl;
110  assert( fabs(ptoo->value(ival) - exp[ival]) < 1.e-6 );
111  }
112 
113  cout << myname << line << endl;
114  cout << myname << "Done." << endl;
115  return 0;
116 }
const std::vector< std::string > & toolNames() const
void print() const
unsigned int Index
tm
Definition: demo.py:21
const double e
std::vector< float > FloatVector
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)