3 #ifndef GAUDIALG_GAUDIHISTOS_ICPP
4 #define GAUDIALG_GAUDIHISTOS_ICPP 1
42 class IBaseHistogram ;
54 template <
class PBASE>
60 m_produceHistos =
true ,
61 "Switch on/off the production of histograms" ) ;
65 m_histosPrint =
false ,
66 "Switch on/off the printout of histograms at finalization" )
70 (
"HistoCheckForNaN" ,
71 m_checkForNaN =
true ,
72 "Switch on/off the checks for NaN and Infinity for histogram fill" ) ;
76 m_splitHistoDir =
false ,
77 "Split long directory names into short pieces (suitable for HBOOK)" );
82 "OffSet for automatically assigned histogram numerical identifiers " ) ;
87 "Top level histogram directory (take care that it ends with '/')" ) ;
91 m_histoDir = this->name() ,
92 "Histogram Directory" ) ;
94 this->declareProperty (
"FullDetail" , m_fullDetail =
false ) ;
96 this->declareProperty (
"MonitorHistograms" , m_declareMoniHists =
true ) ;
99 (
"FormatFor1DHistoTable" ,
101 "Format string for printout of 1D histograms" ) ;
103 this->declareProperty
104 (
"ShortFormatFor1DHistoTable" ,
105 m_histo1DTableFormatShort =
" | %1$-25.25s %2%" ,
106 "Format string for printout of 1D histograms" ) ;
108 this->declareProperty
109 (
"HeaderFor1DHistoTable" ,
111 "The table header for printout of 1D histograms " ) ;
112 this->declareProperty
113 (
"UseSequencialNumericAutoIDs", m_useNumericAutoIDs =
false,
114 "Flag to allow users to switch back to the old style of creating numerical automatic IDs" );
115 m_idReplaceInfo.clear();
116 m_idReplaceInfo[
"/"] =
"=SLASH=";
117 this->declareProperty
118 (
"AutoStringIDPurgeMap", m_idReplaceInfo,
119 "Map of strings to search and replace when using the title as the basis of automatically generated literal IDs" );
124 template <
class PBASE>
138 if ( !produceHistos() )
140 this->debug() <<
"Histogram production is switched OFF" <<
endmsg;
145 if ( this->histoSvc() == NULL )
146 {
return this->Error(
"initialize():: IHistogramSvc* is invalid"); }
149 if ( useNumericAutoIDs() )
152 Warning(
"Using numerical automatic IDs. These are not guaranteed to be totally deterministic. Use with care...",
158 (
"The histogram path is set to be '" + histoPath() +
"'",
166 template <
class PBASE>
176 if ( produceHistos() )
182 const unsigned int n1D = histo1DMapID () . size () ;
183 const unsigned int n2D = histo2DMapID () . size () ;
184 const unsigned int n3D = histo3DMapID () . size () ;
185 const unsigned int n1DP = profile1DMapID () . size () ;
186 const unsigned int n2DP = profile2DMapID () . size () ;
187 const unsigned int total = n1D+n2D+n3D+n1DP+n2DP;
190 this->always() <<
"Booked " << total <<
" Histogram(s) : ";
191 if ( n1D>0 ) this->always() <<
"1D=" << n1D <<
" ";
192 if ( n2D>0 ) this->always() <<
"2D=" << n2D <<
" ";
193 if ( n3D>0 ) this->always() <<
"3D=" << n3D <<
" ";
194 if ( n1DP>0 ) this->always() <<
"1DProf=" << n1DP <<
" ";
195 if ( n2DP>0 ) this->always() <<
"2DProf=" << n2DP <<
" ";
201 if ( histosPrint() ) { printHistos() ; }
206 m_histo1DMapTitle . clear () ;
207 m_histo2DMapTitle . clear () ;
208 m_histo3DMapTitle . clear () ;
209 m_histo1DMapID . clear () ;
210 m_histo2DMapID . clear () ;
211 m_histo3DMapID . clear () ;
212 m_profile1DMapTitle . clear () ;
213 m_profile2DMapTitle . clear () ;
214 m_profile1DMapID . clear () ;
215 m_profile2DMapID . clear () ;
218 return PBASE::finalize();
223 template <
class PBASE>
226 using namespace Gaudi::Utils::Histos ;
231 { this->msgStream(level) <<
"No histograms are booked" <<
endmsg ; }
239 Gaudi::Utils::Histos::Table table
240 ( m_histo1DTableFormat ,
241 m_histo1DTableHeader ) ;
243 if ( !histo1DMapID().
empty() )
245 msg <<
"List of booked 1D histograms in directory "
246 <<
"\"" << histoPath() <<
"\" :-" ;
248 if ( !table.header().empty() )
251 (
"ID" , table.header() , m_histo1DTableFormatShort ) ;
255 OrderedMapType OrderedMap ( histo1DMapID().begin() , histo1DMapID().
end() );
257 for ( OrderedMapType::const_iterator entry = OrderedMap.begin() ;
258 OrderedMap.end() != entry ; ++entry )
260 const AIDA::IHistogram1D* aida = entry->second ;
262 { this->error() <<
"IHistogram1D points to NULL" <<
endmsg ; continue ; }
267 m_histo1DTableFormatShort ) ;
272 if ( !histo2DMapID().
empty() )
274 msg <<
"List of booked 2D histograms in directory "
275 <<
"\"" << histoPath() <<
"\" :-" ;
279 OrderedMapType OrderedMap ( histo2DMapID().begin() , histo2DMapID().
end() ) ;
281 for ( OrderedMapType::const_iterator entry = OrderedMap.begin() ;
282 OrderedMap.end() != entry ; ++entry )
284 const AIDA::IHistogram2D* aida = entry->second ;
286 { this->error() <<
"IHistogram2D points to NULL" <<
endmsg ; continue ; }
293 if ( !histo3DMapID().
empty() )
295 msg <<
"List of booked 3D histograms in directory "
296 <<
"\"" << histoPath() <<
"\" :-" ;
299 OrderedMapType OrderedMap ( histo3DMapID().begin() , histo3DMapID().
end() ) ;
301 for ( OrderedMapType::const_iterator entry = OrderedMap.begin() ;
302 OrderedMap.end() != entry ; ++entry )
304 const AIDA::IHistogram3D* aida = entry->second ;
306 { this->error() <<
"IHistogram3D points to NULL" <<
endmsg ; continue ; }
312 if ( !profile1DMapID().
empty() )
314 msg <<
"List of booked 1D profile histograms in directory "
315 <<
"\"" << histoPath() <<
"\" :-" ;
318 OrderedMapType OrderedMap ( profile1DMapID().begin() , profile1DMapID().
end() ) ;
320 for ( OrderedMapType::const_iterator entry = OrderedMap.begin() ;
321 OrderedMap.end() != entry ; ++entry )
323 const AIDA::IProfile1D* aida = entry->second ;
325 { this->error() <<
"IProfile1D points to NULL" <<
endmsg ; continue ; }
331 if ( !profile2DMapID().
empty() )
333 msg <<
"List of booked 2D profile histograms in directory "
334 <<
"\"" << histoPath() <<
"\" :-" ;
337 OrderedMapType OrderedMap ( profile2DMapID().begin() , profile2DMapID().
end() ) ;
339 for ( OrderedMapType::const_iterator entry = OrderedMap.begin() ;
340 OrderedMap.end() != entry ; ++entry )
342 const AIDA::IProfile2D* aida = entry->second ;
344 { this->error() <<
"IProfile2D points to NULL" <<
endmsg ; continue ; }
350 return this->totalNumberOfHistos() ;
355 template <
class PBASE>
358 return ( histo1DMapTitle () .
empty() &&
359 histo2DMapTitle () .
empty() &&
360 histo3DMapTitle () .
empty() &&
361 profile1DMapTitle () .
empty() &&
362 profile2DMapTitle () .
empty() &&
363 histo1DMapID () .
empty() &&
364 histo2DMapID () .
empty() &&
365 histo3DMapID () .
empty() &&
366 profile1DMapID () .
empty() &&
367 profile2DMapID () .
empty() );
372 template <
class PBASE>
374 (
const AIDA::IBaseHistogram* hist,
377 if ( hist && m_declareMoniHists )
381 this->debug() <<
"Monitoring histogram '"
385 this->declareInfo ( histoPath()+
"/"+ID.
idAsString() ,
393 template <
class PBASE>
396 AIDA::IHistogram1D * h(NULL);
400 h = ( histo1DMapID().end() == found ? NULL : found->second );
407 template <
class PBASE>
410 AIDA::IHistogram2D * h(NULL);
414 h = ( histo2DMapID().end() == found ? NULL : found->second );
421 template <
class PBASE>
424 AIDA::IHistogram3D * h(NULL);
427 h = ( histo3DMapID().end() == found ? NULL : found->second );
434 template <
class PBASE>
437 AIDA::IProfile1D * h(NULL);
441 h = ( profile1DMapID().end() == found ? NULL : found->second );
448 template <
class PBASE>
451 AIDA::IProfile2D * h(NULL);
455 h = ( profile2DMapID().end() == found ? NULL : found->second );
462 template <
class PBASE>
466 histo1DMapID () . size () +
467 histo2DMapID () . size () +
468 histo3DMapID () . size () +
469 profile1DMapID () . size () +
470 profile2DMapID () . size () ;
475 template <
class PBASE>
480 if ( useNumericAutoIDs() || title.empty() )
482 if ( !useNumericAutoIDs() )
484 this -> Warning(
"Cannot generate automatic literal ID from an empty title ! Using numeric ID instead for histogram ID",
488 ID =
HistoID( totalNumberOfHistos() + 1 + histoOffSet() );
490 while ( histoExists( ID ) ) { ID =
HistoID ( ID.
numeric() + 1 ) ; }
495 ID =
HistoID( this->convertTitleToID(title) );
503 template <
class PBASE>
509 m_idReplaceInfo.begin() ;
i != m_idReplaceInfo.end(); ++
i )
511 stringSearchReplace( tmp_id,
i->first,
i->second );
518 template <
class PBASE>
525 while ( std::string::npos != slash )
527 title = title.substr(0,slash) + B + title.substr(slash+A.size());
528 slash = title.find_first_of( A );
534 template <
class PBASE >
539 if (
this -> histosPrint() ) {
this -> printHistos (
MSG::ALWAYS ) ; }
560 #endif // GAUDIALG_GAUDIHISTOS_ICPP