16#include "GaudiKernel/MsgStream.h"
17#include "GaudiKernel/ITHistSvc.h"
28#include "TEfficiency.h"
57 if (
m_msg.level() <= MSG::VERBOSE )
m_msg << MSG::DEBUG <<
"Calling destructor of AthHistogramming" <<
endmsg;
67 const std::string& prefix,
const std::string& rootDir,
68 const std::string& histNamePrefix,
const std::string& histNamePostfix,
69 const std::string& histTitlePrefix,
const std::string& histTitlePostfix )
79 return StatusCode::SUCCESS;
101 std::string histName(histRef.GetName());
102 const std::string histTitle(histRef.GetTitle());
103 std::string bookingString(
"");
107 histRef.SetName(histName.c_str());
111 HistMap_t::const_iterator it =
m_histMap.find( histHash );
114 m_msg << MSG::WARNING
115 <<
"Detected a hash collision. The hash for the histogram with name=" << histName
116 <<
" already exists and points to a histogram with name=" << it->second->GetName()
117 <<
" NOT going to book the new histogram and returning a NULL pointer!" <<
endmsg;
127 if ( !((
histSvc()->regHist(bookingString, &histRef)).isSuccess()) )
129 m_msg << MSG::WARNING
130 <<
"Problem registering histogram with name " << histName
132 <<
", title " << histTitle
140 m_histMap.insert(
m_histMap.end(), std::pair< const hash_t, TH1* >( histHash, &histRef ) );
149 std::string effName(effRef.GetName());
150 const std::string effTitle(effRef.GetTitle());
151 std::string bookingString(
"");
155 effRef.SetName(effName.c_str());
159 EffMap_t::const_iterator it =
m_effMap.find( effHash );
162 m_msg << MSG::WARNING
163 <<
"Detected a hash collision. The hash for the TEfficiency with name=" << effName
164 <<
" already exists and points to a TEfficiency with name=" << it->second->GetName()
165 <<
" NOT going to book the new TEfficiency and returning a NULL pointer!" <<
endmsg;
175 if ( !((
histSvc()->regEfficiency(bookingString, &effRef)).isSuccess()) )
177 m_msg << MSG::WARNING
178 <<
"Problem registering TEfficiency with name " << effName
180 <<
", title " << effTitle
188 m_effMap.insert(
m_effMap.end(), std::pair< const hash_t, TEfficiency* >( effHash, &effRef ) );
204 HistMap_t::const_iterator it =
m_histMap.find( histHash );
209 std::string histNameCopy = histName;
210 std::string tDirCopy = tDir;
211 std::string streamCopy = stream;
214 std::string bookingString(
"");
217 TH1* histPointer(NULL);
218 if ( !((
histSvc()->getHist(bookingString, histPointer)).isSuccess()) )
221 std::string bookingString(
"");
224 if ( !((
histSvc()->getHist(bookingString, histPointer)).isSuccess()) )
226 m_msg << MSG::WARNING
227 <<
"Problem retrieving the histogram with name (including pre- and post-fixes) "
229 <<
" or with name " << histNameCopy
230 <<
" in " <<
m_name <<
"... it doesn't exist, neither in the cached map nor in the THistSvc!"
231 <<
" Will return an NULL pointer... you have to handle it correctly!" <<
endmsg;
236 m_histMap.insert(
m_histMap.end(), std::pair< const hash_t, TH1* >( histHash, histPointer ) );
241 m_histMap.insert(
m_histMap.end(), std::pair< const hash_t, TH1* >( histHash, histPointer ) );
256 EffMap_t::const_iterator it =
m_effMap.find( effHash );
261 std::string effNameCopy = effName;
262 std::string tDirCopy = tDir;
263 std::string streamCopy = stream;
266 std::string bookingString(
"");
269 TEfficiency* effPointer(NULL);
270 if ( !((
histSvc()->getEfficiency(bookingString, effPointer)).isSuccess()) )
273 std::string bookingString(
"");
276 if ( !((
histSvc()->getEfficiency(bookingString, effPointer)).isSuccess()) )
278 m_msg << MSG::WARNING
279 <<
"Problem retrieving the TEfficiency with name (including pre- and post-fixes) "
281 <<
" or with name " << effNameCopy
282 <<
" in " <<
m_name <<
"... it doesn't exist, neither in the cached map nor in the THistSvc!"
283 <<
" Will return an NULL pointer... you have to handle it correctly!" <<
endmsg;
288 m_effMap.insert(
m_effMap.end(), std::pair< const hash_t, TEfficiency* >( effHash, effPointer ) );
293 m_effMap.insert(
m_effMap.end(), std::pair< const hash_t, TEfficiency* >( effHash, effPointer ) );
315 const TTree* treePointer = &treeRef;
320 m_msg << MSG::WARNING
321 <<
"We got an invalid TTree pointer in the BookGetPointer(TTree*) method of the class" <<
m_name
327 std::string treeName = treePointer->GetName();
328 const std::string treeTitle = treePointer->GetTitle();
332 TreeMap_t::const_iterator it =
m_treeMap.find( treeHash );
335 m_msg << MSG::WARNING
336 <<
"Detected a hash collision. The hash for the TTree with name=" << treeName
337 <<
" already exists and points to a TTree with name=" << it->second->GetName()
338 <<
" NOT going to book the new histogram and returning a NULL pointer!" <<
endmsg;
343 TTree* treeClone =
dynamic_cast< TTree*
>( treePointer->Clone(treeName.c_str()) );
346 m_msg << MSG::WARNING
347 <<
"We couldn't clone the TTree in the BookGetPointer(TTree&) method of the class" <<
m_name
351 treeClone->SetTitle (treeTitle.c_str());
354 std::string bookingString(
"");
358 if ( !((
histSvc()->regTree(bookingString, treeClone)).isSuccess()) )
360 m_msg << MSG::WARNING
361 <<
"Problem registering TTree with name " << treeName
362 <<
", title " << treeTitle
368 m_treeMap.insert(
m_treeMap.end(), std::pair< const hash_t, TTree* >( treeHash, treeClone ) );
384 TreeMap_t::const_iterator it =
m_treeMap.find( treeHash );
389 std::string treeNameCopy = treeName;
390 std::string tDirCopy = tDir;
391 std::string streamCopy = stream;
394 std::string bookingString(
"");
397 TTree* treePointer(NULL);
398 if ( !((
histSvc()->getTree(bookingString, treePointer)).isSuccess()) )
400 m_msg << MSG::WARNING
401 <<
"Problem retrieving the TTree with name " << treeNameCopy
402 <<
" in " <<
m_name <<
"... it doesn't exist, neither in the cached map nor in the THistSvc!"
403 <<
" Will return an NULL pointer... you have to handle it correctly!" <<
endmsg;
408 m_treeMap.insert(
m_treeMap.end(), std::pair< const hash_t, TTree* >( treeHash, treePointer ) );
430 const TGraph* graphPointer = &graphRef;
435 m_msg << MSG::WARNING
436 <<
"We got an invalid TGraph pointer in the BookGetPointer(TGraph*) method of the class" <<
m_name
442 std::string graphName = graphPointer->GetName();
443 const std::string graphTitle = graphPointer->GetTitle();
446 const hash_t graphHash = this->
hash(graphName);
447 GraphMap_t::const_iterator it =
m_graphMap.find( graphHash );
450 m_msg << MSG::WARNING
451 <<
"Detected a hash collision. The hash for the TGraph with name=" << graphName
452 <<
" already exists and points to a TGraph with name=" << it->second->GetName()
453 <<
" NOT going to book the new histogram and returning a NULL pointer!" <<
endmsg;
461 m_msg << MSG::WARNING
462 <<
"We couldn't clone the TGraph in the BookGetPointer(TGraph&) method of the class" <<
m_name
469 std::string bookingString(
"");
473 if ( !((
histSvc()->regGraph(bookingString, graphClone)).isSuccess()) )
475 m_msg << MSG::WARNING
476 <<
"Problem registering TGraph with name " << graphName
477 <<
", title " << graphTitle
483 m_graphMap.insert(
m_graphMap.end(), std::pair< const hash_t, TGraph* >( graphHash, graphClone ) );
495 const hash_t graphHash = this->
hash(graphName);
498 GraphMap_t::const_iterator it =
m_graphMap.find( graphHash );
503 std::string graphNameCopy = graphName;
504 std::string tDirCopy = tDir;
505 std::string streamCopy = stream;
508 std::string bookingString(
"");
511 TGraph* graphPointer(NULL);
512 if ( !((
histSvc()->getGraph(bookingString, graphPointer)).isSuccess()) )
515 std::string bookingString(
"");
516 this->
buildBookingString( bookingString, graphNameCopy, tDirCopy, streamCopy,
false );
518 if ( !((
histSvc()->getGraph(bookingString, graphPointer)).isSuccess()) )
520 m_msg << MSG::WARNING
521 <<
"Problem retrieving the TGraph with name (including pre- and post-fixes) "
523 <<
" or with name " << graphNameCopy
524 <<
" in " <<
m_name <<
"... it doesn't exist, neither in the cached map nor in the THistSvc!"
525 <<
" Will return an NULL pointer... you have to handle it correctly!" <<
endmsg;
530 m_graphMap.insert(
m_graphMap.end(), std::pair< const hash_t, TGraph* >( graphHash, graphPointer ) );
535 m_graphMap.insert(
m_graphMap.end(), std::pair< const hash_t, TGraph* >( graphHash, graphPointer ) );
561 std::string& histName,
564 bool usePrefixPostfix)
568 size_t pos = histName.rfind(
'/');
569 if(pos != std::string::npos){
571 tDir.append(histName, 0,pos);
572 histName.erase(0,pos+1);
576 if(usePrefixPostfix){
579 bookingString =
"/"+stream+
"/"+tDir+
"/"+histName;
581 while(bookingString.find(
"//") != std::string::npos){
591 const std::string& oldStr,
592 const std::string& newStr)
595 while((pos =
str.find(oldStr, pos)) != std::string::npos)
597 str.replace(pos, oldStr.length(), newStr);
598 pos += newStr.length();
const ServiceHandle< ITHistSvc > & histSvc() const
The standard THistSvc (for writing histograms and TTrees and more to a root file) Returns (kind of) a...
HistMap_t m_histMap
The map of histogram names to their pointers.
TTree * tree(const std::string &treeName, const std::string &tDir="", const std::string &stream="")
Simplify the retrieval of registered TTrees.
ServiceHandle< ITHistSvc > m_histSvc
Pointer to the THistSvc (event store by default)
std::string m_histNamePostfix
The postfix for the histogram THx name.
hash_t hash(const std::string &histName) const
Method to calculate a 32-bit hash from a string.
std::string m_rootDir
Name of the ROOT directory.
uint32_t hash_t
typedef for the internal hash
TH1 * bookGetPointer(const TH1 &hist, const std::string &tDir="", const std::string &stream="")
Simplify the booking and registering (into THistSvc) of histograms.
std::string m_histTitlePostfix
The postfix for the histogram THx title.
TH1 * hist(const std::string &histName, const std::string &tDir="", const std::string &stream="")
Simplify the retrieval of registered histograms of any type.
virtual ~AthHistogramming()
Destructor:
AthHistogramming(const std::string &name)
Constructor with parameters:
TreeMap_t m_treeMap
The map of TTree names to their pointers.
std::string m_histTitlePrefix
The prefix for the histogram THx title.
std::string m_streamName
Name of the ROOT output stream (file)
StatusCode configAthHistogramming(const ServiceHandle< ITHistSvc > &histSvc, const std::string &prefix, const std::string &rootDir, const std::string &histNamePrefix, const std::string &histNamePostfix, const std::string &histTitlePrefix, const std::string &histTitlePostfix)
To be called by the derived classes to fill the internal configuration.
std::string m_name
Instance name.
MsgStream m_msg
Cached Message Stream.
void buildBookingString(std::string &bookingString, std::string &histName, std::string &tDir, std::string &stream, bool usePrefixPostfix=false)
Method to build individual booking string.
EffMap_t m_effMap
The map of histogram names to their pointers.
TEfficiency * efficiency(const std::string &effName, const std::string &tDir="", const std::string &stream="")
Simplify the retrieval of registered TEfficiency.
void myReplace(std::string &str, const std::string &oldStr, const std::string &newStr)
Helper method to replace sub-string.
TGraph * graph(const std::string &graphName, const std::string &tDir="", const std::string &stream="")
Simplify the retrieval of registered TGraphs.
std::string m_histNamePrefix
The prefix for the histogram THx name.
GraphMap_t m_graphMap
The map of TGraph names to their pointers.
singleton-like access to IMessageSvc via open function and helper
Some weak symbol referencing magic... These are declared in AthenaKernel/getMessageSvc....