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/OpticalDistributionWriter.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <fstream>
0010 #include <mutex>
0011 #include <string>
0012 
0013 #include "corecel/Macros.hh"
0014 #include "celeritas/optical/gen/GeneratorData.hh"
0015 
0016 namespace celeritas
0017 {
0018 //---------------------------------------------------------------------------//
0019 /*!
0020  * Export optical distribution data to JSONL.
0021  *
0022  * This class is thread-safe for concurrent writes: calls to \c operator() are
0023  * serialized using an internal mutex. The writer must be constructed on the
0024  * main thread.
0025  *
0026  * \todo The mutex may be duplicated with OffloadWriter.
0027  */
0028 class OpticalDistributionWriter
0029 {
0030   public:
0031     //!@{
0032     //! \name Type aliases
0033     using VecDistribution = std::vector<optical::GeneratorDistributionData>;
0034     //!@}
0035 
0036     // Construct with output filename
0037     explicit OpticalDistributionWriter(std::string const& filename);
0038 
0039     //! Prevent copying and moving
0040     CELER_DELETE_COPY_MOVE(OpticalDistributionWriter);
0041     ~OpticalDistributionWriter() = default;
0042 
0043     // Export primaries to json
0044     void operator()(VecDistribution const&);
0045 
0046   private:
0047     std::mutex write_mutex_;
0048     std::ofstream outfile_;
0049 };
0050 
0051 //---------------------------------------------------------------------------//
0052 }  // namespace celeritas