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