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.

This commit is contained in:
suter_a 2025-04-04 16:58:57 +02:00
parent e5ff0fa743
commit 764cdf4e51

View File

@ -39,7 +39,9 @@
#include "TString.h" #include "TString.h"
#include "TFile.h" #include "TFile.h"
#include "TFolder.h" #include "TFolder.h"
#include "TDirectoryFile.h"
#include "TKey.h" #include "TKey.h"
#include "TList.h"
#include "TObjArray.h" #include "TObjArray.h"
#include "TObjString.h" #include "TObjString.h"
#include "TSystemFile.h" #include "TSystemFile.h"
@ -73,7 +75,7 @@ class PMusrRoot2Xml
virtual UInt_t GetNoOfDetectors() { return fNoOfDetectors; } virtual UInt_t GetNoOfDetectors() { return fNoOfDetectors; }
private: private:
enum EFolderTag {eUnkown, eDecayAnaModule, eSlowControlAnaModule}; enum fNodeTag {eUnkown, eDecayAnaModule, eSlowControlAnaModule};
std::vector<std::string> fXmlData; ///< keeps the XML structure dump of the ROOT file std::vector<std::string> 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 Bool_t fValid; ///< true if the conversion was fine
TString fFileName; ///< file name of the ROOT file TString fFileName; ///< file name of the ROOT file
TString fXmlDumpFileName; ///< file name of the XML dump 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 fNoOfDecayHistos{0}; ///< number of decay histos in the DecayAnaModule
UInt_t fNoOfHistos; ///< number of histos from run header UInt_t fNoOfHistos{0}; ///< number of histos from run header
UInt_t fNoOfRedGreenOffsets; ///< number of RedGreen offsets UInt_t fNoOfRedGreenOffsets{0}; ///< number of RedGreen offsets
UInt_t fNoOfDetectors; ///< number of detector entries in the header UInt_t fNoOfDetectors{0}; ///< number of detector entries in the header
virtual void SortHistoFolders(); virtual void SortHistoFolders();
virtual void DumpDirectory(TDirectoryFile *dir, UInt_t offset);
virtual void DumpFolder(TFolder *folder, UInt_t offset); virtual void DumpFolder(TFolder *folder, UInt_t offset);
virtual void DumpObjArray(TObjArray *obj, UInt_t offset); virtual void DumpObjArray(TObjArray *obj, UInt_t offset);
virtual void DumpEntry(TObject *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) PMusrRoot2Xml::PMusrRoot2Xml(const char *fileName, bool quiet, bool keep) : fQuiet(quiet), fKeep(keep), fFileName(fileName)
{ {
fXmlDumpFileName = "__MusrRootXmlDump.xml"; fXmlDumpFileName = "__MusrRootXmlDump.xml";
fFolderTag = eUnkown; fNodeTag = eUnkown;
fValid = false; fValid = false;
fXmlData.clear(); fXmlData.clear();
fNoOfDecayHistos = 0;
fNoOfHistos = 0;
fNoOfRedGreenOffsets = 0;
fNoOfDetectors = 0;
// read assumed MusrRoot file // read assumed MusrRoot file
TFile f(fFileName.Data()); TFile f(fFileName.Data());
@ -127,7 +126,8 @@ PMusrRoot2Xml::PMusrRoot2Xml(const char *fileName, bool quiet, bool keep) : fQui
TIter next = f.GetListOfKeys(); TIter next = f.GetListOfKeys();
TKey *key; TKey *key;
TFolder *folder; TFolder *folder;
TString str, tag; TDirectoryFile *dir;
TString str;
UInt_t offset = 2; UInt_t offset = 2;
@ -137,6 +137,9 @@ PMusrRoot2Xml::PMusrRoot2Xml(const char *fileName, bool quiet, bool keep) : fQui
if (str == "TFolder") { if (str == "TFolder") {
folder = dynamic_cast<TFolder*>(key->ReadObj()); folder = dynamic_cast<TFolder*>(key->ReadObj());
CheckClass(folder, str, offset); CheckClass(folder, str, offset);
} else if (str == "TDirectoryFile") {
dir = dynamic_cast<TDirectoryFile*>(key->ReadObj());
CheckClass(dir, str, offset);
} }
} }
if (!fQuiet) std::cout << std::endl; if (!fQuiet) std::cout << std::endl;
@ -226,6 +229,30 @@ void PMusrRoot2Xml::SortHistoFolders()
temp_xml_data.clear(); temp_xml_data.clear();
} }
//-----------------------------------------------------------------------
/**
* <p>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; i<offset; i++)
offsetStr += " ";
TList *ll = dir->GetListOfKeys();
TString str;
TObject *oo;
for (TObject *obj: *ll) {
oo = static_cast<TKey*>(obj)->ReadObj();
if (!fQuiet) std::cout << std::endl << offsetStr << "name: " << oo->GetName() << ", class name: " << oo->ClassName();
str = oo->ClassName();
CheckClass(oo, str, offset);
}
}
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
/** /**
* <p>Dump folder structure. * <p>Dump folder structure.
@ -343,7 +370,7 @@ void PMusrRoot2Xml::DumpEntry(TObject *obj, UInt_t offset)
offsetStr += " "; offsetStr += " ";
TString nameTag(""), typeTag(""); TString nameTag(""), typeTag("");
switch (fFolderTag) { switch (fNodeTag) {
case eDecayAnaModule: case eDecayAnaModule:
nameTag = "HistoName"; nameTag = "HistoName";
typeTag = "HistoType"; typeTag = "HistoType";
@ -359,7 +386,7 @@ void PMusrRoot2Xml::DumpEntry(TObject *obj, UInt_t offset)
break; break;
} }
if (fFolderTag == eDecayAnaModule) if (fNodeTag == eDecayAnaModule)
fNoOfDecayHistos++; fNoOfDecayHistos++;
TString str; TString str;
@ -389,34 +416,37 @@ void PMusrRoot2Xml::CheckClass(TObject *obj, TString str, UInt_t offset)
for (UInt_t i=0; i<offset; i++) for (UInt_t i=0; i<offset; i++)
offsetStr += " "; offsetStr += " ";
if (str == "TFolder") { if ((str == "TFolder") || (str == "TDirectoryFile")) {
TString xmlTagName(TString(obj->GetName())); TString xmlTagName(TString(obj->GetName()));
// set folder tag // set folder tag
if (!xmlTagName.CompareTo("DecayAnaModule")) if (!xmlTagName.CompareTo("DecayAnaModule"))
fFolderTag = eDecayAnaModule; fNodeTag = eDecayAnaModule;
else if (!xmlTagName.CompareTo("SCAnaModule")) else if (!xmlTagName.CompareTo("SCAnaModule"))
fFolderTag = eSlowControlAnaModule; fNodeTag = eSlowControlAnaModule;
else if (!xmlTagName.CompareTo("SCAnaModule")) else if (!xmlTagName.CompareTo("SCAnaModule"))
fFolderTag = eSlowControlAnaModule; fNodeTag = eSlowControlAnaModule;
else else
fFolderTag = eUnkown; fNodeTag = eUnkown;
offset += 2; offset += 2;
str = offsetStr + "<" + xmlTagName + ">"; TString sstr = offsetStr + "<" + xmlTagName + ">";
fXmlData.push_back(str.Data()); fXmlData.push_back(sstr.Data());
DumpFolder(dynamic_cast<TFolder*>(obj), offset); if (str == "TFolder")
DumpFolder(dynamic_cast<TFolder*>(obj), offset);
else
DumpDirectory(dynamic_cast<TDirectoryFile*>(obj), offset);
str = offsetStr + "</" + xmlTagName + ">"; sstr = offsetStr + "</" + xmlTagName + ">";
fXmlData.push_back(str.Data()); fXmlData.push_back(sstr.Data());
} else if (str == "TObjArray") { } else if (str == "TObjArray") {
offset += 2; offset += 2;
DumpObjArray(dynamic_cast<TObjArray*>(obj), offset); DumpObjArray(dynamic_cast<TObjArray*>(obj), offset);
} else { } else {
// filter out the proper entry tag // filter out the proper entry tag
TString entryTag(""); TString entryTag("");
switch (fFolderTag) { switch (fNodeTag) {
case eDecayAnaModule: case eDecayAnaModule:
entryTag = TString("DecayHistoEntry"); entryTag = TString("DecayHistoEntry");
break; break;