ATLAS Offline Software
xAODTestRead.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
12 #include "xAODTestRead.h"
21 #include "StoreGate/ReadHandle.h"
22 #include "StoreGate/WriteHandle.h"
25 #include <memory>
26 #include <sstream>
27 
28 
29 namespace DMTest {
30 
31 
36 {
37  ATH_CHECK( m_ctrigReadKey.initialize() );
38  ATH_CHECK( m_gvecReadKey.initialize (SG::AllowEmpty) );
39  ATH_CHECK( m_cvecWDReadKey.initialize() );
41  ATH_CHECK( m_gvecWriteKey.initialize (SG::AllowEmpty) );
43  return StatusCode::SUCCESS;
44 }
45 
46 
50 StatusCode xAODTestRead::execute (const EventContext& ctx) const
51 {
52  ATH_MSG_INFO (ctx.evt()+1);
53 
54  static const C::Accessor<int> anInt2 ("anInt2");
55  static const C::Accessor<int> anInt10 ("anInt10");
56  static const C::Accessor<int> dInt1 ("dInt1");
57  static const C::Accessor<int> dInt100 ("dInt100");
58  static const C::Accessor<int> dInt150 ("dInt150");
59  static const C::Accessor<int> dInt200 ("dInt200");
60 
61  // Ordering of auxid is not reliable. Sort by name.
63  std::vector<std::string> names;
64 
66 
67  names.clear();
68  for (SG::auxid_t auxid : ctrig->getAuxIDs())
69  names.push_back (r.getName(auxid));
70  std::sort (names.begin(), names.end());
71  std::ostringstream ost1;
72  ost1 << "ctrig aux items: ";
73  for (const std::string& n : names)
74  ost1 << n << " ";
75  ATH_MSG_INFO (ost1.str());
76 
77  for (const C* c : *ctrig) {
78  std::ostringstream ost;
79  ost << " anInt1 " << c->anInt()
80  << " aFloat: " << c->aFloat()
81  << " anInt2: " << anInt2(*c)
82  << " dInt1: " << dInt1(*c);
83  if (dInt100.isAvailable(*c))
84  ost << " dInt100: " << dInt100(*c);
85  if (dInt150.isAvailable(*c))
86  ost << " dInt150: " << dInt150(*c);
87  if (dInt200.isAvailable(*c))
88  ost << " dInt200: " << dInt200(*c);
89  if (anInt10.isAvailable(*c))
90  ost << " anInt10: " << anInt10(*c);
91  ATH_MSG_INFO (ost.str());
92  }
93 
94  if (!m_ctrigWriteKey.empty()) {
95  auto ctrignew = std::make_unique<CVec>();
96  auto trig_store = std::make_unique<CTrigAuxContainer>();
97  ctrignew->setStore (trig_store.get());
98  for (size_t i = 0; i < ctrig->size(); i++) {
99  ctrignew->push_back (new C);
100  *ctrignew->back() = *(*ctrig)[i];
101  }
102  SG::WriteHandle<CVec> ctrigWrite (m_ctrigWriteKey, ctx);
103  ATH_CHECK( ctrigWrite.record (std::move(ctrignew),
104  std::move(trig_store)) );
105  }
106 
107  if (!m_gvecReadKey.empty()) {
108  ATH_CHECK( read_gvec (ctx) );
109  }
110 
112  //ATH_CHECK( read_cview() );
113 
114  return StatusCode::SUCCESS;
115 }
116 
117 
121 StatusCode xAODTestRead::read_cvec_with_data (const EventContext& ctx) const
122 {
124 
125  static const C::Accessor<int> anInt10 ("anInt10");
126  std::ostringstream ost;
127  ost << m_cvecWDReadKey.key() << " " << vec->meta1 << ":";
128  for (const C* c : *vec) {
129  ost << " " << c->anInt();
130  if (anInt10.isAvailable(*c))
131  ost << "(" << anInt10(*c) << ")";
132  }
133  ATH_MSG_INFO (ost.str());
134 
135  if (!m_cvecWDWriteKey.empty()) {
136  auto vecnew = std::make_unique<CVecWithData>();
137  auto store = std::make_unique<CAuxContainer>();
138  vecnew->setStore (store.get());
139  for (size_t i = 0; i < vec->size(); i++) {
140  vecnew->push_back (new C);
141  *vecnew->back() = *(*vec)[i];
142  }
144  ATH_CHECK( cvecWDWrite.record (std::move(vecnew),
145  std::move(store)) );
146  }
147 
148  return StatusCode::SUCCESS;
149 }
150 
151 
155 StatusCode xAODTestRead::read_gvec (const EventContext& ctx) const
156 {
159 
160  std::vector<std::string> names;
161  for (SG::auxid_t auxid : gvec->getAuxIDs())
162  names.push_back (r.getName(auxid));
163  std::sort (names.begin(), names.end());
164  std::ostringstream ost3;
165  ost3 << "gvec aux items: ";
166  for (const std::string& n : names)
167  ost3 << n << " ";
168  ost3 << "\n";
169  for (const G* g : *gvec) {
170  ost3 << " anInt " << g->anInt();
171  ost3 << " gFloat " << g->gFloat();
172  ost3 << " gvFloat ";
173  for (float f : g->gvFloat())
174  ost3 << f << " ";
175  ost3 << "\n";
176  }
177  ATH_MSG_INFO (ost3.str());
178 
179  if (!m_gvecWriteKey.empty()) {
180  auto gvecnew = std::make_unique<GVec>();
181  auto gstore = std::make_unique<GAuxContainer>();
182  gvecnew->setStore (gstore.get());
183  for (size_t i = 0; i < gvec->size(); i++) {
184  gvecnew->push_back (new G);
185  *gvecnew->back() = *(*gvec)[i];
186  }
187  SG::WriteHandle<GVec> gvecWrite (m_gvecWriteKey, ctx);
188  ATH_CHECK( gvecWrite.record (std::move(gvecnew),
189  std::move(gstore)) );
190  }
191 
192  return StatusCode::SUCCESS;
193 }
194 
195 
196 #if 0
197 
200 StatusCode xAODTestRead::read_cview() const
201 {
202  if (!evtStore()->contains<CView> (m_readPrefix + "cview")) {
203  ATH_MSG_INFO( "(No " << m_readPrefix << "cview view container.)" );
204  return StatusCode::SUCCESS;
205  }
206 
207  const CView* cview = nullptr;
208  static const C::Accessor<int> anInt10 ("anInt10");
209  CHECK( evtStore()->retrieve (cview, m_readPrefix + "cview") );
210  std::ostringstream ost;
211  ost << m_readPrefix << "cview:";
212  for (const C* c : *cview) {
213  ost << " " << c->anInt();
214  if (anInt10.isAvailable(*c))
215  ost << "(" << anInt10(*c) << ")";
216  }
217  ATH_MSG_INFO (ost.str());
218 
219  if (!m_writePrefix.empty()) {
220  bool LOCKED = false;
221  CHECK (evtStore()->record (std::make_unique<CView> (*cview),
222  m_writePrefix + "cview", LOCKED));
223  }
224 
225  return StatusCode::SUCCESS;
226 }
227 #endif
228 
229 
234 {
235  return StatusCode::SUCCESS;
236 }
237 
238 
239 } // namespace DMTest
240 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
beamspotman.r
def r
Definition: beamspotman.py:676
store
StoreGateSvc * store
Definition: fbtTestBasics.cxx:69
python.CaloRecoConfig.f
f
Definition: CaloRecoConfig.py:127
DMTest::xAODTestRead::execute
virtual StatusCode execute(const EventContext &ctx) const override
Algorithm event processing.
Definition: xAODTestRead.cxx:50
G.h
Test for xAOD auto schema evolution.
python.trigbs_prescaleL1.ost
ost
Definition: trigbs_prescaleL1.py:104
DMTest::xAODTestRead::read_gvec
StatusCode read_gvec(const EventContext &ctx) const
Test reading GVec object.
Definition: xAODTestRead.cxx:155
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SG::AuxTypeRegistry::instance
static AuxTypeRegistry & instance()
Return the singleton registry instance.
Definition: AuxTypeRegistry.cxx:49
DMTest::xAODTestRead::m_gvecReadKey
SG::ReadHandleKey< DMTest::GVec > m_gvecReadKey
Definition: xAODTestRead.h:70
DMTest::xAODTestRead::read_cvec_with_data
StatusCode read_cvec_with_data(const EventContext &ctx) const
Test reading container with additional data.
Definition: xAODTestRead.cxx:121
SG::Accessor
Helper class to provide type-safe access to aux data.
Definition: Control/AthContainers/AthContainers/Accessor.h:66
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
DMTest::C
C_v1 C
Definition: C.h:26
CAuxContainer.h
Class used for testing xAOD data reading/writing.
DMTest::C_v1
Definition: C_v1.h:29
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:12
DMTest::xAODTestRead::m_ctrigReadKey
SG::ReadHandleKey< DMTest::CVec > m_ctrigReadKey
Test reading view container.
Definition: xAODTestRead.h:67
SG::AuxTypeRegistry
Handle mappings between names and auxid_t.
Definition: AuxTypeRegistry.h:62
CxxUtils::vec
typename vecDetail::vec_typedef< T, N >::type vec
Define a nice alias for the vectorized type.
Definition: vec.h:207
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
WriteHandle.h
Handle class for recording to StoreGate.
SG::auxid_t
size_t auxid_t
Identifier for a particular aux data item.
Definition: AuxTypes.h:27
CVec.h
Class used for testing xAOD data reading/writing.
lumiFormat.i
int i
Definition: lumiFormat.py:92
python.CaloCondTools.g
g
Definition: CaloCondTools.py:15
beamspotman.n
n
Definition: beamspotman.py:731
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
python.subdetectors.mmg.names
names
Definition: mmg.py:8
DMTest::xAODTestRead::m_cvecWDWriteKey
SG::WriteHandleKey< DMTest::CVecWithData > m_cvecWDWriteKey
Definition: xAODTestRead.h:82
C.h
Class used for testing xAOD data reading/writing.
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
DMTest::xAODTestRead::m_ctrigWriteKey
SG::WriteHandleKey< DMTest::CVec > m_ctrigWriteKey
Definition: xAODTestRead.h:76
GVec.h
DMTest::G_v1
Definition: DataModelTestDataRead/DataModelTestDataRead/versions/G_v1.h:28
DMTest::xAODTestRead::initialize
virtual StatusCode initialize() override
Algorithm initialization; called at the beginning of the job.
Definition: xAODTestRead.cxx:35
GAuxContainer.h
Test for xAOD auto schema evolution.
xAODTestRead.h
Algorithm to test reading xAOD data.
errorcheck.h
Helpers for checking error return status codes and reporting errors.
CVecWithData.h
Test writing a container with metadata.
DMTest::CView
CView_v1 CView
Definition: CView.h:26
DMTest::xAODTestRead::m_gvecWriteKey
SG::WriteHandleKey< DMTest::GVec > m_gvecWriteKey
Definition: xAODTestRead.h:79
DMTest::xAODTestRead::finalize
virtual StatusCode finalize() override
Algorithm finalization; called at the end of the job.
Definition: xAODTestRead.cxx:233
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
MuonCond::DcsFsmState::LOCKED
@ LOCKED
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
AuxTypeRegistry.h
Handle mappings between names and auxid_t.
CTrigAuxContainer.h
Class used for testing xAOD data reading/writing.
SG::ConstAccessor< T, AuxAllocator_t< T > >::isAvailable
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
ReadHandle.h
Handle class for reading from StoreGate.
SG::AllowEmpty
@ AllowEmpty
Definition: StoreGate/StoreGate/VarHandleKey.h:30
python.compressB64.c
def c
Definition: compressB64.py:93
DMTest::xAODTestRead::m_cvecWDReadKey
SG::ReadHandleKey< DMTest::CVecWithData > m_cvecWDReadKey
Definition: xAODTestRead.h:73
DMTest
Definition: B.h:23