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 string visibility = "yes";
87 if (!gVol.visible) { visibility = "no"; }
88
89 stream << std::endl;
90 stream << " - Name: " << gVol.name << " - " << gVol.description << std::endl;
91 stream << " - System: " << gVol.system << std::endl;
92 stream << " - Variation: " << gVol.variation << std::endl;
93 stream << " - Run Number: " << gVol.runno << std::endl;
94 if (gVol.copyOf != "" && gVol.copyOf != UNINITIALIZEDSTRINGQUANTITY)
95 stream << " - copyOf: " << gVol.
96 copyOf << std::endl;
97 if (gVol.solidsOpr != "" && gVol.solidsOpr != UNINITIALIZEDSTRINGQUANTITY)
98 stream << " - solidsOpr: "
99 << gVol.solidsOpr << std::endl;
100 if (gVol.type != "" && gVol.type != UNINITIALIZEDSTRINGQUANTITY)
101 stream << " - Type: " << gVol.type <<
102 std::endl;
103 if (gVol.parameters != "" && gVol.parameters != UNINITIALIZEDSTRINGQUANTITY)
104 stream << " - Parameters: " <<
105 gVol.parameters << std::endl;
106 stream << " - Material: " << gVol.material << std::endl;
107 stream << " - Mother: " << gVol.motherName << std::endl;
108 stream << " - Positions: " << gVol.pos << std::endl;
109 stream << " - Rotation(s): " << gVol.rot << std::endl;
110 if (gVol.emfield != "" && gVol.emfield != UNINITIALIZEDSTRINGQUANTITY)
111 stream << " - E.M. emfield: " << gVol.
112 emfield << std::endl;
113 if (gVol.digitization != "" && gVol.digitization != UNINITIALIZEDSTRINGQUANTITY)
114 stream << " - Digitization: "
115 << gVol.digitization << std::endl;
116 if (gVol.gidentity != "" && gVol.gidentity != UNINITIALIZEDSTRINGQUANTITY)
117 stream << " - GIdentity: " <<
118 gVol.gidentity << std::endl;
119 stream << " - Col, Vis, Style: " << gVol.color << ", " << visibility << ", " << style << std::endl;
120 stream << std::endl;
121
122 return stream;
123}
124
125
126GVolume::GVolume(const std::string& rootVolumeDefinition, const std::shared_ptr<GLogger>& logger) : GBase(logger) {
127 // The ROOT/world definition is tokenized by spaces:
128 // <solidType> <dim1> <dim2> ... <material>
129 vector<string> rootDefinitions = getStringVectorFromStringWithDelimiter(rootVolumeDefinition, " ");
130 string volumeParameters;
131
132 // Build the parameter string (skip the type and the final material token).
133 for (size_t i = 1; i < rootDefinitions.size() - 1; i++) { volumeParameters += ", " + rootDefinitions[i]; }
134
136 system = ROOTWORLDGVOLUMENAME;
137 variation = "default";
138 type = rootDefinitions[0];
139 parameters = volumeParameters;
140 material = rootDefinitions.back();
141 motherName = MOTHEROFUSALL;
142 pos = DEFAULTPOSITION;
143 rot = DEFAULTROTATION;
144 emfield = "";
145 visible = false;
146 style = 0; // wireframe
147 color = "ccffff";
148 digitization = "";
149 gidentity = "";
150 copyOf = "";
151 solidsOpr = "";
152 mirror = "";
153 exist = true;
154
155 description = "root volume";
156
157 // modifiers - accessed through options/jcard
158 shift = GSYSTEMNOMODIFIER;
159 tilt = GSYSTEMNOMODIFIER;
160
161 // set file with its path if it's a CAD/GDML import
162 importFilename = "none";
163}
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)