The Gaudi Framework  v38r1p1 (ae26267b)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 // ============================================================================
MSG::DEBUG
@ DEBUG
Definition: IMessageSvc.h:25
Gaudi::Algorithm::sysExecute
StatusCode sysExecute(const EventContext &ctx) override
The actions to be performed by the algorithm on an event.
Definition: Algorithm.cpp:327
GaudiAlgorithm::sysExecute
StatusCode sysExecute(const EventContext &ctx) override
the generic actions for the execution.
Definition: GaudiAlgorithm.cpp:94
GaudiCommon.icpp
GaudiAlgorithm::m_vetoObjs
Gaudi::Property< std::vector< std::string > > m_vetoObjs
Definition: GaudiAlgorithm.h:664
std::string
STL class.
Gaudi::Algorithm::contextSvc
SmartIF< IAlgContextSvc > & contextSvc() const
get Algorithm Context Service
Definition: Algorithm.cpp:568
GaudiAlgorithm::GaudiAlgorithm
GaudiAlgorithm(std::string name, ISvcLocator *pSvcLocator)
Standard constructor.
Definition: GaudiAlgorithm.cpp:45
GaudiAlgorithm::finalize
StatusCode finalize() override
standard finalization method
Definition: GaudiAlgorithm.cpp:65
SmartIF::reset
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:96
PropertyHolder< CommonMessaging< implements< IAlgorithm, IDataHandleHolder, IProperty, IStateful > > >::setProperty
StatusCode setProperty(const Gaudi::Details::PropertyBase &p)
Set the property from a property.
Definition: IProperty.h:39
ISvcLocator
Definition: ISvcLocator.h:46
Algorithm
Alias for backward compatibility.
Definition: Algorithm.h:58
GaudiAlgorithm::m_requireObjs
Gaudi::Property< std::vector< std::string > > m_requireObjs
Definition: GaudiAlgorithm.h:666
CommonMessaging< implements< IAlgorithm, IDataHandleHolder, IProperty, IStateful > >::msgLevel
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
Definition: CommonMessaging.h:148
GaudiPython.Pythonizations.ctx
ctx
Definition: Pythonizations.py:578
StatusCode
Definition: StatusCode.h:65
GaudiAlgorithm::evtColSvc
SmartIF< INTupleSvc > & evtColSvc() const
Access the standard event collection service.
Definition: GaudiAlgorithm.cpp:81
CLHEP::begin
double * begin(CLHEP::HepVector &v)
Definition: TupleAlg.cpp:45
GaudiAlgorithm::initialize
StatusCode initialize() override
standard initialization method
Definition: GaudiAlgorithm.cpp:52
GaudiAlgorithm::m_evtColSvc
SmartIF< INTupleSvc > m_evtColSvc
Event Tag Collection Service.
Definition: GaudiAlgorithm.h:662
Gaudi::Utils::AlgContext
Definition: IAlgContextSvc.h:84
SmartIF< INTupleSvc >
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:203
StatusCode::ignore
const StatusCode & ignore() const
Allow discarding a StatusCode without warning.
Definition: StatusCode.h:139
GaudiCommon::initialize
StatusCode initialize() override
standard initialization method
Definition: GaudiCommon.icpp:76
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:129
ThreadLocalContext.h
GaudiCommon::finalize
StatusCode finalize() override
standard finalization method
Definition: GaudiCommon.icpp:112
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
ConditionsStallTest.name
name
Definition: ConditionsStallTest.py:76
DataObject.h
IAlgContextSvc.h
GaudiAlgorithm.h
std
STL namespace.
EventContext
Definition: EventContext.h:34
IAlgContextSvc
Definition: IAlgContextSvc.h:33
IOTest.end
end
Definition: IOTest.py:123
Gaudi::Algorithm::registerContext
bool registerContext() const
register for Algorithm Context Service?
Definition: Algorithm.h:295
GaudiAlgorithm::execute
StatusCode execute() override
standard execution method
Definition: GaudiAlgorithm.cpp:77
GaudiCommon< Algorithm >::Error
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.
Definition: GaudiCommon.icpp:256
GaudiCommon< Algorithm >