ATLAS Offline Software
StandaloneL1TopoHistSvc.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
5 #include "TFile.h"
6 #include "TH1.h"
7 #include "TH2.h"
8 
9 #include <iostream>
10 #include <map>
11 
13 
14 
16 {
17 public:
18 
20  TrigConfMessaging("StandaloneL1TopoHistSvc")
21  {}
22 
24  for( auto h : m_hists1D ) {
25  delete h.second;
26  }
27  for( auto h : m_hists2D ) {
28  delete h.second;
29  }
30  }
31 
32  void registerHist(TH1 * h) {
33  if(h != nullptr) {
34  TRG_MSG_DEBUG("Registering histogram " << h->GetName());
35  const std::string key = h->GetName();
36  if( m_hists1D.find(key) == end(m_hists1D) ) {
37  m_hists1D[key] = h;
38  } else {
39  TRG_MSG_WARNING("StandaloneL1TopoHistSvc::registerHist: a histogram " << key << " exists already. Will keep the first one and delete the newly requested.");
40  delete h;
41  }
42  }
43  }
44 
45  void registerHist(TH2 * h) {
46  if(h != nullptr) {
47  TRG_MSG_DEBUG("Registering histogram " << h->GetName());
48  const std::string key = h->GetName();
49  if( m_hists2D.find(key) == end(m_hists2D) ) {
50  m_hists2D[key] = h;
51  } else {
52  TRG_MSG_WARNING("StandaloneL1TopoHistSvc::registerHist: a histogram " << key << " exists already. Will keep the first one and delete the newly requested.");
53  delete h;
54  }
55  }
56  }
57 
58  TH1 * findHist(const std::string & histName) {
59  auto colPos = histName.find_first_of('/');
60  std::string realhistName = histName.substr(colPos+1);
61  auto h = m_hists1D.find(realhistName);
62  if( h == end(m_hists1D) ) {
63  return nullptr;
64  } else {
65  return h->second;
66  }
67  }
68 
69  void fillHist1D(const std::string & histName,double x) {
70  auto h = m_hists1D.find(histName);
71  if( h == end(m_hists1D) ) {
72  TRG_MSG_WARNING("No histogram found for " << histName);
73  } else
74  h->second->Fill(x);
75  }
76 
77  void fillHist2D(const std::string & histName,double x,double y) {
78  auto h = m_hists2D.find(histName);
79  if( h == end(m_hists2D) ) {
80  TRG_MSG_WARNING("No histogram found for " << histName);
81  } else
82  h->second->Fill(x,y);
83  }
84 
85  void setBaseDir(const std::string & baseDir) {
86  m_baseDir = baseDir;
87  }
88 
89  void save() {
90 
91  std::string filename = "L1Topo.root";
92  std::string basepath = "";
93 
94  std::string opt = "RECREATE";
95 
96  auto colPos = m_baseDir.find_last_of(':');
97  if( colPos != std::string::npos ) {
98  filename = m_baseDir.substr(0, colPos);
99  basepath = m_baseDir.substr(colPos+1);
100  } else {
102  }
103 
104 
105  TFile * f = TFile::Open(filename.c_str(),opt.c_str());
106  for( auto h : m_hists1D ) {
107 
108  std::string fullName(h.second->GetName());
109  std::string path(basepath);
110 
111  auto slashPos = fullName.find_last_of('/');
112  if(slashPos != std::string::npos) {
113  if(path!="")
114  path += "/";
115  path += fullName.substr(0,slashPos);
116  // set the name
117  h.second->SetName( fullName.substr(slashPos+1).c_str() );
118  }
119 
120  const char* dir = path.c_str();
121  if( ! f->GetDirectory(dir)) {
122  f->mkdir(dir);
123  }
124  f->cd(dir);
125  h.second->Write();
126  }
127  for( auto h : m_hists2D ) {
128 
129  std::string fullName(h.second->GetName());
130  std::string path(basepath);
131 
132  auto slashPos = fullName.find_last_of('/');
133  if(slashPos != std::string::npos) {
134  if(path!="")
135  path += "/";
136  path += fullName.substr(0,slashPos);
137  // set the name
138  h.second->SetName( fullName.substr(slashPos+1).c_str() );
139  }
140 
141  const char* dir = path.c_str();
142  if( ! f->GetDirectory(dir)) {
143  f->mkdir(dir);
144  }
145  f->cd(dir);
146  h.second->Write();
147  }
148  f->Write();
149  f->Close();
150  TRG_MSG_INFO("Wrote " << m_hists1D.size()+m_hists2D.size() << " l1topo algorithm histograms to file " << filename);
151  }
152 
153 private:
154 
155  std::map<std::string,TH1*> m_hists1D;
156  std::map<std::string,TH2*> m_hists2D;
157  std::string m_baseDir {""};
158 
159 };
160 
161 
162 
163 
164 // the interface class
165 
168 {}
169 
171 {}
172 
173 // forwarding the calls from the interface class
174 
175 void
177  //cout << "Called StandaloneL1TopoHistSvc::registerHist(" << h->GetName() << ")" << endl;
178  m_impl->registerHist(h);
179 }
180 
181 void
183  //cout << "Called StandaloneL1TopoHistSvc::registerHist(" << h->GetName() << ")" << endl;
184  m_impl->registerHist(h);
185 }
186 
187 TH1 *
189  //cout << "Called StandaloneL1TopoHistSvc::findHist(" << histName << ")" << endl;
190  return m_impl->findHist(histName);
191 }
192 
193 void StandaloneL1TopoHistSvc::fillHist1D(const std::string & histName, double x) {
194  m_impl->fillHist1D(histName,x);
195 }
196 
197 void StandaloneL1TopoHistSvc::fillHist2D(const std::string & histName, double x, double y) {
198  m_impl->fillHist2D(histName,x,y);
199 }
200 
201 void
202 StandaloneL1TopoHistSvc::setBaseDir(const std::string & baseDir) {
203  m_impl->setBaseDir(baseDir);
204 }
205 
206 
207 void
209  m_impl->save();
210 }
211 
212 
213 
python.CaloRecoConfig.f
f
Definition: CaloRecoConfig.py:127
StandaloneL1TopoHistSvc::StandaloneL1TopoHistSvcImpl::findHist
TH1 * findHist(const std::string &histName)
Definition: StandaloneL1TopoHistSvc.cxx:58
athena.path
path
python interpreter configuration --------------------------------------—
Definition: athena.py:126
AddEmptyComponent.histName
string histName
Definition: AddEmptyComponent.py:64
WriteCellNoiseToCool.fullName
fullName
Definition: WriteCellNoiseToCool.py:461
CSV_InDetExporter.new
new
Definition: CSV_InDetExporter.py:145
StandaloneL1TopoHistSvc::StandaloneL1TopoHistSvcImpl::fillHist2D
void fillHist2D(const std::string &histName, double x, double y)
Definition: StandaloneL1TopoHistSvc.cxx:77
StandaloneL1TopoHistSvc::StandaloneL1TopoHistSvcImpl::m_baseDir
std::string m_baseDir
Definition: StandaloneL1TopoHistSvc.cxx:157
StandaloneL1TopoHistSvc::StandaloneL1TopoHistSvcImpl::registerHist
void registerHist(TH2 *h)
Definition: StandaloneL1TopoHistSvc.cxx:45
x
#define x
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
StandaloneL1TopoHistSvc
Definition: StandaloneL1TopoHistSvc.h:12
StandaloneL1TopoHistSvc::StandaloneL1TopoHistSvcImpl::setBaseDir
void setBaseDir(const std::string &baseDir)
Definition: StandaloneL1TopoHistSvc.cxx:85
StandaloneL1TopoHistSvc::m_impl
std::unique_ptr< StandaloneL1TopoHistSvcImpl > m_impl
Definition: StandaloneL1TopoHistSvc.h:33
extractSporadic.h
list h
Definition: extractSporadic.py:97
TrigConf::TrigConfMessaging::TrigConfMessaging
TrigConfMessaging()=delete
StandaloneL1TopoHistSvc::StandaloneL1TopoHistSvcImpl::StandaloneL1TopoHistSvcImpl
StandaloneL1TopoHistSvcImpl()
Definition: StandaloneL1TopoHistSvc.cxx:19
StandaloneL1TopoHistSvc::StandaloneL1TopoHistSvc
StandaloneL1TopoHistSvc()
Definition: StandaloneL1TopoHistSvc.cxx:166
StandaloneL1TopoHistSvc::setBaseDir
virtual void setBaseDir(const std::string &baseDir) override
Definition: StandaloneL1TopoHistSvc.cxx:202
StandaloneL1TopoHistSvc::fillHist1D
virtual void fillHist1D(const std::string &histName, double x) override
Definition: StandaloneL1TopoHistSvc.cxx:193
StandaloneL1TopoHistSvc::StandaloneL1TopoHistSvcImpl::m_hists2D
std::map< std::string, TH2 * > m_hists2D
Definition: StandaloneL1TopoHistSvc.cxx:156
StandaloneL1TopoHistSvc::StandaloneL1TopoHistSvcImpl::m_hists1D
std::map< std::string, TH1 * > m_hists1D
Definition: StandaloneL1TopoHistSvc.cxx:155
TH2
Definition: rootspy.cxx:373
TRG_MSG_INFO
#define TRG_MSG_INFO(x)
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStreamMacros.h:27
beamspotman.dir
string dir
Definition: beamspotman.py:623
beamspotman.basepath
string basepath
Definition: beamspotman.py:1018
TRG_MSG_WARNING
#define TRG_MSG_WARNING(x)
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStreamMacros.h:28
pmontree.opt
opt
Definition: pmontree.py:16
StandaloneL1TopoHistSvc::StandaloneL1TopoHistSvcImpl
Definition: StandaloneL1TopoHistSvc.cxx:16
TrigConf::TrigConfMessaging
Class to provide easy access to TrigConf::MsgStream for TrigConf classes.
Definition: TrigConfMessaging.h:28
StandaloneL1TopoHistSvc::StandaloneL1TopoHistSvcImpl::save
void save()
Definition: StandaloneL1TopoHistSvc.cxx:89
StandaloneL1TopoHistSvc::StandaloneL1TopoHistSvcImpl::fillHist1D
void fillHist1D(const std::string &histName, double x)
Definition: StandaloneL1TopoHistSvc.cxx:69
StandaloneL1TopoHistSvc::StandaloneL1TopoHistSvcImpl::~StandaloneL1TopoHistSvcImpl
~StandaloneL1TopoHistSvcImpl()
Definition: StandaloneL1TopoHistSvc.cxx:23
y
#define y
h
StandaloneL1TopoHistSvc::findHist
virtual TH1 * findHist(const std::string &histName) override
Definition: StandaloneL1TopoHistSvc.cxx:188
StandaloneL1TopoHistSvc::registerHist
virtual void registerHist(TH1 *h) override
Definition: StandaloneL1TopoHistSvc.cxx:176
TH1
Definition: rootspy.cxx:268
StandaloneL1TopoHistSvc::fillHist2D
virtual void fillHist2D(const std::string &histName, double x, double y) override
Definition: StandaloneL1TopoHistSvc.cxx:197
CaloCellTimeCorrFiller.filename
filename
Definition: CaloCellTimeCorrFiller.py:24
StandaloneL1TopoHistSvc::~StandaloneL1TopoHistSvc
virtual ~StandaloneL1TopoHistSvc()
Definition: StandaloneL1TopoHistSvc.cxx:170
TrigConfMessaging.h
Messaging base class for TrigConf code shared with Lvl1 ( AthMessaging)
StandaloneL1TopoHistSvc::StandaloneL1TopoHistSvcImpl::registerHist
void registerHist(TH1 *h)
Definition: StandaloneL1TopoHistSvc.cxx:32
TRG_MSG_DEBUG
#define TRG_MSG_DEBUG(x)
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStreamMacros.h:25
StandaloneL1TopoHistSvc.h
StandaloneL1TopoHistSvc::save
virtual void save() override
Definition: StandaloneL1TopoHistSvc.cxx:208
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37