Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
InternalAlignmentDecorator.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file InternalAlignmentDecorator.cpp
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 
10 
16 
17 #include <ostream>
18 #include <thread>
19 #include <utility>
20 
23  std::unique_ptr<const Acts::Logger> logger)
24  : m_cfg(cfg), m_logger(std::move(logger)) {}
25 
28  AlgorithmContext& context) {
29  // We need to lock the Decorator
30  std::lock_guard<std::mutex> alignmentLock(m_alignmentMutex);
31 
32  // In which iov batch are we?
33  unsigned int iov = context.eventNumber / m_cfg.iovSize;
34 
35  ACTS_VERBOSE("IOV handling in thread " << std::this_thread::get_id() << ".");
36  ACTS_VERBOSE("IOV resolved to " << iov << " - from event "
37  << context.eventNumber << ".");
38 
39  m_eventsSeen++;
40 
42 
43  if (m_cfg.randomNumberSvc != nullptr) {
44  if (auto it = m_activeIovs.find(iov); it != m_activeIovs.end()) {
45  // Iov is already present, update last accessed
46  it->second.lastAccessed = m_eventsSeen;
47  } else {
48  // Iov is not present yet, create it
49 
50  m_activeIovs.emplace(iov, IovStatus{m_eventsSeen});
51 
52  ACTS_VERBOSE("New IOV " << iov << " detected at event "
53  << context.eventNumber
54  << ", emulate new alignment.");
55 
56  // Create an algorithm local random number generator
57  RandomEngine rng = m_cfg.randomNumberSvc->spawnGenerator(context);
58 
59  for (auto& lstore : m_cfg.detectorStore) {
60  for (auto& ldet : lstore) {
61  // get the nominal transform
62  Acts::Transform3 tForm =
63  ldet->nominalTransform(context.geoContext); // copy
64  // create a new transform
65  applyTransform(tForm, m_cfg, rng, iov);
66  // put it back into the store
67  ldet->addAlignedTransform(tForm, iov);
68  }
69  }
70  }
71  }
72 
73  // Garbage collection
74  if (m_cfg.doGarbageCollection) {
75  for (auto it = m_activeIovs.begin(); it != m_activeIovs.end();) {
76  unsigned int this_iov = it->first;
77  auto& status = it->second;
78  if (m_eventsSeen - status.lastAccessed > m_cfg.flushSize) {
79  ACTS_DEBUG("IOV " << this_iov << " has not been accessed in the last "
80  << m_cfg.flushSize << " events, clearing");
81  it = m_activeIovs.erase(it);
82  for (auto& lstore : m_cfg.detectorStore) {
83  for (auto& ldet : lstore) {
84  ldet->clearAlignedTransform(this_iov);
85  }
86  }
87  } else {
88  it++;
89  }
90  }
91  }
92 
93  return ProcessCode::SUCCESS;
94 }