]>
Commit | Line | Data |
---|---|---|
240601e9 | 1 | // $Id$ |
2 | // Category: geometry | |
3 | // | |
4 | // See the class description in the header file. | |
5 | ||
6 | #include "TG4XMLConvertor.h" | |
2217607d | 7 | #include "TG4Polycone.h" |
8 | #include "TG4Polyhedra.h" | |
b009ffa0 | 9 | #include "TG4G3Units.h" |
240601e9 | 10 | |
2217607d | 11 | #include <G4PVReplica.hh> |
240601e9 | 12 | #include <G4Material.hh> |
13 | #include <G4VSolid.hh> | |
14 | #include <G4Box.hh> | |
15 | #include <G4Tubs.hh> | |
2217607d | 16 | #include <G4Cons.hh> |
240601e9 | 17 | #include <G4Trd.hh> |
4032dc03 | 18 | #include <G4Trap.hh> |
5d22ddb7 | 19 | #include <G4Para.hh> |
2217607d | 20 | #include <G4Polycone.hh> |
21 | #include <G4Polyhedra.hh> | |
240601e9 | 22 | |
23 | #include <g4std/iostream> | |
24 | #include <g4std/iomanip> | |
25 | ||
26 | const G4int TG4XMLConvertor::fgkMaxVolumeNameLength = 10; | |
27 | const G4int TG4XMLConvertor::fgkMaxMaterialNameLength = 20; | |
b7ee896b | 28 | const G4int TG4XMLConvertor::fgkDefaultNumWidth = 7; |
29 | const G4int TG4XMLConvertor::fgkDefaultNumPrecision = 4; | |
240601e9 | 30 | |
72095f7c | 31 | //_____________________________________________________________________________ |
240601e9 | 32 | TG4XMLConvertor::TG4XMLConvertor(G4std::ofstream& outFile) |
33 | : fOutFile(outFile), | |
4b062c78 | 34 | fkBasicIndention(" "), |
b7ee896b | 35 | fNW(fgkDefaultNumWidth), |
36 | fNP(fgkDefaultNumPrecision), | |
4b062c78 | 37 | fIndention(fkBasicIndention), |
4032dc03 | 38 | fRotationCounter(0) |
240601e9 | 39 | { |
b7ee896b | 40 | fOutFile.width(fgkDefaultNumWidth); |
41 | fOutFile.precision(fgkDefaultNumPrecision); | |
240601e9 | 42 | } |
43 | ||
72095f7c | 44 | //_____________________________________________________________________________ |
240601e9 | 45 | TG4XMLConvertor::~TG4XMLConvertor() { |
46 | // | |
47 | } | |
48 | ||
49 | // private methods | |
50 | ||
72095f7c | 51 | //_____________________________________________________________________________ |
240601e9 | 52 | void TG4XMLConvertor::CutName(G4String& name) const |
53 | { | |
54 | // Removes spaces after the name if present. | |
55 | // --- | |
56 | ||
57 | G4int i = name.length(); | |
58 | while (name(--i) == ' ') name = name(0,i); | |
59 | } | |
60 | ||
72095f7c | 61 | //_____________________________________________________________________________ |
240601e9 | 62 | void TG4XMLConvertor::CutName(G4String& name, G4int size) const |
63 | { | |
64 | // Cuts name to given size. | |
65 | // --- | |
66 | ||
67 | if (name.length() > size) name = name(0, size); | |
68 | } | |
69 | ||
72095f7c | 70 | //_____________________________________________________________________________ |
240601e9 | 71 | void TG4XMLConvertor::PutName(G4String& element, G4String name, |
72 | G4String templ) const | |
73 | { | |
74 | // Replaces given template in string element with a give name. | |
75 | // --- | |
76 | ||
77 | CutName(name); | |
78 | // make better | |
79 | if (templ == "#") | |
80 | CutName(name, fgkMaxVolumeNameLength); | |
81 | else if (templ == "!") | |
82 | CutName(name, fgkMaxMaterialNameLength); | |
83 | ||
84 | element.replace(element.find(templ), name.size(), name); | |
85 | element.replace(element.find(templ), 1, "\""); | |
86 | while (element.contains(templ)) element.replace(element.find(templ), 1 , " "); | |
87 | } | |
88 | ||
72095f7c | 89 | //_____________________________________________________________________________ |
4032dc03 | 90 | void TG4XMLConvertor::WriteBox(G4String lvName, const G4Box* box, |
91 | G4String materialName) | |
240601e9 | 92 | { |
93 | // Writes G4box solid. | |
94 | // --- | |
95 | ||
96 | // get parameters | |
b009ffa0 | 97 | G4double x = box->GetXHalfLength()/TG4G3Units::Length()*2.; |
98 | G4double y = box->GetYHalfLength()/TG4G3Units::Length()*2.; | |
99 | G4double z = box->GetZHalfLength()/TG4G3Units::Length()*2.; | |
240601e9 | 100 | |
101 | // compose element string template | |
2217607d | 102 | G4String quota = "\""; |
103 | G4String element1 = "<box name=\"" + lvName + quota; | |
104 | G4String element2 = "material=\"" + materialName + quota; | |
105 | G4String element3 = "X_Y_Z=\""; | |
106 | G4String element4 = "\" />"; | |
4b062c78 | 107 | G4String indention = fkBasicIndention + fkBasicIndention; |
240601e9 | 108 | |
109 | // write element | |
4b062c78 | 110 | fOutFile << fkBasicIndention << element1 << G4endl |
111 | << indention << element2 << G4endl | |
112 | << indention << element3 | |
b7ee896b | 113 | << G4std::setw(fNW) << G4std::setprecision(fNP) << x << " " |
114 | << G4std::setw(fNW) << G4std::setprecision(fNP) << y << " " | |
115 | << G4std::setw(fNW) << G4std::setprecision(fNP) << z | |
2217607d | 116 | << element4 << G4endl << G4endl; |
240601e9 | 117 | } |
118 | ||
72095f7c | 119 | //_____________________________________________________________________________ |
4032dc03 | 120 | void TG4XMLConvertor::WriteTubs(G4String lvName, const G4Tubs* tubs, |
121 | G4String materialName) | |
240601e9 | 122 | { |
123 | // Writes G4tubs solid. | |
124 | // --- | |
125 | ||
126 | // get parameters | |
b009ffa0 | 127 | G4double rmin = tubs->GetInnerRadius()/TG4G3Units::Length(); |
128 | G4double rmax = tubs->GetOuterRadius()/TG4G3Units::Length(); | |
129 | G4double hz = tubs->GetZHalfLength()/TG4G3Units::Length()*2.; | |
130 | G4double sphi = tubs->GetStartPhiAngle()/TG4G3Units::Angle(); | |
131 | G4double dphi = tubs->GetDeltaPhiAngle()/TG4G3Units::Angle(); | |
240601e9 | 132 | |
133 | // compose element string template | |
2217607d | 134 | G4String quota = "\""; |
135 | G4String element1 = "<tubs name=\"" + lvName + quota; | |
136 | G4String element2 = "material=\"" + materialName + quota; | |
137 | G4String element3 = "profile=\""; | |
138 | G4String element4 = "Rio_Z =\""; | |
139 | G4String element5 = "\" />"; | |
4b062c78 | 140 | G4String indention = fkBasicIndention + fkBasicIndention; |
240601e9 | 141 | |
142 | // write element | |
4b062c78 | 143 | fOutFile << fkBasicIndention << element1 << G4endl |
144 | << indention << element2 << G4endl | |
145 | << indention << element3 | |
b7ee896b | 146 | << G4std::setw(fNW) << G4std::setprecision(fNP) << sphi << " " |
147 | << G4std::setw(fNW) << G4std::setprecision(fNP) << sphi+dphi | |
2217607d | 148 | << quota << G4endl |
4b062c78 | 149 | << indention << element4 |
b7ee896b | 150 | << G4std::setw(fNW) << G4std::setprecision(fNP) << rmin << " " |
151 | << G4std::setw(fNW) << G4std::setprecision(fNP) << rmax << " " | |
152 | << G4std::setw(fNW) << G4std::setprecision(fNP) << hz | |
2217607d | 153 | << element5 << G4endl << G4endl; |
154 | } | |
155 | ||
72095f7c | 156 | //_____________________________________________________________________________ |
2217607d | 157 | void TG4XMLConvertor::WriteCons(G4String lvName, const G4Cons* cons, |
158 | G4String materialName) | |
159 | { | |
160 | // Writes G4cons solid. | |
161 | // --- | |
162 | ||
163 | // get parameters | |
b009ffa0 | 164 | G4double rmin1 = cons->GetInnerRadiusMinusZ()/TG4G3Units::Length(); |
165 | G4double rmax1 = cons->GetOuterRadiusMinusZ()/TG4G3Units::Length(); | |
166 | G4double rmin2 = cons->GetInnerRadiusPlusZ()/TG4G3Units::Length(); | |
167 | G4double rmax2 = cons->GetOuterRadiusPlusZ()/TG4G3Units::Length(); | |
168 | G4double hz = cons->GetZHalfLength()/TG4G3Units::Length()*2.; | |
169 | G4double sphi = cons->GetStartPhiAngle()/TG4G3Units::Angle(); | |
170 | G4double dphi = cons->GetDeltaPhiAngle()/TG4G3Units::Angle(); | |
2217607d | 171 | |
172 | // compose element string template | |
173 | G4String quota = "\""; | |
174 | G4String element1 = "<cons name=\"" + lvName + quota; | |
175 | G4String element2 = "material=\"" + materialName + quota; | |
176 | G4String element3 = "profile=\""; | |
177 | G4String element4 = "Rio1_Rio2_Z =\""; | |
178 | G4String element5 = "\" />"; | |
4b062c78 | 179 | G4String indention = fkBasicIndention + fkBasicIndention; |
2217607d | 180 | |
181 | // write element | |
4b062c78 | 182 | fOutFile << fkBasicIndention << element1 << G4endl |
183 | << indention << element2 << G4endl | |
184 | << indention << element3 | |
b7ee896b | 185 | << G4std::setw(fNW) << G4std::setprecision(fNP) << sphi << " " |
186 | << G4std::setw(fNW) << G4std::setprecision(fNP) << sphi+dphi | |
2217607d | 187 | << quota << G4endl |
4b062c78 | 188 | << indention << element4 |
b7ee896b | 189 | << G4std::setw(fNW) << G4std::setprecision(fNP) << rmin1 << " " |
190 | << G4std::setw(fNW) << G4std::setprecision(fNP) << rmin2 << " " | |
191 | << G4std::setw(fNW) << G4std::setprecision(fNP) << rmax1 << " " | |
192 | << G4std::setw(fNW) << G4std::setprecision(fNP) << rmax2 << " " | |
193 | << G4std::setw(fNW) << G4std::setprecision(fNP) << hz | |
2217607d | 194 | << element5 << G4endl << G4endl; |
240601e9 | 195 | } |
196 | ||
72095f7c | 197 | //_____________________________________________________________________________ |
4032dc03 | 198 | void TG4XMLConvertor::WriteTrd(G4String lvName, const G4Trd* trd, |
199 | G4String materialName) | |
240601e9 | 200 | { |
201 | // Writes G4Trd solid. | |
202 | // --- | |
203 | ||
204 | // get parameters | |
b009ffa0 | 205 | G4double x1 = trd->GetXHalfLength1()/TG4G3Units::Length()*2; |
206 | G4double x2 = trd->GetXHalfLength2()/TG4G3Units::Length()*2; | |
207 | G4double y1 = trd->GetYHalfLength1()/TG4G3Units::Length()*2; | |
208 | G4double y2 = trd->GetYHalfLength2()/TG4G3Units::Length()*2; | |
209 | G4double hz = trd->GetZHalfLength()/TG4G3Units::Length()*2; | |
240601e9 | 210 | |
211 | // compose element string template | |
2217607d | 212 | G4String quota = "\""; |
213 | G4String element1 = "<trd name=\"" + lvName + quota; | |
214 | G4String element2 = "material=\"" + materialName + quota; | |
215 | G4String element3 = "Xmp_Ymp_Z=\""; | |
216 | G4String element4 = "\" />"; | |
4b062c78 | 217 | G4String indention = fkBasicIndention + fkBasicIndention; |
240601e9 | 218 | |
219 | // write element | |
4b062c78 | 220 | fOutFile << fkBasicIndention << element1 << G4endl |
221 | << indention << element2 << G4endl | |
222 | << indention << element3 | |
b7ee896b | 223 | << G4std::setw(fNW) << G4std::setprecision(fNP) << x1 << " " |
224 | << G4std::setw(fNW) << G4std::setprecision(fNP) << x2 << " " | |
225 | << G4std::setw(fNW) << G4std::setprecision(fNP) << y1 << " " | |
226 | << G4std::setw(fNW) << G4std::setprecision(fNP) << y2 << " " | |
227 | << G4std::setw(fNW) << G4std::setprecision(fNP) << hz | |
2217607d | 228 | << element4 << G4endl << G4endl; |
240601e9 | 229 | } |
230 | ||
72095f7c | 231 | //_____________________________________________________________________________ |
4032dc03 | 232 | void TG4XMLConvertor::WriteTrap(G4String lvName, const G4Trap* trap, |
233 | G4String materialName) | |
234 | { | |
235 | // Writes G4Trap solid. | |
236 | // --- | |
237 | ||
238 | // get parameters | |
b009ffa0 | 239 | G4double dz = trap->GetZHalfLength()/TG4G3Units::Length()*2.; |
4032dc03 | 240 | G4ThreeVector symAxis = trap->GetSymAxis(); |
b009ffa0 | 241 | G4double y1 = trap->GetYHalfLength1()/TG4G3Units::Length()*2.; |
242 | G4double x1 = trap->GetXHalfLength1()/TG4G3Units::Length()*2.; | |
243 | G4double x2 = trap->GetXHalfLength2()/TG4G3Units::Length()*2.; | |
4032dc03 | 244 | G4double tanAlpha1 = trap->GetTanAlpha1(); |
b009ffa0 | 245 | G4double y2 = trap->GetYHalfLength2()/TG4G3Units::Length()*2.; |
246 | G4double x3 = trap->GetXHalfLength3()/TG4G3Units::Length()*2.; | |
247 | G4double x4 = trap->GetXHalfLength4()/TG4G3Units::Length()*2.; | |
4032dc03 | 248 | G4double tanAlpha2 = trap->GetTanAlpha2(); |
249 | ||
250 | // ordering of parameters in XML element | |
251 | // Xmumdpupd_Ymp_Z: 2x2 2x1 2x4 2x3 2y2 2y1 2dz | |
252 | // inclination: atan(symAxis.x/symAxis.z), atan(symAxis.y/symAxis.z) | |
253 | // declination: alpha1, alpha2 | |
254 | ||
255 | // get angles | |
256 | G4double inc1 = atan(symAxis.x()/symAxis.z()) / deg; | |
257 | G4double inc2 = atan(symAxis.y()/symAxis.z()) / deg; | |
258 | G4double alpha1 = atan(tanAlpha1) / deg; | |
259 | G4double alpha2 = atan(tanAlpha2) / deg; | |
260 | ||
261 | // compose element string template | |
2217607d | 262 | G4String quota = "\""; |
263 | G4String element1 = "<trap name=\"" + lvName + quota; | |
264 | G4String element2 = "material=\"" + materialName + quota; | |
265 | G4String element3 = "Xmumdpupd_Ymp_Z=\""; | |
266 | G4String element4 = "inclination=\""; | |
267 | G4String element5 = "declination=\""; | |
268 | G4String element6 = "\" />"; | |
4b062c78 | 269 | G4String indention = fkBasicIndention + fkBasicIndention; |
2217607d | 270 | |
4032dc03 | 271 | // write element |
4b062c78 | 272 | fOutFile << fkBasicIndention << element1 << G4endl |
273 | << indention << element2 << G4endl | |
274 | << indention << element3 | |
b7ee896b | 275 | << G4std::setw(fNW) << G4std::setprecision(fNP) << x2 << " " |
276 | << G4std::setw(fNW) << G4std::setprecision(fNP) << x1 << " " | |
277 | << G4std::setw(fNW) << G4std::setprecision(fNP) << x4 << " " | |
278 | << G4std::setw(fNW) << G4std::setprecision(fNP) << x3 << " " | |
279 | << G4std::setw(fNW) << G4std::setprecision(fNP) << y2 << " " | |
280 | << G4std::setw(fNW) << G4std::setprecision(fNP) << y1 << " " | |
281 | << G4std::setw(fNW) << G4std::setprecision(fNP) << dz | |
2217607d | 282 | << quota << G4endl |
283 | << indention << element4 | |
b7ee896b | 284 | << G4std::setw(fNW) << G4std::setprecision(fNP) << inc1 << " " |
285 | << G4std::setw(fNW) << G4std::setprecision(fNP) << inc2 | |
2217607d | 286 | << quota << G4endl |
287 | << indention << element5 | |
b7ee896b | 288 | << G4std::setw(fNW) << G4std::setprecision(fNP) << alpha1 << " " |
289 | << G4std::setw(fNW) << G4std::setprecision(fNP) << alpha2 | |
2217607d | 290 | << element6 << G4endl << G4endl; |
4032dc03 | 291 | } |
292 | ||
72095f7c | 293 | //_____________________________________________________________________________ |
5d22ddb7 | 294 | void TG4XMLConvertor::WritePara(G4String lvName, const G4Para* para, |
295 | G4String materialName) | |
296 | { | |
297 | // Writes G4Para solid. | |
298 | // --- | |
299 | ||
300 | // get parameters | |
301 | G4double dx = para->GetXHalfLength()/TG4G3Units::Length()*2.; | |
302 | G4double dy = para->GetYHalfLength()/TG4G3Units::Length()*2.; | |
303 | G4double dz = para->GetZHalfLength()/TG4G3Units::Length()*2.; | |
304 | G4double tanAlpha = para->GetTanAlpha(); | |
305 | G4ThreeVector symAxis = para->GetSymAxis(); | |
306 | ||
307 | G4double alpha = atan(tanAlpha) / deg; | |
308 | G4double theta = acos(symAxis.z()) / deg; | |
309 | G4double phi; | |
310 | if (theta == 0.) | |
311 | phi = 0; | |
312 | else | |
313 | phi = atan(symAxis.y()/symAxis.x()) / deg; | |
314 | ||
315 | // compose element string template | |
316 | G4String quota = "\""; | |
317 | G4String element1 = "<para name=\"" + lvName + quota; | |
318 | G4String element2 = "material=\"" + materialName + quota; | |
319 | G4String element3 = "X_Y_Z=\""; | |
320 | G4String element4 = "alpha=\""; | |
321 | G4String element5 = "theta=\""; | |
322 | G4String element6 = "phi= \""; | |
323 | G4String element7 = "\" />"; | |
324 | G4String indention = fkBasicIndention + fkBasicIndention; | |
325 | ||
326 | // write element | |
327 | fOutFile << fkBasicIndention << element1 << G4endl | |
328 | << indention << element2 << G4endl | |
329 | << indention << element3 | |
b7ee896b | 330 | << G4std::setw(fNW) << G4std::setprecision(fNP) << dx << " " |
331 | << G4std::setw(fNW) << G4std::setprecision(fNP) << dy << " " | |
332 | << G4std::setw(fNW) << G4std::setprecision(fNP) << dz | |
5d22ddb7 | 333 | << quota << G4endl |
334 | << indention << element4 | |
b7ee896b | 335 | << G4std::setw(fNW) << G4std::setprecision(fNP) << alpha |
5d22ddb7 | 336 | << quota << G4endl |
337 | << indention << element5 | |
b7ee896b | 338 | << G4std::setw(fNW) << G4std::setprecision(fNP) << theta |
5d22ddb7 | 339 | << quota << G4endl |
340 | << indention << element6 | |
b7ee896b | 341 | << G4std::setw(fNW) << G4std::setprecision(fNP) << phi |
5d22ddb7 | 342 | << element7 << G4endl << G4endl; |
343 | } | |
344 | ||
72095f7c | 345 | //_____________________________________________________________________________ |
2217607d | 346 | void TG4XMLConvertor::WritePolycone(G4String lvName, const G4Polycone* polycone, |
347 | G4String materialName) | |
348 | { | |
349 | // Writes G4Polycone solid. | |
350 | // --- | |
351 | ||
352 | // get profile parameters | |
b009ffa0 | 353 | G4double sphi = polycone->GetStartPhi()/TG4G3Units::Angle(); |
354 | G4double ephi = polycone->GetEndPhi()/TG4G3Units::Angle(); | |
2217607d | 355 | |
356 | // get polycone Z planes parameters | |
357 | TG4Polycone historicalPolycone = TG4Polycone(*polycone); | |
358 | ||
359 | G4int nofZPlanes = historicalPolycone.GetNofZPlanes(); | |
360 | G4double* rminArray = historicalPolycone.GetRmin(); | |
361 | G4double* rmaxArray = historicalPolycone.GetRmax(); | |
362 | G4double* zArray = historicalPolycone.GetZ(); | |
363 | ||
364 | // compose element string template | |
365 | G4String quota = "\""; | |
366 | G4String element1 = "<pcon name=\"" + lvName + quota; | |
367 | G4String element2 = "material=\"" + materialName + quota; | |
368 | G4String element3 = "profile=\""; | |
369 | G4String element4 = "\" >"; | |
370 | G4String element5 = "<polyplane Rio_Z=\""; | |
371 | G4String element6 = "\" />"; | |
372 | G4String element7 = "</pcon>"; | |
4b062c78 | 373 | G4String indention = fkBasicIndention + fkBasicIndention; |
2217607d | 374 | |
375 | // write pcon element | |
4b062c78 | 376 | fOutFile << fkBasicIndention << element1 << G4endl |
377 | << indention << element2 << G4endl | |
378 | << indention << element3 | |
b7ee896b | 379 | << G4std::setw(fNW) << G4std::setprecision(fNP) << sphi << " " |
380 | << G4std::setw(fNW) << G4std::setprecision(fNP) << ephi | |
2217607d | 381 | << element4 << G4endl; |
382 | ||
383 | // write polyplane elements | |
384 | for (G4int i=0; i<nofZPlanes; i++) { | |
385 | ||
386 | // set units | |
b009ffa0 | 387 | G4double rmin = rminArray[i]/TG4G3Units::Length(); |
388 | G4double rmax = rmaxArray[i]/TG4G3Units::Length(); | |
389 | G4double z = zArray[i]/TG4G3Units::Length(); | |
2217607d | 390 | |
391 | fOutFile << indention << element5 | |
b7ee896b | 392 | << G4std::setw(fNW) << G4std::setprecision(fNP) << rmin << " " |
393 | << G4std::setw(fNW) << G4std::setprecision(fNP) << rmax << " " | |
394 | << G4std::setw(fNW) << G4std::setprecision(fNP) << z | |
2217607d | 395 | << element6 |
396 | << G4endl; | |
397 | } | |
398 | ||
399 | // close pcon element | |
4b062c78 | 400 | fOutFile << fkBasicIndention |
2217607d | 401 | << element7 << G4endl << G4endl; |
402 | } | |
403 | ||
72095f7c | 404 | //_____________________________________________________________________________ |
2217607d | 405 | void TG4XMLConvertor::WritePolyhedra(G4String lvName, const G4Polyhedra* polyhedra, |
406 | G4String materialName) | |
407 | { | |
408 | // Writes G4Polycone solid. | |
409 | // --- | |
410 | ||
411 | // get parameters | |
412 | G4int nofSides = polyhedra->GetNumSide(); | |
b009ffa0 | 413 | G4double sphi = polyhedra->GetStartPhi()/TG4G3Units::Angle(); |
414 | G4double ephi = polyhedra->GetEndPhi()/TG4G3Units::Angle(); | |
2217607d | 415 | |
416 | // get polyhedra Z planes parameters | |
417 | TG4Polyhedra historicalPolyhedra = TG4Polyhedra(*polyhedra); | |
418 | ||
419 | G4int nofZPlanes = historicalPolyhedra.GetNofZPlanes(); | |
420 | G4double* rminArray = historicalPolyhedra.GetRmin(); | |
421 | G4double* rmaxArray = historicalPolyhedra.GetRmax(); | |
422 | G4double* zArray = historicalPolyhedra.GetZ(); | |
423 | ||
424 | // compose element string template | |
425 | G4String quota = "\""; | |
426 | G4String element1 = "<phedra name=\"" + lvName + quota; | |
427 | G4String element2 = "material=\"" + materialName + quota; | |
428 | G4String element3 = "profile=\""; | |
429 | G4String element4 = "sides =\""; | |
430 | G4String element5 = "Ris=\""; | |
431 | G4String element6 = "Ros=\""; | |
432 | G4String element7 = "Zs =\""; | |
433 | G4String element8 = "\" />"; | |
4b062c78 | 434 | G4String indention = fkBasicIndention + fkBasicIndention; |
2217607d | 435 | |
436 | // write element | |
4b062c78 | 437 | fOutFile << fkBasicIndention << element1 << G4endl |
438 | << indention << element2 << G4endl | |
439 | << indention << element3 | |
b7ee896b | 440 | << G4std::setw(fNW) << G4std::setprecision(fNP) << sphi << " " |
441 | << G4std::setw(fNW) << G4std::setprecision(fNP) << ephi | |
2217607d | 442 | << quota << G4endl |
443 | << indention << element4 | |
444 | << nofSides | |
445 | << quota << G4endl; | |
446 | ||
447 | fOutFile << indention << element5; | |
448 | G4int i; | |
449 | for (i=0; i<nofZPlanes; i++) { | |
450 | // set units | |
b009ffa0 | 451 | G4double rmin = rminArray[i]/TG4G3Units::Length(); |
2217607d | 452 | if (i>0) fOutFile << " "; |
b7ee896b | 453 | fOutFile << G4std::setw(fNW) << G4std::setprecision(fNP) << rmin; |
2217607d | 454 | }; |
455 | fOutFile << quota << G4endl; | |
456 | ||
457 | fOutFile << indention << element6; | |
458 | for (i=0; i<nofZPlanes; i++) { | |
459 | // set units | |
b009ffa0 | 460 | G4double rmax = rmaxArray[i]/TG4G3Units::Length(); |
2217607d | 461 | if (i>0) fOutFile << " "; |
b7ee896b | 462 | fOutFile << G4std::setw(fNW) << G4std::setprecision(fNP) << rmax; |
2217607d | 463 | }; |
464 | fOutFile << quota << G4endl; | |
465 | ||
466 | fOutFile << indention << element7; | |
467 | for (i=0; i<nofZPlanes; i++) { | |
468 | // set units | |
b009ffa0 | 469 | G4double z = zArray[i]/TG4G3Units::Length(); |
2217607d | 470 | if (i>0) fOutFile << " "; |
b7ee896b | 471 | fOutFile << G4std::setw(fNW) << G4std::setprecision(fNP) << z; |
2217607d | 472 | }; |
473 | fOutFile << element8 << G4endl << G4endl; | |
474 | } | |
475 | ||
476 | ||
240601e9 | 477 | // public methods |
478 | ||
72095f7c | 479 | //_____________________________________________________________________________ |
3716fae8 | 480 | void TG4XMLConvertor::OpenMaterials(const G4String& version, |
481 | const G4String& date, const G4String& author, | |
482 | const G4String dtdVersion) | |
483 | { | |
484 | // Writes section opening. | |
485 | // --- | |
486 | ||
487 | G4String element1 = "<materials version = \""; | |
488 | G4String element2 = " date = \""; | |
489 | G4String element3 = " author = \""; | |
490 | G4String element4 = " DTD_version=\""; | |
491 | G4String element5 = " >"; | |
492 | G4String quota = "\""; | |
493 | ||
494 | // write element | |
495 | fOutFile << element1 << version << quota << G4endl | |
496 | << element2 << date << quota << G4endl | |
497 | << element3 << author << quota << G4endl | |
498 | << element4 << dtdVersion << quota | |
499 | << element5 << G4endl; | |
500 | } | |
501 | ||
72095f7c | 502 | //_____________________________________________________________________________ |
240601e9 | 503 | void TG4XMLConvertor::OpenSection(const G4String& name, const G4String& version, |
504 | const G4String& date, const G4String& author, | |
505 | const G4String& topVolume) | |
506 | { | |
507 | // Writes section opening. | |
508 | // --- | |
509 | ||
510 | G4String element1 = "<section name = \""; | |
511 | G4String element2 = " version = \""; | |
512 | G4String element3 = " date = \""; | |
513 | G4String element4 = " author = \""; | |
514 | G4String element5 = " topVolume = \""; | |
515 | G4String element6 = " >"; | |
516 | G4String quota = "\""; | |
517 | ||
518 | // write element | |
519 | fOutFile << element1 << name << quota << G4endl | |
520 | << element2 << version << quota << G4endl | |
521 | << element3 << date << quota << G4endl | |
522 | << element4 << author << quota << G4endl | |
523 | << element5 << topVolume << quota | |
524 | << element6 << G4endl; | |
525 | } | |
526 | ||
527 | void TG4XMLConvertor::OpenComposition(const G4String& name) | |
528 | { | |
529 | // Writes composition opening. | |
530 | // --- | |
531 | ||
532 | G4String element = "<composition name=\""; | |
533 | element.append(name); | |
4032dc03 | 534 | element.append("\">"); |
240601e9 | 535 | |
536 | // write element | |
537 | fOutFile << fIndention | |
538 | << element | |
539 | << G4endl; | |
540 | ||
541 | // increase indention | |
3716fae8 | 542 | IncreaseIndention(); |
543 | } | |
544 | ||
72095f7c | 545 | //_____________________________________________________________________________ |
3716fae8 | 546 | void TG4XMLConvertor::CloseMaterials() |
547 | { | |
548 | // Writes materials closing. | |
549 | // --- | |
550 | ||
551 | // define element | |
552 | G4String element = "</materials>"; | |
553 | ||
554 | // write element | |
555 | fOutFile << element | |
556 | << G4endl; | |
240601e9 | 557 | } |
558 | ||
72095f7c | 559 | //_____________________________________________________________________________ |
240601e9 | 560 | void TG4XMLConvertor::CloseSection() |
561 | { | |
562 | // Writes section closing. | |
563 | // --- | |
564 | ||
565 | // define element | |
566 | G4String element = "</section>"; | |
567 | ||
568 | // write element | |
569 | fOutFile << element | |
570 | << G4endl; | |
571 | } | |
572 | ||
72095f7c | 573 | //_____________________________________________________________________________ |
240601e9 | 574 | void TG4XMLConvertor::CloseComposition() |
575 | { | |
576 | // Writes composition closing. | |
577 | // --- | |
578 | ||
579 | // decrease indention | |
3716fae8 | 580 | DecreaseIndention(); |
240601e9 | 581 | |
582 | // define element | |
583 | G4String element = "</composition>"; | |
584 | ||
585 | // write element | |
586 | fOutFile << fIndention | |
587 | << element | |
588 | << G4endl; | |
589 | } | |
590 | ||
72095f7c | 591 | //_____________________________________________________________________________ |
240601e9 | 592 | void TG4XMLConvertor::WriteMaterial(const G4Material* material) |
593 | { | |
594 | // Writes G4Material. | |
595 | // Not yet implemented, only XML comment element is written. | |
596 | // --- | |
597 | ||
598 | G4String name = material->GetName(); | |
599 | CutName(name); | |
600 | ||
240601e9 | 601 | // only comment line |
602 | G4String element1 = "<!-- material = \""; | |
603 | G4String element2 = "\" -->"; | |
604 | ||
605 | // write element | |
4b062c78 | 606 | fOutFile << fkBasicIndention |
3716fae8 | 607 | << element1 << name |
240601e9 | 608 | << element2 |
609 | << G4endl; | |
610 | } | |
611 | ||
72095f7c | 612 | //_____________________________________________________________________________ |
4032dc03 | 613 | void TG4XMLConvertor::WriteSolid(G4String lvName, const G4VSolid* solid, |
614 | G4String materialName) | |
240601e9 | 615 | { |
616 | // Finds G4Solid concrete type and calls writing function. | |
617 | // For not yet implemented solids, only XML comment element is written. | |
618 | // --- | |
619 | ||
4032dc03 | 620 | // to be removed when materials are supported |
621 | materialName = "Hydrogen"; | |
622 | ||
240601e9 | 623 | const G4Box* box = dynamic_cast<const G4Box*>(solid); |
624 | if (box) { | |
4032dc03 | 625 | WriteBox(lvName, box, materialName); |
240601e9 | 626 | return; |
627 | } | |
628 | ||
629 | const G4Tubs* tubs = dynamic_cast<const G4Tubs*>(solid); | |
630 | if (tubs) { | |
4032dc03 | 631 | WriteTubs(lvName, tubs, materialName); |
240601e9 | 632 | return; |
633 | } | |
634 | ||
2217607d | 635 | const G4Cons* cons = dynamic_cast<const G4Cons*>(solid); |
636 | if (cons) { | |
637 | WriteCons(lvName, cons, materialName); | |
638 | return; | |
639 | } | |
640 | ||
240601e9 | 641 | const G4Trd* trd = dynamic_cast<const G4Trd*>(solid); |
642 | if (trd) { | |
4032dc03 | 643 | WriteTrd(lvName, trd, materialName); |
644 | return; | |
645 | } | |
646 | ||
647 | const G4Trap* trap = dynamic_cast<const G4Trap*>(solid); | |
648 | if (trap) { | |
649 | WriteTrap(lvName, trap, materialName); | |
240601e9 | 650 | return; |
651 | } | |
652 | ||
5d22ddb7 | 653 | const G4Para* para = dynamic_cast<const G4Para*>(solid); |
654 | if (para) { | |
655 | WritePara(lvName, para, materialName); | |
656 | return; | |
657 | } | |
658 | ||
2217607d | 659 | const G4Polycone* polycone = dynamic_cast<const G4Polycone*>(solid); |
660 | if (polycone) { | |
661 | WritePolycone(lvName, polycone, materialName); | |
662 | return; | |
663 | } | |
664 | ||
665 | const G4Polyhedra* polyhedra = dynamic_cast<const G4Polyhedra*>(solid); | |
666 | if (polyhedra) { | |
667 | WritePolyhedra(lvName, polyhedra, materialName); | |
668 | return; | |
669 | } | |
670 | ||
240601e9 | 671 | // write comment line in case of unsupported |
672 | // shape | |
673 | ||
674 | // only comment line | |
675 | G4String element1 = "<!-- unsupported shape name= \""; | |
676 | G4String element2 = "\" -->"; | |
677 | ||
678 | // write element | |
4b062c78 | 679 | fOutFile << fkBasicIndention |
4032dc03 | 680 | << element1 << lvName |
240601e9 | 681 | << element2 |
682 | << G4endl; | |
683 | } | |
684 | ||
72095f7c | 685 | //_____________________________________________________________________________ |
240601e9 | 686 | void TG4XMLConvertor::WriteRotation(const G4RotationMatrix* rotation) |
687 | { | |
688 | // Writes G4RotationMatrix. | |
689 | // Not yet implemented, only XML comment element is written. | |
690 | // --- | |
691 | ||
3716fae8 | 692 | // return if this rotation was already written |
693 | G4int nofRotations = fRotations.size(); | |
694 | if (nofRotations>0) | |
695 | for (G4int i=0; i<nofRotations; i++) | |
696 | if (fRotations[i] == rotation) return; | |
697 | ||
698 | fRotations.push_back(rotation); | |
699 | ||
4032dc03 | 700 | |
3716fae8 | 701 | // get parameters |
702 | G4double xx = rotation->xx(); | |
703 | G4double xy = rotation->xy(); | |
704 | G4double xz = rotation->xz(); | |
705 | G4double yx = rotation->yx(); | |
706 | G4double yy = rotation->yy(); | |
707 | G4double yz = rotation->yz(); | |
708 | G4double zx = rotation->zx(); | |
709 | G4double zy = rotation->zy(); | |
710 | G4double zz = rotation->zz(); | |
711 | G4String id = "RM"; | |
4032dc03 | 712 | TG4Globals::AppendNumberToString(id, ++fRotationCounter); |
3716fae8 | 713 | |
714 | // compose element string template | |
715 | G4String quota = "\"\n"; | |
716 | G4String element1 = "<rot_matrix id=\"####### XX_XY_XZ=\""; | |
717 | G4String element2 = " YX_YY_YZ=\""; | |
718 | G4String element3 = " ZX_ZY_ZZ=\""; | |
719 | G4String element4 = "\" />"; | |
240601e9 | 720 | |
3716fae8 | 721 | // put identifier |
722 | PutName(element1, id, "#"); | |
723 | ||
240601e9 | 724 | // write element |
4b062c78 | 725 | fOutFile << fkBasicIndention |
3716fae8 | 726 | << element1 |
727 | << G4std::setw(8) << G4std::setprecision(5) << xx << " " | |
728 | << G4std::setw(8) << G4std::setprecision(5) << xy << " " | |
729 | << G4std::setw(8) << G4std::setprecision(5) << xz << quota | |
4b062c78 | 730 | << fkBasicIndention |
3716fae8 | 731 | << element2 |
732 | << G4std::setw(8) << G4std::setprecision(5) << yx << " " | |
733 | << G4std::setw(8) << G4std::setprecision(5) << yy << " " | |
734 | << G4std::setw(8) << G4std::setprecision(5) << yz << quota | |
4b062c78 | 735 | << fkBasicIndention |
3716fae8 | 736 | << element3 |
737 | << G4std::setw(8) << G4std::setprecision(5) << zx << " " | |
738 | << G4std::setw(8) << G4std::setprecision(5) << zy << " " | |
739 | << G4std::setw(8) << G4std::setprecision(5) << zz | |
740 | << element4 | |
240601e9 | 741 | << G4endl; |
742 | } | |
743 | ||
72095f7c | 744 | //_____________________________________________________________________________ |
4032dc03 | 745 | void TG4XMLConvertor::WritePosition(G4String lvName, G4ThreeVector position) |
240601e9 | 746 | { |
747 | // Writes position without rotation with a given solid name. | |
748 | // --- | |
749 | ||
750 | // get parameters | |
b009ffa0 | 751 | G4double x = position.x()/TG4G3Units::Length(); |
752 | G4double y = position.y()/TG4G3Units::Length(); | |
753 | G4double z = position.z()/TG4G3Units::Length(); | |
240601e9 | 754 | |
755 | // compose element string template | |
3716fae8 | 756 | G4String element1 = "<posXYZ volume=\"########### X_Y_Z=\""; |
240601e9 | 757 | G4String element2 = "\" />"; |
758 | ||
759 | // put solid name | |
4032dc03 | 760 | PutName(element1, lvName, "#"); |
240601e9 | 761 | |
762 | // write element | |
763 | fOutFile << fIndention | |
764 | << element1 | |
b7ee896b | 765 | << G4std::setw(fNW+1) << G4std::setprecision(fNP) << x << " " |
766 | << G4std::setw(fNW+1) << G4std::setprecision(fNP) << y << " " | |
767 | << G4std::setw(fNW+1) << G4std::setprecision(fNP) << z | |
240601e9 | 768 | << element2 |
769 | << G4endl; | |
770 | } | |
771 | ||
72095f7c | 772 | //_____________________________________________________________________________ |
240601e9 | 773 | void TG4XMLConvertor::WritePositionWithRotation( |
4032dc03 | 774 | G4String lvName, G4ThreeVector position, |
240601e9 | 775 | const G4RotationMatrix* rotation) |
776 | { | |
777 | // Writes position with rotation with a given solid name. | |
778 | // Not yet implemented, only XML comment element is written. | |
779 | // --- | |
780 | ||
3716fae8 | 781 | // get parameters |
b009ffa0 | 782 | G4double x = position.x()/TG4G3Units::Length(); |
783 | G4double y = position.y()/TG4G3Units::Length(); | |
784 | G4double z = position.z()/TG4G3Units::Length(); | |
4032dc03 | 785 | G4double xx = rotation->xx(); |
786 | G4double xy = rotation->xy(); | |
787 | G4double xz = rotation->xz(); | |
788 | G4double yx = rotation->yx(); | |
789 | G4double yy = rotation->yy(); | |
790 | G4double yz = rotation->yz(); | |
791 | G4double zx = rotation->zx(); | |
792 | G4double zy = rotation->zy(); | |
793 | G4double zz = rotation->zz(); | |
3716fae8 | 794 | |
4032dc03 | 795 | /* |
3716fae8 | 796 | // find rotation |
797 | G4int i=0; | |
798 | while (i<fRotations.size() && fRotations[i] != rotation) i++; | |
799 | if (i==fRotations.size()) { | |
800 | G4String text = "TG4XMLConvertor::WritePositionWithRotation: "; | |
801 | text = text + " Unknown rotation - fatal error."; | |
802 | TG4Globals::Exception(text); | |
803 | } | |
804 | G4String id = "RM"; | |
805 | TG4Globals::AppendNumberToString(id, i); | |
4032dc03 | 806 | */ |
3716fae8 | 807 | |
808 | // compose element string template | |
4032dc03 | 809 | G4String quota = "\"\n"; |
810 | G4String element1 = "<transform volume=\"########### pos=\""; | |
811 | G4String element2 = " rot=\""; | |
812 | G4String element3 = " "; | |
813 | G4String element4 = "\" />"; | |
3716fae8 | 814 | |
815 | // put solid name | |
4032dc03 | 816 | PutName(element1, lvName, "#"); |
240601e9 | 817 | |
818 | // write element | |
819 | fOutFile << fIndention | |
3716fae8 | 820 | << element1 |
b7ee896b | 821 | << G4std::setw(fNW+1) << G4std::setprecision(fNP) << x << " " |
822 | << G4std::setw(fNW+1) << G4std::setprecision(fNP) << y << " " | |
823 | << G4std::setw(fNW+1) << G4std::setprecision(fNP) << z << quota | |
4032dc03 | 824 | << fIndention |
825 | << element2 | |
826 | << G4std::setw(8) << G4std::setprecision(5) << xx << " " | |
827 | << G4std::setw(8) << G4std::setprecision(5) << xy << " " | |
828 | << G4std::setw(8) << G4std::setprecision(5) << xz << G4endl | |
829 | << fIndention | |
830 | << element3 | |
831 | << G4std::setw(8) << G4std::setprecision(5) << yx << " " | |
832 | << G4std::setw(8) << G4std::setprecision(5) << yy << " " | |
833 | << G4std::setw(8) << G4std::setprecision(5) << yz << G4endl | |
834 | << fIndention | |
835 | << element3 | |
836 | << G4std::setw(8) << G4std::setprecision(5) << zx << " " | |
837 | << G4std::setw(8) << G4std::setprecision(5) << zy << " " | |
838 | << G4std::setw(8) << G4std::setprecision(5) << zz | |
839 | << element4 | |
3716fae8 | 840 | << G4endl; |
240601e9 | 841 | } |
842 | ||
72095f7c | 843 | //_____________________________________________________________________________ |
2217607d | 844 | void TG4XMLConvertor::WriteReplica(G4String lvName, G4PVReplica* pvr) |
845 | { | |
846 | // Writes position without rotation with a given solid name. | |
847 | // --- | |
848 | ||
849 | // get parameters | |
850 | EAxis axis; | |
851 | G4int nReplicas; | |
852 | G4double width; | |
853 | G4double offset; | |
854 | G4bool consuming; | |
855 | pvr->GetReplicationData(axis, nReplicas, width, offset, consuming); | |
856 | ||
857 | G4String tag; | |
858 | switch (axis) { | |
859 | case kXAxis: tag = "X"; break; | |
860 | case kYAxis: tag = "Y"; break; | |
861 | case kZAxis: tag = "Z"; break; | |
862 | case kRho: tag = "R"; break; | |
863 | case kPhi: tag = "Phi"; break; | |
864 | } | |
865 | ||
866 | // set units | |
867 | G4double value0 = offset; | |
868 | G4double dValue = width; | |
869 | if (axis != kPhi) { | |
b009ffa0 | 870 | value0 = value0/TG4G3Units::Length(); |
871 | dValue = dValue/TG4G3Units::Length(); | |
2217607d | 872 | } |
873 | else { | |
b009ffa0 | 874 | value0 = value0/TG4G3Units::Angle(); |
875 | dValue = dValue/TG4G3Units::Angle(); | |
2217607d | 876 | } |
877 | ||
878 | // set tag and attributes names | |
879 | G4String a0 = "mpos"; a0 = a0 + tag; | |
880 | G4String a1 = tag; a1 = a1 + "0"; | |
881 | G4String a2 = "d"; a2 = a2 + tag; | |
882 | ||
883 | // compose element string template | |
884 | G4String element1 = "<" + a0 + " volume=\"########### ncopy=\""; | |
885 | G4String element2 = "\" " + a1 + "=\""; | |
886 | G4String element3 = "\" " + a2 + "=\""; | |
887 | G4String element4 = "\" />"; | |
888 | ||
889 | // put solid name | |
890 | PutName(element1, lvName, "#"); | |
891 | ||
892 | // write element | |
893 | fOutFile << fIndention | |
894 | << element1 | |
b7ee896b | 895 | << G4std::setw(fNW+1) << G4std::setprecision(fNP) << nReplicas |
2217607d | 896 | << element2 |
b7ee896b | 897 | << G4std::setw(fNW+1) << G4std::setprecision(fNP) << value0 |
2217607d | 898 | << element3 |
b7ee896b | 899 | << G4std::setw(fNW+1) << G4std::setprecision(fNP) << dValue |
2217607d | 900 | << element4 |
901 | << G4endl; | |
902 | } | |
903 | ||
72095f7c | 904 | //_____________________________________________________________________________ |
240601e9 | 905 | void TG4XMLConvertor::WriteEmptyLine() |
906 | { | |
907 | // Writes empty line. | |
908 | // --- | |
909 | ||
910 | fOutFile << G4endl; | |
911 | } | |
912 | ||
72095f7c | 913 | //_____________________________________________________________________________ |
3716fae8 | 914 | void TG4XMLConvertor::IncreaseIndention() |
915 | { | |
916 | // increase indention | |
4b062c78 | 917 | fIndention.append(fkBasicIndention); |
3716fae8 | 918 | } |
240601e9 | 919 | |
72095f7c | 920 | //_____________________________________________________________________________ |
3716fae8 | 921 | void TG4XMLConvertor::DecreaseIndention() |
922 | { | |
923 | // decrease indention | |
4b062c78 | 924 | fIndention.replace(fIndention.find(fkBasicIndention), 3 , ""); |
3716fae8 | 925 | } |