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" )
71 (
"HistoCheckForNaN" ,
72 m_checkForNaN =
true ,
73 "Switch on/off the checks for NaN and Infinity for histogram fill" ) ;
77 m_splitHistoDir =
false ,
78 "Split long directory names into short pieces (suitable for HBOOK)" );
83 "OffSet for automatically assigned histogram numerical identifiers " ) ;
88 "Top level histogram directory (take care that it ends with '/')" ) ;
92 m_histoDir = this->name() ,
93 "Histogram Directory" ) ;
95 this->declareProperty (
"FullDetail" , m_fullDetail =
false ) ;
97 this->declareProperty (
"MonitorHistograms" , m_declareMoniHists =
true ) ;
100 (
"FormatFor1DHistoTable" ,
102 "Format string for printout of 1D histograms" ) ;
104 this->declareProperty
105 (
"ShortFormatFor1DHistoTable" ,
106 m_histo1DTableFormatShort =
" | %1$-25.25s %2%" ,
107 "Format string for printout of 1D histograms" ) ;
109 this->declareProperty
110 (
"HeaderFor1DHistoTable" ,
112 "The table header for printout of 1D histograms " ) ;
113 this->declareProperty
114 (
"UseSequencialNumericAutoIDs", m_useNumericAutoIDs =
false,
115 "Flag to allow users to switch back to the old style of creating numerical automatic IDs" );
116 m_idReplaceInfo.clear();
117 m_idReplaceInfo[
"/"] =
"=SLASH=";
118 this->declareProperty
119 (
"AutoStringIDPurgeMap", m_idReplaceInfo,
120 "Map of strings to search and replace when using the title as the basis of automatically generated literal IDs" );
125 template <
class PBASE>
139 if ( !produceHistos() )
141 this->debug() <<
"Histogram production is switched OFF" <<
endmsg;
146 if ( this->histoSvc() == NULL )
147 {
return this->Error(
"initialize():: IHistogramSvc* is invalid"); }
150 if ( useNumericAutoIDs() )
153 Warning(
"Using numerical automatic IDs. These are not guaranteed to be totally deterministic. Use with care...",
159 (
"The histogram path is set to be '" + histoPath() +
"'",
167 template <
class PBASE>
177 if ( produceHistos() )
183 const unsigned int n1D = histo1DMapID () . size () ;
184 const unsigned int n2D = histo2DMapID () . size () ;
185 const unsigned int n3D = histo3DMapID () . size () ;
186 const unsigned int n1DP = profile1DMapID () . size () ;
187 const unsigned int n2DP = profile2DMapID () . size () ;
188 const unsigned int total = n1D+n2D+n3D+n1DP+n2DP;
191 this->always() <<
"Booked " << total <<
" Histogram(s) : ";
192 if ( n1D>0 ) this->always() <<
"1D=" << n1D <<
" ";
193 if ( n2D>0 ) this->always() <<
"2D=" << n2D <<
" ";
194 if ( n3D>0 ) this->always() <<
"3D=" << n3D <<
" ";
195 if ( n1DP>0 ) this->always() <<
"1DProf=" << n1DP <<
" ";
196 if ( n2DP>0 ) this->always() <<
"2DProf=" << n2DP <<
" ";
202 if ( histosPrint() ) { printHistos() ; }
207 m_histo1DMapTitle . clear () ;
208 m_histo2DMapTitle . clear () ;
209 m_histo3DMapTitle . clear () ;
210 m_histo1DMapID . clear () ;
211 m_histo2DMapID . clear () ;
212 m_histo3DMapID . clear () ;
213 m_profile1DMapTitle . clear () ;
214 m_profile2DMapTitle . clear () ;
215 m_profile1DMapID . clear () ;
216 m_profile2DMapID . clear () ;
219 return PBASE::finalize();
224 template <
class PBASE>
227 using namespace Gaudi::Utils::Histos ;
232 { this->msgStream(level) <<
"No histograms are booked" <<
endmsg ; }
240 Gaudi::Utils::Histos::Table table
241 ( m_histo1DTableFormat ,
242 m_histo1DTableHeader ) ;
244 if ( !histo1DMapID().
empty() )
246 msg <<
"List of booked 1D histograms in directory "
247 <<
"\"" << histoPath() <<
"\" :-" ;
249 if ( !table.header().empty() )
252 (
"ID" , table.header() , m_histo1DTableFormatShort ) ;
256 OrderedMapType OrderedMap ( histo1DMapID().begin() , histo1DMapID().
end() );
258 for ( OrderedMapType::const_iterator entry = OrderedMap.begin() ;
259 OrderedMap.end() != entry ; ++entry )
261 const AIDA::IHistogram1D* aida = entry->second ;
263 { this->error() <<
"IHistogram1D points to NULL" <<
endmsg ; continue ; }
268 m_histo1DTableFormatShort ) ;
273 if ( !histo2DMapID().
empty() )
275 msg <<
"List of booked 2D histograms in directory "
276 <<
"\"" << histoPath() <<
"\" :-" ;
280 OrderedMapType OrderedMap ( histo2DMapID().begin() , histo2DMapID().
end() ) ;
282 for ( OrderedMapType::const_iterator entry = OrderedMap.begin() ;
283 OrderedMap.end() != entry ; ++entry )
285 const AIDA::IHistogram2D* aida = entry->second ;
287 { this->error() <<
"IHistogram2D points to NULL" <<
endmsg ; continue ; }
294 if ( !histo3DMapID().
empty() )
296 msg <<
"List of booked 3D histograms in directory "
297 <<
"\"" << histoPath() <<
"\" :-" ;
300 OrderedMapType OrderedMap ( histo3DMapID().begin() , histo3DMapID().
end() ) ;
302 for ( OrderedMapType::const_iterator entry = OrderedMap.begin() ;
303 OrderedMap.end() != entry ; ++entry )
305 const AIDA::IHistogram3D* aida = entry->second ;
307 { this->error() <<
"IHistogram3D points to NULL" <<
endmsg ; continue ; }
313 if ( !profile1DMapID().
empty() )
315 msg <<
"List of booked 1D profile histograms in directory "
316 <<
"\"" << histoPath() <<
"\" :-" ;
319 OrderedMapType OrderedMap ( profile1DMapID().begin() , profile1DMapID().
end() ) ;
321 for ( OrderedMapType::const_iterator entry = OrderedMap.begin() ;
322 OrderedMap.end() != entry ; ++entry )
324 const AIDA::IProfile1D* aida = entry->second ;
326 { this->error() <<
"IProfile1D points to NULL" <<
endmsg ; continue ; }
332 if ( !profile2DMapID().
empty() )
334 msg <<
"List of booked 2D profile histograms in directory "
335 <<
"\"" << histoPath() <<
"\" :-" ;
338 OrderedMapType OrderedMap ( profile2DMapID().begin() , profile2DMapID().
end() ) ;
340 for ( OrderedMapType::const_iterator entry = OrderedMap.begin() ;
341 OrderedMap.end() != entry ; ++entry )
343 const AIDA::IProfile2D* aida = entry->second ;
345 { this->error() <<
"IProfile2D points to NULL" <<
endmsg ; continue ; }
351 return this->totalNumberOfHistos() ;
356 template <
class PBASE>
359 return ( histo1DMapTitle () .
empty() &&
360 histo2DMapTitle () .
empty() &&
361 histo3DMapTitle () .
empty() &&
362 profile1DMapTitle () .
empty() &&
363 profile2DMapTitle () .
empty() &&
364 histo1DMapID () .
empty() &&
365 histo2DMapID () .
empty() &&
366 histo3DMapID () .
empty() &&
367 profile1DMapID () .
empty() &&
368 profile2DMapID () .
empty() );
373 template <
class PBASE>
375 (
const AIDA::IBaseHistogram* hist,
378 if ( hist && m_declareMoniHists )
382 this->debug() <<
"Monitoring histogram '"
386 this->declareInfo ( histoPath()+
"/"+ID.
idAsString() ,
394 template <
class PBASE>
397 AIDA::IHistogram1D * h(NULL);
401 h = ( histo1DMapID().end() == found ? NULL : found->second );
408 template <
class PBASE>
411 AIDA::IHistogram2D * h(NULL);
415 h = ( histo2DMapID().end() == found ? NULL : found->second );
422 template <
class PBASE>
425 AIDA::IHistogram3D * h(NULL);
428 h = ( histo3DMapID().end() == found ? NULL : found->second );
435 template <
class PBASE>
438 AIDA::IProfile1D * h(NULL);
442 h = ( profile1DMapID().end() == found ? NULL : found->second );
449 template <
class PBASE>
452 AIDA::IProfile2D * h(NULL);
456 h = ( profile2DMapID().end() == found ? NULL : found->second );
463 template <
class PBASE>
467 histo1DMapID () . size () +
468 histo2DMapID () . size () +
469 histo3DMapID () . size () +
470 profile1DMapID () . size () +
471 profile2DMapID () . size () ;
476 template <
class PBASE>
481 if ( useNumericAutoIDs() || title.empty() )
483 if ( !useNumericAutoIDs() )
485 this -> Warning(
"Cannot generate automatic literal ID from an empty title ! Using numeric ID instead for histogram ID",
489 ID =
HistoID( totalNumberOfHistos() + 1 + histoOffSet() );
491 while ( histoExists( ID ) ) { ID =
HistoID ( ID.
numeric() + 1 ) ; }
496 ID =
HistoID( this->convertTitleToID(title) );
504 template <
class PBASE>
510 m_idReplaceInfo.begin() ;
i != m_idReplaceInfo.end(); ++
i )
512 stringSearchReplace( tmp_id,
i->first,
i->second );
519 template <
class PBASE>
526 while ( std::string::npos != slash )
528 title = title.substr(0,slash) + B + title.substr(slash+A.size());
529 slash = title.find_first_of( A );
535 template <
class PBASE >
540 if (
this -> histosPrint() ) {
this -> printHistos (
MSG::ALWAYS ) ; }
545 template <
class PBASE >
549 return ( splitHistoDir() ? dirHbookName(path) : path );
570 #endif // GAUDIALG_GAUDIHISTOS_ICPP