diff --git a/source/geometry/volumes/include/G4LogicalBorderSurface.hh b/source/geometry/volumes/include/G4LogicalBorderSurface.hh index 95ef77356db1f6f702be0530659d5855763a4a9c..4cea8c1077b44696569896b1c9b9540ac49cbb0e 100644 --- a/source/geometry/volumes/include/G4LogicalBorderSurface.hh +++ b/source/geometry/volumes/include/G4LogicalBorderSurface.hh @@ -31,12 +31,11 @@ // of two physical volumes. // Author: John Apostolakis (John.Apostolakis@cern.ch), 17-06-1997 -// // -------------------------------------------------------------------- -#ifndef G4LogicalBorderSurface_h -#define G4LogicalBorderSurface_h 1 +#ifndef G4LogicalBorderSurface_hh +#define G4LogicalBorderSurface_hh 1 -#include <vector> +#include <map> #include "G4LogicalSurface.hh" #include "G4VPhysicalVolume.hh" @@ -44,12 +43,14 @@ class G4VPhysicalVolume; class G4LogicalBorderSurface; -using G4LogicalBorderSurfaceTable = std::vector<G4LogicalBorderSurface*>; +using G4LogicalBorderSurfaceTable + = std::map<std::pair<const G4VPhysicalVolume*, + const G4VPhysicalVolume*>, G4LogicalBorderSurface*>; class G4LogicalBorderSurface : public G4LogicalSurface { - public: // with description + public: G4LogicalBorderSurface( const G4String& name, G4VPhysicalVolume* vol1, @@ -64,7 +65,7 @@ class G4LogicalBorderSurface : public G4LogicalSurface G4bool operator==( const G4LogicalBorderSurface& right ) const; G4bool operator!=( const G4LogicalBorderSurface& right ) const; - // Operators. + // Operators static G4LogicalBorderSurface* GetSurface( const G4VPhysicalVolume* vol1, const G4VPhysicalVolume* vol2 ); @@ -72,7 +73,8 @@ class G4LogicalBorderSurface : public G4LogicalSurface G4VPhysicalVolume* vol2 ); inline const G4VPhysicalVolume* GetVolume1() const; inline const G4VPhysicalVolume* GetVolume2() const; - // Generic accessors. + inline std::size_t GetIndex() const; + // Generic accessors inline void SetVolume1( G4VPhysicalVolume* vol1 ); inline void SetVolume2( G4VPhysicalVolume* vol2 ); @@ -80,17 +82,19 @@ class G4LogicalBorderSurface : public G4LogicalSurface static void CleanSurfaceTable(); static const G4LogicalBorderSurfaceTable* GetSurfaceTable(); - static size_t GetNumberOfBorderSurfaces(); + static std::size_t GetNumberOfBorderSurfaces(); static void DumpInfo(); - // To handle the table of surfaces. + // To handle the table of surfaces private: G4VPhysicalVolume* Volume1; // Physical Volume pointer on side 1 G4VPhysicalVolume* Volume2; // Physical Volume pointer on side 2 + std::size_t Index; // Creation order index + static G4LogicalBorderSurfaceTable *theBorderSurfaceTable; - // The static Table of BorderSurfaces. + // The static Table of BorderSurfaces }; // ******************************************************************** @@ -99,5 +103,4 @@ class G4LogicalBorderSurface : public G4LogicalSurface #include "G4LogicalBorderSurface.icc" -#endif /* G4LogicalBorderSurface_h */ - +#endif diff --git a/source/geometry/volumes/include/G4LogicalBorderSurface.icc b/source/geometry/volumes/include/G4LogicalBorderSurface.icc index 42b378076d7526aacc1b71d22c7993fc1250e3ed..279f59acf7154e4509aca2753cc0877fdbf0ff0a 100644 --- a/source/geometry/volumes/include/G4LogicalBorderSurface.icc +++ b/source/geometry/volumes/include/G4LogicalBorderSurface.icc @@ -23,7 +23,7 @@ // * acceptance of all terms of the Geant4 Software license. * // ******************************************************************** // -// class G4LogicalBorderSurface inline implementation +// G4LogicalBorderSurface inline implementation // // ---------------------------------------------------------------------- @@ -47,6 +47,12 @@ const G4VPhysicalVolume* G4LogicalBorderSurface::GetVolume2() const return Volume2; } +inline +std::size_t G4LogicalBorderSurface::GetIndex() const +{ + return Index; +} + inline void G4LogicalBorderSurface::SetVolume1(G4VPhysicalVolume* vol1) { diff --git a/source/geometry/volumes/src/G4LogicalBorderSurface.cc b/source/geometry/volumes/src/G4LogicalBorderSurface.cc index 6d623dec21d042b24fd465b978cc42dc3f74f0c5..63299096b01b8d79b6973169a9d59550dcde6e88 100644 --- a/source/geometry/volumes/src/G4LogicalBorderSurface.cc +++ b/source/geometry/volumes/src/G4LogicalBorderSurface.cc @@ -29,7 +29,7 @@ // of two physical volumes. // // Author: John Apostolakis (John.Apostolakis@cern.ch), 26-06-1997 -// ---------------------------------------------------------------------- +// -------------------------------------------------------------------- #include "G4LogicalBorderSurface.hh" #include "G4VPhysicalVolume.hh" @@ -47,16 +47,17 @@ G4LogicalBorderSurface(const G4String& name, G4VPhysicalVolume* vol2, G4SurfaceProperty* surfaceProperty) : G4LogicalSurface(name, surfaceProperty), - Volume1(vol1), Volume2(vol2) + Volume1(vol1), Volume2(vol2), + Index(theBorderSurfaceTable != nullptr ? theBorderSurfaceTable->size() : 0) { - if (!theBorderSurfaceTable) + if (theBorderSurfaceTable == nullptr) { theBorderSurfaceTable = new G4LogicalBorderSurfaceTable; } // Store in the table of Surfaces // - theBorderSurfaceTable->push_back(this); + theBorderSurfaceTable->insert(std::make_pair(std::make_pair(vol1,vol2),this)); } G4LogicalBorderSurface::~G4LogicalBorderSurface() @@ -92,7 +93,7 @@ const G4LogicalBorderSurfaceTable* G4LogicalBorderSurface::GetSurfaceTable() return theBorderSurfaceTable; } -size_t G4LogicalBorderSurface::GetNumberOfBorderSurfaces() +std::size_t G4LogicalBorderSurface::GetNumberOfBorderSurfaces() { if (theBorderSurfaceTable != nullptr) { @@ -107,14 +108,10 @@ G4LogicalBorderSurface::GetSurface(const G4VPhysicalVolume* vol1, { if (theBorderSurfaceTable != nullptr) { - for(auto pos = theBorderSurfaceTable->cbegin(); - pos != theBorderSurfaceTable->cend(); ++pos) - { - if( (*pos)->GetVolume1() == vol1 && (*pos)->GetVolume2() == vol2 ) - { return *pos; } - } + auto pos = theBorderSurfaceTable->find(std::make_pair(vol1,vol2)); + if(pos != theBorderSurfaceTable->cend()) return pos->second; } - return 0; + return nullptr; } // Dump info for known surfaces @@ -129,11 +126,11 @@ void G4LogicalBorderSurface::DumpInfo() for(auto pos = theBorderSurfaceTable->cbegin(); pos != theBorderSurfaceTable->cend(); ++pos) { - G4cout << (*pos)->GetName() << " : " << G4endl + G4LogicalBorderSurface* pSurf = pos->second; + G4cout << pSurf->GetName() << " : " << G4endl << " Border of volumes " - << (*pos)->GetVolume1()->GetName() << " and " - << (*pos)->GetVolume2()->GetName() - << G4endl; + << pSurf->GetVolume1()->GetName() << " and " + << pSurf->GetVolume2()->GetName() << G4endl; } } G4cout << G4endl; @@ -146,7 +143,7 @@ void G4LogicalBorderSurface::CleanSurfaceTable() for(auto pos = theBorderSurfaceTable->cbegin(); pos != theBorderSurfaceTable->cend(); ++pos) { - if (*pos) { delete *pos; } + if (pos->second) { delete pos->second; } } theBorderSurfaceTable->clear(); } diff --git a/source/persistency/gdml/src/G4GDMLWriteStructure.cc b/source/persistency/gdml/src/G4GDMLWriteStructure.cc index 667eb36a0c6262ac4b49051daa4d4a3d8cc3a3f1..f1829aaca230e9afea12ab00b2874fd80b330d61 100644 --- a/source/persistency/gdml/src/G4GDMLWriteStructure.cc +++ b/source/persistency/gdml/src/G4GDMLWriteStructure.cc @@ -288,48 +288,52 @@ void G4GDMLWriteStructure::AssemblyWrite(xercesc::DOMElement* volumeElement, } -void G4GDMLWriteStructure:: -BorderSurfaceCache(const G4LogicalBorderSurface* const bsurf) +void G4GDMLWriteStructure::BorderSurfaceCache( + const G4LogicalBorderSurface* const bsurf) { - if (!bsurf) { return; } - - const G4SurfaceProperty* psurf = bsurf->GetSurfaceProperty(); - - // Generate the new element for border-surface - // - const G4String& bsname = GenerateName(bsurf->GetName(), bsurf); - const G4String& psname = GenerateName(psurf->GetName(), psurf); - xercesc::DOMElement* borderElement = NewElement("bordersurface"); - borderElement->setAttributeNode(NewAttribute("name", bsname)); - borderElement->setAttributeNode(NewAttribute("surfaceproperty", psname)); - - const G4String volumeref1 = GenerateName(bsurf->GetVolume1()->GetName(), - bsurf->GetVolume1()); - const G4String volumeref2 = GenerateName(bsurf->GetVolume2()->GetName(), - bsurf->GetVolume2()); - xercesc::DOMElement* volumerefElement1 = NewElement("physvolref"); - xercesc::DOMElement* volumerefElement2 = NewElement("physvolref"); - volumerefElement1->setAttributeNode(NewAttribute("ref",volumeref1)); - volumerefElement2->setAttributeNode(NewAttribute("ref",volumeref2)); - borderElement->appendChild(volumerefElement1); - borderElement->appendChild(volumerefElement2); + if(bsurf == nullptr) + { + return; + } - if (FindOpticalSurface(psurf)) - { - const G4OpticalSurface* opsurf = - dynamic_cast<const G4OpticalSurface*>(psurf); - if (!opsurf) - { - G4Exception("G4GDMLWriteStructure::BorderSurfaceCache()", - "InvalidSetup", FatalException, "No optical surface found!"); - return; - } - OpticalSurfaceWrite(solidsElement, opsurf); - } + const G4SurfaceProperty* psurf = bsurf->GetSurfaceProperty(); + + // Generate the new element for border-surface + // + const G4String& bsname = GenerateName(bsurf->GetName(), bsurf); + const G4String& psname = GenerateName(psurf->GetName(), psurf); + xercesc::DOMElement* borderElement = NewElement("bordersurface"); + borderElement->setAttributeNode(NewAttribute("name", bsname)); + borderElement->setAttributeNode(NewAttribute("surfaceproperty", psname)); + + const G4String volumeref1 = + GenerateName(bsurf->GetVolume1()->GetName(), bsurf->GetVolume1()); + const G4String volumeref2 = + GenerateName(bsurf->GetVolume2()->GetName(), bsurf->GetVolume2()); + xercesc::DOMElement* volumerefElement1 = NewElement("physvolref"); + xercesc::DOMElement* volumerefElement2 = NewElement("physvolref"); + volumerefElement1->setAttributeNode(NewAttribute("ref", volumeref1)); + volumerefElement2->setAttributeNode(NewAttribute("ref", volumeref2)); + borderElement->appendChild(volumerefElement1); + borderElement->appendChild(volumerefElement2); + + if(FindOpticalSurface(psurf)) + { + const G4OpticalSurface* opsurf = + dynamic_cast<const G4OpticalSurface*>(psurf); + if(opsurf == nullptr) + { + G4Exception("G4GDMLWriteStructure::BorderSurfaceCache()", "InvalidSetup", + FatalException, "No optical surface found!"); + return; + } + OpticalSurfaceWrite(solidsElement, opsurf); + } - borderElementVec.push_back(borderElement); + borderElementVec.push_back(borderElement); } + void G4GDMLWriteStructure:: SkinSurfaceCache(const G4LogicalSkinSurface* const ssurf) { @@ -399,21 +403,20 @@ G4GDMLWriteStructure::GetSkinSurface(const G4LogicalVolume* const lvol) return surf; } -const G4LogicalBorderSurface* -G4GDMLWriteStructure::GetBorderSurface(const G4VPhysicalVolume* const pvol) +const G4LogicalBorderSurface* G4GDMLWriteStructure::GetBorderSurface( + const G4VPhysicalVolume* const pvol) { - G4LogicalBorderSurface* surf = 0; + G4LogicalBorderSurface* surf = nullptr; G4int nsurf = G4LogicalBorderSurface::GetNumberOfBorderSurfaces(); - if (nsurf) + if(nsurf) { const G4LogicalBorderSurfaceTable* btable = - G4LogicalBorderSurface::GetSurfaceTable(); - std::vector<G4LogicalBorderSurface*>::const_iterator pos; - for (pos = btable->begin(); pos != btable->end(); pos++) + G4LogicalBorderSurface::GetSurfaceTable(); + for(auto pos = btable->cbegin(); pos != btable->cend(); ++pos) { - if (pvol == (*pos)->GetVolume1()) // just the first in the couple - { // could be enough? - surf = *pos; // break; + if(pvol == pos->first.first) // just the first in the couple + { // could be enough? + surf = pos->second; // break; BorderSurfaceCache(surf); } }