diff --git a/geom/gdml/inc/TGDMLWrite.h b/geom/gdml/inc/TGDMLWrite.h index 4210b208d4358..b8cafe6e1865d 100644 --- a/geom/gdml/inc/TGDMLWrite.h +++ b/geom/gdml/inc/TGDMLWrite.h @@ -126,6 +126,7 @@ class TGDMLWrite : public TObject { XMLDocPointer_t fGdmlFile; //pointer storing xml file TString fDefault_lunit; //Default unit of length (depends on ROOT unit system) TString fTopVolumeName; //name of top volume + TGeoVolume *fTopVolume = nullptr; //top volume of the tree being written TXMLEngine *fGdmlE; //xml engine pointer XMLNodePointer_t fDefineNode; //main node... diff --git a/geom/gdml/src/TGDMLParse.cxx b/geom/gdml/src/TGDMLParse.cxx index dce3c50b1d01d..9a41e06673a40 100644 --- a/geom/gdml/src/TGDMLParse.cxx +++ b/geom/gdml/src/TGDMLParse.cxx @@ -1681,6 +1681,8 @@ TGeoTranslation *TGDMLParse::GetPosition(const char *name) if (!pos && fposmap.find(name) != fposmap.end()) pos = fposmap[name]; + if (!pos) + Error("GetPosition", "Position %s not defined", name); return pos; } @@ -1698,6 +1700,8 @@ TGeoRotation *TGDMLParse::GetRotation(const char *name) if (!rot && frotmap.find(name) != frotmap.end()) rot = frotmap[name]; + if (!rot) + Error("GetRotation", "Rotation %s not defined", name); return rot; } @@ -1715,6 +1719,8 @@ TGeoScale *TGDMLParse::GetScaleObj(const char *name) if (!scl && fsclmap.find(name) != fsclmap.end()) scl = fsclmap[name]; + if (!scl) + Error("GetScale", "Scale %s not defined", name); return scl; } @@ -1732,6 +1738,8 @@ TGeoShape *TGDMLParse::GetSolid(const char *name) if (!sol && fsolmap.find(name) != fsolmap.end()) sol = fsolmap[name]; + if (!sol) + Error("GetSolid", "Solid %s not defined", name); return sol; } @@ -1749,6 +1757,8 @@ TGeoVolume *TGDMLParse::GetVolume(const char *name) if (!vol && fvolmap.find(name) != fvolmap.end()) vol = fvolmap[name]; + if (!vol) + Error("GetVolume", "Volume %s not defined", name); return vol; } diff --git a/geom/gdml/src/TGDMLWrite.cxx b/geom/gdml/src/TGDMLWrite.cxx index dcbfbdd570912..b18089b0868f2 100644 --- a/geom/gdml/src/TGDMLWrite.cxx +++ b/geom/gdml/src/TGDMLWrite.cxx @@ -240,7 +240,8 @@ void TGDMLWrite::WriteGDMLfile(TGeoManager * geomanager, const char* filename, T Info("WriteGDMLfile", "Top volume does not exist!"); return; } - fTopVolumeName = ""; + fTopVolume = node->GetVolume(); + fTopVolumeName = fTopVolume->GetName(); WriteGDMLfile(geomanager, node, materials, filename, option); } @@ -259,6 +260,7 @@ void TGDMLWrite::WriteGDMLfile(TGeoManager * geomanager, TGeoNode* node, const c for(TGeoMaterial* m : extract.materials) materials.Add(m); fTopVolumeName = volume->GetName(); + fTopVolume = volume; fSurfaceList.clear(); fVolumeList.clear(); fNodeList.clear(); @@ -569,7 +571,7 @@ void TGDMLWrite::ExtractVolumes(TGeoNode* node) fNodeList.insert(node); fVolumeList.insert(volume); //create the name for volume/assembly - if (volume->IsTopVolume()) { + if (volume == fTopVolume) { //not needed a special function for generating name volname = volume->GetName(); fTopVolumeName = volname; @@ -2432,6 +2434,7 @@ void TGDMLWrite::WriteGDMLfile(TGeoManager * geomanager, TGeoVolume* volume, con for(TGeoMaterial* m : extract.materials) materials.Add(m); fTopVolumeName = volume->GetName(); + fTopVolume = volume; fSurfaceList.clear(); fVolumeList.clear(); fNodeList.clear(); @@ -2583,7 +2586,7 @@ void TGDMLWrite::ExtractVolumes(TGeoVolume* volume) const TString fltPrecision = TString::Format("%%.%dg", fFltPrecision); //create the name for volume/assembly - if (volume->IsTopVolume()) { + if (volume == fTopVolume) { //not needed a special function for generating name volname = volume->GetName(); fTopVolumeName = volname; diff --git a/geom/geom/src/TGeoManager.cxx b/geom/geom/src/TGeoManager.cxx index 384f9f1c9c745..e92fc67212183 100644 --- a/geom/geom/src/TGeoManager.cxx +++ b/geom/geom/src/TGeoManager.cxx @@ -3820,13 +3820,13 @@ TGeoManager *TGeoManager::Import(const char *filename, const char *name, Option_ { if (fgLock) { ::Warning("TGeoManager::Import", "TGeoMananager in lock mode. NOT IMPORTING new geometry"); - return NULL; + return nullptr; } if (!filename) return 0; if (fgVerboseLevel>0) ::Info("TGeoManager::Import","Reading geometry from file: %s",filename); if (gGeoManager) delete gGeoManager; - gGeoManager = 0; + gGeoManager = nullptr; if (strstr(filename,".gdml")) { // import from a gdml file @@ -3834,8 +3834,10 @@ TGeoManager *TGeoManager::Import(const char *filename, const char *name, Option_ TString cmd = TString::Format("TGDMLParse::StartGDML(\"%s\")", filename); TGeoVolume* world = (TGeoVolume*)gROOT->ProcessLineFast(cmd); - if(world == 0) { - ::Error("TGeoManager::Import", "Cannot open file"); + if(world == nullptr) { + delete gGeoManager; + gGeoManager = nullptr; + ::Error("TGeoManager::Import", "Cannot read file %s", filename); } else { gGeoManager->SetTopVolume(world); @@ -3847,12 +3849,12 @@ TGeoManager *TGeoManager::Import(const char *filename, const char *name, Option_ TDirectory::TContext ctxt; // in case a web file is specified, use the cacheread option to cache // this file in the cache directory - TFile *f = 0; + TFile *f = nullptr; if (strstr(filename,"http")) f = TFile::Open(filename,"CACHEREAD"); else f = TFile::Open(filename); if (!f || f->IsZombie()) { ::Error("TGeoManager::Import", "Cannot open file"); - return 0; + return nullptr; } if (name && strlen(name) > 0) { gGeoManager = (TGeoManager*)f->Get(name); diff --git a/geom/geom/src/TGeoMatrix.cxx b/geom/geom/src/TGeoMatrix.cxx index 6a34ed9362129..cb196b48b656d 100644 --- a/geom/geom/src/TGeoMatrix.cxx +++ b/geom/geom/src/TGeoMatrix.cxx @@ -683,6 +683,7 @@ TGeoHMatrix TGeoTranslation::Inverse() const { TGeoHMatrix h; h = *this; + h.ResetBit(kGeoRegistered); Double_t tr[3]; tr[0] = -fTranslation[0]; tr[1] = -fTranslation[1]; @@ -977,6 +978,7 @@ TGeoHMatrix TGeoRotation::Inverse() const { TGeoHMatrix h; h = *this; + h.ResetBit(kGeoRegistered); Double_t newrot[9]; newrot[0] = fRotationMatrix[0]; newrot[1] = fRotationMatrix[3]; @@ -1527,6 +1529,7 @@ TGeoHMatrix TGeoScale::Inverse() const { TGeoHMatrix h; h = *this; + h.ResetBit(kGeoRegistered); Double_t scale[3]; scale[0] = 1./fScale[0]; scale[1] = 1./fScale[1]; @@ -1826,6 +1829,7 @@ TGeoHMatrix TGeoCombiTrans::Inverse() const { TGeoHMatrix h; h = *this; + h.ResetBit(kGeoRegistered); Bool_t is_tr = IsTranslation(); Bool_t is_rot = IsRotation(); Double_t tr[3]; @@ -2232,6 +2236,7 @@ void TGeoGenTrans::SetScale(Double_t sx, Double_t sy, Double_t sz) TGeoHMatrix TGeoGenTrans::Inverse() const { TGeoHMatrix h = *this; + h.ResetBit(kGeoRegistered); return h; } @@ -2458,6 +2463,7 @@ TGeoHMatrix TGeoHMatrix::Inverse() const { TGeoHMatrix h; h = *this; + h.ResetBit(kGeoRegistered); if (IsTranslation()) { Double_t tr[3]; tr[0] = -fTranslation[0]*fRotationMatrix[0] - fTranslation[1]*fRotationMatrix[3] - fTranslation[2]*fRotationMatrix[6];