test_AcdDigitReader.cxx
Go to the documentation of this file.
1 // test_AcdDigitReader.cxx
2 //
3 // David Adams
4 // April 2017
5 //
6 // Test AcdDigitReader.
7 
8 #include <string>
9 #include <iostream>
10 #include <fstream>
11 #include <sstream>
12 #include <iomanip>
16 
17 #undef NDEBUG
18 #include <cassert>
19 
20 using std::string;
21 using std::cout;
22 using std::endl;
23 using std::ostringstream;
24 using std::ofstream;
25 using std::setw;
26 using std::setprecision;
27 using std::fixed;
29 
30 #include "TestDigit.h"
31 
32 //**********************************************************************
33 
34 bool sigequal(AdcSignal sig1, AdcSignal sig2) {
35  AdcSignal sigdiff = sig2 - sig1;
36  if ( sigdiff < -0.5 ) return false;
37  if ( sigdiff > 0.5 ) return false;
38  return true;
39 }
40 
41 //**********************************************************************
42 
43 int test_AcdDigitReader(bool useExistingFcl =false) {
44  const string myname = "test_AcdDigitReader: ";
45 #ifdef NDEBUG
46  cout << myname << "NDEBUG must be off." << endl;
47  abort();
48 #endif
49  string line = "-----------------------------";
50 
51  cout << myname << line << endl;
52  string fclfile = "test_AcdDigitReader.fcl";
53  if ( ! useExistingFcl ) {
54  cout << myname << "Creating top-level FCL." << endl;
55  ofstream fout(fclfile.c_str());
56  fout << "tools: {" << endl;
57  fout << " mytool: {" << endl;
58  fout << " tool_type: AcdDigitReader" << endl;
59  fout << " LogLevel: 2" << endl;
60  fout << " }" << endl;
61  fout << "}" << endl;
62  fout.close();
63  } else {
64  cout << myname << "Using existing top-level FCL." << endl;
65  }
66 
67  cout << myname << line << endl;
68  cout << myname << "Fetching tool manager." << endl;
70  assert ( ptm != nullptr );
71  DuneToolManager& tm = *ptm;
72  tm.print();
73  assert( tm.toolNames().size() == 1 );
74 
75  cout << myname << line << endl;
76  cout << myname << "Fetching tool." << endl;
77  auto prdr = tm.getPrivate<AdcChannelTool>("mytool");
78  assert( prdr != nullptr );
79 
80  cout << myname << line << endl;
81  cout << myname << "Construct test digit." << endl;
82  TestDigit tdig(0);
83  AdcIndex nsig = tdig.nsig;
84  const raw::RawDigit* pdig = tdig.pdig;
85 
86  cout << myname << line << endl;
87  cout << myname << "Extract data from digit." << endl;
88  AdcChannelData acd;
89  acd.digit = pdig;
90  assert( prdr->update(acd) == 0 );
91  const AdcCountVector& raw = acd.raw;
92  const AdcSignalVector& sigs = acd.samples;
93  const AdcFlagVector& flags = acd.flags;
94  AdcChannel chanout = acd.channel();
95  AdcSignal pedout = acd.pedestal;
96  cout << myname << "Output raw vector size: " << sigs.size() << endl;
97  cout << myname << "Output prep vector size: " << sigs.size() << endl;
98  cout << myname << " Output flags size: " << flags.size() << endl;
99  cout << myname << " Pedestal: " << pedout << endl;
100  assert( raw.size() == nsig );
101  assert( chanout == pdig->Channel() );
102  assert( pedout == pdig->GetPedestal() );
103  assert( acd.raw.size() == pdig->Samples() );
104  int dbg = 0;
105  for ( unsigned int isig=0; isig<nsig; ++isig ) {
106  AdcCount sigin = tdig.sigsin[isig] + tdig.pedestal + 0.1;
107  AdcCount sigout = acd.raw[isig];
108  AdcFlag flag = tdig.expflags[isig];
109  if ( dbg ) cout << isig << ": " << sigin << " --> " << sigout
110  << " (flag=" << flag << ")" << endl;
111  if ( flag == AdcGood) assert( sigout == sigin );
112  }
113 
114  cout << myname << line << endl;
115  cout << myname << "Done." << endl;
116  return 0;
117 }
118 
119 //**********************************************************************
120 
121 int main(int argc, char* argv[]) {
122  bool useExistingFcl = false;
123  if ( argc > 1 ) {
124  string sarg(argv[1]);
125  if ( sarg == "-h" ) {
126  cout << "Usage: " << argv[0] << " [ARG]" << endl;
127  cout << " If ARG = true, existing FCL file is used." << endl;
128  return 0;
129  }
130  useExistingFcl = sarg == "true" || sarg == "1";
131  }
132  return test_AcdDigitReader(useExistingFcl);
133 }
134 
135 //**********************************************************************
float GetPedestal() const
Definition: RawDigit.h:214
std::vector< AdcCount > AdcCountVector
Definition: AdcTypes.h:19
AdcSignalVector sigsin
Definition: TestDigit.h:25
ULong64_t Samples() const
Number of samples in the uncompressed ADC data.
Definition: RawDigit.h:213
Collection of charge vs time digitized from a single readout channel.
Definition: RawDigit.h:69
int test_AcdDigitReader(bool useExistingFcl=false)
short AdcFlag
Definition: AdcTypes.h:29
bool dbg
const std::vector< std::string > & toolNames() const
std::string string
Definition: nybbler.cc:12
float AdcSignal
Definition: AdcTypes.h:21
std::vector< AdcFlag > AdcFlagVector
Definition: AdcTypes.h:30
ChannelID_t Channel() const
DAQ channel this raw data was read from.
Definition: RawDigit.h:212
Raw data description.
AdcFlagVector expflags
Definition: TestDigit.h:26
void print() const
const raw::RawDigit * pdig
Definition: TestDigit.h:23
const raw::RawDigit * digit
tm
Definition: demo.py:21
Q_EXPORT QTSManip setprecision(int p)
Definition: qtextstream.h:343
const AdcFlag AdcGood
Definition: AdcTypes.h:32
AdcIndex nsig
Definition: TestDigit.h:24
int main(int argc, char *argv[])
AdcSignal pedestal
Definition: TestDigit.h:22
AdcCountVector raw
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)
Channel channel() const
AdcSignal pedestal
unsigned int AdcChannel
Definition: AdcTypes.h:50
void line(double t, double *p, double &x, double &y, double &z)
std::vector< AdcSignal > AdcSignalVector
Definition: AdcTypes.h:22
bool sigequal(AdcSignal sig1, AdcSignal sig2)
short AdcCount
Definition: AdcTypes.h:18
static DuneToolManager * instance(std::string fclname="", int dbg=1)
AdcSignalVector samples
QTextStream & endl(QTextStream &s)
AdcFlagVector flags