test_MedianPedestalService.cxx
Go to the documentation of this file.
1 // test_MedianPedestalService.cxx
2 //
3 // David Adams
4 // May 2016
5 //
6 // Test MedianPedestalService.
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 //**********************************************************************
32 
33 int test_MedianPedestalService(bool useExistingFcl) {
34  const string myname = "test_MedianPedestalService: ";
35 #ifdef NDEBUG
36  cout << myname << "NDEBUG must be off." << endl;
37  abort();
38 #endif
39  string line = "-----------------------------";
40 
41  cout << myname << line << endl;
42  if (useExistingFcl) {
43  cout << myname << "Using existing top-level FCL." << endl;
44  ArtServiceHelper::load_services("test_MedianPedestalService.fcl",
46  } else {
47  cout << myname << "Creating top-level FCL." << endl;
48  std::stringstream config;
49  config << "services.PedestalEvaluationService: {" << endl;
50  config << " service_provider: MedianPedestalService" << endl;
51  config << " LogLevel: 1" << endl;
52  config << " UseMean: false" << endl;
53  config << " SkipFlaggedSamples: true" << endl;
54  config << " SkipSignals: true" << endl;
55  config << "}" << endl;
57  }
58 
59  cout << myname << line << endl;
60  cout << myname << "Make data." << endl;
61  AdcSignalVector oddsigs = { 1.0, 8.0, 2.0, 3.0, 4.0 };
62  AdcSignalVector evnsigs = { 1.0, 8.0, 2.0, 4.0, 6.0, 9.0 };
63  AdcSignalVector flgsigs = { 1.0, 8.0, 111.0, 2.0, 4.0, 6.0, 222.0, 9.0 };
64  AdcFlagVector flags(8, AdcGood);
65  flags[2] = AdcStuckOff;
66  flags[6] = AdcOverflow;
67  AdcChannelData oddData;
68  oddData.samples = oddsigs;
69  AdcChannelData evnData;
70  oddData.samples = evnsigs;
71  AdcChannelData flgData;
72  flgData.samples = flgsigs;
73  flgData.flags = flags;
74 
75  cout << myname << line << endl;
76  cout << myname << "Fetch service." << endl;
78  hpev->print();
79 
80  cout << myname << line << endl;
81  cout << myname << "Checking odd data." << endl;
82  AdcSignal ped = 0.0;
83  assert( hpev->evaluate(oddData, &ped) == 0 );
84  assert( ped = 3.0 );
85 
86  cout << myname << line << endl;
87  cout << myname << "Checking even data." << endl;
88  ped = 0.0;
89  assert( hpev->evaluate(evnData, &ped) == 0 );
90  assert( ped = 3.0 );
91 
92  cout << myname << line << endl;
93  cout << myname << "Checking flagged data." << endl;
94  ped = 0.0;
95  assert( hpev->evaluate(flgData, &ped) == 0 );
96  assert( ped = 3.0 );
97 
98  cout << myname << line << endl;
99  cout << myname << "Done." << endl;
100  return 0;
101 }
102 
103 //**********************************************************************
104 
105 int main(int argc, char* argv[]) {
106  bool useExistingFcl = false;
107  if ( argc > 1 ) {
108  string sarg(argv[1]);
109  if ( sarg == "-h" ) {
110  cout << "Usage: " << argv[0] << " [ARG]" << endl;
111  cout << " If ARG = true, existing FCL file is used." << endl;
112  return 0;
113  }
114  useExistingFcl = sarg == "true" || sarg == "1";
115  }
116  return test_MedianPedestalService(useExistingFcl);
117 }
118 
119 //**********************************************************************
std::string string
Definition: nybbler.cc:12
float AdcSignal
Definition: AdcTypes.h:21
static constexpr FileOnPath_t FileOnPath
std::vector< AdcFlag > AdcFlagVector
Definition: AdcTypes.h:30
struct vector vector
virtual int evaluate(const AdcChannelData &data, AdcSignal *pped=nullptr, AdcSignal *prms=nullptr, AdcSignal *ppederr=nullptr, AdcSignal *prmserr=nullptr) const =0
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
const AdcFlag AdcOverflow
Definition: AdcTypes.h:34
static Config * config
Definition: config.cpp:1054
virtual std::ostream & print(std::ostream &out=std::cout, std::string prefix="") const =0
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
int main(int argc, char *argv[])
const AdcFlag AdcStuckOff
Definition: AdcTypes.h:36
int test_MedianPedestalService(bool useExistingFcl)
void line(double t, double *p, double &x, double &y, double &z)
std::vector< AdcSignal > AdcSignalVector
Definition: AdcTypes.h:22
AdcSignalVector samples
QTextStream & endl(QTextStream &s)
AdcFlagVector flags