ATLAS Offline Software
EventCnvSuperTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 #include <typeinfo>
8 
14 #include "TrkSurfaces/Surface.h"
15 
17  const std::string& n,
18  const IInterface* p)
19  : base_class(t, n, p),
20  m_detID(nullptr),
21  m_haveIdCnvTool(false), // Will be set to true on retrieval
22  m_haveMuonCnvTool(false), // Will be set to true on retrieval
23  m_doMuons(true),
24  m_doID(true),
25  m_doTrackOverlay(false),
26  m_errCount(0),
27  m_maxErrCount(10) {
28  declareProperty("DoMuons", m_doMuons,
29  "If true (default), attempt to retrieve Muon helper tool and "
30  "convert Muon objects.");
31  declareProperty("DoID", m_doID,
32  "If true (default), attempt to retrieve Inner Detector "
33  "helper tool and convert ID objects.");
34  declareProperty("DoTrackOverlay", m_doTrackOverlay,
35  "If true, ID on-track conversion tools will look for "
36  "background PRD collections");
37  declareProperty("MaxErrorCount", m_maxErrCount,
38  "Maximum number of errors that will be reported");
39 }
40 
42  if (m_errCount > m_maxErrCount)
43  ATH_MSG_WARNING("Suppressed " << (m_errCount - m_maxErrCount)
44  << " WARNING or ERROR messages");
45 }
46 
48  // Try to get AtlasID
49  StatusCode sc = detStore()->retrieve(m_detID, "AtlasID");
50  if (sc.isFailure()) {
51  ATH_MSG_WARNING("Could not get AtlasDetectorID ");
52  }
53 
54  if (!m_doID && !m_doMuons) {
56  "This tool has been configured without either Muons or ID, and so "
57  "can't do anything. Problems likely.");
58  }
59 
60  // Now try to get the tools
61  if (m_doID && !m_idCnvTool.empty()) {
62  if (m_idCnvTool.retrieve().isFailure()) {
64  "Failed to retrieve InDet helper tool "
65  << m_idCnvTool
66  << ". Will not be able to recreate ID Surfaces / Det Elements.");
67  m_doID = false;
68  } else {
69  ATH_MSG_VERBOSE("Retrieved tool " << m_idCnvTool);
70  m_haveIdCnvTool = true;
71  }
72  } else {
73  m_idCnvTool.setTypeAndName("");
74  }
75 
76  if (m_doMuons && !m_muonCnvTool.empty()) {
77  if (m_muonCnvTool.retrieve().isFailure()) {
79  "Failed to retrieve Muon helper tool "
80  << m_muonCnvTool
81  << ". Will not be able to recreate ID Surfaces / Det Elements.");
82  m_doMuons = false;
83  } else {
84  ATH_MSG_VERBOSE("Retrieved tool " << m_muonCnvTool);
85  m_haveMuonCnvTool = true;
86  }
87  } else {
88  m_muonCnvTool.setTypeAndName("");
89  }
90 
91  // Print an extra warning if neither tool found.
92  if (!m_haveIdCnvTool && !m_haveMuonCnvTool) {
94  "Failed to retrieve either and InDet or a Muon tool. Will not be able "
95  "to recreate surfaces / detector elements.");
96  m_maxErrCount = 0; // No point in further WARNINGs
97  }
98 
99  return StatusCode::SUCCESS;
100 }
101 
103  msg() << "Finalize().";
104  if (m_errCount > 0)
105  msg() << " Tried to print " << m_errCount
106  << " ERROR/WARNING messages (with maximum permissable = "
107  << m_maxErrCount << ")";
108  msg() << endmsg;
109  return StatusCode::SUCCESS;
110 }
111 
113  const Identifier& id) const {
114  if (m_detID == nullptr)
115  return nullptr;
116 
117  if (m_detID->is_indet(id)) {
118  if (m_haveIdCnvTool) {
119  return &(*m_idCnvTool);
120  } else {
121  if ((m_errCount++) < m_maxErrCount)
122  ATH_MSG_WARNING("ID RIO_OnTrack, but have no ID cnv tool!");
123  return nullptr;
124  }
125  } else {
126  if (m_detID->is_muon(id)) {
127  if (m_haveMuonCnvTool) {
128  return &(*m_muonCnvTool);
129  } else {
130  if ((m_errCount++) < m_maxErrCount)
132  "Muon RIO_OnTrack, but have no muon cnv tool. Cannot set check "
133  "RoT.");
134  return nullptr;
135  }
136  }
137  }
138 
139  if ((m_errCount++) < m_maxErrCount) {
140  std::string ident = m_detID->show_to_string(id);
141  ATH_MSG_WARNING("Unknown Identifier: (" << ident << "), that is (" << id
142  << ")");
143  }
144  return nullptr;
145 }
146 
148  const Identifier& id) const {
149  const Surface* surface = nullptr;
150  const Trk::ITrkEventCnvTool* cnvTool = getCnvTool(id);
151  if (cnvTool != nullptr) {
152  const TrkDetElementBase* detEl = cnvTool->getDetectorElement(id);
153  if (detEl != nullptr)
154  surface = &(detEl->surface(id));
155  else if ((m_errCount++) < m_maxErrCount)
156  ATH_MSG_WARNING("getSurface: could not get detector element from id:"
157  << id << " Returning 0.");
158  } else {
159  if ((m_errCount++) < m_maxErrCount)
161  "getSurface: could not get cnv tool for Identifier:" << id);
162  }
163  return surface;
164 }
165 
167  using namespace std;
168  const Trk::ITrkEventCnvTool* cnvTool = getCnvTool(RoT->identify());
169  if (cnvTool != nullptr) {
170  cnvTool->recreateRIO_OnTrack(RoT);
171  } else {
172  const type_info& info = typeid(*RoT);
173  if ((m_errCount++) < m_maxErrCount)
175  "recreateRIO_OnTrack: could not get cnv tool. Returning without "
176  "correctly filling ROT of type: "
177  << info.name());
178  }
179 }
180 
182  const Trk::ITrkEventCnvTool* cnvTool = getCnvTool(RoT->identify());
183  if (cnvTool != nullptr) {
184  cnvTool->prepareRIO_OnTrack(RoT);
185  } else {
186  if ((m_errCount++) < m_maxErrCount)
187  msg() << "prepareRIO_OnTrack could not find appropriate tool to prepare: "
188  << *RoT << std::endl;
189  }
190 }
191 
193  ELKey_t& key,
194  ELIndex_t& index) const {
195  const Trk::ITrkEventCnvTool* cnvTool = getCnvTool(RoT->identify());
196  if (cnvTool != nullptr) {
197  cnvTool->prepareRIO_OnTrackLink(RoT, key, index);
198  } else {
199  if ((m_errCount++) < m_maxErrCount)
200  msg() << "prepareRIO_OnTrack could not find appropriate tool to prepare: "
201  << *RoT << std::endl;
202  }
203 }
grepfile.info
info
Definition: grepfile.py:38
Trk::EventCnvSuperTool::finalize
virtual StatusCode finalize() override
Definition: EventCnvSuperTool.cxx:102
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
MeasurementBase.h
Surface.h
index
Definition: index.py:1
Trk::EventCnvSuperTool::m_doMuons
bool m_doMuons
Property deciding whether to attempt Muon conversions.
Definition: EventCnvSuperTool.h:72
Trk::EventCnvSuperTool::getCnvTool
virtual const Trk::ITrkEventCnvTool * getCnvTool(const Identifier &id) const override
Definition: EventCnvSuperTool.cxx:112
Trk::RIO_OnTrack
Definition: RIO_OnTrack.h:70
Trk::TrkDetElementBase
Definition: TrkDetElementBase.h:52
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
Trk::EventCnvSuperTool::EventCnvSuperTool
EventCnvSuperTool(const std::string &t, const std::string &n, const IInterface *p)
Definition: EventCnvSuperTool.cxx:16
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
Trk::EventCnvSuperTool::prepareRIO_OnTrackLink
virtual void prepareRIO_OnTrackLink(const RIO_OnTrack *Rot, ELKey_t &key, ELIndex_t &index) const override
Take the passed RoT and return the EL components to write to disc.
Definition: EventCnvSuperTool.cxx:192
ITrkEventCnvTool.h
AtlasDetectorID.h
This class provides an interface to generate or decode an identifier for the upper levels of the dete...
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
beamspotman.n
n
Definition: beamspotman.py:731
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
Trk::ITrkEventCnvTool::prepareRIO_OnTrack
virtual void prepareRIO_OnTrack(Trk::RIO_OnTrack *rot) const =0
Take the passed RoT and prepare the PRD ElementLink for writing to disk.
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
Trk::EventCnvSuperTool::prepareRIO_OnTrack
virtual void prepareRIO_OnTrack(RIO_OnTrack *Rot) const override
Take the passed RoT and prepare the PRD ElementLink for writing to disc.
Definition: EventCnvSuperTool.cxx:181
Trk::TrkDetElementBase::surface
virtual const Surface & surface() const =0
Return surface associated with this detector element.
EventCnvSuperTool.h
Trk::ITrkEventCnvTool
Definition: ITrkEventCnvTool.h:31
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
RIO_OnTrack.h
Trk::EventCnvSuperTool::~EventCnvSuperTool
virtual ~EventCnvSuperTool()
Definition: EventCnvSuperTool.cxx:41
TRT::Hit::ident
@ ident
Definition: HitInfo.h:77
Trk::ITrkEventCnvTool::recreateRIO_OnTrack
virtual void recreateRIO_OnTrack(Trk::RIO_OnTrack *RoT) const =0
Take the passed RoT and recreate it (i.e.
Trk::EventCnvSuperTool::initialize
virtual StatusCode initialize() override
Definition: EventCnvSuperTool.cxx:47
Trk::EventCnvSuperTool::getSurface
virtual const Trk::Surface * getSurface(const Identifier &id) const override
From passed Identifier.
Definition: EventCnvSuperTool.cxx:147
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
Trk::ITrkEventCnvTool::getDetectorElement
virtual const Trk::TrkDetElementBase * getDetectorElement(const Identifier &id, const IdentifierHash &idHash) const =0
Returns the detectorElement associated with this Identifier & Hash.
Trk::EventCnvSuperTool::m_doID
bool m_doID
Property deciding whether to attempt ID conversions.
Definition: EventCnvSuperTool.h:73
Trk::RIO_OnTrack::identify
virtual Identifier identify() const final
return the identifier -extends MeasurementBase
Definition: RIO_OnTrack.h:155
Trk::EventCnvSuperTool::recreateRIO_OnTrack
virtual void recreateRIO_OnTrack(RIO_OnTrack *RoT) const override
Take the passed RoT and recreate it (i.e.
Definition: EventCnvSuperTool.cxx:166
declareProperty
#define declareProperty(n, p, h)
Definition: BaseFakeBkgTool.cxx:15
Trk::ITrkEventCnvTool::prepareRIO_OnTrackLink
virtual void prepareRIO_OnTrackLink(const Trk::RIO_OnTrack *rot, ELKey_t &key, ELIndex_t &index) const =0
Similar, but just return the EL components rather then changing ROT.
Trk::EventCnvSuperTool::m_doTrackOverlay
bool m_doTrackOverlay
Property for whether track overlay is being used, in which case different PRD containers are used by ...
Definition: EventCnvSuperTool.h:75
Trk::Surface
Definition: Tracking/TrkDetDescr/TrkSurfaces/TrkSurfaces/Surface.h:75
DetElementSurface.h
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
Trk::EventCnvSuperTool::m_maxErrCount
int m_maxErrCount
Maximum number of permissable ERROR/WARNING messages sent to output.
Definition: EventCnvSuperTool.h:78
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37