ATLAS Offline Software
HGTD_RDO_ContainerCnv_p1.cxx
Go to the documentation of this file.
1 
10 
11 #include "GaudiKernel/ISvcLocator.h"
12 #include "GaudiKernel/MsgStream.h"
13 #include "GaudiKernel/StatusCode.h"
18 #include "Identifier/Identifier.h"
19 #include "StoreGate/StoreGateSvc.h"
20 
21 #include <memory>
22 
24  // Do not initialize again:
25  m_is_initialized = true;
26 
27  // Get Storegate, ID helpers, and so on
28  ISvcLocator* svcLocator = Gaudi::svcLocator();
29 
31  StatusCode sc = svcLocator->service("StoreGateSvc", detStore);
32  if (sc.isFailure()) {
33  log << MSG::FATAL << "StoreGate service not found !" << endmsg;
34  return StatusCode::FAILURE;
35  }
36  // get DetectorStore service
37  sc = svcLocator->service("DetectorStore", detStore);
38  if (sc.isFailure()) {
39  log << MSG::FATAL << "DetectorStore service not found !" << endmsg;
40  return StatusCode::FAILURE;
41  }
42  // Get the ID helper from the detector store
43  sc = detStore->retrieve(m_hgtd_idhelper, "HGTD_ID");
44  if (sc.isFailure()) {
45  log << MSG::FATAL << "Could not get HGTD_ID helper !" << endmsg;
46  return StatusCode::FAILURE;
47  }
48 
49  return StatusCode::SUCCESS;
50 }
51 
53  const Trans_t* transient_container, Pers_t* persistent_container,
54  MsgStream& log) {
55 
56  if (!m_is_initialized) {
57  if (this->initialize(log) != StatusCode::SUCCESS) {
58  log << MSG::FATAL << "Could not initialize HGTD_RDO_ContainerCnv_p1 "
59  << endmsg;
60  }
61  }
62 
63  HGTD_RDO_Cnv_p1 rdo_converter;
64  size_t n_collections = transient_container->numberOfCollections();
65  Trans_t::const_iterator container_itr = transient_container->begin();
66 
67  persistent_container->m_collection_separator.resize(n_collections);
68 
69  size_t collection_separator_index_begin = 0;
70  size_t total_n_clusters = 0;
71 
72  for (size_t coll_i = 0; coll_i < n_collections; coll_i++, ++container_itr) {
73  const HGTD_RDO_Collection& collection = (**container_itr);
74 
75  size_t collection_size = collection.size();
76 
77  persistent_container->m_collection_separator.at(coll_i).m_hash_id =
78  collection.identifierHash().value();
79  persistent_container->m_collection_separator.at(coll_i).m_size =
80  collection_size;
81 
82  // continously resize the toal size of vector holding the individual
83  // clusters
84  total_n_clusters += collection_size;
85  persistent_container->m_rdo_list.resize(total_n_clusters);
86 
87  if (log.level() <= MSG::VERBOSE) {
88  log << MSG::VERBOSE << "Reading RDO collections size of "
89  << collection_size << endmsg;
90  }
91 
92  for (size_t rdo_i = 0; rdo_i < collection_size; rdo_i++) {
93  // get pointer to next position in the vector that will be persistified
94  HGTD_RDO_p1* pers_rdo =
95  &((persistent_container->m_rdo_list)
96  .at(rdo_i + collection_separator_index_begin));
97 
98  const HGTD_RDO* trans_rdo =
99  dynamic_cast<const HGTD_RDO*>(collection.at(rdo_i));
100 
101  rdo_converter.transToPers(trans_rdo, pers_rdo, log);
102  }
103  // start next collection at end of previous
104  collection_separator_index_begin += collection.size();
105  }
106 
107  if (log.level() <= MSG::DEBUG) {
108  log << MSG::DEBUG
109  << "Writing HGTD_ClusterContainer to HGTD_ClusterContainer_p1 done"
110  << endmsg;
111  }
112 }
113 
116 
118  const Pers_t* persistent_container, Trans_t* transient_container,
119  MsgStream& log) {
120 
121  if (!m_is_initialized) {
122  if (this->initialize(log) != StatusCode::SUCCESS) {
123  log << MSG::FATAL << "Could not initialize HGTD_RDO_ContainerCnv_p1 "
124  << endmsg;
125  }
126  }
127 
128  std::unique_ptr<HGTD_RDO_Collection> collection = nullptr;
129 
130  HGTD_RDO_Cnv_p1 rdo_converter;
131  size_t collection_separator_index_begin = 0;
132 
133  for (size_t coll_i = 0;
134  coll_i < persistent_container->m_collection_separator.size(); ++coll_i) {
135  const HGTD_RDO_Collection_p1& rdo_coll =
136  persistent_container->m_collection_separator.at(coll_i);
137  // get the identifier for the collection
138  IdentifierHash coll_idhash = IdentifierHash(rdo_coll.m_hash_id);
139  Identifier coll_id = m_hgtd_idhelper->wafer_id(coll_idhash);
140 
141  collection = std::make_unique<HGTD_RDO_Collection>(coll_idhash);
142  collection->setIdentifier(coll_id);
143 
144  unsigned short n_clusters = rdo_coll.m_size;
145  collection->resize(n_clusters);
146  for (unsigned short rdo_i = 0; rdo_i < n_clusters; ++rdo_i) {
147  const HGTD_RDO_p1* pers_rdo =
148  &((persistent_container->m_rdo_list)
149  .at(rdo_i + collection_separator_index_begin));
150 
151  // NOTE I think I have to new it before calling the converter
152  HGTD_RDO* trans_rdo = new HGTD_RDO();
153  rdo_converter.persToTrans(pers_rdo, trans_rdo, log);
154  (*collection).at(rdo_i) = trans_rdo;
155  }
156  collection_separator_index_begin += n_clusters;
157 
158  StatusCode sc =
159  transient_container->addCollection(collection.release(), coll_idhash);
160  if (sc.isFailure()) {
161  throw std::runtime_error("Failed to add collection to ID Container");
162  }
163  }
164 }
165 
168  const Pers_t* persistent_container, MsgStream& log) {
169 
170  if (!m_is_initialized) {
171  if (this->initialize(log) != StatusCode::SUCCESS) {
172  log << MSG::FATAL << "Could not initialize HGTD_RDO_ContainerCnv_p1 "
173  << endmsg;
174  }
175  }
176 
177  std::unique_ptr<Trans_t> transient_container =
178  std::make_unique<Trans_t>(m_hgtd_idhelper->wafer_hash_max());
179 
180  persToTrans(persistent_container, transient_container.get(), log);
181 
182  return (transient_container.release());
183 }
HGTD_RDO_Container_p1
Definition: HGTD_RDO_Container_p1.h:17
HGTD_RDO_Cnv_p1
Definition: HGTD_RDO_Cnv_p1.h:20
HGTD_RDO_ContainerCnv_p1::createTransient
virtual Trans_t * createTransient(const Pers_t *persistent_container, MsgStream &log)
Definition: HGTD_RDO_ContainerCnv_p1.cxx:167
HGTD_RDO_Cnv_p1::persToTrans
void persToTrans(const HGTD_RDO_p1 *pers_obj, HGTD_RDO *trans_obj, MsgStream &log)
Definition: HGTD_RDO_Cnv_p1.cxx:25
python.Constants.FATAL
int FATAL
Definition: Control/AthenaCommon/python/Constants.py:19
HGTD_RDO_Collection_p1::m_size
unsigned short m_size
Definition: HGTD_RDO_Collection_p1.h:29
HGTD_RDO_Cnv_p1.h
Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration.
HGTD_RDO
Definition: HGTD_RDO.h:53
HGTD_RDO_Container
Definition: HGTD_RDO_Container.h:18
HGTD_RDO_Collection
Definition: HGTD_RDO_Collection.h:19
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
HGTD_ID::wafer_id
Identifier wafer_id(int endcap, int layer, int phi_module, int eta_module) const
For a single crystal.
Definition: HGTD_ID.h:287
HGTD_RDO_Container_p1::m_collection_separator
std::vector< HGTD_RDO_Collection_p1 > m_collection_separator
Definition: HGTD_RDO_Container_p1.h:24
HGTD_RDO_ContainerCnv_p1::m_is_initialized
bool m_is_initialized
Definition: HGTD_RDO_ContainerCnv_p1.h:43
StoreGateSvc
The Athena Transient Store API.
Definition: StoreGateSvc.h:128
HGTD_RDO_Collection::setIdentifier
void setIdentifier(Identifier id)
Definition: HGTD_RDO_Collection.h:29
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
HGTD_RDO_Collection_p1.h
Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration.
HGTD_RDO_p1.h
Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration.
ITPConverterFor::Trans_t
TransBase_t Trans_t
Definition: TPConverter.h:40
HGTD_RDO_p1
Definition: HGTD_RDO_p1.h:15
HGTD_RDO_ContainerCnv_p1::initialize
StatusCode initialize(MsgStream &log)
Definition: HGTD_RDO_ContainerCnv_p1.cxx:23
HGTD_ID::wafer_hash_max
size_type wafer_hash_max(void) const
Definition: HGTD_ID.cxx:830
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
DataVector::resize
void resize(size_type sz)
Resizes the collection to the specified number of elements.
HGTD_RDO_ContainerCnv_p1::persToTrans
virtual void persToTrans(const Pers_t *persistent_container, Trans_t *transient_container, MsgStream &log)
Definition: HGTD_RDO_ContainerCnv_p1.cxx:117
HGTD_RDO_Collection::identifierHash
const IdentifierHash & identifierHash() const
Definition: HGTD_RDO_Collection.h:31
HGTD_RDO_Container_p1::m_rdo_list
std::vector< HGTD_RDO_p1 > m_rdo_list
Definition: HGTD_RDO_Container_p1.h:26
HGTD_RDO_ContainerCnv_p1::transToPers
virtual void transToPers(const Trans_t *transient_container, Pers_t *persistent_container, MsgStream &log)
Definition: HGTD_RDO_ContainerCnv_p1.cxx:52
HGTD_ID.h
IdentifierHash::value
unsigned int value(void) const
DEBUG
#define DEBUG
Definition: page_access.h:11
HGTD_RDO_Collection_p1
Definition: HGTD_RDO_Collection_p1.h:14
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
HGTD_RDO_Cnv_p1::transToPers
void transToPers(const HGTD_RDO *trans_obj, HGTD_RDO_p1 *pers_obj, MsgStream &log)
Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration.
Definition: HGTD_RDO_Cnv_p1.cxx:12
python.Constants.VERBOSE
int VERBOSE
Definition: Control/AthenaCommon/python/Constants.py:14
DataVector::at
const T * at(size_type n) const
Access an element, as an rvalue.
HGTD_RDO_ContainerCnv_p1::m_hgtd_idhelper
const HGTD_ID * m_hgtd_idhelper
Definition: HGTD_RDO_ContainerCnv_p1.h:41
IdentifierHash
Definition: IdentifierHash.h:38
StoreGateSvc.h
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
HGTD_RDO_ContainerCnv_p1.h
Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration.
HGTD_RDO_Collection_p1::m_hash_id
IdType_t m_hash_id
Definition: HGTD_RDO_Collection_p1.h:26