All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
GaudiAlgorithm.cpp
Go to the documentation of this file.
1 #define GAUDIALG_GAUDIALGORITHM_CPP 1
2 // ============================================================================
3 // include files
4 // ============================================================================
5 // GaudiKernel
6 // ============================================================================
7 #include "GaudiKernel/IAlgContextSvc.h"
8 #include "GaudiKernel/DataObject.h"
9 // ============================================================================
10 // GaudiAlg
11 // ============================================================================
12 #include "GaudiAlg/GaudiAlgorithm.h"
13 // ============================================================================
25 // ============================================================================
26 // templated methods
27 // ============================================================================
28 #include "GaudiCommon.icpp"
29 // ============================================================================
30 template class GaudiCommon<Algorithm>;
31 // ============================================================================
32 // Standard algorithm like constructor
33 // ============================================================================
34 GaudiAlgorithm::GaudiAlgorithm ( const std::string& name ,
35  ISvcLocator* pSvcLocator )
36  : GaudiCommon<Algorithm> ( name , pSvcLocator )
37 {
38  setProperty ( "RegisterForContextService" , true ).ignore() ;
39 
40  declareProperty( "VetoObjects", m_vetoObjs,
41  "Skip execute if one or more of these TES objects exists" );
42  declareProperty( "RequireObjects", m_requireObjs,
43  "Execute only if one or more of these TES objects exists" );
44 }
45 // ============================================================================
46 // standard initialization method
47 // ============================================================================
49 {
50  // initialize the base class
52  if ( sc.isFailure() ) { return sc; }
53 
54  // Add any customisations here, that cannot go in GaudiCommon
55 
56  // return
57  return sc;
58 }
59 // ============================================================================
60 // standard finalization method
61 // ============================================================================
63 {
64  if ( msgLevel(MSG::DEBUG) )
65  debug() << "Finalize base class GaudiAlgorithm" << endmsg;
66 
67  // reset pointers
68  m_evtColSvc.reset() ;
69 
70  // finalize the base class and return
72 }
73 // ============================================================================
74 // standard execution method
75 // ============================================================================
77 {
78  return Error ( "Default GaudiAlgorithm execute method called !!" ) ;
79 }
80 // ============================================================================
81 // The standard event collection service
82 // ============================================================================
84 {
85  if ( !m_evtColSvc )
86  { m_evtColSvc = svc< INTupleSvc > ( "EvtTupleSvc" , true ) ; }
87  //
88  return m_evtColSvc ;
89 }
90 // ============================================================================
91 /* The generic actions for the execution.
92  * @see Algorithm
93  * @see IAlgorithm
94  * @see Algorithm::sysExecute
95  * @return status code
96  */
97 // ============================================================================
99 {
100  IAlgContextSvc* ctx = nullptr ;
101  if ( registerContext() ) { ctx = contextSvc() ; }
102  // Lock the context
103  Gaudi::Utils::AlgContext cnt ( ctx , this ) ;
104 
105  // Do not execute if one or more of the m_vetoObjs exist in TES
106  auto it = std::find_if( std::begin(m_vetoObjs), std::end(m_vetoObjs),
107  [&](const std::string& loc) { return this->exist<DataObject>(loc); } );
108  if ( it != std::end(m_vetoObjs) ) {
109  debug() << *it << " found, skipping event " << endmsg;
110  return StatusCode::SUCCESS;
111  }
112 
113  // Execute if m_requireObjs is empty
114  // or if one or more of the m_requireObjs exist in TES
115  bool doIt = m_requireObjs.empty() ||
117  [&](const std::string& loc) { return this->exist<DataObject>(loc); } );
118 
119  // execute the generic method:
120  if( doIt ) return Algorithm::sysExecute() ;
121  return StatusCode::SUCCESS;
122 }
123 // ============================================================================
124 
125 // ============================================================================
126 // The END
127 // ============================================================================
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
Helper "sentry" class to automatize the safe register/unregister the algorithm's context.
StatusCode initialize() override
standard initialization method
auto begin(reverse_wrapper< T > &w)
Definition: reverse.h:45
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.
StatusCode finalize() override
standard finalization method
StatusCode execute() override
standard execution method
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
SmartIF< INTupleSvc > & evtColSvc() const
Access the standard event collection service.
std::vector< std::string > m_requireObjs
process the event only if one or more of these objects are present in TES
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
StatusCode sysExecute() override
the generic actions for the execution.
auto end(reverse_wrapper< T > &w)
Definition: reverse.h:47
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
StatusCode sysExecute() override
The actions to be performed by the algorithm on an event.
Definition: Algorithm.cpp:652
StatusCode finalize() override
standard finalization method
SmartIF< INTupleSvc > m_evtColSvc
Event Tag Collection Service.
bool PyHelper() setProperty(IInterface *p, char *name, char *value)
Definition: Bootstrap.cpp:254
StatusCode initialize() override
standard initialization method
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:77
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.
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:88
MSG::Level msgLevel() const
get the output level from the embedded MsgStream