test_KeepAllRoiBuildingService.cxx
Go to the documentation of this file.
1 // test_KeepAllRoiBuildingService.cxx
2 //
3 // David Adams
4 // September 2016
5 //
6 // Test KeepAllRoiBuildingService.
7 //
8 
9 #include <string>
10 #include <iostream>
11 #include <sstream>
12 #include <fstream>
13 #include <iomanip>
17 
18 #undef NDEBUG
19 #include <cassert>
20 
21 using std::string;
22 using std::vector;
23 using std::cout;
24 using std::endl;
25 using std::istringstream;
26 using std::ofstream;
27 using std::setw;
28 using std::setprecision;
29 using std::fixed;
30 using art::ServiceHandle;
31 
32 typedef vector<unsigned int> IndexVector;
33 
34 //**********************************************************************
35 
36 int test_KeepAllRoiBuildingService(int a_LogLevel =1, bool explicitFcl =true) {
37  const string myname = "test_KeepAllRoiBuildingService: ";
38 #ifdef NDEBUG
39  cout << myname << "NDEBUG must be off." << endl;
40  abort();
41 #endif
42  string line = "-----------------------------";
43 
44  cout << myname << line << endl;
45  cout << myname << "Arguments: " << endl;
46  cout << myname << " LogLevel: " << a_LogLevel << endl;
47  cout << myname << " explicitFcl: " << explicitFcl << endl;
48 
49  cout << myname << line << endl;
50  cout << myname << "Create top-level FCL." << endl;
51  std::ostringstream fout;
52  fout << "#include \"services_dune.fcl\"" << endl;
53  fout << "services: @local::dune35t_services_legacy" << endl;
54  if ( explicitFcl ) {
55  fout << "services.AdcRoiBuildingService: {" << endl;
56  fout << " service_provider: KeepAllRoiBuildingService" << endl;
57  fout << " LogLevel: " << a_LogLevel << endl;
58  fout << "}" << endl;
59  } else {
60  fout << "services.AdcRoiBuildingService: @local::adcroi_keepall" << endl;
61  }
63 
64  const unsigned int nsig = 100;
65  AdcChannelData acd;
66  acd.setChannelInfo(100);
67  for ( unsigned int isig=0; isig<nsig; ++isig ) {
68  acd.samples.push_back(0);
69  acd.flags.push_back(AdcGood);
70  }
71  acd.samples[10] = 3.0;
72  acd.samples[29] = 2.0;
73  acd.samples[30] = 8.0;
74  acd.samples[31] = 10.0;
75  acd.samples[32] = 8.0;
76  acd.samples[33] = 4.0;
77  acd.samples[34] = 2.0;
78  acd.samples[35] = 0.5;
79  acd.samples[60] = 20.0;
80  acd.samples[70] = 20.0;
81  acd.samples[90] = 20.0;
82  AdcSignalVector& sigs = acd.samples;
83  AdcSignalVector sigsin = sigs;
84 
85  cout << myname << line << endl;
86  cout << myname << "Fetch ROI building service." << endl;
88  hroi->print(cout, myname);
89 
90  cout << myname << line << endl;
91  cout << myname << "Build ROIs." << endl;
92  hroi->build(acd);
93  cout << myname << "Samples size: " << acd.samples.size() << endl;
94  cout << myname << "Output ROIS size: " << acd.rois.size() << endl;
95  assert( sigs.size() == nsig );
96  for ( unsigned int isig=0; isig<nsig; ++isig ) {
97  cout << myname << setw(4) << isig << ": "
98  << fixed << setprecision(1) << setw(10) << sigsin[isig]
99  << fixed << setprecision(1) << setw(10) << sigs[isig]
100  << endl;
101  assert( sigs[isig] == sigsin[isig] );
102  }
103  cout << myname << line << endl;
104  cout << myname << "ROIS:" << endl;
105  for ( AdcRoi roi : acd.rois ) {
106  cout << setw(6) << roi.first << setw(6) << roi.second << endl;
107  }
108 
109  cout << myname << line << endl;
110  cout << myname << "Check ROIs." << endl;
111  assert( acd.rois.size() == 1 );
112  assert( acd.rois[0].first == 0 );
113  assert( acd.rois[0].second == 99 );
114 
115  cout << myname << line << endl;
116  cout << myname << "Done." << endl;
117  return 0;
118 }
119 
120 //**********************************************************************
121 
122 int main(int argc, char* argv[]) {
123  int a_LogLevel = -1;
124  bool explicitFcl = 1;
125  if ( argc > 1 ) {
126  istringstream ssarg(argv[1]);
127  ssarg >> a_LogLevel;
128  }
129  if ( argc > 2 ) {
130  string sarg(argv[2]);
131  explicitFcl = sarg=="1" || sarg == "true";
132  }
133  cout << " LogLevel: " << a_LogLevel << endl;
134  cout << " explicitFcl: " << explicitFcl << endl;
135  return test_KeepAllRoiBuildingService(a_LogLevel, explicitFcl);
136 }
137 
138 //**********************************************************************
std::string string
Definition: nybbler.cc:12
virtual int build(AdcChannelData &data) const =0
int main(int argc, char *argv[])
vector< unsigned int > IndexVector
virtual std::ostream & print(std::ostream &out=std::cout, std::string prefix="") const =0
struct vector vector
std::pair< AdcIndex, AdcIndex > AdcRoi
Definition: AdcTypes.h:54
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)
AdcRoiVector rois
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
int test_KeepAllRoiBuildingService(int a_LogLevel=1, bool explicitFcl=true)
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