ATLAS Offline Software
Loading...
Searching...
No Matches
xAODTestReadPVec.cxx
Go to the documentation of this file.
1/*
2 * Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration.
3 */
10
11
12#include "xAODTestReadPVec.h"
19#include <memory>
20#include <sstream>
21#include <format>
22
23
24namespace DMTest {
25
26
31{
32 ATH_CHECK( m_pvecKey.initialize() );
33 if (!m_writeKey.key().empty())
34 ATH_CHECK( m_writeKey.initialize() );
35 return StatusCode::SUCCESS;
36}
37
38
42StatusCode xAODTestReadPVec::execute (const EventContext& ctx) const
43{
45
46 const static SG::ConstAccessor<unsigned int> dpInt1 ("dpInt1");
47 const static SG::ConstAccessor<std::vector<float> > dpvFloat ("dpvFloat");
48
49 for (const P* p : *pvec) {
50 std::ostringstream ost;
51 ost << " pInt: " << p->pInt()
52 << " pFloat: " << std::format ("{:.2f}", p->pFloat());
53 if (dpInt1.isAvailable(*p))
54 ost << " dpInt1: " << dpInt1(*p);
55 ost << "\n";
56
57 {
58 const std::vector<int>& pvi = p->pvInt();
59 ost << " pvInt: [";
60 for (auto ii : pvi)
61 ost << ii << " ";
62 ost << "]\n";
63 }
64
65 {
66 const std::vector<float>& pvf = p->pvFloat();
67 ost << " pvFloat: [";
68 for (auto f : pvf)
69 ost << std::format ("{:.3f}", f) << " ";
70 ost << "]\n";
71 }
72
73 if (dpvFloat.isAvailable(*p))
74 {
75 const std::vector<float>& pvf = dpvFloat(*p);
76 ost << " dpvFloat: [";
77 for (auto f : pvf)
78 ost << std::format ("{:.3f}", f) << " ";
79 ost << "]\n";
80 }
81
82 ATH_MSG_INFO (ost.str());
83 }
84
85 if (!m_writeKey.key().empty()) {
86 auto vecnew = std::make_unique<PVec>();
87 auto store = std::make_unique<PAuxContainer>();
88 vecnew->setStore (store.get());
89 for (size_t i = 0; i < pvec->size(); i++) {
90 vecnew->push_back (new P);
91 *vecnew->back() = *(*pvec)[i];
92 }
94 ATH_CHECK( writevec.record(std::move(vecnew), std::move(store)) );
95 }
96
97 return StatusCode::SUCCESS;
98}
99
100
101} // namespace DMTest
102
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
Helper class to provide constant type-safe access to aux data.
std::array< fp_t, 2 > pvec
Class used for testing xAOD data reading/writing with packed containers.
Class used for testing xAOD data reading/writing with packed containers.
Class used for testing xAOD data reading/writing with packed containers.
Handle class for reading from StoreGate.
Handle class for recording to StoreGate.
virtual StatusCode initialize() override
Algorithm initialization; called at the beginning of the job.
SG::WriteHandleKey< DMTest::PVec > m_writeKey
SG::ReadHandleKey< DMTest::PVec > m_pvecKey
virtual StatusCode execute(const EventContext &ctx) const override
Algorithm event processing.
Helper class to provide constant type-safe access to aux data.
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
Definition B.h:23
P_v1 P
Definition P.h:23