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