ATLAS Offline Software
HGTD_RDO_ContainerCnv_p1.cxx
Go to the documentation of this file.
1 
10 
12 #include "GaudiKernel/ISvcLocator.h"
13 #include "GaudiKernel/MsgStream.h"
14 #include "GaudiKernel/StatusCode.h"
19 #include "Identifier/Identifier.h"
20 #include "StoreGate/StoreGateSvc.h"
21 
22 #include <memory>
23 
25  // Do not initialize again:
26  m_is_initialized = true;
27 
28  // Get Storegate, ID helpers, and so on
29  ISvcLocator* svcLocator = Gaudi::svcLocator();
30 
31  // get DetectorStore service
32  SmartIF<StoreGateSvc> detStore{svcLocator->service("DetectorStore")};
33  CHECK( detStore.isValid() );
34 
35  // Get the ID helper from the detector store
36  CHECK( detStore->retrieve(m_hgtd_idhelper, "HGTD_ID") );
37 
38  return StatusCode::SUCCESS;
39 }
40 
42  const Trans_t* transient_container, Pers_t* persistent_container,
43  MsgStream& log) {
44 
45  if (!m_is_initialized) {
46  if (this->initialize(log) != StatusCode::SUCCESS) {
47  log << MSG::FATAL << "Could not initialize HGTD_RDO_ContainerCnv_p1 "
48  << endmsg;
49  }
50  }
51 
52  HGTD_RDO_Cnv_p1 rdo_converter;
53  size_t n_collections = transient_container->numberOfCollections();
54  Trans_t::const_iterator container_itr = transient_container->begin();
55 
56  persistent_container->m_collection_separator.resize(n_collections);
57 
58  size_t collection_separator_index_begin = 0;
59  size_t total_n_clusters = 0;
60 
61  for (size_t coll_i = 0; coll_i < n_collections; coll_i++, ++container_itr) {
62  const HGTD_RDO_Collection& collection = (**container_itr);
63 
64  size_t collection_size = collection.size();
65 
66  persistent_container->m_collection_separator.at(coll_i).m_hash_id =
67  collection.identifierHash().value();
68  persistent_container->m_collection_separator.at(coll_i).m_size =
69  collection_size;
70 
71  // continously resize the toal size of vector holding the individual
72  // clusters
73  total_n_clusters += collection_size;
74  persistent_container->m_rdo_list.resize(total_n_clusters);
75 
76  if (log.level() <= MSG::VERBOSE) {
77  log << MSG::VERBOSE << "Reading RDO collections size of "
78  << collection_size << endmsg;
79  }
80 
81  for (size_t rdo_i = 0; rdo_i < collection_size; rdo_i++) {
82  // get pointer to next position in the vector that will be persistified
83  HGTD_RDO_p1* pers_rdo =
84  &((persistent_container->m_rdo_list)
85  .at(rdo_i + collection_separator_index_begin));
86 
87  const HGTD_RDO* trans_rdo =
88  dynamic_cast<const HGTD_RDO*>(collection.at(rdo_i));
89 
90  rdo_converter.transToPers(trans_rdo, pers_rdo, log);
91  }
92  // start next collection at end of previous
93  collection_separator_index_begin += collection.size();
94  }
95 
96  if (log.level() <= MSG::DEBUG) {
97  log << MSG::DEBUG
98  << "Writing HGTD_ClusterContainer to HGTD_ClusterContainer_p1 done"
99  << endmsg;
100  }
101 }
102 
105 
107  const Pers_t* persistent_container, Trans_t* transient_container,
108  MsgStream& log) {
109 
110  if (!m_is_initialized) {
111  if (this->initialize(log) != StatusCode::SUCCESS) {
112  log << MSG::FATAL << "Could not initialize HGTD_RDO_ContainerCnv_p1 "
113  << endmsg;
114  }
115  }
116 
117  std::unique_ptr<HGTD_RDO_Collection> collection = nullptr;
118 
119  HGTD_RDO_Cnv_p1 rdo_converter;
120  size_t collection_separator_index_begin = 0;
121 
122  for (size_t coll_i = 0;
123  coll_i < persistent_container->m_collection_separator.size(); ++coll_i) {
124  const HGTD_RDO_Collection_p1& rdo_coll =
125  persistent_container->m_collection_separator.at(coll_i);
126  // get the identifier for the collection
127  IdentifierHash coll_idhash = IdentifierHash(rdo_coll.m_hash_id);
128  Identifier coll_id = m_hgtd_idhelper->wafer_id(coll_idhash);
129 
130  collection = std::make_unique<HGTD_RDO_Collection>(coll_idhash);
131  collection->setIdentifier(coll_id);
132 
133  unsigned short n_clusters = rdo_coll.m_size;
134  collection->resize(n_clusters);
135  for (unsigned short rdo_i = 0; rdo_i < n_clusters; ++rdo_i) {
136  const HGTD_RDO_p1* pers_rdo =
137  &((persistent_container->m_rdo_list)
138  .at(rdo_i + collection_separator_index_begin));
139 
140  // NOTE I think I have to new it before calling the converter
141  HGTD_RDO* trans_rdo = new HGTD_RDO();
142  rdo_converter.persToTrans(pers_rdo, trans_rdo, log);
143  (*collection).at(rdo_i) = trans_rdo;
144  }
145  collection_separator_index_begin += n_clusters;
146 
147  StatusCode sc =
148  transient_container->addCollection(collection.release(), coll_idhash);
149  if (sc.isFailure()) {
150  throw std::runtime_error("Failed to add collection to ID Container");
151  }
152  }
153 }
154 
157  const Pers_t* persistent_container, MsgStream& log) {
158 
159  if (!m_is_initialized) {
160  if (this->initialize(log) != StatusCode::SUCCESS) {
161  log << MSG::FATAL << "Could not initialize HGTD_RDO_ContainerCnv_p1 "
162  << endmsg;
163  }
164  }
165 
166  std::unique_ptr<Trans_t> transient_container =
167  std::make_unique<Trans_t>(m_hgtd_idhelper->wafer_hash_max());
168 
169  persToTrans(persistent_container, transient_container.get(), log);
170 
171  return (transient_container.release());
172 }
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:156
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
IdentifierHash::value
unsigned int value() const
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
HGTD_RDO_Collection::setIdentifier
void setIdentifier(Identifier id)
Definition: HGTD_RDO_Collection.h:29
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-2024 CERN for the benefit of the ATLAS collaboration.
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
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:24
HGTD_ID::wafer_hash_max
size_type wafer_hash_max(void) const
Definition: HGTD_ID.cxx:832
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:106
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:41
errorcheck.h
Helpers for checking error return status codes and reporting errors.
HGTD_ID.h
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
This is a "hash" representation of an Identifier. This encodes a 32 bit index which can be used to lo...
Definition: IdentifierHash.h:25
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-2024 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
Identifier
Definition: IdentifierFieldParser.cxx:14