| The Gaudi Framework v32r1 (f65d50dc)

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/DataObject.h"
8 #include "GaudiKernel/IAlgContextSvc.h"
9 #include "GaudiKernel/ThreadLocalContext.h"
10 // ============================================================================
11 // GaudiAlg
12 // ============================================================================
13 #include "GaudiAlg/GaudiAlgorithm.h"
14 // ============================================================================
26 // ============================================================================
27 // templated methods
28 // ============================================================================
29 #include "GaudiCommon.icpp"
30 // ============================================================================
31 template class GaudiCommon<Algorithm>;
32 // ============================================================================
33 // Standard algorithm like constructor
34 // ============================================================================
35 GaudiAlgorithm::GaudiAlgorithm( const std::string& name, ISvcLocator* pSvcLocator )
36 : GaudiCommon<Algorithm>( name, pSvcLocator ) {
37 setProperty( "RegisterForContextService", true ).ignore();
38 }
39 // ============================================================================
40 // standard initialization method
41 // ============================================================================
42 StatusCode GaudiAlgorithm::initialize() {
43 // initialize the base class
44 const StatusCode sc = GaudiCommon<Algorithm>::initialize();
45 if ( sc.isFailure() ) { return sc; }
46
47 // Add any customisations here, that cannot go in GaudiCommon
48
49 // return
50 return sc;
51 }
52 // ============================================================================
53 // standard finalization method
54 // ============================================================================
55 StatusCode GaudiAlgorithm::finalize() {
56 if ( msgLevel( MSG::DEBUG ) ) debug() << "Finalize base class GaudiAlgorithm" << endmsg;
57
58 // reset pointers
59 m_evtColSvc.reset();
60
61 // finalize the base class and return
62 return GaudiCommon<Algorithm>::finalize();
63 }
64 // ============================================================================
65 // standard execution method
66 // ============================================================================
67 StatusCode GaudiAlgorithm::execute() { return Error( "Default GaudiAlgorithm execute method called !!" ); }
68 // ============================================================================
69 // The standard event collection service
70 // ============================================================================
71 SmartIF<INTupleSvc>& GaudiAlgorithm::evtColSvc() const {
72 if ( !m_evtColSvc ) { m_evtColSvc = svc<INTupleSvc>( "EvtTupleSvc", true ); }
73 //
74 return m_evtColSvc;
75 }
76 // ============================================================================
77 /* The generic actions for the execution.
78 * @see Algorithm
79 * @see IAlgorithm
80 * @see Algorithm::sysExecute
81 * @return status code
82 */
83 // ============================================================================
84 StatusCode GaudiAlgorithm::sysExecute( const EventContext& ctx ) {
85 StatusCode sc{StatusCode::SUCCESS};
86
87 IAlgContextSvc* algCtx = nullptr;
88 if ( registerContext() ) { algCtx = contextSvc(); }
89 // Lock the context
90 Gaudi::Utils::AlgContext cnt( this, algCtx, ctx );
91
92 // Do not execute if one or more of the m_vetoObjs exist in TES
93 const auto it = find_if( begin( m_vetoObjs ), end( m_vetoObjs ),
94 [&]( const std::string& loc ) { return this->exist<DataObject>( loc ); } );
95 if ( it != end( m_vetoObjs ) ) {
96 if ( msgLevel( MSG::DEBUG ) ) debug() << *it << " found, skipping event " << endmsg;
97 return sc;
98 }
99
100 // Execute if m_requireObjs is empty
101 // or if one or more of the m_requireObjs exist in TES
102 bool doIt =
103 m_requireObjs.empty() || any_of( begin( m_requireObjs ), end( m_requireObjs ),
104 [&]( const std::string& loc ) { return this->exist<DataObject>( loc ); } );
105
106 // execute the generic method:
107 if ( doIt ) sc = Algorithm::sysExecute( ctx );
108 return sc;
109 }
110 // ============================================================================
111
112 // ============================================================================
113 // The END
114 // ============================================================================
GaudiAlgorithm::evtColSvc
SmartIF< INTupleSvc > & evtColSvc() const
Access the standard event collection service.
Definition: GaudiAlgorithm.cpp:71
SmartIF< INTupleSvc >
GaudiAlgorithm::m_evtColSvc
SmartIF< INTupleSvc > m_evtColSvc
Event Tag Collection Service.
Definition: GaudiAlgorithm.h:652
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
Gaudi::Utils::AlgContext
Helper "sentry" class to automatize the safe register/unregister the algorithm's context.
Definition: IAlgContextSvc.h:74
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:41
GaudiAlgorithm::initialize
StatusCode initialize() override
standard initialization method
Definition: GaudiAlgorithm.cpp:42
ThreadLocalContext.h
GaudiAlgorithm.h
Header file for class GaudiAlgorithm.
MSG::DEBUG
Definition: IMessageSvc.h:15
GaudiCommon< Algorithm >::Error
WARN_UNUSED 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.
Definition: GaudiCommon.icpp:286
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
GaudiCommon::finalize
StatusCode finalize() override
standard finalization method
Definition: GaudiCommon.icpp:131
GaudiAlgorithm::execute
StatusCode execute() override
standard execution method
Definition: GaudiAlgorithm.cpp:67
EventContext
This class represents an entry point to all the event specific data.
Definition: EventContext.h:24
std::string
STL class.
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
GaudiAlgorithm::sysExecute
StatusCode sysExecute(const EventContext &ctx) override
the generic actions for the execution.
Definition: GaudiAlgorithm.cpp:84
GaudiAlgorithm::finalize
StatusCode finalize() override
standard finalization method
Definition: GaudiAlgorithm.cpp:55
setProperty
bool PyHelper() setProperty(IInterface *p, char *name, char *value)
Definition: Bootstrap.cpp:233
IOTest.end
def end
Definition: IOTest.py:112
GaudiCommon.icpp
GaudiCommon::initialize
StatusCode initialize() override
standard initialization method
Definition: GaudiCommon.icpp:95
IAlgContextSvc.h
Algorithm
Alias for backward compatibility.
Definition: Algorithm.h:56
GaudiAlgorithm::m_requireObjs
Gaudi::Property< std::vector< std::string > > m_requireObjs
Definition: GaudiAlgorithm.h:656
GaudiAlgorithm::m_vetoObjs
Gaudi::Property< std::vector< std::string > > m_vetoObjs
Definition: GaudiAlgorithm.h:654
GaudiCommon< Algorithm >
IAlgContextSvc
An abstract interface for Algorithm Context Service.
Definition: IAlgContextSvc.h:23
SmartIF::reset
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:86
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:130
Gaudi::Utils::begin
AttribStringParser::Iterator begin(const AttribStringParser &parser)
Definition: AttribStringParser.h:120
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192
DataObject.h
Gaudi::Algorithm::sysExecute
StatusCode sysExecute(const EventContext &ctx) override
The actions to be performed by the algorithm on an event.
Definition: Algorithm.cpp:438
GaudiAlgorithm::GaudiAlgorithm
GaudiAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Standard constructor.
Definition: GaudiAlgorithm.cpp:35