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 ; }
244 Gaudi::Utils::Histos::Table table
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 ) ;
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() <<
"\" :-" ;
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() <<
"\" :-" ;
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() <<
"\" :-" ;
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() <<
"\" :-" ;
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>
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>
514 m_idReplaceInfo.begin() ;
i != m_idReplaceInfo.end(); ++
i )
516 stringSearchReplace( tmp_id,
i->first,
i->second );
523 template <
class PBASE>
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 >
553 return ( splitHistoDir() ? dirHbookName(path) : path );
574 #endif // GAUDIALG_GAUDIHISTOS_ICPP