Commit 392bcf03 authored by Sandro Christian Wenzel's avatar Sandro Christian Wenzel
Browse files

Add manager class for flat voxel structures

A singleton instance keeping, per logical volume, flat (cubic) voxel structures for
locate and safety calculations.
Follows the logic from similar existing manager classes.

Make a helper function of BoxSafetyEstimator public static so that it can be used
outside (minor clang-format cleanup included).
parent d90b4dc9
......@@ -719,7 +719,8 @@ set(VECGEOM_SRCS
source/Wedge_Evolution.cpp
source/ABBoxManager.cpp
source/HybridManager2.cpp
source/FlatVoxelManager.cpp
source/MessageLogger.cpp
services/NavigationSpecializer.cpp
......
// This file is part of VecGeom and is distributed under the
// conditions in the file LICENSE.txt in the top directory.
// For the full list of authors see CONTRIBUTORS.txt and `git log`.
/// \author created by Sandro Wenzel
#ifndef VECGEOM_MANAGEMENT_FLATVOXELMANAGER_H_
#define VECGEOM_MANAGEMENT_FLATVOXELMANAGER_H_
#include "base/Global.h"
#include "volumes/PlacedVolume.h"
#include "volumes/LogicalVolume.h"
#include "base/Vector3D.h"
#include "management/GeoManager.h"
#include "base/FlatVoxelHashMap.h"
#include <vector>
namespace vecgeom {
inline namespace VECGEOM_IMPL_NAMESPACE {
class VPlacedVolume;
// A singleton class which manages structures for fast voxelized safety lookup
class FlatVoxelManager {
public:
// the actual class encapsulating the Embree structures
struct VoxelStructure {
FlatVoxelHashMap<float, true> *fVoxels = nullptr; // voxels keeping track of best known safety
FlatVoxelHashMap<int, false> *fVoxelToCandidate =
nullptr; // keep list of candidate objects to check for safety (-1 = mother, ...)
FlatVoxelHashMap<int, false> *fVoxelToLocateCandidates =
nullptr; // keep list of candidate objects to check for LevelLocate
LogicalVolume const *fVol = nullptr; // keep track to which volume this belongs
};
private:
// keeps/registers an acceleration structure for logical volumes
std::vector<VoxelStructure const *> fStructureHolder;
public:
// initialized the helper structure for a given logical volume
void InitStructure(LogicalVolume const *lvol);
static FlatVoxelManager &Instance()
{
static FlatVoxelManager manager;
return manager;
}
// removed/deletes the helper structure for a given logical volume
void RemoveStructure(LogicalVolume const *lvol);
VoxelStructure const *GetStructure(LogicalVolume const *lvol) const { return fStructureHolder[lvol->id()]; }
static VoxelStructure *BuildStructure(LogicalVolume const *lvol);
static FlatVoxelHashMap<int, false> *BuildLocateVoxels(LogicalVolume const *lvol);
static FlatVoxelHashMap<int, false> *BuildSafetyVoxels(LogicalVolume const *lvol);
private:
// save to TFile
static void dumpToTFile(const char *name, std::vector<float> const &xs, std::vector<float> const &ys,
std::vector<float> const &zs, std::vector<long> const &keys,
std::vector<float> const &safeties);
// save to TFile
static void dumpToTFile(const char *name, SOA3D<float> const &points, std::vector<long> const &keys,
std::vector<float> const &safeties);
// read from TFile; return true if successful
static bool readFromTFile(const char *name, std::vector<float> &xs, std::vector<float> &ys, std::vector<float> &zs,
std::vector<long> &keys, std::vector<float> &safeties);
static bool readFromTFile(const char *name, SOA3D<float> &points, std::vector<long> &keys,
std::vector<float> &safeties);
// create a name for the backup file
static std::string createName(LogicalVolume const *, int kx, int ky, int kz);
}; // end class
} // namespace VECGEOM_IMPL_NAMESPACE
} // namespace vecgeom
#endif /* MANAGEMENT_FLATVOXELMANAGER_H_ */
......@@ -35,10 +35,11 @@ private:
return lvol->GetDaughtersp()->operator[](id);
}
public:
// helper function calculating some candidate volumes
size_t GetSafetyCandidates_v(Vector3D<Precision> const &point, ABBoxManager::ABBoxContainer_v const &corners,
size_t size, ABBoxManager::BoxIdDistancePair_t *boxsafetypairs,
Precision upper_squared_limit) const
static size_t GetSafetyCandidates_v(Vector3D<Precision> const &point, ABBoxManager::ABBoxContainer_v const &corners,
size_t size, ABBoxManager::BoxIdDistancePair_t *boxsafetypairs,
Precision upper_squared_limit)
{
size_t count = 0;
Vector3D<float> pointfloat((float)point.x(), (float)point.y(), (float)point.z());
......@@ -62,7 +63,6 @@ private:
return count;
}
private:
VECGEOM_FORCE_INLINE
VECCORE_ATT_HOST_DEVICE
Precision TreatSafetyToIn(Vector3D<Precision> const &localpoint, LogicalVolume const *lvol, Precision outsafety) const
......@@ -132,8 +132,8 @@ public:
virtual Real_v ComputeSafetyForLocalPoint(Vector3D<Real_v> const &localpoint, VPlacedVolume const *pvol,
Bool_v m) const override
{
using vecCore::LaneAt;
using vecCore::AssignLane;
using vecCore::LaneAt;
Real_v safety(0.);
if (!vecCore::MaskEmpty(m)) {
// SIMD safety to mother
......@@ -215,7 +215,7 @@ public:
}
}; // end class
}
} // end namespace
} // namespace VECGEOM_IMPL_NAMESPACE
} // namespace vecgeom
#endif /* NAVIGATION_SIMPLEABBOXSAFETYESTIMATOR_H_ */
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment