File indexing completed on 2025-07-13 07:50:04
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "Acts/Detector/DetectorVolume.hpp"
0012 #include "Acts/Detector/Portal.hpp"
0013 #include "Acts/Detector/interface/IGeometryIdGenerator.hpp"
0014 #include "Acts/Geometry/GeometryIdentifier.hpp"
0015 #include "Acts/Surfaces/Surface.hpp"
0016
0017 #include <map>
0018 #include <ranges>
0019
0020 namespace Acts::Experimental {
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034 template <typename SourceIdentifier, typename SourceCapture>
0035 class GeometryIdMapper final : public IGeometryIdGenerator {
0036 public:
0037
0038 struct Config {
0039
0040 std::map<SourceIdentifier, GeometryIdentifier> sourceTargetMap;
0041
0042 SourceCapture sourceCapture = SourceCapture();
0043 };
0044
0045
0046 struct Cache {
0047 unsigned int volumeCounter = 0u;
0048 unsigned int portalCounter = 0u;
0049 unsigned int surfaceCounter = 0u;
0050 };
0051
0052
0053
0054
0055
0056 explicit GeometryIdMapper(const Config& cfg,
0057 std::unique_ptr<const Logger> mlogger =
0058 getDefaultLogger("GeometryIdMapper",
0059 Logging::INFO))
0060 : m_cfg(cfg), m_logger(std::move(mlogger)) {}
0061
0062 ~GeometryIdMapper() override = default;
0063
0064
0065
0066 IGeometryIdGenerator::GeoIdCache generateCache() const final {
0067 return Cache{0u, 0u, 0u};
0068 }
0069
0070
0071
0072
0073
0074 void assignGeometryId(IGeometryIdGenerator::GeoIdCache& cache,
0075 DetectorVolume& dVolume) const final {
0076 auto& sCache = std::any_cast<Cache&>(cache);
0077
0078 SourceIdentifier vID = m_cfg.sourceCapture(dVolume);
0079 auto source = m_cfg.sourceTargetMap.find(vID);
0080 if (source != m_cfg.sourceTargetMap.end()) {
0081 dVolume.assignGeometryId(source->second);
0082 ACTS_VERBOSE("Assigning geometry id " << source->second << " to volume "
0083 << dVolume.name() << " with id "
0084 << vID);
0085 sCache.volumeCounter++;
0086 }
0087
0088
0089 std::ranges::for_each(dVolume.portalPtrs(), [&](auto& portal) {
0090 assignGeometryId(cache, *portal);
0091 });
0092
0093
0094 std::ranges::for_each(dVolume.surfacePtrs(), [&](auto& surface) {
0095 assignGeometryId(cache, *surface);
0096 });
0097
0098
0099 std::ranges::for_each(dVolume.volumePtrs(), [&](auto& volume) {
0100 assignGeometryId(cache, *volume);
0101 });
0102 }
0103
0104
0105
0106
0107
0108 void assignGeometryId(IGeometryIdGenerator::GeoIdCache& cache,
0109 Portal& portal) const final {
0110 auto& sCache = std::any_cast<Cache&>(cache);
0111
0112 SourceIdentifier pID = m_cfg.sourceCapture(portal);
0113 auto source = m_cfg.sourceTargetMap.find(pID);
0114 if (source != m_cfg.sourceTargetMap.end()) {
0115 portal.surface().assignGeometryId(source->second);
0116 ACTS_VERBOSE("Assigning geometry id " << source->second << " to portal "
0117 << " with id " << pID);
0118 sCache.portalCounter++;
0119 }
0120 }
0121
0122
0123
0124
0125
0126 void assignGeometryId(IGeometryIdGenerator::GeoIdCache& cache,
0127 Surface& surface) const final {
0128 auto& sCache = std::any_cast<Cache&>(cache);
0129
0130 SourceIdentifier sID = m_cfg.sourceCapture(surface);
0131 auto source = m_cfg.sourceTargetMap.find(sID);
0132 if (source != m_cfg.sourceTargetMap.end()) {
0133 ACTS_VERBOSE("Assigning geometry id " << source->second << " to surface "
0134 << " with id " << sID);
0135 surface.assignGeometryId(source->second);
0136 sCache.surfaceCounter++;
0137 }
0138 }
0139
0140 private:
0141
0142 Config m_cfg;
0143
0144
0145 const Logger& logger() const { return *m_logger; }
0146
0147
0148 std::unique_ptr<const Logger> m_logger;
0149 };
0150
0151 }