test_SimpleHistogramManager.cxx
Go to the documentation of this file.
1 // test_SimpleHistogramManager.cxx
2 //
3 // David Adams
4 // April 2017
5 //
6 // Test SimpleHistogramManager.
7 
8 #include <string>
9 #include <iostream>
10 #include <fstream>
13 #include "TH1F.h"
14 
15 #undef NDEBUG
16 #include <cassert>
17 
18 using std::string;
19 using std::cout;
20 using std::endl;
21 using std::ofstream;
23 
24 //**********************************************************************
25 
26 int test_SimpleHistogramManager(bool useExistingFcl =false) {
27  const string myname = "test_SimpleHistogramManager: ";
28 #ifdef NDEBUG
29  cout << myname << "NDEBUG must be off." << endl;
30  abort();
31 #endif
32  string line = "-----------------------------";
33 
34  cout << myname << line << endl;
35  string fclfile = "test_SimpleHistogramManager.fcl";
36  if ( ! useExistingFcl ) {
37  cout << myname << "Creating top-level FCL." << endl;
38  ofstream fout(fclfile.c_str());
39  fout << "tools: {" << endl;
40  fout << " mytool: {" << endl;
41  fout << " tool_type: SimpleHistogramManager" << endl;
42  fout << " LogLevel: 1" << endl;
43  fout << " }" << endl;
44  fout << "}" << endl;
45  fout.close();
46  } else {
47  cout << myname << "Using existing top-level FCL." << endl;
48  }
49 
50  cout << myname << line << endl;
51  cout << myname << "Fetching tool manager." << endl;
53  assert ( ptm != nullptr );
54  DuneToolManager& tm = *ptm;
55  tm.print();
56  assert( tm.toolNames().size() == 1 );
57 
58  cout << myname << line << endl;
59  cout << myname << "Fetching tool." << endl;
60  auto phm = tm.getPrivate<HistogramManager>("mytool");
61  assert( phm != nullptr );
62 
63  cout << myname << line << endl;
64  cout << myname << "Creating histogram." << endl;
65  TH1* ph = new TH1F("h1", "h1", 10, 0, 10);
66  assert(ph->GetDirectory() != nullptr);
67 
68  cout << myname << line << endl;
69  cout << myname << "Managing histogram." << endl;
70  assert(phm->manage(ph) == 0);
71  assert(ph->GetDirectory() == nullptr);
72 
73  cout << myname << line << endl;
74  cout << myname << "Done." << endl;
75  return 0;
76 }
77 
78 //**********************************************************************
79 
80 int main(int argc, char* argv[]) {
81  bool useExistingFcl = false;
82  if ( argc > 1 ) {
83  string sarg(argv[1]);
84  if ( sarg == "-h" ) {
85  cout << "Usage: " << argv[0] << " [ARG]" << endl;
86  cout << " If ARG = true, existing FCL file is used." << endl;
87  return 0;
88  }
89  useExistingFcl = sarg == "true" || sarg == "1";
90  }
91  return test_SimpleHistogramManager(useExistingFcl);
92 }
93 
94 //**********************************************************************
int main(int argc, char *argv[])
const std::vector< std::string > & toolNames() const
std::string string
Definition: nybbler.cc:12
void print() const
tm
Definition: demo.py:21
std::unique_ptr< T > getPrivate(std::string name)
void line(double t, double *p, double &x, double &y, double &z)
static DuneToolManager * instance(std::string fclname="", int dbg=1)
int test_SimpleHistogramManager(bool useExistingFcl=false)
QTextStream & endl(QTextStream &s)