ATLAS Offline Software
Loading...
Searching...
No Matches
PixelGangedClusterAmbiguitiesCnv_p1.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 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 // pushback the last one!
104 persObj->m_ambiguityMap.emplace_back(keyPixelCluster->getHashAndIndex().hashAndIndex(), uintvector);
105 }
106}
107
108void PixelGangedClusterAmbiguitiesCnv_p1::persToTrans(const InDet::PixelGangedClusterAmbiguities_p1* persObj, InDet::PixelGangedClusterAmbiguities* transObj, MsgStream &log)
109{
110
111 if(!m_isInitialized) {
112 if (this->initialize(log) != StatusCode::SUCCESS) {
113 log << MSG::FATAL << "Could not initialize PixelGangedClusterAmbiguitiesCnv_p1 " << endmsg;
114 }
115 }
116
117 if (persObj->m_pixelClusterContainerName.empty())
118 {
119 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;
120 } else
121 {
122 const InDet::PixelClusterContainer* pCC(nullptr);
123 if (m_storeGate->retrieve(pCC, persObj->m_pixelClusterContainerName).isFailure()) {
124 log << MSG::FATAL << "PixelGangedClusterAmbiguitiesCnv_p1: Cannot retrieve "
125 << persObj->m_pixelClusterContainerName << endmsg;
126 }
127
128 const InDet::PixelCluster* keyPixelCluster(nullptr);
129 const InDet::PixelCluster* gangedPixelCluster(nullptr);
130
131 for (const std::pair<uint32_t, std::vector<uint32_t> >& mapElement : persObj->m_ambiguityMap)
132 {
133 for (uint32_t elt : mapElement.second)
134 {
135 IdentContIndex keyIdentContIndex(mapElement.first);
136 IdentContIndex gangedIdentContIndex(elt);
137 for (InDet::PixelClusterContainer::const_iterator contItr = pCC->begin();
138 contItr != pCC->end(); ++contItr)
139 {
140 const InDet::PixelClusterCollection* coll = (*contItr);
141 if (coll->identifyHash() == keyIdentContIndex.collHash())
142 {
143 keyPixelCluster = coll->at(keyIdentContIndex.objIndex());
144 gangedPixelCluster = coll->at(gangedIdentContIndex.objIndex());
145 transObj->insert(std::pair<const InDet::PixelCluster*, const InDet::PixelCluster*>(keyPixelCluster,gangedPixelCluster));
146// std::cout << "TPCnv Read "<< keyPixelCluster->getHashAndIndex().hashAndIndex() << "\t" << keyPixelCluster->localPosition()[Trk::x]
147// << "\tGangedPixel: " << gangedPixelCluster->getHashAndIndex().hashAndIndex() << "\t" << gangedPixelCluster->localPosition()[Trk::x] << std::endl;
148 break; // get out of loop
149 }
150 }
151 }
152 }
153}
154}
155
157{
158 // Do not initialize again:
159 m_isInitialized=true;
160
161 // get StoreGate service
162 CHECK( m_storeGate.retrieve() );
163
164 return StatusCode::SUCCESS;
165}
#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 IdentContIndex & getHashAndIndex() const
Definition index.py:1
void initialize()