Skip to content
Snippets Groups Projects
Commit 2db8efde authored by Johannes Junggeburth's avatar Johannes Junggeburth :dog2: Committed by Vakhtang Tsulaia
Browse files

GeoDeDuplicator - Add caching of name tags & improve documentation

parent 35906b5c
No related branches found
No related tags found
1 merge request!394GeoDeDuplicator - Add caching of name tags & improve documentation
Pipeline #9856660 passed
/* /*
Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
*/ */
#ifndef GeoModelHelpers_GEODEDUPLICATOR_H #ifndef GeoModelHelpers_GEODEDUPLICATOR_H
#define GeoModelHelpers_GEODEDUPLICATOR_H #define GeoModelHelpers_GEODEDUPLICATOR_H
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#include "GeoModelKernel/GeoPhysVol.h" #include "GeoModelKernel/GeoPhysVol.h"
#include "GeoModelKernel/GeoShape.h" #include "GeoModelKernel/GeoShape.h"
#include "GeoModelKernel/GeoTransform.h" #include "GeoModelKernel/GeoTransform.h"
#include "GeoModelKernel/GeoSerialIdentifier.h"
#include "GeoModelKernel/GeoNameTag.h"
#include "GeoModelHelpers/GeoLogVolSorter.h" #include "GeoModelHelpers/GeoLogVolSorter.h"
#include "GeoModelHelpers/GeoPhysVolSorter.h" #include "GeoModelHelpers/GeoPhysVolSorter.h"
...@@ -14,6 +16,7 @@ ...@@ -14,6 +16,7 @@
#include "GeoModelHelpers/TransformSorter.h" #include "GeoModelHelpers/TransformSorter.h"
#include <set> #include <set>
#include <map>
#include <mutex> #include <mutex>
#include <thread> #include <thread>
/*** /***
...@@ -71,20 +74,48 @@ class GeoDeDuplicator { ...@@ -71,20 +74,48 @@ class GeoDeDuplicator {
using GeoLogVolPtr = GeoIntrusivePtr<GeoLogVol>; using GeoLogVolPtr = GeoIntrusivePtr<GeoLogVol>;
using GeoTrfPtr = GeoIntrusivePtr<GeoTransform>; using GeoTrfPtr = GeoIntrusivePtr<GeoTransform>;
using GeoPhysVolPtr = GeoIntrusivePtr<GeoPhysVol>; using GeoPhysVolPtr = GeoIntrusivePtr<GeoPhysVol>;
using GeoSerialIdPtr = GeoIntrusivePtr<GeoSerialIdentifier>;
using GeoNamePtr = GeoIntrusivePtr<GeoNameTag>;
/** @brief Standard constructor */
GeoDeDuplicator() = default; GeoDeDuplicator() = default;
/** @brief Standard destructor */
virtual ~GeoDeDuplicator() = default; virtual ~GeoDeDuplicator() = default;
/** @brief Takes a GeoPhysVol and adds it to the cache. If physVol deduplication
* is turned on and an equivalent volume has been parsed before,
* then that volume is returned instead */
GeoPhysVolPtr cacheVolume(GeoPhysVolPtr vol) const; GeoPhysVolPtr cacheVolume(GeoPhysVolPtr vol) const;
/** @brief Converts the transform into GeoTransform with(out) deduplication
* of equivalent transform nodes */
GeoTrfPtr makeTransform(const GeoTrf::Transform3D& trf) const; GeoTrfPtr makeTransform(const GeoTrf::Transform3D& trf) const;
/** @brief Take a GeoTransform node and adds it to the cahce. If transform deduplication
* is turned on and an equivalent transform node has been parsed before,
* then that mpde is returned instead */
GeoTrfPtr cacheTransform(GeoTrfPtr transform) const;
/** @brief Takes a GeoLogVol and adds it to the cache. If LogVol deduplication
* is turned on and an equivalent volume has been parsed before,
* then that volume is returned instead */
GeoLogVolPtr cacheVolume(GeoLogVolPtr vol) const; GeoLogVolPtr cacheVolume(GeoLogVolPtr vol) const;
/** @brief Takes a GeoShape and adds it to the cache. If shape deduplication
* is turned on and an equivalent shape has been parsed before,
* then that shape is returned instead */
GeoShapePtr cacheShape(GeoShapePtr shape) const; GeoShapePtr cacheShape(GeoShapePtr shape) const;
/** @brief Returns a new GeoName tag */
GeoNamePtr nameTag(const std::string& tagName) const;
/** @brief Returns a new GeoSerial Id */
GeoSerialIdPtr serialId(const int id) const;
/** @brief Toggles whether shape deduplication shall be enabled */
void setShapeDeDuplication(bool enable); void setShapeDeDuplication(bool enable);
/** @brief Toggles whether logVol deduplication shall be enabled */
void setLogVolDeDuplication(bool enable); void setLogVolDeDuplication(bool enable);
/** @brief Toggles whether transform node deduplication shall be enabled */
void setTransformDeDuplication(bool enable); void setTransformDeDuplication(bool enable);
/** @brief Toggles whether physVol node deduplication shall be enabled */
void setPhysVolDeDuplication(bool enable); void setPhysVolDeDuplication(bool enable);
/** @brief Clears the shared Shape / Transform / SerialId & NameTag cache */
static void clearSharedCaches();
private: private:
bool m_deDuplicateLogVol{true}; bool m_deDuplicateLogVol{true};
bool m_deDuplicatePhysVol{true}; bool m_deDuplicatePhysVol{true};
...@@ -94,12 +125,17 @@ class GeoDeDuplicator { ...@@ -94,12 +125,17 @@ class GeoDeDuplicator {
using LogVolSet = std::set<GeoLogVolPtr, GeoLogVolSorter>; using LogVolSet = std::set<GeoLogVolPtr, GeoLogVolSorter>;
using TrfSet = std::set<GeoTrfPtr, GeoTrf::TransformSorter>; using TrfSet = std::set<GeoTrfPtr, GeoTrf::TransformSorter>;
using ShapeSet = std::set<GeoShapePtr, GeoShapeSorter>; using ShapeSet = std::set<GeoShapePtr, GeoShapeSorter>;
using SerialIdMap = std::map<int, GeoSerialIdPtr>;
using NameTagMap = std::map<std::string, GeoNamePtr>;
mutable PhysVolSet m_physVolStore{}; mutable PhysVolSet m_physVolStore{};
mutable LogVolSet m_logVolStore{}; mutable LogVolSet m_logVolStore{};
mutable std::vector<GeoIntrusivePtr<const RCBase>> m_genericCache{}; mutable std::vector<GeoIntrusivePtr<const RCBase>> m_genericCache{};
static TrfSet s_trfStore; static TrfSet s_trfStore;
static ShapeSet s_shapeStore; static ShapeSet s_shapeStore;
static SerialIdMap s_serialIds;
static NameTagMap s_nameTags;
mutable std::mutex m_mutex{}; mutable std::mutex m_mutex{};
}; };
......
/* /*
Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
*/ */
#include "GeoModelHelpers/GeoDeDuplicator.h" #include "GeoModelHelpers/GeoDeDuplicator.h"
GeoDeDuplicator::TrfSet GeoDeDuplicator::s_trfStore{}; GeoDeDuplicator::TrfSet GeoDeDuplicator::s_trfStore{};
GeoDeDuplicator::ShapeSet GeoDeDuplicator::s_shapeStore{}; GeoDeDuplicator::ShapeSet GeoDeDuplicator::s_shapeStore{};
GeoDeDuplicator::SerialIdMap GeoDeDuplicator::s_serialIds{};
GeoDeDuplicator::NameTagMap GeoDeDuplicator::s_nameTags{};
namespace { namespace {
std::mutex s_mutex{}; std::mutex s_mutex{};
} }
...@@ -23,9 +26,19 @@ void GeoDeDuplicator::setPhysVolDeDuplication(bool enable) { ...@@ -23,9 +26,19 @@ void GeoDeDuplicator::setPhysVolDeDuplication(bool enable) {
m_deDuplicatePhysVol = enable; m_deDuplicatePhysVol = enable;
} }
void GeoDeDuplicator::clearSharedCaches() {
s_trfStore.clear();
s_shapeStore.clear();
s_serialIds.clear();
s_nameTags.clear();
}
GeoDeDuplicator::GeoTrfPtr GeoDeDuplicator::GeoTrfPtr
GeoDeDuplicator::makeTransform(const GeoTrf::Transform3D& trf) const { GeoDeDuplicator::makeTransform(const GeoTrf::Transform3D& trf) const {
GeoTrfPtr trfNode{make_intrusive<GeoTransform>(trf)}; return cacheTransform(make_intrusive<GeoTransform>(trf));
}
GeoDeDuplicator::GeoTrfPtr
GeoDeDuplicator::cacheTransform(GeoTrfPtr trfNode) const {
if (!m_deDuplicateTransform) { if (!m_deDuplicateTransform) {
std::lock_guard guard{m_mutex}; std::lock_guard guard{m_mutex};
m_genericCache.push_back(trfNode); m_genericCache.push_back(trfNode);
...@@ -62,3 +75,24 @@ GeoDeDuplicator::GeoShapePtr ...@@ -62,3 +75,24 @@ GeoDeDuplicator::GeoShapePtr
std::lock_guard guard{s_mutex}; std::lock_guard guard{s_mutex};
return *s_shapeStore.insert(shape).first; return *s_shapeStore.insert(shape).first;
} }
GeoDeDuplicator::GeoNamePtr GeoDeDuplicator::nameTag(const std::string& tagName) const{
std::lock_guard guard{s_mutex};
NameTagMap::const_iterator itr = s_nameTags.find(tagName);
if (itr != s_nameTags.end()){
return itr->second;
}
GeoNamePtr newTag = make_intrusive<GeoNameTag>(tagName);
s_nameTags.insert(std::make_pair(tagName, newTag));
return newTag;
}
GeoDeDuplicator::GeoSerialIdPtr GeoDeDuplicator::serialId(const int id) const {
std::lock_guard guard{s_mutex};
SerialIdMap::const_iterator itr = s_serialIds.find(id);
if (itr != s_serialIds.end()){
return itr->second;
}
GeoSerialIdPtr newId = make_intrusive<GeoSerialIdentifier>(id);
s_serialIds.insert(std::make_pair(id, newId));
return newId;
}
\ No newline at end of file
...@@ -25,21 +25,15 @@ class GeoNameTag : public GeoGraphNode ...@@ -25,21 +25,15 @@ class GeoNameTag : public GeoGraphNode
// Specifies the name of the next physical volume in the // Specifies the name of the next physical volume in the
// node tree. // node tree.
const std::string& getName () const; const std::string& getName() const {
return m_name;
}
protected: protected:
virtual ~GeoNameTag(); virtual ~GeoNameTag();
private: private:
GeoNameTag(const GeoNameTag &right); std::string m_name{};
GeoNameTag & operator=(const GeoNameTag &right);
std::string m_name;
}; };
inline const std::string& GeoNameTag::getName () const
{
return m_name;
}
#endif #endif
/* /*
Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
*/ */
#ifndef GEOMODELKERNEL_GEOSERIALIDENTIFIER_H #ifndef GEOMODELKERNEL_GEOSERIALIDENTIFIER_H
...@@ -13,30 +13,23 @@ ...@@ -13,30 +13,23 @@
#include "GeoModelKernel/GeoGraphNode.h" #include "GeoModelKernel/GeoGraphNode.h"
class GeoSerialIdentifier : public GeoGraphNode class GeoSerialIdentifier : public GeoGraphNode {
{
public: public:
GeoSerialIdentifier(int baseId); GeoSerialIdentifier(int baseId);
virtual void exec(GeoNodeAction *action) const; virtual void exec(GeoNodeAction *action) const;
inline int getBaseId() const; inline int getBaseId() const{
return m_baseId;
}
protected: protected:
virtual ~GeoSerialIdentifier(); virtual ~GeoSerialIdentifier();
private: private:
GeoSerialIdentifier(const GeoSerialIdentifier &right); int m_baseId{0};
const GeoSerialIdentifier & operator=(const GeoSerialIdentifier &right);
int m_baseId;
}; };
inline int GeoSerialIdentifier::getBaseId() const
{
return m_baseId;
}
#endif #endif
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