Skip to content

Surface finding faster (vector->map) #6

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

Closed
wants to merge 2 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
class G4VPhysicalVolume;
class G4LogicalBorderSurface;

typedef std::vector<G4LogicalBorderSurface*> G4LogicalBorderSurfaceTable;
typedef std::map<std::pair<const G4VPhysicalVolume*,const G4VPhysicalVolume*>, G4LogicalBorderSurface*> G4LogicalBorderSurfaceTable;

class G4LogicalBorderSurface : public G4LogicalSurface
{
Expand Down
18 changes: 8 additions & 10 deletions source/geometry/volumes/src/G4LogicalBorderSurface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
//
// ----------------------------------------------------------------------

#include <map>

#include "G4LogicalBorderSurface.hh"
#include "G4VPhysicalVolume.hh"

Expand All @@ -62,7 +64,7 @@ G4LogicalBorderSurface(const G4String& name,

// Store in the table of Surfaces
//
theBorderSurfaceTable->push_back(this);
theBorderSurfaceTable->insert(std::make_pair(std::make_pair(vol1,vol2),this));
}

G4LogicalBorderSurface::
Expand Down Expand Up @@ -143,12 +145,8 @@ G4LogicalBorderSurface::GetSurface(const G4VPhysicalVolume* vol1,
{
if (theBorderSurfaceTable)
{
for (size_t i=0; i<theBorderSurfaceTable->size(); i++)
{
if( ((*theBorderSurfaceTable)[i]->GetVolume1() == vol1) &&
((*theBorderSurfaceTable)[i]->GetVolume2() == vol2) )
return (*theBorderSurfaceTable)[i];
}
auto foundSurf = theBorderSurfaceTable->find(std::make_pair(vol1,vol2));
if(foundSurf != theBorderSurfaceTable->end()) return foundSurf->second;
}
return 0;
}
Expand All @@ -162,9 +160,9 @@ void G4LogicalBorderSurface::DumpInfo()

if (theBorderSurfaceTable)
{
for (size_t i=0; i<theBorderSurfaceTable->size(); i++)
for (auto it = theBorderSurfaceTable->begin(); it!= theBorderSurfaceTable->end(); ++it)
{
G4LogicalBorderSurface* pBorderSurface = (*theBorderSurfaceTable)[i];
G4LogicalBorderSurface* pBorderSurface = it->second;
G4cout << pBorderSurface->GetName() << " : " << G4endl
<< " Border of volumes "
<< pBorderSurface->GetVolume1()->GetName() << " and "
Expand All @@ -183,7 +181,7 @@ void G4LogicalBorderSurface::CleanSurfaceTable()
for(pos=theBorderSurfaceTable->begin();
pos!=theBorderSurfaceTable->end(); pos++)
{
if (*pos) { delete *pos; }
if (pos->second) { delete pos->second; }
}
theBorderSurfaceTable->clear();
}
Expand Down
5 changes: 2 additions & 3 deletions source/persistency/gdml/src/G4GDMLWriteStructure.cc
Original file line number Diff line number Diff line change
Expand Up @@ -348,10 +348,9 @@ G4GDMLWriteStructure::GetBorderSurface(const G4VPhysicalVolume* const pvol)
{
const G4LogicalBorderSurfaceTable* btable =
G4LogicalBorderSurface::GetSurfaceTable();
std::vector<G4LogicalBorderSurface*>::const_iterator pos;
for (pos = btable->begin(); pos != btable->end(); pos++)
for (auto pos : btable)
{
if (pvol == (*pos)->GetVolume1()) // just the first in the couple
if (pvol == pos->first.first) // just the first in the couple
{ // is enough
surf = *pos; break;
}
Expand Down