Skip to content
Snippets Groups Projects
Commit 79bf7594 authored by Johannes Junggeburth's avatar Johannes Junggeburth :dog2:
Browse files

Add clone volume function

parent 819352d0
No related branches found
No related tags found
2 merge requests!401GeoDeDuplicator - Add GeoId,!400GeoDeDuplicator - Cache GeoIdentifiers & introduce a cloneVolume method
Pipeline #9908847 passed
......@@ -7,6 +7,9 @@
#include "GeoModelKernel/GeoPhysVol.h"
#include "GeoModelKernel/GeoShape.h"
#include "GeoModelKernel/GeoTransform.h"
#include "GeoModelKernel/GeoAlignableTransform.h"
#include "GeoModelKernel/GeoPhysVol.h"
#include "GeoModelKernel/GeoFullPhysVol.h"
#include "GeoModelKernel/GeoSerialIdentifier.h"
#include "GeoModelKernel/GeoNameTag.h"
#include "GeoModelKernel/GeoIdentifierTag.h"
......@@ -109,6 +112,10 @@ class GeoDeDuplicator {
/** @brief Returns a new GeoIdentifier tag */
GeoIdPtr geoId(const int id) const;
/** @brief Clones a physical volume. All components in the tree are
* parsed through the deduplication chain */
PVLink clone(PVConstLink vol) const;
/** @brief Toggles whether shape deduplication shall be enabled */
void setShapeDeDuplication(bool enable);
/** @brief Toggles whether logVol deduplication shall be enabled */
......@@ -117,7 +124,6 @@ class GeoDeDuplicator {
void setTransformDeDuplication(bool enable);
/** @brief Toggles whether physVol node deduplication shall be enabled */
void setPhysVolDeDuplication(bool enable);
/** @brief Clears the shared Shape / Transform / SerialId & NameTag cache */
static void clearSharedCaches();
private:
......
......@@ -109,4 +109,48 @@ GeoDeDuplicator::GeoIdPtr
GeoIdPtr newId = make_intrusive<GeoIdentifierTag>(id);
s_geoIds.insert(std::make_pair(id, newId));
return newId;
}
PVLink GeoDeDuplicator::clone(PVConstLink vol) const {
PVLink newVol{};
bool tryPhysVolDeDup{m_deDuplicatePhysVol};
GeoLogVolPtr logVol{const_cast<GeoLogVol*>(vol->getLogVol())};
if (dynamic_cast<const GeoPhysVol*>(vol.get())) {
newVol = make_intrusive<GeoPhysVol>(cacheVolume(logVol));
} else {
newVol = make_intrusive<GeoFullPhysVol>(cacheVolume(logVol));
tryPhysVolDeDup = false;
}
for(unsigned int chNode =0; chNode < newVol->getNChildNodes(); ++chNode) {
GeoIntrusivePtr<const GeoGraphNode>node{*newVol->getChildNode(chNode)};
/** transform nodes */
if (typeid(*node) == typeid(GeoAlignableTransform)) {
const auto geoTrf = dynamic_pointer_cast<const GeoAlignableTransform>(node);
newVol->add(make_intrusive<GeoAlignableTransform>(geoTrf->getDefTransform()));
} else if (typeid(*node) == typeid(GeoTransform)) {
const auto geoTrf = dynamic_pointer_cast<const GeoTransform>(node);
auto geoTrfNonConst = const_pointer_cast(geoTrf);
newVol->add(cacheTransform(geoTrfNonConst));
}
/** physical volumes */
else if (auto physVol = dynamic_pointer_cast<const GeoVPhysVol>(node); physVol) {
newVol->add(clone(physVol));
} else if (auto geoId = dynamic_pointer_cast<const GeoIdentifierTag>(node); geoId) {
std::lock_guard guard{s_mutex};
newVol->add(s_geoIds.insert(std::make_pair(geoId->getIdentifier(), const_pointer_cast(geoId))).first->second);
} else if (auto serialId = dynamic_pointer_cast<const GeoSerialIdentifier>(node); serialId) {
std::lock_guard guard{s_mutex};
newVol->add(s_serialIds.insert(std::make_pair(serialId->getBaseId(), const_pointer_cast(serialId))).first->second);
} else if (auto nameTag = dynamic_pointer_cast<const GeoNameTag>(node); nameTag) {
std::lock_guard guard{s_mutex};
newVol->add(s_nameTags.insert(std::make_pair(nameTag->getName(), const_pointer_cast(nameTag))).first->second);
} else {
/// Just copy what's left
newVol->add(const_pointer_cast(node));
}
}
if (tryPhysVolDeDup){
newVol = cacheVolume(dynamic_pointer_cast<GeoPhysVol>(newVol));
}
return newVol;
}
\ No newline at end of file
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