Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:11:24

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