test_ConfigurableAdcChannelDataCopyService.cxx
Go to the documentation of this file.
1 // test_ConfigurableAdcChannelDataCopyService.cxx
2 //
3 // David Adams
4 // August 2016
5 //
6 // Test ConfigurableAdcChannelDataCopyService.
7 
8 #include <string>
9 #include <iostream>
10 #include <sstream>
11 #include <fstream>
12 #include <iomanip>
16 
17 #undef NDEBUG
18 #include <cassert>
19 
20 using std::string;
21 using std::vector;
22 using std::cout;
23 using std::endl;
24 using std::istringstream;
25 using std::ofstream;
26 using std::setw;
27 using std::setprecision;
28 using std::fixed;
29 using art::ServiceHandle;
30 
31 typedef vector<unsigned int> IndexVector;
32 
33 //**********************************************************************
34 
35 int test_ConfigurableAdcChannelDataCopyService(int a_LogLevel =1, int a_MaxConsecutiveFlag =0) {
36  const string myname = "test_ConfigurableAdcChannelDataCopyService: ";
37 #ifdef NDEBUG
38  cout << myname << "NDEBUG must be off." << endl;
39  abort();
40 #endif
41  string line = "-----------------------------";
42 
43  cout << myname << line << endl;
44  cout << myname << "Create top-level FCL." << endl;
45  std::ostringstream oss;
46  oss << "services.AdcChannelDataCopyService: {" << endl;
47  oss << " service_provider: ConfigurableAdcChannelDataCopyService" << endl;
48  oss << " LogLevel: " << a_LogLevel << endl;
49  oss << " CopyChannel: true" << endl;
50  oss << " CopyPedestal: true" << endl;
51  oss << " CopySamples: true" << endl;
52  oss << "}" << endl;
54 
55  AdcChannel channel = 123;
56  AdcSignal pedestal = 123.45;
57  const unsigned int nsig = 50;
58  AdcChannelData acd1;
59  for ( unsigned int isig=0; isig<50; ++isig ) {
60  acd1.samples.push_back(10+isig);
61  acd1.flags.push_back(AdcGood);
62  }
63  AdcSignalVector& sigs = acd1.samples;
64  acd1.setChannelInfo(channel);
65  acd1.pedestal = pedestal;
66 
67  cout << myname << line << endl;
68  cout << myname << "Check original." << endl;
69  assert( acd1.channel() == channel );
70  assert( acd1.pedestal == pedestal );
71  assert( acd1.raw.size() == 0);
72  assert( acd1.samples == sigs );
73  assert( acd1.flags.size() == nsig );
74  assert( acd1.raw.size() == 0 );
75  assert( acd1.signal.size() == 0 );
76  assert( acd1.rois.size() == 0 );
77  assert( acd1.digit == nullptr );
78  assert( acd1.wire == nullptr );
79  assert( acd1.digitIndex == AdcChannelData::badIndex() );
80  assert( acd1.wireIndex == AdcChannelData::badIndex() );
81 
82  cout << myname << line << endl;
83  cout << myname << "Fetch service." << endl;
85 
86  cout << myname << line << endl;
87  cout << myname << "Copy." << endl;
88  AdcChannelData acd2;
89  hcop->copy(acd1, acd2);
90 
91  cout << myname << line << endl;
92  cout << myname << "Check copy." << endl;
93  assert( acd2.channel() == channel );
94  assert( acd2.pedestal == pedestal );
95  assert( acd2.raw.size() == 0);
96  assert( acd2.samples == sigs );
97  assert( acd2.flags.size() == 0 );
98  assert( acd2.raw.size() == 0 );
99  assert( acd2.signal.size() == 0 );
100  assert( acd2.rois.size() == 0 );
101  assert( acd2.digit == nullptr );
102  assert( acd2.wire == nullptr );
103  assert( acd2.digitIndex == AdcChannelData::badIndex() );
104  assert( acd2.wireIndex == AdcChannelData::badIndex() );
105 
106  cout << myname << line << endl;
107  cout << myname << "Done." << endl;
108  return 0;
109 }
110 
111 //**********************************************************************
112 
113 int main(int argc, char* argv[]) {
114  int a_LogLevel = 1;
115  int a_MaxConsecutiveFlag = 0;
116  if ( argc > 1 ) {
117  istringstream ssarg(argv[1]);
118  ssarg >> a_LogLevel;
119  }
120  if ( argc > 2 ) {
121  istringstream ssarg(argv[1]);
122  ssarg >> a_MaxConsecutiveFlag;
123  }
124  return test_ConfigurableAdcChannelDataCopyService(a_LogLevel, a_MaxConsecutiveFlag);
125 }
126 
127 //**********************************************************************
std::string string
Definition: nybbler.cc:12
float AdcSignal
Definition: AdcTypes.h:21
struct vector vector
uint8_t channel
Definition: CRTFragment.hh:201
const recob::Wire * wire
int main(int argc, char *argv[])
const raw::RawDigit * digit
static void load_services(std::string const &config)
Q_EXPORT QTSManip setprecision(int p)
Definition: qtextstream.h:343
const AdcFlag AdcGood
Definition: AdcTypes.h:32
void setChannelInfo(ChannelInfoPtr pchi)
virtual int copy(const AdcChannelData &oldacd, AdcChannelData &newacd) const =0
AdcRoiVector rois
AdcCountVector raw
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
Channel channel() const
AdcSignal pedestal
AdcFilterVector signal
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
AdcIndex digitIndex
AdcIndex wireIndex
static Index badIndex()
vector< unsigned int > IndexVector
AdcSignalVector samples
int test_ConfigurableAdcChannelDataCopyService(int a_LogLevel=1, int a_MaxConsecutiveFlag=0)
QTextStream & endl(QTextStream &s)
AdcFlagVector flags