ATLAS Offline Software
Loading...
Searching...
No Matches
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
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 "
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 "
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.
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}
#define endmsg
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
This class provides an interface to generate or decode an identifier for the upper levels of the dete...
static Double_t sc
bool m_doTrackOverlay
Property for whether track overlay is being used, in which case different PRD containers are used by ...
virtual const Trk::Surface * getSurface(const Identifier &id) const override
From passed Identifier.
ToolHandle< Trk::ITrkEventCnvTool > m_idCnvTool
Tool used to handle ID RoTs etc.
bool m_haveIdCnvTool
Flag set in intialise, letting us know whether the tool has been found.
EventCnvSuperTool(const std::string &t, const std::string &n, const IInterface *p)
std::atomic_int m_errCount
Current number of ERROR/WARNING messages sent to output.
const AtlasDetectorID * m_detID
bool m_doMuons
Property deciding whether to attempt Muon conversions.
virtual StatusCode initialize() override
bool m_doID
Property deciding whether to attempt ID conversions.
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.
int m_maxErrCount
Maximum number of permissable ERROR/WARNING messages sent to output.
virtual void prepareRIO_OnTrack(RIO_OnTrack *Rot) const override
Take the passed RoT and prepare the PRD ElementLink for writing to disc.
ToolHandle< Trk::ITrkEventCnvTool > m_muonCnvTool
Tool used to handle Muon RoTs etc.
virtual StatusCode finalize() override
virtual void recreateRIO_OnTrack(RIO_OnTrack *RoT) const override
Take the passed RoT and recreate it (i.e.
virtual const Trk::ITrkEventCnvTool * getCnvTool(const Identifier &id) const override
bool m_haveMuonCnvTool
Flag set in intialise, letting us know whether the tool has been found.
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.
virtual const Trk::TrkDetElementBase * getDetectorElement(const Identifier &id, const IdentifierHash &idHash) const =0
Returns the detectorElement associated with this Identifier & Hash.
virtual void prepareRIO_OnTrack(Trk::RIO_OnTrack *rot) const =0
Take the passed RoT and prepare the PRD ElementLink for writing to disk.
virtual void recreateRIO_OnTrack(Trk::RIO_OnTrack *RoT) const =0
Take the passed RoT and recreate it (i.e.
Class to handle RIO On Tracks ROT) for InDet and Muons, it inherits from the common MeasurementBase.
Definition RIO_OnTrack.h:70
Identifier identify() const
return the identifier -extends MeasurementBase
Abstract Base Class for tracking surfaces.
This is the base class for all tracking detector elements with read-out relevant information.
virtual const Surface & surface() const =0
Return surface associated with this detector element.
Definition index.py:1
STL namespace.
MsgStream & msg
Definition testRead.cxx:32