ATLAS Offline Software
xAODTestWriteCVec.cxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration.
3  */
12 #include "xAODTestWriteCVec.h"
18 #include "AthLinks/ElementLink.h"
20 
21 
22 #define CHECK_OPTION(ret) \
23  do { \
24  if (!ret) { \
25  ATH_MSG_ERROR("setOption failed"); \
26  return StatusCode::FAILURE; \
27  } \
28  } while(0)
29 
30 
31 namespace DMTest {
32 
33 
40  ISvcLocator *pSvcLocator)
41  : AthReentrantAlgorithm (name, pSvcLocator),
42  m_cvecKey ("cvec")
43 {
44  declareProperty ("CVecKey", m_cvecKey);
45  declareProperty ("CVecDecorKey", m_cvecDecorKey);
46 }
47 
48 
53 {
54  ATH_CHECK( m_cvecKey.initialize() );
55 
56  if (m_cvecDecorKey.key().empty())
57  m_cvecDecorKey = m_cvecKey.key() + ".dtest";
58  ATH_CHECK( m_cvecDecorKey.initialize() );
59 
60  return StatusCode::SUCCESS;
61 }
62 
63 
67 StatusCode xAODTestWriteCVec::execute (const EventContext& ctx) const
68 {
69  unsigned int count = ctx.eventID().event_number() + 1;
70 
71  auto coll = std::make_unique<DMTest::CVec>();
72  auto store = std::make_unique<DMTest::CAuxContainer>();
73  coll->setStore (store.get());
74 
75  const static C::Accessor<int> anInt2 ("anInt2");
76  const static C::Decorator<int> dVar1 ("dVar1");
77  const static C::Decorator<int> dVar2 ("dVar2");
78  const static C::Accessor<ElementLink<DMTest::CVec> > cEL ("cEL");
79 
80  const static C::Decorator<unsigned int> dpInt1 ("dpInt1");
81  const static C::Decorator<std::vector<float> > dpvFloat ("dpvFloat");
82 
83  int nent = 10;
84  if (count == 5) nent = 0;
85  for (int i=0; i < nent; i++) {
86  coll->push_back (new DMTest::C);
87  C& c = *coll->back();
88  c.setAnInt (count * 100 + i+1);
89  c.setAFloat (count * 200 + (float)i*0.1);
90  c.setPInt (count * 500 + i+1);
91  c.setPFloat (i + (float)count * 0.01);
92 
93  std::vector<int> pvi;
94  for (int j=0; j<i; j++)
95  pvi.push_back (j + i*10 + count*100 - 500);
96  c.setPVInt (pvi);
97 
98  std::vector<float> pvf;
99  for (int j=0; j<i; j++)
100  pvf.push_back ((float)j*0.1 + (float)i*0.01 + (float)count*0.001 - 0.5);
101  c.setPVFloat (std::move (pvf));
102 
103  anInt2(c) = count*300 + i+1;
104  dVar1(c) = count*450 + i+1;
105  dVar2(c) = count*750 + i+1;
106  dpInt1(c) = count*50 + i+1;
107  cEL(c).toIndexedElement (*coll, 9-i);
108 
109  pvf.clear();
110  for (int j=0; j<i; j++)
111  pvf.push_back ((float)i*0.1 + (float)count*0.01 + (float)j*0.001);
112  dpvFloat(c) = std::move(pvf);
113  }
114 
116  CHECK( cvec.record (std::move(coll), std::move(store)) );
117 
119  for (int i=0; i < nent; i++) {
120  dtest (*(*dtest)[i]) = i+123;
121  }
122 
123  CHECK_OPTION( cvec->setOption ("dpInt1", SG::AuxDataOption ("nbits", 13)) );
124  CHECK_OPTION( cvec->setOption ("dpvFloat", SG::AuxDataOption ("nbits", 13)) );
125  CHECK_OPTION( cvec->setOption ("dpvFloat", SG::AuxDataOption ("signed", 0)));
126  CHECK_OPTION( cvec->setOption ("dpvFloat", SG::AuxDataOption ("nmantissa", 13)) );
127 
128  return StatusCode::SUCCESS;
129 }
130 
131 
136 {
137  return StatusCode::SUCCESS;
138 }
139 
140 
141 } // namespace DMTest
142 
store
StoreGateSvc * store
Definition: fbtTestBasics.cxx:69
DMTest::xAODTestWriteCVec::xAODTestWriteCVec
xAODTestWriteCVec(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition: xAODTestWriteCVec.cxx:39
DMTest::xAODTestWriteCVec::finalize
virtual StatusCode finalize() override
Algorithm finalization; called at the end of the job.
Definition: xAODTestWriteCVec.cxx:135
SG::Accessor
Helper class to provide type-safe access to aux data.
Definition: Control/AthContainers/AthContainers/Accessor.h:66
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
CAuxContainer.h
Class used for testing xAOD data reading/writing.
DMTest::xAODTestWriteCVec::m_cvecDecorKey
SG::WriteDecorHandleKey< DMTest::CVec > m_cvecDecorKey
Definition: xAODTestWriteCVec.h:62
DMTest::C_v1
Definition: C_v1.h:29
xAODTestWriteCVec.h
Algorithm to test writing xAOD classes with auxiliary data (cvec).
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
CHECK_OPTION
#define CHECK_OPTION(ret)
Definition: xAODTestWriteCVec.cxx:22
AuxDataOption.h
Hold information about an option setting request.
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
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
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:99
C.h
Class used for testing xAOD data reading/writing.
WriteDecorHandle.h
Handle class for adding a decoration to an object.
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::xAODTestWriteCVec::m_cvecKey
SG::WriteHandleKey< DMTest::CVec > m_cvecKey
Definition: xAODTestWriteCVec.h:61
DMTest::xAODTestWriteCVec::execute
virtual StatusCode execute(const EventContext &ctx) const override
Algorithm event processing.
Definition: xAODTestWriteCVec.cxx:67
SG::AuxDataOption
Hold information about an option setting request.
Definition: AuxDataOption.h:37
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
DMTest::xAODTestWriteCVec::initialize
virtual StatusCode initialize() override
Algorithm initialization; called at the beginning of the job.
Definition: xAODTestWriteCVec.cxx:52
errorcheck.h
Helpers for checking error return status codes and reporting errors.
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
python.compressB64.c
def c
Definition: compressB64.py:93
DMTest
Definition: B.h:23