ATLAS Offline Software
Loading...
Searching...
No Matches
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
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);
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
#define endmsg
static Double_t sc
#define MSG_DEBUG(log, x)
Definition MsgUtil.h:15
This is an Identifier helper class for the Pixel subdetector.
InDetRawDataCollection< PixelRDORawData > PixelRDO_Collection
InDetRawDataContainer< InDetRawDataCollection< PixelRDORawData > > PixelRDO_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 resize(size_type sz)
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
void setIdentifier(Identifier id)
std::vector< InDetRawDataCollection_p1 > m_collections
std::vector< InDetRawData_p2 > m_rawdata
virtual void transToPers(const Pixel1RawData *transObj, InDetRawData_p2 *persObj, MsgStream &log)
virtual void persToTrans(const InDetRawData_p2 *persObj, Pixel1RawData *transObj, MsgStream &log)
virtual void persToTrans(const InDetRawDataContainer_p2 *persCont, PixelRDO_Container *transCont, MsgStream &log)
virtual void transToPers(const PixelRDO_Container *transCont, InDetRawDataContainer_p2 *persCont, MsgStream &log)
virtual PixelRDO_Container * createTransient(const InDetRawDataContainer_p2 *persObj, MsgStream &log)
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts