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/JsonEventWriter.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <fstream>
0010 #include <memory>
0011 #include <string>
0012 
0013 #include "corecel/Macros.hh"
0014 #include "celeritas/Types.hh"
0015 
0016 #include "EventIOInterface.hh"
0017 
0018 namespace celeritas
0019 {
0020 class ParticleParams;
0021 
0022 //---------------------------------------------------------------------------//
0023 /*!
0024  * Export primary data to json.
0025  *
0026  * This write one event per line.
0027  */
0028 class JsonEventWriter : public EventWriterInterface
0029 {
0030   public:
0031     //!@{
0032     //! \name Type aliases
0033     using SPConstParticles = std::shared_ptr<ParticleParams const>;
0034     //!@}
0035 
0036     // Construct with output filename
0037     JsonEventWriter(std::string const& filename, SPConstParticles particles);
0038 
0039     //! Prevent copying and moving
0040     CELER_DELETE_COPY_MOVE(JsonEventWriter);
0041     ~JsonEventWriter() override = default;
0042 
0043     // Export primaries to json
0044     void operator()(VecPrimary const& primaries) override;
0045 
0046   private:
0047     std::ofstream outfile_;
0048     SPConstParticles particles_;
0049     EventId::size_type event_count_{0};
0050     bool warned_mismatched_events_{false};
0051 };
0052 
0053 //---------------------------------------------------------------------------//
0054 }  // namespace celeritas