gsystem
Loading...
Searching...
No Matches
optional_volume_fields.cc
Go to the documentation of this file.
1
5
6#include "gvolume.h"
7
8#include <cstdlib>
9#include <memory>
10#include <optional>
11#include <stdexcept>
12#include <string>
13#include <vector>
14
15namespace {
16
17std::vector<std::string> volume_parameters(const std::string& emfield,
18 const std::string& digitization,
19 const std::string& identity,
20 const std::string& copy_of,
21 const std::string& solids_operation,
22 const std::string& mirror,
23 const std::string& parameters = "1*cm, 2*cm, 3*cm") {
24 return {
25 "test_volume", "G4Box", parameters, "G4_AIR", "root",
26 "0*cm, 0*cm, 0*cm", "0*deg, 0*deg, 0*deg", "active", emfield,
27 "1", "1", "778899", "1", digitization, identity, copy_of,
28 solids_operation, mirror, "1", "optional field test", "default", "1"
29 };
30}
31
32} // namespace
33
34int main() {
35 const std::shared_ptr<GLogger> logger;
36 GVolume unset(logger, "test",
37 volume_parameters(" NULL ", " not provided ", "~", " no ", "", " none "),
38 " none ");
39
40 if (unset.getEMField() || unset.getDigitization() || unset.getGIdentity() || unset.getCopyOf() ||
41 unset.getSolidsOpr() || unset.getMirror() || unset.getImportedFile() || unset.getShift() ||
42 unset.getTilt()) {
43 return EXIT_FAILURE;
44 }
45 try {
46 [[maybe_unused]] const auto& unresolvedName = unset.getG4Name();
47 return EXIT_FAILURE;
48 }
49 catch (const std::logic_error&) {
50 }
51 unset.assignG4Names("test/test_volume", "root/root");
52 if (unset.getG4Name() != "test/test_volume" || unset.getG4MotherName() != "root/root") {
53 return EXIT_FAILURE;
54 }
55 GVolume imported(logger, "test",
56 volume_parameters("NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL"));
57 if (imported.getParameters() || !imported.getDetectorDimensions().empty()) return EXIT_FAILURE;
58
59 GVolume configured(logger, "test",
60 volume_parameters(" torus field ", " flux ", " sector: 1 ", " source ",
61 " left + right ", " aluminum "),
62 " meshes/part.stl ");
63
64 if (configured.getEMField() != std::optional<std::string>{"torusfield"} ||
65 configured.getDigitization() != std::optional<std::string>{"flux"} ||
66 configured.getGIdentity() != std::optional<std::string>{"sector: 1"} ||
67 configured.getCopyOf() != std::optional<std::string>{"source"} ||
68 configured.getSolidsOpr() != std::optional<std::string>{"left + right"} ||
69 configured.getMirror() != std::optional<std::string>{"aluminum"} ||
70 configured.getImportedFile() != std::optional<std::string>{"meshes/part.stl"}) {
71 return EXIT_FAILURE;
72 }
73
74 configured.setDigitization(" NULL ");
75 configured.setGIdentity(std::nullopt);
76 configured.applyShift("1*cm, 2*cm, 3*cm");
77 configured.applyTilt("1*deg, 2*deg, 3*deg");
78 if (configured.getShift() != std::optional<std::string>{"1*cm, 2*cm, 3*cm"} ||
79 configured.getTilt() != std::optional<std::string>{"1*deg, 2*deg, 3*deg"}) {
80 return EXIT_FAILURE;
81 }
82 return configured.getDigitization() || configured.getGIdentity() ? EXIT_FAILURE : EXIT_SUCCESS;
83}
Geometry volume record loaded into a GSystem.
Definition gvolume.h:35
const std::optional< std::string > & getTilt() const
Definition gvolume.h:195
void setGIdentity(std::optional< std::string > g)
Override the identity string after loading.
Definition gvolume.cc:188
void setDigitization(std::optional< std::string > d)
Override the digitization label after loading.
Definition gvolume.cc:184
const std::string & getG4Name() const
Definition gvolume.cc:38
void assignG4Names(const std::string &g4n, const std::string &g4m)
Assign Geant4 names after all volumes are loaded.
Definition gvolume.h:278
void applyTilt(std::optional< std::string > t)
Apply an additional rotation to this volume.
Definition gvolume.h:232
const std::optional< std::string > & getSolidsOpr() const
Definition gvolume.h:207
void applyShift(std::optional< std::string > s)
Apply an additional translation to this volume.
Definition gvolume.h:222
const std::optional< std::string > & getParameters() const
Definition gvolume.h:170
const std::optional< std::string > & getCopyOf() const
Definition gvolume.h:206
const std::optional< std::string > & getGIdentity() const
Definition gvolume.h:201
const std::optional< std::string > & getShift() const
Definition gvolume.h:194
const std::optional< std::string > & getImportedFile() const
Return the import filename (path) for imported volumes.
Definition gvolume.h:267
const std::optional< std::string > & getEMField() const
Definition gvolume.h:176
std::vector< double > getDetectorDimensions() const
Returns numeric detector dimensions parsed from the parameters string.
Definition gvolume.h:162
const std::string & getG4MotherName() const
Definition gvolume.cc:45
const std::optional< std::string > & getMirror() const
Definition gvolume.h:208
const std::optional< std::string > & getDigitization() const
Definition gvolume.h:200