Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-08 08:10:14

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #include "Acts/Geometry/TrackingGeometryBuilder.hpp"
0010 
0011 #include "Acts/Geometry/TrackingGeometry.hpp"
0012 
0013 #include <functional>
0014 #include <stdexcept>
0015 #include <utility>
0016 
0017 namespace Acts {
0018 
0019 TrackingGeometryBuilder::TrackingGeometryBuilder(
0020     const TrackingGeometryBuilder::Config& cgbConfig,
0021     std::unique_ptr<const Logger> logger)
0022     : m_cfg(), m_logger(std::move(logger)) {
0023   setConfiguration(cgbConfig);
0024 }
0025 
0026 const TrackingGeometryBuilder::Config&
0027 TrackingGeometryBuilder::getConfiguration() const {
0028   return m_cfg;
0029 }
0030 
0031 void TrackingGeometryBuilder::setConfiguration(
0032     const TrackingGeometryBuilder::Config& cgbConfig) {
0033   if (cgbConfig.trackingVolumeBuilders.empty()) {
0034     throw std::invalid_argument("Invalid configuration: no volume builders");
0035   }
0036   m_cfg = cgbConfig;
0037 }
0038 
0039 void TrackingGeometryBuilder::setLogger(
0040     std::unique_ptr<const Logger> newLogger) {
0041   m_logger = std::move(newLogger);
0042 }
0043 
0044 std::unique_ptr<const TrackingGeometry>
0045 TrackingGeometryBuilder::trackingGeometry(const GeometryContext& gctx) const {
0046   ACTS_DEBUG("Building tracking geometry");
0047   MutableTrackingVolumePtr highestVolume = nullptr;
0048   // loop over the builders and wrap one around the other
0049   for (auto& volumeBuilder : m_cfg.trackingVolumeBuilders) {
0050     // assign a new highest volume (and potentially wrap around the given
0051     // highest volume so far)
0052     auto volume = volumeBuilder(gctx, highestVolume, nullptr);
0053     if (!volume) {
0054       ACTS_INFO(
0055           "Received nullptr volume from builder, keeping previous highest "
0056           "volume");
0057     } else {
0058       highestVolume = std::move(volume);
0059     }
0060   }
0061 
0062   // create the TrackingGeometry & decorate it with the material
0063   if (highestVolume) {
0064     return std::make_unique<TrackingGeometry>(
0065         highestVolume,
0066         m_cfg.materialDecorator ? m_cfg.materialDecorator.get() : nullptr,
0067         *m_cfg.geometryIdentifierHook, logger());
0068   } else {
0069     throw std::runtime_error(
0070         "Unable to construct tracking geometry: no tracking volume");
0071   }
0072 }
0073 
0074 }  // namespace Acts