The Gaudi Framework  v33r1 (b1225454)
GaudiAlgorithm.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 #define GAUDIALG_GAUDIALGORITHM_CPP 1
12 // ============================================================================
13 // include files
14 // ============================================================================
15 // GaudiKernel
16 // ============================================================================
17 #include "GaudiKernel/DataObject.h"
20 // ============================================================================
21 // GaudiAlg
22 // ============================================================================
24 // ============================================================================
36 // ============================================================================
37 // templated methods
38 // ============================================================================
39 #include "GaudiCommon.icpp"
40 // ============================================================================
41 template class GaudiCommon<Algorithm>;
42 // ============================================================================
43 // Standard algorithm like constructor
44 // ============================================================================
46  : GaudiCommon<Algorithm>( std::move( name ), pSvcLocator ) {
47  setProperty( "RegisterForContextService", true ).ignore();
48 }
49 // ============================================================================
50 // standard initialization method
51 // ============================================================================
53  // initialize the base class
55  if ( sc.isFailure() ) { return sc; }
56 
57  // Add any customisations here, that cannot go in GaudiCommon
58 
59  // return
60  return sc;
61 }
62 // ============================================================================
63 // standard finalization method
64 // ============================================================================
66  if ( msgLevel( MSG::DEBUG ) ) debug() << "Finalize base class GaudiAlgorithm" << endmsg;
67 
68  // reset pointers
70 
71  // finalize the base class and return
73 }
74 // ============================================================================
75 // standard execution method
76 // ============================================================================
77 StatusCode GaudiAlgorithm::execute() { return Error( "Default GaudiAlgorithm execute method called !!" ); }
78 // ============================================================================
79 // The standard event collection service
80 // ============================================================================
82  if ( !m_evtColSvc ) { m_evtColSvc = svc<INTupleSvc>( "EvtTupleSvc", true ); }
83  //
84  return m_evtColSvc;
85 }
86 // ============================================================================
87 /* The generic actions for the execution.
88  * @see Algorithm
89  * @see IAlgorithm
90  * @see Algorithm::sysExecute
91  * @return status code
92  */
93 // ============================================================================
96 
97  IAlgContextSvc* algCtx = nullptr;
98  if ( registerContext() ) { algCtx = contextSvc(); }
99  // Lock the context
100  Gaudi::Utils::AlgContext cnt( this, algCtx, ctx );
101 
102  // Do not execute if one or more of the m_vetoObjs exist in TES
103  const auto it = find_if( begin( m_vetoObjs ), end( m_vetoObjs ),
104  [&]( const std::string& loc ) { return this->exist<DataObject>( loc ); } );
105  if ( it != end( m_vetoObjs ) ) {
106  if ( msgLevel( MSG::DEBUG ) ) debug() << *it << " found, skipping event " << endmsg;
107  return sc;
108  }
109 
110  // Execute if m_requireObjs is empty
111  // or if one or more of the m_requireObjs exist in TES
112  bool doIt =
113  m_requireObjs.empty() || any_of( begin( m_requireObjs ), end( m_requireObjs ),
114  [&]( const std::string& loc ) { return this->exist<DataObject>( loc ); } );
115 
116  // execute the generic method:
117  if ( doIt ) sc = Algorithm::sysExecute( ctx );
118  return sc;
119 }
120 // ============================================================================
121 
122 // ============================================================================
123 // The END
124 // ============================================================================
SmartIF< INTupleSvc > & evtColSvc() const
Access the standard event collection service.
SmartIF< INTupleSvc > m_evtColSvc
Event Tag Collection Service.
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:35
Helper "sentry" class to automatize the safe register/unregister the algorithm's context.
StatusCode initialize() override
standard initialization method
StatusCode Error(std::string_view msg, const StatusCode st=StatusCode::FAILURE, const size_t mx=10) const
Print the error message and return with the given StatusCode.
Header file for class GaudiAlgorithm.
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
STL namespace.
StatusCode finalize() override
standard finalization method
StatusCode execute() override
standard execution method
This class represents an entry point to all the event specific data.
Definition: EventContext.h:34
STL class.
GaudiAlgorithm(std::string name, ISvcLocator *pSvcLocator)
Standard constructor.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
StatusCode sysExecute(const EventContext &ctx) override
the generic actions for the execution.
StatusCode finalize() override
standard finalization method
bool PyHelper() setProperty(IInterface *p, char *name, char *value)
Definition: Bootstrap.cpp:243
def end
Definition: IOTest.py:123
StatusCode initialize() override
standard initialization method
Alias for backward compatibility.
Definition: Algorithm.h:58
Gaudi::Property< std::vector< std::string > > m_requireObjs
Gaudi::Property< std::vector< std::string > > m_vetoObjs
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:96
bool isFailure() const
Definition: StatusCode.h:145
AttribStringParser::Iterator begin(const AttribStringParser &parser)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
StatusCode sysExecute(const EventContext &ctx) override
The actions to be performed by the algorithm on an event.
Definition: Algorithm.cpp:338