58G4int G4GDMLWriteStructure::levelNo = 0;
75 xercesc::DOMElement* volumeElement,
const G4PVDivision*
const divisionvol)
90 axisString =
"kXAxis";
94 axisString =
"kYAxis";
98 axisString =
"kZAxis";
100 else if(axis ==
kRho)
104 else if(axis ==
kPhi)
115 xercesc::DOMElement* divisionvolElement =
NewElement(
"divisionvol");
116 divisionvolElement->setAttributeNode(
NewAttribute(
"axis", axisString));
117 divisionvolElement->setAttributeNode(
NewAttribute(
"number", number));
118 divisionvolElement->setAttributeNode(
NewAttribute(
"width", width));
119 divisionvolElement->setAttributeNode(
NewAttribute(
"offset", offset));
120 divisionvolElement->setAttributeNode(
NewAttribute(
"unit", unitString));
121 xercesc::DOMElement* volumerefElement =
NewElement(
"volumeref");
122 volumerefElement->setAttributeNode(
NewAttribute(
"ref", volumeref));
123 divisionvolElement->appendChild(volumerefElement);
124 volumeElement->appendChild(divisionvolElement);
139 const G4ThreeVector scl(scale(0, 0), scale(1, 1), scale(2, 2));
146 xercesc::DOMElement* physvolElement =
NewElement(
"physvol");
147 physvolElement->setAttributeNode(
NewAttribute(
"name", name));
150 physvolElement->setAttributeNode(
NewAttribute(
"copynumber", copynumber));
153 volumeElement->appendChild(physvolElement);
168 if(ModuleName.empty())
170 xercesc::DOMElement* volumerefElement =
NewElement(
"volumeref");
171 volumerefElement->setAttributeNode(
NewAttribute(
"ref", volumeref));
172 physvolElement->appendChild(volumerefElement);
176 xercesc::DOMElement* fileElement =
NewElement(
"file");
177 fileElement->setAttributeNode(
NewAttribute(
"name", ModuleName));
178 fileElement->setAttributeNode(
NewAttribute(
"volname", volumeref));
179 physvolElement->appendChild(fileElement);
198 ScaleWrite(physvolElement, name +
"_scl", scl);
218 xercesc::DOMElement* replicavolElement =
NewElement(
"replicavol");
219 replicavolElement->setAttributeNode(
NewAttribute(
"number", number));
220 xercesc::DOMElement* volumerefElement =
NewElement(
"volumeref");
221 volumerefElement->setAttributeNode(
NewAttribute(
"ref", volumeref));
222 replicavolElement->appendChild(volumerefElement);
223 xercesc::DOMElement* replicateElement =
NewElement(
"replicate_along_axis");
224 replicavolElement->appendChild(replicateElement);
226 xercesc::DOMElement* dirElement =
NewElement(
"direction");
239 else if(axis ==
kRho)
243 else if(axis ==
kPhi)
248 replicateElement->appendChild(dirElement);
250 xercesc::DOMElement* widthElement =
NewElement(
"width");
251 widthElement->setAttributeNode(
NewAttribute(
"value", width));
252 widthElement->setAttributeNode(
NewAttribute(
"unit", unitString));
253 replicateElement->appendChild(widthElement);
255 xercesc::DOMElement* offsetElement =
NewElement(
"offset");
256 offsetElement->setAttributeNode(
NewAttribute(
"value", offset));
257 offsetElement->setAttributeNode(
NewAttribute(
"unit", unitString));
258 replicateElement->appendChild(offsetElement);
260 volumeElement->appendChild(replicavolElement);
265 const G4int assemblyID)
270 xercesc::DOMElement* assemblyElement =
NewElement(
"assembly");
271 G4String name =
"Assembly_" + std::to_string(assemblyID);
273 assemblyElement->setAttributeNode(
NewAttribute(
"name", name));
280 for(std::size_t i5 = 0; i5 < myassembly->
TotalTriplets(); ++i5)
285 G4String message =
"Nested assemblies not yet supported for exporting. Sorry!";
286 G4Exception(
"G4GDMLWriteStructure::AssemblyWrite()",
"InvalidSetup",
296 GenerateName((*vit).GetVolume()->GetName() +
"_pv", &(*vit));
298 xercesc::DOMElement* physvolElement =
NewElement(
"physvol");
299 physvolElement->setAttributeNode(
NewAttribute(
"name", pname));
301 assemblyElement->appendChild(physvolElement);
304 GenerateName((*vit).GetVolume()->GetName(), (*vit).GetVolume());
306 xercesc::DOMElement* volumerefElement =
NewElement(
"volumeref");
307 volumerefElement->setAttributeNode(
NewAttribute(
"ref", volumeref));
308 physvolElement->appendChild(volumerefElement);
314 PositionWrite(physvolElement,name+
"_position_" + std::to_string(i5), pos);
321 RotationWrite(physvolElement,name+
"_rotation_" + std::to_string(i5), rot);
326 volumeElement->appendChild(assemblyElement);
344 xercesc::DOMElement* borderElement =
NewElement(
"bordersurface");
345 borderElement->setAttributeNode(
NewAttribute(
"name", bsname));
346 borderElement->setAttributeNode(
NewAttribute(
"surfaceproperty", psname));
352 xercesc::DOMElement* volumerefElement1 =
NewElement(
"physvolref");
353 xercesc::DOMElement* volumerefElement2 =
NewElement(
"physvolref");
354 volumerefElement1->setAttributeNode(
NewAttribute(
"ref", volumeref1));
355 volumerefElement2->setAttributeNode(
NewAttribute(
"ref", volumeref2));
356 borderElement->appendChild(volumerefElement1);
357 borderElement->appendChild(volumerefElement2);
363 if(opsurf ==
nullptr)
365 G4Exception(
"G4GDMLWriteStructure::BorderSurfaceCache()",
"InvalidSetup",
390 xercesc::DOMElement* skinElement =
NewElement(
"skinsurface");
391 skinElement->setAttributeNode(
NewAttribute(
"name", ssname));
392 skinElement->setAttributeNode(
NewAttribute(
"surfaceproperty", psname));
396 xercesc::DOMElement* volumerefElement =
NewElement(
"volumeref");
397 volumerefElement->setAttributeNode(
NewAttribute(
"ref", volumeref));
398 skinElement->appendChild(volumerefElement);
404 if(opsurf ==
nullptr)
406 G4Exception(
"G4GDMLWriteStructure::SkinSurfaceCache()",
"InvalidSetup",
420 auto pos = std::find(opt_vec.cbegin(), opt_vec.cend(), osurf);
421 if(pos != opt_vec.cend())
426 opt_vec.push_back(osurf);
440 for(
auto pos = stable->cbegin(); pos != stable->cend(); ++pos)
442 if(lvol == (*pos)->GetLogicalVolume())
462 for(
auto pos = btable->cbegin(); pos != btable->cend(); ++pos)
464 if(pvol == pos->first.first)
503 for(
auto it = assemblies->cbegin(); it != assemblies->cend(); ++it)
505 auto vit = (*it)->GetVolumesIterator();
507 for(std::size_t i5 = 0; i5 < (*it)->TotalImprintedVolumes(); ++i5)
509 G4String pvname = (*vit)->GetName();
510 std::size_t pos = pvname.find(
"_impr_") + 6;
511 G4String impID = pvname.substr(pos);
513 pos = impID.find(
"_");
514 impID = impID.substr(0, pos);
516 assemblyVolMap[*vit] = (*it)->GetAssemblyID();
517 imprintsMap[*vit] = std::atoi(impID.c_str());
539 std::map<const G4LogicalVolume*, G4GDMLAuxListType>::iterator auxiter;
547 G4String ErrorMessage =
"Referenced solid in volume '" +
549 "' was displaced/reflected too many times!";
550 G4Exception(
"G4GDMLWriteStructure::TraverseVolumeTree()",
"InvalidSetup",
556 R = R * refl->GetTransform3D();
557 solidPtr = refl->GetConstituentMovedSolid();
565 disp->GetObjectTranslation());
566 solidPtr = disp->GetConstituentMovedSolid();
605 xercesc::DOMElement* volumeElement =
NewElement(
"volume");
606 volumeElement->setAttributeNode(
NewAttribute(
"name", name));
607 xercesc::DOMElement* materialrefElement =
NewElement(
"materialref");
608 materialrefElement->setAttributeNode(
NewAttribute(
"ref", materialref));
609 volumeElement->appendChild(materialrefElement);
610 xercesc::DOMElement* solidrefElement =
NewElement(
"solidref");
611 solidrefElement->setAttributeNode(
NewAttribute(
"ref", solidref));
612 volumeElement->appendChild(solidrefElement);
616 if(levelNo == maxLevel)
621 std::map<G4int, std::vector<G4int> > assemblyIDToAddedImprints;
623 for(std::size_t i = 0; i < daughterCount; ++i)
630 if(ModuleName.empty())
646 G4String ErrorMessage =
"Division volume in '" + name +
647 "' can not be related to reflected solid!";
648 G4Exception(
"G4GDMLWriteStructure::TraverseVolumeTree()",
660 G4String ErrorMessage =
"Parameterised volume in '" + name +
661 "' can not be related to reflected solid!";
662 G4Exception(
"G4GDMLWriteStructure::TraverseVolumeTree()",
674 G4String ErrorMessage =
"Replica volume in '" + name +
675 "' can not be related to reflected solid!";
676 G4Exception(
"G4GDMLWriteStructure::TraverseVolumeTree()",
683 if(assemblyVolMap.find(physvol) != assemblyVolMap.cend())
685 G4int assemblyID = assemblyVolMap[physvol];
687 G4String assemblyref =
"Assembly_" + std::to_string(assemblyID);
691 G4int imprintID = imprintsMap[physvol];
699 if(std::find(addedAssemblies.cbegin(), addedAssemblies.cend(),
700 assemblyID) == addedAssemblies.cend())
703 addedAssemblies.push_back(assemblyID);
704 assemblyIDToAddedImprints[assemblyID] = std::vector<G4int>();
713 std::vector<G4int>& addedImprints = assemblyIDToAddedImprints[assemblyID];
714 if(std::find(addedImprints.cbegin(), addedImprints.cend(),
715 imprintID) == addedImprints.cend())
717 G4String imprintname =
"Imprint_" + std::to_string(imprintID) +
"_";
733 const G4ThreeVector scl(scale(0, 0), scale(1, 1), scale(2, 2));
739 xercesc::DOMElement* physvolElement =
NewElement(
"physvol");
740 physvolElement->setAttributeNode(
NewAttribute(
"name", imprintname));
742 xercesc::DOMElement* volumerefElement =
NewElement(
"volumeref");
743 volumerefElement->setAttributeNode(
NewAttribute(
"ref", assemblyref));
744 physvolElement->appendChild(volumerefElement);
762 ScaleWrite(physvolElement, name +
"_scl", scl);
765 volumeElement->appendChild(physvolElement);
767 addedImprints.push_back(imprintID);
779 PhysvolWrite(volumeElement, physvol, invR * P * daughterR,
803 auxiter =
auxmap.find(volumePtr);
804 if(auxiter !=
auxmap.cend())
806 AddAuxInfo(&(auxiter->second), volumeElement);
832 auto pos =
auxmap.find(lvol);
839 auxmap[lvol].push_back(myaux);
915 G4Exception(
"G4GDMLWriteStructure::TraverseVolumeTree()",
"InvalidSetup",
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::vector< G4GDMLAuxStructType > G4GDMLAuxListType
std::map< std::pair< const G4VPhysicalVolume *, const G4VPhysicalVolume * >, G4LogicalBorderSurface * > G4LogicalBorderSurfaceTable
std::vector< G4LogicalSkinSurface * > G4LogicalSkinSurfaceTable
G4GLOB_DLL std::ostream G4cout
HepRotation inverse() const
static G4AssemblyStore * GetInstance()
G4AssemblyVolume * GetAssembly(unsigned int id, G4bool verbose=true) const
G4Transform3D & GetImprintTransformation(unsigned int imprintID)
std::vector< G4AssemblyTriplet >::iterator GetTripletsIterator()
std::size_t TotalTriplets() const
static G4Electron * Electron()
G4String ConvertToString(G4int ival)
static const G4double kLinearPrecision
void RotationWrite(xercesc::DOMElement *element, const G4String &name, const G4ThreeVector &rot)
static const G4double kAngularPrecision
void PositionWrite(xercesc::DOMElement *element, const G4String &name, const G4ThreeVector &pos)
G4ThreeVector GetAngles(const G4RotationMatrix &)
void ScaleWrite(xercesc::DOMElement *element, const G4String &name, const G4ThreeVector &scl)
static const G4double kRelativePrecision
void AddMaterial(const G4Material *const)
virtual void ParamvolWrite(xercesc::DOMElement *, const G4VPhysicalVolume *const)
virtual void AddSolid(const G4VSolid *const)
xercesc::DOMElement * solidsElement
static const G4int maxTransforms
void OpticalSurfaceWrite(xercesc::DOMElement *, const G4OpticalSurface *const)
virtual ~G4GDMLWriteStructure()
const G4LogicalBorderSurface * GetBorderSurface(const G4VPhysicalVolume *const)
void SetEnergyCutsExport(G4bool)
void BorderSurfaceCache(const G4LogicalBorderSurface *const)
std::vector< xercesc::DOMElement * > borderElementVec
std::map< const G4LogicalVolume *, G4GDMLAuxListType > auxmap
void AssemblyWrite(xercesc::DOMElement *, const int assemblyID)
std::vector< xercesc::DOMElement * > skinElementVec
void SkinSurfaceCache(const G4LogicalSkinSurface *const)
const G4LogicalSkinSurface * GetSkinSurface(const G4LogicalVolume *const)
void PhysvolWrite(xercesc::DOMElement *, const G4VPhysicalVolume *const topVol, const G4Transform3D &transform, const G4String &moduleName)
void ExportEnergyCuts(const G4LogicalVolume *const)
virtual void StructureWrite(xercesc::DOMElement *)
G4Transform3D TraverseVolumeTree(const G4LogicalVolume *const topVol, const G4int depth)
xercesc::DOMElement * structureElement
void ExportSD(const G4LogicalVolume *const)
void DivisionvolWrite(xercesc::DOMElement *, const G4PVDivision *const)
G4bool FindOpticalSurface(const G4SurfaceProperty *)
void AddVolumeAuxiliary(G4GDMLAuxStructType myaux, const G4LogicalVolume *const)
G4int GetMaxExportLevel() const
void SetMaxExportLevel(G4int)
void ReplicavolWrite(xercesc::DOMElement *, const G4VPhysicalVolume *const)
xercesc::DOMElement * NewElement(const G4String &)
G4String GenerateName(const G4String &, const void *const)
G4String Modularize(const G4VPhysicalVolume *const topvol, const G4int depth)
virtual void AddExtension(xercesc::DOMElement *, const G4LogicalVolume *const)
G4Transform3D Write(const G4String &filename, const G4LogicalVolume *const topLog, const G4String &schemaPath, const G4int depth, G4bool storeReferences=true)
xercesc::DOMAttr * NewAttribute(const G4String &, const G4String &)
void AddAuxInfo(G4GDMLAuxListType *auxInfoList, xercesc::DOMElement *element)
VolumeMapType & VolumeMap()
static std::size_t GetNumberOfBorderSurfaces()
static const G4LogicalBorderSurfaceTable * GetSurfaceTable()
const G4VPhysicalVolume * GetVolume2() const
const G4VPhysicalVolume * GetVolume1() const
const G4LogicalVolume * GetLogicalVolume() const
static const G4LogicalSkinSurfaceTable * GetSurfaceTable()
static std::size_t GetNumberOfSkinSurfaces()
const G4String & GetName() const
G4SurfaceProperty * GetSurfaceProperty() const
G4VSolid * GetSolid() const
G4VSensitiveDetector * GetSensitiveDetector() const
std::size_t GetNoDaughters() const
G4Region * GetRegion() const
G4Material * GetMaterial() const
G4VPhysicalVolume * GetDaughter(const std::size_t i) const
const G4String & GetName() const
const G4String & GetName() const
EAxis GetDivisionAxis() const
virtual void GetReplicationData(EAxis &axis, G4int &nReplicas, G4double &width, G4double &offset, G4bool &consuming) const
static G4Positron * Positron()
static G4ProductionCutsTable * GetProductionCutsTable()
G4double ConvertRangeToEnergy(const G4ParticleDefinition *particle, const G4Material *material, G4double range)
G4double GetProductionCut(G4int index) const
static G4Proton * Proton()
G4bool IsReflected(G4LogicalVolume *lv) const
static G4ReflectionFactory * Instance()
G4LogicalVolume * GetConstituentLV(G4LogicalVolume *reflLV) const
G4ProductionCuts * GetProductionCuts() const
const G4String & GetName() const
virtual G4bool IsReplicated() const =0
G4LogicalVolume * GetLogicalVolume() const
const G4RotationMatrix * GetFrameRotation() const
virtual void GetReplicationData(EAxis &axis, G4int &nReplicas, G4double &width, G4double &offset, G4bool &consuming) const =0
virtual G4int GetCopyNo() const =0
const G4String & GetName() const
G4ThreeVector GetObjectTranslation() const
virtual G4bool IsParameterised() const =0