ATLAS Offline Software
AthViews/src_dflow/DFlowAlg1.cxx
Go to the documentation of this file.
1 
3 /*
4  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
5 */
6 
7 // DFlowAlg1.cxx
8 // Implementation file for class DFlowAlg1
9 // Modifed by bwynne to add simple tests for views
10 // Author: S.Binet<binet@cern.ch>
12 
13 // AthExStoreGateExample includes
14 #include "DFlowAlg1.h"
15 
16 // STL includes
17 
18 // FrameWork includes
19 #include "Gaudi/Property.h"
20 #include "StoreGate/ReadHandle.h"
21 #include "StoreGate/WriteHandle.h"
22 
23 namespace AthViews {
24 
26 // Public methods:
28 
29 // Constructors
31 DFlowAlg1::DFlowAlg1( const std::string& name,
32  ISvcLocator* pSvcLocator ) :
33  ::AthAlgorithm( name, pSvcLocator ),
34  m_r_int( "view_start" ),
35  m_w_int( "dflow_int" ),
36  m_testUpdate( "testUpdate" )
37 {
38  //
39  // Property declaration
40  //
41  //declareProperty( "Property", m_nProperty );
42 
43  declareProperty( "IntFlow", m_w_int, "Data flow of int" );
44 
45  declareProperty( "ViewStart", m_r_int, "Seed data of view" );
46 
47  declareProperty( "TestUpdate", m_testUpdate, "Test update handle" );
48 }
49 
50 // Destructor
53 {}
54 
55 // Athena Algorithm's Hooks
58 {
59  ATH_MSG_INFO ("Initializing " << name() << "...");
60 
64 
65  return StatusCode::SUCCESS;
66 }
67 
69 {
70  ATH_MSG_INFO ("Finalizing " << name() << "...");
71 
72  return StatusCode::SUCCESS;
73 }
74 
76 {
77  ATH_MSG_DEBUG ("Executing " << name() << "...");
78 
79  const EventContext& ctx = getContext();
80 
81  SG::ReadHandle< int > inputData( m_r_int, ctx );
82  if ( !inputData.isValid() )
83  {
84  ATH_MSG_ERROR( "Failed to retrieve initial view data from store " << inputData.store() );
85  return StatusCode::FAILURE;
86  }
87  int seedData = *inputData;
88 
89  SG::WriteHandle< int > outputData( m_w_int, ctx );
90  ATH_MSG_INFO("myint handle...");
91  ATH_MSG_INFO("name: [" << outputData.name() << "]");
92  ATH_MSG_INFO("store [" << outputData.store() << "]");
93  ATH_MSG_INFO("clid: [" << outputData.clid() << "]");
94 
95  ATH_CHECK( outputData.record( std::make_unique< int >( seedData ) ) );
96 
97  //redundant check as op = would throw if outputData was not valid (e.g. because if clid/key combo was duplicated)
98  if ( outputData.isValid() )
99  {
100  ATH_MSG_INFO("ptr: " << outputData.cptr());
101  ATH_MSG_INFO("val: " << *outputData);
102 
103  ATH_MSG_INFO("modify myint by value...");
104 
105  ATH_MSG_INFO("ptr: " << outputData.cptr());
106  ATH_MSG_INFO("val: " << *outputData);
107  }
108 
109  // Test update handles
110  SG::WriteHandle< HiveDataObj > testUpdate( m_testUpdate, ctx );
111  ATH_CHECK( testUpdate.recordNonConst( std::make_unique< HiveDataObj >( 123 ) ) );
112  ATH_MSG_INFO( "Update handle initial: " << testUpdate->val() );
113 
114  return StatusCode::SUCCESS;
115 }
116 
117 } //> end namespace AthViews
AthViews::DFlowAlg1::initialize
virtual StatusCode initialize()
Definition: AthViews/src_dflow/DFlowAlg1.cxx:57
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
SG::VarHandleBase::name
const std::string & name() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleBase.cxx:75
SG::VarHandleBase::clid
CLID clid() const
Return the class ID for the referenced object.
SG::WriteHandle::cptr
const_pointer_type cptr() const
Dereference the pointer.
AthViews::DFlowAlg1::m_w_int
SG::WriteHandleKey< int > m_w_int
Definition: AthViews/src_dflow/DFlowAlg1.h:62
DFlowAlg1.h
AthViews::DFlowAlg1::m_testUpdate
SG::WriteHandleKey< HiveDataObj > m_testUpdate
Definition: AthViews/src_dflow/DFlowAlg1.h:63
WriteHandle.h
Handle class for recording to StoreGate.
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
SG::WriteHandle::recordNonConst
StatusCode recordNonConst(std::unique_ptr< T > data)
Record a non-const object to the store.
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
SG::VarHandleBase::store
std::string store() const
Return the name of the store holding the object we are proxying.
Definition: StoreGate/src/VarHandleBase.cxx:379
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
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
AthAlgorithm
Definition: AthAlgorithm.h:47
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
AthViews::DFlowAlg1::finalize
virtual StatusCode finalize()
Definition: AthViews/src_dflow/DFlowAlg1.cxx:68
SG::WriteHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
AthViews::DFlowAlg1::execute
virtual StatusCode execute()
Definition: AthViews/src_dflow/DFlowAlg1.cxx:75
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
AthViews
Definition: ViewDataVerifier.cxx:18
AthViews::DFlowAlg1::~DFlowAlg1
virtual ~DFlowAlg1()
Destructor:
Definition: AthViews/src_dflow/DFlowAlg1.cxx:52
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.
AthViews::DFlowAlg1::m_r_int
SG::ReadHandleKey< int > m_r_int
Containers.
Definition: AthViews/src_dflow/DFlowAlg1.h:61
HiveDataObj::val
void val(int i)
Definition: HiveDataObj.h:22
AthViews::DFlowAlg1::DFlowAlg1
DFlowAlg1()
Default constructor:
ReadHandle.h
Handle class for reading from StoreGate.