File indexing completed on 2025-10-27 07:55: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
0048 unsigned int volumeCounter = 0u;
0049
0050 unsigned int portalCounter = 0u;
0051
0052 unsigned int surfaceCounter = 0u;
0053 };
0054
0055
0056
0057
0058
0059 explicit GeometryIdMapper(const Config& cfg,
0060 std::unique_ptr<const Logger> mlogger =
0061 getDefaultLogger("GeometryIdMapper",
0062 Logging::INFO))
0063 : m_cfg(cfg), m_logger(std::move(mlogger)) {}
0064
0065 ~GeometryIdMapper() override = default;
0066
0067
0068
0069 IGeometryIdGenerator::GeoIdCache generateCache() const final {
0070 return Cache{0u, 0u, 0u};
0071 }
0072
0073
0074
0075
0076
0077 void assignGeometryId(IGeometryIdGenerator::GeoIdCache& cache,
0078 DetectorVolume& dVolume) const final {
0079 auto& sCache = std::any_cast<Cache&>(cache);
0080
0081 SourceIdentifier vID = m_cfg.sourceCapture(dVolume);
0082 auto source = m_cfg.sourceTargetMap.find(vID);
0083 if (source != m_cfg.sourceTargetMap.end()) {
0084 dVolume.assignGeometryId(source->second);
0085 ACTS_VERBOSE("Assigning geometry id " << source->second << " to volume "
0086 << dVolume.name() << " with id "
0087 << vID);
0088 sCache.volumeCounter++;
0089 }
0090
0091
0092 std::ranges::for_each(dVolume.portalPtrs(), [&](auto& portal) {
0093 assignGeometryId(cache, *portal);
0094 });
0095
0096
0097 std::ranges::for_each(dVolume.surfacePtrs(), [&](auto& surface) {
0098 assignGeometryId(cache, *surface);
0099 });
0100
0101
0102 std::ranges::for_each(dVolume.volumePtrs(), [&](auto& volume) {
0103 assignGeometryId(cache, *volume);
0104 });
0105 }
0106
0107
0108
0109
0110
0111 void assignGeometryId(IGeometryIdGenerator::GeoIdCache& cache,
0112 Portal& portal) const final {
0113 auto& sCache = std::any_cast<Cache&>(cache);
0114
0115 SourceIdentifier pID = m_cfg.sourceCapture(portal);
0116 auto source = m_cfg.sourceTargetMap.find(pID);
0117 if (source != m_cfg.sourceTargetMap.end()) {
0118 portal.surface().assignGeometryId(source->second);
0119 ACTS_VERBOSE("Assigning geometry id " << source->second << " to portal "
0120 << " with id " << pID);
0121 sCache.portalCounter++;
0122 }
0123 }
0124
0125
0126
0127
0128
0129 void assignGeometryId(IGeometryIdGenerator::GeoIdCache& cache,
0130 Surface& surface) const final {
0131 auto& sCache = std::any_cast<Cache&>(cache);
0132
0133 SourceIdentifier sID = m_cfg.sourceCapture(surface);
0134 auto source = m_cfg.sourceTargetMap.find(sID);
0135 if (source != m_cfg.sourceTargetMap.end()) {
0136 ACTS_VERBOSE("Assigning geometry id " << source->second << " to surface "
0137 << " with id " << sID);
0138 surface.assignGeometryId(source->second);
0139 sCache.surfaceCounter++;
0140 }
0141 }
0142
0143 private:
0144
0145 Config m_cfg;
0146
0147
0148 const Logger& logger() const { return *m_logger; }
0149
0150
0151 std::unique_ptr<const Logger> m_logger;
0152 };
0153
0154 }