| The Gaudi Framework v27r1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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 // ============================================================================
48 StatusCode GaudiAlgorithm::initialize()
49 {
50 // initialize the base class
51 const StatusCode sc = GaudiCommon<Algorithm>::initialize() ;
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 // ============================================================================
62 StatusCode GaudiAlgorithm::finalize()
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
71 return GaudiCommon<Algorithm>::finalize() ;
72 }
73 // ============================================================================
74 // standard execution method
75 // ============================================================================
76 StatusCode GaudiAlgorithm::execute()
77 {
78 return Error ( "Default GaudiAlgorithm execute method called !!" ) ;
79 }
80 // ============================================================================
81 // The standard event collection service
82 // ============================================================================
83 SmartIF<INTupleSvc>& GaudiAlgorithm::evtColSvc() const
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 // ============================================================================
98 StatusCode GaudiAlgorithm::sysExecute ()
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 if ( msgLevel(MSG::DEBUG) )
110 debug() << *it << " found, skipping event " << endmsg;
111 return StatusCode::SUCCESS;
112 }
113
114 // Execute if m_requireObjs is empty
115 // or if one or more of the m_requireObjs exist in TES
116 bool doIt = m_requireObjs.empty() ||
117 std::any_of( std::begin(m_requireObjs), std::end(m_requireObjs),
118 [&](const std::string& loc) { return this->exist<DataObject>(loc); } );
119
120 // execute the generic method:
121 if( doIt ) return Algorithm::sysExecute() ;
122 return StatusCode::SUCCESS;
123 }
124 // ============================================================================
125
126 // ============================================================================
127 // The END
128 // ============================================================================
SmartIF< INTupleSvc >
std::vector::empty
T empty(T...args)
GaudiAlgorithm::m_evtColSvc
SmartIF< INTupleSvc > m_evtColSvc
Event Tag Collection Service.
Definition: GaudiAlgorithm.h:684
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
Algorithm::contextSvc
SmartIF< IAlgContextSvc > & contextSvc() const
get Algorithm Context Service
Gaudi::Utils::AlgContext
Helper "sentry" class to automatize the safe register/unregister the algorithm's context.
Definition: IAlgContextSvc.h:79
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:28
GaudiAlgorithm::initialize
StatusCode initialize() override
standard initialization method
Definition: GaudiAlgorithm.cpp:48
GaudiCommon< Algorithm >::Error
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.
Algorithm::setProperty
StatusCode setProperty(const Property &p) override
Implementation of IProperty::setProperty.
Definition: Algorithm.cpp:980
GaudiAlgorithm.h
MSG::DEBUG
Definition: IMessageSvc.h:18
GaudiAlgorithm::declareProperty
Property * declareProperty(const std::string &name, DataObjectHandle< T > &hndl, const std::string &doc="none") const
Definition: GaudiAlgorithm.h:695
std::end
T end(T...args)
GaudiCommon::finalize
StatusCode finalize() override
standard finalization method
Definition: GaudiCommon.icpp:280
GaudiAlgorithm::execute
StatusCode execute() override
standard execution method
Definition: GaudiAlgorithm.cpp:76
merge_files.sc
int sc
Definition: merge_files.py:167
StatusCode::isFailure
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
GaudiAlgorithm::evtColSvc
SmartIF< INTupleSvc > & evtColSvc() const
Access the standard event collection service.
Definition: GaudiAlgorithm.cpp:83
std::string
STL class.
GaudiAlgorithm::sysExecute
StatusCode sysExecute() override
the generic actions for the execution.
Definition: GaudiAlgorithm.cpp:98
StatusCode::SUCCESS
Definition: StatusCode.h:30
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
Algorithm::sysExecute
StatusCode sysExecute() override
The actions to be performed by the algorithm on an event.
Definition: Algorithm.cpp:567
GaudiAlgorithm::finalize
StatusCode finalize() override
standard finalization method
Definition: GaudiAlgorithm.cpp:62
GaudiCommon.icpp
GaudiCommon::initialize
StatusCode initialize() override
standard initialization method
Definition: GaudiCommon.icpp:186
IAlgContextSvc.h
Algorithm
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:74
std::find_if
T find_if(T...args)
CommonMessagingBase::debug
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
Definition: CommonMessaging.h:127
std::begin
T begin(T...args)
Algorithm::registerContext
bool registerContext() const
register for Algorithm Context Service?
Definition: Algorithm.h:344
std::any_of
T any_of(T...args)
GaudiAlgorithm::m_vetoObjs
std::vector< std::string > m_vetoObjs
skip the event if any of these objects are present in TES
Definition: GaudiAlgorithm.h:686
GaudiCommon< Algorithm >
GaudiAlgorithm::m_requireObjs
std::vector< std::string > m_requireObjs
process the event only if one or more of these objects are present in TES
Definition: GaudiAlgorithm.h:688
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:88
StatusCode::ignore
void ignore() const
Definition: StatusCode.h:108
CommonMessagingBase::msgLevel
MSG::Level msgLevel() const
get the output level from the embedded MsgStream
Definition: CommonMessaging.h:136
GaudiAlgorithm::GaudiAlgorithm
GaudiAlgorithm()
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
DataObject.h