diff --git a/src/external/MusrRoot/TMusrRunHeader.cpp b/src/external/MusrRoot/TMusrRunHeader.cpp index 040a29067..2c9728d04 100644 --- a/src/external/MusrRoot/TMusrRunHeader.cpp +++ b/src/external/MusrRoot/TMusrRunHeader.cpp @@ -344,7 +344,7 @@ Bool_t TMusrRunHeader::FillFolder(TFolder *folder) bool found=false; if (folder == nullptr) { - std::cerr << std::endl << ">> TMusrRunHeader::FillFolder(): **ERROR** folder == 0!!" << std::endl; + std::cerr << std::endl << ">> TMusrRunHeader::FillFolder(): **ERROR** folder == nullptr!!" << std::endl; return false; } @@ -405,9 +405,58 @@ Bool_t TMusrRunHeader::FillFolder(TFolder *folder) * * \param dir to be filled */ -Bool_t TMusrRunHeader::FillDirectory(TDirectoryFile *dir) +Bool_t TMusrRunHeader::FillDirectory(TDirectory *dir) { - // NOT YET IMPLEMENTED + if (dir == nullptr) { + std::cerr << std::endl << ">> TMusrRunHeader::FillDirectory(): **ERROR** dir == nullptr!!" << std::endl; + return false; + } + + if (!UpdateDirTree(dir)) + return false; + + // update/generate tree content + TString path, name, str; + TObjString ostr, *p_ostr; + Ssiz_t pos=0; + TDirectory *currDir=nullptr; + TObjArray *oarray=nullptr; + Bool_t found; + for (UInt_t i=0; i> TMusrRunHeader::FillDirectory(): **ERROR** somethig is wrong with the path=" << path << " !!" << std::endl; + return false; + } + path.Remove(pos); // remove the value from the path + dir->cd(path); + currDir = dir->CurrentDirectory(); + if (currDir->GetList()->Last() == nullptr) { // no oarray present, hence create it + oarray = new TObjArray(); + } else { + oarray = dynamic_cast(currDir->GetList()->First()); + } + + // check if is already found in oarray + ostr = GetHeaderString(i); // encode the string for the MusrRoot file + name = ostr.GetString(); // convert to TString + str = GetFirst(name, ':'); // get the first part of the encoded string, i.e. - + found = false; + for (Int_t j=0; jGetEntriesFast(); j++) { + p_ostr = dynamic_cast(oarray->At(j)); + if (p_ostr->GetString().BeginsWith(str)) { // present hence replace + oarray->AddAt(ostr.Clone(), j); + oarray->Write(); + found = true; + break; + } + } + if (!found) { + oarray->AddLast(ostr.Clone()); + oarray->Write(); + } + } return true; } @@ -899,7 +948,7 @@ Bool_t TMusrRunHeader::ExtractAll(TFolder *folder) * * \param dir */ -Bool_t TMusrRunHeader::ExtractAll(TDirectoryFile *dir) +Bool_t TMusrRunHeader::ExtractAll(TDirectory *dir) { // NOT YET IMPLEMENTED @@ -1558,6 +1607,50 @@ bool TMusrRunHeader::UpdateFolder(TObject *treeObj, TString path) } } +//-------------------------------------------------------------------------- +// UpdateDirTree (private) +//-------------------------------------------------------------------------- +/** + *

Update directory tree for RunHeader + * + * \param dir top directory pointer + * + * \return true on success, false otherwise + */ +bool TMusrRunHeader::UpdateDirTree(TDirectory *topdir) +{ + if (strcmp(topdir->GetName(), "RunHeader")) { + std::cerr << std::endl << ">> TMusrRunHeader::UpdateDirTree(): **ERROR** top dir has to be named RunHeader, found '" << topdir->GetName() << "' !" << std::endl; + return false; + } + + TDirectory *dir; + TObjArray *tok = nullptr; + TObjString *ostr = nullptr; + TString tstr{""}; + TObject *obj; + for (TString str : fPathNameOrder) { // loop through all path-names + dir = topdir; + if (tok != nullptr) + delete tok; + tok = str.Tokenize("/"); + for (UInt_t i=0; iGetEntries(); i++) { + ostr = dynamic_cast(tok->At(i)); + tstr = ostr->GetString(); + if (i != tok->GetEntries()-1) { // TDirectory + if ((obj = topdir->FindObjectAny(tstr.Data())) == nullptr) { // TDirectory new + TDirectory *ndir = dir->mkdir(tstr.Data()); + dir = ndir; + } else { // TDirectory exists + dir = dynamic_cast(obj); + } + } + } + } + + return true; +} + //-------------------------------------------------------------------------- // FindObject (private) //-------------------------------------------------------------------------- diff --git a/src/external/MusrRoot/TMusrRunHeader.h b/src/external/MusrRoot/TMusrRunHeader.h index 7456897c7..999122e0f 100644 --- a/src/external/MusrRoot/TMusrRunHeader.h +++ b/src/external/MusrRoot/TMusrRunHeader.h @@ -38,7 +38,7 @@ #include #include #include -#include +#include #define MRH_UNDEFINED -9.99e99 @@ -130,10 +130,10 @@ public: virtual TString GetFileName() { return fFileName; } virtual Bool_t FillFolder(TFolder *folder); - virtual Bool_t FillDirectory(TDirectoryFile *dir); + virtual Bool_t FillDirectory(TDirectory *dir); virtual Bool_t ExtractAll(TFolder *folder); - virtual Bool_t ExtractAll(TDirectoryFile *folder); + virtual Bool_t ExtractAll(TDirectory *dir); virtual Bool_t ExtractHeaderInformation(TObjArray *headerInfo, TString path); virtual TString GetTypeOfPath(TString pathName); @@ -186,6 +186,7 @@ private: virtual TString GetType(TString str); virtual bool UpdateFolder(TObject *treeObj, TString path); + virtual bool UpdateDirTree(TDirectory *topdir); virtual TObject* FindObject(TObject *treeObj, TString path); virtual TObjString GetHeaderString(UInt_t idx);