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/RootEventWriter.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include <array>
0011 
0012 #include "corecel/Macros.hh"
0013 #include "celeritas/ext/RootFileManager.hh"
0014 #include "celeritas/phys/Primary.hh"
0015 
0016 #include "EventIOInterface.hh"
0017 
0018 namespace celeritas
0019 {
0020 class ParticleParams;
0021 
0022 //---------------------------------------------------------------------------//
0023 /*!
0024  * Export primary data to ROOT.
0025  *
0026  * One TTree entry represents one primary.
0027  */
0028 class RootEventWriter : public EventWriterInterface
0029 {
0030   public:
0031     //!@{
0032     //! \name Type aliases
0033     using SPConstParticles = std::shared_ptr<ParticleParams const>;
0034     using SPRootFileManager = std::shared_ptr<RootFileManager>;
0035     //!@}
0036 
0037     // Construct with ROOT output filename
0038     RootEventWriter(SPRootFileManager root_file_manager,
0039                     SPConstParticles params);
0040 
0041     //! Prevent copying and moving
0042     CELER_DELETE_COPY_MOVE(RootEventWriter);
0043 
0044     // Export primaries to ROOT
0045     void operator()(VecPrimary const& primaries);
0046 
0047   private:
0048     //// DATA ////
0049 
0050     // Basic data types stored to ROOT to avoid the need of a dictionary
0051     struct RootOffloadPrimary
0052     {
0053         std::size_t event_id;
0054         std::size_t track_id;
0055         int particle;
0056         double energy;
0057         double time;
0058         std::array<double, 3> pos;
0059         std::array<double, 3> dir;
0060     };
0061 
0062     SPRootFileManager tfile_mgr_;
0063     SPConstParticles params_;
0064     size_type event_id_;  // Contiguous event id
0065     UPRootTreeWritable ttree_;
0066     RootOffloadPrimary primary_;  // Temporary object stored to the ROOT TTree
0067 
0068     //// HELPER FUNCTIONS ////
0069 
0070     // Hardcoded TTree name and title
0071     char const* tree_name() { return "primaries"; }
0072 };
0073 
0074 //---------------------------------------------------------------------------//
0075 #if !CELERITAS_USE_ROOT
0076 inline RootEventWriter::RootEventWriter(SPRootFileManager, SPConstParticles)
0077 {
0078     CELER_DISCARD(tfile_mgr_);
0079     CELER_DISCARD(params_);
0080     CELER_DISCARD(event_id_);
0081     CELER_DISCARD(ttree_);
0082     CELER_DISCARD(primary_);
0083     CELER_NOT_CONFIGURED("ROOT");
0084 }
0085 
0086 inline void RootEventWriter::operator()(VecPrimary const&)
0087 {
0088     CELER_ASSERT_UNREACHABLE();
0089 }
0090 #endif
0091 
0092 //---------------------------------------------------------------------------//
0093 }  // namespace celeritas