Typedefs | Functions
test_AdcSampleScaler.cxx File Reference
#include <string>
#include <iostream>
#include <fstream>
#include <iomanip>
#include "dunecore/DuneInterface/Tool/TpcDataTool.h"
#include "dunecore/ArtSupport/DuneToolManager.h"
#include "TRandom.h"
#include <cassert>

Go to the source code of this file.

Typedefs

using Vector = std::vector< float >
 
using Index = unsigned int
 

Functions

int test_AdcSampleScaler (bool useExistingFcl, float qsig, float ped, float noise)
 
int main (int argc, char *argv[])
 

Typedef Documentation

using Index = unsigned int

Definition at line 28 of file test_AdcSampleScaler.cxx.

using Vector = std::vector<float>

Definition at line 27 of file test_AdcSampleScaler.cxx.

Function Documentation

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

Definition at line 111 of file test_AdcSampleScaler.cxx.

111  {
112  bool useExistingFcl = false;
113  float qsig = 500.0;
114  float ped = 2.0;
115  float noise = 0.0;
116  if ( argc > 1 ) {
117  string sarg(argv[1]);
118  if ( sarg == "-h" ) {
119  cout << "Usage: " << argv[0] << " [ARG [qsig [ped [noise]]]]" << endl;
120  cout << " If ARG = true, existing FCL file is used." << endl;
121  return 0;
122  }
123  useExistingFcl = sarg == "true" || sarg == "1";
124  }
125  if ( argc > 2 ) {
126  string sarg(argv[2]);
127  istringstream ssarg(sarg);
128  ssarg >> qsig;
129  }
130  if ( argc > 3 ) {
131  string sarg(argv[3]);
132  istringstream ssarg(sarg);
133  ssarg >> ped;
134  }
135  if ( argc > 4 ) {
136  string sarg(argv[4]);
137  istringstream ssarg(sarg);
138  ssarg >> noise;
139  }
140  return test_AdcSampleScaler(useExistingFcl, qsig, ped, noise);
141 }
int test_AdcSampleScaler(bool useExistingFcl, float qsig, float ped, float noise)
QTextStream & endl(QTextStream &s)
int test_AdcSampleScaler ( bool  useExistingFcl,
float  qsig,
float  ped,
float  noise 
)

Definition at line 32 of file test_AdcSampleScaler.cxx.

32  {
33  const string myname = "test_AdcSampleScaler: ";
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_AdcSampleScaler.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: AdcSampleScaler" << endl;
48  fout << " LogLevel: 1" << endl;
49  fout << " ScaleFactor: 100" << endl;
50  fout << " OutputUnit: \"e\"" << endl;
51  fout << " InputUnit: \"ADC\"" << 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<TpcDataTool>("mytool");
70  assert( ptoo != nullptr );
71 
72  cout << myname << line << endl;
73  cout << myname << "Create data." << endl;
74  Index nsam = 50;
75  Vector qsams(nsam, 0.0);
76  Vector qexps(nsam, 99.);
77  for ( Index isam=0; isam<nsam; ++isam ) {
78  float qsam = 200 + isam + 0.1*(isam%10);
79  qsams[isam] = qsam;
80  qexps[isam] = 100*qsam;
81  }
82  AdcChannelData acd;
83  acd.setEventInfo(123, 456);
84  acd.setChannelInfo(12345);
85  acd.samples = qsams;
86  acd.sampleUnit = "ADC";
87  assert ( qsams.size() == nsam );
88 
89  cout << myname << line << endl;
90  cout << myname << "Call tool." << endl;
91  DataMap ret = ptoo->update(acd);
92  assert( ! ret );
93  assert( ret.getInt("ascUnitCheck") == 0 );
94 
95  cout << myname << line << endl;
96  cout << myname << "Check samples." << endl;
97  for ( Index isam=0; isam<nsam; ++isam ) {
98  float qsam = acd.samples[isam];
99  float qexp = qexps[isam];
100  float qdif = fabs(qsam - qexp);
101  assert( qdif < 1.e-5 );
102  }
103 
104  cout << myname << line << endl;
105  cout << myname << "Done." << endl;
106  return 0;
107 }
const std::vector< std::string > & toolNames() const
void print() const
unsigned int Index
tm
Definition: demo.py:21
void setChannelInfo(ChannelInfoPtr pchi)
const double e
void setEventInfo(EventInfoPtr pevi)
std::unique_ptr< T > getPrivate(std::string name)
int getInt(Name name, int def=0) const
Definition: DataMap.h:218
void line(double t, double *p, double &x, double &y, double &z)
static DuneToolManager * instance(std::string fclname="", int dbg=1)
AdcSignalVector samples
QTextStream & endl(QTextStream &s)