ATLAS Offline Software
Loading...
Searching...
No Matches
AthViews/src_dflow/DFlowAlg3.cxx
Go to the documentation of this file.
1
2
3/*
4 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
5*/
6
7// DFlowAlg3.cxx
8// Implementation file for class DFlowAlg3
9// Author: S.Binet<binet@cern.ch>
11
12// AthExStoreGateExample includes
13#include "DFlowAlg3.h"
14
15// STL includes
16
17// FrameWork includes
18#include "Gaudi/Property.h"
22
23namespace AthViews {
24
25// Athena Algorithm's Hooks
28{
29 ATH_MSG_INFO ("Initializing " << name() << "...");
30
31 CHECK( m_r_int.initialize() );
32 CHECK( m_r_ints.initialize() );
33 CHECK( m_w_dflowDummy.initialize() );
34 CHECK( m_testUpdate.initialize() );
35 CHECK( m_condKeyTest.initialize() );
36
37 return StatusCode::SUCCESS;
38}
39
41{
42 ATH_MSG_INFO ("Finalizing " << name() << "...");
43
44 return StatusCode::SUCCESS;
45}
46
47StatusCode DFlowAlg3::execute(const EventContext& ctx) const
48{
49 ATH_MSG_DEBUG ("Executing " << name() << "...");
50
51 SG::ReadHandle< int > inputScalarHandle( m_r_int, ctx );
52 ATH_MSG_INFO("================================");
53 ATH_MSG_INFO("myint r-handle...");
54 ATH_MSG_INFO("name: [" << inputScalarHandle.name() << "]");
55 ATH_MSG_INFO("store [" << inputScalarHandle.store() << "]");
56 ATH_MSG_INFO("clid: [" << inputScalarHandle.clid() << "]");
57
58 ATH_MSG_INFO("ptr: " << inputScalarHandle.cptr());
59 if ( inputScalarHandle.isValid() )
60 {
61 ATH_MSG_INFO( "val: " << *( inputScalarHandle.cptr() ) );
62 }
63
64 SG::ReadHandle< std::vector< int > > inputVectorHandle( m_r_ints, ctx );
65 ATH_MSG_INFO("ints r-handle...");
66 ATH_MSG_INFO("name: [" << inputVectorHandle.name() << "]");
67 ATH_MSG_INFO("store [" << inputVectorHandle.store() << "]");
68 ATH_MSG_INFO("clid: [" << inputVectorHandle.clid() << "]");
69 ATH_MSG_INFO("cptr: " << inputVectorHandle.cptr());
70
71 // try to modify 'ints' via ReadHandle<>
72 // shouldn't compile
73#ifdef TRY_COMPILATION_ERRORS
74 inputVectorHandle->push_back(666);
75#endif
76
77 // create a temporary r-handle
78 SG::ReadHandle< std::vector<int> > ints( inputVectorHandle.name() );
79 StatusCode sc = ints.setProxyDict( Atlas::getExtendedEventContext(ctx).proxy() );
80 if ( !sc.isSuccess() ) ATH_MSG_INFO( "Failed to load view " );
81 ATH_MSG_INFO( "temporary r-handle[ints] - size: " << ints->size() );
82
83 // test that inexistant proxies are correctly detected
84 ATH_MSG_INFO("-- testing inexistant proxies --");
85 {
86 SG::ReadHandle<int> o("--r-not-there--");
87 ATH_MSG_INFO("name: " << o.name());
88 ATH_MSG_INFO("valid:" << o.isValid());
89 if (o.isValid()) {
90 ATH_MSG_ERROR("should NOT be valid ! [line " << __LINE__ << "]" );
91 return StatusCode::FAILURE;
92 }
93 }
94 {
95 SG::WriteHandle<int> o("--w-not-there--");
96 ATH_MSG_INFO("name: " << o.name());
97 ATH_MSG_INFO("valid:" << o.isValid());
98 if (o.isValid()) {
99 ATH_MSG_ERROR("should NOT be valid ! [line " << __LINE__ << "]" );
100 return StatusCode::FAILURE;
101 }
102 }
103
104 // test WVar<T> semantics
105 ATH_MSG_INFO("-- testing WVar<T> semantics...");
106 {
107 SG::WriteHandle<int> o( inputScalarHandle.name() );
108 ATH_MSG_INFO("name: " << o.name());
109 ATH_MSG_INFO("valid:" << o.isValid());
110 if (o.isValid()) {
111 ATH_MSG_ERROR("should NOT be valid ! [line " << __LINE__ << "]" );
112 return StatusCode::FAILURE;
113 }
114 try {
115 *o = 42;
116 if (o.isValid()) {
117 ATH_MSG_ERROR("should NOT be valid ! [line " << __LINE__ << "]" );
118 return StatusCode::FAILURE;
119 }
120 } catch (std::exception &err) {
121 ATH_MSG_INFO("good, caught: [" << err.what() << "]");
122 }
123 ATH_MSG_INFO("valid:" << o.isValid());
124 if (o.isValid()) {
125 ATH_MSG_ERROR("should NOT be valid ! [line " << __LINE__ << "]" );
126 return StatusCode::FAILURE;
127 }
128 }
129
130 //Dummy object to fix the data flow
131 SG::WriteHandle< int > outputHandle( m_w_dflowDummy, ctx );
132 ATH_CHECK( outputHandle.record( std::make_unique<int>(1) ) );
133
134 // Test update handles
136 ATH_MSG_INFO( "Update handle final: " << testUpdate->val() );
137
138 // Test conditions handles
140 ATH_MSG_INFO( "Conditions handle test: " << **testConditions << " from key " << testConditions.fullKey() );
141
142 return StatusCode::SUCCESS;
143}
144
145} //> end namespace AthViews
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
#define CHECK(...)
Evaluate an expression and check for errors.
static Double_t sc
Property holding a SG store/key/clid from which a ReadHandle is made.
Property holding a SG store/key/clid from which a WriteHandle is made.
SG::ReadHandleKey< std::vector< int > > m_r_ints
virtual StatusCode execute(const EventContext &ctx) const override
virtual StatusCode initialize() override
SG::WriteHandleKey< int > m_w_dflowDummy
virtual StatusCode finalize() override
SG::ReadHandleKey< int > m_r_int
SG::ReadHandleKey< HiveDataObj > m_testUpdate
SG::ReadCondHandleKey< CondDataObj > m_condKeyTest
const DataObjID & fullKey() const
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
virtual StatusCode setProxyDict(IProxyDict *store)
Explicitly set the event store.
std::string store() const
Return the name of the store holding the object we are proxying.
CLID clid() const
Return the class ID for the referenced object.
const std::string & name() const
Return the StoreGate ID for the referenced object.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const ExtendedEventContext & getExtendedEventContext(const EventContext &ctx)
Retrieve an extended context from a context object.