Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-03 07:47:58

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/StaticBlueprintNode.hpp"
0010 
0011 #include "Acts/Geometry/CuboidPortalShell.hpp"
0012 #include "Acts/Geometry/CylinderPortalShell.hpp"
0013 #include "Acts/Geometry/DiamondPortalShell.hpp"
0014 #include "Acts/Geometry/GeometryContext.hpp"
0015 #include "Acts/Geometry/TrapezoidPortalShell.hpp"
0016 #include "Acts/Geometry/VolumeBounds.hpp"
0017 #include "Acts/Navigation/INavigationPolicy.hpp"
0018 #include "Acts/Utilities/GraphViz.hpp"
0019 #include "Acts/Visualization/GeometryView3D.hpp"
0020 
0021 namespace Acts::Experimental {
0022 
0023 StaticBlueprintNode::StaticBlueprintNode(std::unique_ptr<TrackingVolume> volume)
0024     : m_volume(std::move(volume)) {}
0025 
0026 Volume& StaticBlueprintNode::build(const BlueprintOptions& options,
0027                                    const GeometryContext& gctx,
0028                                    const Logger& logger) {
0029   ACTS_DEBUG(prefix() << "Static build");
0030   if (!m_volume) {
0031     throw std::runtime_error("Volume is not built");
0032   }
0033 
0034   ACTS_DEBUG(prefix() << "Building volume (" << name()
0035                       << ", id=" << m_volume->geometryId() << ") with "
0036                       << children().size() << " children");
0037   for (auto& child : children()) {
0038     child.build(options, gctx, logger);
0039   }
0040 
0041   ACTS_DEBUG(prefix() << "-> returning volume " << *m_volume);
0042   return *m_volume;
0043 }
0044 
0045 PortalShellBase& StaticBlueprintNode::connect(const BlueprintOptions& options,
0046                                               const GeometryContext& gctx,
0047                                               const Logger& logger) {
0048   ACTS_DEBUG(prefix() << "Static connect");
0049   if (m_volume == nullptr) {
0050     throw std::runtime_error("Volume is not present");
0051   }
0052 
0053   ACTS_DEBUG(prefix() << "Connecting parent volume (" << name() << ") with "
0054                       << children().size() << " children");
0055 
0056   for (auto& child : children()) {
0057     auto& shell = child.connect(options, gctx, logger);
0058     // Register ourselves on the outside of the shell
0059     shell.fill(*m_volume);
0060   }
0061 
0062   VolumeBounds::BoundsType type = m_volume->volumeBounds().type();
0063   if (type == VolumeBounds::eCylinder) {
0064     m_shell = std::make_unique<SingleCylinderPortalShell>(gctx, *m_volume);
0065 
0066   } else if (type == VolumeBounds::eCuboid) {
0067     m_shell = std::make_unique<SingleCuboidPortalShell>(gctx, *m_volume);
0068 
0069   } else if (type == VolumeBounds::eTrapezoid) {
0070     m_shell = std::make_unique<SingleTrapezoidPortalShell>(gctx, *m_volume);
0071 
0072   } else if (type == VolumeBounds::eDiamond) {
0073     m_shell = std::make_unique<SingleDiamondPortalShell>(gctx, *m_volume);
0074 
0075   } else {
0076     throw std::logic_error("Volume type is not supported");
0077   }
0078 
0079   assert(m_shell != nullptr &&
0080          "No shell was built at the end of StaticBlueprintNode::connect");
0081   assert(m_shell->isValid() &&
0082          "Shell is not valid at the end of StaticBlueprintNode::connect");
0083   return *m_shell;
0084 }
0085 
0086 void StaticBlueprintNode::finalize(const BlueprintOptions& options,
0087                                    const GeometryContext& gctx,
0088                                    TrackingVolume& parent,
0089                                    const Logger& logger) {
0090   ACTS_DEBUG(prefix() << "Finalizing static volume");
0091 
0092   if (!m_volume) {
0093     ACTS_ERROR(prefix() << "Volume is not built");
0094     throw std::runtime_error("Volume is not built");
0095   }
0096 
0097   if (!m_shell) {
0098     ACTS_ERROR(prefix() << "Shell is not built");
0099     throw std::runtime_error("Shell is not built");
0100   }
0101 
0102   for (auto& child : children()) {
0103     child.finalize(options, gctx, *m_volume, logger);
0104   }
0105 
0106   ACTS_DEBUG(prefix() << "Registering " << m_shell->size()
0107                       << " portals into volume " << m_volume->volumeName());
0108   m_shell->applyToVolume();
0109 
0110   const auto* policyFactory = options.defaultNavigationPolicyFactory.get();
0111 
0112   if (m_navigationPolicyFactory) {
0113     policyFactory = m_navigationPolicyFactory.get();
0114   }
0115   m_volume->setNavigationPolicy(policyFactory->build(gctx, *m_volume, logger));
0116 
0117   // only add the volume to the parent if it is not the parent itself.
0118   if (name() != "World") {
0119     ACTS_DEBUG(prefix() << " Adding volume (" << m_volume->volumeName()
0120                         << ") to parent volume (" << parent.volumeName()
0121                         << ")");
0122     parent.addVolume(std::move(m_volume));
0123   }
0124 }
0125 const std::string& StaticBlueprintNode::name() const {
0126   static const std::string uninitialized = "uninitialized";
0127   if (m_volume == nullptr) {
0128     return uninitialized;
0129   }
0130   return m_volume->volumeName();
0131 }
0132 
0133 StaticBlueprintNode& StaticBlueprintNode::setNavigationPolicyFactory(
0134     std::shared_ptr<NavigationPolicyFactory> navigationPolicyFactory) {
0135   m_navigationPolicyFactory = std::move(navigationPolicyFactory);
0136   return *this;
0137 }
0138 
0139 const NavigationPolicyFactory* StaticBlueprintNode::navigationPolicyFactory()
0140     const {
0141   return m_navigationPolicyFactory.get();
0142 }
0143 
0144 void StaticBlueprintNode::addToGraphviz(std::ostream& os) const {
0145   std::stringstream ss;
0146   ss << "<b>" << name() << "</b>";
0147   ss << "<br/>";
0148   if (m_volume == nullptr) {
0149     throw std::runtime_error("Volume is not built");
0150   }
0151   switch (m_volume->volumeBounds().type()) {
0152     case VolumeBounds::eCylinder:
0153       ss << "Cylinder";
0154       break;
0155     case VolumeBounds::eCuboid:
0156       ss << "Cuboid";
0157       break;
0158     case VolumeBounds::eCone:
0159       ss << "Cone";
0160       break;
0161     case VolumeBounds::eCutoutCylinder:
0162       ss << "CutoutCylinder";
0163       break;
0164     case VolumeBounds::eGenericCuboid:
0165       ss << "GenericCuboid";
0166       break;
0167     case VolumeBounds::eTrapezoid:
0168       ss << "Trapezoid";
0169       break;
0170     default:
0171       ss << "Other";
0172   }
0173 
0174   GraphViz::Node node{
0175       .id = name(), .label = ss.str(), .shape = GraphViz::Shape::Rectangle};
0176 
0177   os << node;
0178 
0179   BlueprintNode::addToGraphviz(os);
0180 }
0181 
0182 }  // namespace Acts::Experimental