ATLAS Offline Software
Pixel1RawDataContainerCnv_p1.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
11 #include "Pixel1RawDataCnv_p1.h"
13 #include "MsgUtil.h"
14 
15 #include "AthAllocators/DataPool.h"
16 
18 {
19 
20  // The transient model has a container holding collections and the
21  // collections hold channels.
22  //
23  // The persistent model flattens this so that the persistent
24  // container has two vectors:
25  // 1) all collections, and
26  // 2) all RDO
27  //
28  // The persistent collections, then only maintain indexes into the
29  // container's vector of all channels.
30  //
31  // So here we loop over all collection and add their channels
32  // to the container's vector, saving the indexes in the
33  // collection.
34 
35  using TRANS = PixelRDO_Container;
36 
37  Pixel1RawDataCnv_p1 chanCnv;
38  TRANS::const_iterator it_Coll = transCont->begin();
39  TRANS::const_iterator it_CollEnd = transCont->end();
40  size_t chanBegin = 0;
41  size_t chanEnd = 0;
42  int numColl = transCont->numberOfCollections();
43  //if(numColl == transCont->fullSize() ) { // let's count how many collections we have:
44  // numColl = 0;
45  // for ( ; it_Coll != it_CollEnd; it_Coll++)
46  // numColl++;
47  // it_Coll = transCont->begin(); // reset the iterator, we used it!
48  //}
49  persCont->m_collections.resize(numColl);
50  MSG_DEBUG(log," Preparing " << persCont->m_collections.size() << "Collections");
51 
52  for (size_t collIndex = 0; it_Coll != it_CollEnd; ++collIndex, ++it_Coll) {
53  // Add in new collection
54  const PixelRDO_Collection& collection = (**it_Coll);
55  chanBegin = chanEnd;
56  chanEnd += collection.size();
57  InDetRawDataCollection_p1& pcollection = persCont->m_collections[collIndex];
58  pcollection.m_id = collection.identify().get_identifier32().get_compact();
59  pcollection.m_hashId = static_cast<size_t> (collection.identifyHash());
60  pcollection.m_begin = chanBegin;
61  pcollection.m_end = chanEnd;
62  // Add in channels
63  persCont->m_rawdata.resize(chanEnd);
64  for (size_t i = 0; i < collection.size(); ++i) {
65  InDetRawData_p1* pchan = &(persCont->m_rawdata[i + chanBegin]);
66  const Pixel1RawData* chan = dynamic_cast<const Pixel1RawData*>(collection[i]);
67  if (not chan) continue;
68  chanCnv.transToPers(chan, pchan, log);
69  }
70  }
71  MSG_DEBUG(log," *** Writing PixelRDO_Container (Pixel1RawData concrete type)");
72 }
73 
75 {
76 
77  // The transient model has a container holding collections and the
78  // collections hold channels.
79  //
80  // The persistent model flattens this so that the persistent
81  // container has two vectors:
82  // 1) all collections, and
83  // 2) all channels
84  //
85  // The persistent collections, then only maintain indexes into the
86  // container's vector of all channels.
87  //
88  // So here we loop over all collection and extract their channels
89  // from the vector.
90 
91 
92  Pixel1RawDataCnv_p1 chanCnv;
93  const size_t numCollections = persCont->m_collections.size();
94  std::vector<size_t> chans_per_collection{};
95  chans_per_collection.reserve(numCollections);
96  size_t totalChannels = 0;
97  //
98  MSG_DEBUG(log, " Reading " << numCollections << "Collections");
99  for (const InDetRawDataCollection_p1& pcoll : persCont->m_collections) {
100  size_t nchans = pcoll.m_end - pcoll.m_begin;
101  chans_per_collection.push_back(nchans);
102  totalChannels += nchans;
103  }
104  DataPool<Pixel1RawData> dataItems;
105  dataItems.reserve(totalChannels);
106 
107  for (size_t icoll = 0; icoll < numCollections; ++icoll) {
108  const InDetRawDataCollection_p1& pcoll = persCont->m_collections[icoll];
109  Identifier collID(pcoll.m_id);
110  IdentifierHash collIDHash(IdentifierHash(pcoll.m_hashId));
111  //
112  PixelRDO_Collection* coll = new PixelRDO_Collection(collIDHash);
113  coll->setIdentifier(collID);
114  coll->clear(SG::VIEW_ELEMENTS);
115  size_t nchans = chans_per_collection[icoll];
116  coll->resize(nchans);
117  // Fill with channels
118  for (size_t ichan = 0; ichan < nchans; ++ ichan) {
119  const InDetRawData_p1* pchan = &(persCont->m_rawdata[ichan + pcoll.m_begin]);
120  Pixel1RawData* chan = dataItems.nextElementPtr();
121  chanCnv.persToTrans(pchan, chan, log);
122  (*coll)[ichan] = chan;
123  }
124 
125  // register the rdo collection in IDC with hash - faster addCollection
126  StatusCode sc = transCont->addCollection(coll, collIDHash);
127  if (sc.isFailure()) {
128  throw std::runtime_error("Failed to add collection to ID Container");
129  }
130  MSG_VERBOSE(log,"AthenaPoolTPCnvIDCont::persToTrans, collection, hash_id/coll id = "
131  << (int) collIDHash << " / " << collID.get_compact() << ", added to Identifiable container.");
132  }
133 
134  MSG_DEBUG(log," *** Reading PixelRDO_Container (Pixel1RawData concrete type)");
135 }
136 
137 //================================================================
139  std::unique_ptr<PixelRDO_Container> trans(std::make_unique<PixelRDO_Container>(m_pixId->wafer_hash_max()));
140  persToTrans(persObj, trans.get(), log);
141  return(trans.release());
142 }
143 
PixelID.h
This is an Identifier helper class for the Pixel subdetector. This class is a factory for creating co...
Pixel1RawDataContainerCnv_p1::transToPers
virtual void transToPers(const PixelRDO_Container *transCont, InDetRawDataContainer_p1 *persCont, MsgStream &log)
Definition: Pixel1RawDataContainerCnv_p1.cxx:17
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
InDetRawDataCollection::identify
virtual Identifier identify() const override final
Pixel1RawDataCnv_p1::transToPers
virtual void transToPers(const Pixel1RawData *transObj, InDetRawData_p1 *persObj, MsgStream &log)
Definition: Pixel1RawDataCnv_p1.cxx:36
InDetRawDataContainer
Definition: InDetRawDataContainer.h:27
InDetRawDataCollection_p1::m_hashId
IdentifierHash::value_type m_hashId
Definition: InDetRawDataCollection_p1.h:36
InDetRawData_p1.h
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
InDetRawDataCollection::identifyHash
virtual IdentifierHash identifyHash() const override final
IdentifiableContainerMT::numberOfCollections
virtual size_t numberOfCollections() const override final
return number of collections
Definition: IdentifiableContainerMT.h:216
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
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
Pixel1RawData.h
InDetRawDataCollection
Definition: InDetRawDataCollection.h:31
Pixel1RawDataContainerCnv_p1.h
InDetRawDataContainer_p1::m_collections
std::vector< InDetRawDataCollection_p1 > m_collections
Definition: InDetRawDataContainer_p1.h:39
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...
InDetRawDataContainer_p1::m_rawdata
std::vector< InDetRawData_p1 > m_rawdata
Definition: InDetRawDataContainer_p1.h:40
DataVector::clear
void clear()
Erase all the elements in the collection.
DataPool.h
Pixel1RawDataContainerCnv_p1::persToTrans
virtual void persToTrans(const InDetRawDataContainer_p1 *persCont, PixelRDO_Container *transCont, MsgStream &log)
Definition: Pixel1RawDataContainerCnv_p1.cxx:74
Pixel1RawDataContainerCnv_p1::createTransient
virtual PixelRDO_Container * createTransient(const InDetRawDataContainer_p1 *persObj, MsgStream &log)
Definition: Pixel1RawDataContainerCnv_p1.cxx:138
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
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
MSG_VERBOSE
#define MSG_VERBOSE(log, x)
Definition: MsgUtil.h:17
Identifier::get_compact
value_type get_compact(void) const
Get the compact id.
Pixel1RawDataCnv_p1::persToTrans
virtual void persToTrans(const InDetRawData_p1 *persObj, Pixel1RawData *transObj, MsgStream &log)
Definition: Pixel1RawDataCnv_p1.cxx:18
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
InDetRawData_p1
Definition: InDetRawData_p1.h:10
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.
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
InDetRawDataContainer_p1
Definition: InDetRawDataContainer_p1.h:31
InDetRawDataCollection_p1.h
Pixel1RawDataCnv_p1.h
Pixel1RawDataContainerCnv_p1::m_pixId
const PixelID * m_pixId
Definition: Pixel1RawDataContainerCnv_p1.h:28
Pixel1RawDataCnv_p1
Definition: Pixel1RawDataCnv_p1.h:25
MsgUtil.h