ATLAS Offline Software
xAODTestWrite.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // $Id$
14 #include "xAODTestWrite.h"
15 #include "xAODTestWriteHelper.h"
24 //#include "DataModelTestDataWrite/H.h"
25 //#include "DataModelTestDataWrite/HVec.h"
26 //#include "DataModelTestDataWrite/HView.h"
27 //#include "DataModelTestDataWrite/HAuxContainer.h"
29 #include "AthLinks/ElementLink.h"
31 
32 
33 #define CHECK_OPTION(ret) \
34  do { \
35  if (!ret) { \
36  ATH_MSG_ERROR("setOption failed"); \
37  return StatusCode::FAILURE; \
38  } \
39  } while(0)
40 
41 
42 namespace DMTest {
43 
44 
50 xAODTestWrite::xAODTestWrite (const std::string &name,
51  ISvcLocator *pSvcLocator)
52  : AthReentrantAlgorithm (name, pSvcLocator)
53 {
54  declareProperty ("CVecKey", m_cvecKey = "cvec");
55  declareProperty ("CTrigKey", m_ctrigKey = "ctrig");
56  declareProperty ("GVecKey", m_gvecKey = "gvec");
57  declareProperty ("CVecWDKey", m_cvecWDKey = "cvecWD");
58 }
59 
60 
65 {
66  ATH_CHECK( m_cvecKey.initialize() );
67  ATH_CHECK( m_ctrigKey.initialize() );
68  ATH_CHECK( m_gvecKey.initialize() );
69  ATH_CHECK( m_cvecWDKey.initialize() );
70  return StatusCode::SUCCESS;
71 }
72 
73 
77 StatusCode xAODTestWrite::execute (const EventContext& ctx) const
78 {
79  unsigned int count = ctx.eventID().event_number() + 1;
80 
82 
83  auto trig_coll = std::make_unique<DMTest::CVec>();
84  auto trig_store = std::make_unique<DMTest::CTrigAuxContainer>();
85  trig_coll->setStore (trig_store.get());
86 
87  static const C::Accessor<int> anInt2 ("anInt2");
88  static const C::Accessor<ElementLink<DMTest::CVec> > cEL ("cEL");
89 
90  //static const C::Decorator<SG::PackedElement<unsigned int> > dpInt1 ("dpInt1");
91  //static const C::Decorator<SG::PackedElement<std::vector<float> > > dpvFloat ("dpvFloat");
92  static const C::Decorator<unsigned int> dpInt1 ("dpInt1");
93  static const C::Decorator<std::vector<float> > dpvFloat ("dpvFloat");
94 
95  for (int i=0; i < 8; i++) {
96  trig_coll->push_back (new DMTest::C);
97  C& c = *trig_coll->back();
98  c.setAnInt (count * 500 + i+1);
99  c.setAFloat (count * 600 + (float)i*0.1);
100 
101  anInt2(c) = count*700 + i+1;
102  }
103 
105  CHECK( ctrig.record (std::move (trig_coll), std::move (trig_store)) );
106 
107  auto gcont = std::make_unique<DMTest::GVec>();
108  auto gstore = std::make_unique<DMTest::GAuxContainer>();
109  gcont->setStore (gstore.get());
110 
111  for (int i=0; i < 10; i++) {
112  gcont->push_back (new DMTest::G);
113  G& g = *gcont->back();
114  g.setAnInt (count * 700 + i+1);
115  g.setgFloat (count * 700 + 100 + i+0.5);
116  std::vector<double> v;
117  for (int j=0; j<i; j++) {
118  v.push_back (count * 700 + 100*j + i+0.5);
119  }
120  g.setgvFloat (v);
121  }
122 
124  CHECK( gvec.record (std::move (gcont), std::move (gstore)) );
125 
126  CHECK( write_cvec_with_data (count, ctx) );
127 
128  return StatusCode::SUCCESS;
129 }
130 
131 
136  const EventContext& ctx) const
137 {
138  auto coll = std::make_unique<DMTest::CVecWithData>();
139  auto store = std::make_unique<DMTest::CAuxContainer>();
140  coll->setStore (store.get());
141 
142  coll->meta1 = count + 1000;
143  for (int i=0; i < 10; i++) {
144  coll->push_back (new DMTest::C);
145  C& c = *coll->back();
146  c.setAnInt (count * 200 + i+1);
147  }
148 
150  CHECK( cvecWD.record (std::move (coll), std::move (store)) );
151 
152  return StatusCode::SUCCESS;
153 }
154 
155 
156 #if 0
157 
160 StatusCode xAODTestWrite::write_htest()
161 {
162  auto hvec = std::make_unique<DMTest::HVec>();
163  auto store = std::make_unique<DMTest::HAuxContainer>();
164  hvec->setStore (store.get());
165  auto hview = std::make_unique<DMTest::HView>();
166 
167  for (int i = 0; i < 20; i++) {
168  hvec->push_back (new DMTest::H);
169  hvec->back()->setAnInt (i+1 + count * 400);
170  }
171 
172  for (int i = 0; i < 20; i++) {
173  hview->push_back (hvec->at (19-i));
174  }
175 
176  ATH_CHECK( SG::makeHandle(m_hvecKey).record (std::move(hvec),
177  std::move(store)) );
178  CHECK( DMTest::recordView2 (&*evtStore(), std::move(hview), "hview") );
179 
180  return StatusCode::SUCCESS;
181 }
182 #endif
183 
184 
189 {
190  return StatusCode::SUCCESS;
191 }
192 
193 
194 } // namespace DMTest
195 
DMTest::xAODTestWrite::xAODTestWrite
xAODTestWrite(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition: xAODTestWrite.cxx:50
store
StoreGateSvc * store
Definition: fbtTestBasics.cxx:69
DMTest::xAODTestWrite::initialize
virtual StatusCode initialize() override
Algorithm initialization; called at the beginning of the job.
Definition: xAODTestWrite.cxx:64
DMTest::xAODTestWrite::m_ctrigKey
SG::WriteHandleKey< DMTest::CVec > m_ctrigKey
Definition: xAODTestWrite.h:70
SG::Accessor
Helper class to provide type-safe access to aux data.
Definition: Control/AthContainers/AthContainers/Accessor.h:66
DMTest::xAODTestWrite::execute
virtual StatusCode execute(const EventContext &ctx) const override
Algorithm event processing.
Definition: xAODTestWrite.cxx:77
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
GVec.h
DMTest::xAODTestWrite::finalize
virtual StatusCode finalize() override
Algorithm finalization; called at the end of the job.
Definition: xAODTestWrite.cxx:188
CAuxContainer.h
Class used for testing xAOD data reading/writing.
DMTest::C_v1
Definition: C_v1.h:29
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
AuxDataOption.h
Hold information about an option setting request.
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:269
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
G.h
Test for xAOD auto schema evolution.
CVec.h
Class used for testing xAOD data reading/writing.
SG::Decorator
Helper class to provide type-safe access to aux data.
Definition: Decorator.h:58
lumiFormat.i
int i
Definition: lumiFormat.py:92
python.CaloCondTools.g
g
Definition: CaloCondTools.py:15
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
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::xAODTestWrite::write_cvec_with_data
StatusCode write_cvec_with_data(unsigned int count, const EventContext &ctx) const
Test writing container with additional data.
Definition: xAODTestWrite.cxx:135
DMTest::G_v1
Definition: DataModelTestDataRead/DataModelTestDataRead/versions/G_v1.h:28
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
errorcheck.h
Helpers for checking error return status codes and reporting errors.
CVecWithData.h
Test writing a container with metadata.
DMTest::xAODTestWrite::m_cvecWDKey
SG::WriteHandleKey< DMTest::CVecWithData > m_cvecWDKey
Definition: xAODTestWrite.h:72
DMTest::xAODTestWrite::m_cvecKey
SG::ReadHandleKey< DMTest::CVec > m_cvecKey
Definition: xAODTestWrite.h:69
python.PyAthena.v
v
Definition: PyAthena.py:157
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
DMTest::recordView2
StatusCode recordView2(SG::WriteHandle< ViewVector< DMTest::HVec > > &h, std::unique_ptr< ViewVector< DMTest::HVec > > view)
Definition: xAODTestWriteHelper.cxx:28
xAODTestWrite.h
Algorithm to test writing xAOD classes with auxiliary data.
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
xAODTestWriteHelper.h
Test recording ViewVector w/o having CLASS_DEF visible in compilation unit.
CTrigAuxContainer.h
Class used for testing xAOD data reading/writing.
GAuxContainer.h
Test for xAOD auto schema evolution.
python.compressB64.c
def c
Definition: compressB64.py:93
DMTest::xAODTestWrite::m_gvecKey
SG::WriteHandleKey< DMTest::GVec > m_gvecKey
Definition: xAODTestWrite.h:71
DMTest
Definition: B.h:23
DMTest::H_v2
Definition: H_v2.h:30