ATLAS Offline Software
xAODTestReadHVec.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // $Id$
14 #include "xAODTestReadHVec.h"
19 #include "StoreGate/ReadHandle.h"
20 #include "StoreGate/WriteHandle.h"
21 #include <memory>
22 #include <sstream>
23 
24 
25 namespace DMTest {
26 
27 
34  ISvcLocator *pSvcLocator)
35  : AthReentrantAlgorithm (name, pSvcLocator),
36  m_hvecKey ("hvec"),
37  m_hviewKey ("hview"),
38  m_vecWriteKey (""),
39  m_viewWriteKey ("")
40 {
41  declareProperty ("HVecKey", m_hvecKey);
42  declareProperty ("HViewKey", m_hviewKey);
43  declareProperty ("VecWriteKey", m_vecWriteKey);
44  declareProperty ("ViewWriteKey", m_viewWriteKey);
45 }
46 
47 
52 {
53  ATH_CHECK( m_hvecKey.initialize() );
54  if (!m_hviewKey.key().empty())
55  ATH_CHECK( m_hviewKey.initialize() );
56  if (!m_vecWriteKey.key().empty())
57  ATH_CHECK( m_vecWriteKey.initialize() );
58  if (!m_viewWriteKey.key().empty())
59  ATH_CHECK( m_viewWriteKey.initialize() );
60  return StatusCode::SUCCESS;
61 }
62 
63 
67 StatusCode xAODTestReadHVec::execute (const EventContext& ctx) const
68 {
69  const DMTest::HVec* hvec = SG::get (m_hvecKey, ctx);
70  std::ostringstream ost1;
71  ost1 << m_hvecKey.key() << ":";
72  for (const H* h : *hvec)
73  ost1 << " " << h->aFloat();
74  ATH_MSG_INFO (ost1.str());
75 
76  if (const DMTest::HVec* hview = SG::get (m_hviewKey, ctx)) {
77  std::ostringstream ost2;
78  ost2 << m_hviewKey.key() << ":";
79  for (const H* h : *hview)
80  ost2 << " " << h->aFloat();
81  ATH_MSG_INFO (ost2.str());
82 
83 
84  if (!m_vecWriteKey.key().empty()) {
85  auto vecnew = std::make_unique<HVec>();
86  auto store = std::make_unique<HAuxContainer>();
87  vecnew->setStore (store.get());
88  for (size_t i = 0; i < hview->size(); i++) {
89  vecnew->push_back (new H);
90  *vecnew->back() = *(*hview)[i];
91  }
92 
93  auto viewnew = std::make_unique<HView>();
94  for (size_t i = 0; i < vecnew->size(); i++)
95  viewnew->push_back (vecnew->at(vecnew->size()-1-i));
96 
99  ATH_CHECK( writevec.record (std::move(vecnew), std::move(store)) );
100  ATH_CHECK( writeview.record (std::move(viewnew)) );
101  }
102  }
103 
104  return StatusCode::SUCCESS;
105 }
106 
107 
112 {
113  return StatusCode::SUCCESS;
114 }
115 
116 
117 } // namespace DMTest
118 
store
StoreGateSvc * store
Definition: fbtTestBasics.cxx:69
xAODTestReadHVec.h
Algorithm to test reading xAOD data with schema evolution (HVec/HView)
DMTest::xAODTestReadHVec::m_hviewKey
SG::ReadHandleKey< DMTest::HVec > m_hviewKey
Definition: xAODTestReadHVec.h:65
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
H.h
Test for xAOD schema evolution.
DMTest::xAODTestReadHVec::execute
virtual StatusCode execute(const EventContext &ctx) const override
Algorithm event processing.
Definition: xAODTestReadHVec.cxx:67
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
DMTest::xAODTestReadHVec::initialize
virtual StatusCode initialize() override
Algorithm initialization; called at the beginning of the job.
Definition: xAODTestReadHVec.cxx:51
HVec.h
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
DMTest::xAODTestReadHVec::xAODTestReadHVec
xAODTestReadHVec(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition: xAODTestReadHVec.cxx:33
WriteHandle.h
Handle class for recording to StoreGate.
lumiFormat.i
int i
Definition: lumiFormat.py:92
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
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
HAuxContainer.h
Test for xAOD schema evolution.
DMTest::xAODTestReadHVec::m_viewWriteKey
SG::WriteHandleKey< DMTest::HView > m_viewWriteKey
Definition: xAODTestReadHVec.h:67
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
DMTest::xAODTestReadHVec::finalize
virtual StatusCode finalize() override
Algorithm finalization; called at the end of the job.
Definition: xAODTestReadHVec.cxx:111
DMTest::xAODTestReadHVec::m_hvecKey
SG::ReadHandleKey< DMTest::HVec > m_hvecKey
Definition: xAODTestReadHVec.h:64
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
h
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
HView.h
ReadHandle.h
Handle class for reading from StoreGate.
DMTest::xAODTestReadHVec::m_vecWriteKey
SG::WriteHandleKey< DMTest::HVec > m_vecWriteKey
Definition: xAODTestReadHVec.h:66
SG::get
const T * get(const ReadHandleKey< T > &key)
Convenience function to retrieve an object given a ReadHandleKey.
DMTest
Definition: B.h:23
DMTest::H_v2
Definition: H_v2.h:30