ATLAS Offline Software
Loading...
Searching...
No Matches
HGTD_ClusterContainerCnv_p1.cxx
Go to the documentation of this file.
1
9
12#include "GaudiKernel/ISvcLocator.h"
13#include "GaudiKernel/MsgStream.h"
14#include "GaudiKernel/StatusCode.h"
23#include "Identifier/Identifier.h"
25#include <memory>
26
27StatusCode HGTD_ClusterContainerCnv_p1::initialize(MsgStream& /*log*/) {
28 // Do not initialize again:
29 m_is_initialized = true;
30
31 // Get Storegate, ID helpers, and so on
32 ISvcLocator* svcLocator = Gaudi::svcLocator();
33
34 // get DetectorStore service
35 SmartIF<StoreGateSvc> detStore{svcLocator->service("DetectorStore")};
36 CHECK( detStore.isValid() );
37
38 // Get the ID helper from the detector store
39 CHECK( detStore->retrieve(m_hgtd_idhelper, "HGTD_ID") );
40
41 return StatusCode::SUCCESS;
42}
43
45 const Trans_t* transient_container, Pers_t* persistent_container,
46 MsgStream& log) {
47
48 // The transient model has a container holding collections and the
49 // collections hold channels.
50 //
51 // The persistent model flattens this so that the persistent
52 // container has two vectors:
53 // 1) all collections, and
54 // 2) all PRD
55 //
56 // The persistent collections, then only maintain indexes into the
57 // container's vector of all channels.
58 //
59 // So here we loop over all collection and add their channels
60 // to the container's vector, saving the indexes in the
61 // collection.
62
63 if (!m_is_initialized) {
64 if (this->initialize(log) != StatusCode::SUCCESS) {
65 log << MSG::FATAL << "Could not initialize HGTD_ClusterContainerCnv_p1 "
66 << endmsg;
67 }
68 }
69
70 HGTD_ClusterCnv_p1 cluster_converter;
71 size_t n_collections = transient_container->numberOfCollections();
72 Trans_t::const_iterator container_itr = transient_container->begin();
73
74 persistent_container->m_collection_separator.resize(n_collections);
75
76 size_t collection_separator_index_begin = 0;
77 size_t total_n_clusters = 0;
78
79 for (size_t coll_i = 0; coll_i < n_collections; coll_i++, ++container_itr) {
80 const HGTD_ClusterCollection& collection = (**container_itr);
81
82 size_t collection_size = collection.size();
83
84 persistent_container->m_collection_separator.at(coll_i).m_hash_id =
85 collection.identifyHash().value();
86 persistent_container->m_collection_separator.at(coll_i).m_size =
87 collection_size;
88
89 // continously resize the toal size of vector holding the individual
90 // clusters
91 total_n_clusters += collection_size;
92 persistent_container->m_cluster_list.resize(total_n_clusters);
93
94 if (log.level() <= MSG::VERBOSE) {
95 log << MSG::VERBOSE << "Reading collections with " << collection_size
96 << " PRDs " << endmsg;
97 }
98
99 for (size_t clus_i = 0; clus_i < collection_size; clus_i++) {
100 // get pointer to next position in the vector that will be persistified
101 HGTD_Cluster_p1* pers_clus =
102 &((persistent_container->m_cluster_list)
103 .at(clus_i + collection_separator_index_begin));
104
105 const HGTD_Cluster* trans_clus =
106 dynamic_cast<const HGTD_Cluster*>(collection.at(clus_i));
107
108 cluster_converter.transToPers(trans_clus, pers_clus, log);
109 }
110 // start next collection at end of previous
111 collection_separator_index_begin += collection.size();
112 }
113
114 if (log.level() <= MSG::DEBUG) {
115 log << MSG::DEBUG
116 << "Writing HGTD_ClusterContainer to HGTD_ClusterContainer_p1 done"
117 << endmsg;
118 }
119}
120
123
125 const Pers_t* persistent_container, Trans_t* transient_container,
126 MsgStream& log) {
127
128 HGTD_ClusterCollection* collection = nullptr;
129
130 HGTD_ClusterCnv_p1 cluster_converter;
131
132 size_t collection_separator_index_begin = 0;
133
134 for (size_t coll_i = 0;
135 coll_i < persistent_container->m_collection_separator.size(); ++coll_i) {
136
137 const HGTD_PRD_Collection_p1& prd_coll =
138 persistent_container->m_collection_separator.at(coll_i);
139
140 // get the identifier for the collection
141 IdentifierHash coll_idhash = IdentifierHash(prd_coll.m_hash_id);
142 Identifier coll_id = m_hgtd_idhelper->wafer_id(coll_idhash);
143
144 collection = new HGTD_ClusterCollection(coll_idhash);
145 collection->setIdentifier(coll_id);
146
147 unsigned short n_clusters = prd_coll.m_size;
148 collection->resize(n_clusters);
149
150 for (unsigned short clus_i = 0; clus_i < n_clusters; ++clus_i) {
151 const HGTD_Cluster_p1* pers_cluster =
152 &((persistent_container->m_cluster_list)
153 .at(clus_i + collection_separator_index_begin));
154 // NOTE the cluster is created without setting the detector element!
155 // NOTE if this is needed down the road, it has to be added here!
156 HGTD_Cluster* trans_cluster = new HGTD_Cluster(
157 cluster_converter.createHGTDCluster(pers_cluster, nullptr, log));
158
159 trans_cluster->setHashAndIndex(coll_idhash, clus_i);
160 (*collection).at(clus_i) = trans_cluster;
161 }
162 collection_separator_index_begin += n_clusters;
163
164 StatusCode sc = transient_container->addCollection(collection, coll_idhash);
165 if (sc.isFailure()) {
166 throw std::runtime_error("Failed to add collection to ID Container");
167 }
168 }
169}
170
173
175 const Pers_t* persistent_container, MsgStream& log) {
176
177 if (!m_is_initialized) {
178 if (this->initialize(log) != StatusCode::SUCCESS) {
179 log << MSG::FATAL << "Could not initialize HGTD_ClusterContainerCnv_p1 "
180 << endmsg;
181 }
182 }
183
184 std::unique_ptr<Trans_t> transient_container =
185 std::make_unique<Trans_t>(m_hgtd_idhelper->wafer_hash_max());
186
187 persToTrans(persistent_container, transient_container.get(), log);
188
189 return (transient_container.release());
190}
#define endmsg
Helpers for checking error return status codes and reporting errors.
#define CHECK(...)
Evaluate an expression and check for errors.
Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration.
Trk::PrepRawDataCollection< HGTD_Cluster > HGTD_ClusterCollection
Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration.
Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration.
Trk::PrepRawDataContainer< HGTD_ClusterCollection > HGTD_ClusterContainer
Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration.
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration.
Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration.
Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration.
static Double_t sc
void resize(size_type sz)
const PrepRawDataT * at(size_type n) const
size_type size() const noexcept
HGTD_Cluster createHGTDCluster(const HGTD_Cluster_p1 *pers_obj, const InDetDD::SolidStateDetectorElementBase *delEl, MsgStream &log)
void transToPers(const HGTD_Cluster *, HGTD_Cluster_p1 *, MsgStream &)
virtual void persToTrans(const Pers_t *persistent_container, Trans_t *transient_container, MsgStream &log)
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)
std::vector< HGTD_Cluster_p1 > m_cluster_list
std::vector< HGTD_PRD_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
virtual IdentifierHash identifyHash() const override final
void setHashAndIndex(unsigned short collHash, unsigned short objIndex)
TEMP for testing: might make some classes friends later ...
void initialize()