7#include "GaudiKernel/ISvcLocator.h"
12#include "hltinterface/IInfoRegister.h"
30 static TROOT root(
"root",
"ROOT I/O");
35 gErrorIgnoreLevel = kBreak;
38 m_excludeTypeRegex = boost::regex(m_excludeType.value());
39 m_includeTypeRegex = boost::regex(m_includeType.value());
40 m_excludeNameRegex = boost::regex(m_excludeName.value());
41 m_includeNameRegex = boost::regex(m_includeName.value());
46 hltinterface::IInfoRegister::instance()->getPublicationMutex());
48 return StatusCode::SUCCESS;
56 return StatusCode::SUCCESS;
65 return StatusCode::SUCCESS;
77 return StatusCode::FAILURE;
80 if (hist_unique->Class()->InheritsFrom(TH1::Class())) {
81 T* hist = hist_unique.release();
82 if (hltinterface::IInfoRegister::instance()->registerTObject(name(),
id, hist)) {
83 auto [iter,inserted] =
m_hists.try_emplace(
id,
id, hist);
85 ATH_MSG_ERROR(
"Histogram with name " <<
id <<
" already registered");
86 return StatusCode::FAILURE;
88 if (shared) iter->second.mutex =
new std::mutex;
91 << hist->GetName() <<
" registered under " <<
id <<
" " << name());
94 ATH_MSG_ERROR(
"Registration of " << hist->ClassName() <<
" with IInfoRegister failed");
96 return StatusCode::FAILURE;
101 <<
" because it does not inherit from TH1");
102 return StatusCode::FAILURE;
104 return StatusCode::SUCCESS;
112 LockedHandle<T> lh(
nullptr,
nullptr);
117 T* phist = hist.get();
119 if (
regHist_i(std::move(hist),
id,
true, phid).isSuccess()) {
120 lh.set(phist, phid->
mutex);
125 if (
h->second.mutex ==
nullptr) {
126 ATH_MSG_ERROR(
"regShared: previously registered histogram \"" <<
id
127 <<
"\" was not marked shared");
129 T* phist =
dynamic_cast<T*
>(
h->second.obj);
130 if (phist ==
nullptr) {
131 ATH_MSG_ERROR(
"regShared: unable to dcast retrieved shared hist \""
132 <<
id <<
"\" of type " <<
h->second.obj->IsA()->GetName()
133 <<
" to requested type " << System::typeinfoName(
typeid(T)));
136 lh.set(phist,
h->second.mutex);
154 T* phist =
dynamic_cast<T*
>(
h->second.obj);
155 if (phist ==
nullptr) {
156 ATH_MSG_ERROR(
"getHist: unable to dcast retrieved shared hist \""
157 <<
id <<
"\" of type " <<
h->second.obj->IsA()->GetName() <<
" to requested type "
158 << System::typeinfoName(
typeid(T)));
167 for (
const auto& [
id,
h] :
m_hists) {
168 if (
id.
find(dir) == 0) {
172 return StatusCode::SUCCESS;
181 if (
h->second.mutex ==
nullptr) {
183 <<
"\", but it's not marked as shared");
186 T* phist =
dynamic_cast<T*
>(
h->second.obj);
187 if (phist ==
nullptr) {
188 ATH_MSG_ERROR(
"getShared: unable to dcast retrieved shared hist \""
189 <<
id <<
"\" of type " <<
h->second.obj->IsA()->GetName()
190 <<
" to requested type " << System::typeinfoName(
typeid(T)));
193 return LockedHandle<T>(phist,
h->second.mutex);
195 ATH_MSG_ERROR(
"getShared: cannot find histogram with id \"" <<
id <<
"\"");
203 for (
const auto& [name, histid] :
m_hists) {
204 if (histid.obj == optr) {
205 ATH_MSG_DEBUG(
"Found histogram " << optr <<
" booked under " << name
206 <<
" and will deregister it");
210 return StatusCode::FAILURE;
218 hltinterface::IInfoRegister::instance()->releaseTObject(name(),
id);
220 return StatusCode::SUCCESS;
226 std::vector<std::string> l;
228 for (
const auto&
h :
m_hists) l.push_back(
h.first);
238 <<
" does NOT match IncludeType \"" <<
m_includeType <<
"\"");
243 ATH_MSG_WARNING(
"Object " << path <<
" of type " << o->ClassName() <<
" matches ExcludeType \""
272 std::unique_ptr<TH1> hist =
nullptr;
274 return regHist_i(std::move(hist),
id,
false, hid);
280 return regHist_i(std::move(hist),
id,
false, hid);
286 std::unique_ptr<TH1> hist(hist_ptr);
287 return regHist_i(std::move(hist),
id,
false, hid);
295 return (hist !=
nullptr ? StatusCode::SUCCESS : StatusCode::FAILURE);
301 return (hist !=
nullptr ? StatusCode::SUCCESS : StatusCode::FAILURE);
307 return (hist !=
nullptr ? StatusCode::SUCCESS : StatusCode::FAILURE);
314 if (recurse)
ATH_MSG_DEBUG(
"Recursive flag is not supported in this implementation");
315 return getTHists_i(std::string(td->GetPath()), tl);
320 if (recurse)
ATH_MSG_DEBUG(
"Recursive flag is not supported in this implementation");
327 ATH_MSG_DEBUG(
"Recursive flag and automatic registration flag is not "
328 "supported in this implementation");
329 return getTHists_i(std::string(td->GetPath()), tl);
335 ATH_MSG_DEBUG(
"Recursive flag and automatic registration flag is not "
336 "supported in this implementation");
343 LockedHandle<TH1>& lh)
346 return (lh ? StatusCode::SUCCESS : StatusCode::FAILURE);
350 LockedHandle<TH2>& lh)
353 return (lh ? StatusCode::SUCCESS : StatusCode::FAILURE);
357 LockedHandle<TH3>& lh)
360 return (lh ? StatusCode::SUCCESS : StatusCode::FAILURE);
368 return (lh ? StatusCode::SUCCESS : StatusCode::FAILURE);
374 return (lh ? StatusCode::SUCCESS : StatusCode::FAILURE);
380 return (lh ? StatusCode::SUCCESS : StatusCode::FAILURE);
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
OH histogram lock header file.
StatusCode TrigMonTHistSvc::initialize ATLAS_NOT_THREAD_SAFE()
Install fatal handler with default options.
Define macros for attributes used to control the static checker.
Header file for AthHistogramAlgorithm.
Gaudi::Property< std::string > m_excludeType
virtual bool existsHist(const std::string &name) const override
boost::regex m_excludeTypeRegex
virtual StatusCode finalize() override
Gaudi::Property< std::string > m_includeName
std::recursive_mutex m_svcMut
Protect access to histogram list.
boost::regex m_includeNameRegex
virtual StatusCode deReg(TObject *obj) override
Gaudi::Property< std::string > m_includeType
boost::regex m_excludeNameRegex
StatusCode getTHists_i(const std::string &name, TList &) const
Get TList of registered histograms.
boost::regex m_includeTypeRegex
LockedHandle< T > regShared_i(const std::string &id, std::unique_ptr< T > hist)
Gaudi::Property< std::string > m_excludeName
virtual StatusCode regHist(const std::string &name) override
StatusCode regHist_i(std::unique_ptr< T > hist, const std::string &name, bool shared, THistID *&phid)
virtual std::vector< std::string > getHists() const override
virtual StatusCode regShared(const std::string &, std::unique_ptr< TH1 >, LockedHandle< TH1 > &) override
virtual StatusCode stop() override
LockedHandle< T > getShared_i(const std::string &id) const
T * getHist_i(const std::string &id, const size_t &ind, bool quiet=false) const
virtual StatusCode getHist(const std::string &id, TH1 *&hist, size_t ind) const override
bool isObjectAllowed(const std::string &path, const TObject *o) const
Does the histogram follow the naming rules ?
std::unordered_map< std::string, THistID > m_hists
Registered histograms.
virtual StatusCode getShared(const std::string &, LockedHandle< TH1 > &) const override
TrigMonTHistSvc(const std::string &name, ISvcLocator *svc)
virtual StatusCode getTHists(TDirectory *td, TList &, bool recurse=false) const override
static void reset_histogram_mutex()
Reset (disable) histogram mutex.
static void set_histogram_mutex(std::mutex &mutex)
Set mutex to be used in oh_lock_histogram.
std::string find(const std::string &s)
return a remapped string
Helper struct that bundles the histogram, name and mutex.