ATLAS Offline Software
Loading...
Searching...
No Matches
MuonDetDescr/MuonGeoModel/src/MuonDetectorTool.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
11#include "GeoModelKernel/GeoPerfUtils.h"
12#include "GeoModelKernel/GeoPhysVol.h"
23
24#include <fstream>
25
26using namespace MuonGM;
27
31MuonDetectorTool::MuonDetectorTool(const std::string &type, const std::string &name, const IInterface *parent) :
32 GeoModelTool(type, name, parent) {
33 declareInterface<IGeoModelTool>(this);
34}
35
37 ATH_MSG_INFO("Initializing ...");
38 return StatusCode::SUCCESS;
39}
41 if (m_detector) {
42 delete m_detector;
43 m_detector = nullptr;
44 }
45}
46
51
52 std::ofstream geoModelStats;
53 int mem{0}, umem{0};
54 float cpu{0.f}, ucpu{0.f};
55
56 MuonGM::MuonDetectorManager *mgr=nullptr;
57 GeoModelExperiment *theExpt = nullptr;
58 ATH_CHECK(detStore()->retrieve(theExpt, "ATLAS"));
59 GeoIntrusivePtr<GeoPhysVol> world{theExpt->getPhysVol()};
60 ATH_CHECK(createFactory(mgr, world));
61
62 if (!m_detector) {
63 ATH_CHECK(detStore()->record(mgr,mgr->getName()));
64 theExpt->addManager(mgr);
65
66 m_manager = mgr;
67 }
68
70 umem = GeoPerfUtils::getMem();
71 ucpu = float(GeoPerfUtils::getCpu() / 100.);
72 geoModelStats << "At MuonDetectorTool::everything done \t SZ= " << umem << " Kb \t Time = " << ucpu << " seconds ---- \t DeltaM = " << umem - mem
73 << " \t Delta T =" << ucpu - cpu << std::endl;
74 geoModelStats.close();
75 }
76
79 if (m_manager && m_manager->tgcIdHelper()) {
80 unsigned int tgcHashMax = m_manager->tgcIdHelper()->detectorElement_hash_max();
81 std::vector<int> *sectorHashVec = new std::vector<int>(tgcHashMax, 0);
82 for (unsigned int i = 0; i < tgcHashMax; ++i) {
83 const MuonGM::TgcReadoutElement *detEl = m_manager->getTgcReadoutElement(i);
84 if (detEl)
85 (*sectorHashVec)[i] = mapping.getSector(detEl->center().phi());
86 }
87 if (detStore()->record(sectorHashVec, "TGC_SectorMapping").isFailure()) {
88 ATH_MSG_WARNING(" failed to record TGC sector mapping ");
89 }
90 }
91 return StatusCode::SUCCESS;
92}
93
94StatusCode MuonDetectorTool::createFactory(MuonGM::MuonDetectorManager * & mgr, GeoPhysVol* world) const {
95
96 std::ofstream geoModelStats;
97 int mem{0}, umem{0};
98 float cpu{0.f}, ucpu{0.f};
99
100
102 geoModelStats.open("MuonGeoModelStatistics_MuonDetectorTool");
103 mem = GeoPerfUtils::getMem();
104 cpu = float(GeoPerfUtils::getCpu() / 100.);
105 geoModelStats << "At MuonDetectorTool::create entry point: \t SZ= " << mem << " Kb \t Time = " << cpu << " seconds " << std::endl;
106
107 umem = GeoPerfUtils::getMem();
108 ucpu = float(GeoPerfUtils::getCpu() / 100.);
109 geoModelStats << "At MuonDetectorTool::resetting to 0: \t SZ= " << umem - mem << " Kb \t Time = " << ucpu - cpu << " seconds " << std::endl;
110 mem = umem;
111 cpu = ucpu;
112 }
113
114 ATH_MSG_VERBOSE(" Show properties (user sett.s or default): LayoutName "
115 << m_layout << endmsg << " Show properties (user sett.s or default): IncludeCutouts " << m_includeCutouts << endmsg
116 << " Show properties (user sett.s or default): IncludeCutoutsBog " << m_includeCutoutsBog << endmsg
117 << " Show properties (user sett.s or default): IncludeCtbBis " << m_includeCtbBis);
118
119 // Get the detector configuration.
120 SmartIF<IGeoModelSvc> geoModel{Gaudi::svcLocator()->service("GeoModelSvc")};
121 ATH_CHECK(geoModel.isValid());
122
123 std::string AtlasVersion = geoModel->atlasVersion();
124 std::string MuonVersion = geoModel->muonVersionOverride();
125
126 ATH_MSG_INFO("create MuonDetectorTool");
127 ATH_MSG_INFO("(from GeoModelSvc) AtlasVersion = <" << AtlasVersion << "> MuonVersion = <" << MuonVersion << ">");
128
129 // Unless we are using custom muons, the switch positions are going to
130 // come from the database:
131
132 std::string detectorKey = MuonVersion.empty() ? AtlasVersion : MuonVersion;
133 std::string detectorNode = MuonVersion.empty() ? "ATLAS" : "MuonSpectrometer";
134 ATH_MSG_INFO("Keys for Muon Switches are (key) " << detectorKey << " (node) " << detectorNode);
135
136 std::string tempLayout = m_layout;
137 std::map<std::string, std::string> altAsciiDBMap{};
138
139
140 // Get the detector configuration.
141 ServiceHandle<IGeoDbTagSvc> geoDbTag("GeoDbTagSvc",name());
142 ATH_CHECK(geoDbTag.retrieve());
143 ServiceHandle<IRDBAccessSvc> accessSvc(geoDbTag->getParamSvcName(),name());
144 ATH_CHECK(accessSvc.retrieve());
145 GeoModelIO::ReadGeoModel* sqliteReader = geoDbTag->getSqliteReader();
146
147 if (sqliteReader) {
148
149 ATH_MSG_INFO("New DD Activated; Muon detector description input from SQLITE file");
150
151 MuonDetectorFactoryLite theFactory(detStore().operator->(),sqliteReader);
152 theFactory.setRDBAccess(accessSvc.get());
153 theFactory.create(world);
154
155
156 mgr=theFactory.getDetectorManager();
157 mgr->setMinimalGeoFlag(m_minimalGeoFlag);
158 mgr->setGeometryVersion(tempLayout);
159 mgr->fillCache();
160
161 return StatusCode::SUCCESS;
162 }
163 //
164 // New DD: action ends here!!
165 //
166 //=====================================================
167 //
168 // Old DD: action starts here:
169 //
170
171 MuonDetectorFactory001 theFactory(detStore().operator->());
173
174
175 if (MuonVersion == "CUSTOM")
176 ATH_MSG_WARNING("Detector Information coming from a custom configuration !!");
177 else {
178
179 ATH_MSG_DEBUG("Detector Information coming from the database (job options IGNORED)");
180
181 IRDBRecordset_ptr switchSet = accessSvc->getRecordsetPtr("MuonSwitches", detectorKey, detectorNode);
182 if ((*switchSet).size() == 0)
183 return StatusCode::FAILURE;
184 const IRDBRecord *switches = (*switchSet)[0];
185
186 // m_layout = switches->getString("LAYOUTNAME");
187 tempLayout = switches->getString("LAYOUTNAME");
188 // m_includeInertMaterials = switches->getInt("BUILDINERTMATERIALS");
189 // m_minimalgeo = switches->getInt("MINIMALGEO");
190 if (MuonVersion.empty()) {
191 MuonVersion = accessSvc->getChildTag("MuonSpectrometer", detectorKey, detectorNode);
192 ATH_MSG_INFO("(from GeoModelSvc) in AtlasVersion = <" << AtlasVersion << "> default MuonVersion is <" << MuonVersion << ">");
193 }
194
195 ATH_MSG_DEBUG(" m_altAsztFile: " << m_altAsztFile);
196 // use ascii file to read in ASZT parameters
197 if (m_altAsztFile != "")
198 altAsciiDBMap.insert(std::make_pair("ASZT", m_altAsztFile));
199 if (m_altCscIntAlinesFile != "")
200 altAsciiDBMap.insert(std::make_pair("IACSC", m_altCscIntAlinesFile));
201 }
202
203 //
204 // Locate the top level experiment node
205 //
206
207 ATH_MSG_INFO("Properties have been set as follows: " << endmsg
208 // <<" LayoutName "<< m_layout.substr(0,1) <<endmsg
209 << " LayoutName " << tempLayout.substr(0, 1) << endmsg
210 << " IncludeCutouts " << m_includeCutouts << endmsg
211 << " IncludeCutoutsBog " << m_includeCutoutsBog << endmsg
212 << " IncludeCtbBis " << m_includeCtbBis << endmsg
213 << " MinimalGeoFlag " << m_minimalGeoFlag << endmsg
214 << " EnableCscIntAlignmentFromGM " << m_useCscIntAlinesFromGM);
215
216 if (m_stationSelection > 0) {
218 if ((m_selectedStations.size() + m_selectedStEta.size() + m_selectedStPhi.size()) < 1) {
219 ATH_MSG_ERROR(" **** Badly set Option " << endmsg << " **** SelectedStations size =" << m_selectedStations.size() << endmsg
220 << " **** SelectedStJzz size =" << m_selectedStations.size() << endmsg
221 << " **** SelectedStJff size =" << m_selectedStations.size() << endmsg << " **** while StationSelection = 1");
222 return (StatusCode::FAILURE);
223 }
224 for (unsigned int i = 0; i < m_selectedStations.size(); i++) {
225 ATH_MSG_INFO(" Selected stations " << m_selectedStations[i]);
226 }
227
228 if (m_selectedStEta.size() > 0) {
229 for (unsigned int i = 0; i < m_selectedStEta.size(); i++)
230 ATH_MSG_INFO(" Selected Jzz locations " << m_selectedStEta[i]);
231 }
232 if (m_selectedStPhi.size() > 0) {
233 for (unsigned int i = 0; i < m_selectedStPhi.size(); i++)
234 ATH_MSG_INFO(" Selected Jff locations " << m_selectedStPhi[i]);
235 }
236 }
237
239 umem = GeoPerfUtils::getMem();
240 ucpu = float(GeoPerfUtils::getCpu() / 100.);
241 geoModelStats << "At MuonDetectorTool::material mgr done \t SZ= " << umem << " Kb \t Time = " << ucpu << " seconds ---- \t DeltaM = " << umem - mem
242 << " \t Delta T =" << ucpu - cpu << std::endl;
243 mem = umem;
244 cpu = ucpu;
245 }
246
247 if (nullptr == m_detector) {
248
249 theFactory.setDBAtlasVersion(AtlasVersion);
250 theFactory.setDBMuonVersion(MuonVersion);
251 theFactory.setDBkey(detectorKey);
252 theFactory.setDBnode(detectorNode);
253 theFactory.setLayout(tempLayout);
256 theFactory.setCtbBisFlag(m_includeCtbBis);
260 theFactory.hasCSC(m_hasCSC);
261 theFactory.hasSTgc(m_hasSTgc);
262 theFactory.hasMM(m_hasMM);
263 if (m_stationSelection > 0)
265
266 theFactory.setRDBAccess(accessSvc.get());
267 // theFactory.setUseRDB(1);
268 theFactory.setAltAsciiDBMap(altAsciiDBMap);
269 try {
270 //
271 // This strange way of casting is to avoid an
272 // utterly brain damaged compiler warning.
273 //
274 theFactory.create(world);
275 } catch (const std::bad_alloc &) {
276 ATH_MSG_FATAL("Could not create new MuonDetectorNode!");
277 return StatusCode::FAILURE;
278 }
279
281 umem = GeoPerfUtils::getMem();
282 ucpu = float(GeoPerfUtils::getCpu() / 100.);
283 geoModelStats << "At MuonDetectorTool::factory created \t SZ= " << umem << " Kb \t Time = " << ucpu << " seconds ---- \t DeltaM = " << umem - mem
284 << " \t Delta T =" << ucpu - cpu << std::endl;
285 mem = umem;
286 cpu = ucpu;
287 }
288
290 umem = GeoPerfUtils::getMem();
291 ucpu = float(GeoPerfUtils::getCpu() / 100.);
292 geoModelStats << "At MuonDetectorTool::trk cache done \t SZ= " << umem << " Kb \t Time = " << ucpu << " seconds ---- \t DeltaM = " << umem - mem
293 << " \t Delta T =" << ucpu - cpu << std::endl;
294 mem = umem;
295 cpu = ucpu;
296 }
297 }
298 mgr=theFactory.getDetectorManager();
299 mgr->fillCache();
300 return StatusCode::SUCCESS;
301}
302
304 SG::DataProxy *proxy = detStore()->proxy(ClassID_traits<MuonGM::MuonDetectorManager>::ID(), m_manager->getName());
305 if (proxy) {
306 proxy->reset();
307 m_manager = nullptr;
308 }
309 return StatusCode::SUCCESS;
310}
#define endmsg
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
This file defines the class for a collection of AttributeLists where each one is associated with a ch...
a traits class that associates a CLID to a type T It also detects whether T inherits from Gaudi DataO...
Definition of the abstract IRDBAccessSvc interface.
std::shared_ptr< IRDBRecordset > IRDBRecordset_ptr
Definition of the abstract IRDBRecord interface.
Definition of the abstract IRDBRecordset interface.
GeoPhysVol * getPhysVol()
Destructor.
void addManager(const GeoVDetectorManager *)
GeoVDetectorManager * m_detector
IRDBRecord is one record in the IRDBRecordset object.
Definition IRDBRecord.h:27
virtual const std::string & getString(const std::string &fieldName) const =0
Get string field value.
Gaudi::Property< std::vector< int > > m_selectedStPhi
virtual StatusCode clear() override final
MuonDetectorTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor(s)
Gaudi::Property< std::vector< int > > m_selectedStEta
virtual StatusCode create() override final
Create the Detector Node corresponding to this tool.
Gaudi::Property< std::vector< std::string > > m_selectedStations
StatusCode createFactory(MuonGM::MuonDetectorManager *&, GeoPhysVol *world) const
virtual const Amg::Vector3D & center() const override
Return the center of the element.
void setAltAsciiDBMap(const AltAsciiDBMap &asciidbmap)
void setDBMuonVersion(const std::string &v)
virtual void create(GeoPhysVol *world) override
void setDBnode(const std::string &v)
void setSelection(const std::vector< std::string > &, const std::vector< int > &, const std::vector< int > &)
void setRDBAccess(IRDBAccessSvc *access)
virtual const MuonDetectorManager * getDetectorManager() const override
void setDBkey(const std::string &v)
void setDBAtlasVersion(const std::string &v)
void setLayout(const std::string &str)
virtual void create(GeoPhysVol *world) override
void setRDBAccess(IRDBAccessSvc *access)
virtual const MuonDetectorManager * getDetectorManager() const override
The MuonDetectorManager stores the transient representation of the Muon Spectrometer geometry and pro...
static void SetSelectionType(int t)
A TgcReadoutElement corresponds to a single TGC chamber; therefore typically a TGC station contains s...
Ensure that the Athena extensions are properly loaded.
Definition GeoMuonHits.h:27