File indexing completed on 2025-01-19 09:23:17
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 GeometryIdGenerator(const Config& cfg,
0074 std::unique_ptr<const Logger> mlogger = getDefaultLogger(
0075 "GeometryIdGenerator", Logging::INFO))
0076 : m_cfg(cfg), m_logger(std::move(mlogger)) {}
0077
0078 ~GeometryIdGenerator() override = default;
0079
0080
0081
0082 IGeometryIdGenerator::GeoIdCache generateCache() const final;
0083
0084
0085
0086
0087
0088 void assignGeometryId(IGeometryIdGenerator::GeoIdCache& cache,
0089 DetectorVolume& dVolume) const final;
0090
0091
0092
0093
0094
0095 void assignGeometryId(IGeometryIdGenerator::GeoIdCache& cache,
0096 Portal& portal) const final;
0097
0098
0099
0100
0101
0102 void assignGeometryId(IGeometryIdGenerator::GeoIdCache& cache,
0103 Surface& surface) const final;
0104
0105 private:
0106
0107
0108
0109
0110
0111
0112 GeometryIdentifier volumeId(Cache& cache, bool incrementLayer = true) const;
0113
0114
0115 Config m_cfg;
0116
0117
0118 const Logger& logger() const { return *m_logger; }
0119
0120
0121 std::unique_ptr<const Logger> m_logger;
0122 };
0123
0124
0125
0126
0127
0128 template <typename... generators_t>
0129 class ChainedGeometryIdGenerator : public IGeometryIdGenerator {
0130 public:
0131 struct Cache {
0132
0133 std::array<IGeometryIdGenerator::GeoIdCache, sizeof...(generators_t)>
0134 storage;
0135 };
0136
0137
0138 std::tuple<generators_t...> generators;
0139
0140
0141
0142
0143
0144
0145 ChainedGeometryIdGenerator(const std::tuple<generators_t...>&& gens,
0146 std::unique_ptr<const Logger> mlogger =
0147 getDefaultLogger("ChainedGeometryIdGenerator",
0148 Logging::INFO))
0149 : generators(std::move(gens)), m_logger(std::move(mlogger)) {}
0150
0151
0152
0153 IGeometryIdGenerator::GeoIdCache generateCache() const final {
0154
0155 Cache cache;
0156 std::size_t it = 0;
0157 std::apply(
0158 [&](auto&&... generator) {
0159 ((cache.storage[it++] = generator->generateCache()), ...);
0160 },
0161 generators);
0162 return cache;
0163 }
0164
0165
0166
0167
0168
0169 void assignGeometryId(IGeometryIdGenerator::GeoIdCache& cache,
0170 DetectorVolume& dVolume) const final {
0171 ACTS_VERBOSE("Assigning chained geometry id to volume.");
0172 assign(cache, dVolume);
0173 }
0174
0175
0176
0177
0178
0179 void assignGeometryId(IGeometryIdGenerator::GeoIdCache& cache,
0180 Portal& portal) const final {
0181 ACTS_VERBOSE("Assigning chained geometry id to portal.");
0182 assign(cache, portal);
0183 }
0184
0185
0186
0187
0188
0189 void assignGeometryId(IGeometryIdGenerator::GeoIdCache& cache,
0190 Surface& surface) const final {
0191 ACTS_VERBOSE("Assigning chained geometry id to surface.");
0192 assign(cache, surface);
0193 }
0194
0195 private:
0196
0197
0198
0199
0200
0201
0202 template <typename gometry_object_t>
0203 void assign(IGeometryIdGenerator::GeoIdCache& cache,
0204 gometry_object_t& object) const {
0205 std::size_t it = 0;
0206 auto& sCache = std::any_cast<Cache&>(cache);
0207 std::apply(
0208 [&](auto&&... generator) {
0209 (generator->assignGeometryId(sCache.storage[it++], object), ...);
0210 },
0211 generators);
0212 }
0213
0214
0215 const Logger& logger() const { return *m_logger; }
0216
0217
0218 std::unique_ptr<const Logger> m_logger;
0219 };
0220
0221 }
0222 }