ATLAS Offline Software
TrigMonTHistSvc.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef TRIGMONTHISTSVC_THISTSVC_H
6 #define TRIGMONTHISTSVC_THISTSVC_H
7 
8 #include "GaudiKernel/ITHistSvc.h"
11 
12 class TObject;
13 class TH1;
14 class TH2;
15 class TH3;
16 class TGraph;
17 class TTree;
18 
19 #include <vector>
20 #include <string>
21 #include <unordered_map>
22 #include <mutex>
23 
24 #include <boost/regex.hpp>
25 
26 // Helper to mark unsupported interfaces
27 #define NOSUPPORT(lvl, what) \
28  do { \
29  ATH_MSG_LVL(MSG::lvl, what << "is not supported by this implementation"); \
30  return {}; \
31  } while (0)
32 
33 
43 class TrigMonTHistSvc: public extends<AthService, ITHistSvc>
44 {
45 public:
46  TrigMonTHistSvc(const std::string& name, ISvcLocator *svc );
47 
49  virtual StatusCode stop() override;
50  virtual StatusCode finalize() override;
51 
52  virtual StatusCode regHist(const std::string& name) override;
53  virtual StatusCode regHist(const std::string& name, std::unique_ptr<TH1> hist) override;
54  virtual StatusCode regHist(const std::string& name, TH1*) override;
55  virtual StatusCode getHist(const std::string& id, TH1*& hist, size_t ind) const override;
56  virtual StatusCode getHist(const std::string& id, TH2*& hist, size_t ind) const override;
57  virtual StatusCode getHist(const std::string& id, TH3*& hist, size_t ind) const override;
58 
59  virtual StatusCode deReg(TObject* obj) override; //<! very slow
60  virtual StatusCode deReg(const std::string& name) override; //<! use this instead
61 
62  virtual std::vector<std::string> getHists() const override;
63 
64  virtual StatusCode regShared( const std::string&, std::unique_ptr<TH1>, LockedHandle<TH1>& ) override;
65  virtual StatusCode regShared( const std::string&, std::unique_ptr<TH2>, LockedHandle<TH2>& ) override;
66  virtual StatusCode regShared( const std::string&, std::unique_ptr<TH3>, LockedHandle<TH3>& ) override;
67  virtual StatusCode getShared( const std::string&, LockedHandle<TH1>& ) const override;
68  virtual StatusCode getShared( const std::string&, LockedHandle<TH2>& ) const override;
69  virtual StatusCode getShared( const std::string&, LockedHandle<TH3>& ) const override;
70 
71  virtual StatusCode getTHists(TDirectory *td, TList &, bool recurse=false) const override;
72  virtual StatusCode getTHists(const std::string& name, TList &, bool recurse=false) const override;
73  virtual StatusCode getTHists(TDirectory *td, TList &tl, bool recurse=false, bool reg=false) override;
74  virtual StatusCode getTHists(const std::string& name, TList &tl, bool recurse=false, bool reg=false) override;
75 
76  virtual bool exists( const std::string& name ) const override { return existsHist(name); }
77  virtual bool existsHist( const std::string& name ) const override;
78 
79  /* Unsupported interfaces */
80  virtual StatusCode regTree(const std::string&) override { NOSUPPORT(WARNING, "TTree"); }
81  virtual StatusCode regTree(const std::string&, std::unique_ptr<TTree>) override { NOSUPPORT(WARNING, "TTree"); }
82  virtual StatusCode regTree(const std::string&, TTree*) override { NOSUPPORT(WARNING, "TTree"); }
83  virtual StatusCode getTree(const std::string&, TTree*&) const override { NOSUPPORT(WARNING, "TTree"); }
84 
85  virtual std::vector<std::string> getTrees() const override { NOSUPPORT(DEBUG, "TTree"); }
86  virtual StatusCode getTTrees(TDirectory*, TList&, bool) const override { NOSUPPORT(DEBUG, "TTree"); }
87  virtual StatusCode getTTrees(const std::string&, TList&, bool) const override { NOSUPPORT(DEBUG, "TTree"); }
88  virtual StatusCode getTTrees(TDirectory*, TList&, bool, bool) override { NOSUPPORT(DEBUG, "TTree"); }
89  virtual StatusCode getTTrees(const std::string&, TList&, bool, bool) override { NOSUPPORT(DEBUG, "TTree"); }
90 
91  virtual StatusCode regGraph(const std::string&) override { NOSUPPORT(WARNING, "TGraph"); }
92  virtual StatusCode regGraph(const std::string&, std::unique_ptr<TGraph>) override { NOSUPPORT(WARNING, "TGraph"); }
93  virtual StatusCode regGraph(const std::string&, TGraph*) override { NOSUPPORT(WARNING, "TGraph"); }
94  virtual std::vector<std::string> getGraphs() const override { NOSUPPORT(DEBUG, "TGraph"); }
95  virtual StatusCode getGraph(const std::string&, TGraph*&) const override { NOSUPPORT(DEBUG, "TGraph"); }
96 
97  virtual StatusCode regEfficiency(const std::string&) override { NOSUPPORT(WARNING, "TEfficiency"); }
98  virtual StatusCode regEfficiency(const std::string&, std::unique_ptr<TEfficiency>) override { NOSUPPORT(WARNING, "TEfficiency"); }
99  virtual StatusCode regEfficiency(const std::string&, TEfficiency*) override { NOSUPPORT(WARNING, "TEfficiency"); }
100  virtual StatusCode getEfficiency(const std::string&, TEfficiency*&) const override { NOSUPPORT(WARNING, "TEfficiency"); }
101  virtual std::vector<std::string> getEfficiencies() const override { NOSUPPORT(WARNING, "TEfficiency"); }
102 
103  virtual StatusCode getTEfficiencies(TDirectory*, TList&, bool) const override { NOSUPPORT(WARNING, "TEfficiency"); }
104  virtual StatusCode getTEfficiencies(const std::string&, TList&, bool) const override { NOSUPPORT(WARNING, "TEfficiency"); }
105  virtual StatusCode getTEfficiencies(TDirectory*, TList&, bool, bool) override { NOSUPPORT(WARNING, "TEfficiency"); }
106  virtual StatusCode getTEfficiencies(const std::string&, TList&, bool, bool) override { NOSUPPORT(WARNING, "TEfficiency"); }
107 
108  virtual StatusCode regShared( const std::string&, std::unique_ptr<TGraph>, LockedHandle<TGraph>& ) override { NOSUPPORT(WARNING, "TGraph"); }
109  virtual StatusCode getShared( const std::string&, LockedHandle<TGraph>& ) const override { NOSUPPORT(WARNING, "TGraph"); }
110  virtual StatusCode regShared( const std::string&, std::unique_ptr<TEfficiency>, LockedHandle<TEfficiency>& ) override { NOSUPPORT(WARNING, "TEfficiency"); }
111  virtual StatusCode getShared( const std::string&, LockedHandle<TEfficiency>& ) const override { NOSUPPORT(WARNING, "TEfficiency"); }
112 
113  virtual StatusCode merge( const std::string& ) override { NOSUPPORT(WARNING, "merge"); }
114  virtual StatusCode merge( TObject* ) override { NOSUPPORT(WARNING, "merge"); }
115 
116  virtual bool existsTree( const std::string& ) const override { NOSUPPORT(DEBUG, "TTree"); }
117  virtual bool existsGraph( const std::string& ) const override { NOSUPPORT(WARNING, "TGraph"); }
118  virtual bool existsEfficiency( const std::string& ) const override { NOSUPPORT(WARNING, "TEfficiency"); }
119 
120 private:
122  struct THistID {
123  THistID(const std::string& s, TObject* o) : id(s), obj(o) {};
124  ~THistID() { delete mutex; }
125  std::string id;
126  TObject* obj{nullptr};
127  std::mutex* mutex{nullptr};
128  };
129 
131  std::unordered_map<std::string, THistID> m_hists;
132 
134  bool isObjectAllowed(const std::string& path, const TObject *o) const;
135 
137  StatusCode getTHists_i(const std::string& name, TList &) const;
138 
139  // Templated methods implementing the virtual interface methods
140  template <typename T> StatusCode regHist_i(std::unique_ptr<T> hist, const std::string& name, bool shared, THistID*& phid);
141  template <typename T> T* getHist_i(const std::string& id, const size_t& ind, bool quiet = false) const;
142  template <typename T> LockedHandle<T> regShared_i( const std::string& id, std::unique_ptr<T> hist);
143  template <typename T> LockedHandle<T> getShared_i( const std::string& id ) const;
144 
145  // Properties
146  Gaudi::Property<std::string> m_excludeType{this, "ExcludeType", "()"};
147  Gaudi::Property<std::string> m_includeType{this, "IncludeType", ".+"};
148  Gaudi::Property<std::string> m_excludeName{this, "ExcludeName", ".*\\..*"};
149  Gaudi::Property<std::string> m_includeName{this, "IncludeName",
150  "^/((run_[0-9]+/lb_[0-9]+/LB)|(SHIFT)|(EXPERT)|(DEBUG)|(EXPRESS)|(RUNSTAT))/.+/.+"};
151 
152  // Dummy properties for compatibility with THistSvc
153  Gaudi::Property<int> m_autoSave{this, "AutoSave", 0, "Not supported by TrigMonTHistSvc"};
154  Gaudi::Property<int> m_autoFlush{this, "AutoFlush", 0, "Not supported by TrigMonTHistSvc"};
155  Gaudi::Property<bool> m_print{this, "PrintAll", false, "Not supported by TrigMonTHistSvc"};
156  Gaudi::Property<int> m_maxFileSize{this, "MaxFileSize", 10240, "Not supported by TrigMonTHistSvc"};
157  Gaudi::Property<std::vector<std::string>> m_outputfile{this, "Output", {}, "Not supported by TrigMonTHistSvc"};
158  Gaudi::Property<std::vector<std::string>> m_inputfile{this, "Input", {}, "Not supported by TrigMonTHistSvc"};
159 
160  // compiled regexes
165 
166  // Mutexes
167  mutable std::recursive_mutex m_svcMut;
168 };
169 
170 #endif // TRIGMONTHISTSVC_THISTSVC_H
TrigMonTHistSvc::m_maxFileSize
Gaudi::Property< int > m_maxFileSize
Definition: TrigMonTHistSvc.h:156
TrigMonTHistSvc::getGraph
virtual StatusCode getGraph(const std::string &, TGraph *&) const override
Definition: TrigMonTHistSvc.h:95
TrigMonTHistSvc::regEfficiency
virtual StatusCode regEfficiency(const std::string &) override
Definition: TrigMonTHistSvc.h:97
TrigMonTHistSvc::m_hists
std::unordered_map< std::string, THistID > m_hists
Registered histograms.
Definition: TrigMonTHistSvc.h:131
TrigMonTHistSvc::THistID::mutex
std::mutex * mutex
Definition: TrigMonTHistSvc.h:127
TrigMonTHistSvc::getHist_i
T * getHist_i(const std::string &id, const size_t &ind, bool quiet=false) const
Definition: TrigMonTHistSvc.cxx:144
TrigMonTHistSvc::regTree
virtual StatusCode regTree(const std::string &, std::unique_ptr< TTree >) override
Definition: TrigMonTHistSvc.h:81
TrigMonTHistSvc::regGraph
virtual StatusCode regGraph(const std::string &) override
Definition: TrigMonTHistSvc.h:91
TrigMonTHistSvc::THistID
Helper struct that bundles the histogram, name and mutex.
Definition: TrigMonTHistSvc.h:122
TrigMonTHistSvc::getShared
virtual StatusCode getShared(const std::string &, LockedHandle< TEfficiency > &) const override
Definition: TrigMonTHistSvc.h:111
TrigMonTHistSvc::m_excludeName
Gaudi::Property< std::string > m_excludeName
Definition: TrigMonTHistSvc.h:148
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
TrigMonTHistSvc::getTTrees
virtual StatusCode getTTrees(const std::string &, TList &, bool) const override
Definition: TrigMonTHistSvc.h:87
athena.path
path
python interpreter configuration --------------------------------------—
Definition: athena.py:128
TrigMonTHistSvc::regEfficiency
virtual StatusCode regEfficiency(const std::string &, std::unique_ptr< TEfficiency >) override
Definition: TrigMonTHistSvc.h:98
TrigMonTHistSvc::ATLAS_NOT_THREAD_SAFE
virtual StatusCode initialize ATLAS_NOT_THREAD_SAFE() override
TrigMonTHistSvc::regGraph
virtual StatusCode regGraph(const std::string &, std::unique_ptr< TGraph >) override
Definition: TrigMonTHistSvc.h:92
TrigMonTHistSvc::getEfficiencies
virtual std::vector< std::string > getEfficiencies() const override
Definition: TrigMonTHistSvc.h:101
TrigMonTHistSvc::merge
virtual StatusCode merge(const std::string &) override
Definition: TrigMonTHistSvc.h:113
quiet
bool quiet
Definition: TrigGlobEffCorrValidation.cxx:190
BeamSpot::mutex
std::mutex mutex
Definition: InDetBeamSpotVertex.cxx:18
TrigMonTHistSvc::regGraph
virtual StatusCode regGraph(const std::string &, TGraph *) override
Definition: TrigMonTHistSvc.h:93
plotmaker.hist
hist
Definition: plotmaker.py:148
initialize
void initialize()
Definition: run_EoverP.cxx:894
TrigMonTHistSvc::m_includeName
Gaudi::Property< std::string > m_includeName
Definition: TrigMonTHistSvc.h:149
TrigMonTHistSvc::m_excludeTypeRegex
boost::regex m_excludeTypeRegex
Definition: TrigMonTHistSvc.h:161
TrigMonTHistSvc::m_outputfile
Gaudi::Property< std::vector< std::string > > m_outputfile
Definition: TrigMonTHistSvc.h:157
TrigMonTHistSvc::getHists
virtual std::vector< std::string > getHists() const override
Definition: TrigMonTHistSvc.cxx:223
TrigMonTHistSvc::m_svcMut
std::recursive_mutex m_svcMut
Protect access to histogram list.
Definition: TrigMonTHistSvc.h:167
TrigMonTHistSvc::regShared
virtual StatusCode regShared(const std::string &, std::unique_ptr< TH1 >, LockedHandle< TH1 > &) override
Definition: TrigMonTHistSvc.cxx:342
TrigMonTHistSvc::getTTrees
virtual StatusCode getTTrees(TDirectory *, TList &, bool, bool) override
Definition: TrigMonTHistSvc.h:88
TrigMonTHistSvc::m_excludeNameRegex
boost::regex m_excludeNameRegex
Definition: TrigMonTHistSvc.h:163
TrigMonTHistSvc::m_inputfile
Gaudi::Property< std::vector< std::string > > m_inputfile
Definition: TrigMonTHistSvc.h:158
TrigMonTHistSvc::regShared_i
LockedHandle< T > regShared_i(const std::string &id, std::unique_ptr< T > hist)
Definition: TrigMonTHistSvc.cxx:108
TrigMonTHistSvc::getTrees
virtual std::vector< std::string > getTrees() const override
Definition: TrigMonTHistSvc.h:85
python.DomainsRegistry.reg
reg
globals -----------------------------------------------------------------—
Definition: DomainsRegistry.py:343
dq_make_web_display.recurse
def recurse(rdir, dqregion, ignorepath, reffile=None)
Definition: dq_make_web_display.py:23
TrigMonTHistSvc::getTEfficiencies
virtual StatusCode getTEfficiencies(TDirectory *, TList &, bool, bool) override
Definition: TrigMonTHistSvc.h:105
TrigMonTHistSvc::m_excludeType
Gaudi::Property< std::string > m_excludeType
Definition: TrigMonTHistSvc.h:146
TrigMonTHistSvc::getTTrees
virtual StatusCode getTTrees(TDirectory *, TList &, bool) const override
Definition: TrigMonTHistSvc.h:86
TrigMonTHistSvc::exists
virtual bool exists(const std::string &name) const override
Definition: TrigMonTHistSvc.h:76
TrigMonTHistSvc::TrigMonTHistSvc
TrigMonTHistSvc(const std::string &name, ISvcLocator *svc)
Definition: TrigMonTHistSvc.cxx:23
PrepareReferenceFile.regex
regex
Definition: PrepareReferenceFile.py:43
TrigMonTHistSvc::getShared
virtual StatusCode getShared(const std::string &, LockedHandle< TH1 > &) const override
Definition: TrigMonTHistSvc.cxx:365
TrigMonTHistSvc::regShared
virtual StatusCode regShared(const std::string &, std::unique_ptr< TGraph >, LockedHandle< TGraph > &) override
Definition: TrigMonTHistSvc.h:108
TrigMonTHistSvc::THistID::id
std::string id
Definition: TrigMonTHistSvc.h:125
TrigMonTHistSvc::deReg
virtual StatusCode deReg(TObject *obj) override
Definition: TrigMonTHistSvc.cxx:199
TrigMonTHistSvc::THistID::~THistID
~THistID()
Definition: TrigMonTHistSvc.h:124
TrigMonTHistSvc::getShared
virtual StatusCode getShared(const std::string &, LockedHandle< TGraph > &) const override
Definition: TrigMonTHistSvc.h:109
TrigMonTHistSvc::regEfficiency
virtual StatusCode regEfficiency(const std::string &, TEfficiency *) override
Definition: TrigMonTHistSvc.h:99
TrigMonTHistSvc::existsTree
virtual bool existsTree(const std::string &) const override
Definition: TrigMonTHistSvc.h:116
TrigMonTHistSvc::m_includeTypeRegex
boost::regex m_includeTypeRegex
Definition: TrigMonTHistSvc.h:162
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
TH3
Definition: rootspy.cxx:440
TrigMonTHistSvc::isObjectAllowed
bool isObjectAllowed(const std::string &path, const TObject *o) const
Does the histogram follow the naming rules ?
Definition: TrigMonTHistSvc.cxx:232
TrigMonTHistSvc::existsHist
virtual bool existsHist(const std::string &name) const override
Definition: TrigMonTHistSvc.cxx:261
TrigMonTHistSvc::regHist
virtual StatusCode regHist(const std::string &name) override
Definition: TrigMonTHistSvc.cxx:270
TrigMonTHistSvc::merge
virtual StatusCode merge(TObject *) override
Definition: TrigMonTHistSvc.h:114
Handler::svc
AthROOTErrorHandlerSvc * svc
Definition: AthROOTErrorHandlerSvc.cxx:10
python.Constants.WARNING
int WARNING
Definition: Control/AthenaCommon/python/Constants.py:17
TrigMonTHistSvc::getTHists
virtual StatusCode getTHists(TDirectory *td, TList &, bool recurse=false) const override
Definition: TrigMonTHistSvc.cxx:312
TrigMonTHistSvc::getTHists_i
StatusCode getTHists_i(const std::string &name, TList &) const
Get TList of registered histograms.
Definition: TrigMonTHistSvc.cxx:164
TrigMonTHistSvc::getHist
virtual StatusCode getHist(const std::string &id, TH1 *&hist, size_t ind) const override
Definition: TrigMonTHistSvc.cxx:292
TH2
Definition: rootspy.cxx:373
TrigMonTHistSvc::getEfficiency
virtual StatusCode getEfficiency(const std::string &, TEfficiency *&) const override
Definition: TrigMonTHistSvc.h:100
TrigMonTHistSvc::getShared_i
LockedHandle< T > getShared_i(const std::string &id) const
Definition: TrigMonTHistSvc.cxx:176
TrigMonTHistSvc
HLT online histogram service.
Definition: TrigMonTHistSvc.h:44
TrigMonTHistSvc::m_print
Gaudi::Property< bool > m_print
Definition: TrigMonTHistSvc.h:155
TrigMonTHistSvc::regHist_i
StatusCode regHist_i(std::unique_ptr< T > hist, const std::string &name, bool shared, THistID *&phid)
Definition: TrigMonTHistSvc.cxx:69
TrigMonTHistSvc::m_autoFlush
Gaudi::Property< int > m_autoFlush
Definition: TrigMonTHistSvc.h:154
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
NOSUPPORT
#define NOSUPPORT(lvl, what)
Definition: TrigMonTHistSvc.h:27
TrigMonTHistSvc::m_includeType
Gaudi::Property< std::string > m_includeType
Definition: TrigMonTHistSvc.h:147
TrigMonTHistSvc::existsGraph
virtual bool existsGraph(const std::string &) const override
Definition: TrigMonTHistSvc.h:117
TrigMonTHistSvc::getTEfficiencies
virtual StatusCode getTEfficiencies(const std::string &, TList &, bool) const override
Definition: TrigMonTHistSvc.h:104
TrigMonTHistSvc::regTree
virtual StatusCode regTree(const std::string &, TTree *) override
Definition: TrigMonTHistSvc.h:82
TrigMonTHistSvc::stop
virtual StatusCode stop() override
Definition: TrigMonTHistSvc.cxx:51
TrigMonTHistSvc::getTree
virtual StatusCode getTree(const std::string &, TTree *&) const override
Definition: TrigMonTHistSvc.h:83
TH1
Definition: rootspy.cxx:268
DEBUG
#define DEBUG
Definition: page_access.h:11
TrigMonTHistSvc::getGraphs
virtual std::vector< std::string > getGraphs() const override
Definition: TrigMonTHistSvc.h:94
TrigMonTHistSvc::getTTrees
virtual StatusCode getTTrees(const std::string &, TList &, bool, bool) override
Definition: TrigMonTHistSvc.h:89
AthService.h
TrigMonTHistSvc::getTEfficiencies
virtual StatusCode getTEfficiencies(TDirectory *, TList &, bool) const override
Definition: TrigMonTHistSvc.h:103
dqt_zlumi_alleff_HIST.tl
tl
Definition: dqt_zlumi_alleff_HIST.py:73
TrigMonTHistSvc::m_autoSave
Gaudi::Property< int > m_autoSave
Definition: TrigMonTHistSvc.h:153
TrigMonTHistSvc::m_includeNameRegex
boost::regex m_includeNameRegex
Definition: TrigMonTHistSvc.h:164
checker_macros.h
Define macros for attributes used to control the static checker.
python.PyAthena.obj
obj
Definition: PyAthena.py:132
TrigMonTHistSvc::THistID::obj
TObject * obj
Definition: TrigMonTHistSvc.h:126
TrigMonTHistSvc::regShared
virtual StatusCode regShared(const std::string &, std::unique_ptr< TEfficiency >, LockedHandle< TEfficiency > &) override
Definition: TrigMonTHistSvc.h:110
TrigMonTHistSvc::existsEfficiency
virtual bool existsEfficiency(const std::string &) const override
Definition: TrigMonTHistSvc.h:118
TrigMonTHistSvc::finalize
virtual StatusCode finalize() override
Definition: TrigMonTHistSvc.cxx:59
TrigMonTHistSvc::getTEfficiencies
virtual StatusCode getTEfficiencies(const std::string &, TList &, bool, bool) override
Definition: TrigMonTHistSvc.h:106
TrigMonTHistSvc::regTree
virtual StatusCode regTree(const std::string &) override
Definition: TrigMonTHistSvc.h:80
checkFileSG.ind
list ind
Definition: checkFileSG.py:118
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35
TrigMonTHistSvc::THistID::THistID
THistID(const std::string &s, TObject *o)
Definition: TrigMonTHistSvc.h:123