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;
85 std::string histName(histRef.GetName());
86 const std::string histTitle(histRef.GetTitle());
87 std::string bookingString;
94 histRef.SetName(finalHistName.c_str());
97 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;
106 if (!
histSvc()->regHist(bookingString, &histRef).isSuccess()) {
107 m_msg << MSG::WARNING
108 <<
"Problem registering histogram with name " << histName
110 <<
", title " << histTitle
125 std::string effName(effRef.GetName());
126 const std::string effTitle(effRef.GetTitle());
127 std::string bookingString;
131 effRef.SetName(finalEffName.c_str());
134 EffMap_t::const_iterator it =
m_effMap.find(effHash);
136 m_msg << MSG::WARNING
137 <<
"Detected a hash collision. The hash for the TEfficiency with name=" << effName
138 <<
" already exists and points to a TEfficiency with name=" << it->second->GetName()
139 <<
" NOT going to book the new TEfficiency and returning a NULL pointer!" <<
endmsg;
143 if (!
histSvc()->regEfficiency(bookingString, &effRef).isSuccess()) {
144 m_msg << MSG::WARNING
145 <<
"Problem registering TEfficiency with name " << effName
147 <<
", title " << effTitle
154 m_effMap.insert(
m_effMap.end(), std::pair<const hash_t, TEfficiency*>(effHash, &effRef));
165 const std::string& tDir,
166 const std::string& stream)
168 std::string histNameCopy = histName;
169 std::string tDirCopy = tDir;
170 std::string streamCopy = stream;
172 std::string bookingString;
175 const hash_t histHash = this->
hash(histNameCopy);
177 HistMap_t::const_iterator it =
m_histMap.find(histHash);
179 TH1* histPointer(
nullptr);
181 if (!
histSvc()->getHist(bookingString, histPointer).isSuccess()) {
182 std::string prefixedHistNameCopy = histName;
183 std::string prefixedTDirCopy = tDir;
184 std::string prefixedStreamCopy = stream;
186 std::string prefixedBookingString;
188 prefixedHistNameCopy,
193 if (!
histSvc()->getHist(prefixedBookingString, histPointer).isSuccess()) {
194 m_msg << MSG::WARNING
195 <<
"Problem retrieving the histogram with name (including pre- and post-fixes) "
197 <<
" or with name " << histNameCopy
198 <<
" in " <<
m_name <<
"... it doesn't exist, neither in the cached map nor in the THistSvc!"
199 <<
" Will return an NULL pointer... you have to handle it correctly!" <<
endmsg;
204 m_histMap.insert(
m_histMap.end(), std::pair<const hash_t, TH1*>(histHash, histPointer));
217 EffMap_t::const_iterator it =
m_effMap.find( effHash );
222 std::string effNameCopy = effName;
223 std::string tDirCopy = tDir;
224 std::string streamCopy = stream;
227 std::string bookingString(
"");
230 TEfficiency* effPointer(NULL);
231 if ( !((
histSvc()->getEfficiency(bookingString, effPointer)).isSuccess()) )
234 std::string bookingString(
"");
237 if ( !((
histSvc()->getEfficiency(bookingString, effPointer)).isSuccess()) )
239 m_msg << MSG::WARNING
240 <<
"Problem retrieving the TEfficiency with name (including pre- and post-fixes) "
242 <<
" or with name " << effNameCopy
243 <<
" in " <<
m_name <<
"... it doesn't exist, neither in the cached map nor in the THistSvc!"
244 <<
" Will return an NULL pointer... you have to handle it correctly!" <<
endmsg;
249 m_effMap.insert(
m_effMap.end(), std::pair< const hash_t, TEfficiency* >( effHash, effPointer ) );
254 m_effMap.insert(
m_effMap.end(), std::pair< const hash_t, TEfficiency* >( effHash, effPointer ) );
276 const TTree* treePointer = &treeRef;
281 m_msg << MSG::WARNING
282 <<
"We got an invalid TTree pointer in the BookGetPointer(TTree*) method of the class" <<
m_name
288 std::string treeName = treePointer->GetName();
289 const std::string treeTitle = treePointer->GetTitle();
293 TreeMap_t::const_iterator it =
m_treeMap.find( treeHash );
296 m_msg << MSG::WARNING
297 <<
"Detected a hash collision. The hash for the TTree with name=" << treeName
298 <<
" already exists and points to a TTree with name=" << it->second->GetName()
299 <<
" NOT going to book the new histogram and returning a NULL pointer!" <<
endmsg;
304 TTree* treeClone =
dynamic_cast< TTree*
>( treePointer->Clone(treeName.c_str()) );
307 m_msg << MSG::WARNING
308 <<
"We couldn't clone the TTree in the BookGetPointer(TTree&) method of the class" <<
m_name
312 treeClone->SetTitle (treeTitle.c_str());
315 std::string bookingString(
"");
319 if ( !((
histSvc()->regTree(bookingString, treeClone)).isSuccess()) )
321 m_msg << MSG::WARNING
322 <<
"Problem registering TTree with name " << treeName
323 <<
", title " << treeTitle
329 m_treeMap.insert(
m_treeMap.end(), std::pair< const hash_t, TTree* >( treeHash, treeClone ) );
345 TreeMap_t::const_iterator it =
m_treeMap.find( treeHash );
350 std::string treeNameCopy = treeName;
351 std::string tDirCopy = tDir;
352 std::string streamCopy = stream;
355 std::string bookingString(
"");
358 TTree* treePointer(NULL);
359 if ( !((
histSvc()->getTree(bookingString, treePointer)).isSuccess()) )
361 m_msg << MSG::WARNING
362 <<
"Problem retrieving the TTree with name " << treeNameCopy
363 <<
" in " <<
m_name <<
"... it doesn't exist, neither in the cached map nor in the THistSvc!"
364 <<
" Will return an NULL pointer... you have to handle it correctly!" <<
endmsg;
369 m_treeMap.insert(
m_treeMap.end(), std::pair< const hash_t, TTree* >( treeHash, treePointer ) );
391 const TGraph* graphPointer = &graphRef;
396 m_msg << MSG::WARNING
397 <<
"We got an invalid TGraph pointer in the BookGetPointer(TGraph*) method of the class" <<
m_name
403 std::string graphName = graphPointer->GetName();
404 const std::string graphTitle = graphPointer->GetTitle();
407 const hash_t graphHash = this->
hash(graphName);
408 GraphMap_t::const_iterator it =
m_graphMap.find( graphHash );
411 m_msg << MSG::WARNING
412 <<
"Detected a hash collision. The hash for the TGraph with name=" << graphName
413 <<
" already exists and points to a TGraph with name=" << it->second->GetName()
414 <<
" NOT going to book the new histogram and returning a NULL pointer!" <<
endmsg;
422 m_msg << MSG::WARNING
423 <<
"We couldn't clone the TGraph in the BookGetPointer(TGraph&) method of the class" <<
m_name
430 std::string bookingString(
"");
434 if ( !((
histSvc()->regGraph(bookingString, graphClone)).isSuccess()) )
436 m_msg << MSG::WARNING
437 <<
"Problem registering TGraph with name " << graphName
438 <<
", title " << graphTitle
444 m_graphMap.insert(
m_graphMap.end(), std::pair< const hash_t, TGraph* >( graphHash, graphClone ) );
456 const hash_t graphHash = this->
hash(graphName);
459 GraphMap_t::const_iterator it =
m_graphMap.find( graphHash );
464 std::string graphNameCopy = graphName;
465 std::string tDirCopy = tDir;
466 std::string streamCopy = stream;
469 std::string bookingString(
"");
472 TGraph* graphPointer(
nullptr);
473 if ( !((
histSvc()->getGraph(bookingString, graphPointer)).isSuccess()) )
476 std::string bookingString(
"");
479 if ( !((
histSvc()->getGraph(bookingString, graphPointer)).isSuccess()) )
481 m_msg << MSG::WARNING
482 <<
"Problem retrieving the TGraph with name (including pre- and post-fixes) "
484 <<
" or with name " << graphNameCopy
485 <<
" in " <<
m_name <<
"... it doesn't exist, neither in the cached map nor in the THistSvc!"
486 <<
" Will return an NULL pointer... you have to handle it correctly!" <<
endmsg;
491 m_graphMap.insert(
m_graphMap.end(), std::pair< const hash_t, TGraph* >( graphHash, graphPointer ) );
496 m_graphMap.insert(
m_graphMap.end(), std::pair< const hash_t, TGraph* >( graphHash, graphPointer ) );
522 std::string& histName,
525 bool usePrefixPostfix)
529 size_t pos = histName.rfind(
'/');
530 if(pos != std::string::npos){
532 tDir.append(histName, 0,pos);
533 histName.erase(0,pos+1);
537 if(usePrefixPostfix){
540 bookingString =
"/"+stream+
"/"+tDir+
"/"+histName;
542 while(bookingString.find(
"//") != std::string::npos){
552 const std::string& oldStr,
553 const std::string& newStr)
556 while((pos =
str.find(oldStr, pos)) != std::string::npos)
558 str.replace(pos, oldStr.length(), newStr);
559 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....