ATLAS Offline Software
HGTD_ClusterContainerCnv_p1.cxx
Go to the documentation of this file.
1 
12 #include "GaudiKernel/ISvcLocator.h"
13 #include "GaudiKernel/MsgStream.h"
14 #include "GaudiKernel/StatusCode.h"
23 #include "Identifier/Identifier.h"
24 #include "StoreGate/StoreGateSvc.h"
25 #include <memory>
26 
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 }
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.
IdentifierHash::value
unsigned int value() const
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-2024 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
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 ...
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:174
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
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_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: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.
errorcheck.h
Helpers for checking error return status codes and reporting errors.
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-2024 CERN for the benefit of the ATLAS collaboration.
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:27
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
This is a "hash" representation of an Identifier. This encodes a 32 bit index which can be used to lo...
Definition: IdentifierHash.h:25
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:124
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:44
Identifier
Definition: IdentifierFieldParser.cxx:14