Typedefs | Functions
test_FclFloatArray.cxx File Reference
#include <string>
#include <iostream>
#include <fstream>
#include <sstream>
#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

bool isequal (float lhs, float rhs)
 
int test_FclFloatArray (bool useExistingFcl=false)
 
int main (int argc, char *argv[])
 

Typedef Documentation

using Index = unsigned int

Definition at line 25 of file test_FclFloatArray.cxx.

Function Documentation

bool isequal ( float  lhs,
float  rhs 
)

Definition at line 29 of file test_FclFloatArray.cxx.

29  {
30  string myname = "isequal: ";
31  if ( fabs(lhs - rhs) < 1.e-10 ) return true;
32  cout << myname << lhs << " != " << rhs << endl;
33  return false;
34 }
const double e
QTextStream & endl(QTextStream &s)
int main ( int  argc,
char *  argv[] 
)

Definition at line 112 of file test_FclFloatArray.cxx.

112  {
113  bool useExistingFcl = false;
114  if ( argc > 1 ) {
115  string sarg(argv[1]);
116  if ( sarg == "-h" ) {
117  cout << "Usage: " << argv[0] << " [keepFCL] [RUN]" << endl;
118  cout << " If keepFCL = true, existing FCL file is used." << endl;
119  cout << " If RUN is nonzero, the data for that run are displayed." << endl;
120  return 0;
121  }
122  useExistingFcl = sarg == "true" || sarg == "1";
123  }
124  return test_FclFloatArray(useExistingFcl);
125 }
int test_FclFloatArray(bool useExistingFcl=false)
QTextStream & endl(QTextStream &s)
int test_FclFloatArray ( bool  useExistingFcl = false)

Definition at line 36 of file test_FclFloatArray.cxx.

36  {
37  const string myname = "test_FclFloatArray: ";
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_FclFloatArray.fcl";
46  Index ioff = 10;
47  if ( ! useExistingFcl ) {
48  cout << myname << "Creating top-level FCL." << endl;
49  ofstream fout(fclfile.c_str());
50  fout << "tools: {" << endl;
51  fout << " mytool: {" << endl;
52  fout << " tool_type: FclFloatArray" << endl;
53  fout << " LogLevel: 2" << endl;
54  fout << " DefaultValue: -1" << endl;
55  fout << " Offset: " << ioff << endl;
56  fout << " Label: myvals" << endl;
57  fout << " Unit: ke" << endl;
58  fout << " Values: [ 0, 1.01, 2.02, 3.03, 4.04, 5.05, 6.06, 7.07, 8.08, 9.09," << endl;
59  fout << " 10.10, 11.11, 12.12, 13.13, 14.14, 15.15 ]" << endl;
60  fout << " }" << endl;
61  fout << "}" << endl;
62  fout.close();
63  } else {
64  cout << myname << "Using existing top-level FCL." << endl;
65  }
66 
67  cout << myname << line << endl;
68  cout << myname << "Fetching tool manager." << endl;
70  assert ( ptm != nullptr );
71  DuneToolManager& tm = *ptm;
72  tm.print();
73  assert( tm.toolNames().size() >= 1 );
74 
75  cout << myname << line << endl;
76  cout << myname << "Fetching tool." << endl;
77  auto pto = tm.getPrivate<FloatArrayTool>("mytool");
78  assert( pto != nullptr );
79 
80  cout << myname << line << endl;
81  cout << "Check tool params." << endl;
82  Index nval = 16;
83  assert( pto->offset() == ioff );
84  assert( pto->label() == "myvals" );
85  assert( pto->size() == nval );
86  assert( pto->offset() == ioff );
87 
88  cout << myname << line << endl;
89  cout << "Check fill." << endl;
91  float fval = 1234.5;
92  assert( pto->fill(fvals, fval) == 0 );
93  assert( fvals.size() == nval + ioff );
94  for ( Index ival=0; ival<ioff; ++ival ) {
95  assert( fvals[ival] == fval );
96  }
97 
98  cout << myname << line << endl;
99  cout << "Check values." << endl;
100  for ( Index ival=0; ival<nval; ++ival ) {
101  assert( pto->values()[ival] == fvals[ioff+ival] );
102  assert( isequal(pto->values()[ival], 1.01*ival) );
103  }
104 
105  cout << myname << line << endl;
106  cout << myname << "Done." << endl;
107  return 0;
108 }
const std::vector< std::string > & toolNames() const
bool isequal(float lhs, float rhs)
void print() const
unsigned int Index
tm
Definition: demo.py:21
std::vector< float > FloatVector
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)