Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-30 08:10:43

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 #pragma once
0010 
0011 #include "Acts/Utilities/Logger.hpp"
0012 #include "ActsExamples/Framework/AlgorithmContext.hpp"
0013 #include "ActsExamples/Framework/IReader.hpp"
0014 #include "ActsExamples/Framework/ProcessCode.hpp"
0015 
0016 #include <utility>
0017 
0018 namespace ActsExamples {
0019 
0020 class WhiteBoard;
0021 
0022 /// Event data reader that takes a concrete reader instance, reads a number of
0023 /// events in a buffer, and selects events from that buffer instead of directly
0024 /// reading them from disk.
0025 /// The purpose is to avoid IO bottlenecks in timing measurements
0026 class BufferedReader final : public IReader {
0027  public:
0028   struct Config {
0029     /// The upstream reader that should be used
0030     std::shared_ptr<IReader> upstreamReader;
0031 
0032     /// The seed for sampling events from the buffer
0033     std::size_t selectionSeed = 123456;
0034 
0035     /// Buffer size. The reader will throw and exception if the downstream
0036     /// reader does not provide enough events
0037     std::size_t bufferSize = 1;
0038   };
0039 
0040   /// Constructed the reader
0041   BufferedReader(const Config& config, Acts::Logging::Level level);
0042 
0043   /// Return the config
0044   const Config& config() const { return m_cfg; }
0045 
0046   /// Give the reader a understandable name
0047   std::string name() const override {
0048     return "Buffered" + m_cfg.upstreamReader->name();
0049   }
0050 
0051   /// The buffered reader provides the maximum available event range
0052   std::pair<std::size_t, std::size_t> availableEvents() const override {
0053     return {0, std::numeric_limits<std::size_t>::max()};
0054   }
0055 
0056   /// Return a event from the buffer
0057   ProcessCode read(const AlgorithmContext& ctx) override;
0058 
0059   /// Fulfill the algorithm interface
0060   ProcessCode initialize() override { return ProcessCode::SUCCESS; }
0061 
0062   /// Fulfill the algorithm interface
0063   ProcessCode finalize() override { return ProcessCode::SUCCESS; }
0064 
0065  private:
0066   Config m_cfg;
0067   std::unique_ptr<const Acts::Logger> m_logger;
0068   std::vector<std::unique_ptr<ActsExamples::WhiteBoard>> m_buffer;
0069 
0070   const Acts::Logger& logger() const { return *m_logger; }
0071 };
0072 
0073 }  // namespace ActsExamples