Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GeoHandler: store shapes in deterministic order #1277

Merged
merged 2 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions DDCore/include/DD4hep/GeoHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ namespace dd4hep {
*/
class GeometryInfo {
public:
std::set<TGeoShape*> solids;
std::vector<TGeoShape*> solids;
std::set<TGeoShape*> solid_set;
std::set<Volume> volumeSet;
std::vector<Volume> volumes;
std::set<VisAttr> vis;
Expand Down Expand Up @@ -87,7 +88,7 @@ namespace dd4hep {

protected:
bool m_propagateRegions { false };
std::map<int, std::set<const TGeoNode*> >* m_data { nullptr };
std::map<int, std::vector<const TGeoNode*> >* m_data { nullptr };
std::map<const TGeoNode*, std::vector<TGeoNode*> >* m_daughters { nullptr };
/// Internal helper to collect geometry information from traversal
GeoHandler& i_collect(const TGeoNode* parent,
Expand All @@ -107,7 +108,7 @@ namespace dd4hep {
/// Default constructor
GeoHandler();
/// Initializing constructor
GeoHandler(std::map<int, std::set<const TGeoNode*> >* ptr,
GeoHandler(std::map<int, std::vector<const TGeoNode*> >* ptr,
std::map<const TGeoNode*, std::vector<TGeoNode*> >* daus = nullptr);
/// Default destructor
virtual ~GeoHandler();
Expand All @@ -118,7 +119,7 @@ namespace dd4hep {
/// Collect geometry information from traversal with aggregated information
GeoHandler& collect(DetElement top, GeometryInfo& info);
/// Access to collected node list
std::map<int, std::set<const TGeoNode*> >* release();
std::map<int, std::vector<const TGeoNode*> >* release();
};

/// Geometry scanner (handle object)
Expand All @@ -130,7 +131,7 @@ namespace dd4hep {
class GeoScan {
protected:
/// Data holder
std::map<int, std::set<const TGeoNode*> >* m_data;
std::map<int, std::vector<const TGeoNode*> >* m_data;
public:
/// Initializing constructor
GeoScan(DetElement e);
Expand Down
18 changes: 12 additions & 6 deletions DDCore/src/GeoHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <TClass.h>

// C/C++ include files
#include <algorithm>
#include <iostream>

using namespace dd4hep;
Expand All @@ -44,18 +45,20 @@ namespace {
collectSolid(geo, name + "_left", name + "_left", boolean->GetLeftShape(), boolean->GetLeftMatrix());
collectSolid(geo, name + "_right", name + "_right", boolean->GetRightShape(), boolean->GetRightMatrix());
}
geo.solids.emplace(shape);
if(geo.solid_set.emplace(shape).second) {
geo.solids.push_back(shape);
}
geo.trafos.emplace_back(node, matrix);
}
}

/// Default constructor
detail::GeoHandler::GeoHandler() {
m_data = new std::map<int, std::set<const TGeoNode*> >();
m_data = new std::map<int, std::vector<const TGeoNode*> >();
}

/// Initializing constructor
detail::GeoHandler::GeoHandler(std::map<int, std::set<const TGeoNode*> >* ptr,
detail::GeoHandler::GeoHandler(std::map<int, std::vector<const TGeoNode*> >* ptr,
std::map<const TGeoNode*, std::vector<TGeoNode*> >* daus)
: m_data(ptr), m_daughters(daus)
{
Expand All @@ -68,8 +71,8 @@ detail::GeoHandler::~GeoHandler() {
m_data = nullptr;
}

std::map<int, std::set<const TGeoNode*> >* detail::GeoHandler::release() {
std::map<int, std::set<const TGeoNode*> >* d = m_data;
std::map<int, std::vector<const TGeoNode*> >* detail::GeoHandler::release() {
std::map<int, std::vector<const TGeoNode*> >* d = m_data;
m_data = nullptr;
return d;
}
Expand Down Expand Up @@ -147,7 +150,10 @@ detail::GeoHandler& detail::GeoHandler::i_collect(const TGeoNode* /* parent */,
}
}
/// Collect the hierarchy of placements
(*m_data)[level].emplace(current);
auto& vec = (*m_data)[level];
if(std::find(vec.begin(), vec.end(), current) == vec.end()) {
(*m_data)[level].push_back(current);
}
int num = nodes ? nodes->GetEntriesFast() : 0;
for (int i = 0; i < num; ++i)
i_collect(current, (TGeoNode*)nodes->At(i), level + 1, region, limits);
Expand Down
2 changes: 1 addition & 1 deletion DDG4/src/Geant4Converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1689,7 +1689,7 @@ Geant4Converter& Geant4Converter::create(DetElement top) {
handleRMap(this, *m_data, &Geant4Converter::handleAssembly);
// Now place all this stuff appropriately
//handleRMap(this, *m_data, &Geant4Converter::handlePlacement);
std::map<int, std::set<const TGeoNode*> >::const_reverse_iterator i = m_data->rbegin();
std::map<int, std::vector<const TGeoNode*> >::const_reverse_iterator i = m_data->rbegin();
for ( ; i != m_data->rend(); ++i ) {
for ( const TGeoNode* node : i->second ) {
#if 0
Expand Down
Loading