175std::string str_replace(
const std::string &str,
const std::string &pattern,
const std::string &replacement)
177 std::string res = str;
178 for (
size_t id = res.find(pattern);
id != std::string::npos;
id = res.find(pattern))
179 res.replace(
id, pattern.length(), replacement);
184std::string make_NCName(
const std::string &in)
186 std::string res = str_replace(in,
"/",
"_");
187 res = str_replace(res,
"#",
"_");
192struct MaterialExtractor {
193 std::set<TGeoMaterial *> materials;
196 materials.insert(
v->GetMaterial());
197 for (
Int_t i = 0; i <
v->GetNdaughters(); ++i)
198 (*
this)(
v->GetNode(i)->GetVolume());
270 Info(
"WriteGDMLfile",
"Top volume does not exist!");
275 WriteGDMLfile(geomanager, node, materials, filename, option);
283 TList materials, volumes, nodes;
284 MaterialExtractor extract;
286 Info(
"WriteGDMLfile",
"Invalid Volume reference to extract GDML information!");
297 WriteGDMLfile(geomanager, node, &materials, filename, option);
298 materials.
Clear(
"nodelete");
299 volumes.
Clear(
"nodelete");
300 nodes.
Clear(
"nodelete");
315 Info(
"WriteGDMLfile",
"Geant4 compatibility mode set");
321 Info(
"WriteGDMLfile",
"Fast naming convention with pointer suffix set");
324 Info(
"WriteGDMLfile",
"Naming without prefix set - be careful uniqness of name is not ensured");
327 Info(
"WriteGDMLfile",
"Potentially slow with incremental suffix naming convention set");
342 Int_t outputLayout = 1;
343 const char *krootNodeName =
"gdml";
344 const char *knsRefGeneral =
"http://www.w3.org/2001/XMLSchema-instance";
345 const char *knsNameGeneral =
"xsi";
346 const char *knsRefGdml =
"http://service-spi.web.cern.ch/service-spi/app/releases/GDML/schema/gdml.xsd";
347 const char *knsNameGdml =
"xsi:noNamespaceSchemaLocation";
361 fGdmlE->NewNS(rootNode, knsRefGeneral, knsNameGeneral);
362 fGdmlE->NewAttr(rootNode,
nullptr, knsNameGdml, knsRefGdml);
401 startT = time(
nullptr);
406 Info(
"WriteGDMLfile",
"Extracting volumes");
409 Info(
"WriteGDMLfile",
"%i volumes added",
fVolCnt);
414 endT = time(
nullptr);
422 Double_t tdiffI = difftime(endT, startT);
424 Info(
"WriteGDMLfile",
"Exporting time: %s", tdiffS.
Data());
429 Info(
"WriteGDMLfile",
"File %s saved", filename);
445 TIter next(matrixList);
475 if (!surfaces->GetEntriesFast())
478 TIter next(surfaces);
494 if (!surfaces->GetEntriesFast())
497 TIter next(surfaces);
514 if (!surfaces->GetEntriesFast())
517 TIter next(surfaces);
525 Warning(
"ExtractBorderSurfaces",
526 "Inconsistent border surface extraction %s: Node %s"
527 " is not part of GDML!",
531 Warning(
"ExtractBorderSurfaces",
532 "Inconsistent border surface extraction %s: Node %s"
533 " is not part of GDML!",
549 Info(
"ExtractMaterials",
"Extracting materials");
555 TIter next(materialsLst);
559 std::string dummy_nam = dummy_mat ? dummy_mat->
GetName() :
"dummy";
563 std::string mname = lmaterial->
GetName();
565 Info(
"ExtractMaterials",
"Skip dummy material: %s", dummy_nam.c_str());
574 fGdmlE->AddChild(materialsN, mixtureN);
577 fGdmlE->AddChild(materialsN, materialN);
581 Info(
"ExtractMaterials",
"%i materials added", matcnt);
594 if (solidN !=
nullptr)
610 TString volname, matname, solname, pattClsName, nodeVolNameBak;
636 if (solname ==
"-1") {
637 Info(
"ExtractVolumes",
"ERROR! %s volume was not added, because solid is either not supported or corrupted",
664 while ((geoNode = (
TGeoNode *)next())) {
675 if (nodevolname.
Contains(
"missing_")) {
679 nodeVolNameBak = nodevolname;
682 if (isPattern ==
kFALSE) {
684 TString nodename, posname, rotname;
686 nodename = nodename +
"in" + volname;
689 posname = nodename +
"pos";
710 scaleN =
fGdmlE->NewChild(
nullptr,
nullptr,
"scale",
nullptr);
711 fGdmlE->NewAttr(scaleN,
nullptr,
"name", (nodename +
"scl").Data());
728 if ((lxyz.
x != 0.0) || (lxyz.
y != 0.0) || (lxyz.
z != 0.0)) {
729 rotname = nodename +
"rot";
738 fGdmlE->AddChild(volumeN, childN);
743 if (isPattern && pattFinder) {
756 offset = pattFinder->
GetStart() - xlo;
761 fGdmlE->AddChild(volumeN, childN);
773 while ((k = it->
Next())) {
784 auxunit = auxvalue(pos + 1, auxvalue.
Length());
785 auxvalue = auxvalue(0, pos);
788 fGdmlE->NewAttr(auxN,
nullptr,
"auxtype", auxtype.
Data());
789 fGdmlE->NewAttr(auxN,
nullptr,
"auxvalue", auxvalue.
Data());
791 fGdmlE->NewAttr(auxN,
nullptr,
"auxunit", auxunit.
Data());
792 fGdmlE->AddChild(volumeN, auxN);
810 fGdmlE->NewAttr(atomN,
nullptr,
"unit", unit);
822 fGdmlE->NewAttr(densN,
nullptr,
"unit", unit);
835 fGdmlE->NewAttr(fractN,
nullptr,
"ref", refName);
845 fGdmlE->NewAttr(propertyN,
nullptr,
"name", property.
GetName());
856 fGdmlE->NewAttr(mainN,
nullptr,
"name",
name);
870 fGdmlE->NewAttr(mainN,
nullptr,
"name",
name);
879 for (
Int_t idx = 0; idx < nOfIso; idx++) {
882 Fatal(
"CreateElementN",
"Missing isotopes for element %s", element->
GetName());
904 fGdmlE->AddChild(materials, isoNode);
907 for (NameListI::iterator itr = wCounter.begin(); itr != wCounter.end(); ++itr) {
908 if (itr->second > 1) {
909 Info(
"CreateMixtureN",
"WARNING! 2 equal isotopes in one element. Check: %s isotope of %s element",
910 itr->first.Data(),
name);
916 fGdmlE->NewAttr(mainN,
nullptr,
"formula", element->
GetName());
917 Int_t valZ = element->
Z();
922 Int_t valN = element->
N();
935 fGdmlE->NewAttr(mainN,
nullptr,
"name", mname);
940 TIter next(&properties);
942 while ((property = (
TNamed *)next()))
947 if (const_properties.
GetSize()) {
948 TIter next(&const_properties);
950 while ((property = (
TNamed *)next()))
962 for (
Int_t idx = 0; idx < nOfElm; idx++) {
974 wPercentage[lname] += mixture->
GetWmixt()[idx];
985 fGdmlE->AddChild(materials, elmNode);
988 for (NameListI::iterator itr = wCounter.begin(); itr != wCounter.end(); ++itr) {
989 if (itr->second > 1) {
990 Info(
"CreateMixtureN",
"WARNING! 2 equal elements in one material. Check: %s element of %s material",
991 itr->first.Data(), mname.
Data());
1006 fGdmlE->NewAttr(mainN,
nullptr,
"name", mname);
1013 if (tmpname ==
"vacuum") {
1017 Info(
"CreateMaterialN",
1018 "WARNING! value of Z in %s material can't be < 1 in Geant4, that is why it was changed to 1, please "
1019 "check it manually! ",
1023 Info(
"CreateMaterialN",
"WARNING! value of Z in %s material can't be < 1 in Geant4", mname.
Data());
1032 TIter next(&properties);
1034 while ((property = (
TNamed *)next()))
1039 if (const_properties.
GetSize()) {
1040 TIter next(&const_properties);
1042 while ((property = (
TNamed *)next()))
1060 fGdmlE->NewAttr(mainN,
nullptr,
"name", lname);
1081 fGdmlE->NewAttr(mainN,
nullptr,
"name", lname);
1101 fGdmlE->NewAttr(mainN,
nullptr,
"name", lname);
1109 fGdmlE->NewAttr(mainN,
nullptr,
"deltaphi",
1112 fGdmlE->NewAttr(mainN,
nullptr,
"deltatheta",
1115 fGdmlE->NewAttr(mainN,
nullptr,
"aunit",
"deg");
1128 fGdmlE->NewAttr(mainN,
nullptr,
"name", lname);
1163 fGdmlE->NewAttr(mainN,
nullptr,
"name", lname);
1174 fGdmlE->NewAttr(mainN,
nullptr,
"deltaphi",
1177 fGdmlE->NewAttr(mainN,
nullptr,
"aunit",
"deg");
1190 fGdmlE->NewAttr(mainN,
nullptr,
"name", lname);
1203 fGdmlE->NewAttr(mainN,
nullptr,
"aunit",
"deg");
1224 fGdmlE->NewAttr(mainN,
nullptr,
"aunit",
"deg");
1238 if ((geoShape->
GetBl1() == 0 || geoShape->
GetTl1() == 0 || geoShape->
GetH1() == 0) ||
1239 (geoShape->
GetBl2() == 0 || geoShape->
GetTl2() == 0 || geoShape->
GetH2() == 0)) {
1250 mainN =
fGdmlE->NewChild(
nullptr,
nullptr,
"trap",
nullptr);
1252 fGdmlE->NewAttr(mainN,
nullptr,
"name", lname);
1270 fGdmlE->NewAttr(mainN,
nullptr,
"aunit",
"deg");
1284 if ((geoShape->
GetBl1() == 0 && geoShape->
GetTl1() == 0 && geoShape->
GetH1() == 0) ||
1285 (geoShape->
GetBl2() == 0 && geoShape->
GetTl2() == 0 && geoShape->
GetH2() == 0)) {
1302 mainN =
fGdmlE->NewChild(
nullptr,
nullptr,
"twistedtrap",
nullptr);
1304 fGdmlE->NewAttr(mainN,
nullptr,
"name", lname);
1324 Info(
"CreateTwistedTrapN",
1325 "ERROR! Object %s is not exported correctly because parameter Alpha2 is not declared in GDML schema",
1331 fGdmlE->NewAttr(mainN,
nullptr,
"aunit",
"deg");
1344 fGdmlE->NewAttr(mainN,
nullptr,
"name", lname);
1367 fGdmlE->NewAttr(mainN,
nullptr,
"name", lname);
1390 fGdmlE->NewAttr(mainN,
nullptr,
"name", lname);
1399 fGdmlE->NewAttr(mainN,
nullptr,
"deltaphi",
1402 fGdmlE->NewAttr(mainN,
nullptr,
"aunit",
"deg");
1415 mainN =
fGdmlE->NewChild(
nullptr,
nullptr,
"cutTube",
nullptr);
1417 fGdmlE->NewAttr(mainN,
nullptr,
"name", lname);
1429 Info(
"CreateCutTubeN",
"WARNING! %s - CutTube was replaced by intersection of TGeoTubSeg and two TGeoBBoxes",
1437 fGdmlE->NewAttr(mainN,
nullptr,
"deltaphi",
1446 fGdmlE->NewAttr(mainN,
nullptr,
"aunit",
"deg");
1460 fGdmlE->NewAttr(mainN,
nullptr,
"name", lname);
1471 fGdmlE->NewAttr(mainN,
nullptr,
"aunit",
"deg");
1499 fGdmlE->NewAttr(mainN,
nullptr,
"name", lname);
1504 fGdmlE->NewAttr(mainN,
nullptr,
"aunit",
"deg");
1507 for (
Int_t it = 0; it < nZPlns; it++) {
1511 if ((it < nZPlns - 1) && (geoShape->
GetZ(it) == geoShape->
GetZ(it + 1))) {
1521 Info(
"CreatePolyconeN",
"WARNING! One plane was added to %s solid to be compatible with Geant4",
1524 Info(
"CreatePolyconeN",
"WARNING! Solid %s definition seems not contiguous may cause problems in Geant4",
1537 Info(
"CreatePolyconeN",
"WARNING! One plane was added to %s solid to be compatible with Geant4",
1540 Info(
"CreatePolyconeN",
"WARNING! Solid %s definition seems not contiguous may cause problems in Geant4",
1557 fGdmlE->NewAttr(mainN,
nullptr,
"name", lname);
1568 fGdmlE->NewAttr(mainN,
nullptr,
"aunit",
"deg");
1587 fGdmlE->NewAttr(mainN,
nullptr,
"aunit",
"deg");
1589 for (
Int_t it = 0; it < geoShape->
GetNz(); it++) {
1604 fGdmlE->NewAttr(mainN,
nullptr,
"name", lname);
1627 fGdmlE->NewAttr(mainN,
nullptr,
"name", lname);
1638 fGdmlE->NewAttr(mainN,
nullptr,
"aunit",
"deg");
1652 fGdmlE->NewAttr(mainN,
nullptr,
"name", lname);
1658 if (vertNum < 3 || secNum < 2) {
1659 Info(
"CreateXtrusionN",
"ERROR! TGeoXtru %s has only %i vertices and %i sections. It was not exported",
1660 lname.
Data(), vertNum, secNum);
1664 for (
Int_t it = 0; it < vertNum; it++) {
1666 childN =
fGdmlE->NewChild(
nullptr,
nullptr,
"twoDimVertex",
nullptr);
1669 fGdmlE->AddChild(mainN, childN);
1671 for (
Int_t it = 0; it < secNum; it++) {
1673 childN =
fGdmlE->NewChild(
nullptr,
nullptr,
"section",
nullptr);
1679 fGdmlE->AddChild(mainN, childN);
1697 fGdmlE->NewAttr(mainN,
nullptr,
"name", elName.
Data());
1710 Double_t zcut1 = 2 * zorig - zcut2;
1735 Double_t zmax = zcut * ((rx1 + rx2) / (rx1 - rx2));
1762 nodPos.
x = vertex[0];
1763 nodPos.
y = vertex[1];
1764 nodPos.
z = vertex[2];
1769 fGdmlE->NewAttr(mainN,
nullptr,
"name", genname.
Data());
1775 auto facet = geoShape->
GetFacet(it);
1776 bool triangular = facet.
GetNvert() == 3;
1777 TString ntype = (triangular) ?
"triangular" :
"quadrangular";
1778 childN =
fGdmlE->NewChild(
nullptr,
nullptr, ntype.
Data(),
nullptr);
1784 fGdmlE->NewAttr(childN,
nullptr,
"type",
"ABSOLUTE");
1785 fGdmlE->AddChild(mainN, childN);
1806 if (unscaledN !=
nullptr) {
1810 if (uname.
Contains(
"missing_") || uname ==
"") {
1811 Info(
"CreateScaledN",
"ERROR! Unscaled node is NULL - Scaled shape will be skipped");
1822 mainN =
fGdmlE->NewChild(
nullptr,
nullptr,
"scaledSolid",
nullptr);
1823 fGdmlE->NewAttr(mainN,
nullptr,
"name", nodeName);
1826 childN =
fGdmlE->NewChild(
nullptr,
nullptr,
"solidref",
nullptr);
1827 fGdmlE->NewAttr(childN,
nullptr,
"ref", uname);
1828 fGdmlE->AddChild(mainN, childN);
1831 childN =
fGdmlE->NewChild(
nullptr,
nullptr,
"scale",
nullptr);
1832 fGdmlE->NewAttr(childN,
nullptr,
"name", (nodeName +
"scl").Data());
1836 fGdmlE->AddChild(mainN, childN);
1867 if (strcmp(leftS->
ClassName(),
"TGeoScaledShape") == 0 && strcmp(rightS->
ClassName(),
"TGeoBBox") == 0) {
1869 if (lboolType ==
"intersection") {
1876 Xyz translL, translR;
1894 if (ndL !=
nullptr) {
1898 if (lname.
Contains(
"missing_") || lname ==
"") {
1899 Info(
"CreateCommonBoolN",
"ERROR! Left node is NULL - Boolean Shape will be skipped");
1903 if (ndR !=
nullptr) {
1907 if (rname.
Contains(
"missing_") || rname ==
"") {
1908 Info(
"CreateCommonBoolN",
"ERROR! Right node is NULL - Boolean Shape will be skipped");
1923 mainN =
fGdmlE->NewChild(
nullptr,
nullptr, lboolType.
Data(),
nullptr);
1924 fGdmlE->NewAttr(mainN,
nullptr,
"name", nodeName);
1927 childN =
fGdmlE->NewChild(
nullptr,
nullptr,
"first",
nullptr);
1928 fGdmlE->NewAttr(childN,
nullptr,
"ref", lname);
1929 fGdmlE->AddChild(mainN, childN);
1932 childN =
fGdmlE->NewChild(
nullptr,
nullptr,
"second",
nullptr);
1933 fGdmlE->NewAttr(childN,
nullptr,
"ref", rname);
1934 fGdmlE->AddChild(mainN, childN);
1937 if ((translL.
x != 0.0) || (translL.
y != 0.0) || (translL.
z != 0.0)) {
1939 fGdmlE->AddChild(mainN, childN);
1942 if ((lrot.
x != 0.0) || (lrot.
y != 0.0) || (lrot.
z != 0.0)) {
1943 childN =
CreateRotationN((nodeName + lname +
"rot").Data(), lrot,
"firstrotation");
1944 fGdmlE->AddChild(mainN, childN);
1947 if ((translR.
x != 0.0) || (translR.
y != 0.0) || (translR.
z != 0.0)) {
1949 fGdmlE->AddChild(mainN, childN);
1952 if ((rrot.
x != 0.0) || (rrot.
y != 0.0) || (rrot.
z != 0.0)) {
1953 childN =
CreateRotationN((nodeName + rname +
"rot").Data(), rrot,
"rotation");
1954 fGdmlE->AddChild(mainN, childN);
1967 std::string
name = make_NCName(geoSurf->
GetName());
1968 fGdmlE->NewAttr(mainN,
nullptr,
"name",
name.c_str());
1977 TIter next(&properties);
1979 while ((property = (
TNamed *)next()))
1984 if (const_properties.
GetSize()) {
1985 TIter next(&const_properties);
1987 while ((property = (
TNamed *)next()))
1999 std::string
name = make_NCName(geoSurf->
GetName());
2000 std::string prop = make_NCName(geoSurf->
GetTitle());
2002 fGdmlE->NewAttr(mainN,
nullptr,
"name",
name.c_str());
2003 fGdmlE->NewAttr(mainN,
nullptr,
"surfaceproperty", prop.c_str());
2008 fGdmlE->NewAttr(childN,
nullptr,
"ref", volname.
Data());
2009 fGdmlE->AddChild(mainN, childN);
2019 std::string
name = make_NCName(geoSurf->
GetName());
2020 std::string prop = make_NCName(geoSurf->
GetTitle());
2022 fGdmlE->NewAttr(mainN,
nullptr,
"name",
name.c_str());
2023 fGdmlE->NewAttr(mainN,
nullptr,
"surfaceproperty", prop.c_str());
2028 fGdmlE->NewAttr(childN,
nullptr,
"ref", physvolname);
2029 fGdmlE->AddChild(mainN, childN);
2031 childN =
fGdmlE->NewChild(
nullptr,
nullptr,
"physvolref",
nullptr);
2033 fGdmlE->NewAttr(childN,
nullptr,
"ref", physvolname);
2034 fGdmlE->AddChild(mainN, childN);
2045 fGdmlE->NewAttr(mainN,
nullptr,
"name",
name);
2049 fGdmlE->NewAttr(mainN,
nullptr,
"unit", unit);
2060 fGdmlE->NewAttr(mainN,
nullptr,
"name",
name);
2064 fGdmlE->NewAttr(mainN,
nullptr,
"unit", unit);
2073 std::stringstream vals;
2074 size_t cols = matrix->
GetCols();
2075 size_t rows = matrix->
GetRows();
2080 for (
size_t i = 0; i < rows; ++i) {
2081 for (
size_t j = 0; j < cols; ++j) {
2089 fGdmlE->NewAttr(mainN,
nullptr,
"values", vals.str().c_str());
2100 fGdmlE->NewAttr(mainN,
nullptr,
"name",
name);
2101 fGdmlE->NewAttr(mainN,
nullptr,
"coldim",
"1");
2112 fGdmlE->NewAttr(setupN,
nullptr,
"name",
name);
2113 fGdmlE->NewAttr(setupN,
nullptr,
"version", version);
2115 fGdmlE->NewAttr(fworldN,
nullptr,
"ref", topVolName);
2126 fGdmlE->NewAttr(mainN,
nullptr,
"name",
name);
2128 childN =
fGdmlE->NewChild(
nullptr,
nullptr,
"materialref",
nullptr);
2129 fGdmlE->NewAttr(childN,
nullptr,
"ref", material);
2130 fGdmlE->AddChild(mainN, childN);
2132 childN =
fGdmlE->NewChild(
nullptr,
nullptr,
"solidref",
nullptr);
2133 fGdmlE->NewAttr(childN,
nullptr,
"ref", solid);
2134 fGdmlE->AddChild(mainN, childN);
2145 fGdmlE->NewAttr(mainN,
nullptr,
"name",
name);
2159 fGdmlE->NewAttr(mainN,
nullptr,
"name",
name);
2162 childN =
fGdmlE->NewChild(
nullptr,
nullptr,
"volumeref",
nullptr);
2163 fGdmlE->NewAttr(childN,
nullptr,
"ref", volref);
2164 fGdmlE->AddChild(mainN, childN);
2166 childN =
fGdmlE->NewChild(
nullptr,
nullptr,
"positionref",
nullptr);
2167 fGdmlE->NewAttr(childN,
nullptr,
"ref", posref);
2168 fGdmlE->AddChild(mainN, childN);
2171 if (strcmp(rotref,
"") != 0) {
2172 childN =
fGdmlE->NewChild(
nullptr,
nullptr,
"rotationref",
nullptr);
2173 fGdmlE->NewAttr(childN,
nullptr,
"ref", rotref);
2174 fGdmlE->AddChild(mainN, childN);
2176 if (scaleN !=
nullptr) {
2177 fGdmlE->AddChild(mainN, scaleN);
2187 const char *unit,
const char *volref)
2191 fGdmlE->NewAttr(mainN,
nullptr,
"axis", axis);
2197 width = (floor(width * 1E4)) * 1E-4;
2198 if ((offset >= 0.) && (strcmp(axis,
"kPhi") == 0)) {
2200 Double_t decimals = offset - offsetI;
2202 offset = (offsetI % 360) + decimals - 360;
2208 fGdmlE->NewAttr(mainN,
nullptr,
"unit", unit);
2209 if (strcmp(volref,
"") != 0) {
2210 childN =
fGdmlE->NewChild(
nullptr,
nullptr,
"volumeref",
nullptr);
2211 fGdmlE->NewAttr(childN,
nullptr,
"ref", volref);
2213 fGdmlE->AddChild(mainN, childN);
2223 const char *clsname = geoShape->
ClassName();
2231 if (strcmp(clsname,
"TGeoBBox") == 0) {
2233 }
else if (strcmp(clsname,
"TGeoParaboloid") == 0) {
2235 }
else if (strcmp(clsname,
"TGeoSphere") == 0) {
2237 }
else if (strcmp(clsname,
"TGeoArb8") == 0) {
2239 }
else if (strcmp(clsname,
"TGeoConeSeg") == 0) {
2241 }
else if (strcmp(clsname,
"TGeoCone") == 0) {
2243 }
else if (strcmp(clsname,
"TGeoPara") == 0) {
2245 }
else if (strcmp(clsname,
"TGeoTrap") == 0) {
2247 }
else if (strcmp(clsname,
"TGeoGtra") == 0) {
2249 }
else if (strcmp(clsname,
"TGeoTrd1") == 0) {
2251 }
else if (strcmp(clsname,
"TGeoTrd2") == 0) {
2253 }
else if (strcmp(clsname,
"TGeoTubeSeg") == 0) {
2255 }
else if (strcmp(clsname,
"TGeoCtub") == 0) {
2257 }
else if (strcmp(clsname,
"TGeoTube") == 0) {
2259 }
else if (strcmp(clsname,
"TGeoPcon") == 0) {
2261 }
else if (strcmp(clsname,
"TGeoTorus") == 0) {
2263 }
else if (strcmp(clsname,
"TGeoPgon") == 0) {
2265 }
else if (strcmp(clsname,
"TGeoEltu") == 0) {
2267 }
else if (strcmp(clsname,
"TGeoHype") == 0) {
2269 }
else if (strcmp(clsname,
"TGeoXtru") == 0) {
2271 }
else if (strcmp(clsname,
"TGeoTessellated") == 0) {
2273 }
else if (strcmp(clsname,
"TGeoScaledShape") == 0) {
2275 }
else if (strcmp(clsname,
"TGeoCompositeShape") == 0) {
2277 }
else if (strcmp(clsname,
"TGeoUnion") == 0) {
2279 }
else if (strcmp(clsname,
"TGeoIntersection") == 0) {
2281 }
else if (strcmp(clsname,
"TGeoSubtraction") == 0) {
2284 Info(
"ChooseObject",
"ERROR! %s Solid CANNOT be processed, solid is NOT supported", clsname);
2287 if (solidN ==
nullptr) {
2310 if (cosb > 0.00001) {
2347 Double_t boxdx = 1E8 * (2 * rmax) + (2 * z);
2406 Bool_t isIN = list[name2check];
2434 TString fstLet = newname(0, 1);
2436 newname =
"O" + newname(1, newname.
Length());
2447 if (newname != oldname) {
2449 Info(
"GenName",
"WARNING! Name of the object was changed because it failed to comply with NCNAME xml datatype "
2452 Info(
"GenName",
"WARNING! Probably more names are going to be changed to comply with NCNAME xml datatype "
2453 "restriction, but it will not be displayed on the screen.");
2470 newname = newname + nameIter;
2489 return !(isProcessed);
2501 if (strcmp(pattName,
"TGeoPatternX") == 0) {
2503 }
else if (strcmp(pattName,
"TGeoPatternCylR") == 0) {
2508 if (strcmp(pattName,
"TGeoPatternY") == 0) {
2510 }
else if (strcmp(pattName,
"TGeoPatternCylPhi") == 0) {
2516 if (strcmp(pattName,
"TGeoPatternZ") == 0) {
2520 default:
return "kUndefined";
break;
2522 return "kUndefined";
2530 if (parValue == 0.) {
2531 Info(
"IsNullParam",
"ERROR! %s is NULL due to %s = %.12g, Volume based on this shape will be skipped",
2532 objName.
Data(), parName.
Data(), parValue);
2562 TList materials, volumes, nodes;
2563 MaterialExtractor extract;
2565 Info(
"WriteGDMLfile",
"Invalid Volume reference to extract GDML information!");
2576 WriteGDMLfile(geomanager, volume, &materials, filename, option);
2577 materials.
Clear(
"nodelete");
2578 volumes.
Clear(
"nodelete");
2579 nodes.
Clear(
"nodelete");
2594 Info(
"WriteGDMLfile",
"Geant4 compatibility mode set");
2600 Info(
"WriteGDMLfile",
"Fast naming convention with pointer suffix set");
2603 Info(
"WriteGDMLfile",
"Naming without prefix set - be careful uniqness of name is not ensured");
2606 Info(
"WriteGDMLfile",
"Potentially slow with incremental suffix naming convention set");
2610 Int_t outputLayout = 1;
2611 const char *krootNodeName =
"gdml";
2612 const char *knsRefGeneral =
"http://www.w3.org/2001/XMLSchema-instance";
2613 const char *knsNameGeneral =
"xsi";
2614 const char *knsRefGdml =
"http://service-spi.web.cern.ch/service-spi/app/releases/GDML/schema/gdml.xsd";
2615 const char *knsNameGdml =
"xsi:noNamespaceSchemaLocation";
2629 fGdmlE->NewNS(rootNode, knsRefGeneral, knsNameGeneral);
2630 fGdmlE->NewAttr(rootNode,
nullptr, knsNameGdml, knsRefGdml);
2668 time_t startT, endT;
2669 startT = time(
nullptr);
2674 Info(
"WriteGDMLfile",
"Extracting volumes");
2676 Info(
"WriteGDMLfile",
"%i solids added",
fSolCnt);
2677 Info(
"WriteGDMLfile",
"%i volumes added",
fVolCnt);
2682 endT = time(
nullptr);
2690 Double_t tdiffI = difftime(endT, startT);
2692 Info(
"WriteGDMLfile",
"Exporting time: %s", tdiffS.
Data());
2697 Info(
"WriteGDMLfile",
"File %s saved", filename);
2711 TString volname, matname, solname, pattClsName, nodeVolNameBak;
2735 if (solname ==
"-1") {
2736 Info(
"ExtractVolumes",
"ERROR! %s volume was not added, because solid is either not supported or corrupted",
2758 TIter next(nodeLst);
2763 while ((geoNode = (
TGeoNode *)next())) {
2773 if (nodevolname.
Contains(
"missing_")) {
2777 nodeVolNameBak = nodevolname;
2780 if (isPattern ==
kFALSE) {
2782 TString nodename, posname, rotname;
2784 nodename = nodename +
"in" + volname;
2787 posname = nodename +
"pos";
2808 scaleN =
fGdmlE->NewChild(
nullptr,
nullptr,
"scale",
nullptr);
2809 fGdmlE->NewAttr(scaleN,
nullptr,
"name", (nodename +
"scl").Data());
2826 if ((lxyz.
x != 0.0) || (lxyz.
y != 0.0) || (lxyz.
z != 0.0)) {
2827 rotname = nodename +
"rot";
2836 fGdmlE->AddChild(volumeN, childN);
2841 if (isPattern && pattFinder) {
2843 Int_t ndiv, divaxis;
2848 width = pattFinder->
GetStep();
2854 offset = pattFinder->
GetStart() - xlo;
2859 fGdmlE->AddChild(volumeN, childN);
int Int_t
Signed integer 4 bytes (int).
bool Bool_t
Boolean (0=false, 1=true) (bool).
double Double_t
Double 8 bytes.
externTGeoManager * gGeoManager
TRObject operator()(const T1 &t1) const
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
This class is used in the process of reading and writing the GDML "matrix" tag.
Double_t Get(size_t r, size_t c) const
This class contains implementation of converting ROOT's gGeoManager geometry to GDML file.
XMLNodePointer_t fSolidsNode
void UnsetTemporaryBits(TGeoManager *geoMng)
Unsetting bits that were changed in gGeoManager during export so that export can be run more times wi...
std::map< TString, Bool_t > NameList
XMLNodePointer_t CreateDivisionN(Double_t offset, Double_t width, Int_t number, const char *axis, const char *unit, const char *volref)
Creates "divisionvol" node for GDML.
static const UInt_t fgkProcBitVol
XMLNodePointer_t CreatePolyconeN(TGeoPcon *geoShape)
Creates "polycone" node for GDML.
XMLNodePointer_t CreateFractionN(Double_t percentage, const char *refName)
Creates "fraction" node for GDML.
void ExtractMatrices(TObjArray *matrices)
Method exporting GDML matrices.
XMLDocPointer_t fGdmlFile
void SetG4Compatibility(Bool_t G4Compatible)
XMLNodePointer_t CreateParaboloidN(TGeoParaboloid *geoShape)
Creates "paraboloid" node for GDML.
TGeoCompositeShape * CreateFakeCtub(TGeoCtub *geoShape)
Method creating cutTube as an intersection of tube and two boxes.
TGDMLWrite()
Default constructor.
Int_t fIgnoreDummyMaterial
XMLNodePointer_t CreateBoxN(TGeoBBox *geoShape)
Creates "box" node for GDML.
std::map< TString, Float_t > NameListF
XMLNodePointer_t CreateMaterialN(TGeoMaterial *material, TString mname)
Creates "material" node for GDML.
XMLNodePointer_t CreateSphereN(TGeoSphere *geoShape)
Creates "sphere" node for GDML.
XMLNodePointer_t CreateTwistedTrapN(TGeoGtra *geoShape)
Creates "twistedtrap" node for GDML.
XMLNodePointer_t CreateZplaneN(Double_t z, Double_t rmin, Double_t rmax)
Creates "zplane" node for GDML.
static const UInt_t fgkMaxNameErr
Bool_t IsNullParam(Double_t parValue, TString parName, TString objName)
Check for null parameter to skip the NULL objects.
static TGDMLWrite * fgGDMLWrite
TString ExtractSolid(TGeoShape *volShape)
Method creating solid to xml file and returning its name.
XMLNodePointer_t CreateHypeN(TGeoHype *geoShape)
Creates "hype" node for GDML.
XMLNodePointer_t CreateElConeN(TGeoScaledShape *geoShape)
Creates "elcone" (elliptical cone) node for GDML this is a special case, because elliptical cone is n...
XMLNodePointer_t CreateConstantN(const char *name, Double_t value)
Creates "constant" kind of node for GDML.
XMLNodePointer_t CreateMatrixN(TGDMLMatrix const *matrix)
Creates "matrix" kind of node for GDML.
XMLNodePointer_t CreateOpticalSurfaceN(TGeoOpticalSurface *geoSurf)
Creates "opticalsurface" node for GDML.
XMLNodePointer_t CreateMixtureN(TGeoMixture *mixture, XMLNodePointer_t materials, TString mname)
Creates "material" node for GDML with references to other sub elements.
std::map< TString, Int_t > NameListI
void ExtractBorderSurfaces(TObjArray *surfaces)
Method exporting border surfaces.
static const UInt_t fgkProcBit
Bool_t CanProcess(TObject *pointer)
Method which tests whether solids can be processed.
XMLNodePointer_t CreatePolyhedraN(TGeoPgon *geoShape)
Creates "polyhedra" node for GDML.
void WriteGDMLfile(TGeoManager *geomanager, const char *filename="test.gdml", TString option="")
XMLNodePointer_t CreateRotationN(const char *name, Xyz rotation, const char *type="rotation", const char *unit="deg")
Creates "rotation" kind of node for GDML.
XMLNodePointer_t CreatePropertyN(TNamed const &property)
Creates "property" node for GDML.
XMLNodePointer_t CreateElementN(TGeoElement *element, XMLNodePointer_t materials, const char *name)
Creates "element" node for GDML element node and attribute.
XMLNodePointer_t CreateConeN(TGeoConeSeg *geoShape)
Creates "cone" node for GDML from TGeoConeSeg object.
XMLNodePointer_t CreateSkinSurfaceN(TGeoSkinSurface *geoSurf)
Creates "skinsurface" node for GDML.
XMLNodePointer_t CreateTessellatedN(TGeoTessellated *geoShape)
Creates "tessellated" (tessellated shape) node for GDML.
XMLNodePointer_t CreateCutTubeN(TGeoCtub *geoShape)
Creates "cutTube" node for GDML.
XMLNodePointer_t fStructureNode
void ExtractSkinSurfaces(TObjArray *surfaces)
Method exporting skin surfaces.
XMLNodePointer_t fDefineNode
XMLNodePointer_t CreateTorusN(TGeoTorus *geoShape)
Creates "torus" node for GDML.
XMLNodePointer_t CreatePositionN(const char *name, Xyz position, const char *type, const char *unit)
Creates "position" kind of node for GDML.
XMLNodePointer_t ExtractMaterials(TList *materialsLst)
Method exporting materials.
XMLNodePointer_t fMaterialsNode
void ExtractOpticalSurfaces(TObjArray *surfaces)
Method exporting optical surfaces.
XMLNodePointer_t CreateDN(Double_t density, const char *unit="g/cm3")
Creates "D" density node for GDML.
void ExtractConstants(TGeoManager *geom)
Method exporting GDML matrices.
XMLNodePointer_t CreateArb8N(TGeoArb8 *geoShape)
Creates "arb8" node for GDML.
void SetFltPrecision(UInt_t prec)
XMLNodePointer_t StartVolumeN(const char *name, const char *solid, const char *material)
Creates "volume" node for GDML.
void SetNamingSpeed(ENamingType naming)
Set convention of naming solids and volumes.
TString GetPattAxis(Int_t divAxis, const char *pattName, TString &unit)
Method that retrieves axis and unit along which object is divided.
TString GenName(TString oldname)
NCNAME basic restrictions Replace "$" character with empty character etc.
XMLNodePointer_t CreateXtrusionN(TGeoXtru *geoShape)
Creates "xtru" node for GDML.
XMLNodePointer_t CreatePhysVolN(const char *name, Int_t copyno, const char *volref, const char *posref, const char *rotref, XMLNodePointer_t scaleN)
Creates "physvol" node for GDML.
Bool_t IsInList(NameList list, TString name2check)
Checks whether name2check is in (NameList) list.
XMLNodePointer_t StartAssemblyN(const char *name)
Creates "assembly" node for GDML.
void SetIgnoreDummyMaterial(bool value)
Ignore dummy material instance, which causes trouble reading GDML in Geant4.
~TGDMLWrite() override
Destructor.
XMLNodePointer_t CreateParaN(TGeoPara *geoShape)
Creates "para" node for GDML.
XMLNodePointer_t CreateSetupN(const char *topVolName, const char *name="default", const char *version="1.0")
Creates "setup" node for GDML.
XMLNodePointer_t CreateTrapN(TGeoTrap *geoShape)
Creates "trap" node for GDML.
Xyz GetXYZangles(const Double_t *rotationMatrix)
Retrieves X Y Z angles from rotation matrix.
UInt_t fFltPrecision
! floating point precision when writing
XMLNodePointer_t CreateTubeN(TGeoTubeSeg *geoShape)
Creates "tube" node for GDML from object TGeoTubeSeg.
XMLNodePointer_t CreateBorderSurfaceN(TGeoBorderSurface *geoSurf)
Creates "bordersurface" node for GDML.
XMLNodePointer_t CreateAtomN(Double_t atom, const char *unit="g/mole")
Creates "atom" node for GDML.
XMLNodePointer_t CreateEltubeN(TGeoEltu *geoShape)
Creates "eltube" node for GDML.
void ExtractVolumes(TGeoNode *topNode)
Method extracting geometry structure recursively.
XMLNodePointer_t CreateEllipsoidN(TGeoCompositeShape *geoShape, TString elName)
Creates "ellipsoid" node for GDML this is a special case, because ellipsoid is not defined in ROOT so...
XMLNodePointer_t CreateIsotopN(TGeoIsotope *isotope, const char *name)
Creates "isotope" node for GDML.
XMLNodePointer_t CreateCommonBoolN(TGeoCompositeShape *geoShape)
Creates common part of union intersection and subtraction nodes.
XMLNodePointer_t CreateTrdN(TGeoTrd1 *geoShape)
Creates "trd" node for GDML from object TGeoTrd1.
XMLNodePointer_t CreateScaledN(TGeoScaledShape *geoShape)
Creates a scaled node for GDML.
XMLNodePointer_t ChooseObject(TGeoShape *geoShape)
Chooses the object and method that should be used for processing object.
Bool_t TestAttBit(UInt_t f) const
virtual const Double_t * GetOrigin() const
virtual Double_t GetDX() const
virtual Double_t GetDZ() const
virtual Double_t GetDY() const
virtual EGeoBoolType GetBooleanOperator() const =0
TGeoMatrix * GetRightMatrix() const
TGeoShape * GetLeftShape() const
TGeoMatrix * GetLeftMatrix() const
TGeoShape * GetRightShape() const
TGeoNode const * GetNode2() const
TGeoOpticalSurface const * GetSurface() const
TGeoNode const * GetNode1() const
Class describing rotation + translation.
Composite shapes are Boolean combinations of two or more shape components.
TGeoBoolNode * GetBoolNode() const
virtual Double_t GetRmax2() const
virtual Double_t GetDz() const
virtual Double_t GetRmin2() const
virtual Double_t GetRmin1() const
virtual Double_t GetRmax1() const
const Double_t * GetNlow() const
const Double_t * GetNhigh() const
Base class for chemical elements.
Int_t GetNisotopes() const
Bool_t HasIsotopes() const
Double_t GetRelativeAbundance(Int_t i) const
Return relative abundance of i-th isotope in this element.
TGeoIsotope * GetIsotope(Int_t i) const
Return i-th isotope in the element.
virtual Double_t GetA() const
virtual Double_t GetB() const
Double_t GetTwistAngle() const
const Double_t * GetRotationMatrix() const override
Double_t GetStOut() const
Boolean node representing an intersection between two components.
an isotope defined by the atomic number, number of nucleons and atomic weight (g/mole)
The manager class for any TGeo geometry.
TObjArray * GetListOfVolumes() const
TObjArray * GetListOfSkinSurfaces() const
TObjArray * GetListOfGDMLMatrices() const
Int_t GetNproperties() const
TObjArray * GetListOfBorderSurfaces() const
TGeoNode * GetTopNode() const
Double_t GetProperty(const char *name, Bool_t *error=nullptr) const
Get a user-defined property.
static UInt_t GetExportPrecision()
TObjArray * GetListOfOpticalSurfaces() const
TList * GetListOfMaterials() const
Base class describing materials.
virtual Bool_t IsMixture() const
TList const & GetConstProperties() const
TList const & GetProperties() const
virtual Double_t GetA() const
virtual Double_t GetDensity() const
virtual Double_t GetZ() const
Geometrical transformation package.
virtual const Double_t * GetTranslation() const =0
Bool_t IsReflection() const
virtual const Double_t * GetRotationMatrix() const =0
virtual TGeoHMatrix Inverse() const =0
Media are used to store properties related to tracking and which are useful only when using geometry ...
TGeoMaterial * GetMaterial() const
Int_t GetNelements() const override
Double_t * GetWmixt() const
TGeoElement * GetElement(Int_t i=0) const override
Retrieve the pointer to the element corresponding to component I.
A node represent a volume positioned inside another.They store links to both volumes and to the TGeoM...
TGeoVolume * GetVolume() const
virtual TGeoMatrix * GetMatrix() const =0
This is a wrapper class to G4OpticalSurface.
TList const & GetProperties() const
static const char * ModelToString(ESurfaceModel model)
static const char * TypeToString(ESurfaceType type)
ESurfaceModel GetModel() const
TList const & GetConstProperties() const
ESurfaceFinish GetFinish() const
static const char * FinishToString(ESurfaceFinish finish)
Double_t GetValue() const
ESurfaceType GetType() const
Double_t GetAlpha() const
Double_t GetTheta() const
A paraboloid is defined by the revolution surface generated by a parabola and is bounded by two plane...
base finder class for patterns. A pattern is specifying a division type
virtual Int_t GetDivAxis()
Double_t GetStart() const
Double_t * GetRmax() const
Double_t * GetRmin() const
Reference counted extension which has a pointer to and owns a user defined TObject.
TObject * GetUserObject() const
Class describing rotations.
void SetAngles(Double_t phi, Double_t theta, Double_t psi)
Set matrix elements according to Euler angles.
const Double_t * GetScale() const override
A shape scaled by a TGeoScale transformation.
TGeoShape * GetShape() const
TGeoScale * GetScale() const
Base abstract class for all shapes.
virtual Double_t GetAxisRange(Int_t iaxis, Double_t &xlo, Double_t &xhi) const =0
const char * GetName() const override
Get the shape name.
TGeoVolume const * GetVolume() const
TGeoOpticalSurface const * GetSurface() const
virtual Double_t GetRmin() const
Double_t GetTheta2() const
virtual Double_t GetRmax() const
Double_t GetTheta1() const
const TGeoFacet & GetFacet(int i) const
const Vertex_t & GetVertex(int i) const
Class describing translations.
Double_t GetAlpha2() const
Double_t GetTheta() const
Double_t GetAlpha1() const
virtual Double_t GetRmin() const
virtual Double_t GetDz() const
virtual Double_t GetRmax() const
TGeoVolume, TGeoVolumeMulti, TGeoVolumeAssembly are the volume classes.
TGeoExtension * GetUserExtension() const
TGeoMaterial * GetMaterial() const
TGeoPatternFinder * GetFinder() const
static TGeoMedium * DummyMedium()
TGeoShape * GetShape() const
virtual Bool_t IsAssembly() const
Returns true if the volume is an assembly or a scaled assembly.
A TGeoXtru shape is represented by the extrusion of an arbitrary polygon with fixed outline between s...
Double_t GetYOffset(Int_t i) const
Double_t GetY(Int_t i) const
Double_t GetScale(Int_t i) const
Double_t GetXOffset(Int_t i) const
Double_t GetX(Int_t i) const
Iterator abstract base class.
virtual TObject * Next()=0
void Clear(Option_t *option="") override
Remove all objects from the list.
void Add(TObject *obj) override
TMap implements an associative array of (key,value) pairs using a THashTable for efficient retrieval ...
TIterator * MakeIterator(Bool_t dir=kIterForward) const override
Create an iterator for TMap.
TObject * GetValue(const char *keyname) const
Returns a pointer to the value associated with keyname as name of the key.
The TNamed class is the base class for all named ROOT classes.
const char * GetName() const override
Returns name of object.
const char * GetTitle() const override
Returns title of object.
Int_t GetEntriesFast() const
Collectable string class.
const TString & GetString() const
Bool_t TestBit(UInt_t f) const
virtual const char * ClassName() const
Returns name of class to which the object belongs.
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
TObject()
TObject constructor.
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
void ToLower()
Change string to lower-case.
const char * Data() const
Bool_t IsDigit() const
Returns true if all characters in string are digits (0-9) or white spaces, i.e.
TString & ReplaceAll(const TString &s1, const TString &s2)
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Double_t ACos(Double_t)
Returns the principal value of the arc cosine of x, expressed in radians.
Double_t ATan2(Double_t y, Double_t x)
Returns the principal value of the arc tangent of y/x, expressed in radians.
constexpr Double_t DegToRad()
Conversion from degree to radian: .
Double_t Sqrt(Double_t x)
Returns the square root of x.
Double_t Cos(Double_t)
Returns the cosine of an angle of x radians.
Double_t Sin(Double_t)
Returns the sine of an angle of x radians.
constexpr Double_t RadToDeg()
Conversion from radian to degree: .
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.