ATLAS Offline Software
Pixel1RawDataContainerCnv_p2.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
11 #include "Pixel1RawDataCnv_p2.h"
13 #include "MsgUtil.h"
14 
15 #include "AthAllocators/DataPool.h"
16 
17 
19 {
20 
21  // The transient model has a container holding collections and the
22  // collections hold channels.
23  //
24  // The persistent model flattens this so that the persistent
25  // container has two vectors:
26  // 1) all collections, and
27  // 2) all RDO
28  //
29  // The persistent collections, then only maintain indexes into the
30  // container's vector of all channels.
31  //
32  // So here we loop over all collection and add their channels
33  // to the container's vector, saving the indexes in the
34  // collection.
35 
36  using TRANS = PixelRDO_Container;
37 
38  Pixel1RawDataCnv_p2 chanCnv;
39  TRANS::const_iterator it_Coll = transCont->begin();
40  TRANS::const_iterator it_CollEnd = transCont->end();
41  size_t chanBegin = 0;
42  size_t chanEnd = 0;
43  size_t numColl = transCont->numberOfCollections();
44 
45  persCont->m_collections.resize(numColl);
46  MSG_DEBUG(log, " Preparing " << persCont->m_collections.size() << " Collections" );
47 
48  for (size_t collIndex = 0; it_Coll != it_CollEnd; ++collIndex, ++it_Coll) {
49  // Add in new collection
50  const PixelRDO_Collection& collection = (**it_Coll);
51  chanBegin = chanEnd;
52  chanEnd += collection.size();
53  if(collIndex >= numColl) log << MSG::ERROR << "Accessing collIndex " << collIndex << "/" << numColl << endmsg;
54  InDetRawDataCollection_p1& pcollection = persCont->m_collections[collIndex];
55 
56  pcollection.m_id = collection.identify().get_identifier32().get_compact();
57  pcollection.m_hashId = static_cast<size_t> (collection.identifyHash());
58  pcollection.m_begin = chanBegin;
59  pcollection.m_end = chanEnd;
60  // Add in channels
61  persCont->m_rawdata.resize(chanEnd);
62  for (size_t i = 0; i < collection.size(); ++i) {
63  InDetRawData_p2* pchan = &(persCont->m_rawdata[i + chanBegin]);
64  const Pixel1RawData* chan = dynamic_cast<const Pixel1RawData*>(collection[i]);
65  if (nullptr == chan) {
66  throw std::runtime_error(
67  "Pixel1RawDataContainerCnv_p2::transToPers: *** UNABLE TO "
68  "DYNAMIC CAST TO Pixel1RawData");
69  }
70  chanCnv.transToPers(chan, pchan, log);
71  }
72  }
73  MSG_DEBUG(log," *** Writing PixelRDO_Container (Pixel1RawData concrete type)");
74 }
75 
77 {
78 
79  // The transient model has a container holding collections and the
80  // collections hold channels.
81  //
82  // The persistent model flattens this so that the persistent
83  // container has two vectors:
84  // 1) all collections, and
85  // 2) all channels
86  //
87  // The persistent collections, then only maintain indexes into the
88  // container's vector of all channels.
89  //
90  // So here we loop over all collection and extract their channels
91  // from the vector.
92  Pixel1RawDataCnv_p2 chanCnv;
93  //
94  const size_t numCollections = persCont->m_collections.size();
95  std::vector<size_t> chans_per_collection{};
96  chans_per_collection.reserve(numCollections);
97  size_t totalChannels = 0;
98  //
99  MSG_DEBUG(log, " Reading " << numCollections << "Collections");
100  for (const InDetRawDataCollection_p1& pcoll : persCont->m_collections) {
101  size_t nchans = pcoll.m_end - pcoll.m_begin;
102  chans_per_collection.push_back(nchans);
103  totalChannels += nchans;
104  }
105  DataPool<Pixel1RawData> dataItems;
106  dataItems.reserve(totalChannels);
107 
108  for (size_t icoll = 0; icoll < numCollections; ++icoll) {
109  const InDetRawDataCollection_p1& pcoll = persCont->m_collections[icoll];
110  Identifier collID(pcoll.m_id);
111  IdentifierHash collIDHash(IdentifierHash(pcoll.m_hashId));
112  //
113  PixelRDO_Collection* coll = new PixelRDO_Collection(collIDHash);
114  coll->setIdentifier(collID);
115  coll->clear(SG::VIEW_ELEMENTS);
116  size_t nchans = chans_per_collection[icoll];
117  coll->resize(nchans);
118  // Fill with channels
119  for (size_t ichan = 0; ichan < nchans; ++ichan) {
120  const InDetRawData_p2* pchan =
121  &(persCont->m_rawdata[ichan + pcoll.m_begin]);
122  Pixel1RawData* chan = dataItems.nextElementPtr();
123  chanCnv.persToTrans(pchan, chan, log);
124  (*coll)[ichan] = chan;
125  }
126 
127  StatusCode sc = transCont->addCollection(coll, collIDHash);
128  if (sc.isFailure()) {
129  throw std::runtime_error(
130  "Failed to add collection to ID Container");
131  }
132  }
133 
134  MSG_DEBUG(log,
135  " *** Reading PixelRDO_Container (Pixel1RawData concrete type)");
136 }
137 
138 //================================================================
140  std::unique_ptr<PixelRDO_Container> trans(std::make_unique<PixelRDO_Container>(m_pixId->wafer_hash_max()));
141  persToTrans(persObj, trans.get(), log);
142  return(trans.release());
143 }
144 
PixelID.h
This is an Identifier helper class for the Pixel subdetector. This class is a factory for creating co...
PixelRDO_Container
InDetRawDataContainer< InDetRawDataCollection< PixelRDORawData > > PixelRDO_Container
Definition: PixelRDO_Container.h:25
InDetRawDataCollection::setIdentifier
void setIdentifier(Identifier id)
DataPool::reserve
void reserve(unsigned int size)
Set the desired capacity.
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:300
SG::VIEW_ELEMENTS
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Definition: OwnershipPolicy.h:18
InDetRawDataContainer_p2
Definition: InDetRawDataContainer_p2.h:31
Pixel1RawDataCnv_p2::transToPers
virtual void transToPers(const Pixel1RawData *transObj, InDetRawData_p2 *persObj, MsgStream &log)
Definition: Pixel1RawDataCnv_p2.cxx:25
InDetRawDataCollection::identify
virtual Identifier identify() const override final
InDetRawDataContainer
Definition: InDetRawDataContainer.h:27
InDetRawDataCollection_p1::m_hashId
IdentifierHash::value_type m_hashId
Definition: InDetRawDataCollection_p1.h:36
Pixel1RawDataContainerCnv_p2::persToTrans
virtual void persToTrans(const InDetRawDataContainer_p2 *persCont, PixelRDO_Container *transCont, MsgStream &log)
Definition: Pixel1RawDataContainerCnv_p2.cxx:76
InDetRawDataCollection_p1::m_end
unsigned int m_end
Definition: InDetRawDataCollection_p1.h:42
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
Pixel1RawDataContainerCnv_p2::transToPers
virtual void transToPers(const PixelRDO_Container *transCont, InDetRawDataContainer_p2 *persCont, MsgStream &log)
Definition: Pixel1RawDataContainerCnv_p2.cxx:18
InDetRawDataCollection::identifyHash
virtual IdentifierHash identifyHash() const override final
InDetRawDataContainer_p2::m_collections
std::vector< InDetRawDataCollection_p1 > m_collections
Definition: InDetRawDataContainer_p2.h:39
InDetRawData_p2.h
IdentifiableContainerMT::numberOfCollections
virtual size_t numberOfCollections() const override final
return number of collections
Definition: IdentifiableContainerMT.h:216
Pixel1RawDataContainerCnv_p2::m_pixId
const PixelID * m_pixId
Definition: Pixel1RawDataContainerCnv_p2.h:28
Identifier32::get_compact
value_type get_compact(void) const
Get the compact id.
Definition: Identifier32.h:171
lumiFormat.i
int i
Definition: lumiFormat.py:92
PixelRDO_Collection.h
ReadCellNoiseFromCool.chan
chan
Definition: ReadCellNoiseFromCool.py:52
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
Pixel1RawData.h
InDetRawDataCollection
Definition: InDetRawDataCollection.h:31
Pixel1RawData
Definition: Pixel1RawData.h:23
IdentifiableContainerMT::end
const_iterator end() const
return const_iterator for end of container
Definition: IdentifiableContainerMT.h:242
IdentifiableContainerMT::begin
const_iterator begin() const
return const_iterator for first entry
Definition: IdentifiableContainerMT.h:236
DataPool::nextElementPtr
pointer nextElementPtr()
obtain the next available element in pool by pointer pool is resized if its limit has been reached On...
DataVector::clear
void clear()
Erase all the elements in the collection.
Pixel1RawDataContainerCnv_p2.h
DataPool.h
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
PixelRDO_Collection
InDetRawDataCollection< PixelRDORawData > PixelRDO_Collection
Definition: PixelRDO_Collection.h:20
InDetRawData_p2
Definition: InDetRawData_p2.h:10
InDetRawDataCollection_p1::m_begin
unsigned int m_begin
Definition: InDetRawDataCollection_p1.h:39
PixelID::wafer_hash_max
size_type wafer_hash_max(void) const
Definition: PixelID.cxx:912
PixelRDO_Container.h
Pixel1RawDataContainerCnv_p2::createTransient
virtual PixelRDO_Container * createTransient(const InDetRawDataContainer_p2 *persObj, MsgStream &log)
Definition: Pixel1RawDataContainerCnv_p2.cxx:139
Pixel1RawDataCnv_p2
Definition: Pixel1RawDataCnv_p2.h:22
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
MSG_DEBUG
#define MSG_DEBUG(log, x)
Definition: MsgUtil.h:15
DataPool
a typed memory pool that saves time spent allocation small object. This is typically used by containe...
Definition: DataPool.h:47
Pixel1RawDataCnv_p2::persToTrans
virtual void persToTrans(const InDetRawData_p2 *persObj, Pixel1RawData *transObj, MsgStream &log)
Definition: Pixel1RawDataCnv_p2.cxx:16
Pixel1RawDataCnv_p2.h
IdentifierHash
Definition: IdentifierHash.h:38
Identifier::get_identifier32
Identifier32 get_identifier32(void) const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
InDetRawDataContainer_p2::m_rawdata
std::vector< InDetRawData_p2 > m_rawdata
Definition: InDetRawDataContainer_p2.h:40
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
InDetRawDataCollection_p1.h
MsgUtil.h