Gaudi Framework, version v20r3

Generated: 24 Nov 2008

HistogramPersistencySvc.cpp

Go to the documentation of this file.
00001 // $Id: HistogramPersistencySvc.cpp,v 1.9 2008/10/09 13:40:18 marcocle Exp $ 
00002 // ============================================================================
00003 //      HistogramPersistencySvc.cpp
00004 //--------------------------------------------------------------------
00005 //
00006 //      Package    : System ( The LHCb Offline System)
00007 //
00008 //  Description: implementation of the Event data persistency service
00009 //               This specialized service only deals with event related 
00010 //               data
00011 //
00012 //      Author     : M.Frank
00013 //  History    :
00014 // +---------+----------------------------------------------+---------
00015 // |    Date |                 Comment                      | Who     
00016 // +---------+----------------------------------------------+---------
00017 // | 29/10/98| Initial version                              | MF
00018 // +---------+----------------------------------------------+---------
00019 //
00020 //====================================================================
00021 #define  PERSISTENCYSVC_HISTOGRAMPERSISTENCYSVC_CPP
00022 // ============================================================================
00023 // Include files 
00024 // ============================================================================
00025 // GaudiKernel
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 // ============================================================================
00035 // local
00036 // ============================================================================
00037 #include "HistogramPersistencySvc.h"
00038 // ============================================================================
00039 // AIDA 
00040 // ============================================================================
00041 #include "AIDA/IBaseHistogram.h"
00042 // ============================================================================
00043 // Instantiation of a static factory class used by clients to create
00044 // instances of this service
00045 DECLARE_SERVICE_FACTORY(HistogramPersistencySvc)
00046 
00047 // ============================================================================
00048 // Finalize the service.
00049 StatusCode HistogramPersistencySvc::finalize()
00050 {
00051   //
00052   MsgStream log ( msgSvc() , name() );
00053   if ( !(m_convert.empty() && m_exclude.empty()) )
00054   { // print message if any of the two properties is used
00055     log << MSG::INFO  << "Histograms Converted/Excluded: " 
00056         << m_converted.size() << "/" << m_excluded.size() << endreq ;
00057   }
00058   //
00059   if ( !m_excluded.empty() ) 
00060   {
00061     log << MSG::DEBUG << "Excluded  Histos : #" << m_excluded.size() ;
00062     for ( Set::const_iterator item = m_excluded.begin() ; 
00063           m_excluded.end() != item ; ++item ) 
00064     { log << std::endl << "  '" << (*item) << "'" ; }
00065     log << endreq ;
00066   }
00067   //
00068   if ( !m_converted.empty() ) 
00069   {
00070     log << MSG::DEBUG << "Converted Histos : #" << m_converted.size() ;
00071     for ( Set::const_iterator item = m_converted.begin() ; 
00072           m_converted.end() != item ; ++item ) 
00073     { log << std::endl << "  '" << (*item) << "'" ; }
00074     log << endreq ;
00075   }
00076   //
00077   StatusCode status = PersistencySvc::finalize();
00078   return status;
00079 }
00080 // ============================================================================
00081 // Initialize the service.
00082 // ============================================================================
00083 StatusCode HistogramPersistencySvc::initialize()     {
00084   StatusCode status = PersistencySvc::initialize();
00085   if ( status.isSuccess() )   {
00086     status = reinitialize();
00087   }
00088   return status;
00089 }
00090 // ============================================================================
00091 // Reinitialize the service.
00092 // ============================================================================
00093 StatusCode HistogramPersistencySvc::reinitialize()
00094 {
00095   MsgStream log(msgSvc(), name());
00096   // Obtain the IProperty of the ApplicationMgr
00097   SmartIF<IProperty> prpMgr(serviceLocator());
00098   if ( !prpMgr.isValid() )   {
00099     log << MSG::FATAL << "IProperty interface not found in ApplicationMgr." << endreq;
00100     return StatusCode::FAILURE;
00101   }
00102   else {
00103     setProperty(prpMgr->getProperty("HistogramPersistency")).ignore();
00104   }
00105   
00106   // To keep backward compatibility, we set the property of conversion service
00107   // into JobOptions catalogue
00108   if( m_outputFile != "" ) {
00109     IJobOptionsSvc* joptsvc;
00110     if( serviceLocator()->service("JobOptionsSvc", joptsvc ).isSuccess() ) {
00111       StringProperty p("OutputFile", m_outputFile);
00112       if ( m_histPersName == "ROOT" ) {
00113         joptsvc->addPropertyToCatalogue("RootHistSvc", p).ignore();
00114       } else if (m_histPersName == "HBOOK" ) {
00115         joptsvc->addPropertyToCatalogue("HbookHistSvc", p).ignore();
00116       }
00117       joptsvc->release();
00118     }
00119   }
00120 
00121   // Load the Histogram persistency service that's required as default
00122   setConversionSvc(0).ignore();
00123   if ( m_histPersName == "ROOT" ) {
00124     setConversionSvc(service("RootHistSvc")).ignore();
00125     if ( !conversionSvc() ) {
00126       return StatusCode::FAILURE;
00127     }
00128     enable(true);
00129   }
00130   else if ( m_histPersName == "HBOOK" ) {
00131     setConversionSvc(service("HbookHistSvc")).ignore();
00132     if ( !conversionSvc() ) {
00133       return StatusCode::FAILURE;
00134     }
00135     enable(true);
00136   }
00137   else if ( m_histPersName == "NONE" ) {
00138     enable(false);
00139     if ( m_warnings ) {
00140       log << MSG::WARNING << "Histograms saving not required." << endreq;
00141     }
00142   }
00143   else {
00144     setConversionSvc(service(m_histPersName)).ignore();
00145     if ( !conversionSvc() ) {
00146       return StatusCode::FAILURE;
00147     }
00148     enable(true);
00149     if ( m_warnings ) {
00150       log << MSG::WARNING << "Unknown Histogram Persistency Mechanism " << m_histPersName << endreq;
00151     }
00152   }
00153   return StatusCode::SUCCESS;
00154 }
00155 // ============================================================================
00156 namespace 
00157 {
00158   // ==========================================================================
00160   const std::string s_NULL = "<NULL>" ;
00161   // ==========================================================================
00167   // ==========================================================================
00168   inline bool match 
00169   ( const std::string& name , 
00170     const std::string& pat  ) 
00171   {
00172     // the most primitive match
00173     return std::string::npos != name.find ( pat );
00174   }
00175   // ==========================================================================
00180   inline const std::string& oname ( const DataObject* obj ) 
00181   {
00182     if ( 0 == obj ) { return s_NULL ; }
00183     const IRegistry* reg = obj->registry() ;
00184     return ( 0 == reg ) ? obj -> name () : reg -> identifier () ;
00185   }
00186   // ==========================================================================  
00192   inline bool match ( const DataObject*  obj , 
00193                       const std::string& pat ) 
00194   {
00195     if ( 0 == obj ) { return false ; }
00196     return match ( oname ( obj ) , pat ) ;
00197   }
00198   // ==========================================================================
00199 }
00200 // ============================================================================
00201 // Convert the transient object to the requested representation.
00202 // ============================================================================
00203 StatusCode HistogramPersistencySvc::createRep
00204 ( DataObject*      pObj     , 
00205   IOpaqueAddress*& refpAddr )  
00206 {
00207   // enable the conversion 
00208   enable ( true ) ;
00209   // conversion is possible ?
00210   if ( "NONE" == m_histPersName ) 
00211   {
00212     enable ( false ) ; 
00213     return PersistencySvc::createRep ( pObj , refpAddr ) ;   // RETURN 
00214   }
00215   // histogram ?
00216   if ( 0 != dynamic_cast<AIDA::IBaseHistogram*> ( pObj ) ) 
00217   {
00218     bool select = false ;
00219     // Empty ConvertHistos property means convert all
00220     if ( m_convert.empty() ) { select = true ; }
00221     else  
00222     {
00223       for ( Strings::const_iterator item = m_convert.begin() ; 
00224             m_convert.end() != item ; ++item ) 
00225       { if ( match ( pObj , *item ) ) { select = true ; break ; } }
00226     }
00227     // exclude ?
00228     for ( Strings::const_iterator item = m_exclude.begin() ;
00229           m_exclude.end() != item && select ; ++item ) 
00230     { if ( match ( pObj , *item ) ) { select = false ; break ; } }
00231     //
00232     enable ( select ) ;
00233     //
00234     const std::string& path = oname ( pObj ) ;
00235     //
00236     if ( !select ) { m_excluded.insert  ( path ) ; }
00237     else           { m_converted.insert ( path ) ; }
00238   }
00239   //
00240   return PersistencySvc::createRep ( pObj , refpAddr ) ;     // RETURN 
00241 }
00242 // ============================================================================
00243 // Standard Constructor
00244 // ============================================================================
00245 HistogramPersistencySvc::HistogramPersistencySvc
00246 ( const std::string& name , 
00247   ISvcLocator*       svc  )
00248   :  PersistencySvc(name, svc)
00249   //
00250   , m_convert   () 
00251   , m_exclude   () 
00252   , m_converted () 
00253   , m_excluded  ()
00254   //
00255 {
00256   std::vector<std::string> defServices;
00257   defServices.push_back("HbookHistSvc");
00258   defServices.push_back("RootHistSvc");
00259   m_svcNames.set(defServices);
00260   declareProperty ("HistogramPersistency", m_histPersName = "");
00261   declareProperty ("OutputFile", m_outputFile = "");
00262   //
00263   declareProperty 
00264     ("ConvertHistos" , m_convert , 
00265      "The list of patterns to be accepted for conversion" ) ;
00266   //
00267   declareProperty 
00268     ("ExcludeHistos" , m_exclude , 
00269      "The list of patterns to be excluded for conversion" ) ;
00270   declareProperty("Warnings",m_warnings=true,
00271                   "Set this property to false to suppress warning messages");
00272 }
00273 // ============================================================================
00274 // Standard Destructor
00275 // ============================================================================
00276 HistogramPersistencySvc::~HistogramPersistencySvc()   {}
00277 // ============================================================================
00278 
00279 
00280 // ============================================================================
00281 // The END
00282 // ============================================================================

Generated at Mon Nov 24 14:38:49 2008 for Gaudi Framework, version v20r3 by Doxygen version 1.5.6 written by Dimitri van Heesch, © 1997-2004