Typedefs | Functions
test_IdealAdcSimulator.cxx File Reference
#include <string>
#include <iostream>
#include <fstream>
#include "fhiclcpp/ParameterSet.h"
#include "fhiclcpp/intermediate_table.h"
#include "fhiclcpp/make_ParameterSet.h"
#include "art/Utilities/make_tool.h"
#include "dunecore/DuneInterface/Data/AdcSimulator.h"
#include <cassert>

Go to the source code of this file.

Typedefs

using ToolPtr = std::unique_ptr< AdcSimulator >
 
using Count = AdcSimulator::Count
 

Functions

template<class T1 , class T2 >
void checkEqual (T1 x1, T2 x2, string msg="Assert failed")
 
void checkCount (const ToolPtr &ptool, double vin, Count countExpected)
 
int test_IdealAdcSimulator (bool useExistingFcl)
 
int main (int argc, char *argv[])
 

Typedef Documentation

Definition at line 26 of file test_IdealAdcSimulator.cxx.

using ToolPtr = std::unique_ptr<AdcSimulator>

Definition at line 25 of file test_IdealAdcSimulator.cxx.

Function Documentation

void checkCount ( const ToolPtr ptool,
double  vin,
Count  countExpected 
)

Definition at line 38 of file test_IdealAdcSimulator.cxx.

38  {
39  Count countActual = ptool->count(vin);
40  cout << " ADC(" << vin << ") = " << countActual << endl;
41  checkEqual(countActual, countExpected);
42 }
AdcSimulator::Count Count
void checkEqual(T1 x1, T2 x2, string msg="Assert failed")
QTextStream & endl(QTextStream &s)
template<class T1 , class T2 >
void checkEqual ( T1  x1,
T2  x2,
string  msg = "Assert failed" 
)

Definition at line 31 of file test_IdealAdcSimulator.cxx.

31  {
32  if ( x1 != x2 ) {
33  cout << msg << ": " << x1 << " != " << x2 << endl;
34  assert(false);
35  }
36 }
void msg(const char *fmt,...)
Definition: message.cpp:107
QTextStream & endl(QTextStream &s)
int main ( int  argc,
char *  argv[] 
)

Definition at line 110 of file test_IdealAdcSimulator.cxx.

110  {
111  bool useExistingFcl = false;
112  if ( argc > 1 ) {
113  string sarg(argv[1]);
114  if ( sarg == "-h" ) {
115  cout << "Usage: " << argv[0] << " [ARG]" << endl;
116  cout << " If ARG = true, existing FCL file is used." << endl;
117  return 0;
118  }
119  useExistingFcl = sarg == "true" || sarg == "1";
120  }
121  return test_IdealAdcSimulator(useExistingFcl);
122 }
int test_IdealAdcSimulator(bool useExistingFcl)
QTextStream & endl(QTextStream &s)
int test_IdealAdcSimulator ( bool  useExistingFcl)

Definition at line 46 of file test_IdealAdcSimulator.cxx.

46  {
47  const string myname = "test_IdealAdcSimulator: ";
48 #ifdef NDEBUG
49  cout << myname << "NDEBUG must be off." << endl;
50  abort();
51 #endif
52  string line = "-----------------------------";
53 
54  cout << myname << line << endl;
55  string fclfile = "test_IdealAdcSimulator.fcl";
56  if ( ! useExistingFcl ) {
57  cout << myname << "Creating top-level FCL." << endl;
58  ofstream fout(fclfile.c_str());
59  fout << "mytool: {" << endl;
60  fout << " tool_type: IdealAdcSimulator" << endl;
61  fout << " Vsen: 2.0" << endl;
62  fout << " Nbit: 12" << endl;
63  fout << "}" << endl;
64  fout.close();
65  } else {
66  cout << myname << "Using existing top-level FCL." << endl;
67  }
68 
69  // Create pset
70  cout << myname << line << endl;
71  cout << myname << "Creating parameter set." << endl;
72  //putenv(const_cast<char*>("FHICL_FILE_PATH=./test:."));
73  cet::filepath_lookup policy("FHICL_FILE_PATH");
74  auto const psTop =
76 
77  cout << myname << line << endl;
78  cout << myname << "Checking tool type." << endl;
79  ParameterSet psTool = psTop.get<fhicl::ParameterSet>("mytool");
80  cout << "Tool type: " << psTool.get<string>("tool_type") << endl;
81  assert( psTool.get<string>("tool_type") == "IdealAdcSimulator" );
82 
83  cout << myname << line << endl;
84  cout << myname << "Instantiate tool." << endl;
85  std::unique_ptr<AdcSimulator> ptool = art::make_tool<AdcSimulator>(psTool);
86  assert( ptool != nullptr );
87  double vin = 1200;
88  cout << "ADC count is " << ptool->count(vin) << endl;
89  checkCount(ptool, -999.0, 0);
90  checkCount(ptool, -999.0, 0 );
91  checkCount(ptool, -0.01, 0 );
92  checkCount(ptool, 0.0, 0 );
93  checkCount(ptool, 0.2, 0 );
94  checkCount(ptool, 1.0, 1);
95  checkCount(ptool, 201.0, 101 );
96  checkCount(ptool, 2001.0, 1001 );
97  checkCount(ptool, 8187.0, 4094 );
98  checkCount(ptool, 8189.0, 4095 );
99  checkCount(ptool, 8190.0, 4095 );
100  checkCount(ptool, 8191.0, 4095 );
101  checkCount(ptool, 999999.0, 4095 );
102 
103  cout << myname << line << endl;
104  cout << myname << "Done." << endl;
105  return 0;
106 }
static ParameterSet make(intermediate_table const &tbl)
Definition: ParameterSet.cc:68
void checkCount(const ToolPtr &ptool, double vin, Count countExpected)
T get(std::string const &key) const
Definition: ParameterSet.h:271
virtual Count count(double vin, Channel chan=0, Tick tick=0) const =0
intermediate_table parse_document(std::string const &filename, cet::filepath_maker &maker)
Definition: parse.cc:720
void line(double t, double *p, double &x, double &y, double &z)
QTextStream & endl(QTextStream &s)