![]() |
|
|||
File indexing completed on 2025-07-03 07:52:00
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 #pragma once 0010 0011 #include "Acts/Geometry/BlueprintNode.hpp" 0012 #include "Acts/Geometry/BlueprintOptions.hpp" 0013 #include "Acts/Geometry/TrackingVolume.hpp" 0014 #include "Acts/Geometry/VolumeAttachmentStrategy.hpp" 0015 #include "Acts/Geometry/VolumeResizeStrategy.hpp" 0016 #include "Acts/Geometry/VolumeStack.hpp" 0017 #include "Acts/Utilities/AxisDefinitions.hpp" 0018 #include "Acts/Utilities/GraphViz.hpp" 0019 #include "Acts/Utilities/Logger.hpp" 0020 #include "Acts/Utilities/ThrowAssert.hpp" 0021 0022 #include <map> 0023 0024 namespace Acts::Experimental { 0025 0026 /// @class ContainerBlueprintNode 0027 /// 0028 /// A blueprint node that can contain multiple child volumes. It is responsible 0029 /// for managing the child volumes and their shells. The child volumes can be 0030 /// either gap volumes or volumes from child nodes. 0031 /// 0032 /// The container node is responsible for: 0033 /// 1. Managing the child volumes and their shells 0034 /// 2. Creating gap volumes between child volumes 0035 /// 3. Collecting shells from child nodes and gap volumes 0036 /// 4. Building the volume stack 0037 /// 0038 /// The container node is an abstract base class. Derived classes must 0039 /// implement: 0040 /// 1. makeStack - to create the appropriate volume stack 0041 /// 2. typeName - to provide the type name for debug output 0042 /// 0043 class ContainerBlueprintNode : public BlueprintNode { 0044 public: 0045 /// Main constructor for the container node. 0046 /// @param name The name of the node (for debug only) 0047 /// @param axis The stacking axis direction in local reference frame 0048 /// @param attachmentStrategy The attachment strategy for the stack 0049 /// @param resizeStrategy The resize strategy for the stack 0050 ContainerBlueprintNode( 0051 const std::string& name, AxisDirection axis, 0052 VolumeAttachmentStrategy attachmentStrategy = 0053 VolumeAttachmentStrategy::Midpoint, 0054 VolumeResizeStrategy resizeStrategy = VolumeResizeStrategy::Expand); 0055 0056 /// Main constructor for the container node. 0057 /// @param name The name of the node (for debug only) 0058 /// @param axis The stacking axis direction in local reference frame 0059 /// @param attachmentStrategy The attachment strategy for the stack 0060 /// @param resizeStrategies The resize strategies for the stack 0061 ContainerBlueprintNode( 0062 const std::string& name, AxisDirection axis, 0063 VolumeAttachmentStrategy attachmentStrategy, 0064 std::pair<VolumeResizeStrategy, VolumeResizeStrategy> resizeStrategies); 0065 0066 /// @copydoc BlueprintNode::name 0067 const std::string& name() const override; 0068 0069 /// This participates in the construction of the geometry via the blueprint 0070 /// tree. The steps are approximately as follows: 0071 /// -# Collect all child volumes 0072 /// -# Package them into a VolumeStack (cuboid or cylinder), which performs 0073 /// sizing and/or gap creation 0074 /// -# Return the VolumeStack as a volume up the tree 0075 /// 0076 /// @param options The global blueprint options 0077 /// @param gctx The geometry context (nominal usually) 0078 /// @param logger The logger to use 0079 /// @return The combined VolumeStack 0080 Volume& build(const Experimental::BlueprintOptions& options, 0081 const GeometryContext& gctx, 0082 const Logger& logger = Acts::getDummyLogger()) override; 0083 0084 /// This participates in the construction of the geometry via the blueprint 0085 /// tree. The steps are approximately as follows: 0086 /// -# Register portals created for gap volumes, as they're not handled by 0087 /// dedicated nodes 0088 /// -# Register gap volumes in the @p parent volume 0089 /// -# Create a configured @ref Acts::INavigationPolicy for the gap 0090 /// -# Call `finalize` on all children while passing through @p parent. 0091 /// 0092 /// @param options The global blueprint options 0093 /// @param gctx The geometry context (nominal usually) 0094 /// @param parent The parent volume 0095 /// @param logger The logger to use 0096 void finalize(const Experimental::BlueprintOptions& options, 0097 const GeometryContext& gctx, TrackingVolume& parent, 0098 const Logger& logger) override; 0099 0100 /// Setter for the stacking direction 0101 /// @param direction The stacking direction 0102 /// @return This node for chaining 0103 ContainerBlueprintNode& setDirection(AxisDirection direction); 0104 0105 /// Setter for the attachment strategy 0106 /// @param attachmentStrategy The attachment strategy 0107 /// @return This node for chaining 0108 ContainerBlueprintNode& setAttachmentStrategy( 0109 VolumeAttachmentStrategy attachmentStrategy); 0110 0111 /// Setter for the resize strategy 0112 /// @param resizeStrategy The resize strategy 0113 /// @note @p resizeStrategy is used for both sides of the container 0114 /// @return This node for chaining 0115 ContainerBlueprintNode& setResizeStrategy( 0116 VolumeResizeStrategy resizeStrategy); 0117 0118 /// Setter for the resize strategies 0119 /// @param inner The inner resize strategy 0120 /// @param outer The outer resize strategy 0121 /// @return This node for chaining 0122 ContainerBlueprintNode& setResizeStrategies(VolumeResizeStrategy inner, 0123 VolumeResizeStrategy outer); 0124 0125 /// Accessor to the stacking direction 0126 /// @return The stacking direction 0127 AxisDirection direction() const; 0128 0129 /// Accessor to the attachment strategy 0130 /// @return The attachment strategy 0131 VolumeAttachmentStrategy attachmentStrategy() const; 0132 0133 /// Accessor to the resize strategy 0134 /// @return The resize strategy 0135 [[deprecated("Use resizeStrategies() instead")]] 0136 VolumeResizeStrategy resizeStrategy() const; 0137 0138 /// Accessor to the resize strategies 0139 /// @return The resize strategies 0140 std::pair<VolumeResizeStrategy, VolumeResizeStrategy> resizeStrategies() 0141 const; 0142 0143 /// @copydoc BlueprintNode::addToGraphviz 0144 void addToGraphviz(std::ostream& os) const override; 0145 0146 protected: 0147 /// Make the volume stack for the container. This is called by the build 0148 /// method and is implemented by the derived classes. 0149 /// @param volumes The volumes to stack 0150 /// @param logger The logger to use 0151 /// @return The volume stack 0152 virtual std::unique_ptr<VolumeStack> makeStack(std::vector<Volume*>& volumes, 0153 const Logger& logger) = 0; 0154 0155 /// Get the type name of the container. This is used for the debug output 0156 /// of the container and encoding the volume shape in the dot graph. 0157 /// @return The type name 0158 virtual const std::string& typeName() const = 0; 0159 0160 /// Collect shells from child nodes and gap volumes 0161 /// 0162 /// This function is responsible for collecting shells from child nodes and 0163 /// creating shells for gap volumes. It is used by the connect method to 0164 /// prepare the shells for the volume stack. 0165 /// 0166 /// The function processes each volume in m_childVolumes in two ways: 0167 /// 1. For gap volumes: 0168 /// - Creates a TrackingVolume from the gap volume 0169 /// - Assigns a unique name (ContainerName::GapN) 0170 /// - Creates a single shell for the gap volume 0171 /// - Stores both the shell and gap volume in m_gaps for later use 0172 /// 0173 /// 2. For child volumes: 0174 /// - Looks up the corresponding child node in m_volumeToNode 0175 /// - Calls connect() on the child node to get its shell 0176 /// - Validates that the shell type matches the expected type 0177 /// - Ensures the shell is valid 0178 /// 0179 /// The function maintains the order of volumes as they appear in 0180 /// m_childVolumes, which is important for the final stack shell construction. 0181 /// 0182 /// @tparam BaseShell The base shell type (e.g. CylinderPortalShell) 0183 /// @tparam SingleShell The single shell type (e.g. SingleCylinderPortalShell) 0184 /// @param options The blueprint options 0185 /// @param gctx The geometry context 0186 /// @param stack The volume stack 0187 /// @param prefix The prefix for debug output 0188 /// @param logger The logger to use 0189 /// @return A vector of shells in the same order as m_childVolumes 0190 template <typename BaseShell, typename SingleShell> 0191 std::vector<BaseShell*> collectChildShells( 0192 const Experimental::BlueprintOptions& options, 0193 const GeometryContext& gctx, VolumeStack& stack, 0194 const std::string& prefix, const Logger& logger); 0195 0196 /// Implementation of the connect method for container nodes 0197 /// 0198 /// This method is responsible for: 0199 /// 1. Collecting shells from child nodes and gap volumes 0200 /// 2. Validating that the number of shells matches the number of child 0201 /// volumes 0202 /// 3. Ensuring all shells are valid 0203 /// 4. Creating a merged stack shell from all collected shells 0204 /// 0205 /// @tparam BaseShell The base shell type (e.g. CylinderPortalShell) 0206 /// @tparam SingleShell The single shell type (e.g. SingleCylinderPortalShell) 0207 /// @tparam ShellStack The stack shell type (e.g. StackCylinderPortalShell) 0208 /// @param options The blueprint options 0209 /// @param gctx The geometry context 0210 /// @param stack The volume stack 0211 /// @param prefix The prefix for debug output 0212 /// @param logger The logger to use 0213 /// @return The merged stack shell 0214 template <typename BaseShell, typename SingleShell, typename ShellStack> 0215 PortalShellBase& connectImpl(const Experimental::BlueprintOptions& options, 0216 const GeometryContext& gctx, VolumeStack* stack, 0217 const std::string& prefix, const Logger& logger); 0218 0219 std::string m_name; 0220 AxisDirection m_direction = AxisDirection::AxisZ; 0221 VolumeAttachmentStrategy m_attachmentStrategy{ 0222 VolumeAttachmentStrategy::Midpoint}; 0223 0224 std::pair<VolumeResizeStrategy, VolumeResizeStrategy> m_resizeStrategies{ 0225 VolumeResizeStrategy::Expand, VolumeResizeStrategy::Expand}; 0226 0227 std::vector<Volume*> m_childVolumes; 0228 // This is going to be an instance of a *stack* of volumes, which is created 0229 // by the derived classes 0230 std::unique_ptr<VolumeStack> m_stack{nullptr}; 0231 std::map<const Volume*, BlueprintNode*> m_volumeToNode; 0232 0233 std::unique_ptr<PortalShellBase> m_shell{nullptr}; 0234 std::vector<std::pair<std::unique_ptr<PortalShellBase>, 0235 std::unique_ptr<TrackingVolume>>> 0236 m_gaps; 0237 }; 0238 0239 class CylinderContainerBlueprintNode final : public ContainerBlueprintNode { 0240 public: 0241 using ContainerBlueprintNode::ContainerBlueprintNode; 0242 0243 /// This participates in the construction of the geometry via the blueprint 0244 /// tree. The steps are approximately as follows: 0245 /// -# Walk through all volumes that were created by the build phase 0246 /// -# Check if they are: *real* child volumes or gap volumes 0247 /// - If gap volume: produce a @ref Acts::TrackingVolume, and wrap it in a single use shell 0248 /// - If child volume: locate the right child node it came from, call 0249 /// ` connect` and collect the returned shell 0250 /// -# Produce a combined StackPortalShell (cuboid or cylinder) from all the 0251 /// shells 0252 /// -# Return that shell representation 0253 /// 0254 /// @param options The global blueprint options 0255 /// @param gctx The geometry context (nominal usually) 0256 /// @param logger The logger to use 0257 /// @return The combined StackPortalShell (cuboid or cylinder) 0258 PortalShellBase& connect( 0259 const Experimental::BlueprintOptions& options, 0260 const GeometryContext& gctx, 0261 const Logger& logger = Acts::getDummyLogger()) override; 0262 0263 std::unique_ptr<VolumeStack> makeStack(std::vector<Volume*>& volumes, 0264 const Logger& logger) override; 0265 0266 protected: 0267 inline static const std::string s_typeName = "Cylinder"; 0268 const std::string& typeName() const override; 0269 }; 0270 0271 class CuboidContainerBlueprintNode final : public ContainerBlueprintNode { 0272 public: 0273 using ContainerBlueprintNode::ContainerBlueprintNode; 0274 0275 /// This participates in the construction of the geometry via the blueprint 0276 /// tree. The steps are approximately as follows: 0277 /// -# Walk through all volumes that were created by the build phase 0278 /// -# Check if they are: *real* child volumes or gap volumes 0279 /// - If gap volume: produce a @ref Acts::TrackingVolume, and wrap it in a single use shell 0280 /// - If child volume: locate the right child node it came from, call 0281 /// ` connect` and collect the returned shell 0282 /// -# Produce a combined StackPortalShell (cuboid or cylinder) from all the 0283 /// shells 0284 /// -# Return that shell representation 0285 /// 0286 /// @param options The global blueprint options 0287 /// @param gctx The geometry context (nominal usually) 0288 /// @param logger The logger to use 0289 /// @return The combined StackPortalShell (cuboid or cylinder) 0290 PortalShellBase& connect( 0291 const Experimental::BlueprintOptions& options, 0292 const GeometryContext& gctx, 0293 const Logger& logger = Acts::getDummyLogger()) override; 0294 0295 std::unique_ptr<VolumeStack> makeStack(std::vector<Volume*>& volumes, 0296 const Logger& logger) override; 0297 0298 protected: 0299 inline static const std::string s_typeName = "Cuboid"; 0300 const std::string& typeName() const override; 0301 }; 0302 0303 } // namespace Acts::Experimental
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |