ATLAS Offline Software
Loading...
Searching...
No Matches
TRT_LoLumRawDataContainerCnv_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
12#include "MsgUtil.h"
13
15
17{
18
19 // The transient model has a container holding collections and the
20 // collections hold channels.
21 //
22 // The persistent model flattens this so that the persistent
23 // container has two vectors:
24 // 1) all collections, and
25 // 2) all RDO
26 //
27 // The persistent collections, then only maintain indexes into the
28 // container's vector of all channels.
29 //
30 // So here we loop over all collection and add their channels
31 // to the container's vector, saving the indexes in the
32 // collection.
33
34 using TRANS = TRT_RDO_Container;
35
37 TRANS::const_iterator it_Coll = transCont->begin();
38 TRANS::const_iterator it_CollEnd = transCont->end();
39 unsigned int collIndex;
40 unsigned int chanBegin = 0;
41 unsigned int 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 (collIndex = 0; it_Coll != it_CollEnd; ++collIndex, ++it_Coll) {
53 // Add in new collection
54 const TRT_RDO_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 = (unsigned int) collection.identifyHash();
60 pcollection.m_begin = chanBegin;
61 pcollection.m_end = chanEnd;
62 MSG_VERBOSE(log,"Writing collection number " << collIndex << " with hash" << pcollection.m_hashId);
63 // Add in channels
64 persCont->m_rawdata.resize(chanEnd);
65 for (unsigned int i = 0; i < collection.size(); ++i) {
66 InDetRawData_p2* pchan = &(persCont->m_rawdata[i + chanBegin]);
67 const TRT_LoLumRawData* chan = dynamic_cast<const TRT_LoLumRawData*>(collection[i]);
68 if (nullptr == chan) throw std::runtime_error("TRT_LoLumRawDataContainerCnv_p2::transToPers: *** UNABLE TO DYNAMIC CAST TO TRT_LoLumRawData");
69 chanCnv.transToPers(chan, pchan, log);
70 }
71 }
72 MSG_DEBUG(log," *** Writing TRT_RDO_Container (TRT_LoLumRawData concrete type)");
73}
74
76{
77
78 // The transient model has a container holding collections and the
79 // collections hold channels.
80 //
81 // The persistent model flattens this so that the persistent
82 // container has two vectors:
83 // 1) all collections, and
84 // 2) all channels
85 //
86 // The persistent collections, then only maintain indexes into the
87 // container's vector of all channels.
88 //
89 // So here we loop over all collection and extract their channels
90 // from the vector.
91
92 // create Data Pool
94 // It resizes as needed .
95 // The max number of straws is 350847 but assume
96 // that we do not have 100% occupancy
97 dataItems.reserve(180000);
98 TRT_RDO_Collection* coll = nullptr;
100 MSG_DEBUG(log," Reading " << persCont->m_collections.size() << "Collections");
101 for (unsigned int icoll = 0; icoll < persCont->m_collections.size(); ++icoll) {
102
103 // Create trans collection - in NOT owner of TRT_RDO_RawData (SG::VIEW_ELEMENTS)
104 // IDet collection don't have the Ownership policy c'tor
105 const InDetRawDataCollection_p1& pcoll = persCont->m_collections[icoll];
106 Identifier collID(pcoll.m_id);
107 IdentifierHash collIDHash(pcoll.m_hashId);
108 coll = new TRT_RDO_Collection(IdentifierHash(collIDHash));
109 coll->setIdentifier(collID);
110 coll->clear (SG::VIEW_ELEMENTS);
111 unsigned int nchans = pcoll.m_end - pcoll.m_begin;
112 coll->resize(nchans);
113 // Fill with channels
114 for (unsigned int ichan = 0; ichan < nchans; ++ ichan) {
115 const InDetRawData_p2* pchan = &(persCont->m_rawdata[ichan + pcoll.m_begin]);
116 //ask the pool for the next pointer
117 TRT_LoLumRawData* chan = dataItems.nextElementPtr();
118 //set the payload
119 *chan = TRT_LoLumRawData();
120 chanCnv.persToTrans(pchan, chan, log);
121 (*coll)[ichan] = chan;
122 }
123
124 // register the rdo collection in IDC with hash - faster addCollection
125 StatusCode sc = transCont->addCollection(coll, collIDHash);
126 if (sc.isFailure()) {
127 throw std::runtime_error("Failed to add collection to ID Container");
128 }
129 MSG_VERBOSE(log,"AthenaPoolTPCnvIDCont::persToTrans, collection, hash_id/coll id = "
130 << (int) collIDHash << " / " << collID.get_compact() << ", added to Identifiable container.");
131 }
132
133 MSG_DEBUG(log," *** Reading TRT_RDO_Container (TRT_LoLumRawData concrete type)");
134}
135
136//================================================================
138 std::unique_ptr<TRT_RDO_Container> trans(std::make_unique<TRT_RDO_Container>(m_trtId->straw_layer_hash_max()));
139 persToTrans(persObj, trans.get(), log);
140 return(trans.release());
141}
142
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 TRT subdetector.
InDetRawDataCollection< TRT_RDORawData > TRT_RDO_Collection
InDetRawDataContainer< InDetRawDataCollection< TRT_RDORawData > > TRT_RDO_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_p2 > m_rawdata
virtual void transToPers(const TRT_LoLumRawData *transObj, InDetRawData_p2 *persObj, MsgStream &log)
virtual void persToTrans(const InDetRawData_p2 *persObj, TRT_LoLumRawData *transObj, MsgStream &log)
virtual void transToPers(const TRT_RDO_Container *transCont, InDetRawDataContainer_p2 *persCont, MsgStream &log)
virtual void persToTrans(const InDetRawDataContainer_p2 *persCont, TRT_RDO_Container *transCont, MsgStream &log)
virtual TRT_RDO_Container * createTransient(const InDetRawDataContainer_p2 *persObj, MsgStream &log)
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts