The Gaudi Framework  master (37c0b60a)
User.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 #include <Gaudi/Algorithm.h>
13 
17  class UserAlg : public ConditionAccessorHolder<Algorithm> {
20 
22  ConditionAccessor<int> m_cond{ this, "MyCondition", "condition/key" };
23 
24  StatusCode initialize() override {
25  auto status = base_class::initialize();
26  if ( !status ) return status;
27 
28  info() << "initialize" << endmsg;
29 
30  return status;
31  }
32 
33  StatusCode execute( const EventContext& ctx ) const override {
34  // get the condition slot for the current event
35  const auto& condCtx = getConditionContext( ctx );
36  // get the condition value from the current condition slot.
37  const auto& cond = m_cond.get( condCtx );
38 
39  info() << "got condition value " << cond << endmsg;
40 
41  return StatusCode::SUCCESS;
42  }
43 
44  StatusCode finalize() override {
45  info() << "finalize" << endmsg;
46 
47  return base_class::finalize();
48  }
49  };
50  DECLARE_COMPONENT( UserAlg )
51 } // namespace Gaudi::TestSuite::Conditions
Gaudi::TestSuite::Conditions::UserAlg
Example of a simple algorithm using conditions via the ConditionAccessorHolder pattern.
Definition: User.cpp:17
GaudiPython.Pythonizations.ctx
ctx
Definition: Pythonizations.py:578
StatusCode
Definition: StatusCode.h:65
Gaudi::TestSuite::Conditions
Definition: ConditionAccessorHolder.h:21
Gaudi::TestSuite::Conditions::UserAlg::initialize
StatusCode initialize() override
Definition: User.cpp:24
Algorithm.h
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
Gaudi::TestSuite::Conditions::UserAlg::finalize
StatusCode finalize() override
Definition: User.cpp:44
Gaudi::TestSuite::Conditions::ConditionAccessorHolder
Example of a ConditionAccessorHolder implementation.
Definition: ConditionAccessorHolder.h:77
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
Gaudi::TestSuite::Conditions::UserAlg::execute
StatusCode execute(const EventContext &ctx) const override
Definition: User.cpp:33
Gaudi::TestSuite::Conditions::ConditionAccessorHolder< Algorithm >::getConditionContext
const ConditionContext & getConditionContext(const EventContext &ctx) const
Helper to map the event being processed to the corresponding conditions slot.
Definition: ConditionAccessorHolder.h:141
ConditionAccessorHolder.h
EventContext
Definition: EventContext.h:34
CommonMessaging::base_class
CommonMessaging base_class
Definition: CommonMessaging.h:142
Gaudi::TestSuite::Conditions::UserAlg::m_cond
ConditionAccessor< int > m_cond
Data member to access condition values for the current event.
Definition: User.cpp:22