ATLAS Offline Software
Loading...
Searching...
No Matches
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
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);
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
static Double_t sc
#define MSG_VERBOSE(log, x)
Definition MsgUtil.h:17
#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.
value_type get_compact() const
Get the compact id.
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_p1 > m_rawdata
virtual void persToTrans(const InDetRawData_p1 *persObj, Pixel1RawData *transObj, MsgStream &log)
virtual void transToPers(const Pixel1RawData *transObj, InDetRawData_p1 *persObj, MsgStream &log)
virtual void transToPers(const PixelRDO_Container *transCont, InDetRawDataContainer_p1 *persCont, MsgStream &log)
virtual PixelRDO_Container * createTransient(const InDetRawDataContainer_p1 *persObj, MsgStream &log)
virtual void persToTrans(const InDetRawDataContainer_p1 *persCont, PixelRDO_Container *transCont, MsgStream &log)
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts