From 764cdf4e51390ebed7677f238fae133d42f0bb4e Mon Sep 17 00:00:00 2001 From: Andreas Suter Date: Fri, 4 Apr 2025 16:58:57 +0200 Subject: [PATCH] start implementing TDirectoryFile instead of TFolder, since TFolder is depricated. First I added the necessary parts on the validator. The read/write are still missing. --- src/musrRootValidation.cpp | 80 ++++++++++++++++++++++++++------------ 1 file changed, 55 insertions(+), 25 deletions(-) diff --git a/src/musrRootValidation.cpp b/src/musrRootValidation.cpp index fcc0b23f..5d214bfa 100644 --- a/src/musrRootValidation.cpp +++ b/src/musrRootValidation.cpp @@ -39,7 +39,9 @@ #include "TString.h" #include "TFile.h" #include "TFolder.h" +#include "TDirectoryFile.h" #include "TKey.h" +#include "TList.h" #include "TObjArray.h" #include "TObjString.h" #include "TSystemFile.h" @@ -73,7 +75,7 @@ class PMusrRoot2Xml virtual UInt_t GetNoOfDetectors() { return fNoOfDetectors; } private: - enum EFolderTag {eUnkown, eDecayAnaModule, eSlowControlAnaModule}; + enum fNodeTag {eUnkown, eDecayAnaModule, eSlowControlAnaModule}; std::vector fXmlData; ///< keeps the XML structure dump of the ROOT file @@ -82,14 +84,15 @@ class PMusrRoot2Xml Bool_t fValid; ///< true if the conversion was fine TString fFileName; ///< file name of the ROOT file TString fXmlDumpFileName; ///< file name of the XML dump file - EFolderTag fFolderTag; ///< switch indicating which kind of TFolder object is found + fNodeTag fNodeTag; ///< switch indicating which kind of TFolder or TDirectoryFile object is found - UInt_t fNoOfDecayHistos; ///< number of decay histos in the DecayAnaModule - UInt_t fNoOfHistos; ///< number of histos from run header - UInt_t fNoOfRedGreenOffsets; ///< number of RedGreen offsets - UInt_t fNoOfDetectors; ///< number of detector entries in the header + UInt_t fNoOfDecayHistos{0}; ///< number of decay histos in the DecayAnaModule + UInt_t fNoOfHistos{0}; ///< number of histos from run header + UInt_t fNoOfRedGreenOffsets{0}; ///< number of RedGreen offsets + UInt_t fNoOfDetectors{0}; ///< number of detector entries in the header virtual void SortHistoFolders(); + virtual void DumpDirectory(TDirectoryFile *dir, UInt_t offset); virtual void DumpFolder(TFolder *folder, UInt_t offset); virtual void DumpObjArray(TObjArray *obj, UInt_t offset); virtual void DumpEntry(TObject *obj, UInt_t offset); @@ -105,13 +108,9 @@ class PMusrRoot2Xml PMusrRoot2Xml::PMusrRoot2Xml(const char *fileName, bool quiet, bool keep) : fQuiet(quiet), fKeep(keep), fFileName(fileName) { fXmlDumpFileName = "__MusrRootXmlDump.xml"; - fFolderTag = eUnkown; + fNodeTag = eUnkown; fValid = false; fXmlData.clear(); - fNoOfDecayHistos = 0; - fNoOfHistos = 0; - fNoOfRedGreenOffsets = 0; - fNoOfDetectors = 0; // read assumed MusrRoot file TFile f(fFileName.Data()); @@ -127,7 +126,8 @@ PMusrRoot2Xml::PMusrRoot2Xml(const char *fileName, bool quiet, bool keep) : fQui TIter next = f.GetListOfKeys(); TKey *key; TFolder *folder; - TString str, tag; + TDirectoryFile *dir; + TString str; UInt_t offset = 2; @@ -137,6 +137,9 @@ PMusrRoot2Xml::PMusrRoot2Xml(const char *fileName, bool quiet, bool keep) : fQui if (str == "TFolder") { folder = dynamic_cast(key->ReadObj()); CheckClass(folder, str, offset); + } else if (str == "TDirectoryFile") { + dir = dynamic_cast(key->ReadObj()); + CheckClass(dir, str, offset); } } if (!fQuiet) std::cout << std::endl; @@ -226,6 +229,30 @@ void PMusrRoot2Xml::SortHistoFolders() temp_xml_data.clear(); } +//----------------------------------------------------------------------- +/** + *

Dump TDirectoryFile structure. + * + * \param dir TDirectoryFile object found in the ROOT file + * \param offset needed to indent dump info + */ +void PMusrRoot2Xml::DumpDirectory(TDirectoryFile *dir, UInt_t offset) +{ + TString offsetStr=""; + for (UInt_t i=0; iGetListOfKeys(); + TString str; + TObject *oo; + for (TObject *obj: *ll) { + oo = static_cast(obj)->ReadObj(); + if (!fQuiet) std::cout << std::endl << offsetStr << "name: " << oo->GetName() << ", class name: " << oo->ClassName(); + str = oo->ClassName(); + CheckClass(oo, str, offset); + } +} + //----------------------------------------------------------------------- /** *

Dump folder structure. @@ -343,7 +370,7 @@ void PMusrRoot2Xml::DumpEntry(TObject *obj, UInt_t offset) offsetStr += " "; TString nameTag(""), typeTag(""); - switch (fFolderTag) { + switch (fNodeTag) { case eDecayAnaModule: nameTag = "HistoName"; typeTag = "HistoType"; @@ -359,7 +386,7 @@ void PMusrRoot2Xml::DumpEntry(TObject *obj, UInt_t offset) break; } - if (fFolderTag == eDecayAnaModule) + if (fNodeTag == eDecayAnaModule) fNoOfDecayHistos++; TString str; @@ -389,34 +416,37 @@ void PMusrRoot2Xml::CheckClass(TObject *obj, TString str, UInt_t offset) for (UInt_t i=0; iGetName())); // set folder tag if (!xmlTagName.CompareTo("DecayAnaModule")) - fFolderTag = eDecayAnaModule; + fNodeTag = eDecayAnaModule; else if (!xmlTagName.CompareTo("SCAnaModule")) - fFolderTag = eSlowControlAnaModule; + fNodeTag = eSlowControlAnaModule; else if (!xmlTagName.CompareTo("SCAnaModule")) - fFolderTag = eSlowControlAnaModule; + fNodeTag = eSlowControlAnaModule; else - fFolderTag = eUnkown; + fNodeTag = eUnkown; offset += 2; - str = offsetStr + "<" + xmlTagName + ">"; - fXmlData.push_back(str.Data()); + TString sstr = offsetStr + "<" + xmlTagName + ">"; + fXmlData.push_back(sstr.Data()); - DumpFolder(dynamic_cast(obj), offset); + if (str == "TFolder") + DumpFolder(dynamic_cast(obj), offset); + else + DumpDirectory(dynamic_cast(obj), offset); - str = offsetStr + ""; - fXmlData.push_back(str.Data()); + sstr = offsetStr + ""; + fXmlData.push_back(sstr.Data()); } else if (str == "TObjArray") { offset += 2; DumpObjArray(dynamic_cast(obj), offset); } else { // filter out the proper entry tag TString entryTag(""); - switch (fFolderTag) { + switch (fNodeTag) { case eDecayAnaModule: entryTag = TString("DecayHistoEntry"); break;