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 auto pos = stable->find(lvol);
441 if(pos != stable->cend())
459 for(
auto pos = btable->cbegin(); pos != btable->cend(); ++pos)
461 if(pvol == pos->first.first)
500 for(
auto it = assemblies->cbegin(); it != assemblies->cend(); ++it)
502 auto vit = (*it)->GetVolumesIterator();
504 for(std::size_t i5 = 0; i5 < (*it)->TotalImprintedVolumes(); ++i5)
506 G4String pvname = (*vit)->GetName();
507 std::size_t pos = pvname.find(
"_impr_") + 6;
508 G4String impID = pvname.substr(pos);
510 pos = impID.find(
"_");
511 impID = impID.substr(0, pos);
513 assemblyVolMap[*vit] = (*it)->GetAssemblyID();
514 imprintsMap[*vit] = std::atoi(impID.c_str());
536 std::map<const G4LogicalVolume*, G4GDMLAuxListType>::iterator auxiter;
544 G4String ErrorMessage =
"Referenced solid in volume '" +
546 "' was displaced/reflected too many times!";
547 G4Exception(
"G4GDMLWriteStructure::TraverseVolumeTree()",
"InvalidSetup",
553 R = R * refl->GetTransform3D();
554 solidPtr = refl->GetConstituentMovedSolid();
562 disp->GetObjectTranslation());
563 solidPtr = disp->GetConstituentMovedSolid();
602 xercesc::DOMElement* volumeElement =
NewElement(
"volume");
603 volumeElement->setAttributeNode(
NewAttribute(
"name", name));
604 xercesc::DOMElement* materialrefElement =
NewElement(
"materialref");
605 materialrefElement->setAttributeNode(
NewAttribute(
"ref", materialref));
606 volumeElement->appendChild(materialrefElement);
607 xercesc::DOMElement* solidrefElement =
NewElement(
"solidref");
608 solidrefElement->setAttributeNode(
NewAttribute(
"ref", solidref));
609 volumeElement->appendChild(solidrefElement);
613 if(levelNo == maxLevel)
618 std::map<G4int, std::vector<G4int> > assemblyIDToAddedImprints;
620 for(std::size_t i = 0; i < daughterCount; ++i)
627 if(ModuleName.empty())
643 G4String ErrorMessage =
"Division volume in '" + name +
644 "' can not be related to reflected solid!";
645 G4Exception(
"G4GDMLWriteStructure::TraverseVolumeTree()",
657 G4String ErrorMessage =
"Parameterised volume in '" + name +
658 "' can not be related to reflected solid!";
659 G4Exception(
"G4GDMLWriteStructure::TraverseVolumeTree()",
671 G4String ErrorMessage =
"Replica volume in '" + name +
672 "' can not be related to reflected solid!";
673 G4Exception(
"G4GDMLWriteStructure::TraverseVolumeTree()",
680 if(assemblyVolMap.find(physvol) != assemblyVolMap.cend())
682 G4int assemblyID = assemblyVolMap[physvol];
684 G4String assemblyref =
"Assembly_" + std::to_string(assemblyID);
688 G4int imprintID = imprintsMap[physvol];
696 if(std::find(addedAssemblies.cbegin(), addedAssemblies.cend(),
697 assemblyID) == addedAssemblies.cend())
700 addedAssemblies.push_back(assemblyID);
701 assemblyIDToAddedImprints[assemblyID] = std::vector<G4int>();
710 std::vector<G4int>& addedImprints = assemblyIDToAddedImprints[assemblyID];
711 if(std::find(addedImprints.cbegin(), addedImprints.cend(),
712 imprintID) == addedImprints.cend())
714 G4String imprintname =
"Imprint_" + std::to_string(imprintID) +
"_";
730 const G4ThreeVector scl(scale(0, 0), scale(1, 1), scale(2, 2));
736 xercesc::DOMElement* physvolElement =
NewElement(
"physvol");
737 physvolElement->setAttributeNode(
NewAttribute(
"name", imprintname));
739 xercesc::DOMElement* volumerefElement =
NewElement(
"volumeref");
740 volumerefElement->setAttributeNode(
NewAttribute(
"ref", assemblyref));
741 physvolElement->appendChild(volumerefElement);
759 ScaleWrite(physvolElement, name +
"_scl", scl);
762 volumeElement->appendChild(physvolElement);
764 addedImprints.push_back(imprintID);
776 PhysvolWrite(volumeElement, physvol, invR * P * daughterR,
800 auxiter =
auxmap.find(volumePtr);
801 if(auxiter !=
auxmap.cend())
803 AddAuxInfo(&(auxiter->second), volumeElement);
829 auto pos =
auxmap.find(lvol);
836 auxmap[lvol].push_back(myaux);
912 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::map< const G4LogicalVolume *, 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 * GetMasterSensitiveDetector() 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
void GetReplicationData(EAxis &axis, G4int &nReplicas, G4double &width, G4double &offset, G4bool &consuming) const override
EAxis GetDivisionAxis() 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