forked from celeritas-project/celeritas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GeantImporter.hh
142 lines (118 loc) · 4.2 KB
/
GeantImporter.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
//----------------------------------*-C++-*----------------------------------//
// Copyright 2022-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/GeantImporter.hh
//---------------------------------------------------------------------------//
#pragma once
#include <memory>
#include "celeritas_config.h"
#include "celeritas/io/ImportData.hh"
#include "celeritas/io/ImporterInterface.hh"
#include "GeantSetup.hh"
// Geant4 forward declaration
class G4VPhysicalVolume; // IWYU pragma: keep
namespace celeritas
{
//---------------------------------------------------------------------------//
//! Only import a subset of available Geant4 data
struct GeantImportDataSelection
{
//! Bit flags for selecting particles and process types
using Flags = unsigned int;
enum : unsigned int
{
none = 0x0,
dummy = 0x1, //!< Dummy particles+processes
em_basic = 0x2, //!< Electron, positron, gamma
em_ex = 0x4, //!< Extended EM particles
em = em_basic | em_ex, //!< Any EM
hadron = 0x8, //!< Hadronic particles and processes
};
Flags particles = em;
bool materials = true;
Flags processes = em;
//! Change volume names to match exported GDML file
bool unique_volumes = false;
// TODO expand/set reader flags automatically based on loaded processes
bool reader_data = true;
};
//---------------------------------------------------------------------------//
/*!
* Load problem data directly from Geant4.
*
* This can be used to circumvent ROOT as a serialization tool, whether to
* simplify the toolchain or to integrate better with Acceleritas.
*
* \code
GeantImporter import(GeantSetup("blah.gdml"));
ImportData data = import();
\endcode
* or to import from an existing, initialized Geant4 state:
* \code
* GeantImport import(world_volume);
ImportData data = import();
* \endcode
*/
class GeantImporter final : public ImporterInterface
{
public:
//!@{
//! \name Type aliases
using DataSelection = GeantImportDataSelection;
//!@}
public:
// Get an externally loaded Geant4 top-level geometry element
static G4VPhysicalVolume const* get_world_volume();
// Construct from an existing Geant4 geometry, assuming physics is loaded
explicit GeantImporter(G4VPhysicalVolume const* world);
// Construct by capturing a GeantSetup object
explicit GeantImporter(GeantSetup&& setup);
// Fill data from Geant4
ImportData operator()(DataSelection const& selection);
//! Fill all available data from Geant4
ImportData operator()() { return (*this)(DataSelection{}); }
private:
// Optional setup if celeritas handles initialization
GeantSetup setup_;
// World physical volume
G4VPhysicalVolume const* world_{nullptr};
//// HELPER FUNCTIONS ////
std::vector<ImportVolume> import_volumes(bool unique_volumes) const;
};
//---------------------------------------------------------------------------//
// INLINE DEFINITIONS
//---------------------------------------------------------------------------//
inline bool operator==(GeantImporter::DataSelection const& lhs,
GeantImporter::DataSelection const& rhs)
{
return lhs.particles == rhs.particles && lhs.processes == rhs.processes
&& lhs.reader_data == rhs.reader_data;
}
inline bool operator!=(GeantImporter::DataSelection const& lhs,
GeantImporter::DataSelection const& rhs)
{
return !(lhs == rhs);
}
#if !CELERITAS_USE_GEANT4
inline G4VPhysicalVolume const* GeantImporter::get_world_volume()
{
CELER_NOT_CONFIGURED("Geant4");
}
inline GeantImporter::GeantImporter(G4VPhysicalVolume const*)
{
CELER_DISCARD(world_);
CELER_NOT_CONFIGURED("Geant4");
}
inline GeantImporter::GeantImporter(GeantSetup&&)
{
CELER_NOT_CONFIGURED("Geant4");
}
inline ImportData GeantImporter::operator()(DataSelection const&)
{
CELER_ASSERT_UNREACHABLE();
}
#endif
//---------------------------------------------------------------------------//
} // namespace celeritas