ATLAS Offline Software
Loading...
Searching...
No Matches
MuonDetDescr/MuonGeoModel/src/MuonDetectorTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 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
39 ATH_MSG_INFO("Initializing ...");
40 return StatusCode::SUCCESS;
41}
42
47
48 std::ofstream geoModelStats;
49 int mem{0}, umem{0};
50 float cpu{0.f}, ucpu{0.f};
51
52 MuonGM::MuonDetectorManager *mgr=nullptr;
53 GeoModelExperiment *theExpt = nullptr;
54 ATH_CHECK(detStore()->retrieve(theExpt, "ATLAS"));
55 GeoIntrusivePtr<GeoPhysVol> world{theExpt->getPhysVol()};
56 ATH_CHECK(createFactory(mgr, world));
57
58 ATH_CHECK(detStore()->record(mgr,mgr->getName()));
59 theExpt->addManager(mgr);
60
61 m_manager = mgr;
62
64 umem = GeoPerfUtils::getMem();
65 ucpu = float(GeoPerfUtils::getCpu() / 100.);
66 geoModelStats << "At MuonDetectorTool::everything done \t SZ= " << umem << " Kb \t Time = " << ucpu << " seconds ---- \t DeltaM = " << umem - mem
67 << " \t Delta T =" << ucpu - cpu << std::endl;
68 geoModelStats.close();
69 }
70
73 if (m_manager && m_manager->tgcIdHelper()) {
74 unsigned int tgcHashMax = m_manager->tgcIdHelper()->detectorElement_hash_max();
75 std::vector<int> *sectorHashVec = new std::vector<int>(tgcHashMax, 0);
76 for (unsigned int i = 0; i < tgcHashMax; ++i) {
77 const MuonGM::TgcReadoutElement *detEl = m_manager->getTgcReadoutElement(i);
78 if (detEl)
79 (*sectorHashVec)[i] = mapping.getSector(detEl->center().phi());
80 }
81 if (detStore()->record(sectorHashVec, "TGC_SectorMapping").isFailure()) {
82 ATH_MSG_WARNING(" failed to record TGC sector mapping ");
83 }
84 }
85 return StatusCode::SUCCESS;
86}
87
88StatusCode MuonDetectorTool::createFactory(MuonGM::MuonDetectorManager * & mgr, GeoPhysVol* world) const {
89
90 std::ofstream geoModelStats;
91 int mem{0}, umem{0};
92 float cpu{0.f}, ucpu{0.f};
93
95 geoModelStats.open("MuonGeoModelStatistics_MuonDetectorTool");
96 mem = GeoPerfUtils::getMem();
97 cpu = float(GeoPerfUtils::getCpu() / 100.);
98 geoModelStats << "At MuonDetectorTool::create entry point: \t SZ= " << mem << " Kb \t Time = " << cpu << " seconds " << std::endl;
99
100 umem = GeoPerfUtils::getMem();
101 ucpu = float(GeoPerfUtils::getCpu() / 100.);
102 geoModelStats << "At MuonDetectorTool::resetting to 0: \t SZ= " << umem - mem << " Kb \t Time = " << ucpu - cpu << " seconds " << std::endl;
103 mem = umem;
104 cpu = ucpu;
105 }
106
107 ATH_MSG_VERBOSE(" Show properties (user sett.s or default): LayoutName "
108 << m_layout << endmsg << " Show properties (user sett.s or default): IncludeCutouts " << m_includeCutouts << endmsg
109 << " Show properties (user sett.s or default): IncludeCutoutsBog " << m_includeCutoutsBog << endmsg
110 << " Show properties (user sett.s or default): IncludeCtbBis " << m_includeCtbBis);
111
112 // Get the detector configuration.
113 SmartIF<IGeoModelSvc> geoModel{Gaudi::svcLocator()->service("GeoModelSvc")};
114 ATH_CHECK(geoModel.isValid());
115
116 std::string AtlasVersion = geoModel->atlasVersion();
117 std::string MuonVersion = geoModel->muonVersionOverride();
118
119 ATH_MSG_INFO("create MuonDetectorTool");
120 ATH_MSG_INFO("(from GeoModelSvc) AtlasVersion = <" << AtlasVersion << "> MuonVersion = <" << MuonVersion << ">");
121
122 // Unless we are using custom muons, the switch positions are going to
123 // come from the database:
124
125 std::string detectorKey = MuonVersion.empty() ? AtlasVersion : MuonVersion;
126 std::string detectorNode = MuonVersion.empty() ? "ATLAS" : "MuonSpectrometer";
127 ATH_MSG_INFO("Keys for Muon Switches are (key) " << detectorKey << " (node) " << detectorNode);
128
129 std::string tempLayout = m_layout;
130 std::map<std::string, std::string> altAsciiDBMap{};
131
132
133 // Get the detector configuration.
134 ServiceHandle<IGeoDbTagSvc> geoDbTag("GeoDbTagSvc",name());
135 ATH_CHECK(geoDbTag.retrieve());
136 ServiceHandle<IRDBAccessSvc> accessSvc(geoDbTag->getParamSvcName(),name());
137 ATH_CHECK(accessSvc.retrieve());
138 GeoModelIO::ReadGeoModel* sqliteReader = geoDbTag->getSqliteReader();
139
140 if (sqliteReader) {
141
142 ATH_MSG_INFO("New DD Activated; Muon detector description input from SQLITE file");
143
144 MuonDetectorFactoryLite theFactory(detStore().operator->(),sqliteReader);
145 theFactory.setRDBAccess(accessSvc.get());
146 theFactory.create(world);
147
148
149 mgr=theFactory.getDetectorManager();
150 mgr->setMinimalGeoFlag(m_minimalGeoFlag);
151 mgr->setGeometryVersion(tempLayout);
152 mgr->fillCache();
153
154 return StatusCode::SUCCESS;
155 }
156 //
157 // New DD: action ends here!!
158 //
159 //=====================================================
160 //
161 // Old DD: action starts here:
162 //
163
164 MuonDetectorFactory001 theFactory(detStore().operator->());
166
167
168 ATH_MSG_DEBUG("Detector Information coming from the database (job options IGNORED)");
169
170 IRDBRecordset_ptr switchSet = accessSvc->getRecordsetPtr("MuonSwitches", detectorKey, detectorNode);
171 if (switchSet->size() == 0) {
172 ATH_MSG_ERROR("Failed to retrieve MuonSwitches from the database!");
173 return StatusCode::FAILURE;
174 }
175 const IRDBRecord *switches = (*switchSet)[0];
176
177 tempLayout = switches->getString("LAYOUTNAME");
178 if (MuonVersion.empty()) {
179 MuonVersion = accessSvc->getChildTag("MuonSpectrometer", detectorKey, detectorNode);
180 ATH_MSG_INFO("(from GeoModelSvc) in AtlasVersion = <" << AtlasVersion << "> default MuonVersion is <" << MuonVersion << ">");
181 }
182
183 ATH_MSG_DEBUG(" m_altAsztFile: " << m_altAsztFile);
184 // use ascii file to read in ASZT parameters
185 if (m_altAsztFile != "")
186 altAsciiDBMap.insert(std::make_pair("ASZT", m_altAsztFile));
187 if (m_altCscIntAlinesFile != "")
188 altAsciiDBMap.insert(std::make_pair("IACSC", m_altCscIntAlinesFile));
189
190 //
191 // Locate the top level experiment node
192 //
193 ATH_MSG_INFO("Properties have been set as follows: " << endmsg
194 << " LayoutName " << tempLayout.substr(0, 1) << endmsg
195 << " IncludeCutouts " << m_includeCutouts << endmsg
196 << " IncludeCutoutsBog " << m_includeCutoutsBog << endmsg
197 << " IncludeCtbBis " << m_includeCtbBis << endmsg
198 << " MinimalGeoFlag " << m_minimalGeoFlag << endmsg
199 << " EnableCscIntAlignmentFromGM " << m_useCscIntAlinesFromGM);
200
201 if (m_stationSelection > 0) {
203 if ((m_selectedStations.size() + m_selectedStEta.size() + m_selectedStPhi.size()) < 1) {
204 ATH_MSG_ERROR(" **** Badly set Option " << endmsg << " **** SelectedStations size =" << m_selectedStations.size() << endmsg
205 << " **** SelectedStJzz size =" << m_selectedStations.size() << endmsg
206 << " **** SelectedStJff size =" << m_selectedStations.size() << endmsg << " **** while StationSelection = 1");
207 return (StatusCode::FAILURE);
208 }
209 for (const std::string& station : m_selectedStations) {
210 ATH_MSG_INFO(" Selected stations " << station);
211 }
212
213 for (int stEta : m_selectedStEta) {
214 ATH_MSG_INFO(" Selected Jzz locations " << stEta);
215 }
216 for (int stPhi : m_selectedStPhi) {
217 ATH_MSG_INFO(" Selected Jff locations " << stPhi);
218 }
219 }
220
222 umem = GeoPerfUtils::getMem();
223 ucpu = float(GeoPerfUtils::getCpu() / 100.);
224 geoModelStats << "At MuonDetectorTool::material mgr done \t SZ= " << umem << " Kb \t Time = " << ucpu << " seconds ---- \t DeltaM = " << umem - mem
225 << " \t Delta T =" << ucpu - cpu << std::endl;
226 mem = umem;
227 cpu = ucpu;
228 }
229
230 theFactory.setDBAtlasVersion(AtlasVersion);
231 theFactory.setDBMuonVersion(MuonVersion);
232 theFactory.setDBkey(detectorKey);
233 theFactory.setDBnode(detectorNode);
234 theFactory.setLayout(tempLayout);
237 theFactory.setCtbBisFlag(m_includeCtbBis);
241 theFactory.hasCSC(m_hasCSC);
242 theFactory.hasSTgc(m_hasSTgc);
243 theFactory.hasMM(m_hasMM);
244 if (m_stationSelection > 0)
246
247 theFactory.setRDBAccess(accessSvc.get());
248 theFactory.setAltAsciiDBMap(altAsciiDBMap);
249
250 theFactory.create(world);
251
253 umem = GeoPerfUtils::getMem();
254 ucpu = float(GeoPerfUtils::getCpu() / 100.);
255 geoModelStats << "At MuonDetectorTool::factory created \t SZ= " << umem << " Kb \t Time = " << ucpu << " seconds ---- \t DeltaM = " << umem - mem
256 << " \t Delta T =" << ucpu - cpu << std::endl;
257 mem = umem;
258 cpu = ucpu;
259 }
260
261 mgr=theFactory.getDetectorManager();
262 mgr->fillCache();
263 return StatusCode::SUCCESS;
264}
265
267 SG::DataProxy *proxy = detStore()->proxy(ClassID_traits<MuonGM::MuonDetectorManager>::ID(), m_manager->getName());
268 if (proxy) {
269 proxy->reset();
270 m_manager = nullptr;
271 }
272 return StatusCode::SUCCESS;
273}
#define endmsg
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(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 *)
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.
virtual unsigned int size() const =0
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 ~MuonDetectorTool() override final
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