ATLAS Offline Software
Loading...
Searching...
No Matches
SCT_RawDataContainerCnv_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
6
7
8#include "MsgUtil.h"
10#include "SCT3_RawDataCnv_p1.h"
11
18
19#include <memory>
20
22{
23
24 // The transient model has a container holding collections and the
25 // collections hold channels.
26 //
27 // The persistent model flattens this so that the persistent
28 // container has two vectors:
29 // 1) all collections, and
30 // 2) all RDO
31 //
32 // The persistent collections, then only maintain indexes into the
33 // container's vector of all channels.
34 //
35 // So here we loop over all collection and add their channels
36 // to the container's vector, saving the indexes in the
37 // collection.
38
39 using TRANS = SCT_RDO_Container;
40
41 SCT1_RawDataCnv_p1 chan1Cnv;
42 SCT3_RawDataCnv_p1 chan3Cnv;
43 TRANS::const_iterator it_Coll = transCont->begin();
44 TRANS::const_iterator it_CollEnd = transCont->end();
45 unsigned int collIndex;
46 unsigned int chanBegin = 0;
47 unsigned int chanEnd = 0;
48 int numColl = transCont->numberOfCollections();
49 persCont->m_collections.resize(numColl);
50
51 for (collIndex = 0; it_Coll != it_CollEnd; ++collIndex, ++it_Coll) {
52 // Add in new collection
53 const SCT_RDO_Collection& collection = (**it_Coll);
54 chanBegin = chanEnd;
55 chanEnd += collection.size();
56 InDetRawDataCollection_p1& pcollection = persCont->m_collections[collIndex];
57 pcollection.m_id = collection.identify().get_compact();
58 pcollection.m_hashId = static_cast<unsigned int>(collection.identifyHash());
59 pcollection.m_begin = chanBegin;
60 pcollection.m_end = chanEnd;
61 // Add in channels
62 if (m_type == 1) {
63 persCont->m_rawdata.resize(chanEnd);
64 for (unsigned int i = 0; i < collection.size(); ++i) {
65 InDetRawData_p1* pchan = &(persCont->m_rawdata[i + chanBegin]);
66 const SCT1_RawData* chan = dynamic_cast<const SCT1_RawData*>(collection[i]);
67 if (chan) {
68 chan1Cnv.transToPers(chan, pchan, log);
69 }
70 }
71 } else if (m_type == 3) {
72 persCont->m_sct3data.resize(chanEnd);
73 for (unsigned int i = 0; i < collection.size(); ++i) {
74 SCT3_RawData_p1* pchan = &(persCont->m_sct3data[i + chanBegin]);
75 const SCT3_RawData* chan = dynamic_cast<const SCT3_RawData*>(collection[i]);
76 if (chan) {
77 chan3Cnv.transToPers(chan, pchan, log);
78 }
79 }
80 }
81 }
82}
83
85{
86
87 // The transient model has a container holding collections and the
88 // collections hold channels.
89 //
90 // The persistent model flattens this so that the persistent
91 // container has two vectors:
92 // 1) all collections, and
93 // 2) all channels
94 //
95 // The persistent collections, then only maintain indexes into the
96 // container's vector of all channels.
97 //
98 // So here we loop over all collection and extract their channels
99 // from the vector.
100
101 SCT1_RawDataCnv_p1 chan1Cnv;
102 SCT3_RawDataCnv_p1 chan3Cnv;
103 // check for the type of the contained objects:
104 //
105 if (persCont->m_rawdata.size() !=0 && persCont->m_sct3data.size() != 0) {
106 log << MSG::FATAL << "The collection has mixed SCT1 and SCT3 elements, this is not allowed " << endmsg;
107 }
108 if (persCont->m_rawdata.size() != 0 ) m_type = 1;
109 if (persCont->m_sct3data.size() != 0 ) m_type = 3;
110
111 for (unsigned int icoll = 0; icoll < persCont->m_collections.size(); ++icoll) {
112 // Create trans collection - in NOT owner of SCT_RDO_RawData (SG::VIEW_ELEMENTS)
113 // IDet collection don't have the Ownership policy c'tor
114 const InDetRawDataCollection_p1& pcoll = persCont->m_collections[icoll];
115 Identifier collID(pcoll.m_id);
116 IdentifierHash collIDHash(IdentifierHash(pcoll.m_hashId));
117 std::unique_ptr<SCT_RDO_Collection> coll = std::make_unique<SCT_RDO_Collection>(collIDHash);
118 coll->setIdentifier(collID);
119 unsigned int nchans = pcoll.m_end - pcoll.m_begin;
120 coll->resize(nchans);
121 // Fill with channels
122 for (unsigned int ichan = 0; ichan < nchans; ++ ichan) {
123 if (m_type == 1) {
124 const InDetRawData_p1* pchan = &(persCont->m_rawdata[ichan + pcoll.m_begin]);
125 std::unique_ptr<SCT1_RawData> chan = std::make_unique<SCT1_RawData>();
126 chan1Cnv.persToTrans(pchan, chan.get(), log);
127 (*coll)[ichan] = chan.release();
128 } else if (m_type == 3) {
129 const SCT3_RawData_p1* pchan = &(persCont->m_sct3data[ichan + pcoll.m_begin]);
130 std::unique_ptr<SCT3_RawData> chan = std::make_unique<SCT3_RawData>();
131 chan3Cnv.persToTrans(pchan, chan.get(), log);
132 (*coll)[ichan] = chan.release();
133 }
134 }
135
136 // register the rdo collection in IDC with hash - faster addCollection
137 StatusCode sc = transCont->addCollection(coll.release(), collIDHash);
138 if (sc.isFailure()) {
139 throw std::runtime_error("Failed to add collection to ID Container");
140 }
141 MSG_VERBOSE(log,"AthenaPoolTPCnvIDCont::persToTrans, collection, hash_id/coll id = "
142 << collIDHash.value() << " / " << collID.get_compact() << ", added to Identifiable container.");
143 }
144}
145
146//================================================================
148 std::unique_ptr<SCT_RDO_Container> trans(std::make_unique<SCT_RDO_Container>(m_sctId->wafer_hash_max()));
149 persToTrans(persObj, trans.get(), log);
150 return trans.release();
151}
#define endmsg
static Double_t sc
#define MSG_VERBOSE(log, x)
Definition MsgUtil.h:17
This is an Identifier helper class for the SCT subdetector.
InDetRawDataCollection< SCT_RDORawData > SCT_RDO_Collection
InDetRawDataContainer< InDetRawDataCollection< SCT_RDORawData > > SCT_RDO_Container
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
This is a "hash" representation of an Identifier.
value_type value() const
value_type get_compact() const
Get the compact id.
IdentifierHash::value_type m_hashId
virtual Identifier identify() const override final
virtual IdentifierHash identifyHash() const override final
virtual void transToPers(const SCT1_RawData *transObj, InDetRawData_p1 *persObj, MsgStream &log)
virtual void persToTrans(const InDetRawData_p1 *persObj, SCT1_RawData *transObj, MsgStream &log)
virtual void transToPers(const SCT3_RawData *transObj, SCT3_RawData_p1 *persObj, MsgStream &log)
virtual void persToTrans(const SCT3_RawData_p1 *persObj, SCT3_RawData *transObj, MsgStream &log)
virtual void transToPers(const SCT_RDO_Container *transCont, SCT_RawDataContainer_p1 *persCont, MsgStream &log)
virtual void persToTrans(const SCT_RawDataContainer_p1 *persCont, SCT_RDO_Container *transCont, MsgStream &log)
virtual SCT_RDO_Container * createTransient(const SCT_RawDataContainer_p1 *persObj, MsgStream &log)
std::vector< SCT3_RawData_p1 > m_sct3data
std::vector< InDetRawData_p1 > m_rawdata
std::vector< InDetRawDataCollection_p1 > m_collections