3 #ifndef GAUDIALG_GAUDIHISTOS_ICPP
4 #define GAUDIALG_GAUDIHISTOS_ICPP 1
43 class IBaseHistogram ;
55 template <
class PBASE>
61 m_produceHistos =
true ,
62 "Switch on/off the production of histograms" ) ;
66 m_histosPrint =
false ,
67 "Switch on/off the printout of histograms at finalization" )
70 (
"HistoCountersPrint" ,
71 m_histoCountersPrint =
true ,
72 "Switch on/off the printout of histogram counters at finalization" ) ;
75 (
"HistoCheckForNaN" ,
76 m_checkForNaN =
true ,
77 "Switch on/off the checks for NaN and Infinity for histogram fill" ) ;
81 m_splitHistoDir =
false ,
82 "Split long directory names into short pieces (suitable for HBOOK)" );
87 "OffSet for automatically assigned histogram numerical identifiers " ) ;
92 "Top level histogram directory (take care that it ends with '/')" ) ;
96 m_histoDir = this->name() ,
97 "Histogram Directory" ) ;
99 this->declareProperty (
"FullDetail" , m_fullDetail =
false ) ;
101 this->declareProperty (
"MonitorHistograms" , m_declareMoniHists =
true ) ;
103 this->declareProperty
104 (
"FormatFor1DHistoTable" ,
106 "Format string for printout of 1D histograms" ) ;
108 this->declareProperty
109 (
"ShortFormatFor1DHistoTable" ,
110 m_histo1DTableFormatShort =
" | %1$-25.25s %2%" ,
111 "Format string for printout of 1D histograms" ) ;
113 this->declareProperty
114 (
"HeaderFor1DHistoTable" ,
116 "The table header for printout of 1D histograms " ) ;
117 this->declareProperty
118 (
"UseSequencialNumericAutoIDs", m_useNumericAutoIDs =
false,
119 "Flag to allow users to switch back to the old style of creating numerical automatic IDs" );
120 m_idReplaceInfo.clear();
121 m_idReplaceInfo[
"/"] =
"=SLASH=";
122 this->declareProperty
123 (
"AutoStringIDPurgeMap", m_idReplaceInfo,
124 "Map of strings to search and replace when using the title as the basis of automatically generated literal IDs" );
129 template <
class PBASE>
143 if ( !produceHistos() )
145 this->debug() <<
"Histogram production is switched OFF" <<
endmsg;
150 if ( this->histoSvc() == NULL )
151 {
return this->Error(
"initialize():: IHistogramSvc* is invalid"); }
154 if ( useNumericAutoIDs() )
157 Warning(
"Using numerical automatic IDs. These are not guaranteed to be totally deterministic. Use with care...",
163 (
"The histogram path is set to be '" + histoPath() +
"'",
171 template <
class PBASE>
181 if ( produceHistos() )
185 if ( (!noHistos()) && histoCountersPrint() )
187 const unsigned int n1D = histo1DMapID () . size () ;
188 const unsigned int n2D = histo2DMapID () . size () ;
189 const unsigned int n3D = histo3DMapID () . size () ;
190 const unsigned int n1DP = profile1DMapID () . size () ;
191 const unsigned int n2DP = profile2DMapID () . size () ;
192 const unsigned int total = n1D+n2D+n3D+n1DP+n2DP;
195 this->always() <<
"Booked " << total <<
" Histogram(s) : ";
196 if ( n1D>0 ) this->always() <<
"1D=" << n1D <<
" ";
197 if ( n2D>0 ) this->always() <<
"2D=" << n2D <<
" ";
198 if ( n3D>0 ) this->always() <<
"3D=" << n3D <<
" ";
199 if ( n1DP>0 ) this->always() <<
"1DProf=" << n1DP <<
" ";
200 if ( n2DP>0 ) this->always() <<
"2DProf=" << n2DP <<
" ";
206 if ( histosPrint() ) { printHistos() ; }
211 m_histo1DMapTitle . clear () ;
212 m_histo2DMapTitle . clear () ;
213 m_histo3DMapTitle . clear () ;
214 m_histo1DMapID . clear () ;
215 m_histo2DMapID . clear () ;
216 m_histo3DMapID . clear () ;
217 m_profile1DMapTitle . clear () ;
218 m_profile2DMapTitle . clear () ;
219 m_profile1DMapID . clear () ;
220 m_profile2DMapID . clear () ;
223 return PBASE::finalize();
228 template <
class PBASE>
231 using namespace Gaudi::Utils::Histos ;
236 { this->msgStream(level) <<
"No histograms are booked" <<
endmsg ; }
245 ( m_histo1DTableFormat ,
246 m_histo1DTableHeader ) ;
248 if ( !histo1DMapID().empty() )
250 msg <<
"List of booked 1D histograms in directory "
251 <<
"\"" << histoPath() <<
"\" :-" ;
253 if ( !table.
header().empty() )
256 (
"ID" , table.
header() , m_histo1DTableFormatShort ) ;
259 typedef std::map<HistoID,const AIDA::IHistogram1D*> OrderedMapType;
260 OrderedMapType OrderedMap ( histo1DMapID().begin() , histo1DMapID().
end() );
262 for ( OrderedMapType::const_iterator entry = OrderedMap.begin() ;
263 OrderedMap.end() != entry ; ++entry )
265 const AIDA::IHistogram1D* aida = entry->second ;
267 { this->error() <<
"IHistogram1D points to NULL" <<
endmsg ; continue ; }
272 m_histo1DTableFormatShort ) ;
277 if ( !histo2DMapID().empty() )
279 msg <<
"List of booked 2D histograms in directory "
280 <<
"\"" << histoPath() <<
"\" :-" ;
283 typedef std::map<HistoID,const AIDA::IHistogram2D*> OrderedMapType;
284 OrderedMapType OrderedMap ( histo2DMapID().begin() , histo2DMapID().
end() ) ;
286 for ( OrderedMapType::const_iterator entry = OrderedMap.begin() ;
287 OrderedMap.end() != entry ; ++entry )
289 const AIDA::IHistogram2D* aida = entry->second ;
291 { this->error() <<
"IHistogram2D points to NULL" <<
endmsg ; continue ; }
298 if ( !histo3DMapID().empty() )
300 msg <<
"List of booked 3D histograms in directory "
301 <<
"\"" << histoPath() <<
"\" :-" ;
303 typedef std::map<HistoID,const AIDA::IHistogram3D*> OrderedMapType;
304 OrderedMapType OrderedMap ( histo3DMapID().begin() , histo3DMapID().
end() ) ;
306 for ( OrderedMapType::const_iterator entry = OrderedMap.begin() ;
307 OrderedMap.end() != entry ; ++entry )
309 const AIDA::IHistogram3D* aida = entry->second ;
311 { this->error() <<
"IHistogram3D points to NULL" <<
endmsg ; continue ; }
317 if ( !profile1DMapID().empty() )
319 msg <<
"List of booked 1D profile histograms in directory "
320 <<
"\"" << histoPath() <<
"\" :-" ;
322 typedef std::map<HistoID,const AIDA::IProfile1D*> OrderedMapType;
323 OrderedMapType OrderedMap ( profile1DMapID().begin() , profile1DMapID().
end() ) ;
325 for ( OrderedMapType::const_iterator entry = OrderedMap.begin() ;
326 OrderedMap.end() != entry ; ++entry )
328 const AIDA::IProfile1D* aida = entry->second ;
330 { this->error() <<
"IProfile1D points to NULL" <<
endmsg ; continue ; }
336 if ( !profile2DMapID().empty() )
338 msg <<
"List of booked 2D profile histograms in directory "
339 <<
"\"" << histoPath() <<
"\" :-" ;
341 typedef std::map<HistoID,const AIDA::IProfile2D*> OrderedMapType;
342 OrderedMapType OrderedMap ( profile2DMapID().begin() , profile2DMapID().
end() ) ;
344 for ( OrderedMapType::const_iterator entry = OrderedMap.begin() ;
345 OrderedMap.end() != entry ; ++entry )
347 const AIDA::IProfile2D* aida = entry->second ;
349 { this->error() <<
"IProfile2D points to NULL" <<
endmsg ; continue ; }
355 return this->totalNumberOfHistos() ;
360 template <
class PBASE>
363 return ( histo1DMapTitle () . empty() &&
364 histo2DMapTitle () . empty() &&
365 histo3DMapTitle () . empty() &&
366 profile1DMapTitle () . empty() &&
367 profile2DMapTitle () . empty() &&
368 histo1DMapID () . empty() &&
369 histo2DMapID () . empty() &&
370 histo3DMapID () . empty() &&
371 profile1DMapID () . empty() &&
372 profile2DMapID () . empty() );
377 template <
class PBASE>
379 (
const AIDA::IBaseHistogram* hist,
382 if ( hist && m_declareMoniHists )
386 this->debug() <<
"Monitoring histogram '"
390 this->declareInfo ( histoPath()+
"/"+ID.
idAsString() ,
398 template <
class PBASE>
401 AIDA::IHistogram1D * h(NULL);
405 h = ( histo1DMapID().end() == found ? NULL : found->second );
412 template <
class PBASE>
415 AIDA::IHistogram2D * h(NULL);
419 h = ( histo2DMapID().end() == found ? NULL : found->second );
426 template <
class PBASE>
429 AIDA::IHistogram3D * h(NULL);
432 h = ( histo3DMapID().end() == found ? NULL : found->second );
439 template <
class PBASE>
442 AIDA::IProfile1D * h(NULL);
446 h = ( profile1DMapID().end() == found ? NULL : found->second );
453 template <
class PBASE>
456 AIDA::IProfile2D * h(NULL);
460 h = ( profile2DMapID().end() == found ? NULL : found->second );
467 template <
class PBASE>
471 histo1DMapID () . size () +
472 histo2DMapID () . size () +
473 histo3DMapID () . size () +
474 profile1DMapID () . size () +
475 profile2DMapID () . size () ;
480 template <
class PBASE>
482 (
const std::string & title ,
485 if ( useNumericAutoIDs() || title.empty() )
487 if ( !useNumericAutoIDs() )
489 this -> Warning(
"Cannot generate automatic literal ID from an empty title ! Using numeric ID instead for histogram ID",
493 ID =
HistoID( totalNumberOfHistos() + 1 + histoOffSet() );
495 while ( histoExists( ID ) ) { ID =
HistoID ( ID.
numeric() + 1 ) ; }
500 ID =
HistoID( this->convertTitleToID(title) );
508 template <
class PBASE>
512 std::string tmp_id = title;
513 for ( std::map<std::string,std::string>::const_iterator
i =
514 m_idReplaceInfo.begin() ;
i != m_idReplaceInfo.end(); ++
i )
516 stringSearchReplace( tmp_id,
i->first,
i->second );
523 template <
class PBASE>
525 ( std::string & title ,
526 const std::string & A ,
527 const std::string & B )
const
529 std::string::size_type slash = title.find_first_of ( A ) ;
530 while ( std::string::npos != slash )
532 title = title.substr(0,slash) + B + title.substr(slash+A.size());
533 slash = title.find_first_of( A );
539 template <
class PBASE >
544 if (
this -> histosPrint() ) {
this -> printHistos (
MSG::ALWAYS ) ; }
549 template <
class PBASE >
552 const std::string
path = histoTopDir() + histoDir();
553 return ( splitHistoDir() ? dirHbookName(path) : path );
574 #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.
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 ...
This class is used for returning status codes from appropriate routines.
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)
map_type::const_iterator const_iterator
void stringSearchReplace(std::string &title, const std::string &A, const std::string &B) const
Searches 'title' for all instancies of 'A' and replaces them with 'B'.
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".
std::string convertTitleToID(const std::string &title) const
Create an ID string from a title string.
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)
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.
std::string toString(const AIDA::IHistogram1D *histo) const
make the string representation according to the default format
void initGaudiHistosConstructor()
Constructor initialisation and job options.