ATLAS Offline Software
Loading...
Searching...
No Matches
SCT_RawDataContainerCnv_p4.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7
8#include "MsgUtil.h"
10#include "SCT3_RawDataCnv_p4.h"
11
18
19#include <memory>
21
23{
24
39
40 using TRANS = SCT_RDO_Container;
41
42 SCT1_RawDataCnv_p2 chan1Cnv;
44 TRANS::const_iterator it_Coll = transCont->begin();
45 TRANS::const_iterator it_CollEnd = transCont->end();
46 unsigned int collIndex;
47 unsigned int chanBegin = 0;
48 unsigned int chanEnd = 0;
49 int numColl = transCont->numberOfCollections();
50 persCont->m_collections.resize(numColl);
51
54
55 for (collIndex = 0; it_Coll != it_CollEnd; ++collIndex, ++it_Coll) {
57 const SCT_RDO_Collection& collection = (**it_Coll);
58 chanBegin = chanEnd;
59 chanEnd += collection.size();
60 InDetRawDataCollection_p1& pcollection = persCont->m_collections[collIndex];
61 pcollection.m_id = collection.identify().get_identifier32().get_compact();
62 pcollection.m_hashId = static_cast<unsigned int>(collection.identifyHash());
63 pcollection.m_begin = chanBegin;
64 pcollection.m_end = chanEnd;
66 if (m_type == 1) {
67 persCont->m_rawdata.resize(chanEnd);
68 for (unsigned int i = 0; i < collection.size(); ++i) {
69 InDetRawData_p2* pchan = &(persCont->m_rawdata[i + chanBegin]);
70 const SCT1_RawData* chan = dynamic_cast<const SCT1_RawData*>(collection[i]);
71 if (nullptr == chan) throw std::runtime_error("SCT_RawDataContainerCnv_p4::transToPers: *** UNABLE TO DYNAMIC CAST TO SCT1_RawData");
72 chan1Cnv.transToPers(chan, pchan, log);
73 }
74 } else if (m_type == 3) {
75 persCont->m_sct3data.resize(chanEnd);
76 for (unsigned int i = 0; i < collection.size(); ++i) {
77 SCT3_RawData_p4* pchan = &(persCont->m_sct3data[i + chanBegin]);
78 const SCT3_RawData* chan = dynamic_cast<const SCT3_RawData*>(collection[i]);
79 if (nullptr == chan) throw std::runtime_error("SCT_RawDataContainerCnv_p4::transToPers: *** UNABLE TO DYNAMIC CAST TO SCT3_RawData");
80 chan3Cnv.transToPers(chan, pchan, log);
81 }
82 }
83 }
84}
85
87{
101
102 SCT1_RawDataCnv_p2 chan1Cnv;
103 SCT3_RawDataCnv_p4 chan3Cnv(m_sctId);
105 if (persCont->m_rawdata.size() != 0 && persCont->m_sct3data.size() != 0) {
106 log << MSG::FATAL
107 << "The collection has mixed SCT1 and SCT3 elements, this is not "
108 "allowed "
109 << endmsg;
110 }
111 if (persCont->m_rawdata.size() != 0){
112 m_type = 1;
113 }
114 if (persCont->m_sct3data.size() != 0){
115 m_type = 3;
116 }
117
118 const size_t numCollections = persCont->m_collections.size();
119 std::vector<size_t> chans_per_collection{};
120 chans_per_collection.reserve(numCollections);
121 size_t totalChannels = 0;
122 for (unsigned int icoll = 0; icoll < numCollections; ++icoll) {
123 const InDetRawDataCollection_p1& pcoll = persCont->m_collections[icoll];
124 unsigned int nchans = pcoll.m_end - pcoll.m_begin;
125 chans_per_collection.push_back(nchans);
126 totalChannels += nchans;
127 }
128
129 if (m_type == 1) {
130 DataPool<SCT1_RawData> dataItems;
131 dataItems.reserve(totalChannels);
132 for (unsigned int icoll = 0; icoll < numCollections; ++icoll) {
133 const InDetRawDataCollection_p1& pcoll = persCont->m_collections[icoll];
134 Identifier collID(pcoll.m_id);
135 chan3Cnv.setWaferId(collID);
136 IdentifierHash collIDHash(pcoll.m_hashId);
137 //
138 std::unique_ptr<SCT_RDO_Collection> coll =
139 std::make_unique<SCT_RDO_Collection>(IdentifierHash(collIDHash));
140 coll->setIdentifier(collID);
141 coll->clear(SG::VIEW_ELEMENTS);
142 unsigned int nchans = chans_per_collection[icoll];
143 coll->resize(nchans);
144 //
145 for (unsigned int ichan = 0; ichan < nchans; ++ichan) {
146 const InDetRawData_p2* pchan =
147 &(persCont->m_rawdata[ichan + pcoll.m_begin]);
148 SCT1_RawData* chan = dataItems.nextElementPtr();
149 chan1Cnv.persToTrans(pchan, chan, log);
150 (*coll)[ichan] = chan;
151 }
152 StatusCode sc = transCont->addCollection(coll.release(), collIDHash);
153 if (sc.isFailure()) {
154 throw std::runtime_error("Failed to add collection to ID Container");
155 }
156 }
157 } // type 1
158 else if (m_type == 3) {
159 DataPool<SCT3_RawData> dataItems;
160 dataItems.prepareToAdd(totalChannels);
161 for (unsigned int icoll = 0; icoll < numCollections; ++icoll) {
162 const InDetRawDataCollection_p1& pcoll = persCont->m_collections[icoll];
163 Identifier collID(pcoll.m_id);
164 chan3Cnv.setWaferId(collID);
165 IdentifierHash collIDHash(pcoll.m_hashId);
166 //
167 std::unique_ptr<SCT_RDO_Collection> coll =
168 std::make_unique<SCT_RDO_Collection>(IdentifierHash(collIDHash));
169 coll->setIdentifier(collID);
170 coll->clear(SG::VIEW_ELEMENTS);
171 unsigned int nchans = chans_per_collection[icoll];
172 coll->resize(nchans);
173 //
174 for (unsigned int ichan = 0; ichan < nchans; ++ichan) {
175 const SCT3_RawData_p4* pchan =
176 &(persCont->m_sct3data[ichan + pcoll.m_begin]);
177 SCT3_RawData* chan = dataItems.nextElementPtr();
178 chan3Cnv.persToTrans(pchan, chan, log);
179 (*coll)[ichan] = chan;
180 }
181 StatusCode sc = transCont->addCollection(coll.release(), collIDHash);
182 if (sc.isFailure()) {
183 throw std::runtime_error("Failed to add collection to ID Container");
184 }
185 }
186 } // type 3
187}
188
189//================================================================
191 std::unique_ptr<SCT_RDO_Container> trans(std::make_unique<SCT_RDO_Container>(m_sctId->wafer_hash_max()));
192 persToTrans(persObj, trans.get(), log);
193 return trans.release();
194}
#define endmsg
static Double_t sc
This is an Identifier helper class for the SCT subdetector.
InDetRawDataCollection< SCT_RDORawData > SCT_RDO_Collection
InDetRawDataContainer< InDetRawDataCollection< SCT_RDORawData > > SCT_RDO_Container
a typed memory pool that saves time spent allocation small object.
Definition DataPool.h:63
void reserve(unsigned int size)
Set the desired capacity.
pointer nextElementPtr()
obtain the next available element in pool by pointer pool is resized if its limit has been reached On...
void prepareToAdd(unsigned int size)
Prepare to add cached elements.
size_type size() const noexcept
const_iterator end() const
return const_iterator for end of container
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
value_type get_compact() const
Get the compact id.
This is a "hash" representation of an Identifier.
Identifier32 get_identifier32() const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
IdentifierHash::value_type m_hashId
virtual Identifier identify() const override final
virtual IdentifierHash identifyHash() const override final
virtual void transToPers(const SCT1_RawData *transObj, InDetRawData_p2 *persObj, MsgStream &log)
virtual void persToTrans(const InDetRawData_p2 *persObj, SCT1_RawData *transObj, MsgStream &log)
void setWaferId(const Identifier waferId)
virtual void transToPers(const SCT3_RawData *transObj, SCT3_RawData_p4 *persObj, MsgStream &log)
virtual void persToTrans(const SCT3_RawData_p4 *persObj, SCT3_RawData *transObj, MsgStream &log)
S.Oda, Oct 2018 replace unsigned int by unsigned short for for the presampling samples for Overlay MC...
virtual void transToPers(const SCT_RDO_Container *transCont, SCT_RawDataContainer_p4 *persCont, MsgStream &log)
virtual SCT_RDO_Container * createTransient(const SCT_RawDataContainer_p4 *persObj, MsgStream &log)
virtual void persToTrans(const SCT_RawDataContainer_p4 *persCont, SCT_RDO_Container *transCont, MsgStream &log)
Persistent represenation of an SCT_RawDataContainer.
std::vector< InDetRawDataCollection_p1 > m_collections
std::vector< InDetRawData_p2 > m_rawdata
std::vector< SCT3_RawData_p4 > m_sct3data
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts