ATLAS Offline Software
DMTestWrite.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
19 #include "DMTestWrite.h"
28 #include "StoreGate/StoreGateSvc.h"
29 #include "GaudiKernel/MsgStream.h"
31 
32 
33 namespace DMTest {
34 
35 
41 DMTestWrite::DMTestWrite (const std::string& name, ISvcLocator* pSvcLocator)
42  : AthReentrantAlgorithm (name, pSvcLocator)
43 {
44 }
45 
46 
47 namespace {
48 
49 
58 template <class VEC>
59 StatusCode make_vec (StoreGateSvc* sg,
60  int n,
61  int istart,
62  const std::string& key,
63  const std::string& context)
64 {
65  VEC* vec = new VEC;
66  for (int i=0; i < n; i++)
67  vec->push_back (new typename VEC::base_value_type (i + istart));
68  CHECK_WITH_CONTEXT( sg->record (vec, key), context);
69  return StatusCode::SUCCESS;
70 }
71 
72 
73 StatusCode make_elvec (StoreGateSvc* sg,
74  const std::string& key,
75  const std::string& context)
76 {
78  for (int i = 0; i < 10; i += 3) {
79  vec->m_el.push_back (ElementLink<BVec> ("bvec", i));
80  vec->m_el.back().toPersistent();
81  }
82  for (int i = 1; i < 10; i += 3) {
83  vec->m_el.push_back (ElementLink<BVec> ("bder", i));
84  vec->m_el.back().toPersistent();
85  }
86  CHECK_WITH_CONTEXT( sg->record (vec, key), context);
87  return StatusCode::SUCCESS;
88 }
89 
90 
91 StatusCode remap_test (StoreGateSvc* sg, int istart, MsgStream& log)
92 {
93  ELVec* elv = new ELVec;
94  CHECK_WITH_CONTEXT( sg->record (elv, "elv_remap"), "remap_test");
95 
96  BVec* b1 = new BVec;
97  CHECK_WITH_CONTEXT( sg->record (b1, "b1"), "remap_test");
98  for (int i=0; i < 10; i++) {
99  b1->push_back (new B (i + istart + 100));
100  elv->m_el2.push_back (ElementLink<BVec> ("b1", i));
101  if ((i%2) == 0)
102  elv->m_elv2.push_back (ElementLink<BVec> ("b1", i));
103  else
104  elv->m_elv2.push_back (ElementLink<BVec> (*b1, i));
105  }
106 
107  BVec* b2 = new BVec;
108  CHECK_WITH_CONTEXT( sg->record (b2, "b2"), "remap_test");
109  for (int i=0; i < 10; i++) {
110  b2->push_back (new B (i + istart + 200));
111  elv->m_el2.push_back (ElementLink<BVec> ("b2", i));
112  elv->m_elv2.push_back (ElementLink<BVec> ("b2", i));
113  }
114 
115  elv->m_dl2.push_back (DataLink<BVec> ("b1"));
116  elv->m_dl2.push_back (DataLink<BVec> ("b2"));
117 
118  BVec* b3 = new BVec (SG::VIEW_ELEMENTS);
119  CHECK_WITH_CONTEXT( sg->record (b3, "b3"), "remap_test");
120  b3->insert (b3->end(), b1->begin(), b1->end());
121  b3->insert (b3->end(), b2->begin(), b2->end());
122 
123  sg->remap (ClassID_traits<BVec>::ID(), "b1", "b3", 0);
124  sg->remap (ClassID_traits<BVec>::ID(), "b2", "b3", b1->size());
125 
127  elvcnv.transToPers (&elv->m_elv2, &elv->m_elv2_p, log);
128 
130  elv->m_el2_p.resize (elv->m_el2.size());
131  for (size_t i=0; i < elv->m_el2.size(); i++)
132  elcnv.transToPers (&elv->m_el2[i], &elv->m_el2_p[i], log);
133 
135  elv->m_dl2_p.resize (elv->m_dl2.size());
136  for (size_t i=0; i < elv->m_dl2.size(); i++)
137  dlcnv.transToPers (&elv->m_dl2[i], &elv->m_dl2_p[i], log);
138 
139  return StatusCode::SUCCESS;
140 }
141 
142 
143 } // anonymous namespace
144 
145 
149 StatusCode DMTestWrite::execute(const EventContext& ctx) const
150 {
151  const unsigned int i = ctx.eventID().event_number();
152  // Make one instance of each container.
153  StoreGateSvc* sg = &*evtStore();
154  CHECK( make_vec<BVec> (sg, 10, 0+i, "bvec", name()) );
155  CHECK( make_vec<BDer> (sg, 10, 100+i, "bder", name()) );
156  CHECK( make_vec<DVec> (sg, 10, 200+i, "dvec", name()) );
157  CHECK( make_vec<DDer> (sg, 10, 300+i, "dder", name()) );
158  CHECK( make_elvec (sg, "elvec", name()) );
159  CHECK( remap_test (sg, i, msg()) );
160 
161  return StatusCode::SUCCESS;
162 }
163 
164 
165 } // namespace DMTest
StoreGateSvc::record
StatusCode record(T *p2BRegistered, const TKEY &key)
Record an object with a key.
ElementLinkCnv_p3
Definition: ElementLinkCnv_p3.h:27
CHECK_WITH_CONTEXT
#define CHECK_WITH_CONTEXT(...)
Evaluate an expression and check for errors, with an explicitly specified context name.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:396
ElementLinkCnv_p3.h
This file contains the class definition for the ElementLinkCnv_p3 class.
BVec.h
Class used for testing the new DataVector inheritance scheme.
DataLinkCnv_p1.h
This file contains the class definition for the DataLinkCnv_p1 class and DataLinkVectorCnv_p1 class.
SG::VIEW_ELEMENTS
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Definition: OwnershipPolicy.h:18
ElementLinkVectorCnv_p1
Definition: ElementLinkVectorCnv_p1.h:28
ElementLinkVectorCnv_p1.h
This file contains the class definition for the ElementLinkVectorCnv_p1 class. NOTE: it should be inc...
ELVec.h
Class used for testing new ElementLink.
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:12
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
DMTest::ELVec
For testing ElementLink.
Definition: DataModelTestDataRead/DataModelTestDataRead/ELVec.h:35
ElementLinkCnv_p3::transToPers
void transToPers(const Link_t &trans, PersLink_t &pers, const SG::ThinningCache *cache, MsgStream &log) const
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
StoreGateSvc
The Athena Transient Store API.
Definition: StoreGateSvc.h:128
DataLinkCnv_p1::transToPers
virtual void transToPers(const DLink_t *trans, PersDLink_t *pers, MsgStream &log) const override
DMTest::ELVec::m_el
std::vector< ElementLink< BVec > > m_el
Definition: DataModelTestDataRead/DataModelTestDataRead/ELVec.h:36
lumiFormat.i
int i
Definition: lumiFormat.py:92
beamspotman.n
n
Definition: beamspotman.py:731
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
DMTest::DMTestWrite::execute
virtual StatusCode execute(const EventContext &ctx) const override
Algorithm event processing.
Definition: DMTestWrite.cxx:149
ClassID_traits
Default, invalid implementation of ClassID_traits.
Definition: Control/AthenaKernel/AthenaKernel/ClassID_traits.h:40
DVec.h
Class used for testing the new DataVector inheritance scheme.
BDer.h
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
errorcheck.h
Helpers for checking error return status codes and reporting errors.
DMTestWrite.h
Algorithm to test writing DataVector data.
DMTest::BVec
DataVector< DMTest::B > BVec
A DataVector containing the base class, B.
Definition: DataModelTestDataRead/DataModelTestDataRead/BVec.h:35
StoreGateSvc::remap
void remap(CLID clid, const TKEY &source, const TKEY &target, off_t index_offset)
Declare a remapping.
AthCommonMsg< Gaudi::Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
ElementLinkVectorCnv_p1::transToPers
void transToPers(const LinkVect_t &trans, PersLinkVect_t &pers, const SG::ThinningCache *cache, MsgStream &log) const
StoreGateSvc.h
DDer.h
Class used for testing the new DataVector inheritance scheme.
DMTest::DMTestWrite::DMTestWrite
DMTestWrite(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition: DMTestWrite.cxx:41
DMTest
Definition: B.h:23
DataLinkCnv_p1
Definition: DataLinkCnv_p1.h:23
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37