Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:26:05

0001 // This file is part of VecGeom and is distributed under the
0002 // conditions in the file LICENSE.txt in the top directory.
0003 // For the full list of authors see CONTRIBUTORS.txt and `git log`.
0004 
0005 /// \brief Geometry physical node tree visitors.
0006 /// \file management/GeoVisitor.h
0007 /// \author Split from GeoManager based on implementation by Philippe Canal and Sandro Wenzel
0008 
0009 #ifndef VECGEOM_MANAGEMENT_GEOVISITOR_H_
0010 #define VECGEOM_MANAGEMENT_GEOVISITOR_H_
0011 
0012 #include "VecGeom/base/Global.h"
0013 #include "VecGeom/volumes/PlacedVolume.h"
0014 #include "VecGeom/volumes/LogicalVolume.h"
0015 #include "VecGeom/navigation/NavStateFwd.h"
0016 
0017 namespace vecgeom {
0018 inline namespace VECGEOM_IMPL_NAMESPACE {
0019 
0020 /// A visitor functor interface used when iterating over the geometry tree.
0021 template <typename Container>
0022 class GeoVisitor {
0023 protected:
0024   Container &c_;
0025 
0026 public:
0027   GeoVisitor(Container &c) : c_(c){};
0028 
0029   virtual void apply(VPlacedVolume *, int level = 0) = 0;
0030   virtual ~GeoVisitor() {}
0031 };
0032 
0033 /// A visitor functor interface used when iterating over the geometry tree.
0034 /// This visitor gets injected path information.
0035 template <typename Container>
0036 class GeoVisitorWithAccessToPath {
0037 protected:
0038   Container &c_;
0039 
0040 public:
0041   GeoVisitorWithAccessToPath(Container &c) : c_(c){};
0042 
0043   virtual void apply(NavigationState *state, int level = 0) = 0;
0044   virtual ~GeoVisitorWithAccessToPath() {}
0045 };
0046 
0047 /// A visitor functor interface used when iterating over the geometry tree.
0048 /// This visitor gets injected path information, the mother navigation index and the current daughter index
0049 class GeoVisitorNavIndex {
0050 
0051 public:
0052   GeoVisitorNavIndex(){};
0053 
0054   virtual NavIndex_t apply(NavStatePath *state, int level, NavIndex_t mother, int dind) = 0;
0055   virtual ~GeoVisitorNavIndex() {}
0056 };
0057 
0058 /// A basic implementation of a GeoVisitor.
0059 template <typename Container>
0060 class SimpleLogicalVolumeVisitor : public GeoVisitor<Container> {
0061 public:
0062   SimpleLogicalVolumeVisitor(Container &c) : GeoVisitor<Container>(c) {}
0063   virtual void apply(VPlacedVolume *vol, int /*level*/)
0064   {
0065     LogicalVolume const *lvol = vol->GetLogicalVolume();
0066     if (std::find(this->c_.begin(), this->c_.end(), lvol) == this->c_.end()) {
0067       this->c_.push_back(const_cast<LogicalVolume *>(lvol));
0068     }
0069   }
0070   virtual ~SimpleLogicalVolumeVisitor() {}
0071 };
0072 
0073 template <typename Container>
0074 class SimplePlacedVolumeVisitor : public GeoVisitor<Container> {
0075 public:
0076   SimplePlacedVolumeVisitor(Container &c) : GeoVisitor<Container>(c) {}
0077   virtual void apply(VPlacedVolume *vol, int /* level */) { this->c_.push_back(vol); }
0078   virtual ~SimplePlacedVolumeVisitor() {}
0079 };
0080 
0081 /// A visitor to find out the geometry depth.
0082 class GetMaxDepthVisitor {
0083 private:
0084   int maxdepth_;
0085 
0086 public:
0087   GetMaxDepthVisitor() : maxdepth_(0) {}
0088   void apply(VPlacedVolume * /* vol */, int level) { maxdepth_ = (level > maxdepth_) ? level : maxdepth_; }
0089   int getMaxDepth() const { return maxdepth_; }
0090 };
0091 
0092 /// A visitor to find out the total number of geometry nodes.
0093 class GetTotalNodeCountVisitor {
0094 private:
0095   int fTotalNodeCount;
0096 
0097 public:
0098   GetTotalNodeCountVisitor() : fTotalNodeCount(0) {}
0099   void apply(VPlacedVolume *, int /* level */) { fTotalNodeCount++; }
0100   int GetTotalNodeCount() const { return fTotalNodeCount; }
0101 };
0102 
0103 } // namespace VECGEOM_IMPL_NAMESPACE
0104 } // namespace vecgeom
0105 
0106 #endif // VECGEOM_MANAGEMENT_GEOVISITOR_H_