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() != GVOLUMENUMBEROFPARS) {
26 // Dump received parameters to help diagnose mismatched schema or input corruption.
27 for (auto& parameter : pars) { log->warning(" - parameter ", parameter); }
28
30 "Incorrect number of system parameters for GVolume: ", pars.size(), ", it should be ",
32 }
33 else {
34 // The parameter vector is a serialized DB/ASCII row. Parsing is positional.
35 int i = 0;
36
37 name = removeAllSpacesFromString(pars[i++]);
38
39 // checking that name does not contain GSYSTEM_DELIMITER
40 // because GSYSTEM_DELIMITER is used later to build fully-qualified Geant4 names.
41 if (name.find(GSYSTEM_DELIMITER) != string::npos) {
43 "the gVolume name <", name, "> contains the invalid character: <", GSYSTEM_DELIMITER,
44 ">. Exiting.");
45 }
46
47 type = removeAllSpacesFromString(pars[i++]);
48 parameters = removeLeadingAndTrailingSpacesFromString(pars[i++]);
49 material = removeAllSpacesFromString(pars[i++]);
50 motherName = removeAllSpacesFromString(pars[i++]);
53 emfield = removeAllSpacesFromString(pars[i++]);
54 string pvis = removeAllSpacesFromString(pars[i++]);
55 visible = (pvis == "1") ? true : false;
56 style = stoi(removeAllSpacesFromString(pars[i++]));
57 color = removeAllSpacesFromString(pars[i++]);
58 opacity = stod(removeAllSpacesFromString(pars[i++]));
59 digitization = removeAllSpacesFromString(pars[i++]);
60 gidentity = removeLeadingAndTrailingSpacesFromString(pars[i++]);
62 solidsOpr = removeLeadingAndTrailingSpacesFromString(pars[i++]);
64 string pexists = removeAllSpacesFromString(pars[i++]);
65 exist = (pexists == "1") ? true : false;
66
67 // these will be assigned later
69 g4motherName = UNINITIALIZEDSTRINGQUANTITY;
70
71 description = removeLeadingAndTrailingSpacesFromString(pars[i++]);
72 variation = removeLeadingAndTrailingSpacesFromString(pars[i++]);
73 runno = stoi(removeAllSpacesFromString(pars[i++]));
74
75 // modifiers - accessed through options/jcard
76 shift = GSYSTEMNOMODIFIER;
77 tilt = GSYSTEMNOMODIFIER;
78 }
79}
80
81
82std::ostream& operator<<(std::ostream& stream, const GVolume& gVol) {
83 string style = "unknown";
84 if (gVol.style == 0) { style = "wireframe"; }
85 else if (gVol.style == 1) { style = "solid"; }
86 else if (gVol.style == 2) { style = "cloud"; }
87 string visibility = "yes";
88 if (!gVol.visible) { visibility = "no"; }
89
90 stream << std::endl;
91 stream << " - Name: " << gVol.name << " - " << gVol.description << std::endl;
92 stream << " - System: " << gVol.system << std::endl;
93 stream << " - Variation: " << gVol.variation << std::endl;
94 stream << " - Run Number: " << gVol.runno << std::endl;
95 if (gVol.copyOf != "" && gVol.copyOf != UNINITIALIZEDSTRINGQUANTITY)
96 stream << " - copyOf: " << gVol.
97 copyOf << std::endl;
98 if (gVol.solidsOpr != "" && gVol.solidsOpr != UNINITIALIZEDSTRINGQUANTITY)
99 stream << " - solidsOpr: "
100 << gVol.solidsOpr << std::endl;
101 if (gVol.type != "" && gVol.type != UNINITIALIZEDSTRINGQUANTITY)
102 stream << " - Type: " << gVol.type <<
103 std::endl;
104 if (gVol.parameters != "" && gVol.parameters != UNINITIALIZEDSTRINGQUANTITY)
105 stream << " - Parameters: " <<
106 gVol.parameters << std::endl;
107 stream << " - Material: " << gVol.material << std::endl;
108 stream << " - Mother: " << gVol.motherName << std::endl;
109 stream << " - Positions: " << gVol.pos << std::endl;
110 stream << " - Rotation(s): " << gVol.rot << std::endl;
111 if (gVol.emfield != "" && gVol.emfield != UNINITIALIZEDSTRINGQUANTITY)
112 stream << " - E.M. emfield: " << gVol.
113 emfield << std::endl;
114 if (gVol.digitization != "" && gVol.digitization != UNINITIALIZEDSTRINGQUANTITY)
115 stream << " - Digitization: "
116 << gVol.digitization << std::endl;
117 if (gVol.gidentity != "" && gVol.gidentity != UNINITIALIZEDSTRINGQUANTITY)
118 stream << " - GIdentity: " <<
119 gVol.gidentity << std::endl;
120 stream << " - Col, Vis, Style: " << gVol.color << ", " << visibility << ", " << style << std::endl;
121 stream << std::endl;
122
123 return stream;
124}
125
126
127GVolume::GVolume(const std::string& rootVolumeDefinition, const std::shared_ptr<GLogger>& logger) : GBase(logger) {
128 // The ROOT/world definition is tokenized by spaces:
129 // <solidType> <dim1> <dim2> ... <material>
130 vector<string> rootDefinitions = getStringVectorFromStringWithDelimiter(rootVolumeDefinition, " ");
131 string volumeParameters;
132
133 // Build the parameter string (skip the type and the final material token).
134 for (size_t i = 1; i < rootDefinitions.size() - 1; i++) { volumeParameters += ", " + rootDefinitions[i]; }
135
137 system = ROOTWORLDGVOLUMENAME;
138 variation = "default";
139 type = rootDefinitions[0];
140 parameters = volumeParameters;
141 material = rootDefinitions.back();
142 motherName = MOTHEROFUSALL;
143 pos = DEFAULTPOSITION;
144 rot = DEFAULTROTATION;
145 emfield = "";
146 visible = false;
147 style = 0; // wireframe
148 color = "ccffff";
149 digitization = "";
150 gidentity = "";
151 copyOf = "";
152 solidsOpr = "";
153 mirror = "";
154 exist = true;
155
156 description = "root volume";
157
158 // modifiers - accessed through options/jcard
159 shift = GSYSTEMNOMODIFIER;
160 tilt = GSYSTEMNOMODIFIER;
161
162 // set file with its path if it's a CAD/GDML import
163 importFilename = "none";
164}
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:33
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 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 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:82
string removeAllSpacesFromString(const std::string &str)
vector< string > getStringVectorFromStringWithDelimiter(const string &input, const string &x)
string removeLeadingAndTrailingSpacesFromString(const std::string &input)