Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-22 10:31:24

0001 //----------------------------------*-C++-*----------------------------------//
0002 // Copyright 2023-2024 UT-Battelle, LLC, and other Celeritas developers.
0003 // See the top-level COPYRIGHT file for details.
0004 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0005 //---------------------------------------------------------------------------//
0006 //! \file celeritas/io/EventWriter.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include <memory>
0011 #include <string>
0012 
0013 #include "corecel/Config.hh"
0014 
0015 #include "corecel/Assert.hh"
0016 #include "corecel/Macros.hh"
0017 #include "celeritas/Types.hh"
0018 
0019 #include "EventIOInterface.hh"
0020 
0021 namespace HepMC3
0022 {
0023 class Writer;
0024 }
0025 
0026 namespace celeritas
0027 {
0028 //---------------------------------------------------------------------------//
0029 class ParticleParams;
0030 
0031 //---------------------------------------------------------------------------//
0032 /*!
0033  * Write events using HepMC3.
0034  */
0035 class EventWriter : public EventWriterInterface
0036 {
0037   public:
0038     //!@{
0039     //! \name Type aliases
0040     using SPConstParticles = std::shared_ptr<ParticleParams const>;
0041     //!@}
0042 
0043     //! Output format
0044     enum class Format
0045     {
0046         hepevt,
0047         hepmc2,
0048         hepmc3,
0049         size_
0050     };
0051 
0052   public:
0053     // Construct by parsing the extension
0054     EventWriter(std::string const& filename, SPConstParticles params);
0055 
0056     // Construct with a filename, particle data, and output format
0057     EventWriter(std::string const& filename,
0058                 SPConstParticles params,
0059                 Format fmt);
0060 
0061     //! Prevent copying and moving due to file ownership
0062     CELER_DELETE_COPY_MOVE(EventWriter);
0063 
0064     // Write all the primaries from a single event
0065     void operator()(VecPrimary const& primaries) final;
0066 
0067   private:
0068     // Shared standard model particle data
0069     SPConstParticles particles_;
0070 
0071     Format fmt_;
0072 
0073     // HepMC3 event record writer
0074     std::shared_ptr<HepMC3::Writer> writer_;
0075 
0076     // Number of events written
0077     EventId::size_type event_count_{0};
0078 };
0079 
0080 //---------------------------------------------------------------------------//
0081 // FREE FUNCTIONS
0082 //---------------------------------------------------------------------------//
0083 char const* to_cstring(EventWriter::Format);
0084 
0085 //---------------------------------------------------------------------------//
0086 // INLINE DEFINITIONS
0087 //---------------------------------------------------------------------------//
0088 #if !CELERITAS_USE_HEPMC3
0089 inline EventWriter::EventWriter(std::string const& s, SPConstParticles p)
0090     : EventWriter{s, p, Format::size_}
0091 {
0092 }
0093 inline EventWriter::EventWriter(std::string const&, SPConstParticles, Format)
0094 {
0095     CELER_DISCARD(particles_);
0096     CELER_DISCARD(fmt_);
0097     CELER_DISCARD(writer_);
0098     CELER_DISCARD(event_count_);
0099     CELER_NOT_CONFIGURED("HepMC3");
0100 }
0101 
0102 inline void EventWriter::operator()(argument_type)
0103 {
0104     CELER_ASSERT_UNREACHABLE();
0105 }
0106 #endif
0107 
0108 //---------------------------------------------------------------------------//
0109 }  // namespace celeritas