Typedefs | Functions
test_AdcToRoi2d.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 Index = Tpc2dRoi::Index
 

Functions

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

Typedef Documentation

Definition at line 27 of file test_AdcToRoi2d.cxx.

Function Documentation

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

Definition at line 146 of file test_AdcToRoi2d.cxx.

146  {
147  bool useExistingFcl = false;
148  if ( argc > 1 ) {
149  string sarg(argv[1]);
150  if ( sarg == "-h" ) {
151  cout << "Usage: " << argv[0] << " [ARG]" << endl;
152  cout << " If ARG = true, existing FCL file is used." << endl;
153  return 0;
154  }
155  useExistingFcl = sarg == "true" || sarg == "1";
156  }
157  return test_AdcToRoi2d(useExistingFcl);
158 }
int test_AdcToRoi2d(bool useExistingFcl=false)
QTextStream & endl(QTextStream &s)
int test_AdcToRoi2d ( bool  useExistingFcl = false)

Definition at line 31 of file test_AdcToRoi2d.cxx.

31  {
32  const string myname = "test_AdcToRoi2d: ";
33 #ifdef NDEBUG
34  cout << myname << "NDEBUG must be off." << endl;
35  abort();
36 #endif
37  string line = "-----------------------------";
38 
39  cout << myname << line << endl;
40  string fclfile = "test_AdcToRoi2d.fcl";
41  if ( ! useExistingFcl ) {
42  cout << myname << "Creating top-level FCL." << endl;
43  ofstream fout(fclfile.c_str());
44  fout << "#include \"dataprep_tools.fcl\"" << endl;
45  fout << "tools.mytool1: {" << endl;
46  fout << " tool_type: AdcToRoi2d" << endl;
47  fout << " LogLevel: 3" << endl;
48  fout << " Option: 1" << endl;
49  fout << " InputAdcMaps: []" << endl;
50  fout << " OutputNames: []" << endl;
51  fout << "}" << endl;
52  fout.close();
53  } else {
54  cout << myname << "Using existing top-level FCL." << endl;
55  }
56 
57  cout << myname << line << endl;
58  cout << myname << "Fetching tool manager." << endl;
60  assert ( ptm != nullptr );
61  DuneToolManager& tm = *ptm;
62  tm.print();
63  assert( tm.toolNames().size() >= 2 );
64 
65  cout << myname << line << endl;
66  cout << myname << "Create test data." << endl;
67  // The data for each channel is offset by one tick using acd.tick0.
68  TpcData tpd;
70  AdcChannelDataMap acds;
71  Index ncha = 4;
72  Index ntck = 5;
73  Index ntckexp = ntck + ncha - 1;
74  Index icha0 = 100;
75  Index itck0 = 1000;
77  Tpc2dRoi exp(ncha, ntckexp, icha0, itck0);
78  Index dtck = 0;
79  DuneEventInfo* peviMutable = new DuneEventInfo(123, 1);
80  peviMutable->triggerTick0 = itck0;
81  AdcChannelData::EventInfoPtr pevi(peviMutable);
82  for ( Index kcha=0; kcha<ncha; ++kcha, ++dtck ) {
83  Index icha = icha0 + kcha;
84  AdcChannelData& acd = (*pacm)[icha];
85  acd.setEventInfo(pevi);
86  acd.setChannelInfo(icha);
87  acd.tick0 = dtck;
88  acd.samples.resize(ntck, 0.0);
89  float val = 10*(kcha + 1);
90  idxs[0] = kcha;
91  idxs[1] = dtck;
92  for ( Index ktck=0; ktck<3; ++ktck, ++idxs[1] ) {
93  exp.data().setValue(idxs, val);
94  acd.samples[ktck] = val;
95  }
96  }
97  assert( tpd.getAdcData().size() == 1 );
98  assert( tpd.getAdcData()[0]->size() == ncha );
99  for ( auto& iacd : *(tpd.getAdcData()[0]) ) {
100  const AdcChannelData& acd = iacd.second;
101  assert( acd.samples.size() == ntck );
102  }
103  assert( tpd.get2dRois().size() == 0 );
104 
105  cout << myname << line << endl;
106  cout << myname << "Fetching tool." << endl;
107  auto ptoo = tm.getPrivate<TpcDataTool>("mytool1");
108  assert( ptoo != nullptr );
109 
110  cout << myname << line << endl;
111  cout << myname << "Call tool." << endl;
112  DataMap res = ptoo->updateTpcData(tpd);
113  res.print();
114  assert( res.status() == 0 );
115 
116  cout << myname << line << endl;
117  cout << myname << "Check results." << endl;
118  assert( tpd.get2dRois().size() == 1 );
119  const Tpc2dRoi& roi = tpd.get2dRois().at(0);
120  assert( roi.channelSize() == ncha );
121  assert( roi.channelOffset() == icha0 );
122  assert( roi.sampleSize() == ntckexp );
123  assert( roi.sampleOffset() == itck0 );
124  Index& kcha = idxs[0];
125  Index& ktck = idxs[1];
126  for ( kcha=0; kcha<ncha; ++kcha ) {
127  Index icha = icha0 + kcha;
128  for ( ktck=0; ktck<ntckexp; ++ktck ) {
129  Index itck = itck0 + ktck;
130  float expval = exp.data().value(idxs);
131  float val = roi.data().value(idxs);
132  cout << myname << setw(5) << icha << setw(5) << itck << ": "
133  << setw(12) << expval << " ?= " << setw(12) << val << endl;
134  assert( val == expval );
135  }
136  cout << myname << line << endl;
137  }
138 
139  cout << myname << line << endl;
140  cout << myname << "Done." << endl;
141  return 0;
142 }
LongIndex triggerTick0
Definition: DuneEventInfo.h:28
const std::vector< std::string > & toolNames() const
std::shared_ptr< AdcChannelDataMap > AdcDataPtr
Definition: TpcData.h:35
void print() const
unsigned int Index
void print(std::ostream *pout) const
Definition: DataMap.h:245
std::shared_ptr< const EventInfo > EventInfoPtr
tm
Definition: demo.py:21
int status() const
Definition: DataMap.h:202
AdcDataVector & getAdcData()
Definition: TpcData.h:55
void setChannelInfo(ChannelInfoPtr pchi)
std::array< Index, 2 > IndexArray
Definition: Real2dData.h:34
void setEventInfo(EventInfoPtr pevi)
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
std::unique_ptr< T > getPrivate(std::string name)
void line(double t, double *p, double &x, double &y, double &z)
AdcDataPtr createAdcData(bool updateParent=true)
Definition: TpcData.cxx:99
std::map< AdcChannel, AdcChannelData > AdcChannelDataMap
Tpc2dRoiVector & get2dRois()
Definition: TpcData.h:57
static DuneToolManager * instance(std::string fclname="", int dbg=1)
AdcSignalVector samples
QTextStream & endl(QTextStream &s)