ATLAS Offline Software
xAODTestReadHVec.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
12 #include "xAODTestReadHVec.h"
17 #include "StoreGate/ReadHandle.h"
18 #include "StoreGate/WriteHandle.h"
19 #include <memory>
20 #include <sstream>
21 
22 
23 namespace DMTest {
24 
25 
30 {
31  ATH_CHECK( m_hvecKey.initialize() );
32  ATH_CHECK( m_hviewKey.initialize(SG::AllowEmpty) );
33  ATH_CHECK( m_vecWriteKey.initialize(SG::AllowEmpty) );
35  return StatusCode::SUCCESS;
36 }
37 
38 
42 StatusCode xAODTestReadHVec::execute (const EventContext& ctx) const
43 {
44  const DMTest::HVec* hvec = SG::get (m_hvecKey, ctx);
45  std::ostringstream ost1;
46  ost1 << m_hvecKey.key() << ":";
47  for (const H* h : *hvec)
48  ost1 << " " << h->aFloat();
49  ATH_MSG_INFO (ost1.str());
50 
51  if (!m_hviewKey.empty()) {
52  const DMTest::HVec* hview = SG::get (m_hviewKey, ctx);
53  std::ostringstream ost2;
54  ost2 << m_hviewKey.key() << ":";
55  for (const H* h : *hview)
56  ost2 << " " << h->aFloat();
57  ATH_MSG_INFO (ost2.str());
58 
59 
60  if (!m_vecWriteKey.key().empty()) {
61  auto vecnew = std::make_unique<HVec>();
62  auto store = std::make_unique<HAuxContainer>();
63  vecnew->setStore (store.get());
64  for (size_t i = 0; i < hview->size(); i++) {
65  vecnew->push_back (new H);
66  *vecnew->back() = *(*hview)[i];
67  }
68 
69  auto viewnew = std::make_unique<HView>();
70  for (size_t i = 0; i < vecnew->size(); i++)
71  viewnew->push_back (vecnew->at(vecnew->size()-1-i));
72 
75  ATH_CHECK( writevec.record (std::move(vecnew), std::move(store)) );
76  ATH_CHECK( writeview.record (std::move(viewnew)) );
77  }
78  }
79 
80  return StatusCode::SUCCESS;
81 }
82 
83 
84 } // namespace DMTest
85 
store
StoreGateSvc * store
Definition: fbtTestBasics.cxx:71
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:53
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:42
DMTest::xAODTestReadHVec::initialize
virtual StatusCode initialize() override
Algorithm initialization; called at the beginning of the job.
Definition: xAODTestReadHVec.cxx:29
HVec.h
WriteHandle.h
Handle class for recording to StoreGate.
lumiFormat.i
int i
Definition: lumiFormat.py:85
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:57
DMTest::xAODTestReadHVec::m_hvecKey
SG::ReadHandleKey< DMTest::HVec > m_hvecKey
Definition: xAODTestReadHVec.h:51
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:55
SG::get
const T * get(const ReadHandleKey< T > &key)
Convenience function to retrieve an object given a ReadHandleKey.
SG::AllowEmpty
@ AllowEmpty
Definition: StoreGate/StoreGate/VarHandleKey.h:30
DMTest
Definition: B.h:23
DMTest::H_v2
Definition: H_v2.h:30