forked from celeritas-project/celeritas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RootImporter.hh
86 lines (74 loc) · 2.67 KB
/
RootImporter.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//----------------------------------*-C++-*----------------------------------//
// Copyright 2020-2024 UT-Battelle, LLC, and other Celeritas developers.
// See the top-level COPYRIGHT file for details.
// SPDX-License-Identifier: (Apache-2.0 OR MIT)
//---------------------------------------------------------------------------//
//! \file celeritas/ext/RootImporter.hh
//---------------------------------------------------------------------------//
#pragma once
#include <string>
#include "celeritas_config.h"
#include "corecel/Assert.hh"
#include "celeritas/io/ImportData.hh"
#include "celeritas/io/ImporterInterface.hh"
#include "RootUniquePtr.hh"
// Forward declare ROOT
class TFile;
namespace celeritas
{
//---------------------------------------------------------------------------//
/*!
* Create an \c ImportData object from a ROOT data file.
*
* RootImporter loads particle, element, material, process, and volume
* information from a ROOT file that contains an \c ImportData object.
* Currently, said ROOT file is created by the \c RootExporter class. The
* imported data will be converted to the native unit system.
*
* \c RootImporter , along with all \c Import[Class] type of classes, are the
* link between Geant4 and Celeritas. Every Celeritas' host/device class that
* relies on imported data has its own \c from_import(...) function that will
* take the data loaded by the \c RootImporter and load it accordingly:
*
* \code
* RootImporter import("/path/to/root_file.root");
* const auto data = import();
* const auto particle_params = ParticleParams::from_import(data);
* const auto material_params = MaterialParams::from_import(data);
* const auto cutoff_params = CutoffParams::from_import(data);
* // And so on
* \endcode
*/
class RootImporter final : public ImporterInterface
{
public:
// Construct with ROOT file name
explicit RootImporter(char const* filename);
//! Construct with ROOT file name
explicit RootImporter(std::string const& filename)
: RootImporter(filename.c_str())
{
}
// Load data from the ROOT files
ImportData operator()();
private:
// ROOT file
UPExtern<TFile> root_input_;
// ROOT TTree name
static char const* tree_name();
// ROOT TBranch name
static char const* branch_name();
};
//---------------------------------------------------------------------------//
#if !CELERITAS_USE_ROOT
inline RootImporter::RootImporter(char const*)
{
CELER_NOT_CONFIGURED("ROOT");
}
inline auto RootImporter::operator()() -> ImportData
{
CELER_ASSERT_UNREACHABLE();
}
#endif
//---------------------------------------------------------------------------//
} // namespace celeritas