ATLAS Offline Software
ExampleAlg.cxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration.
3  */
4 // $Id$
13 #include "ExampleAlg.h"
14 
15 
16 ExampleAlg::ExampleAlg (const std::string& name, ISvcLocator* svcLocator)
17  : AthReentrantAlgorithm (name, svcLocator)
18 {
19  // Declare the keys as properties.
20  // You can set defaults here that can be overridden during job configuration.
21  declareProperty ("ReadKey", m_readKey = "in");
22  declareProperty ("WriteKey", m_writeKey = "out");
23 }
24 
25 
27 {
28  // This will check that the properties were initialized properly
29  // by job condifiguration.
32  return StatusCode::SUCCESS;
33 }
34 
35 
36 StatusCode ExampleAlg::execute (const EventContext& ctx) const
37 {
38  // Construct handles from the keys.
39  // Since this is a reentrant algorithm, we have an explicit event context,
40  // which we pass to the handles.
43 
44  // Now we can dereference the read handle to access input data.
45  int newval = h_read->val()+1;
46 
47  // We make a new object, held by a unique_ptr, and record it
48  // in the store using the record method of the handle.
49  ATH_CHECK( h_write.record (std::make_unique<MyDataObj> (newval)) );
50  return StatusCode::SUCCESS;
51 }
52 
53 
ExampleAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: ExampleAlg.cxx:36
SG::ReadHandle< MyDataObj >
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
MyDataObj::val
void val(int i)
Definition: AthExStoreGateExample/MyDataObj.h:24
ExampleAlg::m_writeKey
SG::WriteHandleKey< MyDataObj > m_writeKey
Definition: ExampleAlg.h:38
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
ExampleAlg.h
Example of using handles for data access.
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
ExampleAlg::ExampleAlg
ExampleAlg(const std::string &name, ISvcLocator *svcLocator)
Definition: ExampleAlg.cxx:16
ExampleAlg::initialize
virtual StatusCode initialize() override
Definition: ExampleAlg.cxx:26
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
ExampleAlg::m_readKey
SG::ReadHandleKey< MyDataObj > m_readKey
Definition: ExampleAlg.h:37