Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
InternallyAlignedDetectorElement.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file InternallyAlignedDetectorElement.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2019 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #pragma once
10 
18 
19 #include <iostream>
20 #include <memory>
21 #include <mutex>
22 #include <unordered_map>
23 
24 namespace ActsExamples {
25 
26 namespace Contextual {
27 
42  public:
43  struct ContextType {
45  unsigned int iov = 0;
46  bool nominal = false;
47  };
48 
49  // Inherit constructor
51 
58  const Acts::GeometryContext& gctx) const override;
59 
64  const Acts::GeometryContext& gctx) const;
65 
70  void addAlignedTransform(const Acts::Transform3& alignedTransform,
71  unsigned int iov);
72 
73  void clearAlignedTransform(unsigned int iov);
74 
75  private:
76  std::unordered_map<unsigned int, Acts::Transform3> m_alignedTransforms;
77  mutable std::mutex m_alignmentMutex;
78 };
79 
81  const Acts::GeometryContext& gctx) const {
82  if (!gctx.hasValue()) {
83  // Return the standard transform if geo context is empty
84  return nominalTransform(gctx);
85  }
86  const auto& alignContext = gctx.get<ContextType&>();
87 
88  std::lock_guard lock{m_alignmentMutex};
89  if (alignContext.nominal) {
90  // nominal alignment
91  return nominalTransform(gctx);
92  }
93  auto aTransform = m_alignedTransforms.find(alignContext.iov);
94  if (aTransform == m_alignedTransforms.end()) {
95  throw std::runtime_error{
96  "Aligned transform for IOV " + std::to_string(alignContext.iov) +
97  " not found. This can happen if the garbage collection runs too "
98  "early (--align-flushsize too low)"};
99  }
100  return aTransform->second;
101 }
102 
103 inline const Acts::Transform3&
105  const Acts::GeometryContext& gctx) const {
107 }
108 
110  const Acts::Transform3& alignedTransform, unsigned int iov) {
111  std::lock_guard lock{m_alignmentMutex};
112  m_alignedTransforms[iov] = alignedTransform;
113 }
114 
116  unsigned int iov) {
117  std::lock_guard lock{m_alignmentMutex};
118  if (auto it = m_alignedTransforms.find(iov);
119  it != m_alignedTransforms.end()) {
120  m_alignedTransforms.erase(it);
121  }
122 }
123 
124 } // namespace Contextual
125 } // end of namespace ActsExamples