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

Go to the source code of this file.

Typedefs

using Index = unsigned int
 

Functions

int test_FclRunDataTool (bool useExistingFcl=false, Index runin=0)
 
int main (int argc, char *argv[])
 

Typedef Documentation

using Index = unsigned int

Definition at line 25 of file test_FclRunDataTool.cxx.

Function Documentation

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

Definition at line 122 of file test_FclRunDataTool.cxx.

122  {
123  bool useExistingFcl = false;
124  Index run = 0;
125  if ( argc > 1 ) {
126  string sarg(argv[1]);
127  if ( sarg == "-h" ) {
128  cout << "Usage: " << argv[0] << " [keepFCL] [RUN]" << endl;
129  cout << " If keepFCL = true, existing FCL file is used." << endl;
130  cout << " If RUN is nonzero, the data for that run are displayed." << endl;
131  return 0;
132  }
133  useExistingFcl = sarg == "true" || sarg == "1";
134  }
135  if ( argc > 2 ) {
136  string sarg(argv[2]);
137  istringstream ssarg(argv[2]);
138  ssarg >> run;
139  }
140  return test_FclRunDataTool(useExistingFcl, run);
141 }
int test_FclRunDataTool(bool useExistingFcl=false, Index runin=0)
unsigned int Index
QTextStream & endl(QTextStream &s)
int test_FclRunDataTool ( bool  useExistingFcl = false,
Index  runin = 0 
)

Definition at line 29 of file test_FclRunDataTool.cxx.

29  {
30  const string myname = "test_FclRunDataTool: ";
31 #ifdef NDEBUG
32  cout << myname << "NDEBUG must be off." << endl;
33  abort();
34 #endif
35  string line = "-----------------------------";
36 
37  cout << myname << line << endl;
38  string fclfile = "test_FclRunDataTool.fcl";
39  if ( ! useExistingFcl ) {
40  cout << myname << "Creating top-level FCL." << endl;
41  ofstream fout(fclfile.c_str());
42  if ( runin == 0 ) {
43  fout << "tools: {" << endl;
44  fout << " mytool: {" << endl;
45  fout << " tool_type: FclRunDataTool" << endl;
46  fout << " LogLevel: 3" << endl;
47  fout << " FileNames: [\"rdtest/rundata.fcl\", \"rdtest/rundata/run000123.fcl\"]" << endl;
48  fout << " }" << endl;
49  fout << "}" << endl;
50  } else {
51  fout << "#include \"dunecommon_tools.fcl\"" << endl;
52  fout << "tools.mytool: @local::tools.protoduneRunDataTool" << endl;
53  }
54  fout.close();
55  } else {
56  cout << myname << "Using existing top-level FCL." << endl;
57  }
58 
59  cout << myname << line << endl;
60  cout << myname << "Create rundata fcl" << endl;
61  if ( ! useExistingFcl ) {
62  system("rm -rf rdtest");
63  system("mkdir rdtest");
64  ofstream fout("rdtest/rundata.fcl");
65  fout << "cryostat: protodune\n";
66  fout << "apas: [1, 2, 3, 4, 5, 6]\n";
67  fout << "gain: 14.0\n";
68  fout << "shaping: 2.0\n";
69  fout << "leakage: 500\n";
70  fout << "hvfrac: 1.0\n";
71  fout << "pulserAmplitude: 0\n";
72  fout.close();
73  }
74  if ( ! useExistingFcl ) {
75  system("mkdir rdtest/rundata");
76  ofstream fout("rdtest/rundata/run000123.fcl");
77  fout << "run: 123\n";
78  fout << "gain: 25.0\n";
79  fout << "shaping: 3.0\n";
80  fout << "hvfrac: 0.5\n";
81  fout << "pulserAmplitude: 8\n";
82  fout.close();
83  }
84 
85  cout << myname << line << endl;
86  cout << myname << "Fetching tool manager." << endl;
88  assert ( ptm != nullptr );
89  DuneToolManager& tm = *ptm;
90  tm.print();
91  assert( tm.toolNames().size() >= 1 );
92 
93  cout << myname << line << endl;
94  cout << myname << "Fetching tool." << endl;
95  auto rdt = tm.getPrivate<RunDataTool>("mytool");
96  assert( rdt != nullptr );
97 
98  Index run = runin == 0 ? 123 : runin;
99 
100  cout << myname << line << endl;
101  cout << "Fetch run data." << endl;
102  RunData rdat = rdt->runData(run);
103  cout << rdat << endl;
104  assert( rdat.run() == run );
105  if ( run == 123 ) {
106  assert( rdat.cryostat() == "protodune" );
107  assert( rdat.apas().size() == 6 );
108  assert( rdat.gain() == 25.0 );
109  assert( rdat.shaping() == 3.0 );
110  assert( rdat.leakage() == 500 );
111  assert( rdat.hvfrac() == 0.5 );
112  assert( rdat.pulserAmplitude() == 8 );
113  }
114 
115  cout << myname << line << endl;
116  cout << myname << "Done." << endl;
117  return 0;
118 }
Index pulserAmplitude() const
Definition: RunData.h:41
const std::vector< std::string > & toolNames() const
const IndexVector & apas() const
Definition: RunData.h:35
Index run() const
Definition: RunData.h:33
void print() const
unsigned int Index
tm
Definition: demo.py:21
float gain() const
Definition: RunData.h:36
float shaping() const
Definition: RunData.h:37
float hvfrac() const
Definition: RunData.h:40
std::unique_ptr< T > getPrivate(std::string name)
Name cryostat() const
Definition: RunData.h:34
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)
float leakage() const
Definition: RunData.h:39