Skip to content

Commit

Permalink
GeoHandler: make collect give deterministic volume order
Browse files Browse the repository at this point in the history
  • Loading branch information
andresailer committed May 30, 2024
1 parent 704911a commit d5238ce
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
8 changes: 4 additions & 4 deletions DDCore/include/DD4hep/GeoHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,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 @@ -108,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 @@ -119,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 @@ -131,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
14 changes: 9 additions & 5 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 Down Expand Up @@ -53,11 +54,11 @@ namespace {

/// 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 @@ -70,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 @@ -149,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

0 comments on commit d5238ce

Please sign in to comment.