Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #define PERSISTENCYSVC_HISTOGRAMPERSISTENCYSVC_CPP
00022
00023
00024
00025
00026
00027 #include "GaudiKernel/SmartIF.h"
00028 #include "GaudiKernel/MsgStream.h"
00029 #include "GaudiKernel/SvcFactory.h"
00030 #include "GaudiKernel/ISvcLocator.h"
00031 #include "GaudiKernel/IJobOptionsSvc.h"
00032 #include "GaudiKernel/DataObject.h"
00033 #include "GaudiKernel/IRegistry.h"
00034 #include "GaudiKernel/IDataProviderSvc.h"
00035
00036
00037
00038 #include "HistogramPersistencySvc.h"
00039
00040
00041
00043 #define class class GAUDI_API
00044 #include "AIDA/IBaseHistogram.h"
00045 #undef class
00046
00047
00048
00049 DECLARE_SERVICE_FACTORY(HistogramPersistencySvc)
00050
00051
00052
00053 StatusCode HistogramPersistencySvc::finalize()
00054 {
00055
00056 MsgStream log ( msgSvc() , name() );
00057 if ( !(m_convert.empty() && m_exclude.empty()) )
00058 {
00059 log << MSG::INFO << "Histograms Converted/Excluded: "
00060 << m_converted.size() << "/" << m_excluded.size() << endmsg ;
00061 }
00062 if (msgLevel(MSG::DEBUG)) {
00063 if ( !m_excluded.empty() )
00064 {
00065 log << MSG::DEBUG << "Excluded Histos : #" << m_excluded.size() ;
00066 for ( Set::const_iterator item = m_excluded.begin() ;
00067 m_excluded.end() != item ; ++item )
00068 { log << std::endl << " '" << (*item) << "'" ; }
00069 log << endmsg ;
00070 }
00071
00072 if ( !m_converted.empty() )
00073 {
00074 log << MSG::DEBUG << "Converted Histos : #" << m_converted.size() ;
00075 for ( Set::const_iterator item = m_converted.begin() ;
00076 m_converted.end() != item ; ++item )
00077 { log << std::endl << " '" << (*item) << "'" ; }
00078 log << endmsg ;
00079 }
00080 }
00081 return PersistencySvc::finalize();
00082 }
00083
00084
00085
00086 StatusCode HistogramPersistencySvc::initialize() {
00087 StatusCode status = PersistencySvc::initialize();
00088 if ( status.isSuccess() ) {
00089 status = reinitialize();
00090 }
00091 return status;
00092 }
00093
00094
00095
00096 StatusCode HistogramPersistencySvc::reinitialize()
00097 {
00098 MsgStream log(msgSvc(), name());
00099
00100 SmartIF<IProperty> prpMgr(serviceLocator());
00101 if ( !prpMgr.isValid() ) {
00102 log << MSG::FATAL << "IProperty interface not found in ApplicationMgr." << endmsg;
00103 return StatusCode::FAILURE;
00104 }
00105 else {
00106 setProperty(prpMgr->getProperty("HistogramPersistency")).ignore();
00107 }
00108
00109
00110
00111 if( m_outputFile != "" ) {
00112 SmartIF<IJobOptionsSvc> joptsvc(serviceLocator()->service("JobOptionsSvc"));
00113 if( joptsvc.isValid() ) {
00114 StringProperty p("OutputFile", m_outputFile);
00115 if ( m_histPersName == "ROOT" ) {
00116 joptsvc->addPropertyToCatalogue("RootHistSvc", p).ignore();
00117 } else if (m_histPersName == "HBOOK" ) {
00118 joptsvc->addPropertyToCatalogue("HbookHistSvc", p).ignore();
00119 }
00120 }
00121 }
00122
00123
00124 setConversionSvc(0).ignore();
00125 if ( m_histPersName == "ROOT" ) {
00126 setConversionSvc(service("RootHistSvc")).ignore();
00127 if ( !conversionSvc() ) {
00128 return StatusCode::FAILURE;
00129 }
00130 enable(true);
00131 }
00132 else if ( m_histPersName == "HBOOK" ) {
00133 setConversionSvc(service("HbookHistSvc")).ignore();
00134 if ( !conversionSvc() ) {
00135 return StatusCode::FAILURE;
00136 }
00137 enable(true);
00138 }
00139 else if ( m_histPersName == "NONE" ) {
00140 enable(false);
00141 if ( m_warnings ) {
00142 log << MSG::WARNING << "Histograms saving not required." << endmsg;
00143 }
00144 }
00145 else {
00146 setConversionSvc(service(m_histPersName)).ignore();
00147 if ( !conversionSvc() ) {
00148 return StatusCode::FAILURE;
00149 }
00150 enable(true);
00151 if ( m_warnings ) {
00152 log << MSG::WARNING << "Unknown Histogram Persistency Mechanism " << m_histPersName << endmsg;
00153 }
00154 }
00155 return StatusCode::SUCCESS;
00156 }
00157
00158 namespace
00159 {
00160
00162 const std::string s_NULL = "<NULL>" ;
00163
00169
00170 inline bool match
00171 ( const std::string& name ,
00172 const std::string& pat )
00173 {
00174
00175 return std::string::npos != name.find ( pat );
00176 }
00177
00182 inline const std::string& oname ( const DataObject* obj )
00183 {
00184 if ( 0 == obj ) { return s_NULL ; }
00185 const IRegistry* reg = obj->registry() ;
00186 return ( 0 == reg ) ? obj -> name () : reg -> identifier () ;
00187 }
00188
00194 inline bool match ( const DataObject* obj ,
00195 const std::string& pat )
00196 {
00197 if ( 0 == obj ) { return false ; }
00198 return match ( oname ( obj ) , pat ) ;
00199 }
00200
00201 }
00202
00203
00204
00205 StatusCode HistogramPersistencySvc::createRep
00206 ( DataObject* pObj ,
00207 IOpaqueAddress*& refpAddr )
00208 {
00209
00210 enable ( true ) ;
00211
00212 if ( "NONE" == m_histPersName )
00213 {
00214 enable ( false ) ;
00215 return PersistencySvc::createRep ( pObj , refpAddr ) ;
00216 }
00217
00218 if ( 0 != dynamic_cast<AIDA::IBaseHistogram*> ( pObj ) )
00219 {
00220 bool select = false ;
00221
00222 if ( m_convert.empty() ) { select = true ; }
00223 else
00224 {
00225 for ( Strings::const_iterator item = m_convert.begin() ;
00226 m_convert.end() != item ; ++item )
00227 { if ( match ( pObj , *item ) ) { select = true ; break ; } }
00228 }
00229
00230 for ( Strings::const_iterator item = m_exclude.begin() ;
00231 m_exclude.end() != item && select ; ++item )
00232 { if ( match ( pObj , *item ) ) { select = false ; break ; } }
00233
00234 enable ( select ) ;
00235
00236 const std::string& path = oname ( pObj ) ;
00237
00238 if ( !select ) { m_excluded.insert ( path ) ; }
00239 else { m_converted.insert ( path ) ; }
00240 }
00241
00242 return PersistencySvc::createRep ( pObj , refpAddr ) ;
00243 }
00244
00245
00246
00247 HistogramPersistencySvc::HistogramPersistencySvc
00248 ( const std::string& name ,
00249 ISvcLocator* svc )
00250 : PersistencySvc(name, svc)
00251
00252 , m_convert ()
00253 , m_exclude ()
00254 , m_converted ()
00255 , m_excluded ()
00256
00257 {
00258 std::vector<std::string> defServices;
00259 defServices.push_back("RootHistSvc");
00260 m_svcNames.set(defServices);
00261 declareProperty ("HistogramPersistency", m_histPersName = "");
00262 declareProperty ("OutputFile", m_outputFile = "");
00263
00264 declareProperty
00265 ("ConvertHistos" , m_convert ,
00266 "The list of patterns to be accepted for conversion" ) ;
00267
00268 declareProperty
00269 ("ExcludeHistos" , m_exclude ,
00270 "The list of patterns to be excluded for conversion" ) ;
00271 declareProperty("Warnings",m_warnings=true,
00272 "Set this property to false to suppress warning messages");
00273 }
00274
00275
00276
00277 HistogramPersistencySvc::~HistogramPersistencySvc() {}
00278
00279
00280
00281
00282
00283