ATLAS Offline Software
AthenaL1TopoHistSvc.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 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>
20 using namespace std;
21 
22 
24 {
25 public:
26 
28  TrigConfMessaging("AthenaL1TopoHistSvc"),
29  m_histSvc(histSvc)
30  {
31  TRG_MSG_INFO("Activating");
32  }
33 
35  {}
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 
118 private:
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 
131 {}
132 
134 {}
135 
136 void
138  m_impl->registerHist(h);
139 }
140 
141 void
143  m_impl->registerHist(h);
144 }
145 
146 TH1 *
148  return m_impl->findHist( histName );
149 }
150 
151 void
152 AthenaL1TopoHistSvc::fillHist1D(const std::string & histName, double x) {
153  m_impl->fillHist1D(histName,x);
154 }
155 
156 void
157 AthenaL1TopoHistSvc::fillHist2D(const std::string & histName, double x, double y) {
158  m_impl->fillHist2D(histName,x,y);
159 }
160 
161 void
162 AthenaL1TopoHistSvc::setBaseDir(const std::string & baseDir) {
163  m_impl->setBaseDir( baseDir );
164 }
165 
166 void
168  // not implemented
169 }
ReadHandleKey.h
Property holding a SG store/key/clid from which a ReadHandle is made.
AthenaL1TopoHistSvc::AthenaL1TopoHistSvcImpl::ATLAS_THREAD_SAFE
std::unordered_map< std::string, LockedHandle< TH1 > > m_hist1D ATLAS_THREAD_SAFE
Definition: AthenaL1TopoHistSvc.cxx:122
AthenaL1TopoHistSvc::AthenaL1TopoHistSvcImpl
Definition: AthenaL1TopoHistSvc.cxx:24
TRG_MSG_ERROR
#define TRG_MSG_ERROR(x)
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStreamMacros.h:29
IMonitorToolBase.h
DiTauMassTools::TauTypes::lh
@ lh
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:49
AthenaL1TopoHistSvc.h
AddEmptyComponent.histName
string histName
Definition: AddEmptyComponent.py:64
AthenaL1TopoHistSvc::AthenaL1TopoHistSvcImpl::registerHist
void registerHist(TH1 *h)
Definition: AthenaL1TopoHistSvc.cxx:38
WriteCellNoiseToCool.fullName
fullName
Definition: WriteCellNoiseToCool.py:461
CSV_InDetExporter.new
new
Definition: CSV_InDetExporter.py:145
AthenaL1TopoHistSvc::fillHist1D
virtual void fillHist1D(const std::string &histName, double x) override
Definition: AthenaL1TopoHistSvc.cxx:152
AthenaL1TopoHistSvc::save
virtual void save() override
Definition: AthenaL1TopoHistSvc.cxx:167
AthenaL1TopoHistSvc::AthenaL1TopoHistSvcImpl::setBaseDir
void setBaseDir(const std::string &baseDir)
Definition: AthenaL1TopoHistSvc.cxx:105
x
#define x
AthenaL1TopoHistSvc::AthenaL1TopoHistSvcImpl::~AthenaL1TopoHistSvcImpl
~AthenaL1TopoHistSvcImpl()
Definition: AthenaL1TopoHistSvc.cxx:34
h
extractSporadic.h
list h
Definition: extractSporadic.py:97
MuonSegmentReaderConfig.histSvc
histSvc
Definition: MuonSegmentReaderConfig.py:96
AthenaL1TopoHistSvc::AthenaL1TopoHistSvcImpl::ATLAS_THREAD_SAFE
std::unordered_map< std::string, LockedHandle< TH2 > > m_hist2D ATLAS_THREAD_SAFE
Definition: AthenaL1TopoHistSvc.cxx:123
AthenaL1TopoHistSvc::AthenaL1TopoHistSvcImpl::fillHist2D
void fillHist2D(const std::string &histName, double x, double y)
Definition: AthenaL1TopoHistSvc.cxx:96
AthenaL1TopoHistSvc::findHist
virtual TH1 * findHist(const std::string &histName) override
Definition: AthenaL1TopoHistSvc.cxx:147
TRG_MSG_INFO
#define TRG_MSG_INFO(x)
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStreamMacros.h:27
TRG_MSG_WARNING
#define TRG_MSG_WARNING(x)
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStreamMacros.h:28
AthenaL1TopoHistSvc::AthenaL1TopoHistSvcImpl::findHist
TH1 * findHist(const std::string &histName)
Definition: AthenaL1TopoHistSvc.cxx:78
TrigConf::TrigConfMessaging
Class to provide easy access to TrigConf::MsgStream for TrigConf classes.
Definition: TrigConfMessaging.h:28
AthenaL1TopoHistSvc::~AthenaL1TopoHistSvc
virtual ~AthenaL1TopoHistSvc()
Definition: AthenaL1TopoHistSvc.cxx:133
AthenaL1TopoHistSvc::setBaseDir
virtual void setBaseDir(const std::string &baseDir) override
Definition: AthenaL1TopoHistSvc.cxx:162
AthenaL1TopoHistSvc::AthenaL1TopoHistSvcImpl::m_histSvc
ServiceHandle< ITHistSvc > m_histSvc
Definition: AthenaL1TopoHistSvc.cxx:119
y
#define y
AthenaL1TopoHistSvc::fillHist2D
virtual void fillHist2D(const std::string &histName, double x, double y) override
Definition: AthenaL1TopoHistSvc.cxx:157
AthenaL1TopoHistSvc::AthenaL1TopoHistSvc
AthenaL1TopoHistSvc(ServiceHandle< ITHistSvc > histSvc)
Definition: AthenaL1TopoHistSvc.cxx:129
AthenaL1TopoHistSvc
Definition: AthenaL1TopoHistSvc.h:16
TrigConfMessaging.h
Messaging base class for TrigConf code shared with Lvl1 ( AthMessaging)
AthenaL1TopoHistSvc::m_impl
std::unique_ptr< AthenaL1TopoHistSvcImpl > m_impl
Definition: AthenaL1TopoHistSvc.h:37
AthenaL1TopoHistSvc::registerHist
virtual void registerHist(TH1 *h) override
Definition: AthenaL1TopoHistSvc.cxx:137
AthenaL1TopoHistSvc::AthenaL1TopoHistSvcImpl::AthenaL1TopoHistSvcImpl
AthenaL1TopoHistSvcImpl(ServiceHandle< ITHistSvc > histSvc)
Definition: AthenaL1TopoHistSvc.cxx:27
AthenaL1TopoHistSvc::AthenaL1TopoHistSvcImpl::registerHist
void registerHist(TH2 *h)
Definition: AthenaL1TopoHistSvc.cxx:58
TRG_MSG_DEBUG
#define TRG_MSG_DEBUG(x)
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStreamMacros.h:25
AthenaL1TopoHistSvc::AthenaL1TopoHistSvcImpl::fillHist1D
void fillHist1D(const std::string &histName, double x)
Definition: AthenaL1TopoHistSvc.cxx:88
ServiceHandle< ITHistSvc >
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37