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 %1", parameter); }
72 "Incorrect number of system parameters for GVolume: %1, it should be %2", pars.size(),
86 "the gVolume name <%1> contains the invalid character: <%2>. Exiting.", name,
91 parameters = normalize_optional_geometry_field(pars[i++],
false);
100 emfield = normalize_optional_geometry_field(pars[i++],
true);
102 visible = (pvis ==
"1") ?
true : false;
106 digitization = normalize_optional_geometry_field(pars[i++],
true);
107 gidentity = normalize_optional_geometry_field(pars[i++],
false);
108 copyOf = normalize_optional_geometry_field(pars[i++],
false);
109 solidsOpr = normalize_optional_geometry_field(pars[i++],
false);
110 mirror = normalize_optional_geometry_field(pars[i++],
false);
112 exist = (pexists ==
"1") ?
true : false;
123 string style =
"unknown";
124 if (gVol.style == 0) { style =
"wireframe"; }
125 else if (gVol.style == 1) { style =
"solid"; }
126 else if (gVol.style == 2) { style =
"cloud"; }
127 string visibility =
"yes";
128 if (!gVol.visible) { visibility =
"no"; }
131 stream <<
" - Name: " << gVol.name <<
" - " << gVol.description << std::endl;
132 stream <<
" - System: " << gVol.system << std::endl;
133 stream <<
" - Variation: " << gVol.variation << std::endl;
134 stream <<
" - Run Number: " << gVol.runno << std::endl;
135 if (gVol.copyOf) stream <<
" - copyOf: " << *gVol.copyOf << std::endl;
136 if (gVol.solidsOpr) stream <<
" - solidsOpr: " << *gVol.solidsOpr << std::endl;
138 stream <<
" - Type: " << gVol.type <<
140 if (gVol.parameters) stream <<
" - Parameters: " << *gVol.parameters << std::endl;
141 stream <<
" - Material: " << gVol.material << std::endl;
142 stream <<
" - Mother: " << gVol.motherName << std::endl;
143 stream <<
" - Positions: " << gVol.pos << std::endl;
144 stream <<
" - Rotation(s): " << gVol.rot << std::endl;
145 stream <<
" - G4 Placement: " << gVol.g4placementType << std::endl;
146 if (gVol.emfield) stream <<
" - E.M. field: " << *gVol.emfield << std::endl;
147 if (gVol.digitization) stream <<
" - Digitization: " << *gVol.digitization << std::endl;
148 if (gVol.gidentity) stream <<
" - GIdentity: " << *gVol.gidentity << std::endl;
149 stream <<
" - Col, Vis, Style: " << gVol.color <<
", " << visibility <<
", " << style << std::endl;
157 const std::shared_ptr<GLogger>& logger) :
162 string volumeParameters;
165 for (
size_t i = 1; i < rootDefinitions.size() - 1; i++) { volumeParameters +=
", " + rootDefinitions[i]; }
169 variation =
"default";
170 type = rootDefinitions[0];
171 parameters = volumeParameters;
172 material = rootDefinitions.back();
182 description =
"root volume";
187 digitization = normalize_optional_geometry_field(std::move(value),
true);
191 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)