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-2020 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
26// Public methods:
28
29// Constructors
31DFlowAlg3::DFlowAlg3( const std::string& name,
32 ISvcLocator* pSvcLocator ) :
33 ::AthAlgorithm( name, pSvcLocator ),
34 m_r_int( "dflow_int" ),
35 m_r_ints( "dflow_ints" ),
36 m_w_dflowDummy( "dflow_dummy" ),
37 m_testUpdate( "testUpdate" )
38{
39 //
40 // Property declaration
41 //
42 //declareProperty( "Property", m_nProperty );
43
44
45 declareProperty( "RIntFlow", m_r_int, "Data flow of int (read)" );
46
47 declareProperty( "RIntsFlow", m_r_ints, "Data flow of integers (read)" );
48
49 declareProperty( "DFlowDummy", m_w_dflowDummy, "Dummy object to fix dependencies" );
50
51 declareProperty( "TestUpdate", m_testUpdate, "Test update handle" );
52
53}
54
55// Destructor
59
60// Athena Algorithm's Hooks
63{
64 ATH_MSG_INFO ("Initializing " << name() << "...");
65
66 CHECK( m_r_int.initialize() );
67 CHECK( m_r_ints.initialize() );
68 CHECK( m_w_dflowDummy.initialize() );
69 CHECK( m_testUpdate.initialize() );
70 CHECK( m_condKeyTest.initialize() );
71
72 return StatusCode::SUCCESS;
73}
74
76{
77 ATH_MSG_INFO ("Finalizing " << name() << "...");
78
79 return StatusCode::SUCCESS;
80}
81
83{
84 ATH_MSG_DEBUG ("Executing " << name() << "...");
85
86 const EventContext& ctx = getContext();
87
88 SG::ReadHandle< int > inputScalarHandle( m_r_int, ctx );
89 ATH_MSG_INFO("================================");
90 ATH_MSG_INFO("myint r-handle...");
91 ATH_MSG_INFO("name: [" << inputScalarHandle.name() << "]");
92 ATH_MSG_INFO("store [" << inputScalarHandle.store() << "]");
93 ATH_MSG_INFO("clid: [" << inputScalarHandle.clid() << "]");
94
95 ATH_MSG_INFO("ptr: " << inputScalarHandle.cptr());
96 if ( inputScalarHandle.isValid() )
97 {
98 ATH_MSG_INFO( "val: " << *( inputScalarHandle.cptr() ) );
99 }
100
101 SG::ReadHandle< std::vector< int > > inputVectorHandle( m_r_ints, ctx );
102 ATH_MSG_INFO("ints r-handle...");
103 ATH_MSG_INFO("name: [" << inputVectorHandle.name() << "]");
104 ATH_MSG_INFO("store [" << inputVectorHandle.store() << "]");
105 ATH_MSG_INFO("clid: [" << inputVectorHandle.clid() << "]");
106 ATH_MSG_INFO("cptr: " << inputVectorHandle.cptr());
107
108 // try to modify 'ints' via ReadHandle<>
109 // shouldn't compile
110#ifdef TRY_COMPILATION_ERRORS
111 inputVectorHandle->push_back(666);
112#endif
113
114 // create a temporary r-handle
115 SG::ReadHandle< std::vector<int> > ints( inputVectorHandle.name() );
116 StatusCode sc = ints.setProxyDict( Atlas::getExtendedEventContext(ctx).proxy() );
117 if ( !sc.isSuccess() ) ATH_MSG_INFO( "Failed to load view " );
118 ATH_MSG_INFO( "temporary r-handle[ints] - size: " << ints->size() );
119
120 // test that inexistant proxies are correctly detected
121 ATH_MSG_INFO("-- testing inexistant proxies --");
122 {
123 SG::ReadHandle<int> o("--r-not-there--");
124 ATH_MSG_INFO("name: " << o.name());
125 ATH_MSG_INFO("valid:" << o.isValid());
126 if (o.isValid()) {
127 ATH_MSG_ERROR("should NOT be valid ! [line " << __LINE__ << "]" );
128 return StatusCode::FAILURE;
129 }
130 }
131 {
132 SG::WriteHandle<int> o("--w-not-there--");
133 ATH_MSG_INFO("name: " << o.name());
134 ATH_MSG_INFO("valid:" << o.isValid());
135 if (o.isValid()) {
136 ATH_MSG_ERROR("should NOT be valid ! [line " << __LINE__ << "]" );
137 return StatusCode::FAILURE;
138 }
139 }
140
141 // test WVar<T> semantics
142 ATH_MSG_INFO("-- testing WVar<T> semantics...");
143 {
144 SG::WriteHandle<int> o( inputScalarHandle.name() );
145 ATH_MSG_INFO("name: " << o.name());
146 ATH_MSG_INFO("valid:" << o.isValid());
147 if (o.isValid()) {
148 ATH_MSG_ERROR("should NOT be valid ! [line " << __LINE__ << "]" );
149 return StatusCode::FAILURE;
150 }
151 try {
152 *o = 42;
153 if (o.isValid()) {
154 ATH_MSG_ERROR("should NOT be valid ! [line " << __LINE__ << "]" );
155 return StatusCode::FAILURE;
156 }
157 } catch (std::exception &err) {
158 ATH_MSG_INFO("good, caught: [" << err.what() << "]");
159 }
160 ATH_MSG_INFO("valid:" << o.isValid());
161 if (o.isValid()) {
162 ATH_MSG_ERROR("should NOT be valid ! [line " << __LINE__ << "]" );
163 return StatusCode::FAILURE;
164 }
165 }
166
167 //Dummy object to fix the data flow
168 SG::WriteHandle< int > outputHandle( m_w_dflowDummy, ctx );
169 ATH_CHECK( outputHandle.record( std::make_unique<int>(1) ) );
170
171 // Test update handles
173 ATH_MSG_INFO( "Update handle final: " << testUpdate->val() );
174
175 // Test conditions handles
177 ATH_MSG_INFO( "Conditions handle test: " << **testConditions << " from key " << testConditions.fullKey() );
178
179 return StatusCode::SUCCESS;
180}
181
182} //> 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.
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
SG::ReadHandleKey< std::vector< int > > m_r_ints
SG::WriteHandleKey< int > m_w_dflowDummy
DFlowAlg3()
Default constructor:
SG::ReadHandleKey< int > m_r_int
Containers.
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.