21 std::pair<std::string_view, std::string_view>
22 splitName(std::string_view name){
23 const auto pos =
name.rfind(
'/');
24 if (pos == std::string_view::npos){
27 return {
name.substr(0,pos),
name.substr(pos+1)};
55 if (
m_msg.level() <= MSG::VERBOSE )
m_msg << MSG::DEBUG <<
"Calling destructor of AthHistogramming" <<
endmsg;
65 const std::string& prefix,
const std::string& rootDir,
66 const std::string& histNamePrefix,
const std::string& histNamePostfix,
67 const std::string& histTitlePrefix,
const std::string& histTitlePostfix )
77 return StatusCode::SUCCESS;
99 const std::string originalName{histRef.GetName()};
100 const auto histName = splitName(originalName).second;
102 const std::string histTitle(histRef.GetTitle());
106 finalHistName += histName;
110 histRef.SetName(finalHistName.c_str());
113 HistMap_t::const_iterator it =
m_histMap.find(histHash);
115 m_msg << MSG::WARNING
116 <<
"Detected a hash collision. The hash for the histogram with name=" << histName
117 <<
" already exists and points to a histogram with name=" << it->second->GetName()
118 <<
" NOT going to book the new histogram and returning a NULL pointer!" <<
endmsg;
122 if (!
histSvc()->regHist(bookingString, &histRef).isSuccess()) {
123 m_msg << MSG::WARNING
124 <<
"Problem registering histogram with name " << histName
126 <<
", title " << histTitle
141 std::string originalName{effRef.GetName()};
142 const auto effName = splitName(originalName).second;
143 const std::string effTitle(effRef.GetTitle());
146 finalEffName += effName;
149 effRef.SetName(finalEffName.c_str());
152 EffMap_t::const_iterator it =
m_effMap.find(effHash);
154 m_msg << MSG::WARNING
155 <<
"Detected a hash collision. The hash for the TEfficiency with name=" << effName
156 <<
" already exists and points to a TEfficiency with name=" << it->second->GetName()
157 <<
" NOT going to book the new TEfficiency and returning a NULL pointer!" <<
endmsg;
161 if (!
histSvc()->regEfficiency(bookingString, &effRef).isSuccess()) {
162 m_msg << MSG::WARNING
163 <<
"Problem registering TEfficiency with name " << effName
165 <<
", title " << effTitle
172 m_effMap.insert(
m_effMap.end(), std::pair<const hash_t, TEfficiency*>(effHash, &effRef));
183 std::string_view stream){
185 const auto histBaseName = splitName(histName).second;
188 const hash_t histHash = this->
hash(histBaseName);
190 HistMap_t::const_iterator it =
m_histMap.find(histHash);
192 TH1* histPointer(
nullptr);
194 if (!
histSvc()->getHist(bookingString, histPointer).isSuccess()) {
196 if (!
histSvc()->getHist(prefixedBookingString, histPointer).isSuccess()) {
197 m_msg << MSG::WARNING
198 <<
"Problem retrieving the histogram with name (including pre- and post-fixes) "
199 << prefixedBookingString
200 <<
" or with name " << histName
201 <<
" in " <<
m_name <<
"... it doesn't exist, neither in the cached map nor in the THistSvc!"
202 <<
" Will return an NULL pointer... you have to handle it correctly!" <<
endmsg;
207 m_histMap.insert(
m_histMap.end(), std::pair<const hash_t, TH1*>(histHash, histPointer));
220 EffMap_t::const_iterator it =
m_effMap.find( effHash );
226 TEfficiency* effPointer{};
227 if ( !((
histSvc()->getEfficiency(bookingString, effPointer)).isSuccess()) )
232 if ( !((
histSvc()->getEfficiency(bookingString, effPointer)).isSuccess()) )
234 m_msg << MSG::WARNING
235 <<
"Problem retrieving the TEfficiency with name (including pre- and post-fixes) "
237 <<
" or with name " << effName
238 <<
" in " <<
m_name <<
"... it doesn't exist, neither in the cached map nor in the THistSvc!"
239 <<
" Will return an NULL pointer... you have to handle it correctly!" <<
endmsg;
244 m_effMap.insert(
m_effMap.end(), std::pair< const hash_t, TEfficiency* >( effHash, effPointer ) );
249 m_effMap.insert(
m_effMap.end(), std::pair< const hash_t, TEfficiency* >( effHash, effPointer ) );
271 const TTree* treePointer = &treeRef;
276 m_msg << MSG::WARNING
277 <<
"We got an invalid TTree pointer in the BookGetPointer(TTree*) method of the class" <<
m_name
283 std::string treeName = treePointer->GetName();
284 const std::string treeTitle = treePointer->GetTitle();
288 TreeMap_t::const_iterator it =
m_treeMap.find( treeHash );
291 m_msg << MSG::WARNING
292 <<
"Detected a hash collision. The hash for the TTree with name=" << treeName
293 <<
" already exists and points to a TTree with name=" << it->second->GetName()
294 <<
" NOT going to book the new histogram and returning a NULL pointer!" <<
endmsg;
299 TTree* treeClone =
dynamic_cast< TTree*
>( treePointer->Clone(treeName.c_str()) );
302 m_msg << MSG::WARNING
303 <<
"We couldn't clone the TTree in the BookGetPointer(TTree&) method of the class" <<
m_name
307 treeClone->SetTitle (treeTitle.c_str());
313 if ( !((
histSvc()->regTree(bookingString, treeClone)).isSuccess()) )
315 m_msg << MSG::WARNING
316 <<
"Problem registering TTree with name " << treeName
317 <<
", title " << treeTitle
323 m_treeMap.insert(
m_treeMap.end(), std::pair< const hash_t, TTree* >( treeHash, treeClone ) );
338 TreeMap_t::const_iterator it =
m_treeMap.find( treeHash );
344 TTree* treePointer(NULL);
345 if ( !((
histSvc()->getTree(bookingString, treePointer)).isSuccess()) )
347 m_msg << MSG::WARNING
348 <<
"Problem retrieving the TTree with name " << treeName
349 <<
" in " <<
m_name <<
"... it doesn't exist, neither in the cached map nor in the THistSvc!"
350 <<
" Will return an NULL pointer... you have to handle it correctly!" <<
endmsg;
355 m_treeMap.insert(
m_treeMap.end(), std::pair< const hash_t, TTree* >( treeHash, treePointer ) );
377 const TGraph* graphPointer = &graphRef;
382 m_msg << MSG::WARNING
383 <<
"We got an invalid TGraph pointer in the BookGetPointer(TGraph*) method of the class" <<
m_name
389 std::string graphName = graphPointer->GetName();
390 const std::string graphTitle = graphPointer->GetTitle();
393 const hash_t graphHash = this->
hash(graphName);
394 GraphMap_t::const_iterator it =
m_graphMap.find( graphHash );
397 m_msg << MSG::WARNING
398 <<
"Detected a hash collision. The hash for the TGraph with name=" << graphName
399 <<
" already exists and points to a TGraph with name=" << it->second->GetName()
400 <<
" NOT going to book the new histogram and returning a NULL pointer!" <<
endmsg;
408 m_msg << MSG::WARNING
409 <<
"We couldn't clone the TGraph in the BookGetPointer(TGraph&) method of the class" <<
m_name
419 if ( !((
histSvc()->regGraph(bookingString, graphClone)).isSuccess()) )
421 m_msg << MSG::WARNING
422 <<
"Problem registering TGraph with name " << graphName
423 <<
", title " << graphTitle
429 m_graphMap.insert(
m_graphMap.end(), std::pair< const hash_t, TGraph* >( graphHash, graphClone ) );
441 const hash_t graphHash = this->
hash(graphName);
444 GraphMap_t::const_iterator it =
m_graphMap.find( graphHash );
451 TGraph* graphPointer(
nullptr);
452 if ( !((
histSvc()->getGraph(bookingString, graphPointer)).isSuccess()) )
457 if ( !((
histSvc()->getGraph(bookingString, graphPointer)).isSuccess()) )
459 m_msg << MSG::WARNING
460 <<
"Problem retrieving the TGraph with name (including pre- and post-fixes) "
462 <<
" or with name " << graphName
463 <<
" in " <<
m_name <<
"... it doesn't exist, neither in the cached map nor in the THistSvc!"
464 <<
" Will return an NULL pointer... you have to handle it correctly!" <<
endmsg;
469 m_graphMap.insert(
m_graphMap.end(), std::pair< const hash_t, TGraph* >( graphHash, graphPointer ) );
474 m_graphMap.insert(
m_graphMap.end(), std::pair< const hash_t, TGraph* >( graphHash, graphPointer ) );
501 std::string_view stream,
bool usePrefixPostfix)
const {
505 if (stream.empty()) {
508 const auto [histDir, baseName] = splitName(histName);
509 std::string bookingString{
"/"};
510 bookingString += stream;
511 bookingString +=
'/';
512 bookingString += tDir;
513 if (!histDir.empty()) {
514 bookingString +=
'/';
515 bookingString += histDir;
517 bookingString +=
'/';
518 if (usePrefixPostfix) {
521 bookingString += baseName;
522 if (usePrefixPostfix) {
525 const auto tail = std::ranges::unique(
526 bookingString, [](
char lhs,
char rhs) {
return lhs ==
'/' && rhs ==
'/'; });
527 bookingString.erase(
tail.begin(),
tail.end());
528 return bookingString;
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.
hash_t hash(std::string_view histName) const
Method to calculate a 32-bit hash from a string.
ServiceHandle< ITHistSvc > m_histSvc
Pointer to the THistSvc (event store by default).
std::string buildBookingString(std::string_view histName, std::string_view tDir, std::string_view stream, bool usePrefixPostfix=false) const
Method to build individual booking string.
std::string m_histNamePostfix
The postfix for the histogram THx name.
std::string m_rootDir
Name of the ROOT directory.
uint32_t hash_t
typedef for the internal hash
std::string m_histTitlePostfix
The postfix for the histogram THx title.
TH1 * hist(std::string_view histName, std::string_view tDir="", std::string_view 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).
TH1 * bookGetPointer(const TH1 &hist, std::string_view tDir="", std::string_view stream="")
Simplify the booking and registering (into THistSvc) of histograms.
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 to fill the internal configuration.
std::string m_name
Instance name.
TGraph * graph(std::string_view graphName, std::string_view tDir="", std::string_view stream="")
Simplify the retrieval of registered TGraphs.
TTree * tree(std::string_view treeName, std::string_view tDir="", std::string_view stream="")
Simplify the retrieval of registered TTrees.
MsgStream m_msg
Cached Message Stream.
TEfficiency * efficiency(std::string_view effName, std::string_view tDir="", std::string_view stream="")
Simplify the retrieval of registered TEfficiency.
EffMap_t m_effMap
The map of histogram names to their pointers.
std::string m_histNamePrefix
The prefix for the histogram THx name.
GraphMap_t m_graphMap
The map of TGraph names to their pointers.
std::string tail(std::string s, const std::string &pattern)
tail of a string
singleton-like access to IMessageSvc via open function and helper
Some weak symbol referencing magic... These are declared in AthenaKernel/getMessageSvc....