File indexing completed on 2025-06-30 07:51:39
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "Acts/Detector/interface/IGeometryIdGenerator.hpp"
0012 #include "Acts/Geometry/GeometryIdentifier.hpp"
0013 #include "Acts/Utilities/Logger.hpp"
0014
0015 #include <any>
0016
0017 namespace Acts {
0018
0019 class Surface;
0020
0021 namespace Experimental {
0022
0023 class Portal;
0024 class DetectorVolume;
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041 class GeometryIdGenerator final : public IGeometryIdGenerator {
0042 public:
0043
0044 struct Config {
0045
0046 bool containerMode = false;
0047
0048 unsigned int containerId = 0u;
0049
0050 bool resetSubCounters = true;
0051
0052 bool overrideExistingIds = false;
0053 };
0054
0055
0056 struct Cache {
0057
0058 unsigned int volumeCount = 0u;
0059
0060 unsigned int layerCount = 0u;
0061
0062 unsigned int portalCount = 0u;
0063
0064 unsigned int passiveCount = 0u;
0065
0066 unsigned int sensitiveCount = 0u;
0067 };
0068
0069
0070
0071
0072
0073 explicit GeometryIdGenerator(const Config& cfg,
0074 std::unique_ptr<const Logger> mlogger =
0075 getDefaultLogger("GeometryIdGenerator",
0076 Logging::INFO))
0077 : m_cfg(cfg), m_logger(std::move(mlogger)) {}
0078
0079 ~GeometryIdGenerator() override = default;
0080
0081
0082
0083 IGeometryIdGenerator::GeoIdCache generateCache() const final;
0084
0085
0086
0087
0088
0089 void assignGeometryId(IGeometryIdGenerator::GeoIdCache& cache,
0090 DetectorVolume& dVolume) const final;
0091
0092
0093
0094
0095
0096 void assignGeometryId(IGeometryIdGenerator::GeoIdCache& cache,
0097 Portal& portal) const final;
0098
0099
0100
0101
0102
0103 void assignGeometryId(IGeometryIdGenerator::GeoIdCache& cache,
0104 Surface& surface) const final;
0105
0106 private:
0107
0108
0109
0110
0111
0112
0113 GeometryIdentifier volumeId(Cache& cache, bool incrementLayer = true) const;
0114
0115
0116 Config m_cfg;
0117
0118
0119 const Logger& logger() const { return *m_logger; }
0120
0121
0122 std::unique_ptr<const Logger> m_logger;
0123 };
0124
0125
0126
0127
0128
0129 template <typename... generators_t>
0130 class ChainedGeometryIdGenerator : public IGeometryIdGenerator {
0131 public:
0132 struct Cache {
0133
0134 std::array<IGeometryIdGenerator::GeoIdCache, sizeof...(generators_t)>
0135 storage;
0136 };
0137
0138
0139 std::tuple<generators_t...> generators;
0140
0141
0142
0143
0144
0145
0146 explicit ChainedGeometryIdGenerator(
0147 const std::tuple<generators_t...>&& gens,
0148 std::unique_ptr<const Logger> mlogger =
0149 getDefaultLogger("ChainedGeometryIdGenerator", Logging::INFO))
0150 : generators(std::move(gens)), m_logger(std::move(mlogger)) {}
0151
0152
0153
0154 IGeometryIdGenerator::GeoIdCache generateCache() const final {
0155
0156 Cache cache;
0157 std::size_t it = 0;
0158 std::apply(
0159 [&](auto&&... generator) {
0160 ((cache.storage[it++] = generator->generateCache()), ...);
0161 },
0162 generators);
0163 return cache;
0164 }
0165
0166
0167
0168
0169
0170 void assignGeometryId(IGeometryIdGenerator::GeoIdCache& cache,
0171 DetectorVolume& dVolume) const final {
0172 ACTS_VERBOSE("Assigning chained geometry id to volume.");
0173 assign(cache, dVolume);
0174 }
0175
0176
0177
0178
0179
0180 void assignGeometryId(IGeometryIdGenerator::GeoIdCache& cache,
0181 Portal& portal) const final {
0182 ACTS_VERBOSE("Assigning chained geometry id to portal.");
0183 assign(cache, portal);
0184 }
0185
0186
0187
0188
0189
0190 void assignGeometryId(IGeometryIdGenerator::GeoIdCache& cache,
0191 Surface& surface) const final {
0192 ACTS_VERBOSE("Assigning chained geometry id to surface.");
0193 assign(cache, surface);
0194 }
0195
0196 private:
0197
0198
0199
0200
0201
0202
0203 template <typename gometry_object_t>
0204 void assign(IGeometryIdGenerator::GeoIdCache& cache,
0205 gometry_object_t& object) const {
0206 std::size_t it = 0;
0207 auto& sCache = std::any_cast<Cache&>(cache);
0208 std::apply(
0209 [&](auto&&... generator) {
0210 (generator->assignGeometryId(sCache.storage[it++], object), ...);
0211 },
0212 generators);
0213 }
0214
0215
0216 const Logger& logger() const { return *m_logger; }
0217
0218
0219 std::unique_ptr<const Logger> m_logger;
0220 };
0221
0222 }
0223 }