ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
InnerDetector
InDetEventCnv
InDetEventTPCnv
src
TRT_DriftCircleContainerCnv_p2.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include "
InDetPrepRawData/TRT_DriftCircle.h
"
6
#include "
InDetEventTPCnv/InDetPrepRawData/TRT_DriftCircle_p2.h
"
7
#include "
InDetEventTPCnv/TRT_DriftCircleContainer_p2.h
"
8
#include "
InDetEventTPCnv/InDetPrepRawData/InDetPRD_Collection_p2.h
"
9
#include "
InDetPrepRawData/TRT_DriftCircleContainer.h
"
10
11
#include "Identifier/Identifier.h"
12
#include "
InDetIdentifier/TRT_ID.h
"
13
#include "
InDetEventTPCnv/InDetPrepRawData/TRT_DriftCircleCnv_p2.h
"
14
#include "
InDetEventTPCnv/TRT_DriftCircleContainerCnv_p2.h
"
15
#include "
AthAllocators/DataPool.h
"
16
17
// Gaudi
18
#include "GaudiKernel/ISvcLocator.h"
19
#include "GaudiKernel/Bootstrap.h"
20
#include "GaudiKernel/StatusCode.h"
21
#include "GaudiKernel/Service.h"
22
#include "GaudiKernel/MsgStream.h"
23
24
// Athena
25
#include "
StoreGate/StoreGateSvc.h
"
26
#include "
AthenaKernel/errorcheck.h
"
27
#include "
AthenaBaseComps/AthMsgStreamMacros.h
"
28
#include "
StoreGate/ReadCondHandle.h
"
29
30
// #define IDJUMP 0x400
31
32
33
void
TRT_DriftCircleContainerCnv_p2::transToPers
(
const
InDet::TRT_DriftCircleContainer* transCont,
InDet::TRT_DriftCircleContainer_p2
* persCont, MsgStream &log)
34
{
35
36
// The transient model has a container holding collections and the
37
// collections hold channels.
38
//
39
// The persistent model flattens this so that the persistent
40
// container has two vectors:
41
// 1) all collections, and
42
// 2) all PRD
43
//
44
// The persistent collections, then only maintain indexes into the
45
// container's vector of all channels.
46
//
47
// So here we loop over all collection and add their channels
48
// to the container's vector, saving the indexes in the
49
// collection.
50
51
using
TRANS = InDet::TRT_DriftCircleContainer;
52
53
// this is the id of the latest collection read in
54
// Thisstarts from the base of the TRT identifiers
55
unsigned
int
idLast(0);
56
57
//
58
TRT_DriftCircleCnv_p2
chanCnv;
59
TRANS::const_iterator it_Coll = transCont->begin();
60
TRANS::const_iterator it_CollEnd = transCont->end();
61
unsigned
int
collIndex;
62
unsigned
int
chanBegin = 0;
63
unsigned
int
chanEnd = 0;
64
65
persCont->
m_collections
.resize(transCont->numberOfCollections());
66
67
// to avoid the inside-loop resize
68
int
totSize = 0;
69
//for ( ; it_Coll != it_CollEnd; it_Coll++) {
70
for
( it_Coll=transCont->begin(); it_Coll != it_CollEnd; ++it_Coll) {
71
const
InDet::TRT_DriftCircleCollection& collection = (**it_Coll);
72
totSize+=collection.size();
73
}
74
persCont->
m_rawdata
.resize(totSize);
75
persCont->
m_prdDeltaId
.resize(totSize);
76
77
for
(collIndex = 0, it_Coll=transCont->begin(); it_Coll != it_CollEnd; ++collIndex, ++it_Coll) {
78
// Add in new collection
79
const
InDet::TRT_DriftCircleCollection& collection = (**it_Coll);
80
chanBegin = chanEnd;
81
chanEnd += collection.
size
();
82
InDet::InDetPRD_Collection_p2
& pcollection = persCont->
m_collections
[collIndex];
83
unsigned
int
deltaId = (collection.identifyHash()-idLast);
84
85
pcollection.
m_hashId
= deltaId;
86
idLast = collection.identifyHash();
87
pcollection.
m_size
= collection.size();
88
// Add in channels
89
90
for
(
unsigned
int
i = 0; i < collection.size(); ++i) {
91
InDet::TRT_DriftCircle_p2
* pchan = &(persCont->
m_rawdata
[i + chanBegin]);
92
const
InDet::TRT_DriftCircle
* chan =
static_cast<
const
InDet::TRT_DriftCircle
*
>
(collection[i]);
93
chanCnv.
transToPers
(chan, pchan, log);
94
persCont->
m_prdDeltaId
[i+chanBegin]=chan->identify().get_identifier32().get_compact()-collection.identify().get_identifier32().get_compact();
95
}
96
}
97
}
98
99
void
TRT_DriftCircleContainerCnv_p2::persToTrans
(
const
InDet::TRT_DriftCircleContainer_p2
* persCont, InDet::TRT_DriftCircleContainer* transCont, MsgStream &log)
100
{
101
102
// The transient model has a container holding collections and the
103
// collections hold channels.
104
//
105
// The persistent model flattens this so that the persistent
106
// container has two vectors:
107
// 1) all collections, and
108
// 2) all channels
109
//
110
// The persistent collections, then only maintain indexes into the
111
// container's vector of all channels.
112
//
113
// So here we loop over all collection and extract their channels
114
// from the vector.
115
116
const
InDetDD::TRT_DetElementCollection
* elements(
nullptr
);
117
if
(
m_useDetectorElement
) {
118
SG::ReadCondHandle<InDetDD::TRT_DetElementContainer>
trtDetEleHandle(
m_trtDetEleContKey
);
119
elements = (*trtDetEleHandle)->getElements();
120
if
(not trtDetEleHandle.
isValid
() or elements==
nullptr
) {
121
log << MSG::FATAL <<
m_trtDetEleContKey
.fullKey() <<
" is not available."
<<
endmsg
;
122
return
;
123
}
124
}
125
126
InDet::TRT_DriftCircleCollection* coll =
nullptr
;
127
128
TRT_DriftCircleCnv_p2
chanCnv;
129
unsigned
int
collBegin(0);
130
// this is the id of the latest collection read in
131
// This starts from the base of the TRT identifiers
132
unsigned
int
idLast(0);
133
// if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " Reading " << persCont->m_collections.size() << "Collections" << endmsg;
134
for
(
unsigned
int
icoll = 0; icoll < persCont->
m_collections
.size(); ++icoll) {
135
136
// Create trans collection - in NOT owner of TRT_DriftCircle (SG::VIEW_ELEMENTS)
137
// IDet collection don't have the Ownership policy c'tor
138
const
InDet::InDetPRD_Collection_p2
& pcoll = persCont->
m_collections
[icoll];
139
// idLast+= pcoll.m_idDelta*IDJUMP;
140
// Identifier collID= Identifier(idLast);
141
idLast += pcoll.
m_hashId
;
142
IdentifierHash
collIDHash=
IdentifierHash
((
unsigned
int
) idLast);
143
Identifier
collID =
m_trtId
->layer_id(collIDHash);
144
coll =
new
InDet::TRT_DriftCircleCollection(collIDHash);
145
coll->setIdentifier(collID);
146
unsigned
int
nchans = pcoll.
m_size
;
147
coll->resize(nchans);
148
const
InDetDD::TRT_BaseElement
* detEl = (elements==
nullptr
? nullptr : elements->
getDetectorElement
(collIDHash));
149
// Fill with channels:
150
// This is used to read the vector of errMat
151
// values and lenght of the value are specified in separate vectors
152
// if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "Reading collection with " << nchans << "Channels " << endmsg;
153
for
(
unsigned
int
ichan = 0; ichan < nchans; ++ ichan) {
154
const
InDet::TRT_DriftCircle_p2
* pchan = &(persCont->
m_rawdata
[ichan + collBegin]);
155
Identifier
clusId=
Identifier
(collID.
get_identifier32
().
get_compact
()+persCont->
m_prdDeltaId
[ichan + collBegin]);
156
157
std::vector<Identifier> rdoList(1);
158
rdoList[0]=clusId;
159
160
InDet::TRT_DriftCircle
* chan =
new
InDet::TRT_DriftCircle
161
(chanCnv.
createTRT_DriftCircle
(pchan,
162
clusId,
163
std::move(rdoList),
164
detEl,
165
log));
166
167
// DC bugfix: set hash Id of the drift circle
168
chan->setHashAndIndex(collIDHash,ichan);
169
(*coll)[ichan] = chan;
170
}
171
collBegin += pcoll.
m_size
;
172
173
// register the PRD collection in IDC with hash - faster addCollection
174
StatusCode
sc
= transCont->addCollection(coll, collIDHash);
175
if
(
sc
.isFailure()) {
176
throw
std::runtime_error(
"Failed to add collection to ID Container"
);
177
}
178
// if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "AthenaPoolTPCnvIDCont::persToTrans, collection, hash_id/coll id = " << (int) collIDHash << " / " << collID << ", added to Identifiable container." << endmsg;
179
}
180
181
// if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " *** Reading InDet::TRT_DriftCircleContainer" << endmsg;
182
}
183
184
185
186
//================================================================
187
InDet::TRT_DriftCircleContainer*
TRT_DriftCircleContainerCnv_p2::createTransient
(
const
InDet::TRT_DriftCircleContainer_p2
* persObj, MsgStream& log) {
188
// if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "TRT_DriftCircleContainerCnv_p2::createTransient called " << endmsg;
189
if
(!
m_isInitialized
) {
190
if
(this->
initialize
(log) != StatusCode::SUCCESS) {
191
log << MSG::FATAL <<
"Could not initialize TRT_DriftCircleContainerCnv_p2 "
<<
endmsg
;
192
return
nullptr
;
// if m_trtId not initialized return null pointer instead of dereferencing it later
193
}
194
}
195
std::unique_ptr<InDet::TRT_DriftCircleContainer> trans(std::make_unique<InDet::TRT_DriftCircleContainer>(
m_trtId
->straw_layer_hash_max()));
196
persToTrans
(persObj, trans.get(), log);
197
return
(trans.release());
198
}
199
200
201
StatusCode
TRT_DriftCircleContainerCnv_p2::initialize
(MsgStream&) {
202
203
204
// Do not initialize again:
205
m_isInitialized
=
true
;
206
207
// Get Storegate, ID helpers, and so on
208
SmartIF<StoreGateSvc> detStore{Gaudi::svcLocator()->service(
"DetectorStore"
)};
209
CHECK
( detStore.isValid() );
210
211
// Get the TRT helper from the detector store
212
CHECK
( detStore->retrieve(
m_trtId
,
"TRT_ID"
) );
213
214
CHECK
(
m_trtDetEleContKey
.initialize(
m_useDetectorElement
));
215
216
return
StatusCode::SUCCESS;
217
}
218
219
// Methods for test/TRT_DriftCircleContainerCnv_p2_test.cxx
220
void
TRT_DriftCircleContainerCnv_p2::setIdHelper
(
const
TRT_ID
* trt_id) {
221
m_trtId
= trt_id;
222
}
223
224
void
TRT_DriftCircleContainerCnv_p2::setUseDetectorElement
(
const
bool
useDetectorElement) {
225
m_useDetectorElement
= useDetectorElement;
226
}
227
endmsg
#define endmsg
Definition
AnalysisConfig_Ntuple.cxx:54
AthMsgStreamMacros.h
errorcheck.h
Helpers for checking error return status codes and reporting errors.
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition
Control/AthenaKernel/AthenaKernel/errorcheck.h:422
DataPool.h
InDetPRD_Collection_p2.h
sc
static Double_t sc
Definition
LArPhysWaveHECTool.cxx:37
ReadCondHandle.h
StoreGateSvc.h
TRT_DriftCircleCnv_p2.h
TRT_DriftCircleContainerCnv_p2.h
TRT_DriftCircleContainer.h
TRT_DriftCircleContainer_p2.h
TRT_DriftCircle.h
TRT_DriftCircle_p2.h
TRT_ID.h
This is an Identifier helper class for the TRT subdetector.
DataVector< PrepRawDataT >::size
size_type size() const noexcept
Identifier32::get_compact
value_type get_compact() const
Get the compact id.
Definition
Identifier32.h:47
IdentifierHash
This is a "hash" representation of an Identifier.
Definition
IdentifierHash.h:25
Identifier::get_identifier32
Identifier32 get_identifier32() const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
InDetDD::TRT_BaseElement
Virtual base class of TRT readout elements.
Definition
TRT_BaseElement.h:56
InDetDD::TRT_DetElementCollection
Class to hold collection of TRT detector elements.
Definition
TRT_DetElementCollection.h:26
InDetDD::TRT_DetElementCollection::getDetectorElement
const TRT_BaseElement * getDetectorElement(const IdentifierHash &hash) const
Definition
TRT_DetElementCollection.cxx:9
InDet::InDetPRD_Collection_p2
Definition
InDetPRD_Collection_p2.h:11
InDet::InDetPRD_Collection_p2::m_hashId
unsigned short m_hashId
Definition
InDetPRD_Collection_p2.h:35
InDet::InDetPRD_Collection_p2::m_size
unsigned short m_size
Definition
InDetPRD_Collection_p2.h:40
InDet::TRT_DriftCircleContainer_p2
Definition
TRT_DriftCircleContainer_p2.h:21
InDet::TRT_DriftCircleContainer_p2::m_prdDeltaId
std::vector< unsigned short > m_prdDeltaId
Definition
TRT_DriftCircleContainer_p2.h:29
InDet::TRT_DriftCircleContainer_p2::m_collections
std::vector< InDet::InDetPRD_Collection_p2 > m_collections
Definition
TRT_DriftCircleContainer_p2.h:26
InDet::TRT_DriftCircleContainer_p2::m_rawdata
std::vector< InDet::TRT_DriftCircle_p2 > m_rawdata
Definition
TRT_DriftCircleContainer_p2.h:27
InDet::TRT_DriftCircle_p2
Definition
TRT_DriftCircle_p2.h:20
InDet::TRT_DriftCircle
Definition
TRT_DriftCircle.h:32
SG::ReadCondHandle
Definition
ReadCondHandle.h:40
SG::ReadCondHandle::isValid
bool isValid()
Definition
ReadCondHandle.h:205
TRT_DriftCircleCnv_p2
Definition
TRT_DriftCircleCnv_p2.h:25
TRT_DriftCircleCnv_p2::createTRT_DriftCircle
InDet::TRT_DriftCircle createTRT_DriftCircle(const InDet::TRT_DriftCircle_p2 *persObj, Identifier clusId, std::vector< Identifier > &&rdoList, const InDetDD::TRT_BaseElement *detEl, MsgStream &log)
Definition
TRT_DriftCircleCnv_p2.cxx:19
TRT_DriftCircleCnv_p2::transToPers
void transToPers(const InDet::TRT_DriftCircle *transObj, InDet::TRT_DriftCircle_p2 *persObj, MsgStream &log)
Definition
TRT_DriftCircleCnv_p2.cxx:55
TRT_DriftCircleContainerCnv_p2::initialize
StatusCode initialize(MsgStream &log)
Definition
TRT_DriftCircleContainerCnv_p2.cxx:201
TRT_DriftCircleContainerCnv_p2::m_trtId
const TRT_ID * m_trtId
Definition
TRT_DriftCircleContainerCnv_p2.h:44
TRT_DriftCircleContainerCnv_p2::setIdHelper
void setIdHelper(const TRT_ID *trt_id)
Definition
TRT_DriftCircleContainerCnv_p2.cxx:220
TRT_DriftCircleContainerCnv_p2::m_trtDetEleContKey
SG::ReadCondHandleKey< InDetDD::TRT_DetElementContainer > m_trtDetEleContKey
Definition
TRT_DriftCircleContainerCnv_p2.h:46
TRT_DriftCircleContainerCnv_p2::m_useDetectorElement
bool m_useDetectorElement
Definition
TRT_DriftCircleContainerCnv_p2.h:47
TRT_DriftCircleContainerCnv_p2::createTransient
virtual InDet::TRT_DriftCircleContainer * createTransient(const InDet::TRT_DriftCircleContainer_p2 *persObj, MsgStream &log)
Definition
TRT_DriftCircleContainerCnv_p2.cxx:187
TRT_DriftCircleContainerCnv_p2::transToPers
virtual void transToPers(const InDet::TRT_DriftCircleContainer *transCont, InDet::TRT_DriftCircleContainer_p2 *persCont, MsgStream &log)
Definition
TRT_DriftCircleContainerCnv_p2.cxx:33
TRT_DriftCircleContainerCnv_p2::m_isInitialized
bool m_isInitialized
Definition
TRT_DriftCircleContainerCnv_p2.h:45
TRT_DriftCircleContainerCnv_p2::persToTrans
virtual void persToTrans(const InDet::TRT_DriftCircleContainer_p2 *persCont, InDet::TRT_DriftCircleContainer *transCont, MsgStream &log)
Definition
TRT_DriftCircleContainerCnv_p2.cxx:99
TRT_DriftCircleContainerCnv_p2::setUseDetectorElement
void setUseDetectorElement(const bool useDetectorElement)
Definition
TRT_DriftCircleContainerCnv_p2.cxx:224
TRT_ID
This is an Identifier helper class for the TRT subdetector.
Definition
TRT_ID.h:84
Identifier
Definition
IdentifierFieldParser.cxx:14
initialize
void initialize()
Definition
run_EoverP.cxx:894
Generated on
for ATLAS Offline Software by
1.17.0