Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 09:16:52

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 #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   // We need to lock the Decorator
0028   std::lock_guard<std::mutex> alignmentLock(m_alignmentMutex);
0029 
0030   // In which iov batch are we?
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       // Iov is already present, update last accessed
0044       it->second.lastAccessed = m_eventsSeen;
0045     } else {
0046       // Iov is not present yet, create it
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       // Create an algorithm local random number generator
0055       RandomEngine rng = m_cfg.randomNumberSvc->spawnGenerator(context);
0056 
0057       for (auto& lstore : m_cfg.detectorStore) {
0058         for (auto& ldet : lstore) {
0059           // get the nominal transform
0060           Acts::Transform3 tForm =
0061               ldet->nominalTransform(context.geoContext);  // copy
0062           // create a new transform
0063           applyTransform(tForm, m_cfg, rng, iov);
0064           // put it back into the store
0065           ldet->addAlignedTransform(tForm, iov);
0066         }
0067       }
0068     }
0069   }
0070 
0071   // Garbage collection
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 }  // namespace ActsExamples