ATLAS Offline Software
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"
21 #include "StoreGate/StoreGateSvc.h"
22 
23 // monitor memory usage
24 #ifdef TRKDETDESCR_MEMUSAGE
25 #include <unistd.h>
26 #endif
27 
29 Trk::TrackingGeometrySvc::TrackingGeometrySvc(const std::string& name, ISvcLocator* svc)
30  : base_class(name, svc)
31  , m_geometryProcessors(this)
32 {
33  // geometry processors to validation / distort the TrackingGeometry ------------
34  declareProperty("GeometryProcessors", m_geometryProcessors);
35 }
36 
39 
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 
56  if (m_buildGeometryFromTagInfo) {
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 
74 void
76 {
77  ATH_MSG_INFO("tagInfoUpdated() callback trigerred");
78  trackingGeometryInit().ignore();
79 }
80 
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
103  if (detStore->contains<Trk::TrackingGeometry>(m_trackingGeometryName) && !m_rerunOnCallback) {
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 
178 void
180 {
181  ATH_MSG_WARNING("TrackingGeometry not set ptr=" << static_cast<const void*>(m_trackingGeometry));
182 }
183 
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 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
Trk::TrackingGeometrySvc::m_geometryProcessors
ToolHandleArray< Trk::IGeometryProcessor > m_geometryProcessors
Definition: TrackingGeometrySvc.h:84
BinnedArray.h
Layer.h
Trk::TrackingGeometrySvc::TrackingGeometrySvc
TrackingGeometrySvc(const std::string &name, ISvcLocator *svc)
Standard Destructor.
Definition: TrackingGeometrySvc.cxx:29
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
Trk::TrackingGeometrySvc::trackingGeometryInit
StatusCode trackingGeometryInit(bool needsInit=true)
Create the geometry.
Definition: TrackingGeometrySvc.cxx:82
Trk::TrackingGeometry
Definition: TrackingGeometry.h:67
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
Handler::svc
AthROOTErrorHandlerSvc * svc
Definition: AthROOTErrorHandlerSvc.cxx:10
TrackingGeometrySvc.h
Trk::TrackingGeometrySvc::tagInfoUpdated
virtual void tagInfoUpdated() override final
Definition: TrackingGeometrySvc.cxx:75
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
Trk::TrackingGeometrySvc::trackingGeometryNotSet
void trackingGeometryNotSet() const
Definition: TrackingGeometrySvc.cxx:179
IGeometryProcessor.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
Trk::TrackingGeometrySvc::initialize
virtual StatusCode initialize() override
Initialize Service.
Definition: TrackingGeometrySvc.cxx:42
TrackingVolume.h
IGeometryBuilder.h
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
Trk::TrackingGeometrySvc::finalize
virtual StatusCode finalize() override
Finalize Service.
Definition: TrackingGeometrySvc.cxx:186
Trk::TrackingGeometrySvc::~TrackingGeometrySvc
virtual ~TrackingGeometrySvc()
Destructor.
TrackingGeometry.h
StoreGateSvc.h
LayerMaterialProperties.h
ServiceHandle< ITagInfoMgr >