ATLAS Offline Software
Loading...
Searching...
No Matches
HGTD_RDO_ContainerCnv_p1.cxx
Go to the documentation of this file.
1
8
10
12#include "GaudiKernel/ISvcLocator.h"
13#include "GaudiKernel/MsgStream.h"
14#include "GaudiKernel/StatusCode.h"
19#include "Identifier/Identifier.h"
21
22#include <memory>
23
24StatusCode HGTD_RDO_ContainerCnv_p1::initialize(MsgStream& /*log*/) {
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 = dynamic_cast<const HGTD_RDO*>(collection.at(rdo_i));
88 if (not trans_rdo){
89 continue;
90 }
91
92 rdo_converter.transToPers(trans_rdo, pers_rdo, log);
93 }
94 // start next collection at end of previous
95 collection_separator_index_begin += collection.size();
96 }
97
98 if (log.level() <= MSG::DEBUG) {
99 log << MSG::DEBUG
100 << "Writing HGTD_ClusterContainer to HGTD_ClusterContainer_p1 done"
101 << endmsg;
102 }
103}
104
107
109 const Pers_t* persistent_container, Trans_t* transient_container,
110 MsgStream& log) {
111
112 if (!m_is_initialized) {
113 if (this->initialize(log) != StatusCode::SUCCESS) {
114 log << MSG::FATAL << "Could not initialize HGTD_RDO_ContainerCnv_p1 "
115 << endmsg;
116 }
117 }
118
119 std::unique_ptr<HGTD_RDO_Collection> collection = nullptr;
120
121 HGTD_RDO_Cnv_p1 rdo_converter;
122 size_t collection_separator_index_begin = 0;
123
124 for (size_t coll_i = 0;
125 coll_i < persistent_container->m_collection_separator.size(); ++coll_i) {
126 const HGTD_RDO_Collection_p1& rdo_coll =
127 persistent_container->m_collection_separator.at(coll_i);
128 // get the identifier for the collection
129 IdentifierHash coll_idhash = IdentifierHash(rdo_coll.m_hash_id);
130 Identifier coll_id = m_hgtd_idhelper->wafer_id(coll_idhash);
131
132 collection = std::make_unique<HGTD_RDO_Collection>(coll_idhash);
133 collection->setIdentifier(coll_id);
134
135 unsigned short n_clusters = rdo_coll.m_size;
136 collection->resize(n_clusters);
137 for (unsigned short rdo_i = 0; rdo_i < n_clusters; ++rdo_i) {
138 const HGTD_RDO_p1* pers_rdo =
139 &((persistent_container->m_rdo_list)
140 .at(rdo_i + collection_separator_index_begin));
141
142 // NOTE I think I have to new it before calling the converter
143 HGTD_RDO* trans_rdo = new HGTD_RDO();
144 rdo_converter.persToTrans(pers_rdo, trans_rdo, log);
145 (*collection).at(rdo_i) = trans_rdo;
146 }
147 collection_separator_index_begin += n_clusters;
148
149 StatusCode sc =
150 transient_container->addCollection(collection.release(), coll_idhash);
151 if (sc.isFailure()) {
152 throw std::runtime_error("Failed to add collection to ID Container");
153 }
154 }
155}
156
159 const Pers_t* persistent_container, MsgStream& log) {
160
161 if (!m_is_initialized) {
162 if (this->initialize(log) != StatusCode::SUCCESS) {
163 log << MSG::FATAL << "Could not initialize HGTD_RDO_ContainerCnv_p1 "
164 << endmsg;
165 }
166 }
167
168 std::unique_ptr<Trans_t> transient_container =
169 std::make_unique<Trans_t>(m_hgtd_idhelper->wafer_hash_max());
170
171 persToTrans(persistent_container, transient_container.get(), log);
172
173 return (transient_container.release());
174}
#define endmsg
Helpers for checking error return status codes and reporting errors.
#define CHECK(...)
Evaluate an expression and check for errors.
Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration.
Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration.
Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration.
Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration.
static Double_t sc
const T * at(size_type n) const
Access an element, as an rvalue.
size_type size() const noexcept
Returns the number of elements in the collection.
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.
void persToTrans(const HGTD_RDO_p1 *pers_obj, HGTD_RDO *trans_obj, MsgStream &log)
const IdentifierHash & identifierHash() const
virtual void transToPers(const Trans_t *transient_container, Pers_t *persistent_container, MsgStream &log)
virtual Trans_t * createTransient(const Pers_t *persistent_container, MsgStream &log)
StatusCode initialize(MsgStream &log)
virtual void persToTrans(const Pers_t *persistent_container, Trans_t *transient_container, MsgStream &log)
std::vector< HGTD_RDO_p1 > m_rdo_list
std::vector< HGTD_RDO_Collection_p1 > m_collection_separator
virtual size_t numberOfCollections() const override final
return number of collections
virtual StatusCode addCollection(const T *coll, IdentifierHash hashId) override final
insert collection into container with id hash if IDC should not take ownership of collection,...
const_iterator begin() const
return const_iterator for first entry
This is a "hash" representation of an Identifier.
value_type value() const
void initialize()