Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 09:09:06

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/EventReader.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <memory>
0010 #include <string>
0011 #include <vector>
0012 
0013 #include "corecel/Config.hh"
0014 
0015 #include "corecel/Assert.hh"
0016 #include "corecel/Macros.hh"
0017 #include "corecel/Types.hh"
0018 
0019 #include "EventIOInterface.hh"
0020 
0021 namespace HepMC3
0022 {
0023 class Reader;
0024 }
0025 
0026 namespace celeritas
0027 {
0028 //---------------------------------------------------------------------------//
0029 class ParticleParams;
0030 struct Primary;
0031 
0032 //---------------------------------------------------------------------------//
0033 /*!
0034  * Read a HepMC3 event record file and create primary particles.
0035  *
0036  * Each \c operator() call returns a vector of primaries from a single event
0037  * until all events have been read. Supported formats are Asciiv3, IO_GenEvent,
0038  * HEPEVT, and LHEF.
0039  *
0040  * \todo Define ImportPrimary with double precision.
0041  */
0042 class EventReader : public EventReaderInterface
0043 {
0044   public:
0045     //!@{
0046     //! \name Type aliases
0047     using SPConstParticles = std::shared_ptr<ParticleParams const>;
0048     using result_type = std::vector<Primary>;
0049     //!@}
0050 
0051   public:
0052     // Construct from a filename
0053     EventReader(std::string const& filename, SPConstParticles particles);
0054 
0055     //! Prevent copying and moving
0056     CELER_DELETE_COPY_MOVE(EventReader);
0057 
0058     ~EventReader() override = default;
0059 
0060     // Read a single event from the event record
0061     result_type operator()() final;
0062 
0063     //! Get total number of events
0064     size_type num_events() const final { return num_events_; }
0065 
0066   private:
0067     using SPReader = std::shared_ptr<HepMC3::Reader>;
0068 
0069     // Shared standard model particle data
0070     SPConstParticles particles_;
0071 
0072     // HepMC3 event record reader
0073     SPReader reader_;
0074 
0075     // Number of events read
0076     size_type event_count_{0};
0077 
0078     // Total number of events in file
0079     size_type num_events_;
0080 };
0081 
0082 //---------------------------------------------------------------------------//
0083 // Set verbosity from the environment (HEPMC3_VERBOSE)
0084 void set_hepmc3_verbosity_from_env();
0085 
0086 //---------------------------------------------------------------------------//
0087 // Wrapper function for HepMC3::deduce_reader to avoid duplicate symbols
0088 std::shared_ptr<HepMC3::Reader> open_hepmc3(std::string const& filename);
0089 
0090 //---------------------------------------------------------------------------//
0091 // INLINE DEFINITIONS
0092 //---------------------------------------------------------------------------//
0093 #if !CELERITAS_USE_HEPMC3
0094 inline EventReader::EventReader(std::string const&, SPConstParticles)
0095 {
0096     CELER_DISCARD(particles_);
0097     CELER_DISCARD(reader_);
0098     CELER_DISCARD(event_count_);
0099     CELER_DISCARD(num_events_);
0100     CELER_NOT_CONFIGURED("HepMC3");
0101 }
0102 
0103 inline auto EventReader::operator()() -> result_type
0104 {
0105     CELER_ASSERT_UNREACHABLE();
0106 }
0107 
0108 inline void set_hepmc3_verbosity_from_env() {}
0109 #endif
0110 
0111 //---------------------------------------------------------------------------//
0112 }  // namespace celeritas