Gaudi Framework, version v20r2

Generated: 18 Jul 2008

HistogramPersistencySvc.cpp

Go to the documentation of this file.
00001 // $Id: HistogramPersistencySvc.cpp,v 1.8 2008/05/14 16:33:17 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 // Finalize the service.
00048 StatusCode HistogramPersistencySvc::finalize()
00049 {
00050   //
00051   MsgStream log ( msgSvc() , name() );
00052   if ( !(m_convert.empty() && m_exclude.empty()) )
00053   { // print message if any of the two properties is used
00054     log << MSG::INFO  << "Histograms Converted/Excluded: " 
00055         << m_converted.size() << "/" << m_excluded.size() << endreq ;
00056   }
00057   //
00058   if ( !m_excluded.empty() ) 
00059   {
00060     log << MSG::DEBUG << "Excluded  Histos : #" << m_excluded.size() ;
00061     for ( Set::const_iterator item = m_excluded.begin() ; 
00062           m_excluded.end() != item ; ++item ) 
00063     { log << std::endl << "  '" << (*item) << "'" ; }
00064     log << endreq ;
00065   }
00066   //
00067   if ( !m_converted.empty() ) 
00068   {
00069     log << MSG::DEBUG << "Converted Histos : #" << m_converted.size() ;
00070     for ( Set::const_iterator item = m_converted.begin() ; 
00071           m_converted.end() != item ; ++item ) 
00072     { log << std::endl << "  '" << (*item) << "'" ; }
00073     log << endreq ;
00074   }
00075   //
00076   StatusCode status = PersistencySvc::finalize();
00077   return status;
00078 }
00079 // ============================================================================
00080 // Initialize the service.
00081 // ============================================================================
00082 StatusCode HistogramPersistencySvc::initialize()     {
00083   StatusCode status = PersistencySvc::initialize();
00084   if ( status.isSuccess() )   {
00085     status = reinitialize();
00086   }
00087   return status;
00088 }
00089 // ============================================================================
00090 // Reinitialize the service.
00091 // ============================================================================
00092 StatusCode HistogramPersistencySvc::reinitialize()
00093 {
00094   MsgStream log(msgSvc(), name());
00095   // Obtain the IProperty of the ApplicationMgr
00096   SmartIF<IProperty> prpMgr(serviceLocator());
00097   if ( !prpMgr.isValid() )   {
00098     log << MSG::FATAL << "IProperty interface not found in ApplicationMgr." << endreq;
00099     return StatusCode::FAILURE;
00100   }
00101   else {
00102     setProperty(prpMgr->getProperty("HistogramPersistency")).ignore();
00103   }
00104   
00105   // To keep backward compatibility, we set the property of conversion service
00106   // into JobOptions catalogue
00107   if( m_outputFile != "" ) {
00108     IJobOptionsSvc* joptsvc;
00109     if( serviceLocator()->service("JobOptionsSvc", joptsvc ).isSuccess() ) {
00110       StringProperty p("OutputFile", m_outputFile);
00111       if ( m_histPersName == "ROOT" ) {
00112         joptsvc->addPropertyToCatalogue("RootHistSvc", p).ignore();
00113       } else if (m_histPersName == "HBOOK" ) {
00114         joptsvc->addPropertyToCatalogue("HbookHistSvc", p).ignore();
00115       }
00116       joptsvc->release();
00117     }
00118   }
00119 
00120   // Load the Histogram persistency service that's required as default
00121   setConversionSvc(0).ignore();
00122   if ( m_histPersName == "ROOT" ) {
00123     setConversionSvc(service("RootHistSvc")).ignore();
00124     if ( !conversionSvc() ) {
00125       return StatusCode::FAILURE;
00126     }
00127     enable(true);
00128   }
00129   else if ( m_histPersName == "HBOOK" ) {
00130     setConversionSvc(service("HbookHistSvc")).ignore();
00131     if ( !conversionSvc() ) {
00132       return StatusCode::FAILURE;
00133     }
00134     enable(true);
00135   }
00136   else if ( m_histPersName == "NONE" ) {
00137     enable(false);
00138     log << MSG::WARNING << "Histograms saving not required." << endreq;
00139   }
00140   else {
00141     setConversionSvc(service(m_histPersName)).ignore();
00142     if ( !conversionSvc() ) {
00143       return StatusCode::FAILURE;
00144     }
00145     enable(true);
00146     log << MSG::WARNING << "Unknown Histogram Persistency Mechanism " << m_histPersName << endreq;
00147   }
00148   return StatusCode::SUCCESS;
00149 }
00150 // ============================================================================
00151 namespace 
00152 {
00153   // ==========================================================================
00155   const std::string s_NULL = "<NULL>" ;
00156   // ==========================================================================
00162   // ==========================================================================
00163   inline bool match 
00164   ( const std::string& name , 
00165     const std::string& pat  ) 
00166   {
00167     // the most primitive match
00168     return std::string::npos != name.find ( pat );
00169   }
00170   // ==========================================================================
00175   inline const std::string& oname ( const DataObject* obj ) 
00176   {
00177     if ( 0 == obj ) { return s_NULL ; }
00178     const IRegistry* reg = obj->registry() ;
00179     return ( 0 == reg ) ? obj -> name () : reg -> identifier () ;
00180   }
00181   // ==========================================================================  
00187   inline bool match ( const DataObject*  obj , 
00188                       const std::string& pat ) 
00189   {
00190     if ( 0 == obj ) { return false ; }
00191     return match ( oname ( obj ) , pat ) ;
00192   }
00193   // ==========================================================================
00194 }
00195 // ============================================================================
00196 // Convert the transient object to the requested representation.
00197 // ============================================================================
00198 StatusCode HistogramPersistencySvc::createRep
00199 ( DataObject*      pObj     , 
00200   IOpaqueAddress*& refpAddr )  
00201 {
00202   // enable the conversion 
00203   enable ( true ) ;
00204   // conversion is possible ?
00205   if ( "NONE" == m_histPersName ) 
00206   {
00207     enable ( false ) ; 
00208     return PersistencySvc::createRep ( pObj , refpAddr ) ;   // RETURN 
00209   }
00210   // histogram ?
00211   if ( 0 != dynamic_cast<AIDA::IBaseHistogram*> ( pObj ) ) 
00212   {
00213     bool select = false ;
00214     // Empty ConvertHistos property means convert all
00215     if ( m_convert.empty() ) { select = true ; }
00216     else  
00217     {
00218       for ( Strings::const_iterator item = m_convert.begin() ; 
00219             m_convert.end() != item ; ++item ) 
00220       { if ( match ( pObj , *item ) ) { select = true ; break ; } }
00221     }
00222     // exclude ?
00223     for ( Strings::const_iterator item = m_exclude.begin() ;
00224           m_exclude.end() != item && select ; ++item ) 
00225     { if ( match ( pObj , *item ) ) { select = false ; break ; } }
00226     //
00227     enable ( select ) ;
00228     //
00229     const std::string& path = oname ( pObj ) ;
00230     //
00231     if ( !select ) { m_excluded.insert  ( path ) ; }
00232     else           { m_converted.insert ( path ) ; }
00233   }
00234   //
00235   return PersistencySvc::createRep ( pObj , refpAddr ) ;     // RETURN 
00236 }
00237 // ============================================================================
00238 // Standard Constructor
00239 // ============================================================================
00240 HistogramPersistencySvc::HistogramPersistencySvc
00241 ( const std::string& name , 
00242   ISvcLocator*       svc  )
00243   :  PersistencySvc(name, svc)
00244   //
00245   , m_convert   () 
00246   , m_exclude   () 
00247   , m_converted () 
00248   , m_excluded  ()
00249   //
00250 {
00251   std::vector<std::string> defServices;
00252   defServices.push_back("HbookHistSvc");
00253   defServices.push_back("RootHistSvc");
00254   m_svcNames.set(defServices);
00255   declareProperty ("HistogramPersistency", m_histPersName = "");
00256   declareProperty ("OutputFile", m_outputFile = "");
00257   //
00258   declareProperty 
00259     ("ConvertHistos" , m_convert , 
00260      "The list of patterns to be accepted for conversion" ) ;
00261   //
00262   declareProperty 
00263     ("ExcludeHistos" , m_exclude , 
00264      "The list of patterns to be excluded for conversion" ) ;
00265 }
00266 // ============================================================================
00267 // Standard Destructor
00268 // ============================================================================
00269 HistogramPersistencySvc::~HistogramPersistencySvc()   {}
00270 // ============================================================================
00271 
00272 
00273 // ============================================================================
00274 // The END
00275 // ============================================================================

Generated at Fri Jul 18 11:59:25 2008 for Gaudi Framework, version v20r2 by Doxygen version 1.5.1 written by Dimitri van Heesch, © 1997-2004