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

Go to the source code of this file.

Typedefs

using Index = AdcIndex
 

Functions

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

Typedef Documentation

using Index = AdcIndex

Definition at line 24 of file test_AdcRegularSignalFinder.cxx.

Function Documentation

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

Definition at line 127 of file test_AdcRegularSignalFinder.cxx.

127  {
128  bool useExistingFcl = false;
129  if ( argc > 1 ) {
130  string sarg(argv[1]);
131  if ( sarg == "-h" ) {
132  cout << "Usage: " << argv[0] << " [ARG]" << endl;
133  cout << " If ARG = true, existing FCL file is used." << endl;
134  return 0;
135  }
136  useExistingFcl = sarg == "true" || sarg == "1";
137  }
138  return test_AdcRegularSignalFinder(useExistingFcl);
139 }
int test_AdcRegularSignalFinder(bool useExistingFcl=false)
QTextStream & endl(QTextStream &s)
int test_AdcRegularSignalFinder ( bool  useExistingFcl = false)

Definition at line 28 of file test_AdcRegularSignalFinder.cxx.

28  {
29  const string myname = "test_AdcRegularSignalFinder: ";
30 #ifdef NDEBUG
31  cout << myname << "NDEBUG must be off." << endl;
32  abort();
33 #endif
34  string line = "-----------------------------";
35 
36  cout << myname << line << endl;
37  string fclfile = "test_AdcRegularSignalFinder.fcl";
38  if ( ! useExistingFcl ) {
39  cout << myname << "Creating top-level FCL." << endl;
40  ofstream fout(fclfile.c_str());
41  fout << "tools: {" << endl;
42  fout << " mytool: {" << endl;
43  fout << " tool_type: AdcRegularSignalFinder" << endl;
44  fout << " LogLevel: 1" << endl;
45  fout << " Period: 30" << endl;
46  fout << " Length: 20" << endl;
47  fout << " }" << endl;
48  fout << "}" << endl;
49  fout.close();
50  } else {
51  cout << myname << "Using existing top-level FCL." << endl;
52  }
53 
54  cout << myname << line << endl;
55  cout << myname << "Fetching tool manager." << endl;
57  assert ( ptm != nullptr );
58  DuneToolManager& tm = *ptm;
59  tm.print();
60  assert( tm.toolNames().size() == 1 );
61 
62  cout << myname << line << endl;
63  cout << myname << "Fetching tool." << endl;
64  auto psgf = tm.getPrivate<TpcDataTool>("mytool");
65  assert( psgf != nullptr );
66  auto psgfmod = tm.getPrivate<TpcDataTool>("mytool");
67  assert( psgfmod != nullptr );
68 
69  cout << myname << line << endl;
70  cout << myname << "Create data and call tool." << endl;
72  Index nsam = 100;
73  for ( AdcIndex itic=0; itic<nsam; ++itic ) {
74  float xadc = rand()%20 - 10.0;
75  data.samples.push_back(xadc);
76  }
77  data.samples[30] = 150.0;
78  assert( data.signal.size() == 0 );
79  assert( data.rois.size() == 0 );
80  assert( data.samples.size() == nsam );
81  assert( data.samples[30] = 150 );
82 
83  cout << myname << line << endl;
84  cout << myname << "Running tool." << endl;
85  DataMap resmod = psgfmod->update(data);
86  resmod.print();
87 
88  cout << myname << line << endl;
89  cout << myname << "Checking results." << endl;
90  Index per = 30;
91  Index len = 20;
92  Index nroi = 4;
93 
94  assert( resmod == 0 );
95  assert( resmod.getInt("roiPeriod") == int(per) );
96  assert( resmod.getInt("roiLength") == int(len) );
97  assert( resmod.getInt("roiCount") == int(nroi) );
98  assert( data.signal.size() == nsam );
99  assert( data.rois.size() == nroi );
100  for ( Index iroi=0; iroi<nroi; ++iroi ) {
101  AdcRoi roi = data.rois[iroi];
102  cout << myname << "ROI " << iroi << ": ["
103  << roi.first << ", "
104  << roi.second << "]" << endl;
105  Index isam1 = iroi*per;
106  Index isam2 = isam1 + len;
107  if ( isam2 > nsam ) isam2 = nsam;
108  Index isam3 = isam1 + per;
109  if ( isam3 > nsam ) isam3 = nsam;
110  for ( Index isam=isam1; isam<isam3; ++isam ) {
111  bool sig = data.signal[isam];
112  string ssig = sig ? "true" : "false";
113  cout << myname << setw(4) << isam << ": " << ssig << endl;
114  if ( isam < isam2 ) assert( data.signal[isam]);
115  else assert( ! data.signal[isam]);
116  }
117  assert( roi.first == isam1 );
118  assert( roi.second == isam2 - 1 );
119  }
120  cout << myname << line << endl;
121  cout << myname << "Done." << endl;
122  return 0;
123 }
const std::vector< std::string > & toolNames() const
std::pair< AdcIndex, AdcIndex > AdcRoi
Definition: AdcTypes.h:54
void print() const
unsigned int Index
void print(std::ostream *pout) const
Definition: DataMap.h:245
tm
Definition: demo.py:21
AdcRoiVector rois
unsigned int AdcIndex
Definition: AdcTypes.h:15
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
std::unique_ptr< T > getPrivate(std::string name)
AdcFilterVector signal
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)