ATLAS Offline Software
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"
9 #include "SCT1_RawDataCnv_p2.h"
10 #include "SCT3_RawDataCnv_p4.h"
11 
12 #include "InDetIdentifier/SCT_ID.h"
18 
19 #include <memory>
20 #include "AthAllocators/DataPool.h"
21 
23 {
24 
39 
40  using TRANS = SCT_RDO_Container;
41 
42  SCT1_RawDataCnv_p2 chan1Cnv;
43  SCT3_RawDataCnv_p4 chan3Cnv(m_sctId);
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 
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 }
SCT_ID.h
This is an Identifier helper class for the SCT subdetector. This class is a factory for creating comp...
SCT3_RawDataCnv_p4.h
SCT3_RawData_p4
S.Oda, Oct 2018 replace unsigned int by unsigned short for for the presampling samples for Overlay MC...
Definition: SCT3_RawData_p4.h:14
SCT3_RawDataCnv_p4::persToTrans
virtual void persToTrans(const SCT3_RawData_p4 *persObj, SCT3_RawData *transObj, MsgStream &log)
Definition: SCT3_RawDataCnv_p4.cxx:16
InDetRawDataCollection::setIdentifier
void setIdentifier(Identifier id)
python.Constants.FATAL
int FATAL
Definition: Control/AthenaCommon/python/Constants.py:19
IdentifiableContainerMT::addCollection
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,...
Definition: IdentifiableContainerMT.h:297
SCT_RawDataContainer_p4::m_collections
std::vector< InDetRawDataCollection_p1 > m_collections
Definition: SCT_RawDataContainer_p4.h:30
SG::VIEW_ELEMENTS
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Definition: OwnershipPolicy.h:18
SCT_RawDataContainerCnv_p4.h
SCT1_RawDataCnv_p2::transToPers
virtual void transToPers(const SCT1_RawData *transObj, InDetRawData_p2 *persObj, MsgStream &log)
Definition: SCT1_RawDataCnv_p2.cxx:26
SCT_RawDataContainerCnv_p4::m_sctId
const SCT_ID * m_sctId
Definition: SCT_RawDataContainerCnv_p4.h:29
InDetRawDataCollection::identify
virtual Identifier identify() const override final
Identifier::get_identifier32
Identifier32 get_identifier32() const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
DataPool::reserve
void reserve(unsigned int size)
Set the desired capacity.
SCT_RawDataContainerCnv_p4::m_type
int m_type
Definition: SCT_RawDataContainerCnv_p4.h:30
InDetRawDataContainer
Definition: InDetRawDataContainer.h:27
InDetRawDataCollection_p1::m_hashId
IdentifierHash::value_type m_hashId
Definition: InDetRawDataCollection_p1.h:36
SCT1_RawDataCnv_p2::persToTrans
virtual void persToTrans(const InDetRawData_p2 *persObj, SCT1_RawData *transObj, MsgStream &log)
Definition: SCT1_RawDataCnv_p2.cxx:18
InDetRawDataCollection_p1::m_end
unsigned int m_end
Definition: InDetRawDataCollection_p1.h:42
Identifier32::get_compact
value_type get_compact() const
Get the compact id.
Definition: Identifier32.h:44
InDetRawDataCollection_p1::m_id
Identifier32::value_type m_id
Definition: InDetRawDataCollection_p1.h:32
InDetRawDataCollection_p1
Definition: InDetRawDataCollection_p1.h:13
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
InDetRawDataCollection::identifyHash
virtual IdentifierHash identifyHash() const override final
DataPool::nextElementPtr
pointer nextElementPtr()
obtain the next available element in pool by pointer pool is resized if its limit has been reached On...
SCT_RawDataContainerCnv_p4::createTransient
virtual SCT_RDO_Container * createTransient(const SCT_RawDataContainer_p4 *persObj, MsgStream &log)
Definition: SCT_RawDataContainerCnv_p4.cxx:190
SCT_RDO_Container.h
IdentifiableContainerMT::numberOfCollections
virtual size_t numberOfCollections() const override final
return number of collections
Definition: IdentifiableContainerMT.h:213
SCT3_RawData.h
DataPool::prepareToAdd
void prepareToAdd(unsigned int size)
Prepare to add cached elements.
lumiFormat.i
int i
Definition: lumiFormat.py:85
SCT3_RawDataCnv_p4
Definition: SCT3_RawDataCnv_p4.h:22
ReadCellNoiseFromCool.chan
chan
Definition: ReadCellNoiseFromCool.py:52
SCT3_RawData
Definition: SCT3_RawData.h:24
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
InDetRawDataCollection
Definition: InDetRawDataCollection.h:31
SCT3_RawDataCnv_p4::transToPers
virtual void transToPers(const SCT3_RawData *transObj, SCT3_RawData_p4 *persObj, MsgStream &log)
Definition: SCT3_RawDataCnv_p4.cxx:35
IdentifiableContainerMT::end
const_iterator end() const
return const_iterator for end of container
Definition: IdentifiableContainerMT.h:239
IdentifiableContainerMT::begin
const_iterator begin() const
return const_iterator for first entry
Definition: IdentifiableContainerMT.h:233
SCT_RawDataContainer_p4::m_rawdata
std::vector< InDetRawData_p2 > m_rawdata
Definition: SCT_RawDataContainer_p4.h:31
DataVector::clear
void clear()
Erase all the elements in the collection.
DataPool.h
SCT_RawDataContainerCnv_p4::persToTrans
virtual void persToTrans(const SCT_RawDataContainer_p4 *persCont, SCT_RDO_Container *transCont, MsgStream &log)
Definition: SCT_RawDataContainerCnv_p4.cxx:86
DataVector::resize
void resize(size_type sz)
Resizes the collection to the specified number of elements.
defineDB.ichan
int ichan
Definition: JetTagCalibration/share/defineDB.py:28
SCT_ID::wafer_hash_max
size_type wafer_hash_max(void) const
Definition: SCT_ID.cxx:645
InDetRawData_p2
Definition: InDetRawData_p2.h:10
InDetRawDataCollection_p1::m_begin
unsigned int m_begin
Definition: InDetRawDataCollection_p1.h:39
SCT_RDO_Collection.h
SCT_RawDataContainer_p4::m_sct3data
std::vector< SCT3_RawData_p4 > m_sct3data
Definition: SCT_RawDataContainer_p4.h:32
SCT_RDO_Container
InDetRawDataContainer< InDetRawDataCollection< SCT_RDORawData > > SCT_RDO_Container
Definition: SCT_RDO_Container.h:23
SCT_RawDataContainer_p4
Persistent represenation of an SCT_RawDataContainer.
Definition: SCT_RawDataContainer_p4.h:24
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
SCT1_RawData
Definition: SCT1_RawData.h:27
SCT_RawDataContainerCnv_p4::transToPers
virtual void transToPers(const SCT_RDO_Container *transCont, SCT_RawDataContainer_p4 *persCont, MsgStream &log)
Definition: SCT_RawDataContainerCnv_p4.cxx:22
DataPool
a typed memory pool that saves time spent allocation small object. This is typically used by containe...
Definition: DataPool.h:63
SCT1_RawDataCnv_p2
Definition: SCT1_RawDataCnv_p2.h:22
SCT3_RawData_p4.h
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
SCT1_RawDataCnv_p2.h
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
InDetRawDataCollection_p1.h
SCT3_RawDataCnv_p4::setWaferId
void setWaferId(const Identifier waferId)
Definition: SCT3_RawDataCnv_p4.h:27
Identifier
Definition: IdentifierFieldParser.cxx:14
MsgUtil.h