File indexing completed on 2025-01-31 09:16:52
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "ActsExamples/ContextualDetector/InternalAlignmentDecorator.hpp"
0010
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "ActsExamples/ContextualDetector/InternallyAlignedDetectorElement.hpp"
0013 #include "ActsExamples/Framework/AlgorithmContext.hpp"
0014 #include "ActsExamples/Framework/RandomNumbers.hpp"
0015
0016 #include <ostream>
0017 #include <thread>
0018 #include <utility>
0019
0020 namespace ActsExamples {
0021
0022 InternalAlignmentDecorator::InternalAlignmentDecorator(
0023 const Config& cfg, std::unique_ptr<const Acts::Logger> logger)
0024 : m_cfg(cfg), m_logger(std::move(logger)) {}
0025
0026 ProcessCode InternalAlignmentDecorator::decorate(AlgorithmContext& context) {
0027
0028 std::lock_guard<std::mutex> alignmentLock(m_alignmentMutex);
0029
0030
0031 unsigned int iov = context.eventNumber / m_cfg.iovSize;
0032
0033 ACTS_VERBOSE("IOV handling in thread " << std::this_thread::get_id() << ".");
0034 ACTS_VERBOSE("IOV resolved to " << iov << " - from event "
0035 << context.eventNumber << ".");
0036
0037 m_eventsSeen++;
0038
0039 context.geoContext = InternallyAlignedDetectorElement::ContextType{iov};
0040
0041 if (m_cfg.randomNumberSvc != nullptr) {
0042 if (auto it = m_activeIovs.find(iov); it != m_activeIovs.end()) {
0043
0044 it->second.lastAccessed = m_eventsSeen;
0045 } else {
0046
0047
0048 m_activeIovs.emplace(iov, IovStatus{m_eventsSeen});
0049
0050 ACTS_VERBOSE("New IOV " << iov << " detected at event "
0051 << context.eventNumber
0052 << ", emulate new alignment.");
0053
0054
0055 RandomEngine rng = m_cfg.randomNumberSvc->spawnGenerator(context);
0056
0057 for (auto& lstore : m_cfg.detectorStore) {
0058 for (auto& ldet : lstore) {
0059
0060 Acts::Transform3 tForm =
0061 ldet->nominalTransform(context.geoContext);
0062
0063 applyTransform(tForm, m_cfg, rng, iov);
0064
0065 ldet->addAlignedTransform(tForm, iov);
0066 }
0067 }
0068 }
0069 }
0070
0071
0072 if (m_cfg.doGarbageCollection) {
0073 for (auto it = m_activeIovs.begin(); it != m_activeIovs.end();) {
0074 unsigned int this_iov = it->first;
0075 auto& status = it->second;
0076 if (m_eventsSeen - status.lastAccessed > m_cfg.flushSize) {
0077 ACTS_DEBUG("IOV " << this_iov << " has not been accessed in the last "
0078 << m_cfg.flushSize << " events, clearing");
0079 it = m_activeIovs.erase(it);
0080 for (auto& lstore : m_cfg.detectorStore) {
0081 for (auto& ldet : lstore) {
0082 ldet->clearAlignedTransform(this_iov);
0083 }
0084 }
0085 } else {
0086 it++;
0087 }
0088 }
0089 }
0090
0091 return ProcessCode::SUCCESS;
0092 }
0093
0094 }