ATLAS Offline Software
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
21 #include "StoreGate/StoreGateSvc.h"
22 
23 
25  m_storeGate("StoreGateSvc", "PixelGangedClusterAmbiguitiesCnv_p1"),
26  m_isInitialized(0)
27 {}
28 
29 
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 
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 }
python.Constants.FATAL
int FATAL
Definition: Control/AthenaCommon/python/Constants.py:19
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
InDet::PixelGangedClusterAmbiguities
std::multimap< const SiCluster *, const SiCluster *, ::InDet::compare_SiCluster > PixelGangedClusterAmbiguities
Definition: PixelGangedClusterAmbiguities.h:46
index
Definition: index.py:1
InDet::PixelGangedClusterAmbiguities_p1::m_pixelClusterContainerName
std::string m_pixelClusterContainerName
Definition: PixelGangedClusterAmbiguities_p1.h:24
IdentContIndex
Identifiable container index to a contained object.
Definition: IdentContIndex.h:23
PixelGangedClusterAmbiguitiesCnv_p1::m_isInitialized
bool m_isInitialized
Definition: PixelGangedClusterAmbiguitiesCnv_p1.h:28
PyPoolBrowser.dh
dh
Definition: PyPoolBrowser.py:102
InDet::PixelClusterContainer
Trk::PrepRawDataContainer< PixelClusterCollection > PixelClusterContainer
Definition: InnerDetector/InDetRecEvent/InDetPrepRawData/InDetPrepRawData/PixelClusterContainer.h:28
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
InDet::PixelGangedClusterAmbiguities_p1
Definition: PixelGangedClusterAmbiguities_p1.h:19
PixelGangedClusterAmbiguitiesCnv_p1::PixelGangedClusterAmbiguitiesCnv_p1
PixelGangedClusterAmbiguitiesCnv_p1()
Definition: PixelGangedClusterAmbiguitiesCnv_p1.cxx:24
PixelGangedClusterAmbiguities.h
PixelGangedClusterAmbiguitiesCnv_p1.h
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
PixelGangedClusterAmbiguitiesCnv_p1::persToTrans
virtual void persToTrans(const InDet::PixelGangedClusterAmbiguities_p1 *persCont, InDet::PixelGangedClusterAmbiguities *transCont, MsgStream &log)
Definition: PixelGangedClusterAmbiguitiesCnv_p1.cxx:108
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
PixelGangedClusterAmbiguitiesCnv_p1::initialize
StatusCode initialize(MsgStream &log)
Definition: PixelGangedClusterAmbiguitiesCnv_p1.cxx:156
PixelGangedClusterAmbiguitiesCnv_p1::m_storeGate
ServiceHandle< StoreGateSvc > m_storeGate
Definition: PixelGangedClusterAmbiguitiesCnv_p1.h:27
IdentContIndex::hashAndIndex
unsigned int hashAndIndex() const
combined index
Definition: IdentContIndex.h:99
IdentContIndex::objIndex
unsigned short objIndex() const
object index in collection
Definition: IdentContIndex.h:92
IdentContIndex.h
PixelClusterContainer.h
errorcheck.h
Helpers for checking error return status codes and reporting errors.
SiCluster.h
Trk::PrepRawData::getHashAndIndex
const IdentContIndex & getHashAndIndex() const
InDet::PixelCluster
Definition: InnerDetector/InDetRecEvent/InDetPrepRawData/InDetPrepRawData/PixelCluster.h:49
Trk::pixelCluster
@ pixelCluster
Definition: MeasurementType.h:22
PixelGangedClusterAmbiguities_p1.h
DEBUG
#define DEBUG
Definition: page_access.h:11
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
InDet::PixelGangedClusterAmbiguities_p1::m_ambiguityMap
std::vector< std::pair< uint32_t, std::vector< uint32_t > > > m_ambiguityMap
Definition: PixelGangedClusterAmbiguities_p1.h:25
IdentifierHash
This is a "hash" representation of an Identifier. This encodes a 32 bit index which can be used to lo...
Definition: IdentifierHash.h:25
StoreGateSvc.h
SG::ConstIterator
Definition: SGIterator.h:163
IdentContIndex::collHash
unsigned short collHash() const
Accessor to hash, obj index and combined index.
Definition: IdentContIndex.h:85
InDet::SiCluster
Definition: InnerDetector/InDetRecEvent/InDetPrepRawData/InDetPrepRawData/SiCluster.h:40
InDet::PixelClusterCollection
Trk::PrepRawDataCollection< PixelCluster > PixelClusterCollection
Definition: PixelClusterCollection.h:26
PixelGangedClusterAmbiguitiesCnv_p1::transToPers
virtual void transToPers(const InDet::PixelGangedClusterAmbiguities *transCont, InDet::PixelGangedClusterAmbiguities_p1 *persCont, MsgStream &log)
Definition: PixelGangedClusterAmbiguitiesCnv_p1.cxx:31