gsystem
Loading...
Searching...
No Matches
gvolume.cc
Go to the documentation of this file.
1
8// gsystem
9#include "gvolume.h"
10
11#include <utility>
12#include "gsystemConventions.h"
13
14using namespace gutilities;
15
16// need to set pCopyNo with unique identifier
17// see c++ thread safe ID generation function
18GVolume::GVolume(const std::shared_ptr<GLogger>& logger,
19 const std::string& s,
20 std::vector<std::string> pars,
21 const std::string& importPath) :
22 GBase(logger),
23 system(s),
24 importFilename(importPath) {
25 if (pars.size() == GVOLUMELEGACYNUMBEROFPARS) {
26 pars.insert(pars.begin() + 7, DEFAULTG4PLACEMENTTYPE);
27 }
28
29 if (pars.size() != GVOLUMENUMBEROFPARS) {
30 // Dump received parameters to help diagnose mismatched schema or input corruption.
31 for (auto& parameter : pars) { log->warning(" - parameter ", parameter); }
32
34 "Incorrect number of system parameters for GVolume: ", pars.size(), ", it should be ",
36 }
37 else {
38 // The parameter vector is a serialized DB/ASCII row. Parsing is positional.
39 int i = 0;
40
41 name = removeAllSpacesFromString(pars[i++]);
42
43 // checking that name does not contain GSYSTEM_DELIMITER
44 // because GSYSTEM_DELIMITER is used later to build fully-qualified Geant4 names.
45 if (name.find(GSYSTEM_DELIMITER) != string::npos) {
47 "the gVolume name <", name, "> contains the invalid character: <", GSYSTEM_DELIMITER,
48 ">. Exiting.");
49 }
50
51 type = removeAllSpacesFromString(pars[i++]);
52 parameters = removeLeadingAndTrailingSpacesFromString(pars[i++]);
53 material = removeAllSpacesFromString(pars[i++]);
54 motherName = removeAllSpacesFromString(pars[i++]);
57 g4placementType = removeAllSpacesFromString(pars[i++]);
58 if (g4placementType == "" || g4placementType == UNINITIALIZEDSTRINGQUANTITY) {
59 g4placementType = DEFAULTG4PLACEMENTTYPE;
60 }
61 emfield = removeAllSpacesFromString(pars[i++]);
62 string pvis = removeAllSpacesFromString(pars[i++]);
63 visible = (pvis == "1") ? true : false;
64 style = stoi(removeAllSpacesFromString(pars[i++]));
65 color = removeAllSpacesFromString(pars[i++]);
66 opacity = stod(removeAllSpacesFromString(pars[i++]));
67 digitization = removeAllSpacesFromString(pars[i++]);
68 gidentity = removeLeadingAndTrailingSpacesFromString(pars[i++]);
70 solidsOpr = removeLeadingAndTrailingSpacesFromString(pars[i++]);
72 string pexists = removeAllSpacesFromString(pars[i++]);
73 exist = (pexists == "1") ? true : false;
74
75 // these will be assigned later
77 g4motherName = UNINITIALIZEDSTRINGQUANTITY;
78
79 description = removeLeadingAndTrailingSpacesFromString(pars[i++]);
80 variation = removeLeadingAndTrailingSpacesFromString(pars[i++]);
81 runno = stoi(removeAllSpacesFromString(pars[i++]));
82
83 // modifiers - accessed through options/jcard
84 shift = GSYSTEMNOMODIFIER;
85 tilt = GSYSTEMNOMODIFIER;
86 }
87}
88
89
90std::ostream& operator<<(std::ostream& stream, const GVolume& gVol) {
91 string style = "unknown";
92 if (gVol.style == 0) { style = "wireframe"; }
93 else if (gVol.style == 1) { style = "solid"; }
94 else if (gVol.style == 2) { style = "cloud"; }
95 string visibility = "yes";
96 if (!gVol.visible) { visibility = "no"; }
97
98 stream << std::endl;
99 stream << " - Name: " << gVol.name << " - " << gVol.description << std::endl;
100 stream << " - System: " << gVol.system << std::endl;
101 stream << " - Variation: " << gVol.variation << std::endl;
102 stream << " - Run Number: " << gVol.runno << std::endl;
103 if (gVol.copyOf != "" && gVol.copyOf != UNINITIALIZEDSTRINGQUANTITY)
104 stream << " - copyOf: " << gVol.
105 copyOf << std::endl;
106 if (gVol.solidsOpr != "" && gVol.solidsOpr != UNINITIALIZEDSTRINGQUANTITY)
107 stream << " - solidsOpr: "
108 << gVol.solidsOpr << std::endl;
109 if (gVol.type != "" && gVol.type != UNINITIALIZEDSTRINGQUANTITY)
110 stream << " - Type: " << gVol.type <<
111 std::endl;
112 if (gVol.parameters != "" && gVol.parameters != UNINITIALIZEDSTRINGQUANTITY)
113 stream << " - Parameters: " <<
114 gVol.parameters << std::endl;
115 stream << " - Material: " << gVol.material << std::endl;
116 stream << " - Mother: " << gVol.motherName << std::endl;
117 stream << " - Positions: " << gVol.pos << std::endl;
118 stream << " - Rotation(s): " << gVol.rot << std::endl;
119 stream << " - G4 Placement: " << gVol.g4placementType << std::endl;
120 if (gVol.emfield != "" && gVol.emfield != UNINITIALIZEDSTRINGQUANTITY)
121 stream << " - E.M. emfield: " << gVol.
122 emfield << std::endl;
123 if (gVol.digitization != "" && gVol.digitization != UNINITIALIZEDSTRINGQUANTITY)
124 stream << " - Digitization: "
125 << gVol.digitization << std::endl;
126 if (gVol.gidentity != "" && gVol.gidentity != UNINITIALIZEDSTRINGQUANTITY)
127 stream << " - GIdentity: " <<
128 gVol.gidentity << std::endl;
129 stream << " - Col, Vis, Style: " << gVol.color << ", " << visibility << ", " << style << std::endl;
130 stream << std::endl;
131
132 return stream;
133}
134
135
136GVolume::GVolume(const std::string& rootVolumeDefinition,
137 const std::shared_ptr<GLogger>& logger) :
138 GBase(logger) {
139 // The ROOT/world definition is tokenized by spaces:
140 // <solidType> <dim1> <dim2> ... <material>
141 vector<string> rootDefinitions = getStringVectorFromStringWithDelimiter(rootVolumeDefinition, " ");
142 string volumeParameters;
143
144 // Build the parameter string (skip the type and the final material token).
145 for (size_t i = 1; i < rootDefinitions.size() - 1; i++) { volumeParameters += ", " + rootDefinitions[i]; }
146
148 system = ROOTWORLDGVOLUMENAME;
149 variation = "default";
150 type = rootDefinitions[0];
151 parameters = volumeParameters;
152 material = rootDefinitions.back();
153 motherName = MOTHEROFUSALL;
154 pos = DEFAULTPOSITION;
155 rot = DEFAULTROTATION;
156 g4placementType = DEFAULTG4PLACEMENTTYPE;
157 emfield = "";
158 visible = false;
159 style = 0; // wireframe
160 color = "ccffff";
161 digitization = "";
162 gidentity = "";
163 copyOf = "";
164 solidsOpr = "";
165 mirror = "";
166 exist = true;
167
168 description = "root volume";
169
170 // modifiers - accessed through options/jcard
171 shift = GSYSTEMNOMODIFIER;
172 tilt = GSYSTEMNOMODIFIER;
173
174 // set file with its path if it's a CAD/GDML import
175 importFilename = "none";
176}
std::shared_ptr< GLogger > log
void warning(Args &&... args) const
void error(int exit_code, Args &&... args) const
Geometry volume record loaded into a GSystem.
Definition gvolume.h:34
GVolume(const std::shared_ptr< GLogger > &log, const std::string &system, std::vector< std::string > pars, const std::string &importPath=UNINITIALIZEDSTRINGQUANTITY)
Construct a volume from a serialized parameter vector.
Definition gvolume.cc:18
Conventions and shared constants for the detector-system module.
#define DEFAULTPOSITION
#define DEFAULTG4PLACEMENTTYPE
#define GSYSTEM_DELIMITER
Delimiter used to build fully-qualified names (system/name).
#define GVOLUMENUMBEROFPARS
#define GSYSTEMNOMODIFIER
#define ROOTWORLDGVOLUMENAME
Canonical name for the ROOT/world gvolume entry.
#define GVOLUMELEGACYNUMBEROFPARS
Number of database parameters defining a legacy gvolume entry without g4placement_type.
#define DEFAULTROTATION
#define MOTHEROFUSALL
Special mother-name marker for the top-level world root.
#define ERR_GVOLUMENAMECONTAINSINVALID
#define ERR_GWRONGNUMBEROFPARS
#define UNINITIALIZEDSTRINGQUANTITY
std::ostream & operator<<(std::ostream &stream, const GVolume &gVol)
Definition gvolume.cc:90
string removeAllSpacesFromString(const std::string &str)
vector< string > getStringVectorFromStringWithDelimiter(const string &input, const string &x)
string removeLeadingAndTrailingSpacesFromString(const std::string &input)