21std::optional<std::string> normalize_optional_geometry_field(std::optional<std::string> value,
22 bool remove_all_spaces) {
23 if (!value)
return std::nullopt;
26 if (
is_unset(trimmed))
return std::nullopt;
28 std::string lowercase = trimmed;
29 std::transform(lowercase.begin(), lowercase.end(), lowercase.begin(),
30 [](
unsigned char c) { return static_cast<char>(std::tolower(c)); });
31 if (lowercase ==
"no" || lowercase ==
"none" || lowercase ==
"not provided")
return std::nullopt;
40 throw std::logic_error(
"Geant4 name requested before GVolume <" + system +
"/" + name +
"> was resolved");
47 throw std::logic_error(
48 "Geant4 mother name requested before GVolume <" + system +
"/" + name +
"> was resolved");
57 std::vector<std::string> pars,
58 std::optional<std::string> importPath) :
61 importFilename(normalize_optional_geometry_field(std::move(importPath), false)) {
63 pars.insert(pars.begin() + 7, gsystem::DEFAULTG4PLACEMENTTYPE);
68 for (auto& parameter : pars) { log->warning(
" - parameter ", parameter); }
71 "Incorrect number of system parameters for GVolume: ", pars.size(),
", it should be ",
89 parameters = normalize_optional_geometry_field(pars[i++],
false);
98 emfield = normalize_optional_geometry_field(pars[i++],
true);
100 visible = (pvis ==
"1") ?
true : false;
104 digitization = normalize_optional_geometry_field(pars[i++],
true);
105 gidentity = normalize_optional_geometry_field(pars[i++],
false);
106 copyOf = normalize_optional_geometry_field(pars[i++],
false);
107 solidsOpr = normalize_optional_geometry_field(pars[i++],
false);
108 mirror = normalize_optional_geometry_field(pars[i++],
false);
110 exist = (pexists ==
"1") ?
true : false;
121 string style =
"unknown";
122 if (gVol.style == 0) { style =
"wireframe"; }
123 else if (gVol.style == 1) { style =
"solid"; }
124 else if (gVol.style == 2) { style =
"cloud"; }
125 string visibility =
"yes";
126 if (!gVol.visible) { visibility =
"no"; }
129 stream <<
" - Name: " << gVol.name <<
" - " << gVol.description << std::endl;
130 stream <<
" - System: " << gVol.system << std::endl;
131 stream <<
" - Variation: " << gVol.variation << std::endl;
132 stream <<
" - Run Number: " << gVol.runno << std::endl;
133 if (gVol.copyOf) stream <<
" - copyOf: " << *gVol.copyOf << std::endl;
134 if (gVol.solidsOpr) stream <<
" - solidsOpr: " << *gVol.solidsOpr << std::endl;
136 stream <<
" - Type: " << gVol.type <<
138 if (gVol.parameters) stream <<
" - Parameters: " << *gVol.parameters << std::endl;
139 stream <<
" - Material: " << gVol.material << std::endl;
140 stream <<
" - Mother: " << gVol.motherName << std::endl;
141 stream <<
" - Positions: " << gVol.pos << std::endl;
142 stream <<
" - Rotation(s): " << gVol.rot << std::endl;
143 stream <<
" - G4 Placement: " << gVol.g4placementType << std::endl;
144 if (gVol.emfield) stream <<
" - E.M. field: " << *gVol.emfield << std::endl;
145 if (gVol.digitization) stream <<
" - Digitization: " << *gVol.digitization << std::endl;
146 if (gVol.gidentity) stream <<
" - GIdentity: " << *gVol.gidentity << std::endl;
147 stream <<
" - Col, Vis, Style: " << gVol.color <<
", " << visibility <<
", " << style << std::endl;
155 const std::shared_ptr<GLogger>& logger) :
160 string volumeParameters;
163 for (
size_t i = 1; i < rootDefinitions.size() - 1; i++) { volumeParameters +=
", " + rootDefinitions[i]; }
167 variation =
"default";
168 type = rootDefinitions[0];
169 parameters = volumeParameters;
170 material = rootDefinitions.back();
180 description =
"root volume";
185 digitization = normalize_optional_geometry_field(std::move(value),
true);
189 gidentity = normalize_optional_geometry_field(std::move(value),
false);
GBase(const std::shared_ptr< GOptions > &gopt, std::string logger_name="")
std::shared_ptr< GLogger > log
void setGIdentity(std::optional< std::string > g)
Override the identity string after loading.
void setDigitization(std::optional< std::string > d)
Override the digitization label after loading.
const std::string & getG4Name() const
GVolume(const std::shared_ptr< GLogger > &log, const std::string &system, std::vector< std::string > pars, std::optional< std::string > importPath=std::nullopt)
Construct a volume from a serialized parameter vector.
const std::string & getG4MotherName() const
Conventions and shared constants for the detector-system module.
std::ostream & operator<<(std::ostream &stream, const GVolume &gVol)
constexpr int GVOLUMELEGACYNUMBEROFPARS
Number of database parameters defining a legacy gvolume entry without g4placement_type.
constexpr int ERR_GWRONGNUMBEROFPARS
constexpr char DEFAULTG4PLACEMENTTYPE[]
constexpr char GSYSTEM_DELIMITER[]
Delimiter used to build fully-qualified names (system/name).
constexpr char DEFAULTROTATION[]
constexpr int ERR_GVOLUMENAMECONTAINSINVALID
constexpr int GVOLUMENUMBEROFPARS
constexpr char MOTHEROFUSALL[]
Special mother-name marker for the top-level world root.
constexpr char DEFAULTPOSITION[]
constexpr char ROOTWORLDGVOLUMENAME[]
Canonical name for the ROOT/world gvolume entry.
string removeAllSpacesFromString(const std::string &str)
vector< string > getStringVectorFromStringWithDelimiter(const string &input, const string &x)
bool is_unset(std::string_view s)
string removeLeadingAndTrailingSpacesFromString(const std::string &input)