Skip to content
Snippets Groups Projects
Commit cf5a33b0 authored by Walter Lampl's avatar Walter Lampl
Browse files

Merge branch 'TrackingGeometry_master_propagate_tracking_geometry_to_svc' into 'master'

Propagate TrackingGeometry conditions data to TrackingGeometrySvc and detector store.

See merge request atlas/athena!37360
parents 16bfe41c b44d5cca
No related branches found
No related tags found
No related merge requests found
...@@ -16,6 +16,7 @@ atlas_depends_on_subdirs( ...@@ -16,6 +16,7 @@ atlas_depends_on_subdirs(
Tracking/TrkDetDescr/TrkGeometry Tracking/TrkDetDescr/TrkGeometry
InnerDetector/InDetDetDescr/InDetReadoutGeometry InnerDetector/InDetDetDescr/InDetReadoutGeometry
PRIVATE PRIVATE
Tracking/TrkDetDescr/TrkDetDescrSvc
) )
find_package( Eigen ) find_package( Eigen )
...@@ -33,6 +34,7 @@ atlas_add_component( TrackingGeometryCondAlg ...@@ -33,6 +34,7 @@ atlas_add_component( TrackingGeometryCondAlg
TrkDetDescrUtils TrkDetDescrUtils
TrkGeometry TrkGeometry
InDetReadoutGeometry InDetReadoutGeometry
TrkDetDescrSvcLib
) )
# Install files from the package: # Install files from the package:
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "TrkDetDescrInterfaces/IGeometryBuilderCond.h" #include "TrkDetDescrInterfaces/IGeometryBuilderCond.h"
#include "TrkDetDescrInterfaces/IGeometryProcessor.h" #include "TrkDetDescrInterfaces/IGeometryProcessor.h"
#include "InDetReadoutGeometry/SiDetectorElementCollection.h" #include "InDetReadoutGeometry/SiDetectorElementCollection.h"
#include "TrkDetDescrInterfaces/ITrackingGeometrySvc.h"
#include "GaudiKernel/ICondSvc.h" #include "GaudiKernel/ICondSvc.h"
#include "GaudiKernel/ToolHandle.h" #include "GaudiKernel/ToolHandle.h"
...@@ -40,6 +41,7 @@ private: ...@@ -40,6 +41,7 @@ private:
ServiceHandle<ICondSvc> m_condSvc{this, "CondSvc", "CondSvc"}; ServiceHandle<ICondSvc> m_condSvc{this, "CondSvc", "CondSvc"};
ToolHandle<Trk::IGeometryBuilderCond> m_trackingGeometryBuilder {this, "GeometryBuilder", ""}; ToolHandle<Trk::IGeometryBuilderCond> m_trackingGeometryBuilder {this, "GeometryBuilder", ""};
ToolHandleArray<Trk::IGeometryProcessor> m_geometryProcessors ; ToolHandleArray<Trk::IGeometryProcessor> m_geometryProcessors ;
ServiceHandle<ITrackingGeometrySvc> m_trackingGeometrySvc {this,"TrackingGeometrySvc",""};
}; };
} }
#endif //TRACKINGGEOMETRYCONDALG_H #endif //TRACKINGGEOMETRYCONDALG_H
...@@ -6,13 +6,14 @@ ...@@ -6,13 +6,14 @@
// Trk includes // Trk includes
#include "TrkGeometry/TrackingGeometry.h" #include "TrkGeometry/TrackingGeometry.h"
#include "AthenaKernel/IOVSvcDefs.h" #include "AthenaKernel/IOVSvcDefs.h"
#include "TrkDetDescrSvc/TrackingGeometrySvc.h"
#include "TrackingGeometryCondAlg/TrackingGeometryCondAlg.h" #include "TrackingGeometryCondAlg/TrackingGeometryCondAlg.h"
#include "TrkDetDescrSvc/TrackingGeometryMirror.h"
Trk::TrackingGeometryCondAlg::TrackingGeometryCondAlg(const std::string& name, ISvcLocator* pSvcLocator) Trk::TrackingGeometryCondAlg::TrackingGeometryCondAlg(const std::string& name, ISvcLocator* pSvcLocator)
: AthReentrantAlgorithm(name, pSvcLocator), : AthReentrantAlgorithm(name, pSvcLocator),
m_geometryProcessors(this) m_geometryProcessors(this)
{ {
declareProperty("GeometryProcessors", m_geometryProcessors); declareProperty("GeometryProcessors", m_geometryProcessors);
} }
...@@ -33,6 +34,9 @@ StatusCode Trk::TrackingGeometryCondAlg::initialize() ...@@ -33,6 +34,9 @@ StatusCode Trk::TrackingGeometryCondAlg::initialize()
ATH_MSG_FATAL( "Could not retrieve " << m_geometryProcessors ); ATH_MSG_FATAL( "Could not retrieve " << m_geometryProcessors );
return StatusCode::FAILURE; return StatusCode::FAILURE;
} }
if (!m_trackingGeometrySvc.name().empty()) {
ATH_CHECK( m_trackingGeometrySvc.retrieve() );
}
return StatusCode::SUCCESS; return StatusCode::SUCCESS;
} }
...@@ -66,5 +70,18 @@ StatusCode Trk::TrackingGeometryCondAlg::execute(const EventContext& ctx) const{ ...@@ -66,5 +70,18 @@ StatusCode Trk::TrackingGeometryCondAlg::execute(const EventContext& ctx) const{
} }
} }
ATH_CHECK(writeHandle.record(trackingGeometryPair.first,trackingGeometry)); ATH_CHECK(writeHandle.record(trackingGeometryPair.first,trackingGeometry));
if (msgLvl(MSG::VERBOSE)) {
Trk::TrackingGeometryMirror dumper(trackingGeometry);
dumper.dump(msg(MSG::VERBOSE), name() + " TrackingGeometry dump " );
}
if (!m_trackingGeometrySvc.name().empty()) {
Trk::TrackingGeometrySvc *the_service = dynamic_cast<Trk::TrackingGeometrySvc *>(&(*m_trackingGeometrySvc));
if (!the_service) {
ATH_MSG_FATAL("Expected a special TrackingGeometrySvc implementation derived from Trk::TrackingGeometrySvc but got " << typeid(the_service).name() );
}
ATH_MSG_DEBUG("Set TrackingGeometry " << static_cast<const void *>(trackingGeometry) << " in svc " << m_trackingGeometrySvc.name() );
the_service->setTrackingGeometry(trackingGeometry);
}
return StatusCode::SUCCESS; return StatusCode::SUCCESS;
} }
#ifndef _Trk_TrackingGeometryMirror_h_
#define _Trk_TrackingGeometryMirror_h_
namespace Trk {
class TrackingGeometryMirror;
}
#include "TrkGeometry/TrackingGeometry.h"
#include "AthenaKernel/CLASS_DEF.h"
#include "TrkGeometry/Layer.h"
#include "TrkVolumes/VolumeBounds.h"
#include "TrkGeometry/TrackingVolume.h"
#include "TrkDetDescrUtils/BinnedArray.h"
#include <iostream>
namespace Trk {
/// Helper class to provide the same objects as an existing TrackingGeometry without claiming ownership over these objects.
/// The class is solely meant to allow using the TrackingGeometry conditions data and the TrackingGeometrySvc at the same time.
class TrackingGeometryMirror : public Trk::TrackingGeometry {
public:
TrackingGeometryMirror(TrackingGeometry *src) : TrackingGeometry(nullptr,src->m_navigationLevel) {
update(src);
}
~TrackingGeometryMirror() {
cleanup();
}
void update(TrackingGeometry *src) {
m_world = src->m_world;
m_beam = src->m_beam;
/** The unique boundary Layers */
m_boundaryLayers = src->m_boundaryLayers;
/** The Volumes in a map for later finding */
m_trackingVolumes = src->m_trackingVolumes;
}
void cleanup() {
m_world=nullptr;
m_beam=nullptr;
m_boundaryLayers.clear();
m_trackingVolumes.clear();
}
template <class T_Ostream>
void dump(T_Ostream &out, const std::string &head) const {
for(const std::pair<const Layer*,int> &bound_layers : m_boundaryLayers) {
out << head << " [" << bound_layers.second << "] ";
dumpLayer(out, "",bound_layers.first);
}
int counter=0;
for (const std::pair<const std::string, const TrackingVolume*> &volume : m_trackingVolumes) {
out << head << " [" << counter++ << "] " << volume.first << " volumeBound=" << volume.second->volumeBounds() << std::endl;
if (volume.second->confinedArbitraryLayers()) {
int j=0;
for(const Layer* confined_layer : *volume.second->confinedArbitraryLayers()) {
out << head << " [" << counter++ << "] " << volume.first << " confinedArbitrary layer " << j++ << " ";
dumpLayer(out, "",confined_layer);
}
}
if (volume.second->confinedLayers()) {
int j=0;
for(const Layer* confined_layer : volume.second->confinedLayers()->arrayObjects()) {
out << head << " [" << counter++ << "] " << volume.first << " confined layer" << j++ << " ";
dumpLayer(out,"",confined_layer);
}
}
}
}
protected:
template <class T_Ostream>
static void dumpLayer(T_Ostream &out, const std::string &head, const Layer *layer) {
if (layer) {
out << head
<< layer->layerIndex().value() << " [t=" << layer->layerType() << "] d=" << layer->thickness();
if (layer->representingVolume()) {
out << " vol=" << layer->representingVolume()->volumeBounds();
}
out << layer->surfaceRepresentation();
}
out << std::endl;
}
};
}
#endif
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
#ifdef TRKDETDESCR_MEMUSAGE #ifdef TRKDETDESCR_MEMUSAGE
#include "TrkDetDescrUtils/MemoryLogger.h" #include "TrkDetDescrUtils/MemoryLogger.h"
#endif #endif
class StoreGateSvc; class StoreGateSvc;
...@@ -76,8 +76,10 @@ namespace Trk { ...@@ -76,8 +76,10 @@ namespace Trk {
//!< Standard Destructor //!< Standard Destructor
virtual ~TrackingGeometrySvc(); virtual ~TrackingGeometrySvc();
void setTrackingGeometry(const Trk::TrackingGeometry *ptr);
private: private:
void trackingGeometryNotSet() const;
//!< cached pointers: //!< cached pointers:
ISvcLocator* m_pSvcLocator {nullptr}; ISvcLocator* m_pSvcLocator {nullptr};
StoreGateSvc* m_pDetStore {nullptr}; StoreGateSvc* m_pDetStore {nullptr};
...@@ -85,6 +87,7 @@ namespace Trk { ...@@ -85,6 +87,7 @@ namespace Trk {
ToolHandle<Trk::IGeometryBuilder> m_trackingGeometryBuilder {this, "GeometryBuilder", ""}; ToolHandle<Trk::IGeometryBuilder> m_trackingGeometryBuilder {this, "GeometryBuilder", ""};
//!< the actual building tool //!< the actual building tool
mutable const Trk::TrackingGeometry* m_trackingGeometry {nullptr}; mutable const Trk::TrackingGeometry* m_trackingGeometry {nullptr};
//!< the cached TrackingGeometry //!< the cached TrackingGeometry
Gaudi::Property<std::string> m_trackingGeometryName {this, "TrackingGeometryName", "AtlasTrackingGeometry"}; Gaudi::Property<std::string> m_trackingGeometryName {this, "TrackingGeometryName", "AtlasTrackingGeometry"};
//!< the name of the TrackingGeometry //!< the name of the TrackingGeometry
...@@ -103,13 +106,13 @@ namespace Trk { ...@@ -103,13 +106,13 @@ namespace Trk {
Gaudi::Property<bool> m_rerunOnCallback {this, "RerunOnCallback", false}; Gaudi::Property<bool> m_rerunOnCallback {this, "RerunOnCallback", false};
//!< enables the callback //!< enables the callback
Gaudi::Property<bool> m_buildGeometryFromTagInfo {this, "BuildGeometryFromTagInfo", true}; Gaudi::Property<bool> m_buildGeometryFromTagInfo {this, "BuildGeometryFromTagInfo", true};
Gaudi::Property<bool> m_useConditionsData {this, "UseExternalConditionsData", false};
}; };
} }
inline const Trk::TrackingGeometry* Trk::TrackingGeometrySvc::trackingGeometry() const inline const Trk::TrackingGeometry* Trk::TrackingGeometrySvc::trackingGeometry() const
{ return m_trackingGeometry; } { if (!m_trackingGeometry) { trackingGeometryNotSet(); }
return m_trackingGeometry; }
inline const std::string& Trk::TrackingGeometrySvc::trackingGeometryName() const inline const std::string& Trk::TrackingGeometrySvc::trackingGeometryName() const
{ return m_trackingGeometryName; } { return m_trackingGeometryName; }
......
/* /*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
*/ */
/////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
/////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////
// Trk // Trk
#include "TrkDetDescrSvc/TrackingGeometryMirror.h"
#include "TrkGeometry/TrackingGeometry.h" #include "TrkGeometry/TrackingGeometry.h"
#include "TrkGeometry/TrackingVolume.h" #include "TrkGeometry/TrackingVolume.h"
#include "TrkGeometry/Layer.h" #include "TrkGeometry/Layer.h"
...@@ -44,18 +45,23 @@ Trk::TrackingGeometrySvc::~TrackingGeometrySvc() ...@@ -44,18 +45,23 @@ Trk::TrackingGeometrySvc::~TrackingGeometrySvc()
/** Initialize Service */ /** Initialize Service */
StatusCode Trk::TrackingGeometrySvc::initialize() StatusCode Trk::TrackingGeometrySvc::initialize()
{ {
// get the DetectorStore
ATH_CHECK( service("DetectorStore", m_pDetStore ) );
// alternative mode which only uses an externally provided TrackingGeometry rather than building its own
if (m_useConditionsData) {
for (auto &handle : m_geometryProcessors ) {
handle.disable();
}
m_trackingGeometryBuilder.disable();
return StatusCode::SUCCESS;
}
if (m_geometryProcessors.retrieve().isFailure()){ if (m_geometryProcessors.retrieve().isFailure()){
ATH_MSG_FATAL( "Could not retrieve " << m_geometryProcessors ); ATH_MSG_FATAL( "Could not retrieve " << m_geometryProcessors );
return StatusCode::FAILURE; return StatusCode::FAILURE;
} }
// get the DetectorStore
if (service("DetectorStore", m_pDetStore ).isFailure())
{
ATH_MSG_FATAL( "DetectorStore service not found!" );
return StatusCode::FAILURE;
}
// get the key -- from StoreGate (DetectorStore) // get the key -- from StoreGate (DetectorStore)
std::vector< std::string > tagInfoKeys = m_pDetStore->keys<TagInfo> (); std::vector< std::string > tagInfoKeys = m_pDetStore->keys<TagInfo> ();
std::string tagInfoKey = ""; std::string tagInfoKey = "";
...@@ -93,6 +99,9 @@ StatusCode Trk::TrackingGeometrySvc::initialize() ...@@ -93,6 +99,9 @@ StatusCode Trk::TrackingGeometrySvc::initialize()
StatusCode Trk::TrackingGeometrySvc::trackingGeometryInit(IOVSVC_CALLBACK_ARGS_P(I,keys)) StatusCode Trk::TrackingGeometrySvc::trackingGeometryInit(IOVSVC_CALLBACK_ARGS_P(I,keys))
{ {
if (m_useConditionsData) {
ATH_MSG_FATAL("Logic error: TrackingGeometry init callback called despite being configured to use external TrackingGeometries provided by a conditions algorithm.");
}
// Retrieve the tracking geometry builder tool ---------------------------------------------------- // Retrieve the tracking geometry builder tool ----------------------------------------------------
if (!m_trackingGeometryBuilder.empty() && m_trackingGeometryBuilder.retrieve().isFailure()) { if (!m_trackingGeometryBuilder.empty() && m_trackingGeometryBuilder.retrieve().isFailure()) {
ATH_MSG_FATAL( "Failed to retrieve tool '" << m_trackingGeometryBuilder << "'. Aborting." ); ATH_MSG_FATAL( "Failed to retrieve tool '" << m_trackingGeometryBuilder << "'. Aborting." );
...@@ -125,7 +134,7 @@ StatusCode Trk::TrackingGeometrySvc::trackingGeometryInit(IOVSVC_CALLBACK_ARGS_P ...@@ -125,7 +134,7 @@ StatusCode Trk::TrackingGeometrySvc::trackingGeometryInit(IOVSVC_CALLBACK_ARGS_P
if (needsInit || !m_callbackStringCheck) { if (needsInit || !m_callbackStringCheck) {
// cleanup the geometry if you have one // cleanup the geometry if you have one
// (will delete what is in detector store, because new one will overwrite old one) // (will delete what is in detector store, because new one will overwrite old one)
delete m_trackingGeometry; m_trackingGeometry = 0; m_trackingGeometry = nullptr;
#ifdef TRKDETDESCR_MEMUSAGE #ifdef TRKDETDESCR_MEMUSAGE
// memory monitoring // memory monitoring
...@@ -179,7 +188,12 @@ StatusCode Trk::TrackingGeometrySvc::trackingGeometryInit(IOVSVC_CALLBACK_ARGS_P ...@@ -179,7 +188,12 @@ StatusCode Trk::TrackingGeometrySvc::trackingGeometryInit(IOVSVC_CALLBACK_ARGS_P
#endif #endif
} }
} }
if (msgLvl(MSG::VERBOSE)) {
Trk::TrackingGeometryMirror mirror(atlasTrackingGeometry);
mirror.dump(msg(MSG::VERBOSE), name()+" TrackingGeometry dump ");
mirror.cleanup();
}
// record the resulting TrackingGeometry // record the resulting TrackingGeometry
if (m_pDetStore->record(atlasTrackingGeometry, m_trackingGeometryName, false).isFailure() ){ if (m_pDetStore->record(atlasTrackingGeometry, m_trackingGeometryName, false).isFailure() ){
ATH_MSG_WARNING( "Couldn't write TrackingGeometry to DetectorStore." ); ATH_MSG_WARNING( "Couldn't write TrackingGeometry to DetectorStore." );
...@@ -189,6 +203,41 @@ StatusCode Trk::TrackingGeometrySvc::trackingGeometryInit(IOVSVC_CALLBACK_ARGS_P ...@@ -189,6 +203,41 @@ StatusCode Trk::TrackingGeometrySvc::trackingGeometryInit(IOVSVC_CALLBACK_ARGS_P
return StatusCode::SUCCESS; return StatusCode::SUCCESS;
} }
void Trk::TrackingGeometrySvc::setTrackingGeometry(const Trk::TrackingGeometry *ptr) {
if (!m_useConditionsData) {
ATH_MSG_FATAL("Logic error: external TrackingGeometry provided despite being configured to build an internal one.");
}
if (m_pDetStore->contains<Trk::TrackingGeometry>(m_trackingGeometryName)) {
const TrackingGeometry *mirror;
if (m_pDetStore->retrieve(mirror, m_trackingGeometryName).isFailure()) {
ATH_MSG_FATAL("TrackingGeometry " << m_trackingGeometryName << " exists, but cannot be retrieved.");
}
TrackingGeometry *non_const_mirror ATLAS_NOT_THREAD_SAFE = const_cast<TrackingGeometry *>(mirror);
static_cast<Trk::TrackingGeometryMirror *>(non_const_mirror)->update(const_cast<TrackingGeometry *>(ptr));
if (msgLvl(MSG::VERBOSE)) {
ATH_MSG_VERBOSE( "Setting TrackingGeometry from cond alg ptr=" << static_cast<const void *>(ptr));
static_cast<const Trk::TrackingGeometryMirror *>(mirror)->dump(msg(MSG::VERBOSE), "external TrackingGeometry dump ");
}
}
else {
std::unique_ptr<Trk::TrackingGeometryMirror> mirror=std::make_unique<Trk::TrackingGeometryMirror>(const_cast<TrackingGeometry *>(ptr));
if (msgLvl(MSG::VERBOSE)) {
ATH_MSG_VERBOSE( "Setting TrackingGeometry from cond alg ptr=" << static_cast<const void *>(ptr));
mirror->dump(msg(MSG::VERBOSE), "external TrackingGeometry dump ");
}
// record the resulting TrackingGeometry
if (m_pDetStore->record(static_cast<TrackingGeometry *>(mirror.release()), m_trackingGeometryName, false).isFailure() ){
ATH_MSG_WARNING( "Couldn't write TrackingGeometry to DetectorStore." );
} else {
ATH_MSG_DEBUG( "initialize() successful: TrackingGeometry '" << m_trackingGeometryName << "' built and written to DetectorStore." );
}
}
m_trackingGeometry=ptr;
}
void Trk::TrackingGeometrySvc::trackingGeometryNotSet() const {
ATH_MSG_WARNING( "TrackingGeometry not set ptr=" << static_cast<const void *>(m_trackingGeometry));
}
/** Finalize Service */ /** Finalize Service */
StatusCode Trk::TrackingGeometrySvc::finalize() StatusCode Trk::TrackingGeometrySvc::finalize()
...@@ -201,6 +250,17 @@ StatusCode Trk::TrackingGeometrySvc::finalize() ...@@ -201,6 +250,17 @@ StatusCode Trk::TrackingGeometrySvc::finalize()
ATH_MSG_INFO( "[ memory usage ] ---------------------------------------------------------" ); ATH_MSG_INFO( "[ memory usage ] ---------------------------------------------------------" );
#endif #endif
if (m_useConditionsData) {
const TrackingGeometry *clone=nullptr;
if (m_pDetStore->retrieve(clone, m_trackingGeometryName).isFailure() ){
ATH_MSG_WARNING( "Failed to retrieve TrackingGeometry " << m_trackingGeometryName << " from DetectorStore." );
}
if (clone) {
static_cast<Trk::TrackingGeometryMirror *>(const_cast<TrackingGeometry *>(clone))->cleanup();
ATH_MSG_WARNING( "Cleaned TrackingGeometryMirror " << m_trackingGeometryName << "." );
}
}
ATH_MSG_INFO( "finalize() successful." ); ATH_MSG_INFO( "finalize() successful." );
return StatusCode::SUCCESS; return StatusCode::SUCCESS;
} }
...@@ -217,4 +277,3 @@ StatusCode Trk::TrackingGeometrySvc::queryInterface(const InterfaceID& riid, voi ...@@ -217,4 +277,3 @@ StatusCode Trk::TrackingGeometrySvc::queryInterface(const InterfaceID& riid, voi
addRef(); addRef();
return StatusCode::SUCCESS; return StatusCode::SUCCESS;
} }
...@@ -63,13 +63,19 @@ namespace Trk { ...@@ -63,13 +63,19 @@ namespace Trk {
friend class GeometryBuilderCond; friend class GeometryBuilderCond;
friend class IGeometryBuilderCond; friend class IGeometryBuilderCond;
// give access to private members to allow the class below to mirror a TrackingGeometry.
// This is needed for a temporary workaround to allow using the TrackingGeometryCondAlg and
// TrackingGeometrySvc at the same time.
// @TODO revert once the TrackingGeometrySvc is completly replaced
friend class TrackingGeometryMirror;
public : public :
/** Constructor */ /** Constructor */
TrackingGeometry(const TrackingVolume* highestVolume, NavigationLevel navlevel=globalSearch); TrackingGeometry(const TrackingVolume* highestVolume, NavigationLevel navlevel=globalSearch);
/** Destructor */ /** Destructor */
~TrackingGeometry(); virtual ~TrackingGeometry();
/** return the world */ /** return the world */
const TrackingVolume* highestTrackingVolume() const; const TrackingVolume* highestTrackingVolume() const;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment