11#ifndef ATHENABASECOMPS_ATHHISTOGRAMMING_H
12#define ATHENABASECOMPS_ATHHISTOGRAMMING_H 1
19#include "GaudiKernel/ServiceHandle.h"
20#include "GaudiKernel/ITHistSvc.h"
23#include "GaudiKernel/MsgStream.h"
29#include "TEfficiency.h"
70 const std::string& prefix,
const std::string& rootDir,
71 const std::string& histNamePrefix,
const std::string& histNamePostfix,
72 const std::string& histTitlePrefix,
const std::string& histTitlePostfix );
79 inline TH1*
bookGetPointer(
const TH1&
hist,
const std::string& tDir=
"",
const std::string& stream=
"" );
82 inline TH1*
bookGetPointer( TH1*
hist,
const std::string& tDir=
"",
const std::string& stream=
"" );
85 TH1*
bookGetPointer( TH1& histRef, std::string tDir=
"", std::string stream=
"" );
89 inline StatusCode
book(
const TH1&
hist,
const std::string& tDir=
"",
const std::string& stream=
"" );
92 inline StatusCode
book( TH1*
hist,
const std::string& tDir=
"",
const std::string& stream=
"" );
95 inline StatusCode
book( TH1& histRef,
const std::string& tDir=
"",
const std::string& stream=
"" );
99 TH1*
hist(
const std::string& histName,
const std::string& tDir=
"",
const std::string& stream=
"" );
102 inline TH2*
hist2d(
const std::string& histName,
const std::string& tDir=
"",
const std::string& stream=
"" );
105 inline TH3*
hist3d(
const std::string& histName,
const std::string& tDir=
"",
const std::string& stream=
"" );
113 TTree*
bookGetPointer(
const TTree& treeRef, std::string tDir=
"", std::string stream=
"" );
116 inline StatusCode
book(
const TTree& treeRef,
const std::string& tDir=
"",
const std::string& stream=
"" );
119 TTree*
tree(
const std::string& treeName,
const std::string& tDir=
"",
const std::string& stream=
"" );
127 TGraph*
bookGetPointer(
const TGraph& graphRef, std::string tDir=
"", std::string stream=
"" );
130 inline StatusCode
book(
const TGraph& graphRef,
const std::string& tDir=
"",
const std::string& stream=
"" );
133 TGraph*
graph(
const std::string& graphName,
const std::string& tDir=
"",
const std::string& stream=
"" );
141 inline TEfficiency*
bookGetPointer(
const TEfficiency& eff,
const std::string& tDir=
"",
const std::string& stream=
"" );
144 inline TEfficiency*
bookGetPointer( TEfficiency* eff,
const std::string& tDir=
"",
const std::string& stream=
"" );
147 TEfficiency*
bookGetPointer( TEfficiency& effRef, std::string tDir=
"", std::string stream=
"" );
151 inline StatusCode
book(
const TEfficiency& eff,
const std::string& tDir=
"",
const std::string& stream=
"" );
154 inline StatusCode
book( TEfficiency* eff,
const std::string& tDir=
"",
const std::string& stream=
"" );
157 inline StatusCode
book( TEfficiency& effRef,
const std::string& tDir=
"",
const std::string& stream=
"" );
161 TEfficiency*
efficiency(
const std::string& effName,
const std::string& tDir=
"",
const std::string& stream=
"" );
173 std::string& histName,
176 bool usePrefixPostfix =
false);
180 const std::string& oldStr,
181 const std::string& newStr);
184 hash_t hash(
const std::string& histName )
const;
205 typedef std::map< const hash_t, TEfficiency* >
EffMap_t;
263 TH1* histClone =
dynamic_cast< TH1*
>(
hist.Clone() );
265 m_msg << MSG::ERROR <<
"Couldn't create a TH1 clone in bookGetPointer" <<
endmsg;
275 m_msg << MSG::ERROR <<
"Got a zero pointer to a TH1 in bookGetPointer" <<
endmsg;
284 TEfficiency* histClone =
dynamic_cast< TEfficiency*
>(
hist.Clone() );
286 m_msg << MSG::ERROR <<
"Couldn't create a TEfficiency clone in bookGetPointer" <<
endmsg;
296 m_msg << MSG::ERROR <<
"Got a zero pointer to a TEfficiency in bookGetPointer" <<
endmsg;
306 TH1* histClone =
dynamic_cast< TH1*
>(
hist.Clone() );
308 m_msg << MSG::ERROR <<
"Couldn't create a TH1 clone" <<
endmsg;
309 return StatusCode::FAILURE;
311 return this->
book( *histClone, tDir, stream );
317 m_msg << MSG::ERROR <<
"Got a zero pointer to a TH1" <<
endmsg;
318 return StatusCode::FAILURE;
320 return this->
book( *hist, tDir, stream );
328 if ( !histPointer ) {
329 m_msg << MSG::ERROR <<
"Couldn't book a TH1" <<
endmsg;
330 return StatusCode::FAILURE;
332 return StatusCode::SUCCESS;
338 TEfficiency* effClone =
dynamic_cast< TEfficiency*
>( eff.Clone() );
340 m_msg << MSG::ERROR <<
"Couldn't create a TEfficiency clone" <<
endmsg;
341 return StatusCode::FAILURE;
343 return this->
book( *effClone, tDir, stream );
349 m_msg << MSG::ERROR <<
"Got a zero pointer to a TEfficiency" <<
endmsg;
350 return StatusCode::FAILURE;
352 return this->
book( *eff, tDir, stream );
359 TEfficiency* effPointer = this->
bookGetPointer( effRef, tDir, stream );
361 m_msg << MSG::ERROR <<
"Couldn't book a TEfficiency" <<
endmsg;
362 return StatusCode::FAILURE;
364 return StatusCode::SUCCESS;
372 TH1* th1Pointer = this->
hist(histName, tDir, stream);
376 <<
"Cannot get a 2-d histogram with name " << histName
377 <<
"... will probably seg-fault!" <<
endmsg;
381 return dynamic_cast<TH2*
>( th1Pointer );
389 TH1* th1Pointer = this->
hist(histName, tDir, stream);
393 <<
"Cannot get a 3-d histogram with name " << histName
394 <<
"... will probably seg-fault!" <<
endmsg;
398 return dynamic_cast<TH3*
>( th1Pointer );
406 TTree* treePointer = this->
bookGetPointer( treeRef, tDir, stream );
409 return StatusCode::SUCCESS;
413 return StatusCode::FAILURE;
431 return (
hash_t)(hash64 & 0xFFFFFFFF);
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.
ServiceHandle< ITHistSvc > m_histSvc
Pointer to the THistSvc (event store by default)
std::string m_histNamePostfix
The postfix for the histogram THx name.
std::map< const hash_t, TH1 * > HistMap_t
Typedef for convenience.
StatusCode book(const TH1 &hist, const std::string &tDir="", const std::string &stream="")
Simplify the booking and registering (into THistSvc) of histograms.
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.
StatusCode book(const TGraph &graphRef, const std::string &tDir="", const std::string &stream="")
Simplify the booking and registering (into THistSvc) of TGraphs.
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.
std::map< const hash_t, TEfficiency * > EffMap_t
Typedef for convenience.
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.
TH3 * hist3d(const std::string &histName, const std::string &tDir="", const std::string &stream="")
Simplify the retrieval of registered 3-d histograms.
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.
std::map< const hash_t, TTree * > TreeMap_t
Typedef for convenience.
std::map< const hash_t, TGraph * > GraphMap_t
Typedef for convenience.
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.
TH2 * hist2d(const std::string &histName, const std::string &tDir="", const std::string &stream="")
Simplify the retrieval of registered 2-d histograms.
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.
A crc-64 implementation, using pclmul where possible.
uint64_t crc64(const CRCTable &table, const char *data, size_t data_len)
Find the CRC-64 of a string,.