Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
G4GDMLReadStructure.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26// $Id$
27//
28// class G4GDMLReadStructure Implementation
29//
30// Original author: Zoltan Torzsok, November 2007
31//
32// --------------------------------------------------------------------
33
35
36#include "G4LogicalVolume.hh"
37#include "G4VPhysicalVolume.hh"
38#include "G4PVPlacement.hh"
41#include "G4AssemblyVolume.hh"
46#include "G4VisAttributes.hh"
47
49 : G4GDMLReadParamvol(), pMotherLogical(0)
50{
51}
52
54{
55}
56
58AuxiliaryRead(const xercesc::DOMElement* const auxiliaryElement)
59{
60 G4GDMLAuxPairType auxpair = {"",""};
61
62 const xercesc::DOMNamedNodeMap* const attributes
63 = auxiliaryElement->getAttributes();
64 XMLSize_t attributeCount = attributes->getLength();
65
66 for (XMLSize_t attribute_index=0;
67 attribute_index<attributeCount; attribute_index++)
68 {
69 xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
70
71 if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
72 { continue; }
73
74 const xercesc::DOMAttr* const attribute
75 = dynamic_cast<xercesc::DOMAttr*>(attribute_node);
76 if (!attribute)
77 {
78 G4Exception("G4GDMLReadStructure::AuxiliaryRead()",
79 "InvalidRead", FatalException, "No attribute found!");
80 return auxpair;
81 }
82 const G4String attName = Transcode(attribute->getName());
83 const G4String attValue = Transcode(attribute->getValue());
84
85 if (attName=="auxtype") { auxpair.type = attValue; } else
86 // if (attName=="auxvalue") { auxpair.value = eval.Evaluate(attValue); }
87 if (attName=="auxvalue") { auxpair.value = attValue; }
88 }
89
90 return auxpair;
91}
92
94BorderSurfaceRead(const xercesc::DOMElement* const bordersurfaceElement)
95{
96 G4String name;
97 G4VPhysicalVolume* pv1 = 0;
98 G4VPhysicalVolume* pv2 = 0;
99 G4SurfaceProperty* prop = 0;
100 G4int index = 0;
101
102 const xercesc::DOMNamedNodeMap* const attributes
103 = bordersurfaceElement->getAttributes();
104 XMLSize_t attributeCount = attributes->getLength();
105
106 for (XMLSize_t attribute_index=0;
107 attribute_index<attributeCount; attribute_index++)
108 {
109 xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
110
111 if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
112 { continue; }
113
114 const xercesc::DOMAttr* const attribute
115 = dynamic_cast<xercesc::DOMAttr*>(attribute_node);
116 if (!attribute)
117 {
118 G4Exception("G4GDMLReadStructure::BorderSurfaceRead()",
119 "InvalidRead", FatalException, "No attribute found!");
120 return;
121 }
122 const G4String attName = Transcode(attribute->getName());
123 const G4String attValue = Transcode(attribute->getValue());
124
125 if (attName=="name")
126 { name = GenerateName(attValue); } else
127 if (attName=="surfaceproperty")
128 { prop = GetSurfaceProperty(GenerateName(attValue)); }
129 }
130
131 for (xercesc::DOMNode* iter = bordersurfaceElement->getFirstChild();
132 iter != 0; iter = iter->getNextSibling())
133 {
134 if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) { continue; }
135
136 const xercesc::DOMElement* const child
137 = dynamic_cast<xercesc::DOMElement*>(iter);
138 if (!child)
139 {
140 G4Exception("G4GDMLReadStructure::BorderSurfaceRead()",
141 "InvalidRead", FatalException, "No child found!");
142 return;
143 }
144 const G4String tag = Transcode(child->getTagName());
145
146 if (tag != "physvolref") { continue; }
147
148 if (index==0)
149 { pv1 = GetPhysvol(GenerateName(RefRead(child))); index++; } else
150 if (index==1)
151 { pv2 = GetPhysvol(GenerateName(RefRead(child))); index++; } else
152 break;
153 }
154
155 new G4LogicalBorderSurface(Strip(name),pv1,pv2,prop);
156}
157
159DivisionvolRead(const xercesc::DOMElement* const divisionvolElement)
160{
161 G4String name;
162 G4double unit = 1.0;
163 G4double width = 0.0;
164 G4double offset = 0.0;
165 G4int number = 0;
166 EAxis axis = kUndefined;
167 G4LogicalVolume* logvol = 0;
168
169 const xercesc::DOMNamedNodeMap* const attributes
170 = divisionvolElement->getAttributes();
171 XMLSize_t attributeCount = attributes->getLength();
172
173 for (XMLSize_t attribute_index=0;
174 attribute_index<attributeCount; attribute_index++)
175 {
176 xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
177
178 if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
179 { continue; }
180
181 const xercesc::DOMAttr* const attribute
182 = dynamic_cast<xercesc::DOMAttr*>(attribute_node);
183 if (!attribute)
184 {
185 G4Exception("G4GDMLReadStructure::DivisionvolRead()",
186 "InvalidRead", FatalException, "No attribute found!");
187 return;
188 }
189 const G4String attName = Transcode(attribute->getName());
190 const G4String attValue = Transcode(attribute->getValue());
191
192 if (attName=="name") { name = attValue; } else
193 if (attName=="unit") { unit = eval.Evaluate(attValue); } else
194 if (attName=="width") { width = eval.Evaluate(attValue); } else
195 if (attName=="offset") { offset = eval.Evaluate(attValue); } else
196 if (attName=="number") { number = eval.EvaluateInteger(attValue); } else
197 if (attName=="axis")
198 {
199 if (attValue=="kXAxis") { axis = kXAxis; } else
200 if (attValue=="kYAxis") { axis = kYAxis; } else
201 if (attValue=="kZAxis") { axis = kZAxis; } else
202 if (attValue=="kRho") { axis = kRho; } else
203 if (attValue=="kPhi") { axis = kPhi; }
204 }
205 }
206
207 width *= unit;
208 offset *= unit;
209
210 for (xercesc::DOMNode* iter = divisionvolElement->getFirstChild();
211 iter != 0;iter = iter->getNextSibling())
212 {
213 if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) { continue; }
214
215 const xercesc::DOMElement* const child
216 = dynamic_cast<xercesc::DOMElement*>(iter);
217 if (!child)
218 {
219 G4Exception("G4GDMLReadStructure::DivisionvolRead()",
220 "InvalidRead", FatalException, "No child found!");
221 return;
222 }
223 const G4String tag = Transcode(child->getTagName());
224
225 if (tag=="volumeref") { logvol = GetVolume(GenerateName(RefRead(child))); }
226 }
227
228 if (!logvol) { return; }
229
232
233 G4String pv_name = logvol->GetName() + "_div";
234 if ((number != 0) && (width == 0.0))
235 {
237 ->Divide(pv_name,logvol,pMotherLogical,axis,number,offset);
238 }
239 else if ((number == 0) && (width != 0.0))
240 {
242 ->Divide(pv_name,logvol,pMotherLogical,axis,width,offset);
243 }
244 else
245 {
247 ->Divide(pv_name,logvol,pMotherLogical,axis,number,width,offset);
248 }
249
250 if (pair.first != 0) { GeneratePhysvolName(name,pair.first); }
251 if (pair.second != 0) { GeneratePhysvolName(name,pair.second); }
252}
253
255FileRead(const xercesc::DOMElement* const fileElement)
256{
257 G4String name;
258 G4String volname;
259
260 const xercesc::DOMNamedNodeMap* const attributes
261 = fileElement->getAttributes();
262 XMLSize_t attributeCount = attributes->getLength();
263
264 for (XMLSize_t attribute_index=0;
265 attribute_index<attributeCount; attribute_index++)
266 {
267 xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
268
269 if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
270 { continue; }
271
272 const xercesc::DOMAttr* const attribute
273 = dynamic_cast<xercesc::DOMAttr*>(attribute_node);
274 if (!attribute)
275 {
276 G4Exception("G4GDMLReadStructure::FileRead()",
277 "InvalidRead", FatalException, "No attribute found!");
278 return 0;
279 }
280 const G4String attName = Transcode(attribute->getName());
281 const G4String attValue = Transcode(attribute->getValue());
282
283 if (attName=="name") { name = attValue; } else
284 if (attName=="volname") { volname = attValue; }
285 }
286
287 const G4bool isModule = true;
288 G4GDMLReadStructure structure;
289 structure.Read(name,validate,isModule);
290
291 // Register existing auxiliar information defined in child module
292 //
293 const G4GDMLAuxMapType* aux = structure.GetAuxMap();
294 if (!aux->empty())
295 {
296 G4GDMLAuxMapType::const_iterator pos;
297 for (pos = aux->begin(); pos != aux->end(); ++pos)
298 {
299 auxMap.insert(std::make_pair(pos->first,pos->second));
300 }
301 }
302
303 // Return volume structure from child module
304 //
305 if (volname.empty())
306 {
307 return structure.GetVolume(structure.GetSetup("Default"));
308 }
309 else
310 {
311 return structure.GetVolume(structure.GenerateName(volname));
312 }
313}
314
316PhysvolRead(const xercesc::DOMElement* const physvolElement,
317 G4AssemblyVolume* pAssembly)
318{
319 G4String name;
320 G4LogicalVolume* logvol = 0;
321 G4AssemblyVolume* assembly = 0;
322 G4ThreeVector position(0.0,0.0,0.0);
323 G4ThreeVector rotation(0.0,0.0,0.0);
324 G4ThreeVector scale(1.0,1.0,1.0);
325
326 const xercesc::DOMNamedNodeMap* const attributes
327 = physvolElement->getAttributes();
328 XMLSize_t attributeCount = attributes->getLength();
329
330 for (XMLSize_t attribute_index=0;
331 attribute_index<attributeCount; attribute_index++)
332 {
333 xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
334
335 if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
336 { continue; }
337
338 const xercesc::DOMAttr* const attribute
339 = dynamic_cast<xercesc::DOMAttr*>(attribute_node);
340 if (!attribute)
341 {
342 G4Exception("G4GDMLReadStructure::PhysvolRead()",
343 "InvalidRead", FatalException, "No attribute found!");
344 return;
345 }
346 const G4String attName = Transcode(attribute->getName());
347 const G4String attValue = Transcode(attribute->getValue());
348
349 if (attName=="name") { name = attValue; }
350 }
351
352 for (xercesc::DOMNode* iter = physvolElement->getFirstChild();
353 iter != 0; iter = iter->getNextSibling())
354 {
355 if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) { continue; }
356
357 const xercesc::DOMElement* const child
358 = dynamic_cast<xercesc::DOMElement*>(iter);
359 if (!child)
360 {
361 G4Exception("G4GDMLReadStructure::PhysvolRead()",
362 "InvalidRead", FatalException, "No child found!");
363 return;
364 }
365 const G4String tag = Transcode(child->getTagName());
366
367 if (tag=="volumeref")
368 {
369 const G4String& child_name = GenerateName(RefRead(child));
370 assembly = GetAssembly(child_name);
371 if (!assembly) { logvol = GetVolume(child_name); }
372 }
373 else if (tag=="file")
374 { logvol = FileRead(child); }
375 else if (tag=="position")
376 { VectorRead(child,position); }
377 else if (tag=="rotation")
378 { VectorRead(child,rotation); }
379 else if (tag=="scale")
380 { VectorRead(child,scale); }
381 else if (tag=="positionref")
383 else if (tag=="rotationref")
384 { rotation = GetRotation(GenerateName(RefRead(child))); }
385 else if (tag=="scaleref")
386 { scale = GetScale(GenerateName(RefRead(child))); }
387 else
388 {
389 G4String error_msg = "Unknown tag in physvol: " + tag;
390 G4Exception("G4GDMLReadStructure::PhysvolRead()", "ReadError",
391 FatalException, error_msg);
392 return;
393 }
394 }
395
396 G4Transform3D transform(GetRotationMatrix(rotation).inverse(),position);
397 transform = transform*G4Scale3D(scale.x(),scale.y(),scale.z());
398
399 if (pAssembly) // Fill assembly structure
400 {
401 if (!logvol) { return; }
402 pAssembly->AddPlacedVolume(logvol, transform);
403 }
404 else // Generate physical volume tree or do assembly imprint
405 {
406 if (assembly)
407 {
408 assembly->MakeImprint(pMotherLogical, transform, 0, check);
409 }
410 else
411 {
412 if (!logvol) { return; }
413 G4String pv_name = logvol->GetName() + "_PV";
415 ->Place(transform,pv_name,logvol,pMotherLogical,false,0,check);
416
417 if (pair.first != 0) { GeneratePhysvolName(name,pair.first); }
418 if (pair.second != 0) { GeneratePhysvolName(name,pair.second); }
419 }
420 }
421}
422
424ReplicavolRead(const xercesc::DOMElement* const replicavolElement, G4int number)
425{
426 G4LogicalVolume* logvol = 0;
427 for (xercesc::DOMNode* iter = replicavolElement->getFirstChild();
428 iter != 0; iter = iter->getNextSibling())
429 {
430 if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) { continue; }
431
432 const xercesc::DOMElement* const child
433 = dynamic_cast<xercesc::DOMElement*>(iter);
434 if (!child)
435 {
436 G4Exception("G4GDMLReadStructure::ReplicavolRead()",
437 "InvalidRead", FatalException, "No child found!");
438 return;
439 }
440 const G4String tag = Transcode(child->getTagName());
441
442 if (tag=="volumeref")
443 {
444 logvol = GetVolume(GenerateName(RefRead(child)));
445 }
446 else if (tag=="replicate_along_axis")
447 {
448 if (logvol) { ReplicaRead(child,logvol,number); }
449 }
450 else
451 {
452 G4String error_msg = "Unknown tag in ReplicavolRead: " + tag;
453 G4Exception("G4GDMLReadStructure::ReplicavolRead()",
454 "ReadError", FatalException, error_msg);
455 }
456 }
457}
458
460ReplicaRead(const xercesc::DOMElement* const replicaElement,
461 G4LogicalVolume* logvol, G4int number)
462{
463 G4double width = 0.0;
464 G4double offset = 0.0;
465 G4ThreeVector position(0.0,0.0,0.0);
466 G4ThreeVector rotation(0.0,0.0,0.0);
467 EAxis axis = kUndefined;
468 G4String name;
469
470 for (xercesc::DOMNode* iter = replicaElement->getFirstChild();
471 iter != 0; iter = iter->getNextSibling())
472 {
473 if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) { continue; }
474
475 const xercesc::DOMElement* const child
476 = dynamic_cast<xercesc::DOMElement*>(iter);
477 if (!child)
478 {
479 G4Exception("G4GDMLReadStructure::ReplicaRead()",
480 "InvalidRead", FatalException, "No child found!");
481 return;
482 }
483 const G4String tag = Transcode(child->getTagName());
484
485 if (tag=="position")
486 { VectorRead(child,position); } else
487 if (tag=="rotation")
488 { VectorRead(child,rotation); } else
489 if (tag=="positionref")
490 { position = GetPosition(GenerateName(RefRead(child))); } else
491 if (tag=="rotationref")
492 { rotation = GetRotation(GenerateName(RefRead(child))); } else
493 if (tag=="direction")
494 { axis=AxisRead(child); } else
495 if (tag=="width")
496 { width=QuantityRead(child); } else
497 if (tag=="offset")
498 { offset=QuantityRead(child); }
499 else
500 {
501 G4String error_msg = "Unknown tag in ReplicaRead: " + tag;
502 G4Exception("G4GDMLReadStructure::ReplicaRead()", "ReadError",
503 FatalException, error_msg);
504 }
505 }
506
507 G4String pv_name = logvol->GetName() + "_PV";
509 ->Replicate(pv_name,logvol,pMotherLogical,axis,number,width,offset);
510
511 if (pair.first != 0) { GeneratePhysvolName(name,pair.first); }
512 if (pair.second != 0) { GeneratePhysvolName(name,pair.second); }
513
514}
515
517AxisRead(const xercesc::DOMElement* const axisElement)
518{
519 EAxis axis = kUndefined;
520
521 const xercesc::DOMNamedNodeMap* const attributes
522 = axisElement->getAttributes();
523 XMLSize_t attributeCount = attributes->getLength();
524
525 for (XMLSize_t attribute_index=0;
526 attribute_index<attributeCount; attribute_index++)
527 {
528 xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
529
530 if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
531 { continue; }
532
533 const xercesc::DOMAttr* const attribute
534 = dynamic_cast<xercesc::DOMAttr*>(attribute_node);
535 if (!attribute)
536 {
537 G4Exception("G4GDMLReadStructure::AxisRead()",
538 "InvalidRead", FatalException, "No attribute found!");
539 return axis;
540 }
541 const G4String attName = Transcode(attribute->getName());
542 const G4String attValue = Transcode(attribute->getValue());
543 if (attName=="x")
544 { if( eval.Evaluate(attValue)==1.) {axis=kXAxis;} }
545 else if (attName=="y")
546 { if( eval.Evaluate(attValue)==1.) {axis=kYAxis;} }
547 else if (attName=="z")
548 { if( eval.Evaluate(attValue)==1.) {axis=kZAxis;} }
549 else if (attName=="rho")
550 { if( eval.Evaluate(attValue)==1.) {axis=kRho;} }
551 else if (attName=="phi")
552 { if( eval.Evaluate(attValue)==1.) {axis=kPhi;} }
553 }
554
555 return axis;
556}
557
559QuantityRead(const xercesc::DOMElement* const readElement)
560{
561 G4double value = 0.0;
562 G4double unit = 0.0;
563 const xercesc::DOMNamedNodeMap* const attributes
564 = readElement->getAttributes();
565 XMLSize_t attributeCount = attributes->getLength();
566
567 for (XMLSize_t attribute_index=0;
568 attribute_index<attributeCount; attribute_index++)
569 {
570 xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
571
572 if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
573 { continue; }
574 const xercesc::DOMAttr* const attribute
575 = dynamic_cast<xercesc::DOMAttr*>(attribute_node);
576 if (!attribute)
577 {
578 G4Exception("G4GDMLReadStructure::QuantityRead()",
579 "InvalidRead", FatalException, "No attribute found!");
580 return value;
581 }
582 const G4String attName = Transcode(attribute->getName());
583 const G4String attValue = Transcode(attribute->getValue());
584
585 if (attName=="unit") { unit = eval.Evaluate(attValue); } else
586 if (attName=="value"){ value= eval.Evaluate(attValue); }
587 }
588
589 return value*unit;
590}
591
593VolumeRead(const xercesc::DOMElement* const volumeElement)
594{
595 G4VSolid* solidPtr = 0;
596 G4Material* materialPtr = 0;
597 G4GDMLAuxListType auxList;
598
599 XMLCh *name_attr = xercesc::XMLString::transcode("name");
600 const G4String name = Transcode(volumeElement->getAttribute(name_attr));
601 xercesc::XMLString::release(&name_attr);
602
603 for (xercesc::DOMNode* iter = volumeElement->getFirstChild();
604 iter != 0; iter = iter->getNextSibling())
605 {
606 if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) { continue; }
607
608 const xercesc::DOMElement* const child
609 = dynamic_cast<xercesc::DOMElement*>(iter);
610 if (!child)
611 {
612 G4Exception("G4GDMLReadStructure::VolumeRead()",
613 "InvalidRead", FatalException, "No child found!");
614 return;
615 }
616 const G4String tag = Transcode(child->getTagName());
617
618 if (tag=="auxiliary")
619 { auxList.push_back(AuxiliaryRead(child)); } else
620 if (tag=="materialref")
621 { materialPtr = GetMaterial(GenerateName(RefRead(child),true)); } else
622 if (tag=="solidref")
623 { solidPtr = GetSolid(GenerateName(RefRead(child))); }
624 }
625
626 pMotherLogical = new G4LogicalVolume(solidPtr,materialPtr,
627 GenerateName(name),0,0,0);
628
629 if (!auxList.empty()) { auxMap[pMotherLogical] = auxList; }
630
631 Volume_contentRead(volumeElement);
632}
633
635AssemblyRead(const xercesc::DOMElement* const assemblyElement)
636{
637 XMLCh *name_attr = xercesc::XMLString::transcode("name");
638 const G4String name = Transcode(assemblyElement->getAttribute(name_attr));
639 xercesc::XMLString::release(&name_attr);
640
641 G4AssemblyVolume* pAssembly = new G4AssemblyVolume();
642 assemblyMap.insert(std::make_pair(GenerateName(name), pAssembly));
643
644 for (xercesc::DOMNode* iter = assemblyElement->getFirstChild();
645 iter != 0; iter = iter->getNextSibling())
646 {
647 if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) { continue; }
648 const xercesc::DOMElement* const child
649 = dynamic_cast<xercesc::DOMElement*>(iter);
650 if (!child)
651 {
652 G4Exception("G4GDMLReadStructure::AssemblyRead()",
653 "InvalidRead", FatalException, "No child found!");
654 return;
655 }
656 const G4String tag = Transcode(child->getTagName());
657
658 if (tag=="physvol")
659 {
660 PhysvolRead(child, pAssembly);
661 }
662 else
663 {
664 G4cout << "Unsupported GDML tag '" << tag
665 << "' for Geant4 assembly structure !" << G4endl;
666 }
667 }
668}
669
671SkinSurfaceRead(const xercesc::DOMElement* const skinsurfaceElement)
672{
673 G4String name;
674 G4LogicalVolume* logvol = 0;
675 G4SurfaceProperty* prop = 0;
676
677 const xercesc::DOMNamedNodeMap* const attributes
678 = skinsurfaceElement->getAttributes();
679 XMLSize_t attributeCount = attributes->getLength();
680
681 for (XMLSize_t attribute_index=0;
682 attribute_index<attributeCount; attribute_index++)
683 {
684 xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
685
686 if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
687 { continue; }
688
689 const xercesc::DOMAttr* const attribute
690 = dynamic_cast<xercesc::DOMAttr*>(attribute_node);
691 if (!attribute)
692 {
693 G4Exception("G4GDMLReadStructure::SkinsurfaceRead()",
694 "InvalidRead", FatalException, "No attribute found!");
695 return;
696 }
697 const G4String attName = Transcode(attribute->getName());
698 const G4String attValue = Transcode(attribute->getValue());
699
700 if (attName=="name")
701 { name = GenerateName(attValue); } else
702 if (attName=="surfaceproperty")
703 { prop = GetSurfaceProperty(GenerateName(attValue)); }
704 }
705
706 for (xercesc::DOMNode* iter = skinsurfaceElement->getFirstChild();
707 iter != 0; iter = iter->getNextSibling())
708 {
709 if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) { continue; }
710
711 const xercesc::DOMElement* const child
712 = dynamic_cast<xercesc::DOMElement*>(iter);
713 if (!child)
714 {
715 G4Exception("G4GDMLReadStructure::SkinsurfaceRead()",
716 "InvalidRead", FatalException, "No child found!");
717 return;
718 }
719 const G4String tag = Transcode(child->getTagName());
720
721 if (tag=="volumeref")
722 {
723 logvol = GetVolume(GenerateName(RefRead(child)));
724 }
725 else
726 {
727 G4String error_msg = "Unknown tag in skinsurface: " + tag;
728 G4Exception("G4GDMLReadStructure::SkinsurfaceRead()", "ReadError",
729 FatalException, error_msg);
730 }
731 }
732
733 new G4LogicalSkinSurface(Strip(name),logvol,prop);
734}
735
737Volume_contentRead(const xercesc::DOMElement* const volumeElement)
738{
739 for (xercesc::DOMNode* iter = volumeElement->getFirstChild();
740 iter != 0; iter = iter->getNextSibling())
741 {
742 if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) { continue; }
743
744 const xercesc::DOMElement* const child
745 = dynamic_cast<xercesc::DOMElement*>(iter);
746 if (!child)
747 {
748 G4Exception("G4GDMLReadStructure::Volume_contentRead()",
749 "InvalidRead", FatalException, "No child found!");
750 return;
751 }
752 const G4String tag = Transcode(child->getTagName());
753
754 if ((tag=="auxiliary") || (tag=="materialref") || (tag=="solidref"))
755 {
756 // These are already processed in VolumeRead()
757 }
758 else if (tag=="paramvol")
759 {
761 }
762 else if (tag=="physvol")
763 {
764 PhysvolRead(child);
765 }
766 else if (tag=="replicavol")
767 {
768 G4int number = 1;
769 const xercesc::DOMNamedNodeMap* const attributes
770 = child->getAttributes();
771 XMLSize_t attributeCount = attributes->getLength();
772 for (XMLSize_t attribute_index=0;
773 attribute_index<attributeCount; attribute_index++)
774 {
775 xercesc::DOMNode* attribute_node
776 = attributes->item(attribute_index);
777 if (attribute_node->getNodeType()!=xercesc::DOMNode::ATTRIBUTE_NODE)
778 {
779 continue;
780 }
781 const xercesc::DOMAttr* const attribute
782 = dynamic_cast<xercesc::DOMAttr*>(attribute_node);
783 if (!attribute)
784 {
785 G4Exception("G4GDMLReadStructure::Volume_contentRead()",
786 "InvalidRead", FatalException, "No attribute found!");
787 return;
788 }
789 const G4String attName = Transcode(attribute->getName());
790 const G4String attValue = Transcode(attribute->getValue());
791 if (attName=="number")
792 {
793 number = eval.EvaluateInteger(attValue);
794 }
795 }
796 ReplicavolRead(child,number);
797 }
798 else if (tag=="divisionvol")
799 {
800 DivisionvolRead(child);
801 }
802 else if (tag=="loop")
803 {
805 }
806 else
807 {
808 G4cout << "Treating unknown GDML tag in volume '" << tag
809 << "' as GDML extension..." << G4endl;
810 }
811 }
812}
813
815StructureRead(const xercesc::DOMElement* const structureElement)
816{
817 G4cout << "G4GDML: Reading structure..." << G4endl;
818
819 for (xercesc::DOMNode* iter = structureElement->getFirstChild();
820 iter != 0; iter = iter->getNextSibling())
821 {
822 if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) { continue; }
823
824 const xercesc::DOMElement* const child
825 = dynamic_cast<xercesc::DOMElement*>(iter);
826 if (!child)
827 {
828 G4Exception("G4GDMLReadStructure::StructureRead()",
829 "InvalidRead", FatalException, "No child found!");
830 return;
831 }
832 const G4String tag = Transcode(child->getTagName());
833
834 if (tag=="bordersurface") { BorderSurfaceRead(child); } else
835 if (tag=="skinsurface") { SkinSurfaceRead(child); } else
836 if (tag=="volume") { VolumeRead(child); } else
837 if (tag=="assembly") { AssemblyRead(child); } else
838 if (tag=="loop") { LoopRead(child,&G4GDMLRead::StructureRead); }
839 else
840 {
841 G4String error_msg = "Unknown tag in structure: " + tag;
842 G4Exception("G4GDMLReadStructure::StructureRead()",
843 "ReadError", FatalException, error_msg);
844 }
845 }
846}
847
849GetPhysvol(const G4String& ref) const
850{
851 G4VPhysicalVolume* physvolPtr =
853
854 if (!physvolPtr)
855 {
856 G4String error_msg = "Referenced physvol '" + ref + "' was not found!";
857 G4Exception("G4GDMLReadStructure::GetPhysvol()", "ReadError",
858 FatalException, error_msg);
859 }
860
861 return physvolPtr;
862}
863
865GetVolume(const G4String& ref) const
866{
867 G4LogicalVolume *volumePtr
869
870 if (!volumePtr)
871 {
872 G4String error_msg = "Referenced volume '" + ref + "' was not found!";
873 G4Exception("G4GDMLReadStructure::GetVolume()", "ReadError",
874 FatalException, error_msg);
875 }
876
877 return volumePtr;
878}
879
881GetAssembly(const G4String& ref) const
882{
883 G4GDMLAssemblyMapType::const_iterator pos = assemblyMap.find(ref);
884 if (pos != assemblyMap.end()) { return pos->second; }
885 return 0;
886}
887
890{
891 G4GDMLAuxMapType::const_iterator pos = auxMap.find(logvol);
892 if (pos != auxMap.end()) { return pos->second; }
893 else { return G4GDMLAuxListType(); }
894}
895
897GetAuxMap() const
898{
899 return &auxMap;
900}
901
903GetWorldVolume(const G4String& setupName)
904{
905 G4LogicalVolume* volume = GetVolume(Strip(GetSetup(setupName)));
907
908 G4VPhysicalVolume* pvWorld = 0;
909
910 if(setuptoPV[setupName])
911 {
912 pvWorld = setuptoPV[setupName];
913 }
914 else
915 {
916 pvWorld = new G4PVPlacement(0,G4ThreeVector(0,0,0),volume,
917 volume->GetName()+"_PV",0,0,0);
918 setuptoPV[setupName] = pvWorld;
919 }
920 return pvWorld;
921}
922
924{
925 eval.Clear();
926 setuptoPV.clear();
927}
@ FatalException
std::map< G4LogicalVolume *, G4GDMLAuxListType > G4GDMLAuxMapType
std::vector< G4GDMLAuxPairType > G4GDMLAuxListType
std::pair< G4VPhysicalVolume *, G4VPhysicalVolume * > G4PhysicalVolumesPair
CLHEP::Hep3Vector G4ThreeVector
HepGeom::Scale3D G4Scale3D
double G4double
Definition: G4Types.hh:64
int G4int
Definition: G4Types.hh:66
bool G4bool
Definition: G4Types.hh:67
#define G4endl
Definition: G4ios.hh:52
G4DLLIMPORT std::ostream G4cout
double z() const
double x() const
double y() const
void MakeImprint(G4LogicalVolume *pMotherLV, G4ThreeVector &translationInMother, G4RotationMatrix *pRotationInMother, G4int copyNumBase=0, G4bool surfCheck=false)
void AddPlacedVolume(G4LogicalVolume *pPlacedVolume, G4ThreeVector &translation, G4RotationMatrix *rotation)
G4double Evaluate(const G4String &)
G4int EvaluateInteger(const G4String &)
G4ThreeVector GetScale(const G4String &)
void VectorRead(const xercesc::DOMElement *const, G4ThreeVector &)
G4RotationMatrix GetRotationMatrix(const G4ThreeVector &)
G4ThreeVector GetPosition(const G4String &)
G4String RefRead(const xercesc::DOMElement *const)
G4ThreeVector GetRotation(const G4String &)
G4Material * GetMaterial(const G4String &, G4bool verbose=true) const
virtual void ParamvolRead(const xercesc::DOMElement *const, G4LogicalVolume *)
G4String GetSetup(const G4String &)
G4SurfaceProperty * GetSurfaceProperty(const G4String &) const
G4VSolid * GetSolid(const G4String &) const
const G4GDMLAuxMapType * GetAuxMap() const
void BorderSurfaceRead(const xercesc::DOMElement *const)
virtual void Volume_contentRead(const xercesc::DOMElement *const)
virtual void StructureRead(const xercesc::DOMElement *const)
void AssemblyRead(const xercesc::DOMElement *const)
G4LogicalVolume * GetVolume(const G4String &) const
void PhysvolRead(const xercesc::DOMElement *const, G4AssemblyVolume *assembly=0)
void ReplicaRead(const xercesc::DOMElement *const replicaElement, G4LogicalVolume *logvol, G4int number)
EAxis AxisRead(const xercesc::DOMElement *const axisElement)
G4VPhysicalVolume * GetWorldVolume(const G4String &)
G4double QuantityRead(const xercesc::DOMElement *const readElement)
void DivisionvolRead(const xercesc::DOMElement *const)
std::map< std::string, G4VPhysicalVolume * > setuptoPV
void SkinSurfaceRead(const xercesc::DOMElement *const)
G4LogicalVolume * pMotherLogical
void ReplicavolRead(const xercesc::DOMElement *const, G4int number)
G4GDMLAuxPairType AuxiliaryRead(const xercesc::DOMElement *const)
virtual void VolumeRead(const xercesc::DOMElement *const)
G4GDMLAssemblyMapType assemblyMap
G4VPhysicalVolume * GetPhysvol(const G4String &) const
G4AssemblyVolume * GetAssembly(const G4String &) const
G4LogicalVolume * FileRead(const xercesc::DOMElement *const)
G4GDMLAuxListType GetVolumeAuxiliaryInformation(G4LogicalVolume *) const
G4bool check
Definition: G4GDMLRead.hh:146
G4String Strip(const G4String &) const
Definition: G4GDMLRead.cc:100
G4bool validate
Definition: G4GDMLRead.hh:145
void GeneratePhysvolName(const G4String &, G4VPhysicalVolume *)
Definition: G4GDMLRead.cc:84
G4String GenerateName(const G4String &name, G4bool strip=false)
Definition: G4GDMLRead.cc:68
void LoopRead(const xercesc::DOMElement *const, void(G4GDMLRead::*)(const xercesc::DOMElement *const))
Definition: G4GDMLRead.cc:179
virtual void Volume_contentRead(const xercesc::DOMElement *const)=0
void Read(const G4String &, G4bool validation, G4bool isModule, G4bool strip=true)
Definition: G4GDMLRead.cc:271
G4String Transcode(const XMLCh *const)
Definition: G4GDMLRead.cc:55
virtual void StructureRead(const xercesc::DOMElement *const)=0
G4GDMLEvaluator eval
Definition: G4GDMLRead.hh:144
G4LogicalVolume * GetVolume(const G4String &name, G4bool verbose=true) const
static G4LogicalVolumeStore * GetInstance()
G4String GetName() const
void SetVisAttributes(const G4VisAttributes *pVA)
static G4PVDivisionFactory * GetInstance()
static G4PhysicalVolumeStore * GetInstance()
G4VPhysicalVolume * GetVolume(const G4String &name, G4bool verbose=true) const
G4PhysicalVolumesPair Divide(const G4String &name, G4LogicalVolume *LV, G4LogicalVolume *motherLV, EAxis axis, G4int nofDivisions, G4double width, G4double offset)
static G4ReflectionFactory * Instance()
G4PhysicalVolumesPair Place(const G4Transform3D &transform3D, const G4String &name, G4LogicalVolume *LV, G4LogicalVolume *motherLV, G4bool isMany, G4int copyNo, G4bool surfCheck=false)
G4PhysicalVolumesPair Replicate(const G4String &name, G4LogicalVolume *LV, G4LogicalVolume *motherLV, EAxis axis, G4int nofReplicas, G4double width, G4double offset=0)
G4int first(char) const
static const G4VisAttributes Invisible
EAxis
Definition: geomdefs.hh:54
@ kPhi
Definition: geomdefs.hh:54
@ kYAxis
Definition: geomdefs.hh:54
@ kXAxis
Definition: geomdefs.hh:54
@ kZAxis
Definition: geomdefs.hh:54
@ kUndefined
Definition: geomdefs.hh:54
@ kRho
Definition: geomdefs.hh:54
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
Definition: xmlparse.cc:179
#define position
Definition: xmlparse.cc:605