ATLAS Offline Software
Loading...
Searching...
No Matches
TrkDetDescr/TrkDetDescrSvc/src/TrackingGeometrySvc.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// TrackingGeometrySvc.cxx, (c) ATLAS Detector software
8
9// Trk
13#include "TrkGeometry/Layer.h"
17// GaudiKernel && Control
18#include "GaudiKernel/ISvcLocator.h"
19#include "GaudiKernel/MsgStream.h"
21
22// monitor memory usage
23#ifdef TRKDETDESCR_MEMUSAGE
24#include <unistd.h>
25#endif
26
27
31{
32
34 "!!! Initialization of TrackingGeometrySvc !!! The Service it to be "
35 "deprecated in favour of the relevant Condition Algorithm. !!!");
36 m_autoRetrieveTools = false;
37 m_checkToolDeps = false;
38
39 if (m_geometryProcessors.retrieve().isFailure()) {
40 ATH_MSG_FATAL("Could not retrieve " << m_geometryProcessors);
41 return StatusCode::FAILURE;
42 }
43
45 ATH_MSG_INFO("Building Geometry from TagInfo");
46 // register a callback on TagInfo updates
47 ServiceHandle<ITagInfoMgr> tagInfoMgr("TagInfoMgr", name());
48 ATH_CHECK(tagInfoMgr.retrieve());
49 tagInfoMgr->addListener(this);
50 } else {
51 ATH_MSG_INFO("Building Geometry at initialisation time.");
52 // build with no dependency on COOL
53 if (trackingGeometryInit(false).isFailure()) {
54 ATH_MSG_FATAL("Unable to build the TrackingGeometry!");
55 return StatusCode::FAILURE;
56 }
57 }
58 ATH_MSG_INFO("initialize() successful! ");
59 return StatusCode::SUCCESS;
60}
61
62void
64{
65 ATH_MSG_INFO("tagInfoUpdated() callback trigerred");
66 trackingGeometryInit().ignore();
67}
68
69StatusCode
71{
72 ATH_MSG_INFO("Trk::TrackingGeometrySvc::trackingGeometryInit");
73
74 SmartIF<StoreGateSvc> detStore{service("DetectorStore")};
75 ATH_CHECK( detStore.isValid() );
76
77 // Retrieve the tracking geometry builder tool
78 // ----------------------------------------------------
79 if (!m_trackingGeometryBuilder.empty() && m_trackingGeometryBuilder.retrieve().isFailure()) {
80 ATH_MSG_FATAL("Failed to retrieve tool '" << m_trackingGeometryBuilder << "'. Aborting.");
81 return StatusCode::FAILURE;
82 } else if (m_trackingGeometryBuilder.empty()) {
83 ATH_MSG_FATAL("TrackingGeometrySvc " << name()
84 << " not properly configured. No GeometryBuilder defined. Aborting.");
85 return StatusCode::FAILURE;
86 } else {
87 ATH_MSG_DEBUG("Retrieved tool " << m_trackingGeometryBuilder);
88 }
89
90 // nothing to do in this case since rerun is switched off
92 return StatusCode::SUCCESS;
93 }
94
95 // only build if the callback string was true
96 // (MN: I set this to alwaus true if called on TagInfo update)
97 if (needsInit) {
98 ATH_MSG_INFO("trackingGeometryInit - initialize on TagInfoMgr callback");
99 // cleanup the geometry if you have one
100 // (will delete what is in detector store, because new one will overwrite old one)
101 m_trackingGeometry = nullptr;
102
103#ifdef TRKDETDESCR_MEMUSAGE
104 // memory monitoring
105 ATH_MSG_INFO("[ memory usage ] Start to monitor memory usage of PID: " << getpid());
106
107 m_memoryLogger.refresh(getpid());
108 ATH_MSG_INFO(m_memoryLogger);
109 // record the difference
110 m_changeVsize = (-1.) * m_memoryLogger.vmSize();
111 m_changeRss = (-1.) * m_memoryLogger.vmRss();
112#endif
113
114 // build the TrackingGeometry from the builder
115 m_trackingGeometry = m_trackingGeometryBuilder->trackingGeometry().release();
116
117#ifdef TRKDETDESCR_MEMUSAGE
118 ATH_MSG_INFO("[ memory usage ] TrackingGeometry retrieved: ");
119 m_memoryLogger.refresh(getpid());
120 ATH_MSG_INFO(m_memoryLogger);
121#endif
122
123 // cast constness away for StoreGate
124 Trk::TrackingGeometry* atlasTrackingGeometry = const_cast<Trk::TrackingGeometry*>(m_trackingGeometry);
125
126 // check if a second call back has occured
127 if (detStore->contains<Trk::TrackingGeometry>(m_trackingGeometryName)) {
128 ATH_MSG_VERBOSE("New Callback evoked remove of existing object!");
129 // you need to retrieve the object first to remove it
130 const Trk::TrackingGeometry* oldTrackingGeometry = nullptr;
131 if (detStore->retrieve(oldTrackingGeometry, m_trackingGeometryName).isFailure())
132 ATH_MSG_WARNING("Callback evoked remove of '" << m_trackingGeometryName << "'. But retrieve did not succeed! ");
133 if (oldTrackingGeometry && detStore->remove<Trk::TrackingGeometry>(oldTrackingGeometry).isFailure())
134 ATH_MSG_WARNING("Callback evoked remove of '" << m_trackingGeometryName << "'. But it did not succeed!");
135 // delete is safe
136 delete oldTrackingGeometry;
137 }
138
139 // loop over the recursive geometry processors
140 ToolHandleArray<Trk::IGeometryProcessor>::iterator gpIter = m_geometryProcessors.begin();
141 ToolHandleArray<Trk::IGeometryProcessor>::iterator gpIterE = m_geometryProcessors.end();
142 for (; gpIter != gpIterE; ++gpIter) {
143 if ((*gpIter)->process(*atlasTrackingGeometry).isFailure()) {
144 ATH_MSG_FATAL("Processing of TrackingGeometry did not succeed. Abort.");
145 return StatusCode::FAILURE;
146 } else {
147 ATH_MSG_VERBOSE("Successfully processed the TrackingGeometry with " << (*gpIter));
148#ifdef TRKDETDESCR_MEMUSAGE
149 ATH_MSG_INFO("[ memory usage ] After processing with " << (*gpIter));
150 m_memoryLogger.refresh(getpid());
151 ATH_MSG_INFO(m_memoryLogger);
152#endif
153 }
154 }
155 // record the resulting TrackingGeometry
156 if (detStore->record(atlasTrackingGeometry, m_trackingGeometryName, false).isFailure()) {
157 ATH_MSG_WARNING("Couldn't write TrackingGeometry to DetectorStore.");
158 } else {
159 ATH_MSG_DEBUG("initialize() successful: TrackingGeometry '" << m_trackingGeometryName
160 << "' built and written to DetectorStore.");
161 }
162 }
163 return StatusCode::SUCCESS;
164}
165
166void
168{
169 ATH_MSG_WARNING("TrackingGeometry not set ptr=" << static_cast<const void*>(m_trackingGeometry));
170}
171
173StatusCode
175{
176#ifdef TRKDETDESCR_MEMUSAGE
177 ATH_MSG_INFO("[ memory usage ] Change in memory usage -------------------------------- ");
178 ATH_MSG_INFO("[ memory usage ] Virtual memory change (vsize) : " << m_changeVsize);
179 ATH_MSG_INFO("[ memory usage ] Real memory change (rss) : " << m_changeRss);
180 ATH_MSG_INFO("[ memory usage ] ---------------------------------------------------------");
181#endif
182 ATH_MSG_INFO("finalize() successful.");
183 return StatusCode::SUCCESS;
184}
#define ATH_CHECK
Evaluate an expression and check for errors.
#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)
virtual StatusCode initialize() override
Initialize Service.
StatusCode trackingGeometryInit(bool needsInit=true)
Create the geometry.
ToolHandle< Trk::IGeometryBuilder > m_trackingGeometryBuilder
the actual building tool
virtual StatusCode finalize() override
Finalize Service.
ToolHandleArray< Trk::IGeometryProcessor > m_geometryProcessors
processors to help
Gaudi::Property< std::string > m_trackingGeometryName
the name of the TrackingGeometry
const Trk::TrackingGeometry * m_trackingGeometry
the cached TrackingGeometry
The TrackingGeometry class is the owner of the constructed TrackingVolumes.
::StatusCode StatusCode
StatusCode definition for legacy code.