ATLAS Offline Software
Loading...
Searching...
No Matches
TgcCoinDataContainerCnv_p3.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
13
14// Gaudi
15#include "GaudiKernel/ISvcLocator.h"
16#include "GaudiKernel/Bootstrap.h"
17#include "GaudiKernel/StatusCode.h"
18#include "GaudiKernel/Service.h"
19#include "GaudiKernel/MsgStream.h"
20
21// Athena
25
26
28 // Do not initialize again:
29 m_isInitialized=true;
30
31 // get DetectorStore service
32 SmartIF<StoreGateSvc> detStore{Gaudi::svcLocator()->service("DetectorStore")};
33 CHECK( detStore.isValid() );
34
35 // Get the helper from the detector store
36 CHECK( detStore->retrieve(m_TgcId) );
37
38 CHECK( m_eventCnvTool.retrieve() );
39 log << MSG::DEBUG << "Converter initialized." << endmsg;
40 return StatusCode::SUCCESS;
41}
42
44{
45
46 // The transient model has a container holding collections and the
47 // collections hold channels.
48 //
49 // The persistent model flattens this so that the persistent
50 // container has two vectors:
51 // 1) all collections, and
52 // 2) all RDO
53 //
54 // The persistent collections, then only maintain indexes into the
55 // container's vector of all channels.
56 //
57 // So here we loop over all collection and add their channels
58 // to the container's vector, saving the indexes in the
59 // collection.
60
63
64 TgcCoinDataCnv_p3 chanCnv;
65 TRANS::const_iterator it_Coll = transCont->begin();
66 TRANS::const_iterator it_CollEnd = transCont->end();
67 unsigned int collIndex;
68 unsigned int chanBegin = 0;
69 unsigned int chanEnd = 0;
70 int numColl = transCont->numberOfCollections();
71 // if(numColl == transCont->hashFunc().max() ) { // let's count how many collections we have:
72 // numColl = 0;
73 // for ( ; it_Coll != it_CollEnd; it_Coll++)
74 // numColl++;
75 // it_Coll = transCont->begin(); // reset the iterator, we used it!
76 // }
77 persCont->m_collections.resize(numColl); log << MSG::DEBUG << " Preparing " << persCont->m_collections.size() << "Collections" << endmsg;
78
79 for (collIndex = 0; it_Coll != it_CollEnd; ++collIndex, ++it_Coll) {
80 // Add in new collection
81 log << MSG::DEBUG << " New collection" << endmsg;
82 const Muon::TgcCoinDataCollection& collection = (**it_Coll);
83 chanBegin = chanEnd;
84 chanEnd += collection.size();
85 Muon::MuonCoinDataCollection_p1& pcollection = persCont->m_collections[collIndex];
86 pcollection.m_id = collection.identify().get_identifier32().get_compact();
87 pcollection.m_hashId = (unsigned int) collection.identifyHash();
88 pcollection.m_begin = chanBegin;
89 pcollection.m_end = chanEnd;
90 // Add in channels
91 persCont->m_CoinData.resize(chanEnd);
92 for (unsigned int i = 0; i < collection.size(); ++i) {
93 const Muon::TgcCoinData* chan = collection[i];
94 persCont->m_CoinData[i + chanBegin] = toPersistent((CONV**)nullptr, chan, log );
95 }
96 }
97 log << MSG::DEBUG << " *** Writing TgcCoinDataContainer ***" << endmsg;
98}
99
101{
102
103 // The transient model has a container holding collections and the
104 // collections hold channels.
105 //
106 // The persistent model flattens this so that the persistent
107 // container has two vectors:
108 // 1) all collections, and
109 // 2) all channels
110 //
111 // The persistent collections, then only maintain indexes into the
112 // container's vector of all channels.
113 //
114 // So here we loop over all collection and extract their channels
115 // from the vector.
116
117
118 Muon::TgcCoinDataCollection* coll = nullptr;
119
120 TgcCoinDataCnv_p3 chanCnv;
122
123 log << MSG::DEBUG << " Reading " << persCont->m_collections.size() << "Collections" << endmsg;
124 for (unsigned int icoll = 0; icoll < persCont->m_collections.size(); ++icoll) {
125
126 // Create trans collection - is NOT owner of TgcCoinData (SG::VIEW_ELEMENTS)
127 // IDet collection don't have the Ownership policy c'tor
128 const Muon::MuonCoinDataCollection_p1& pcoll = persCont->m_collections[icoll];
129 Identifier collID(Identifier(pcoll.m_id));
130 IdentifierHash collIDHash(IdentifierHash(pcoll.m_hashId));
131 coll = new Muon::TgcCoinDataCollection(collIDHash);
132 coll->setIdentifier(Identifier(pcoll.m_id));
133 unsigned int nchans = pcoll.m_end - pcoll.m_begin;
134 coll->resize(nchans);
135
136 // Fill with channels
137 for (unsigned int ichan = 0; ichan < nchans; ++ ichan) {
138 const TPObjRef pchan = persCont->m_CoinData[ichan + pcoll.m_begin];
139 Muon::TgcCoinData* chan = dynamic_cast<Muon::TgcCoinData*>(createTransFromPStore((CONV**)nullptr, pchan, log ) );
140 if( (chan->type()!=Muon::TgcCoinData::TYPE_TRACKLET_EIFI && (!chan->isInner() )) && (chan->type()!=Muon::TgcCoinData::TYPE_UNKNOWN) ) {
141 const MuonGM::TgcReadoutElement * deOut = getReadOutElement(Identifier(chan->channelIdOut()));
142 chan->m_detElOut = deOut;
143 }
144 if((chan->type()==Muon::TgcCoinData::TYPE_TRACKLET || chan->type()==Muon::TgcCoinData::TYPE_HIPT ||
145 chan->type()==Muon::TgcCoinData::TYPE_TRACKLET_EIFI)&& !chan->isInner() ) {
146 const MuonGM::TgcReadoutElement * deIn = getReadOutElement(Identifier(chan->channelIdIn()));
147 chan->m_detElIn = deIn;
148 }
149 else {
150 chan->m_detElIn = nullptr;
151 }
152 (*coll)[ichan] = chan;
153 }
154
155 // register the rdo collection in IDC with hash - faster addCollection
156 StatusCode sc = transCont->addCollection(coll, collIDHash);
157 if (sc.isFailure()) {
158 throw std::runtime_error("Failed to add collection to ID Container");
159 }
160 if (log.level() <= MSG::DEBUG) {
161 log << MSG::DEBUG << "AthenaPoolTPCnvIDCont::persToTrans, collection, hash_id/coll id = " << (int) collIDHash << " / " <<
162 collID.get_compact() << ", added to Identifiable container." << endmsg;
163 }
164 }
165
166 log << MSG::DEBUG << " *** Reading TgcCoinDataContainer" << endmsg;
167}
168
169
170
171//================================================================
173{
174 if(!m_isInitialized) {
175 if (this->initialize(log) != StatusCode::SUCCESS) {
176 log << MSG::FATAL << "Could not initialize TgcCoinDataContainerCnv_p3 " << endmsg;
177 return nullptr;
178 }
179 }
180 std::unique_ptr<Muon::TgcCoinDataContainer> trans(new Muon::TgcCoinDataContainer(m_TgcId->module_hash_max()));
181 persToTrans(persObj, trans.get(), log);
182 return(trans.release());
183}
184
185
187 const Trk::ITrkEventCnvTool* cnv_tool = m_eventCnvTool->getCnvTool(id);
188 if (!cnv_tool) return nullptr;
189 return dynamic_cast<const MuonGM::TgcReadoutElement*>(cnv_tool->getDetectorElement(id));
190}
#define endmsg
Helpers for checking error return status codes and reporting errors.
#define CHECK(...)
Evaluate an expression and check for errors.
static Double_t sc
void resize(size_type sz)
size_type size() const noexcept
Common base class for all TP converters, specialized for a given transient type.
Definition TPConverter.h:37
CNV::Trans_t * createTransFromPStore(CNV **cnv, const TPObjRef &ref, MsgStream &log) const
TPObjRef toPersistent(CNV **cnv, const typename CNV::TransBase_t *transObj, MsgStream &log) const
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.
A TgcReadoutElement corresponds to a single TGC chamber; therefore typically a TGC station contains s...
unsigned int m_id
Identifier of this collection.
unsigned int m_begin
Begin index into master collection.
unsigned int m_end
End index into master collection.
unsigned int m_hashId
Hash Identifier of this collection (write this one as well, so we don't rely on the IdHelper for it)
IdentifierHash identifyHash() const
std::vector< Muon::MuonCoinDataCollection_p1 > m_collections
ToolHandle< Trk::IEventCnvSuperTool > m_eventCnvTool
virtual void persToTrans(const PERS *persCont, TRANS *transCont, MsgStream &log)
virtual Muon::TgcCoinDataContainer * createTransient(const Muon::MuonCoinDataContainer_p1 *persObj, MsgStream &log)
const MuonGM::TgcReadoutElement * getReadOutElement(const Identifier &id) const
virtual void transToPers(const TRANS *transCont, PERS *persCont, MsgStream &log)
This class is an object reference used in Athena persistent data model.
Definition TPObjRef.h:20
virtual const Trk::TrkDetElementBase * getDetectorElement(const Identifier &id, const IdentifierHash &idHash) const =0
Returns the detectorElement associated with this Identifier & Hash.
MuonCoinDataCollection< TgcCoinData > TgcCoinDataCollection
MuonCoinDataContainer< TgcCoinDataCollection > TgcCoinDataContainer
void initialize()