test_ArtServiceHelper.cxx
Go to the documentation of this file.
1 // test_ArtServiceHelper.cxx
2 
3 //#include "AXService/ArtServiceHelper.h"
5 
6 #include <string>
7 #include <iostream>
8 #include <fstream>
9 #include <sstream>
10 #include <iomanip>
11 #include <cassert>
14 #include "art_root_io/TFileService.h"
16 
17 #include "TFile.h"
18 #include "TROOT.h"
19 
20 using std::string;
21 using std::cout;
22 using std::endl;
23 using std::istringstream;
24 using std::ofstream;
25 using art::ServiceHandle;
26 
27 #undef NDEBUG
28 #include <cassert>
29 
31  const string myname = "test_ArtServiceHelper: ";
32  cout << myname << "Starting test" << endl;
33 #ifdef NDEBUG
34  cout << myname << "NDEBUG must be off." << endl;
35  abort();
36 #endif
37  string line = "-----------------------------";
38  string scfg;
39  string fclfile = "test_ArtServiceHelper.fcl";
40  string datafile = "mytest.root";
41 
42  if ( opt == 1 ) {
43  ofstream fout(fclfile);
44  fout << "services: {" << endl;
45  fout << " RandomNumberGenerator: {}" << endl;
46  fout << " TFileService: {fileName: \"" << datafile << "\"}" << endl;
47  fout << "}" << endl;
48  }
49  ArtServiceHelper::load(fclfile);
50 
51  cout << myname << line << endl;
52  cout << myname << "Check RandomNumberGenerator is available." << endl;
54  cout << myname << " " << &*hrng << endl;
55 
56  cout << myname << line << endl;
57  cout << myname << "Check TFileService is available." << endl;
59  cout << myname << " " << &*hrng << endl;
60  cout << myname << " TFile name: " << htf->file().GetName() << endl;
61  //assert( htf->file().GetName() == datafile );
62 
63  cout << myname << line << endl;
64  cout << myname << "Done." << endl;
65  return 0;
66 }
67 
68 int main(int argc, char** argv) {
69  const string myname = "main: ";
70  int opt = 1;
71  if ( argc > 1 ) {
72  opt = -1;
73  istringstream ssopt(argv[1]);
74  ssopt >> opt;
75  if ( opt < 0 ) {
76  cout << "Usage: test_ArtServiceHelper [OPT]" << endl;
77  cout << " OPT = 0 to skip test." << endl;
78  cout << " 1 to load from string." << endl;
79  cout << " 2 to load all services from a file." << endl;
80  }
81  }
82 
83  if ( opt == 0 ) return 0;
84  int rstat = test_ArtServiceHelper(opt);
85  return rstat;
86 }
int main(int argc, char **argv)
std::string string
Definition: nybbler.cc:12
opt
Definition: train.py:196
static void load(std::string const &filename)
int test_ArtServiceHelper(int opt)
void line(double t, double *p, double &x, double &y, double &z)
QTextStream & endl(QTextStream &s)