From 30ef55c89d9df87cff1836c31535d75f5695f07a Mon Sep 17 00:00:00 2001 From: Kolja Date: Sun, 9 Nov 2025 11:32:48 +0000 Subject: [PATCH] [Geom] Add auxiliary user-data export in TGDMLWrite This adds the option of exporting auxiliary of TGeoVolumes in TGDMLWrite Fixes #20356 --- geom/gdml/src/TGDMLWrite.cxx | 38 ++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/geom/gdml/src/TGDMLWrite.cxx b/geom/gdml/src/TGDMLWrite.cxx index 08915d5ed80ba..cca1691544ea2 100644 --- a/geom/gdml/src/TGDMLWrite.cxx +++ b/geom/gdml/src/TGDMLWrite.cxx @@ -156,7 +156,10 @@ See that function for details. #include "TGeoElement.h" #include "TGeoShape.h" #include "TGeoCompositeShape.h" +#include "TGeoExtension.h" #include "TGeoOpticalSurface.h" +#include "TMap.h" +#include "TObjString.h" #include #include #include @@ -758,6 +761,41 @@ void TGDMLWrite::ExtractVolumes(TGeoNode *node) fGdmlE->AddChild(volumeN, childN); } + // export auxiliary user-data if present (TMap of TObjString->TObjString) + { + TGeoRCExtension *rcext = (TGeoRCExtension *)volume->GetUserExtension(); + if (rcext) { + TMap *auxmap = nullptr; + TObject *userObj = rcext->GetUserObject(); + if (userObj && userObj->InheritsFrom("TMap")) { + TMap *auxmap = (TMap *)userObj; + TIterator *it = auxmap->MakeIterator(); + TObject *k = nullptr; + while (k = it->Next()) { + TObject *valobj = auxmap->GetValue(k); + if (!valobj || !k->InheritsFrom("TObjString") || !valobj->InheritsFrom("TObjString")) + continue; + TObjString *key = (TObjString *)k; + TObjString *val = (TObjString *)valobj; + TString auxtype = key->GetString(); + TString auxvalue = val->GetString(); + TString auxunit = ""; + Int_t pos = auxvalue.Index('*'); + if (pos >= 0) { + auxunit = auxvalue(pos + 1, auxvalue.Length()); + auxvalue = auxvalue(0, pos); + } + XMLNodePointer_t auxN = fGdmlE->NewChild(nullptr, nullptr, "auxiliary", nullptr); + fGdmlE->NewAttr(auxN, nullptr, "auxtype", auxtype.Data()); + fGdmlE->NewAttr(auxN, nullptr, "auxvalue", auxvalue.Data()); + if (!auxunit.IsNull()) + fGdmlE->NewAttr(auxN, nullptr, "auxunit", auxunit.Data()); + fGdmlE->AddChild(volumeN, auxN); + } + } + } + } + fVolCnt++; // add volume/assembly node into the node fGdmlE->AddChild(fStructureNode, volumeN);