Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-01 07:59:22

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