Back to home page

EIC code displayed by LXR

 
 

    


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

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