42 if (
m_msg.level() <= MSG::VERBOSE )
m_msg << MSG::DEBUG <<
"Calling destructor of AthHistogramming" <<
endmsg;
52 const std::string& prefix,
const std::string& rootDir,
53 const std::string& histNamePrefix,
const std::string& histNamePostfix,
54 const std::string& histTitlePrefix,
const std::string& histTitlePostfix )
64 return StatusCode::SUCCESS;
86 std::string histName(histRef.GetName());
87 const std::string histTitle(histRef.GetTitle());
88 std::string bookingString(
"");
92 histRef.SetName(histName.c_str());
96 HistMap_t::const_iterator it =
m_histMap.find( histHash );
100 <<
"Detected a hash collision. The hash for the histogram with name=" << histName
101 <<
" already exists and points to a histogram with name=" << it->second->GetName()
102 <<
" NOT going to book the new histogram and returning a NULL pointer!" <<
endmsg;
112 if ( !((
histSvc()->regHist(bookingString, &histRef)).isSuccess()) )
114 m_msg << MSG::WARNING
115 <<
"Problem registering histogram with name " << histName
117 <<
", title " << histTitle
125 m_histMap.insert(
m_histMap.end(), std::pair< const hash_t, TH1* >( histHash, &histRef ) );
134 std::string effName(effRef.GetName());
135 const std::string effTitle(effRef.GetTitle());
136 std::string bookingString(
"");
140 effRef.SetName(effName.c_str());
144 EffMap_t::const_iterator it =
m_effMap.find( effHash );
147 m_msg << MSG::WARNING
148 <<
"Detected a hash collision. The hash for the TEfficiency with name=" << effName
149 <<
" already exists and points to a TEfficiency with name=" << it->second->GetName()
150 <<
" NOT going to book the new TEfficiency and returning a NULL pointer!" <<
endmsg;
160 if ( !((
histSvc()->regEfficiency(bookingString, &effRef)).isSuccess()) )
162 m_msg << MSG::WARNING
163 <<
"Problem registering TEfficiency with name " << effName
165 <<
", title " << effTitle
173 m_effMap.insert(
m_effMap.end(), std::pair< const hash_t, TEfficiency* >( effHash, &effRef ) );
189 HistMap_t::const_iterator it =
m_histMap.find( histHash );
194 std::string histNameCopy = histName;
195 std::string tDirCopy = tDir;
196 std::string streamCopy = stream;
199 std::string bookingString(
"");
202 TH1* histPointer(NULL);
203 if ( !((
histSvc()->getHist(bookingString, histPointer)).isSuccess()) )
206 std::string bookingString(
"");
209 if ( !((
histSvc()->getHist(bookingString, histPointer)).isSuccess()) )
211 m_msg << MSG::WARNING
212 <<
"Problem retrieving the histogram with name (including pre- and post-fixes) "
214 <<
" or with name " << histNameCopy
215 <<
" in " <<
m_name <<
"... it doesn't exist, neither in the cached map nor in the THistSvc!"
216 <<
" Will return an NULL pointer... you have to handle it correctly!" <<
endmsg;
221 m_histMap.insert(
m_histMap.end(), std::pair< const hash_t, TH1* >( histHash, histPointer ) );
226 m_histMap.insert(
m_histMap.end(), std::pair< const hash_t, TH1* >( histHash, histPointer ) );
241 EffMap_t::const_iterator it =
m_effMap.find( effHash );
246 std::string effNameCopy = effName;
247 std::string tDirCopy = tDir;
248 std::string streamCopy = stream;
251 std::string bookingString(
"");
254 TEfficiency* effPointer(NULL);
255 if ( !((
histSvc()->getEfficiency(bookingString, effPointer)).isSuccess()) )
258 std::string bookingString(
"");
261 if ( !((
histSvc()->getEfficiency(bookingString, effPointer)).isSuccess()) )
263 m_msg << MSG::WARNING
264 <<
"Problem retrieving the TEfficiency with name (including pre- and post-fixes) "
266 <<
" or with name " << effNameCopy
267 <<
" in " <<
m_name <<
"... it doesn't exist, neither in the cached map nor in the THistSvc!"
268 <<
" Will return an NULL pointer... you have to handle it correctly!" <<
endmsg;
273 m_effMap.insert(
m_effMap.end(), std::pair< const hash_t, TEfficiency* >( effHash, effPointer ) );
278 m_effMap.insert(
m_effMap.end(), std::pair< const hash_t, TEfficiency* >( effHash, effPointer ) );
300 const TTree* treePointer = &treeRef;
305 m_msg << MSG::WARNING
306 <<
"We got an invalid TTree pointer in the BookGetPointer(TTree*) method of the class" <<
m_name
312 std::string treeName = treePointer->GetName();
313 const std::string treeTitle = treePointer->GetTitle();
317 TreeMap_t::const_iterator it =
m_treeMap.find( treeHash );
320 m_msg << MSG::WARNING
321 <<
"Detected a hash collision. The hash for the TTree with name=" << treeName
322 <<
" already exists and points to a TTree with name=" << it->second->GetName()
323 <<
" NOT going to book the new histogram and returning a NULL pointer!" <<
endmsg;
328 TTree* treeClone =
dynamic_cast< TTree*
>( treePointer->Clone(treeName.c_str()) );
331 m_msg << MSG::WARNING
332 <<
"We couldn't clone the TTree in the BookGetPointer(TTree&) method of the class" <<
m_name
336 treeClone->SetTitle (treeTitle.c_str());
339 std::string bookingString(
"");
343 if ( !((
histSvc()->regTree(bookingString, treeClone)).isSuccess()) )
345 m_msg << MSG::WARNING
346 <<
"Problem registering TTree with name " << treeName
347 <<
", title " << treeTitle
353 m_treeMap.insert(
m_treeMap.end(), std::pair< const hash_t, TTree* >( treeHash, treeClone ) );
369 TreeMap_t::const_iterator it =
m_treeMap.find( treeHash );
374 std::string treeNameCopy = treeName;
375 std::string tDirCopy = tDir;
376 std::string streamCopy = stream;
379 std::string bookingString(
"");
382 TTree* treePointer(NULL);
383 if ( !((
histSvc()->getTree(bookingString, treePointer)).isSuccess()) )
385 m_msg << MSG::WARNING
386 <<
"Problem retrieving the TTree with name " << treeNameCopy
387 <<
" in " <<
m_name <<
"... it doesn't exist, neither in the cached map nor in the THistSvc!"
388 <<
" Will return an NULL pointer... you have to handle it correctly!" <<
endmsg;
393 m_treeMap.insert(
m_treeMap.end(), std::pair< const hash_t, TTree* >( treeHash, treePointer ) );
415 const TGraph* graphPointer = &graphRef;
420 m_msg << MSG::WARNING
421 <<
"We got an invalid TGraph pointer in the BookGetPointer(TGraph*) method of the class" <<
m_name
427 std::string graphName = graphPointer->GetName();
428 const std::string graphTitle = graphPointer->GetTitle();
431 const hash_t graphHash = this->
hash(graphName);
432 GraphMap_t::const_iterator it =
m_graphMap.find( graphHash );
435 m_msg << MSG::WARNING
436 <<
"Detected a hash collision. The hash for the TGraph with name=" << graphName
437 <<
" already exists and points to a TGraph with name=" << it->second->GetName()
438 <<
" NOT going to book the new histogram and returning a NULL pointer!" <<
endmsg;
446 m_msg << MSG::WARNING
447 <<
"We couldn't clone the TGraph in the BookGetPointer(TGraph&) method of the class" <<
m_name
454 std::string bookingString(
"");
458 if ( !((
histSvc()->regGraph(bookingString, graphClone)).isSuccess()) )
460 m_msg << MSG::WARNING
461 <<
"Problem registering TGraph with name " << graphName
462 <<
", title " << graphTitle
468 m_graphMap.insert(
m_graphMap.end(), std::pair< const hash_t, TGraph* >( graphHash, graphClone ) );
480 const hash_t graphHash = this->
hash(graphName);
483 GraphMap_t::const_iterator it =
m_graphMap.find( graphHash );
488 std::string graphNameCopy = graphName;
489 std::string tDirCopy = tDir;
490 std::string streamCopy = stream;
493 std::string bookingString(
"");
496 TGraph* graphPointer(NULL);
497 if ( !((
histSvc()->getGraph(bookingString, graphPointer)).isSuccess()) )
500 std::string bookingString(
"");
501 this->
buildBookingString( bookingString, graphNameCopy, tDirCopy, streamCopy,
false );
503 if ( !((
histSvc()->getGraph(bookingString, graphPointer)).isSuccess()) )
505 m_msg << MSG::WARNING
506 <<
"Problem retrieving the TGraph with name (including pre- and post-fixes) "
508 <<
" or with name " << graphNameCopy
509 <<
" in " <<
m_name <<
"... it doesn't exist, neither in the cached map nor in the THistSvc!"
510 <<
" Will return an NULL pointer... you have to handle it correctly!" <<
endmsg;
515 m_graphMap.insert(
m_graphMap.end(), std::pair< const hash_t, TGraph* >( graphHash, graphPointer ) );
520 m_graphMap.insert(
m_graphMap.end(), std::pair< const hash_t, TGraph* >( graphHash, graphPointer ) );
546 std::string& histName,
549 bool usePrefixPostfix)
553 size_t pos = histName.rfind(
'/');
554 if(pos != std::string::npos){
556 tDir.append(histName, 0,pos);
557 histName.erase(0,pos+1);
561 if(usePrefixPostfix){
564 bookingString =
"/"+stream+
"/"+tDir+
"/"+histName;
566 while(bookingString.find(
"//") != std::string::npos){
576 const std::string& oldStr,
577 const std::string& newStr)
580 while((pos =
str.find(oldStr, pos)) != std::string::npos)
582 str.replace(pos, oldStr.length(), newStr);
583 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....