Skip to content

Commit 2a00482

Browse files
authored
GDML fixes (root-project#10044)
* Emit error messages when parsing undefined gdml names. * Correct handling when written gdml node not matching top one. * Cleaning TGeoManager instance in case of gdml import failure. * Correctly mark inverse transformations as not registered.
1 parent 6cf3303 commit 2a00482

File tree

5 files changed

+31
-9
lines changed

5 files changed

+31
-9
lines changed

geom/gdml/inc/TGDMLWrite.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ class TGDMLWrite : public TObject {
126126
XMLDocPointer_t fGdmlFile; //pointer storing xml file
127127
TString fDefault_lunit; //Default unit of length (depends on ROOT unit system)
128128
TString fTopVolumeName; //name of top volume
129+
TGeoVolume *fTopVolume = nullptr; //top volume of the tree being written
129130
TXMLEngine *fGdmlE; //xml engine pointer
130131

131132
XMLNodePointer_t fDefineNode; //main <define> node...

geom/gdml/src/TGDMLParse.cxx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,6 +1681,8 @@ TGeoTranslation *TGDMLParse::GetPosition(const char *name)
16811681
if (!pos && fposmap.find(name) != fposmap.end())
16821682
pos = fposmap[name];
16831683

1684+
if (!pos)
1685+
Error("GetPosition", "Position %s not defined", name);
16841686
return pos;
16851687
}
16861688

@@ -1698,6 +1700,8 @@ TGeoRotation *TGDMLParse::GetRotation(const char *name)
16981700
if (!rot && frotmap.find(name) != frotmap.end())
16991701
rot = frotmap[name];
17001702

1703+
if (!rot)
1704+
Error("GetRotation", "Rotation %s not defined", name);
17011705
return rot;
17021706
}
17031707

@@ -1715,6 +1719,8 @@ TGeoScale *TGDMLParse::GetScaleObj(const char *name)
17151719
if (!scl && fsclmap.find(name) != fsclmap.end())
17161720
scl = fsclmap[name];
17171721

1722+
if (!scl)
1723+
Error("GetScale", "Scale %s not defined", name);
17181724
return scl;
17191725
}
17201726

@@ -1732,6 +1738,8 @@ TGeoShape *TGDMLParse::GetSolid(const char *name)
17321738
if (!sol && fsolmap.find(name) != fsolmap.end())
17331739
sol = fsolmap[name];
17341740

1741+
if (!sol)
1742+
Error("GetSolid", "Solid %s not defined", name);
17351743
return sol;
17361744
}
17371745

@@ -1749,6 +1757,8 @@ TGeoVolume *TGDMLParse::GetVolume(const char *name)
17491757
if (!vol && fvolmap.find(name) != fvolmap.end())
17501758
vol = fvolmap[name];
17511759

1760+
if (!vol)
1761+
Error("GetVolume", "Volume %s not defined", name);
17521762
return vol;
17531763
}
17541764

geom/gdml/src/TGDMLWrite.cxx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,8 @@ void TGDMLWrite::WriteGDMLfile(TGeoManager * geomanager, const char* filename, T
240240
Info("WriteGDMLfile", "Top volume does not exist!");
241241
return;
242242
}
243-
fTopVolumeName = "";
243+
fTopVolume = node->GetVolume();
244+
fTopVolumeName = fTopVolume->GetName();
244245
WriteGDMLfile(geomanager, node, materials, filename, option);
245246
}
246247

@@ -259,6 +260,7 @@ void TGDMLWrite::WriteGDMLfile(TGeoManager * geomanager, TGeoNode* node, const c
259260
for(TGeoMaterial* m : extract.materials)
260261
materials.Add(m);
261262
fTopVolumeName = volume->GetName();
263+
fTopVolume = volume;
262264
fSurfaceList.clear();
263265
fVolumeList.clear();
264266
fNodeList.clear();
@@ -569,7 +571,7 @@ void TGDMLWrite::ExtractVolumes(TGeoNode* node)
569571
fNodeList.insert(node);
570572
fVolumeList.insert(volume);
571573
//create the name for volume/assembly
572-
if (volume->IsTopVolume()) {
574+
if (volume == fTopVolume) {
573575
//not needed a special function for generating name
574576
volname = volume->GetName();
575577
fTopVolumeName = volname;
@@ -2432,6 +2434,7 @@ void TGDMLWrite::WriteGDMLfile(TGeoManager * geomanager, TGeoVolume* volume, con
24322434
for(TGeoMaterial* m : extract.materials)
24332435
materials.Add(m);
24342436
fTopVolumeName = volume->GetName();
2437+
fTopVolume = volume;
24352438
fSurfaceList.clear();
24362439
fVolumeList.clear();
24372440
fNodeList.clear();
@@ -2583,7 +2586,7 @@ void TGDMLWrite::ExtractVolumes(TGeoVolume* volume)
25832586
const TString fltPrecision = TString::Format("%%.%dg", fFltPrecision);
25842587

25852588
//create the name for volume/assembly
2586-
if (volume->IsTopVolume()) {
2589+
if (volume == fTopVolume) {
25872590
//not needed a special function for generating name
25882591
volname = volume->GetName();
25892592
fTopVolumeName = volname;

geom/geom/src/TGeoManager.cxx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3820,22 +3820,24 @@ TGeoManager *TGeoManager::Import(const char *filename, const char *name, Option_
38203820
{
38213821
if (fgLock) {
38223822
::Warning("TGeoManager::Import", "TGeoMananager in lock mode. NOT IMPORTING new geometry");
3823-
return NULL;
3823+
return nullptr;
38243824
}
38253825
if (!filename) return 0;
38263826
if (fgVerboseLevel>0) ::Info("TGeoManager::Import","Reading geometry from file: %s",filename);
38273827

38283828
if (gGeoManager) delete gGeoManager;
3829-
gGeoManager = 0;
3829+
gGeoManager = nullptr;
38303830

38313831
if (strstr(filename,".gdml")) {
38323832
// import from a gdml file
38333833
new TGeoManager("GDMLImport", "Geometry imported from GDML");
38343834
TString cmd = TString::Format("TGDMLParse::StartGDML(\"%s\")", filename);
38353835
TGeoVolume* world = (TGeoVolume*)gROOT->ProcessLineFast(cmd);
38363836

3837-
if(world == 0) {
3838-
::Error("TGeoManager::Import", "Cannot open file");
3837+
if(world == nullptr) {
3838+
delete gGeoManager;
3839+
gGeoManager = nullptr;
3840+
::Error("TGeoManager::Import", "Cannot read file %s", filename);
38393841
}
38403842
else {
38413843
gGeoManager->SetTopVolume(world);
@@ -3847,12 +3849,12 @@ TGeoManager *TGeoManager::Import(const char *filename, const char *name, Option_
38473849
TDirectory::TContext ctxt;
38483850
// in case a web file is specified, use the cacheread option to cache
38493851
// this file in the cache directory
3850-
TFile *f = 0;
3852+
TFile *f = nullptr;
38513853
if (strstr(filename,"http")) f = TFile::Open(filename,"CACHEREAD");
38523854
else f = TFile::Open(filename);
38533855
if (!f || f->IsZombie()) {
38543856
::Error("TGeoManager::Import", "Cannot open file");
3855-
return 0;
3857+
return nullptr;
38563858
}
38573859
if (name && strlen(name) > 0) {
38583860
gGeoManager = (TGeoManager*)f->Get(name);

geom/geom/src/TGeoMatrix.cxx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,7 @@ TGeoHMatrix TGeoTranslation::Inverse() const
683683
{
684684
TGeoHMatrix h;
685685
h = *this;
686+
h.ResetBit(kGeoRegistered);
686687
Double_t tr[3];
687688
tr[0] = -fTranslation[0];
688689
tr[1] = -fTranslation[1];
@@ -977,6 +978,7 @@ TGeoHMatrix TGeoRotation::Inverse() const
977978
{
978979
TGeoHMatrix h;
979980
h = *this;
981+
h.ResetBit(kGeoRegistered);
980982
Double_t newrot[9];
981983
newrot[0] = fRotationMatrix[0];
982984
newrot[1] = fRotationMatrix[3];
@@ -1527,6 +1529,7 @@ TGeoHMatrix TGeoScale::Inverse() const
15271529
{
15281530
TGeoHMatrix h;
15291531
h = *this;
1532+
h.ResetBit(kGeoRegistered);
15301533
Double_t scale[3];
15311534
scale[0] = 1./fScale[0];
15321535
scale[1] = 1./fScale[1];
@@ -1826,6 +1829,7 @@ TGeoHMatrix TGeoCombiTrans::Inverse() const
18261829
{
18271830
TGeoHMatrix h;
18281831
h = *this;
1832+
h.ResetBit(kGeoRegistered);
18291833
Bool_t is_tr = IsTranslation();
18301834
Bool_t is_rot = IsRotation();
18311835
Double_t tr[3];
@@ -2232,6 +2236,7 @@ void TGeoGenTrans::SetScale(Double_t sx, Double_t sy, Double_t sz)
22322236
TGeoHMatrix TGeoGenTrans::Inverse() const
22332237
{
22342238
TGeoHMatrix h = *this;
2239+
h.ResetBit(kGeoRegistered);
22352240
return h;
22362241
}
22372242

@@ -2458,6 +2463,7 @@ TGeoHMatrix TGeoHMatrix::Inverse() const
24582463
{
24592464
TGeoHMatrix h;
24602465
h = *this;
2466+
h.ResetBit(kGeoRegistered);
24612467
if (IsTranslation()) {
24622468
Double_t tr[3];
24632469
tr[0] = -fTranslation[0]*fRotationMatrix[0] - fTranslation[1]*fRotationMatrix[3] - fTranslation[2]*fRotationMatrix[6];

0 commit comments

Comments
 (0)