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