| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

GaudiAlgorithm.cpp

Go to the documentation of this file.
00001 // $Id: GaudiAlgorithm.cpp,v 1.12 2008/11/04 22:49:25 marcocle Exp $ 
00002 // ============================================================================
00003 #define  GAUDIALG_GAUDIALGORITHM_CPP 1
00004 // ============================================================================
00005 // include files
00006 // ============================================================================
00007 // GaudiKernel
00008 // ============================================================================
00009 #include "GaudiKernel/IAlgContextSvc.h"
00010 #include "GaudiKernel/DataObject.h"
00011 // ============================================================================
00012 // GaudiAlg
00013 // ============================================================================
00014 #include "GaudiAlg/GaudiAlgorithm.h"
00015 // ============================================================================
00027 // ============================================================================
00028 // templated methods
00029 // ============================================================================
00030 #include "GaudiCommon.icpp"
00031 // ============================================================================
00032 template class GaudiCommon<Algorithm>;
00033 // ============================================================================
00034 // Standard algorithm like constructor
00035 // ============================================================================
00036 GaudiAlgorithm::GaudiAlgorithm ( const std::string&  name        ,
00037                                  ISvcLocator*        pSvcLocator )
00038   : GaudiCommon<Algorithm> ( name , pSvcLocator )
00039   //
00040   , m_evtColSvc  ( 0        ) // pointer to Event Tag Collection Service
00041   , m_contextSvc ( 0        ) // pointer to Algorithm Context Service
00042   , m_contextSvcName ( "AlgContextSvc" ) // Algorithm Context Service name 
00043   // enforce the algorithm registration for Algorithm Context Service
00044   , m_registerContext ( true )
00045 {
00046   m_vetoObjs.clear();
00047   m_requireObjs.clear();
00048   
00049   declareProperty 
00050     ( "ContextService" , 
00051       m_contextSvcName , 
00052       "The name of Algorithm Context Service" ) ;
00053   declareProperty 
00054     ( "RegisterForContextService" , 
00055       m_registerContext  , 
00056       "The flag to enforce the registration for Algorithm Context Service") ;
00057   declareProperty( "VetoObjects", m_vetoObjs,
00058                    "Skip execute if one or more of these TES objects exists" );
00059   declareProperty( "RequireObjects", m_requireObjs,
00060                    "Execute only if one or more of these TES objects exists" );
00061 }
00062 // ============================================================================
00063 // Destructor
00064 // ============================================================================
00065 GaudiAlgorithm::~GaudiAlgorithm() { }
00066 // ============================================================================
00067 // standard initialization method
00068 // ============================================================================
00069 StatusCode GaudiAlgorithm::initialize()
00070 {
00071   // initialize the base class
00072   const StatusCode sc = GaudiCommon<Algorithm>::initialize() ;
00073   if ( sc.isFailure() ) { return sc; }
00074 
00075   // Add any customisations here, that cannot go in GaudiCommon
00076 
00077   // return
00078   return sc;
00079 }
00080 // ============================================================================
00081 // standard finalization method
00082 // ============================================================================
00083 StatusCode GaudiAlgorithm::finalize()
00084 {
00085   if ( msgLevel(MSG::DEBUG) )
00086     debug() << "Finalize base class GaudiAlgorithm" << endreq;
00087 
00088   // reset pointers
00089   m_evtColSvc = 0 ;
00090 
00091   // finalize the base class and return
00092   return GaudiCommon<Algorithm>::finalize() ;
00093 }
00094 // ============================================================================
00095 // standard execution method
00096 // ============================================================================
00097 StatusCode GaudiAlgorithm::execute()
00098 {
00099   return Error ( "Default GaudiAlgorithm execute method called !!" ) ;
00100 }
00101 // ============================================================================
00102 // The standard event collection service
00103 // ============================================================================
00104 INTupleSvc* GaudiAlgorithm::evtColSvc() const
00105 {
00106   if ( 0 == m_evtColSvc )
00107   {
00108     m_evtColSvc = svc< INTupleSvc > ( "EvtTupleSvc" , true ) ;
00109   }
00110   return m_evtColSvc ;
00111 }
00112 // ============================================================================
00113 // The standard Algorithm Context Service 
00114 // ============================================================================
00115 IAlgContextSvc* GaudiAlgorithm::contextSvc() const
00116 {
00117   if ( 0 == m_contextSvc )
00118   {
00119     m_contextSvc = svc< IAlgContextSvc > ( m_contextSvcName , true ) ;
00120   }
00121   return m_contextSvc ;
00122 }
00123 // ============================================================================
00124 /*  The generic actions for the execution.
00125  *  @see  Algorithm
00126  *  @see IAlgorithm
00127  *  @see Algorithm::sysExecute
00128  *  @return status code 
00129  */
00130 // ============================================================================
00131 StatusCode GaudiAlgorithm::sysExecute () 
00132 {
00133   IAlgContextSvc* ctx = 0 ;
00134   if ( registerContext() ) { ctx = contextSvc() ; }
00135   // Lock the context 
00136   Gaudi::Utils::AlgContext cnt ( ctx , this ) ;  
00137 
00138   // Do not execute if one or more of the m_vetoObjs exist in TES
00139   for( std::vector<std::string>::iterator it  = m_vetoObjs.begin();
00140                                           it != m_vetoObjs.end(); it++ ) {
00141     if( exist<DataObject>(*it) ) {
00142       debug() << *it << " found, skipping event " << endmsg;
00143       return StatusCode::SUCCESS;
00144     }
00145   }
00146 
00147   // Execute if m_requireObjs is empty
00148   bool doIt = m_requireObjs.empty() ? true : false;
00149 
00150   // Execute also if one or more of the m_requireObjs exist in TES
00151   for( std::vector<std::string>::iterator it  = m_requireObjs.begin();
00152                                           it != m_requireObjs.end(); it++ ) {
00153     if( exist<DataObject>(*it) ) {
00154       doIt = true;
00155       break;
00156     }
00157   }
00158 
00159   if( doIt )
00160     // execute the generic method:
00161     return Algorithm::sysExecute() ;
00162   else
00163     return StatusCode::SUCCESS;
00164 }
00165 // ============================================================================
00166 
00167 
00168 
00169 
00170 // ============================================================================
00171 // The END 
00172 // ============================================================================
00173 
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 19:58:14 2011 for GaudiAlg by doxygen 1.4.7