ATLAS Offline Software
Loading...
Searching...
No Matches
AthHistogramming Class Reference

#include <AthHistogramming.h>

Inheritance diagram for AthHistogramming:
Collaboration diagram for AthHistogramming:

Public Member Functions

 AthHistogramming (const std::string &name)
 Constructor with parameters:
virtual ~AthHistogramming ()
 Destructor:
const ServiceHandle< ITHistSvc > & histSvc () const
 The standard THistSvc (for writing histograms and TTrees and more to a root file) Returns (kind of) a pointer to the THistSvc.

Protected Member Functions

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.
TH1 * bookGetPointer (const TH1 &hist, const std::string &tDir="", const std::string &stream="")
 Simplify the booking and registering (into THistSvc) of histograms.
TH1 * bookGetPointer (TH1 *hist, const std::string &tDir="", const std::string &stream="")
 Simplify the booking and registering (into THistSvc) of histograms.
TH1 * bookGetPointer (TH1 &histRef, std::string tDir="", std::string stream="")
 Simplify the booking and registering (into THistSvc) of histograms.
StatusCode book (const TH1 &hist, const std::string &tDir="", const std::string &stream="")
 Simplify the booking and registering (into THistSvc) of histograms.
StatusCode book (TH1 *hist, const std::string &tDir="", const std::string &stream="")
 Simplify the booking and registering (into THistSvc) of histograms.
StatusCode book (TH1 &histRef, const std::string &tDir="", const std::string &stream="")
 Simplify the booking and registering (into THistSvc) of histograms.
TH1 * hist (std::string_view histName, const std::string &tDir="", const std::string &stream="")
 Simplify the retrieval of registered histograms of any type.
TH2 * hist2d (std::string_view histName, const std::string &tDir="", const std::string &stream="")
 Simplify the retrieval of registered 2-d histograms.
TH3 * hist3d (std::string_view histName, const std::string &tDir="", const std::string &stream="")
 Simplify the retrieval of registered 3-d histograms.
TTree * bookGetPointer (const TTree &treeRef, std::string tDir="", std::string stream="")
 Simplify the booking and registering (into THistSvc) of TTrees.
StatusCode book (const TTree &treeRef, const std::string &tDir="", const std::string &stream="")
 Simplify the booking and registering (into THistSvc) of TTrees.
TTree * tree (const std::string &treeName, const std::string &tDir="", const std::string &stream="")
 Simplify the retrieval of registered TTrees.
TGraph * bookGetPointer (const TGraph &graphRef, std::string tDir="", std::string stream="")
 Simplify the booking and registering (into THistSvc) of TGraphs.
StatusCode book (const TGraph &graphRef, const std::string &tDir="", const std::string &stream="")
 Simplify the booking and registering (into THistSvc) of TGraphs.
TGraph * graph (const std::string &graphName, const std::string &tDir="", const std::string &stream="")
 Simplify the retrieval of registered TGraphs.
TEfficiency * bookGetPointer (const TEfficiency &eff, const std::string &tDir="", const std::string &stream="")
 Simplify the booking and registering (into THistSvc) of TEfficiency.
TEfficiency * bookGetPointer (TEfficiency *eff, const std::string &tDir="", const std::string &stream="")
 Simplify the booking and registering (into THistSvc) of TEfficiency.
TEfficiency * bookGetPointer (TEfficiency &effRef, std::string tDir="", std::string stream="")
 Simplify the booking and registering (into THistSvc) of TEfficiency.
StatusCode book (const TEfficiency &eff, const std::string &tDir="", const std::string &stream="")
 Simplify the booking and registering (into THistSvc) of TEfficiency.
StatusCode book (TEfficiency *eff, const std::string &tDir="", const std::string &stream="")
 Simplify the booking and registering (into THistSvc) of TEfficiency.
StatusCode book (TEfficiency &effRef, const std::string &tDir="", const std::string &stream="")
 Simplify the booking and registering (into THistSvc) of TEfficiency.
TEfficiency * efficiency (const std::string &effName, const std::string &tDir="", const std::string &stream="")
 Simplify the retrieval of registered TEfficiency.

Private Types

typedef uint32_t hash_t
 typedef for the internal hash
typedef std::map< const hash_t, TH1 * > HistMap_t
 Typedef for convenience.
typedef std::map< const hash_t, TEfficiency * > EffMap_t
 Typedef for convenience.
typedef std::map< const hash_t, TTree * > TreeMap_t
 Typedef for convenience.
typedef std::map< const hash_t, TGraph * > GraphMap_t
 Typedef for convenience.

Private Member Functions

std::string buildBookingString (std::string &histName, std::string &tDir, std::string &stream, bool usePrefixPostfix=false)
 Method to build individual booking string.
void myReplace (std::string &str, const std::string &oldStr, const std::string &newStr)
 Helper method to replace sub-string.
hash_t hash (const std::string &histName) const
 Method to calculate a 32-bit hash from a string.

Private Attributes

ServiceHandle< ITHistSvc > m_histSvc
 Pointer to the THistSvc (event store by default).
HistMap_t m_histMap
 The map of histogram names to their pointers.
EffMap_t m_effMap
 The map of histogram names to their pointers.
TreeMap_t m_treeMap
 The map of TTree names to their pointers.
GraphMap_t m_graphMap
 The map of TGraph names to their pointers.
std::string m_streamName
 Name of the ROOT output stream (file).
std::string m_rootDir
 Name of the ROOT directory.
std::string m_histNamePrefix
 The prefix for the histogram THx name.
std::string m_histNamePostfix
 The postfix for the histogram THx name.
std::string m_histTitlePrefix
 The prefix for the histogram THx title.
std::string m_histTitlePostfix
 The postfix for the histogram THx title.
std::string m_name
 Instance name.
MsgStream m_msg
 Cached Message Stream.

Detailed Description

Definition at line 38 of file AthHistogramming.h.

Member Typedef Documentation

◆ EffMap_t

typedef std::map< const hash_t, TEfficiency* > AthHistogramming::EffMap_t
private

Typedef for convenience.

Definition at line 206 of file AthHistogramming.h.

◆ GraphMap_t

typedef std::map< const hash_t, TGraph* > AthHistogramming::GraphMap_t
private

Typedef for convenience.

Definition at line 220 of file AthHistogramming.h.

◆ hash_t

typedef uint32_t AthHistogramming::hash_t
private

typedef for the internal hash

Definition at line 171 of file AthHistogramming.h.

◆ HistMap_t

typedef std::map< const hash_t, TH1* > AthHistogramming::HistMap_t
private

Typedef for convenience.

Definition at line 199 of file AthHistogramming.h.

◆ TreeMap_t

typedef std::map< const hash_t, TTree* > AthHistogramming::TreeMap_t
private

Typedef for convenience.

Definition at line 213 of file AthHistogramming.h.

Constructor & Destructor Documentation

◆ AthHistogramming()

AthHistogramming::AthHistogramming ( const std::string & name)

Constructor with parameters:

Definition at line 26 of file AthHistogramming.cxx.

26 :
27 m_histSvc ( "THistSvc/THistSvc", name ),
28 m_streamName(""),
29 m_name ( name ),
31{
32}
ServiceHandle< ITHistSvc > m_histSvc
Pointer to the THistSvc (event store by default).
std::string m_streamName
Name of the ROOT output stream (file).
std::string m_name
Instance name.
MsgStream m_msg
Cached Message Stream.
IMessageSvc * getMessageSvc(bool quiet=false)

◆ ~AthHistogramming()

AthHistogramming::~AthHistogramming ( )
virtual

Destructor:

Definition at line 39 of file AthHistogramming.cxx.

40{
41 //ATH_MSG_DEBUG ("Calling destructor of AthHistogramming");
42 if ( m_msg.level() <= MSG::VERBOSE ) m_msg << MSG::DEBUG << "Calling destructor of AthHistogramming" << endmsg;
43}
#define endmsg

Member Function Documentation

◆ book() [1/8]

StatusCode AthHistogramming::book ( const TEfficiency & eff,
const std::string & tDir = "",
const std::string & stream = "" )
inlineprotected

Simplify the booking and registering (into THistSvc) of TEfficiency.

Definition at line 336 of file AthHistogramming.h.

337{
338 // We need to create a non-const clone
339 TEfficiency* effClone = dynamic_cast< TEfficiency* >( eff.Clone() );
340 if ( !effClone ) {
341 m_msg << MSG::ERROR << "Couldn't create a TEfficiency clone" << endmsg;
342 return StatusCode::FAILURE;
343 }
344 return this->book( *effClone, tDir, stream );
345}
StatusCode book(const TH1 &hist, const std::string &tDir="", const std::string &stream="")
Simplify the booking and registering (into THistSvc) of histograms.

◆ book() [2/8]

StatusCode AthHistogramming::book ( const TGraph & graphRef,
const std::string & tDir = "",
const std::string & stream = "" )
inlineprotected

Simplify the booking and registering (into THistSvc) of TGraphs.

◆ book() [3/8]

StatusCode AthHistogramming::book ( const TH1 & hist,
const std::string & tDir = "",
const std::string & stream = "" )
inlineprotected

Simplify the booking and registering (into THistSvc) of histograms.

Definition at line 304 of file AthHistogramming.h.

305{
306 // We need to create a non-const clone
307 TH1* histClone = dynamic_cast< TH1* >( hist.Clone() );
308 if ( !histClone ) {
309 m_msg << MSG::ERROR << "Couldn't create a TH1 clone" << endmsg;
310 return StatusCode::FAILURE;
311 }
312 return this->book( *histClone, tDir, stream );
313}
TH1 * hist(std::string_view histName, const std::string &tDir="", const std::string &stream="")
Simplify the retrieval of registered histograms of any type.

◆ book() [4/8]

StatusCode AthHistogramming::book ( const TTree & treeRef,
const std::string & tDir = "",
const std::string & stream = "" )
inlineprotected

Simplify the booking and registering (into THistSvc) of TTrees.

Definition at line 404 of file AthHistogramming.h.

405{
406 // Call the other Book method and see if it returns a valid pointer
407 TTree* treePointer = this->bookGetPointer( treeRef, tDir, stream );
408 if ( treePointer )
409 {
410 return StatusCode::SUCCESS;
411 }
412 else
413 {
414 return StatusCode::FAILURE;
415 }
416}
TH1 * bookGetPointer(const TH1 &hist, const std::string &tDir="", const std::string &stream="")
Simplify the booking and registering (into THistSvc) of histograms.

◆ book() [5/8]

StatusCode AthHistogramming::book ( TEfficiency & effRef,
const std::string & tDir = "",
const std::string & stream = "" )
inlineprotected

Simplify the booking and registering (into THistSvc) of TEfficiency.

Definition at line 357 of file AthHistogramming.h.

358{
359 // Call the other Book method and see if it returns a valid pointer
360 TEfficiency* effPointer = this->bookGetPointer( effRef, tDir, stream );
361 if ( !effPointer ) {
362 m_msg << MSG::ERROR << "Couldn't book a TEfficiency" << endmsg;
363 return StatusCode::FAILURE;
364 }
365 return StatusCode::SUCCESS;
366}

◆ book() [6/8]

StatusCode AthHistogramming::book ( TEfficiency * eff,
const std::string & tDir = "",
const std::string & stream = "" )
inlineprotected

Simplify the booking and registering (into THistSvc) of TEfficiency.

Definition at line 347 of file AthHistogramming.h.

348{
349 if ( !eff ) {
350 m_msg << MSG::ERROR << "Got a zero pointer to a TEfficiency" << endmsg;
351 return StatusCode::FAILURE;
352 }
353 return this->book( *eff, tDir, stream );
354}

◆ book() [7/8]

StatusCode AthHistogramming::book ( TH1 & histRef,
const std::string & tDir = "",
const std::string & stream = "" )
inlineprotected

Simplify the booking and registering (into THistSvc) of histograms.

Definition at line 325 of file AthHistogramming.h.

326{
327 // Call the other Book method and see if it returns a valid pointer
328 TH1* histPointer = this->bookGetPointer( histRef, tDir, stream );
329 if ( !histPointer ) {
330 m_msg << MSG::ERROR << "Couldn't book a TH1" << endmsg;
331 return StatusCode::FAILURE;
332 }
333 return StatusCode::SUCCESS;
334}

◆ book() [8/8]

StatusCode AthHistogramming::book ( TH1 * hist,
const std::string & tDir = "",
const std::string & stream = "" )
inlineprotected

Simplify the booking and registering (into THistSvc) of histograms.

Definition at line 315 of file AthHistogramming.h.

316{
317 if ( !hist ) {
318 m_msg << MSG::ERROR << "Got a zero pointer to a TH1" << endmsg;
319 return StatusCode::FAILURE;
320 }
321 return this->book( *hist, tDir, stream );
322}

◆ bookGetPointer() [1/8]

TEfficiency * AthHistogramming::bookGetPointer ( const TEfficiency & eff,
const std::string & tDir = "",
const std::string & stream = "" )
inlineprotected

Simplify the booking and registering (into THistSvc) of TEfficiency.

Definition at line 282 of file AthHistogramming.h.

283{
284 // We need to create a non-const clone
285 TEfficiency* histClone = dynamic_cast< TEfficiency* >( hist.Clone() );
286 if ( !histClone ) {
287 m_msg << MSG::ERROR << "Couldn't create a TEfficiency clone in bookGetPointer" << endmsg;
288 return 0;
289 }
290 return this->bookGetPointer( *histClone, tDir, stream );
291
292}

◆ bookGetPointer() [2/8]

TGraph * AthHistogramming::bookGetPointer ( const TGraph & graphRef,
std::string tDir = "",
std::string stream = "" )
protected

Simplify the booking and registering (into THistSvc) of TGraphs.

Definition at line 378 of file AthHistogramming.cxx.

379{
380 // Get a pointer
381 const TGraph* graphPointer = &graphRef;
382
383 // Check that we got a valid pointer
384 if ( !graphPointer )
385 {
386 m_msg << MSG::WARNING
387 << "We got an invalid TGraph pointer in the BookGetPointer(TGraph*) method of the class" << m_name
388 << "!" << endmsg;
389 return NULL;
390 }
391
392 // Modify the name and title according to the prefixes of this classes instance
393 std::string graphName = graphPointer->GetName();
394 const std::string graphTitle = graphPointer->GetTitle();
395
396 // Check if the hash for this graphName already exists, i.e., if we have a hash collision
397 const hash_t graphHash = this->hash(graphName);
398 GraphMap_t::const_iterator it = m_graphMap.find( graphHash );
399 if ( it != m_graphMap.end() ) // It does exist!
400 {
401 m_msg << MSG::WARNING
402 << "Detected a hash collision. The hash for the TGraph with name=" << graphName
403 << " already exists and points to a TGraph with name=" << it->second->GetName()
404 << " NOT going to book the new histogram and returning a NULL pointer!" << endmsg;
405 return NULL;
406 }
407
408 // Create a clone that has the new name
409 TGraph* graphClone = dynamic_cast< TGraph* >( graphPointer->Clone((m_histNamePrefix+graphName+m_histNamePostfix).c_str()) );
410 if( !graphClone )
411 {
412 m_msg << MSG::WARNING
413 << "We couldn't clone the TGraph in the BookGetPointer(TGraph&) method of the class" << m_name
414 << "!" << endmsg;
415 return NULL;
416 }
417 graphClone->SetTitle ((m_histTitlePrefix+graphTitle+m_histTitlePostfix).c_str());
418
419 // Massage the final string to book things
420 std::string bookingString = buildBookingString( graphName, tDir, stream );
421
422 // Register the TGraph into the THistSvc
423 if ( !((histSvc()->regGraph(bookingString, graphClone)).isSuccess()) )
424 {
425 m_msg << MSG::WARNING
426 << "Problem registering TGraph with name " << graphName
427 << ", title " << graphTitle
428 << " in " << m_name << "!" << endmsg;
429 return NULL;
430 }
431
432 // Also register it in the local map of string to pointer
433 m_graphMap.insert( m_graphMap.end(), std::pair< const hash_t, TGraph* >( graphHash, graphClone ) );
434
435 return graphClone;
436}
const ServiceHandle< ITHistSvc > & histSvc() const
The standard THistSvc (for writing histograms and TTrees and more to a root file) Returns (kind of) a...
std::string m_histNamePostfix
The postfix for the histogram THx name.
std::string buildBookingString(std::string &histName, std::string &tDir, std::string &stream, bool usePrefixPostfix=false)
Method to build individual booking string.
hash_t hash(const std::string &histName) const
Method to calculate a 32-bit hash from a string.
uint32_t hash_t
typedef for the internal hash
std::string m_histTitlePostfix
The postfix for the histogram THx title.
std::string m_histTitlePrefix
The prefix for the histogram THx title.
std::string m_histNamePrefix
The prefix for the histogram THx name.
GraphMap_t m_graphMap
The map of TGraph names to their pointers.

◆ bookGetPointer() [3/8]

TH1 * AthHistogramming::bookGetPointer ( const TH1 & hist,
const std::string & tDir = "",
const std::string & stream = "" )
inlineprotected

Simplify the booking and registering (into THistSvc) of histograms.

Definition at line 261 of file AthHistogramming.h.

262{
263 // We need to create a non-const clone
264 TH1* histClone = dynamic_cast< TH1* >( hist.Clone() );
265 if ( !histClone ) {
266 m_msg << MSG::ERROR << "Couldn't create a TH1 clone in bookGetPointer" << endmsg;
267 return 0;
268 }
269 return this->bookGetPointer( *histClone, tDir, stream );
270
271}

◆ bookGetPointer() [4/8]

TTree * AthHistogramming::bookGetPointer ( const TTree & treeRef,
std::string tDir = "",
std::string stream = "" )
protected

Simplify the booking and registering (into THistSvc) of TTrees.

Definition at line 265 of file AthHistogramming.cxx.

266{
267 // Get a pointer
268 const TTree* treePointer = &treeRef;
269
270 // Check that we got a valid pointer
271 if ( !treePointer )
272 {
273 m_msg << MSG::WARNING
274 << "We got an invalid TTree pointer in the BookGetPointer(TTree*) method of the class" << m_name
275 << "!" << endmsg;
276 return NULL;
277 }
278
279 // Modify the name and title according to the prefixes of this classes instance
280 std::string treeName = treePointer->GetName();
281 const std::string treeTitle = treePointer->GetTitle();
282
283 // Check if the hash for this treeName already exists, i.e., if we have a hash collision
284 const hash_t treeHash = this->hash(treeName);
285 TreeMap_t::const_iterator it = m_treeMap.find( treeHash );
286 if ( it != m_treeMap.end() ) // It does exist!
287 {
288 m_msg << MSG::WARNING
289 << "Detected a hash collision. The hash for the TTree with name=" << treeName
290 << " already exists and points to a TTree with name=" << it->second->GetName()
291 << " NOT going to book the new histogram and returning a NULL pointer!" << endmsg;
292 return NULL;
293 }
294
295 // Create a clone that has the new name
296 TTree* treeClone = dynamic_cast< TTree* >( treePointer->Clone(treeName.c_str()) );
297 if( !treeClone )
298 {
299 m_msg << MSG::WARNING
300 << "We couldn't clone the TTree in the BookGetPointer(TTree&) method of the class" << m_name
301 << "!" << endmsg;
302 return NULL;
303 }
304 treeClone->SetTitle (treeTitle.c_str());
305
306 // Massage the final string to book things
307 std::string bookingString = buildBookingString( treeName, tDir, stream );
308
309 // Register the TTree into the THistSvc
310 if ( !((histSvc()->regTree(bookingString, treeClone)).isSuccess()) )
311 {
312 m_msg << MSG::WARNING
313 << "Problem registering TTree with name " << treeName
314 << ", title " << treeTitle
315 << " in " << m_name << "!" << endmsg;
316 return NULL;
317 }
318
319 // Also register it in the local map of string to pointer
320 m_treeMap.insert( m_treeMap.end(), std::pair< const hash_t, TTree* >( treeHash, treeClone ) );
321
322 return treeClone;
323}
TreeMap_t m_treeMap
The map of TTree names to their pointers.

◆ bookGetPointer() [5/8]

TEfficiency * AthHistogramming::bookGetPointer ( TEfficiency & effRef,
std::string tDir = "",
std::string stream = "" )
protected

Simplify the booking and registering (into THistSvc) of TEfficiency.

Definition at line 121 of file AthHistogramming.cxx.

122{
123 std::string effName(effRef.GetName());
124 const std::string effTitle(effRef.GetTitle());
125 std::string bookingString = buildBookingString(effName, tDir, stream);
126 const std::string finalEffName = m_histNamePrefix + effName + m_histNamePostfix;
127 effRef.SetTitle((m_histTitlePrefix + effTitle + m_histTitlePostfix).c_str());
128 effRef.SetName(finalEffName.c_str());
129
130 const hash_t effHash = this->hash(effName);
131 EffMap_t::const_iterator it = m_effMap.find(effHash);
132 if (it != m_effMap.end()) {
133 m_msg << MSG::WARNING
134 << "Detected a hash collision. The hash for the TEfficiency with name=" << effName
135 << " already exists and points to a TEfficiency with name=" << it->second->GetName()
136 << " NOT going to book the new TEfficiency and returning a NULL pointer!" << endmsg;
137 return nullptr;
138 }
139
140 if (!histSvc()->regEfficiency(bookingString, &effRef).isSuccess()) {
141 m_msg << MSG::WARNING
142 << "Problem registering TEfficiency with name " << effName
143 << ", name prefix " << m_histNamePrefix
144 << ", title " << effTitle
145 << ", title prefix " << m_histTitlePrefix
146 << ", and title postfix " << m_histTitlePostfix
147 << " in " << m_name << "!" << endmsg;
148 return nullptr;
149 }
150
151 m_effMap.insert(m_effMap.end(), std::pair<const hash_t, TEfficiency*>(effHash, &effRef));
152
153 return &effRef;
154}
EffMap_t m_effMap
The map of histogram names to their pointers.

◆ bookGetPointer() [6/8]

TEfficiency * AthHistogramming::bookGetPointer ( TEfficiency * eff,
const std::string & tDir = "",
const std::string & stream = "" )
inlineprotected

Simplify the booking and registering (into THistSvc) of TEfficiency.

Definition at line 294 of file AthHistogramming.h.

295{
296 if ( !hist ) {
297 m_msg << MSG::ERROR << "Got a zero pointer to a TEfficiency in bookGetPointer" << endmsg;
298 return 0;
299 }
300 return this->bookGetPointer( *hist, tDir, stream );
301}

◆ bookGetPointer() [7/8]

TH1 * AthHistogramming::bookGetPointer ( TH1 & histRef,
std::string tDir = "",
std::string stream = "" )
protected

Simplify the booking and registering (into THistSvc) of histograms.

Definition at line 83 of file AthHistogramming.cxx.

84{
85 std::string histName(histRef.GetName());
86 const std::string histTitle(histRef.GetTitle());
87 std::string bookingString = buildBookingString(histName, tDir, stream);
88
89 const std::string finalHistName = m_histNamePrefix + histName + m_histNamePostfix;
90
91 histRef.SetTitle((m_histTitlePrefix + histTitle + m_histTitlePostfix).c_str());
92 histRef.SetName(finalHistName.c_str());
93
94 const hash_t histHash = this->hash(histName);
95 HistMap_t::const_iterator it = m_histMap.find(histHash);
96 if (it != m_histMap.end()) {
97 m_msg << MSG::WARNING
98 << "Detected a hash collision. The hash for the histogram with name=" << histName
99 << " already exists and points to a histogram with name=" << it->second->GetName()
100 << " NOT going to book the new histogram and returning a NULL pointer!" << endmsg;
101 return nullptr;
102 }
103
104 if (!histSvc()->regHist(bookingString, &histRef).isSuccess()) {
105 m_msg << MSG::WARNING
106 << "Problem registering histogram with name " << histName
107 << ", name prefix " << m_histNamePrefix
108 << ", title " << histTitle
109 << ", title prefix " << m_histTitlePrefix
110 << ", and title postfix " << m_histTitlePostfix
111 << " in " << m_name << "!" << endmsg;
112 return nullptr;
113 }
114
115 m_histMap.insert(m_histMap.end(), std::pair<const hash_t, TH1*>(histHash, &histRef));
116
117 return &histRef;
118}
HistMap_t m_histMap
The map of histogram names to their pointers.

◆ bookGetPointer() [8/8]

TH1 * AthHistogramming::bookGetPointer ( TH1 * hist,
const std::string & tDir = "",
const std::string & stream = "" )
inlineprotected

Simplify the booking and registering (into THistSvc) of histograms.

Definition at line 273 of file AthHistogramming.h.

274{
275 if ( !hist ) {
276 m_msg << MSG::ERROR << "Got a zero pointer to a TH1 in bookGetPointer" << endmsg;
277 return 0;
278 }
279 return this->bookGetPointer( *hist, tDir, stream );
280}

◆ buildBookingString()

std::string AthHistogramming::buildBookingString ( std::string & histName,
std::string & tDir,
std::string & stream,
bool usePrefixPostfix = false )
private

Method to build individual booking string.

Definition at line 509 of file AthHistogramming.cxx.

511{
512 std::string bookingString;
513 // Massage the final string to book things
514 if(tDir.empty()) tDir = m_rootDir;
515 size_t pos = histName.rfind('/');
516 if(pos != std::string::npos){
517 tDir+='/';
518 tDir.append(histName, 0,pos);
519 histName.erase(0,pos+1);
520 };
521 if(stream.empty()) stream = m_streamName;
522
523 if(usePrefixPostfix){
524 bookingString = "/"+stream+"/"+tDir+"/"+m_histNamePrefix+histName+m_histNamePostfix;
525 } else {
526 bookingString = "/"+stream+"/"+tDir+"/"+histName;
527 }
528 while(bookingString.find("//") != std::string::npos){
529 this->myReplace(bookingString,"//","/");
530 }
531
532 return bookingString;
533}
std::string m_rootDir
Name of the ROOT directory.
void myReplace(std::string &str, const std::string &oldStr, const std::string &newStr)
Helper method to replace sub-string.

◆ configAthHistogramming()

StatusCode AthHistogramming::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 )
protected

To be called by the derived classes to fill the internal configuration.

Definition at line 51 of file AthHistogramming.cxx.

55{
58 m_rootDir = rootDir;
59 m_histNamePrefix = histNamePrefix;
60 m_histNamePostfix = histNamePostfix;
61 m_histTitlePrefix = histTitlePrefix;
62 m_histTitlePostfix = histTitlePostfix;
63
64 return StatusCode::SUCCESS;
65}

◆ efficiency()

TEfficiency * AthHistogramming::efficiency ( const std::string & effName,
const std::string & tDir = "",
const std::string & stream = "" )
protected

Simplify the retrieval of registered TEfficiency.

Definition at line 205 of file AthHistogramming.cxx.

206{
207 // Build a 32 bit hash out of the name
208 const hash_t effHash = this->hash(effName);
209
210 // See if this entry exists in the map
211 EffMap_t::const_iterator it = m_effMap.find( effHash );
212 if ( it == m_effMap.end() ) // It doesn't exist!
213 { // Let's see into the THistSvc if somebody else has registered the TEfficiency...
214
215 // Need to copy the strings as we will massage them from here on
216 std::string effNameCopy = effName;
217 std::string tDirCopy = tDir;
218 std::string streamCopy = stream;
219
220 // Massage the final string to book things
221 std::string bookingString = buildBookingString(effNameCopy, tDirCopy, streamCopy ,false);
222
223 TEfficiency* effPointer(NULL);
224 if ( !((histSvc()->getEfficiency(bookingString, effPointer)).isSuccess()) )
225 {
226 // Massage the final string to book things
227 std::string bookingString = buildBookingString( effNameCopy, tDirCopy, streamCopy, true );
228
229 if ( !((histSvc()->getEfficiency(bookingString, effPointer)).isSuccess()) )
230 {
231 m_msg << MSG::WARNING
232 << "Problem retrieving the TEfficiency with name (including pre- and post-fixes) "
233 << m_histNamePrefix + effNameCopy + m_histNamePostfix
234 << " or with name " << effNameCopy
235 << " in " << m_name << "... it doesn't exist, neither in the cached map nor in the THistSvc!"
236 << " Will return an NULL pointer... you have to handle it correctly!" << endmsg;
237 return NULL;
238 }
239 // If we get to here, we actually found the TEfficiency in the THistSvc.
240 // So let's add it to the local cache map and return its pointer
241 m_effMap.insert( m_effMap.end(), std::pair< const hash_t, TEfficiency* >( effHash, effPointer ) );
242 return effPointer;
243 }
244 // If we get to here, we actually found the TEfficiency in the THistSvc.
245 // So let's add it to the local cache map and return its pointer
246 m_effMap.insert( m_effMap.end(), std::pair< const hash_t, TEfficiency* >( effHash, effPointer ) );
247 return effPointer;
248 }
249
250 // Return the pointer to the TEfficiency that we got from the local cache map
251 return it->second;
252}
std::pair< StatusCode, TEfficiency * > getEfficiency(ITHistSvc &svc, const std::string &name)

◆ graph()

TGraph * AthHistogramming::graph ( const std::string & graphName,
const std::string & tDir = "",
const std::string & stream = "" )
protected

Simplify the retrieval of registered TGraphs.

Definition at line 442 of file AthHistogramming.cxx.

443{
444 // Build a 32 bit hash out of the name
445 const hash_t graphHash = this->hash(graphName);
446
447 // See if this entry exists in the map
448 GraphMap_t::const_iterator it = m_graphMap.find( graphHash );
449 if ( it == m_graphMap.end() ) // It doesn't exist!
450 { // Let's see into the THistSvc if somebody else has registered the TGraph...
451
452 // Need to copy the strings as we will massage them from here on
453 std::string graphNameCopy = graphName;
454 std::string tDirCopy = tDir;
455 std::string streamCopy = stream;
456
457 // Massage the final string to book things
458 std::string bookingString = buildBookingString( graphNameCopy, tDirCopy, streamCopy, false);
459
460 TGraph* graphPointer(nullptr);
461 if ( !((histSvc()->getGraph(bookingString, graphPointer)).isSuccess()) )
462 {
463 // Massage the final string to book things
464 std::string bookingString = buildBookingString( graphNameCopy, tDirCopy, streamCopy, true );
465
466 if ( !((histSvc()->getGraph(bookingString, graphPointer)).isSuccess()) )
467 {
468 m_msg << MSG::WARNING
469 << "Problem retrieving the TGraph with name (including pre- and post-fixes) "
470 << m_histNamePrefix + graphNameCopy + m_histNamePostfix
471 << " or with name " << graphNameCopy
472 << " in " << m_name << "... it doesn't exist, neither in the cached map nor in the THistSvc!"
473 << " Will return an NULL pointer... you have to handle it correctly!" << endmsg;
474 return nullptr;
475 }
476 // If we get to here, we actually found the TGraph in the THistSvc.
477 // So let's add it to the local cache map and return its pointer
478 m_graphMap.insert( m_graphMap.end(), std::pair< const hash_t, TGraph* >( graphHash, graphPointer ) );
479 return graphPointer;
480 }
481 // If we get to here, we actually found the TGraph in the THistSvc.
482 // So let's add it to the local cache map and return its pointer
483 m_graphMap.insert( m_graphMap.end(), std::pair< const hash_t, TGraph* >( graphHash, graphPointer ) );
484 return graphPointer;
485 }
486
487
488 // Return the pointer to the TGraph that we got from the local cache map
489 return it->second;
490}
std::pair< StatusCode, TGraph * > getGraph(ITHistSvc &svc, const std::string &name)

◆ hash()

AthHistogramming::hash_t AthHistogramming::hash ( const std::string & histName) const
inlineprivate

Method to calculate a 32-bit hash from a string.

Definition at line 429 of file AthHistogramming.h.

430{
431 const uint64_t hash64 = CxxUtils::crc64( histName );
432 return (hash_t)(hash64 & 0xFFFFFFFF);
433}
uint64_t crc64(const CRCTable &table, const char *data, size_t data_len)
Find the CRC-64 of a string,.
Definition crc64.cxx:696
std::uint64_t hash64(const void *data, std::size_t size)
Passthrough to XXH3_64bits.
Definition XXH.cxx:9

◆ hist()

TH1 * AthHistogramming::hist ( std::string_view histName,
const std::string & tDir = "",
const std::string & stream = "" )
protected

Simplify the retrieval of registered histograms of any type.

Definition at line 161 of file AthHistogramming.cxx.

164{
165 std::string histNameCopy{histName};
166 std::string tDirCopy = tDir;
167 std::string streamCopy = stream;
168
169 std::string bookingString = buildBookingString(histNameCopy, tDirCopy, streamCopy, false);
170
171 const hash_t histHash = this->hash(histNameCopy);
172
173 HistMap_t::const_iterator it = m_histMap.find(histHash);
174 if (it == m_histMap.end()) {
175 TH1* histPointer(nullptr);
176
177 if (!histSvc()->getHist(bookingString, histPointer).isSuccess()) {
178 std::string prefixedHistNameCopy{histName};
179 std::string prefixedTDirCopy = tDir;
180 std::string prefixedStreamCopy = stream;
181
182 std::string prefixedBookingString = buildBookingString(prefixedHistNameCopy,
183 prefixedTDirCopy,
184 prefixedStreamCopy,
185 true);
186
187 if (!histSvc()->getHist(prefixedBookingString, histPointer).isSuccess()) {
188 m_msg << MSG::WARNING
189 << "Problem retrieving the histogram with name (including pre- and post-fixes) "
190 << m_histNamePrefix + histNameCopy + m_histNamePostfix
191 << " or with name " << histNameCopy
192 << " in " << m_name << "... it doesn't exist, neither in the cached map nor in the THistSvc!"
193 << " Will return an NULL pointer... you have to handle it correctly!" << endmsg;
194 return nullptr;
195 }
196 }
197
198 m_histMap.insert(m_histMap.end(), std::pair<const hash_t, TH1*>(histHash, histPointer));
199 return histPointer;
200 }
201
202 return it->second;
203}
std::pair< StatusCode, TH1 * > getHist(ITHistSvc &svc, const std::string &name, size_t index=0)

◆ hist2d()

TH2 * AthHistogramming::hist2d ( std::string_view histName,
const std::string & tDir = "",
const std::string & stream = "" )
inlineprotected

Simplify the retrieval of registered 2-d histograms.

Definition at line 370 of file AthHistogramming.h.

371{
372 // Get the TH1 pointer
373 TH1* th1Pointer = this->hist(histName, tDir, stream);
374 if ( !th1Pointer )
375 {
376 m_msg << MSG::ERROR
377 << "Cannot get a 2-d histogram with name " << histName
378 << "... will probably seg-fault!" << endmsg;
379 return NULL;
380 }
381 // If the TH1 pointer is valid, simply return the dynamic_cast
382 return dynamic_cast<TH2*>( th1Pointer );
383}

◆ hist3d()

TH3 * AthHistogramming::hist3d ( std::string_view histName,
const std::string & tDir = "",
const std::string & stream = "" )
inlineprotected

Simplify the retrieval of registered 3-d histograms.

Definition at line 387 of file AthHistogramming.h.

388{
389 // Get the TH1 pointer
390 TH1* th1Pointer = this->hist(histName, tDir, stream);
391 if ( !th1Pointer )
392 {
393 m_msg << MSG::ERROR
394 << "Cannot get a 3-d histogram with name " << histName
395 << "... will probably seg-fault!" << endmsg;
396 return NULL;
397 }
398 // If the TH1 pointer is valid, simply return the dynamic_cast
399 return dynamic_cast<TH3*>( th1Pointer );
400}

◆ histSvc()

const ServiceHandle< ITHistSvc > & AthHistogramming::histSvc ( ) const
inline

The standard THistSvc (for writing histograms and TTrees and more to a root file) Returns (kind of) a pointer to the THistSvc.

Definition at line 422 of file AthHistogramming.h.

423{
424 return m_histSvc;
425}

◆ myReplace()

void AthHistogramming::myReplace ( std::string & str,
const std::string & oldStr,
const std::string & newStr )
private

Helper method to replace sub-string.

Definition at line 537 of file AthHistogramming.cxx.

540{
541 size_t pos = 0;
542 while((pos = str.find(oldStr, pos)) != std::string::npos)
543 {
544 str.replace(pos, oldStr.length(), newStr);
545 pos += newStr.length();
546 }
547}

◆ tree()

TTree * AthHistogramming::tree ( const std::string & treeName,
const std::string & tDir = "",
const std::string & stream = "" )
protected

Simplify the retrieval of registered TTrees.

Definition at line 330 of file AthHistogramming.cxx.

331{
332 // Build a 32 bit hash out of the name
333 const hash_t treeHash = this->hash(treeName);
334
335 // See if this entry exists in the map
336 TreeMap_t::const_iterator it = m_treeMap.find( treeHash );
337 if ( it == m_treeMap.end() ) // It doesn't exist!
338 { // Let's see into the THistSvc if somebody else has registered the TTree...
339
340 // Need to copy the strings as we will massage them from here on
341 std::string treeNameCopy = treeName;
342 std::string tDirCopy = tDir;
343 std::string streamCopy = stream;
344
345 // Massage the final string to book things
346 std::string bookingString = buildBookingString( treeNameCopy, tDirCopy, streamCopy );
347
348 TTree* treePointer(NULL);
349 if ( !((histSvc()->getTree(bookingString, treePointer)).isSuccess()) )
350 {
351 m_msg << MSG::WARNING
352 << "Problem retrieving the TTree with name " << treeNameCopy
353 << " in " << m_name << "... it doesn't exist, neither in the cached map nor in the THistSvc!"
354 << " Will return an NULL pointer... you have to handle it correctly!" << endmsg;
355 return NULL;
356 }
357 // If we get to here, we actually found the TTree in the THistSvc.
358 // So let's add it to the local cache map and return its pointer
359 m_treeMap.insert( m_treeMap.end(), std::pair< const hash_t, TTree* >( treeHash, treePointer ) );
360 return treePointer;
361 }
362
363 // Return the pointer to the TTree that we got from the local cache map
364 return it->second;
365}
std::pair< StatusCode, TTree * > getTree(ITHistSvc &svc, const std::string &name)

Member Data Documentation

◆ m_effMap

EffMap_t AthHistogramming::m_effMap
private

The map of histogram names to their pointers.

Definition at line 209 of file AthHistogramming.h.

◆ m_graphMap

GraphMap_t AthHistogramming::m_graphMap
private

The map of TGraph names to their pointers.

Definition at line 223 of file AthHistogramming.h.

◆ m_histMap

HistMap_t AthHistogramming::m_histMap
private

The map of histogram names to their pointers.

Definition at line 202 of file AthHistogramming.h.

◆ m_histNamePostfix

std::string AthHistogramming::m_histNamePostfix
private

The postfix for the histogram THx name.

Definition at line 236 of file AthHistogramming.h.

◆ m_histNamePrefix

std::string AthHistogramming::m_histNamePrefix
private

The prefix for the histogram THx name.

Definition at line 233 of file AthHistogramming.h.

◆ m_histSvc

ServiceHandle<ITHistSvc> AthHistogramming::m_histSvc
private

Pointer to the THistSvc (event store by default).

Definition at line 195 of file AthHistogramming.h.

◆ m_histTitlePostfix

std::string AthHistogramming::m_histTitlePostfix
private

The postfix for the histogram THx title.

Definition at line 242 of file AthHistogramming.h.

◆ m_histTitlePrefix

std::string AthHistogramming::m_histTitlePrefix
private

The prefix for the histogram THx title.

Definition at line 239 of file AthHistogramming.h.

◆ m_msg

MsgStream AthHistogramming::m_msg
private

Cached Message Stream.

Definition at line 249 of file AthHistogramming.h.

◆ m_name

std::string AthHistogramming::m_name
private

Instance name.

Definition at line 246 of file AthHistogramming.h.

◆ m_rootDir

std::string AthHistogramming::m_rootDir
private

Name of the ROOT directory.

Definition at line 230 of file AthHistogramming.h.

◆ m_streamName

std::string AthHistogramming::m_streamName
private

Name of the ROOT output stream (file).

Definition at line 227 of file AthHistogramming.h.

◆ m_treeMap

TreeMap_t AthHistogramming::m_treeMap
private

The map of TTree names to their pointers.

Definition at line 216 of file AthHistogramming.h.


The documentation for this class was generated from the following files: