From f620b53dc86929a2322aeb1fc09e559ecb0225b6 Mon Sep 17 00:00:00 2001 From: Joseph Boudreau <joseph.boudreau@cern.ch> Date: Wed, 15 May 2024 14:06:01 +0200 Subject: [PATCH] Deal with mutable materials such as a gas mixture. --- .../GeoModelKernel/GeoModelKernel/GeoLogVol.h | 17 +++++++++++++---- .../KitchenSinkPlugin/src/KitchenSinkPlugin.cxx | 3 +++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoLogVol.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoLogVol.h index cb3b5a3e9..7885deaad 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoLogVol.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoLogVol.h @@ -4,7 +4,6 @@ #ifndef GEOMODELKERNEL_GEOLOGVOL_H #define GEOMODELKERNEL_GEOLOGVOL_H - /** * @class GeoLogVol * @@ -17,7 +16,9 @@ #include "GeoModelKernel/GeoIntrusivePtr.h" #include "GeoModelKernel/GeoMaterial.h" #include <vector> - +#include <thread> +#include <shared_mutex> +#include <mutex> class GeoLogVol : public RCBase { public: @@ -35,7 +36,14 @@ class GeoLogVol : public RCBase // Returns the material of the logical volume. const GeoMaterial* getMaterial () const { - return m_material; + std::shared_lock lock{m_mutex}; + return m_material; + } + + // In some cases (gases, liquids) materials be updated? + void setMaterial (const GeoMaterial *newMaterial) const { + std::unique_lock guards{m_mutex}; + m_material = newMaterial; } protected: @@ -47,7 +55,8 @@ class GeoLogVol : public RCBase std::string m_name{}; // Material composition of this volume. - GeoIntrusivePtr<const GeoMaterial> m_material{}; + mutable GeoIntrusivePtr<const GeoMaterial> m_material{}; + mutable std::shared_mutex m_mutex{}; // Shape of this volume. GeoIntrusivePtr<const GeoShape> m_shape{}; diff --git a/GeoModelExamples/KitchenSinkPlugin/src/KitchenSinkPlugin.cxx b/GeoModelExamples/KitchenSinkPlugin/src/KitchenSinkPlugin.cxx index d1597e8ef..e94433954 100644 --- a/GeoModelExamples/KitchenSinkPlugin/src/KitchenSinkPlugin.cxx +++ b/GeoModelExamples/KitchenSinkPlugin/src/KitchenSinkPlugin.cxx @@ -301,6 +301,9 @@ void KitchenSinkPlugin::create(GeoVPhysVol *world, bool /*publish*/) { ); world->add(wTransform); world->add(wPhys); + wLog->setMaterial(Stainless); + + } //--------------------------------------// -- GitLab