Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-07 10:11:35

0001 //------------------------------- -*- C++ -*- -------------------------------//
0002 // Copyright Celeritas contributors: see top-level COPYRIGHT file for details
0003 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0004 //---------------------------------------------------------------------------//
0005 //! \file celeritas/io/JsonEventReader.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <fstream>
0010 #include <memory>
0011 #include <string>
0012 #include <vector>
0013 
0014 #include "corecel/Macros.hh"
0015 #include "celeritas/phys/Primary.hh"
0016 
0017 #include "EventIOInterface.hh"
0018 
0019 namespace celeritas
0020 {
0021 class ParticleParams;
0022 
0023 //---------------------------------------------------------------------------//
0024 /*!
0025  * Read file generated by \c JsonEventWriter .
0026  */
0027 class JsonEventReader : public EventReaderInterface
0028 {
0029   public:
0030     //!@{
0031     //! \name Type aliases
0032     using SPConstParticles = std::shared_ptr<ParticleParams const>;
0033     using result_type = std::vector<Primary>;
0034     //!@}
0035 
0036     // Construct with filename
0037     JsonEventReader(std::string const& filename, SPConstParticles particles);
0038 
0039     //! Prevent copying and moving
0040     CELER_DELETE_COPY_MOVE(JsonEventReader);
0041     ~JsonEventReader() override = default;
0042 
0043     // Read a single event from the json file
0044     result_type operator()() final;
0045 
0046     //! Get total number of events
0047     size_type num_events() const final { return num_events_; }
0048 
0049   private:
0050     std::ifstream infile_;
0051     SPConstParticles particles_;
0052     size_type num_events_{0};
0053 };
0054 
0055 //---------------------------------------------------------------------------//
0056 }  // namespace celeritas