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