Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-15 08:54:42

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/ext/RootImporter.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <string>
0010 
0011 #include "corecel/Config.hh"
0012 
0013 #include "corecel/Assert.hh"
0014 #include "celeritas/io/ImportData.hh"
0015 #include "celeritas/io/ImporterInterface.hh"
0016 
0017 #include "RootUniquePtr.hh"
0018 
0019 // Forward declare ROOT
0020 class TFile;
0021 
0022 namespace celeritas
0023 {
0024 //---------------------------------------------------------------------------//
0025 /*!
0026  * Create an \c ImportData object from a ROOT data file.
0027  *
0028  * RootImporter loads particle, element, material, process, and volume
0029  * information from a ROOT file that contains an \c ImportData object.
0030  * Currently, said ROOT file is created by the \c RootExporter class. The
0031  * imported data will be converted to the native unit system.
0032  *
0033  * \c RootImporter , along with all \c Import[Class] type of classes, are the
0034  * link between Geant4 and Celeritas. Every Celeritas' host/device class that
0035  * relies on imported data has its own \c from_import(...) function that will
0036  * take the data loaded by the \c RootImporter and load it accordingly:
0037  *
0038  * \code
0039  *  RootImporter import("/path/to/root_file.root");
0040  *  const auto data            = import();
0041  *  const auto particle_params = ParticleParams::from_import(data);
0042  *  const auto material_params = MaterialParams::from_import(data);
0043  *  const auto cutoff_params   = CutoffParams::from_import(data);
0044  *  // And so on
0045  * \endcode
0046  */
0047 class RootImporter final : public ImporterInterface
0048 {
0049   public:
0050     // Construct with ROOT file name
0051     explicit RootImporter(char const* filename);
0052 
0053     //! Construct with ROOT file name
0054     explicit RootImporter(std::string const& filename)
0055         : RootImporter(filename.c_str())
0056     {
0057     }
0058 
0059     // Load data from the ROOT files
0060     ImportData operator()() final;
0061 
0062   private:
0063     // ROOT file
0064     UPExtern<TFile> root_input_;
0065 
0066     // ROOT TTree name
0067     static char const* tree_name();
0068     // ROOT TBranch name
0069     static char const* branch_name();
0070 };
0071 
0072 //---------------------------------------------------------------------------//
0073 #if !CELERITAS_USE_ROOT
0074 inline RootImporter::RootImporter(char const*)
0075 {
0076     CELER_NOT_CONFIGURED("ROOT");
0077 }
0078 
0079 inline auto RootImporter::operator()() -> ImportData
0080 {
0081     CELER_ASSERT_UNREACHABLE();
0082 }
0083 #endif
0084 
0085 //---------------------------------------------------------------------------//
0086 }  // namespace celeritas