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