File indexing completed on 2025-01-31 09:16:52
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Geometry/GeometryContext.hpp"
0013 #include "ActsExamples/GenericDetector/GenericDetectorElement.hpp"
0014
0015 #include <mutex>
0016 #include <unordered_map>
0017
0018 namespace ActsExamples {
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032 class InternallyAlignedDetectorElement : public GenericDetectorElement {
0033 public:
0034 struct ContextType {
0035
0036 unsigned int iov = 0;
0037 bool nominal = false;
0038 };
0039
0040
0041 using GenericDetectorElement::GenericDetectorElement;
0042
0043
0044
0045
0046
0047
0048 const Acts::Transform3& transform(
0049 const Acts::GeometryContext& gctx) const override;
0050
0051
0052
0053
0054 const Acts::Transform3& nominalTransform(
0055 const Acts::GeometryContext& gctx) const;
0056
0057
0058
0059
0060
0061 void addAlignedTransform(const Acts::Transform3& alignedTransform,
0062 unsigned int iov);
0063
0064 void clearAlignedTransform(unsigned int iov);
0065
0066 private:
0067 std::unordered_map<unsigned int, Acts::Transform3> m_alignedTransforms;
0068 mutable std::mutex m_alignmentMutex;
0069 };
0070
0071 inline const Acts::Transform3& InternallyAlignedDetectorElement::transform(
0072 const Acts::GeometryContext& gctx) const {
0073 if (!gctx.hasValue()) {
0074
0075 return nominalTransform(gctx);
0076 }
0077 const auto& alignContext = gctx.get<ContextType&>();
0078
0079 std::lock_guard lock{m_alignmentMutex};
0080 if (alignContext.nominal) {
0081
0082 return nominalTransform(gctx);
0083 }
0084 auto aTransform = m_alignedTransforms.find(alignContext.iov);
0085 if (aTransform == m_alignedTransforms.end()) {
0086 throw std::runtime_error{
0087 "Aligned transform for IOV " + std::to_string(alignContext.iov) +
0088 " not found. This can happen if the garbage collection runs too "
0089 "early (--align-flushsize too low)"};
0090 }
0091 return aTransform->second;
0092 }
0093
0094 inline const Acts::Transform3&
0095 InternallyAlignedDetectorElement::nominalTransform(
0096 const Acts::GeometryContext& gctx) const {
0097 return GenericDetectorElement::transform(gctx);
0098 }
0099
0100 inline void InternallyAlignedDetectorElement::addAlignedTransform(
0101 const Acts::Transform3& alignedTransform, unsigned int iov) {
0102 std::lock_guard lock{m_alignmentMutex};
0103 m_alignedTransforms[iov] = alignedTransform;
0104 }
0105
0106 inline void InternallyAlignedDetectorElement::clearAlignedTransform(
0107 unsigned int iov) {
0108 std::lock_guard lock{m_alignmentMutex};
0109 if (auto it = m_alignedTransforms.find(iov);
0110 it != m_alignedTransforms.end()) {
0111 m_alignedTransforms.erase(it);
0112 }
0113 }
0114
0115 }