ATLAS Offline Software
Loading...
Searching...
No Matches
PixelGangedClusterAmbiguitiesCnv_p1.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
12
13// Gaudi
14#include "GaudiKernel/ISvcLocator.h"
15#include "GaudiKernel/Bootstrap.h"
16#include "GaudiKernel/StatusCode.h"
17#include "GaudiKernel/Service.h"
18#include "GaudiKernel/MsgStream.h"
19
20// Athena
22
23
25 m_storeGate("StoreGateSvc", "PixelGangedClusterAmbiguitiesCnv_p1"),
27{}
28
29
31(const InDet::PixelGangedClusterAmbiguities* transObj, InDet::PixelGangedClusterAmbiguities_p1* persObj, MsgStream &log)
32{
33// if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << " *** Writing InDet::PixelGangedClusterAmbiguities" << endmsg;
34
35 if(!m_isInitialized) {
36 if (this->initialize(log) != StatusCode::SUCCESS) {
37 log << MSG::FATAL << "Could not initialize PixelGangedClusterAmbiguitiesCnv_p1 " << endmsg;
38 }
39 }
40
41 if (transObj->empty()) {
42 if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "No ganged pixels in this event. PixelAmbiMap has size 0. This happens often on single particle files." << endmsg;
43 }
44 else {
45 InDet::PixelGangedClusterAmbiguities::const_iterator itr = transObj->begin();
46 InDet::PixelGangedClusterAmbiguities::const_iterator itrE = transObj->end();
47 InDet::PixelGangedClusterAmbiguities::const_iterator previous_itr = transObj->begin();
48
50 StatusCode sc = m_storeGate->retrieve(dh, dhEnd);
51 if (sc.isFailure()){
52 log << MSG::WARNING <<"No containers found!"<< endmsg;
53 return;
54 }
55
56 const InDet::SiCluster* ExamplePixelCluster = itr->first;
57
58 // only need to check in which container ONE PixelCluster in the map is:
59 // there is ONE ambiguity map per CONTAINER
60 persObj->m_pixelClusterContainerName = "";
61 const InDet::SiCluster* pixelCluster = ExamplePixelCluster;
62 unsigned int index = pixelCluster->getHashAndIndex().objIndex(); // prd index within collection
63 IdentifierHash idHash = pixelCluster->getHashAndIndex().collHash(); // idHash of collection
64
65 // loop over dhs
66 for ( ; dh!=dhEnd; ++dh ) {
67 const auto *coll = dh->indexFindPtr(idHash); //matching collection
68 // does coll exist?
69 // check prd exists in collection
70 // check idhaspointer value the same.
71 if ( (coll!=nullptr)&& (coll->size()>index) && (pixelCluster==(*coll)[index]) ){
72 // okay, so we found the correct PRD in the container.
73 // Now set the name to the container correctly
74 persObj->m_pixelClusterContainerName = dh.key();
75 break; //exit loop, name found
76 }
77 }
78
79 if (persObj->m_pixelClusterContainerName.empty()) {
80 log << MSG::ERROR<<"Could not find matching PRD container for this PixelCluster! Dumping PRD: "<<*pixelCluster<<endmsg;
81 }
82
83 std::vector<unsigned int> uintvector;
84 const InDet::SiCluster* keyPixelCluster(nullptr);
85 const InDet::SiCluster* gangedPixelCluster(nullptr);
86 for( ; itr != itrE ; ++itr ) {
87
88 // for clarity assign the elements
89 keyPixelCluster = itr->first;
90 const InDet::SiCluster* keyPreviousPixelCluster = previous_itr->first;
91 gangedPixelCluster = itr->second;
92
93 if (keyPixelCluster == keyPreviousPixelCluster) uintvector.push_back(gangedPixelCluster->getHashAndIndex().hashAndIndex());
94 else if (keyPixelCluster != keyPreviousPixelCluster)
95 {
96 persObj->m_ambiguityMap.emplace_back(keyPreviousPixelCluster->getHashAndIndex().hashAndIndex(), uintvector);
97 uintvector.clear();
98 uintvector.push_back(gangedPixelCluster->getHashAndIndex().hashAndIndex());
99 }
100 previous_itr = itr;
101
102 }
103 if (keyPixelCluster)[[likely]]{
104 // pushback the last one!
105 persObj->m_ambiguityMap.emplace_back(keyPixelCluster->getHashAndIndex().hashAndIndex(), uintvector);
106 }
107 }
108}
109
110void PixelGangedClusterAmbiguitiesCnv_p1::persToTrans(const InDet::PixelGangedClusterAmbiguities_p1* persObj, InDet::PixelGangedClusterAmbiguities* transObj, MsgStream &log)
111{
112
113 if(!m_isInitialized) {
114 if (this->initialize(log) != StatusCode::SUCCESS) {
115 log << MSG::FATAL << "Could not initialize PixelGangedClusterAmbiguitiesCnv_p1 " << endmsg;
116 }
117 }
118
119 if (persObj->m_pixelClusterContainerName.empty())
120 {
121 if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "Name of the pixel cluster container is empty. Most likely cause: input is a single particle file and there were no pixel ambiguities." << endmsg;
122 } else
123 {
124 const InDet::PixelClusterContainer* pCC(nullptr);
125 if (m_storeGate->retrieve(pCC, persObj->m_pixelClusterContainerName).isFailure()) {
126 log << MSG::FATAL << "PixelGangedClusterAmbiguitiesCnv_p1: Cannot retrieve "
127 << persObj->m_pixelClusterContainerName << endmsg;
128 }
129
130 const InDet::PixelCluster* keyPixelCluster(nullptr);
131 const InDet::PixelCluster* gangedPixelCluster(nullptr);
132
133 for (const std::pair<uint32_t, std::vector<uint32_t> >& mapElement : persObj->m_ambiguityMap)
134 {
135 for (uint32_t elt : mapElement.second)
136 {
137 IdentContIndex keyIdentContIndex(mapElement.first);
138 IdentContIndex gangedIdentContIndex(elt);
139 for (InDet::PixelClusterContainer::const_iterator contItr = pCC->begin();
140 contItr != pCC->end(); ++contItr)
141 {
142 const InDet::PixelClusterCollection* coll = (*contItr);
143 if (coll->identifyHash() == keyIdentContIndex.collHash())
144 {
145 keyPixelCluster = coll->at(keyIdentContIndex.objIndex());
146 gangedPixelCluster = coll->at(gangedIdentContIndex.objIndex());
147 transObj->insert(std::pair<const InDet::PixelCluster*, const InDet::PixelCluster*>(keyPixelCluster,gangedPixelCluster));
148// std::cout << "TPCnv Read "<< keyPixelCluster->getHashAndIndex().hashAndIndex() << "\t" << keyPixelCluster->localPosition()[Trk::x]
149// << "\tGangedPixel: " << gangedPixelCluster->getHashAndIndex().hashAndIndex() << "\t" << gangedPixelCluster->localPosition()[Trk::x] << std::endl;
150 break; // get out of loop
151 }
152 }
153 }
154 }
155}
156}
157
159{
160 // Do not initialize again:
161 m_isInitialized=true;
162
163 // get StoreGate service
164 CHECK( m_storeGate.retrieve() );
165
166 return StatusCode::SUCCESS;
167}
#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
Identifiable container index to a contained object.
unsigned short objIndex() const
object index in collection
unsigned int hashAndIndex() const
combined index
unsigned short collHash() const
Accessor to hash, obj index and combined index.
This is a "hash" representation of an Identifier.
std::vector< std::pair< uint32_t, std::vector< uint32_t > > > m_ambiguityMap
virtual void persToTrans(const InDet::PixelGangedClusterAmbiguities_p1 *persCont, InDet::PixelGangedClusterAmbiguities *transCont, MsgStream &log)
virtual void transToPers(const InDet::PixelGangedClusterAmbiguities *transCont, InDet::PixelGangedClusterAmbiguities_p1 *persCont, MsgStream &log)
a const_iterator facade to DataHandle.
Definition SGIterator.h:164
const std::string & key() const
Get the key string with which the current object was stored.
const IdentContIndex & getHashAndIndex() const
Definition index.py:1
#define likely(x)
void initialize()