16 #include "GaudiKernel/MsgStream.h"
17 #include "GaudiKernel/ITHistSvc.h"
28 #include "TEfficiency.h"
42 m_histSvc (
"THistSvc/THistSvc",
name ),
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(
"");
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 ) );
564 bool usePrefixPostfix)
569 if(
pos != std::string::npos){
576 if(usePrefixPostfix){
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();