Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-09 08:18:13

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 // Set the Geometry Context PLUGIN
0012 #ifdef ACTS_CORE_GEOMETRYCONTEXT_PLUGIN
0013 #include ACTS_CORE_GEOMETRYCONTEXT_PLUGIN
0014 #else
0015 
0016 #include "Acts/Utilities/Diagnostics.hpp"
0017 #include "Acts/Utilities/detail/ContextType.hpp"
0018 
0019 #include <ostream>
0020 
0021 namespace Acts {
0022 
0023 /// @brief This is the central definition of the Acts
0024 /// payload object regarding detector geometry status (e.g. alignment)
0025 ///
0026 /// @ingroup context
0027 ///
0028 /// It is propagated through the code to allow for event/thread
0029 /// dependent geometry changes.
0030 ///
0031 /// ## Construction
0032 ///
0033 /// For typical use cases with alignment or conditions data:
0034 /// @code
0035 /// MyAlignmentData alignment = ...;
0036 /// GeometryContext gctx{alignment};
0037 /// @endcode
0038 ///
0039 /// For testing or simple applications without alignment:
0040 /// @code
0041 /// auto gctx = GeometryContext::dangerouslyDefaultConstruct();
0042 /// @endcode
0043 ///
0044 /// @note The default constructor is deprecated. Use the factory method
0045 ///       dangerouslyDefaultConstruct() to make empty context creation explicit.
0046 class GeometryContext : public ContextType {
0047  public:
0048   /// Static factory method for default construction
0049   /// @note Use this when you need a default context for testing or
0050   ///       simple applications without alignment/conditions data
0051   /// @return A default-constructed GeometryContext
0052   static GeometryContext dangerouslyDefaultConstruct() {
0053     ACTS_PUSH_IGNORE_DEPRECATED()
0054     return GeometryContext();
0055     ACTS_POP_IGNORE_DEPRECATED()
0056   }
0057 
0058   /// Move construct from arbitrary type (inherited from ContextType)
0059   /// @tparam T The type of the value to construct from
0060   /// @param value The value to construct from
0061   template <typename T>
0062     requires(!std::is_same_v<std::decay_t<T>, GeometryContext> &&
0063              !std::is_base_of_v<ContextType, std::decay_t<T> >)
0064   explicit GeometryContext(T&& value) : ContextType(std::forward<T>(value)) {}
0065 
0066   /// Copy construct from arbitrary type (inherited from ContextType)
0067   /// @tparam T The type of the value to construct from
0068   /// @param value The value to construct from
0069   template <typename T>
0070     requires(!std::is_same_v<std::decay_t<T>, GeometryContext> &&
0071              !std::is_base_of_v<ContextType, std::decay_t<T> >)
0072   explicit GeometryContext(const T& value) : ContextType(value) {}
0073 
0074   /// Inherit assignment operators
0075   using ContextType::operator=;
0076 
0077  private:
0078   GeometryContext() = default;
0079 };
0080 
0081 /// Helper struct that stores an object and a context, and will print it to
0082 /// an outstream.
0083 /// This allows you to write
0084 /// ```cpp
0085 /// std::cout << surface->toStream(geoContext) << std::endl;
0086 /// ```
0087 template <typename T>
0088 struct GeometryContextOstreamWrapper {
0089   /// Constructor wrapping an object with geometry context for output streaming
0090   /// @param object The object to wrap for streaming
0091   /// @param gctx The geometry context to associate with the object
0092   GeometryContextOstreamWrapper(const T& object, const GeometryContext& gctx)
0093       : m_object(object), m_gctx(gctx) {}
0094 
0095   GeometryContextOstreamWrapper(const GeometryContextOstreamWrapper&) = delete;
0096   GeometryContextOstreamWrapper(GeometryContextOstreamWrapper&&) = delete;
0097   GeometryContextOstreamWrapper& operator=(
0098       const GeometryContextOstreamWrapper&) = delete;
0099   GeometryContextOstreamWrapper& operator=(GeometryContextOstreamWrapper&&) =
0100       delete;
0101 
0102   friend std::ostream& operator<<(
0103       std::ostream& os, const GeometryContextOstreamWrapper& osWrapper) {
0104     osWrapper.toStream(os);
0105     return os;
0106   }
0107 
0108  private:
0109   void toStream(std::ostream& os) const { m_object.toStreamImpl(m_gctx, os); }
0110 
0111   const T& m_object;
0112   const GeometryContext& m_gctx;
0113 };
0114 
0115 }  // namespace Acts
0116 
0117 #endif