ATLAS Offline Software
AthViews/src_dflow/DFlowAlg3.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 // 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 
23 namespace AthViews {
24 
26 // Public methods:
28 
29 // Constructors
31 DFlowAlg3::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
58 {}
59 
60 // Athena Algorithm's Hooks
63 {
64  ATH_MSG_INFO ("Initializing " << name() << "...");
65 
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() );
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
172  SG::ReadHandle< HiveDataObj > testUpdate( m_testUpdate, ctx );
173  ATH_MSG_INFO( "Update handle final: " << testUpdate->val() );
174 
175  // Test conditions handles
176  SG::ReadCondHandle< CondDataObj > testConditions( m_condKeyTest, ctx );
177  ATH_MSG_INFO( "Conditions handle test: " << **testConditions << " from key " << testConditions.fullKey() );
178 
179  return StatusCode::SUCCESS;
180 }
181 
182 } //> end namespace AthViews
ReadHandleKey.h
Property holding a SG store/key/clid from which a ReadHandle is made.
StateLessPT_NewConfig.proxy
proxy
Definition: StateLessPT_NewConfig.py:392
AthViews::DFlowAlg3::m_w_dflowDummy
SG::WriteHandleKey< int > m_w_dflowDummy
Definition: AthViews/src_dflow/DFlowAlg3.h:64
SG::ReadCondHandle::fullKey
const DataObjID & fullKey() const
Definition: ReadCondHandle.h:60
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
AthViews::DFlowAlg3::finalize
virtual StatusCode finalize()
Definition: AthViews/src_dflow/DFlowAlg3.cxx:75
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
ExtendedEventContext.h
SG::VarHandleBase::clid
CLID clid() const
Return the class ID for the referenced object.
AthViews::DFlowAlg3::execute
virtual StatusCode execute()
Definition: AthViews/src_dflow/DFlowAlg3.cxx:82
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
Atlas::getExtendedEventContext
const ExtendedEventContext & getExtendedEventContext(const EventContext &ctx)
Retrieve an extended context from a context object.
Definition: ExtendedEventContext.cxx:32
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
SG::VarHandleBase::setProxyDict
virtual StatusCode setProxyDict(IProxyDict *store)
Explicitly set the event store.
Definition: StoreGate/src/VarHandleBase.cxx:534
dqt_zlumi_pandas.err
err
Definition: dqt_zlumi_pandas.py:193
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
AthViews::DFlowAlg3::m_r_ints
SG::ReadHandleKey< std::vector< int > > m_r_ints
Definition: AthViews/src_dflow/DFlowAlg3.h:63
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
calibdata.exception
exception
Definition: calibdata.py:496
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
AthViews::DFlowAlg3::initialize
virtual StatusCode initialize()
Definition: AthViews/src_dflow/DFlowAlg3.cxx:62
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
AthViews::DFlowAlg3::DFlowAlg3
DFlowAlg3()
Default constructor:
AthAlgorithm
Definition: AthAlgorithm.h:47
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
WriteHandleKey.h
Property holding a SG store/key/clid from which a WriteHandle is made.
AthViews::DFlowAlg3::m_r_int
SG::ReadHandleKey< int > m_r_int
Containers.
Definition: AthViews/src_dflow/DFlowAlg3.h:62
SG::WriteHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
AthViews
Definition: ViewDataVerifier.cxx:18
DFlowAlg3.h
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
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.
HiveDataObj::val
void val(int i)
Definition: HiveDataObj.h:22
AthViews::DFlowAlg3::m_testUpdate
SG::ReadHandleKey< HiveDataObj > m_testUpdate
Definition: AthViews/src_dflow/DFlowAlg3.h:65
AthViews::DFlowAlg3::m_condKeyTest
SG::ReadCondHandleKey< CondDataObj > m_condKeyTest
Definition: AthViews/src_dflow/DFlowAlg3.h:66
AthViews::DFlowAlg3::~DFlowAlg3
virtual ~DFlowAlg3()
Destructor:
Definition: AthViews/src_dflow/DFlowAlg3.cxx:57