GaudiAlgorithm.cpp
Go to the documentation of this file.
1 // $Id: GaudiAlgorithm.cpp,v 1.12 2008/11/04 22:49:25 marcocle Exp $
2 // ============================================================================
3 #define GAUDIALG_GAUDIALGORITHM_CPP 1
4 // ============================================================================
5 // include files
6 // ============================================================================
7 // GaudiKernel
8 // ============================================================================
9 #include "GaudiKernel/IAlgContextSvc.h"
10 #include "GaudiKernel/DataObject.h"
11 // ============================================================================
12 // GaudiAlg
13 // ============================================================================
14 #include "GaudiAlg/GaudiAlgorithm.h"
15 // ============================================================================
27 // ============================================================================
28 // templated methods
29 // ============================================================================
30 #include "GaudiCommon.icpp"
31 // ============================================================================
32 template class GaudiCommon<Algorithm>;
33 // ============================================================================
34 // Standard algorithm like constructor
35 // ============================================================================
36 GaudiAlgorithm::GaudiAlgorithm ( const std::string& name ,
37  ISvcLocator* pSvcLocator )
38  : GaudiCommon<Algorithm> ( name , pSvcLocator )
39  //
40  , m_evtColSvc () // pointer to Event Tag Collection Service
41 {
42  m_vetoObjs.clear();
43  m_requireObjs.clear();
44 
45  setProperty ( "RegisterForContextService" , true ).ignore() ;
46 
47  declareProperty( "VetoObjects", m_vetoObjs,
48  "Skip execute if one or more of these TES objects exists" );
49  declareProperty( "RequireObjects", m_requireObjs,
50  "Execute only if one or more of these TES objects exists" );
51 }
52 // ============================================================================
53 // Destructor
54 // ============================================================================
56 // ============================================================================
57 // standard initialization method
58 // ============================================================================
60 {
61  // initialize the base class
63  if ( sc.isFailure() ) { return sc; }
64 
65  // Add any customisations here, that cannot go in GaudiCommon
66 
67  // return
68  return sc;
69 }
70 // ============================================================================
71 // standard finalization method
72 // ============================================================================
74 {
75  if ( msgLevel(MSG::DEBUG) )
76  debug() << "Finalize base class GaudiAlgorithm" << endmsg;
77 
78  // reset pointers
79  m_evtColSvc.reset() ;
80 
81  // finalize the base class and return
83 }
84 // ============================================================================
85 // standard execution method
86 // ============================================================================
88 {
89  return Error ( "Default GaudiAlgorithm execute method called !!" ) ;
90 }
91 // ============================================================================
92 // The standard event collection service
93 // ============================================================================
95 {
96  if ( !m_evtColSvc.isValid() )
97  { m_evtColSvc = svc< INTupleSvc > ( "EvtTupleSvc" , true ) ; }
98  //
99  return m_evtColSvc ;
100 }
101 // ============================================================================
102 /* The generic actions for the execution.
103  * @see Algorithm
104  * @see IAlgorithm
105  * @see Algorithm::sysExecute
106  * @return status code
107  */
108 // ============================================================================
110 {
111  IAlgContextSvc* ctx = 0 ;
112  if ( registerContext() ) { ctx = contextSvc() ; }
113  // Lock the context
114  Gaudi::Utils::AlgContext cnt ( ctx , this ) ;
115 
116  // Do not execute if one or more of the m_vetoObjs exist in TES
117  for( std::vector<std::string>::iterator it = m_vetoObjs.begin();
118  it != m_vetoObjs.end(); it++ ) {
119  if( exist<DataObject>(*it) ) {
120  debug() << *it << " found, skipping event " << endmsg;
121  return StatusCode::SUCCESS;
122  }
123  }
124 
125  // Execute if m_requireObjs is empty
126  bool doIt = m_requireObjs.empty() ? true : false;
127 
128  // Execute also if one or more of the m_requireObjs exist in TES
129  for( std::vector<std::string>::iterator it = m_requireObjs.begin();
130  it != m_requireObjs.end(); it++ ) {
131  if( exist<DataObject>(*it) ) {
132  doIt = true;
133  break;
134  }
135  }
136 
137  if( doIt )
138  // execute the generic method:
139  return Algorithm::sysExecute() ;
140  else
141  return StatusCode::SUCCESS;
142 }
143 // ============================================================================
144 
145 
146 
147 
148 // ============================================================================
149 // The END
150 // ============================================================================
151 
virtual StatusCode setProperty(const Property &p)
Implementation of IProperty::setProperty.
Definition: Algorithm.cpp:1141
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:26
SmartIF< IAlgContextSvc > & contextSvc() const
get Algorithm Context Service
Helper "sentry" class to automatize the safe register/unregister the algorithm's context.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
virtual StatusCode sysExecute()
The actions to be performed by the algorithm on an event.
Definition: Algorithm.cpp:578
StatusCode Error(const std::string &msg, const StatusCode st=StatusCode::FAILURE, const size_t mx=10) const
Print the error message and return with the given StatusCode.
virtual StatusCode finalize()
standard finalization method
virtual StatusCode initialize()
standard initialization method
Property * declareProperty(const std::string &name, T &property, const std::string &doc="none") const
Declare the named property.
Definition: Algorithm.h:402
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:85
SmartIF< INTupleSvc > & evtColSvc() const
Access the standard event collection service.
MSG::Level msgLevel() const
The current message service output level.
Definition: GaudiCommon.h:532
virtual StatusCode finalize()
standard finalization method
std::vector< std::string > m_requireObjs
process the event only if one or more of these objects are present in TES
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
SmartIF< INTupleSvc > m_evtColSvc
Event Tag Collection Service.
MsgStream & debug() const
shortcut for the method msgStream ( MSG::DEBUG )
Definition: GaudiCommon.h:499
virtual StatusCode execute()
standard execution method
void reset(TYPE *ptr=0)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:74
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:61
bool isValid() const
Allow for check if smart pointer is valid.
Definition: SmartIF.h:51
bool registerContext() const
register for Algorithm Context Service?
Definition: Algorithm.h:325
std::vector< std::string > m_vetoObjs
skip the event if any of these objects are present in TES
An abstract interface for Algorithm Context Service.
virtual StatusCode initialize()
standard initialization method
void ignore() const
Definition: StatusCode.h:107
GaudiAlgorithm()
no public default constructor
virtual StatusCode sysExecute()
the generic actions for the execution.
virtual ~GaudiAlgorithm()
destructor, virtual and protected