ATLAS Offline Software
Loading...
Searching...
No Matches
AthenaL1TopoHistSvc.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6#include "TH1.h"
7#include "TH2.h"
8
10
11
13
14#include "GaudiKernel/ITHistSvc.h"
15
17
18
19#include <iostream>
20using namespace std;
21
22
24{
25public:
26
28 TrigConfMessaging("AthenaL1TopoHistSvc"),
29 m_histSvc(histSvc)
30 {
31 TRG_MSG_INFO("Activating");
32 }
33
36
37
38 void registerHist(TH1 * h) {
39 TRG_MSG_DEBUG("Registration of " << h->GetName() );
40 if(m_histSvc) {
41 string histName = h->GetName();
42 auto colPos = histName.find_first_of('/');
43 const string key = histName;
44 const string fullName( m_baseDir + histName );
45 h->SetName(histName.substr(colPos+1).c_str());
46 std::unique_ptr<TH1> uhist(h);
47 LockedHandle<TH1> lh;
48 if( ! m_histSvc->regShared(fullName, std::move(uhist), lh).isSuccess() ) {
49 TRG_MSG_WARNING("Could not register histogram " << fullName << " with " << m_histSvc->name() );
50 }
51 else
52 { m_hist1D[key] = lh; }
53 } else {
54 TRG_MSG_WARNING("No THistSvc available, can't register histogram");
55 }
56 }
57
58 void registerHist(TH2 * h) {
59 TRG_MSG_DEBUG("Registration of " << h->GetName() );
60 if(m_histSvc) {
61 string histName = h->GetName();
62 auto colPos = histName.find_first_of('/');
63 const string key = histName;
64 const string fullName( m_baseDir + histName );
65 h->SetName(histName.substr(colPos+1).c_str());
66 std::unique_ptr<TH2> uhist(h);
67 LockedHandle<TH2> lh;
68 if( ! m_histSvc->regShared(fullName, std::move(uhist), lh).isSuccess() ) {
69 TRG_MSG_WARNING("Could not register histogram " << fullName << " with " << m_histSvc->name() );
70 }
71 else
72 { m_hist2D[key] = lh; }
73 } else {
74 TRG_MSG_WARNING("No THistSvc available, can't register histogram");
75 }
76 }
77
78 TH1 * findHist(const std::string & histName) {
79 TH1 * h;
80 string fullName( m_baseDir + histName );
81 if ( ! m_histSvc->getHist(fullName, h).isSuccess() )
82 { TRG_MSG_WARNING("Could not find histogram with name : " << fullName ); }
83 else
84 { TRG_MSG_DEBUG("findHist(" << histName << ") found: " << (void*)h); }
85 return h;
86 }
87
88 void fillHist1D(const std::string & histName,double x) {
89 const string key = histName;
90 if(m_hist1D.find(key) == m_hist1D.end()) {
91 TRG_MSG_ERROR("1D-hist with registration key " << key << " does not exist");
92 }
93 else { m_hist1D[key]->Fill(x); }
94 }
95
96 void fillHist2D(const std::string & histName,double x,double y) {
97 const string key = histName;
98 if(m_hist2D.find(key) == m_hist2D.end()) {
99 TRG_MSG_ERROR("2D-hist with registration key " << key << " does not exist");
100 }
101 else
102 { m_hist2D[key]->Fill(x,y); }
103 }
104
105 void setBaseDir(const std::string & baseDir) {
106 auto colPos = baseDir.find_last_of(':');
107 if( colPos != string::npos ) {
108 m_baseDir = baseDir.substr(colPos+1);
109 } else {
110 m_baseDir = baseDir;
111 }
112 if( '/' != m_baseDir[m_baseDir.size()-1] ) {
113 // add a '/' at the end
114 m_baseDir += "/";
115 }
116 }
117
118private:
120 string m_baseDir {""};
121
122 std::unordered_map<std::string, LockedHandle<TH1>> m_hist1D ATLAS_THREAD_SAFE;
123 std::unordered_map<std::string, LockedHandle<TH2>> m_hist2D ATLAS_THREAD_SAFE;
124
125
126};
127
128
132
135
136void
138 m_impl->registerHist(h);
139}
140
141void
143 m_impl->registerHist(h);
144}
145
146TH1 *
147AthenaL1TopoHistSvc::findHist(const std::string & histName) {
148 return m_impl->findHist( histName );
149}
150
151void
152AthenaL1TopoHistSvc::fillHist1D(const std::string & histName, double x) {
153 m_impl->fillHist1D(histName,x);
154}
155
156void
157AthenaL1TopoHistSvc::fillHist2D(const std::string & histName, double x, double y) {
158 m_impl->fillHist2D(histName,x,y);
159}
160
161void
162AthenaL1TopoHistSvc::setBaseDir(const std::string & baseDir) {
163 m_impl->setBaseDir( baseDir );
164}
165
166void
168 // not implemented
169}
Property holding a SG store/key/clid from which a ReadHandle is made.
Messaging base class for TrigConf code shared with Lvl1 ( AthMessaging)
#define y
#define x
AthenaL1TopoHistSvcImpl(const ServiceHandle< ITHistSvc > &histSvc)
TH1 * findHist(const std::string &histName)
void fillHist2D(const std::string &histName, double x, double y)
std::unordered_map< std::string, LockedHandle< TH1 > > m_hist1D ATLAS_THREAD_SAFE
void fillHist1D(const std::string &histName, double x)
virtual void save() override
std::unique_ptr< AthenaL1TopoHistSvcImpl > m_impl
AthenaL1TopoHistSvc(const ServiceHandle< ITHistSvc > &histSvc)
virtual void registerHist(TH1 *h) override
virtual void fillHist2D(const std::string &histName, double x, double y) override
virtual void setBaseDir(const std::string &baseDir) override
virtual TH1 * findHist(const std::string &histName) override
virtual void fillHist1D(const std::string &histName, double x) override
Class to provide easy access to TrigConf::MsgStream for TrigConf classes.
TrigConfMessaging(const std::string &name)
Constructor with parameters.
STL namespace.