SimpleHistogramManager_tool.cc
Go to the documentation of this file.
1 // SimpleHistogramManager.cxx
2 
4 #include "TH1.h"
5 #include <iostream>
6 
7 using std::string;
8 using std::cout;
9 using std::endl;
10 
12 
13 //**********************************************************************
14 
16 : m_LogLevel(ps.get<int>("LogLevel")) {
17  const string myname = "SimpleHistogramManager::ctor: ";
18  if ( m_LogLevel > 0 ) {
19  cout << myname << "LogLevel: " << m_LogLevel << endl;
20  }
21 }
22 
23 //**********************************************************************
24 
26  release("*");
27 }
28 
29 //**********************************************************************
30 
32  const string myname = "SimpleHistogramManager::manage: ";
33  if ( ph == nullptr ) {
34  if ( m_LogLevel > 1 ) {
35  cout << myname << "Histogram pointer is null." << endl;
36  }
37  return 1;
38  }
39  string hname = ph->GetName();
40  //if ( ph->GetDirectory() == nullptr ) {
41  // if ( m_LogLevel > 1 ) {
42  // cout << myname << "Histogram " << hname << " is not in a directory." << endl;
43  // }
44  // return 2;
45  //}
46  if ( m_hists.find(hname) != m_hists.end() ) {
47  if ( m_LogLevel > 1 ) {
48  cout << myname << "Histogram with name " << hname << " is already managed here." << endl;
49  }
50  return 3;
51  }
52  ph->SetDirectory(nullptr);
53  m_hists[hname] = ph;
54  m_names.push_back(hname);
55  return 0;
56 }
57 
58 //**********************************************************************
59 
61  return m_names;
62 }
63 
64 //**********************************************************************
65 
66 TH1* SimpleHistogramManager::get(Name hname) const {
68  if ( ihst == m_hists.end() ) return nullptr;
69  return ihst->second;
70 }
71 
72 //**********************************************************************
73 
75  if ( m_hists.size() == 0 ) return nullptr;
76  return get(names().back());
77 }
78 
79 //**********************************************************************
80 
82  if ( hname == "*" ) {
83  for ( auto ent : m_hists ) delete ent.second;
84  m_names.clear();
85  m_hists.clear();
86  }
88  if ( ihst == m_hists.end() ) return 1;
89  NameVector::iterator inam = find(m_names.begin(), m_names.end(), hname );
90  if ( inam == m_names.end() ) return 2;
91  m_names.erase(inam);
92  m_hists.erase(ihst);
93  return 0;
94 }
95 
96 //**********************************************************************
97 
intermediate_table::iterator iterator
std::map< Name, TH1 * > m_hists
#define DEFINE_ART_CLASS_TOOL(tool)
Definition: ToolMacros.h:42
std::string string
Definition: nybbler.cc:12
SimpleHistogramManager(fhicl::ParameterSet const &ps)
intermediate_table::const_iterator const_iterator
int release(Name hname) override
NameVector names() const override
static constexpr double ps
Definition: Units.h:99
std::vector< Name > NameVector
std::vector< string > NameVector
TH1 * get(Name hname) const override
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115
QTextStream & endl(QTextStream &s)