1 #ifndef GAUDIALG_GAUDIHISTOS_ICPP
2 #define GAUDIALG_GAUDIHISTOS_ICPP 1
21 #include "boost/algorithm/string/replace.hpp"
43 class IBaseHistogram ;
56 constexpr
struct ordered_t {
63 template <
typename Map>
64 typename Map::mapped_type lookup_(
const Map&
map,
const typename Map::key_type& ID) {
65 auto found = map.find( ID ) ;
66 return found !=
std::end(map) ? found->second :
nullptr;
72 inline void stringSearchReplace (
std::string & title ,
77 slash != std::string::npos ;
87 template <
class PBASE>
93 m_produceHistos =
true ,
94 "Switch on/off the production of histograms" ) ;
98 m_histosPrint =
false ,
99 "Switch on/off the printout of histograms at finalization" )
101 this->declareProperty
102 (
"HistoCountersPrint" ,
103 m_histoCountersPrint =
true ,
104 "Switch on/off the printout of histogram counters at finalization" ) ;
106 this->declareProperty
107 (
"HistoCheckForNaN" ,
108 m_checkForNaN =
true ,
109 "Switch on/off the checks for NaN and Infinity for histogram fill" ) ;
111 this->declareProperty
113 m_splitHistoDir =
false ,
114 "Split long directory names into short pieces (suitable for HBOOK)" );
116 this->declareProperty
119 "OffSet for automatically assigned histogram numerical identifiers " ) ;
121 this->declareProperty
124 "Top level histogram directory (take care that it ends with '/')" ) ;
126 this->declareProperty
128 m_histoDir = boost::algorithm::replace_all_copy( this->
name(),
":",
"_" ) ,
129 "Histogram Directory" ) ;
131 this->declareProperty (
"FullDetail" , m_fullDetail =
false ) ;
133 this->declareProperty (
"MonitorHistograms" , m_declareMoniHists =
true ) ;
135 this->declareProperty
136 (
"FormatFor1DHistoTable" ,
138 "Format string for printout of 1D histograms" ) ;
140 this->declareProperty
141 (
"ShortFormatFor1DHistoTable" ,
142 m_histo1DTableFormatShort =
" | %1$-25.25s %2%" ,
143 "Format string for printout of 1D histograms" ) ;
145 this->declareProperty
146 (
"HeaderFor1DHistoTable" ,
148 "The table header for printout of 1D histograms " ) ;
149 this->declareProperty
150 (
"UseSequencialNumericAutoIDs", m_useNumericAutoIDs =
false,
151 "Flag to allow users to switch back to the old style of creating numerical automatic IDs" );
152 this->declareProperty
153 (
"AutoStringIDPurgeMap", m_idReplaceInfo = { {
"/",
"=SLASH=" } } ,
154 "Map of strings to search and replace when using the title as the basis of automatically generated literal IDs" );
159 template <
class PBASE>
173 if ( !produceHistos() )
175 this->debug() <<
"Histogram production is switched OFF" <<
endmsg;
180 if ( !this->histoSvc() )
181 {
return this->Error(
"initialize():: IHistogramSvc* is invalid"); }
184 if ( useNumericAutoIDs() )
187 Warning(
"Using numerical automatic IDs. These are not guaranteed to be totally deterministic. Use with care...",
193 (
"The histogram path is set to be '" + histoPath() +
"'",
201 template <
class PBASE>
211 if ( produceHistos() )
215 if ( (!noHistos()) && histoCountersPrint() )
217 const unsigned int n1D = histo1DMapID () . size () ;
218 const unsigned int n2D = histo2DMapID () . size () ;
219 const unsigned int n3D = histo3DMapID () . size () ;
220 const unsigned int n1DP = profile1DMapID () . size () ;
221 const unsigned int n2DP = profile2DMapID () . size () ;
222 const unsigned int total = n1D+n2D+n3D+n1DP+n2DP;
225 this->always() <<
"Booked " << total <<
" Histogram(s) : ";
226 if ( n1D>0 ) this->always() <<
"1D=" << n1D <<
" ";
227 if ( n2D>0 ) this->always() <<
"2D=" << n2D <<
" ";
228 if ( n3D>0 ) this->always() <<
"3D=" << n3D <<
" ";
229 if ( n1DP>0 ) this->always() <<
"1DProf=" << n1DP <<
" ";
230 if ( n2DP>0 ) this->always() <<
"2DProf=" << n2DP <<
" ";
236 if ( histosPrint() ) { printHistos() ; }
241 m_histo1DMapTitle . clear () ;
242 m_histo2DMapTitle . clear () ;
243 m_histo3DMapTitle . clear () ;
244 m_histo1DMapID . clear () ;
245 m_histo2DMapID . clear () ;
246 m_histo3DMapID . clear () ;
247 m_profile1DMapTitle . clear () ;
248 m_profile2DMapTitle . clear () ;
249 m_profile1DMapID . clear () ;
250 m_profile2DMapID . clear () ;
253 return PBASE::finalize();
258 template <
class PBASE>
266 { this->msgStream(level) <<
"No histograms are booked" <<
endmsg ; }
275 ( m_histo1DTableFormat ,
276 m_histo1DTableHeader ) ;
278 if ( !histo1DMapID().empty() )
280 msg <<
"List of booked 1D histograms in directory "
281 <<
"\"" << histoPath() <<
"\" :-" ;
286 (
"ID" , table.
header() , m_histo1DTableFormatShort ) ;
288 for (
const auto& entry : ordered( histo1DMapID() ))
290 const auto* aida = entry.second ;
292 { this->error() <<
"IHistogram1D points to NULL" <<
endmsg ; continue ; }
297 m_histo1DTableFormatShort ) ;
302 if ( !histo2DMapID().empty() )
304 msg <<
"List of booked 2D histograms in directory "
305 <<
"\"" << histoPath() <<
"\" :-" ;
307 for (
const auto& entry : ordered( histo2DMapID() ) )
309 const auto* aida = entry.second ;
311 { this->error() <<
"IHistogram2D points to NULL" <<
endmsg ; continue ; }
318 if ( !histo3DMapID().empty() )
320 msg <<
"List of booked 3D histograms in directory "
321 <<
"\"" << histoPath() <<
"\" :-" ;
322 for (
const auto& entry : ordered( histo3DMapID() ) )
324 const auto* aida = entry.second ;
326 { this->error() <<
"IHistogram3D points to NULL" <<
endmsg ; continue ; }
332 if ( !profile1DMapID().empty() )
334 msg <<
"List of booked 1D profile histograms in directory "
335 <<
"\"" << histoPath() <<
"\" :-" ;
336 for (
const auto& entry : ordered( profile1DMapID() ) )
338 const auto* aida = entry.second ;
340 { this->error() <<
"IProfile1D points to NULL" <<
endmsg ; continue ; }
346 if ( !profile2DMapID().empty() )
348 msg <<
"List of booked 2D profile histograms in directory "
349 <<
"\"" << histoPath() <<
"\" :-" ;
350 for (
const auto& entry : ordered(profile2DMapID() ) )
352 const auto* aida = entry.second ;
354 { this->error() <<
"IProfile2D points to NULL" <<
endmsg ; continue ; }
360 return this->totalNumberOfHistos() ;
365 template <
class PBASE>
368 return ( histo1DMapTitle () . empty() &&
369 histo2DMapTitle () . empty() &&
370 histo3DMapTitle () . empty() &&
371 profile1DMapTitle () . empty() &&
372 profile2DMapTitle () . empty() &&
373 histo1DMapID () . empty() &&
374 histo2DMapID () . empty() &&
375 histo3DMapID () . empty() &&
376 profile1DMapID () . empty() &&
377 profile2DMapID () . empty() );
382 template <
class PBASE>
384 (
const AIDA::IBaseHistogram* hist,
387 if ( hist && m_declareMoniHists )
391 this->debug() <<
"Monitoring histogram '"
395 this->declareInfo ( histoPath()+
"/"+ID.
idAsString() ,
403 template <
class PBASE>
406 return lookup_( histo1DMapID(), ID );
411 template <
class PBASE>
414 return lookup_( histo2DMapID(), ID );
419 template <
class PBASE>
422 return lookup_( histo3DMapID(), ID );
427 template <
class PBASE>
430 return lookup_( profile1DMapID(), ID );
435 template <
class PBASE>
438 return lookup_( profile2DMapID(), ID );
443 template <
class PBASE>
447 histo1DMapID () . size () +
448 histo2DMapID () . size () +
449 histo3DMapID () . size () +
450 profile1DMapID () . size () +
451 profile2DMapID () . size () ;
456 template <
class PBASE>
461 if ( useNumericAutoIDs() || title.
empty() )
463 if ( !useNumericAutoIDs() )
465 this -> Warning(
"Cannot generate automatic literal ID from an empty title ! Using numeric ID instead for histogram ID",
469 ID =
HistoID( totalNumberOfHistos() + 1 + histoOffSet() );
471 while ( histoExists( ID ) ) { ID =
HistoID ( ID.
numeric() + 1 ) ; }
476 ID =
HistoID( this->convertTitleToID(title) );
484 template <
class PBASE>
488 for (
const auto&
i : m_idReplaceInfo )
490 stringSearchReplace( title,
i.first,
i.second );
497 template <
class PBASE >
502 if (
this -> histosPrint() ) {
this -> printHistos (
MSG::ALWAYS ) ; }
507 template <
class PBASE >
511 return splitHistoDir() ? dirHbookName(path) :
path;
532 #endif // GAUDIALG_GAUDIHISTOS_ICPP
Definition of the MsgStream class used to transmit messages.
GAUDI_API std::string htitle(const AIDA::IBaseHistogram *histo, const std::string &title="")
get the title
AIDA::IHistogram2D * histo2D(const std::string &title) const
access the EXISTING 2D histogram by title return the pointer to existing 2D histogram or NULL ...
int printHistos(const MSG::Level level=MSG::ALWAYS) const
perform the actual printout of histograms
AIDA::IProfile1D * profile1D(const double valueX, const double valueY, const std::string &title, const double lowX, const double highX, const unsigned long binsX=100, const std::string &opt="", const double lowY=-std::numeric_limits< double >::max(), const double highY=std::numeric_limits< double >::max(), const double weight=1.0) const
fill the 1D profile histogram (book on demand)
void printHistoHandler(Property &)
the handler for "HistoPrint" property
bool noHistos() const
Check if all histogram maps are empty.
GaudiAlg::ID HistoID
The actual type for histogram identifier.
void newHistoID(const std::string &title, HistoID &ID) const
Create a new histogram ID using the given title.
GAUDI_API std::string format(const AIDA::IHistogram1D *histo, const std::string &fmt)
Make the string representation of the historgam according to the specified format.
Collection of useful utilities for manipulations with AIDA hisgograms.
few useful function to construct names of Hbook histograms and directories functions are imported fro...
bool isFailure() const
Test for a status code of FAILURE.
const std::string & header() const
the table header
void monitorHisto(const AIDA::IBaseHistogram *hist, const HistoID &ID) const
Declare a histogram to the monitor service.
AIDA::IHistogram1D * histo1D(const std::string &title) const
access the EXISTING 1D histogram by title return the pointer to existing 1D histogram or NULL ...
struct GAUDI_API map
Parametrisation class for map-like implementation.
This class is used for returning status codes from appropriate routines.
T find_first_of(T...args)
unsigned int totalNumberOfHistos() const
Returns the total number of histograms (of all types) currently booked.
Simple class for the customizeble printout of the histogram tables.
collection of useful utilities to print certain objects (currently used for implementation in class G...
static std::string toString(const AIDA::IHistogram3D *aida, const GaudiAlg::HistoID &ID)
GAUDI_API std::string path(const AIDA::IBaseHistogram *aida)
get the path in THS for AIDA histogram
std::string histoPath() const
get the constructed histogram path
Property base class allowing Property* collections to be "homogeneous".
GAUDI_API LiteralID idAsString() const
Return ID as string, for both numeric and literal IDs.
static std::string toString(const AIDA::IHistogram2D *aida, const GaudiAlg::HistoID &ID)
Templated base class providing common histogramming methods for GaudiAlgorithm and GaudiTool like cla...
static std::string toString(const AIDA::IProfile1D *aida, const GaudiAlg::HistoID &ID)
std::string convertTitleToID(std::string title) const
Create an ID string from a title string.
AIDA::IProfile2D * profile2D(const double valueX, const double valueY, const double valueZ, const std::string &title, const double lowX, const double highX, const double lowY, const double highY, const unsigned long binsX=50, const unsigned long binsY=50, const double weight=1.0) const
fill the 2D profile histogram (book on demand)
static std::string toString(const AIDA::IProfile2D *aida, const GaudiAlg::HistoID &ID)
ID class for Histogram and Ntuples.
bool numeric() const
Is this ID numeric.
AIDA::IHistogram3D * histo3D(const std::string &title) const
access the EXISTING 3D histogram by title return the pointer to existing 3D histogram or NULL ...
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
KeyedObjectManager< map > Map
Forward declaration of specialized std::map-like object manager.
std::string toString(const AIDA::IHistogram1D *histo) const
make the string representation according to the default format
void initGaudiHistosConstructor()
Constructor initialisation and job options.