start implementing TDirectory infrastructure.

This commit is contained in:
2025-09-28 16:45:49 +02:00
parent db71346ebb
commit 7e28402e25
2 changed files with 101 additions and 7 deletions

View File

@@ -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<fPathNameOrder.size(); i++) {
path=fPathNameOrder[i];
pos = path.Last('/');
if (pos == -1) {
std::cerr << std::endl << ">> 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<TObjArray*>(currDir->GetList()->First());
}
// check if <value> 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. <nnn> - <name>
found = false;
for (Int_t j=0; j<oarray->GetEntriesFast(); j++) {
p_ostr = dynamic_cast<TObjString*>(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)
//--------------------------------------------------------------------------
/**
* <p>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; i<tok->GetEntries(); i++) {
ostr = dynamic_cast<TObjString*>(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<TDirectory*>(obj);
}
}
}
}
return true;
}
//--------------------------------------------------------------------------
// FindObject (private)
//--------------------------------------------------------------------------

View File

@@ -38,7 +38,7 @@
#include <TObjString.h>
#include <TObjArray.h>
#include <TFolder.h>
#include <TDirectoryFile.h>
#include <TDirectory.h>
#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);