Typedefs | Functions
test_AdcChannelTrimmer.cxx File Reference
#include <string>
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#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 Index = unsigned int
 

Functions

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

Typedef Documentation

using Index = unsigned int

Definition at line 28 of file test_AdcChannelTrimmer.cxx.

Function Documentation

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

Definition at line 115 of file test_AdcChannelTrimmer.cxx.

115  {
116  bool useExistingFcl = false;
117  if ( argc > 1 ) {
118  string sarg(argv[1]);
119  if ( sarg == "-h" ) {
120  cout << "Usage: " << argv[0] << " [ARG]" << endl;
121  cout << " If ARG = true, existing FCL file is used." << endl;
122  return 0;
123  }
124  useExistingFcl = sarg == "true" || sarg == "1";
125  }
126  return test_AdcChannelTrimmer(useExistingFcl);
127 }
int test_AdcChannelTrimmer(bool useExistingFcl=false)
QTextStream & endl(QTextStream &s)
int test_AdcChannelTrimmer ( bool  useExistingFcl = false)

Definition at line 32 of file test_AdcChannelTrimmer.cxx.

32  {
33  const string myname = "test_AdcChannelTrimmer: ";
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_AdcChannelTrimmer.fcl";
42  if ( ! useExistingFcl ) {
43  cout << myname << "Creating top-level FCL." << endl;
44  ofstream fout(fclfile.c_str());
45  fout << "#include \"dataprep_tools.fcl\"" << endl;
46  fout << "tools.mytool: {" << endl;
47  fout << " tool_type: AdcChannelTrimmer" << endl;
48  fout << " LogLevel: 2" << endl;
49  fout << " Length: 20" << endl;
50  fout << " MaxTrim: 10" << endl;
51  fout << "}" << endl;
52  fout << "" << endl;
53  fout.close();
54  } else {
55  cout << myname << "Using existing top-level FCL." << endl;
56  }
57 
58  cout << myname << line << endl;
59  cout << myname << "Fetching tool manager." << endl;
61  assert ( ptm != nullptr );
62  DuneToolManager& tm = *ptm;
63  tm.print();
64  assert( tm.toolNames().size() >= 1 );
65 
66  cout << myname << line << endl;
67  cout << myname << "Fetching tool." << endl;
68  auto ptoo = tm.getPrivate<TpcDataTool>("mytool");
69 
70  cout << myname << line << endl;
71  cout << myname << "Create data." << endl;
72  AdcChannelData acd;
73  acd.setEventInfo(123, 2468, 45);
74  acd.setChannelInfo(100123);
75  acd.sampleUnit = "fC";
76  acd.samples.resize(15);
77  for ( Index isam=0; isam<acd.samples.size(); ++isam ) {
78  acd.samples[isam] = 1.0 + 0.01*isam;
79  }
80  assert( acd.samples.size() == 15 );
81 
82  cout << myname << line << endl;
83  cout << myname << "Call tool view." << endl;
84  DataMap dmv = ptoo->view(acd);
85  dmv.print();
86  assert( dmv == 0 );
87  assert( dmv.getInt("trimAction") == -1 );
88  assert( dmv.getInt("trimLength") == -5 );
89  assert( acd.samples.size() == 15 );
90 
91  cout << myname << line << endl;
92  cout << myname << "Call tool update." << endl;
93  Index len1 = acd.samples.size();
94  DataMap dmu = ptoo->update(acd);
95  Index len2 = acd.samples.size();
96  dmu.print();
97  assert( dmu == 0 );
98  assert( dmu.getInt("trimAction") == 1 );
99  assert( dmu.getInt("trimLength") == -5 );
100  assert( len1 == 15 );
101  assert( len2 == 20 );
102  for ( Index isam=len1; isam<len2; ++isam ) {
103  float qsam = acd.samples[isam];
104  float qchk = acd.samples[isam-len1];
105  assert( fabs(qsam-qchk) < 1.e-6 );
106  }
107 
108  cout << myname << line << endl;
109  cout << myname << "Done." << endl;
110  return 0;
111 }
const std::vector< std::string > & toolNames() const
void print() const
unsigned int Index
void print(std::ostream *pout) const
Definition: DataMap.h:245
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)