added the reader part for MusrRoot if written with TDirectory rather than TFolder.
This commit is contained in:
95
src/external/MusrRoot/TMusrRunHeader.cpp
vendored
95
src/external/MusrRoot/TMusrRunHeader.cpp
vendored
@@ -42,6 +42,7 @@
|
||||
#include <TString.h>
|
||||
#include <TList.h>
|
||||
#include <TMap.h>
|
||||
#include <TKey.h>
|
||||
|
||||
ClassImp(TMusrRunPhysicalQuantity)
|
||||
|
||||
@@ -447,15 +448,14 @@ Bool_t TMusrRunHeader::FillDirectory(TDirectory *dir)
|
||||
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();
|
||||
}
|
||||
oarray->Write();
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -936,6 +936,7 @@ Bool_t TMusrRunHeader::ExtractAll(TFolder *folder)
|
||||
while ((entry = dynamic_cast<TObjArray*>(next()))) {
|
||||
ExtractHeaderInformation(entry, entry->GetName());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -950,45 +951,58 @@ Bool_t TMusrRunHeader::ExtractAll(TFolder *folder)
|
||||
*/
|
||||
Bool_t TMusrRunHeader::ExtractAll(TDirectory *dir)
|
||||
{
|
||||
// NOT YET IMPLEMENTED
|
||||
TIter next(dir->GetListOfKeys());
|
||||
TKey *key;
|
||||
TObjString *entry;
|
||||
|
||||
// clean up all internal structures - just in case this is called multiple times
|
||||
if (dir->GetName() == "RunHeader") {
|
||||
std::cout << "as35> dir->GetName()=" << dir->GetName() << std::endl;
|
||||
CleanUp();
|
||||
}
|
||||
|
||||
while ((key = (TKey*)next())) {
|
||||
if (strcmp(key->GetClassName(), "TDirectoryFile") == 0) {
|
||||
TDirectory *subdir = (TDirectory*)key->ReadObj();
|
||||
ExtractAll(subdir);
|
||||
} else if (strcmp(key->GetClassName(), "TObjString") == 0) {
|
||||
entry = (TObjString*)key->ReadObj();
|
||||
TString str = dir->GetPath();
|
||||
Ssiz_t start_idx = str.Index("RunHeader/");
|
||||
start_idx += 10; // got to end of 'RunHeader/'
|
||||
ExtractHeaderInformationData(entry, str(start_idx, str.Length()-start_idx));
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// ExtractHeaderInformation (public)
|
||||
// ExtractHeaderInformationData (public)
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* \param headerInfo
|
||||
* \param headerData
|
||||
* \param requestedPath
|
||||
*/
|
||||
Bool_t TMusrRunHeader::ExtractHeaderInformation(TObjArray *headerInfo, TString requestedPath)
|
||||
Bool_t TMusrRunHeader::ExtractHeaderInformationData(TObjString *headerData, TString requestedPath)
|
||||
{
|
||||
TString label(""), path(""), pathName(""), str(""), strValue(""), type("");
|
||||
TString label(""), pathName(""), str(""), strValue(""), type("");
|
||||
TObjString *ostr = nullptr;
|
||||
TObjArray *tokens = nullptr;
|
||||
Ssiz_t idx1;
|
||||
Int_t intValue;
|
||||
Double_t dval;
|
||||
|
||||
// go through all entries of this header information from the MUSR-ROOT file
|
||||
for (Int_t i=0; i<headerInfo->GetEntries(); i++) {
|
||||
// check if entry is a TObjArray, i.e. a sub tree
|
||||
str = TString(headerInfo->At(i)->ClassName());
|
||||
if (str == "TObjArray") { // sub tree
|
||||
path = requestedPath + "/" + TString(headerInfo->At(i)->GetName());
|
||||
ExtractHeaderInformation(dynamic_cast<TObjArray*>(headerInfo->At(i)), path);
|
||||
} else { // handle all the rest, i.e. already data
|
||||
|
||||
ostr = dynamic_cast<TObjString*>(headerInfo->At(i));
|
||||
ostr = dynamic_cast<TObjString*>(headerData);
|
||||
str = ostr->GetString();
|
||||
|
||||
// get the run header label
|
||||
label = GetLabel(str);
|
||||
if (label == "n/a") // not a TMusrRunHeader object, hence ignore it
|
||||
continue;
|
||||
return true;
|
||||
|
||||
// get the run header 'value'
|
||||
strValue = GetStrValue(str);
|
||||
@@ -999,7 +1013,7 @@ Bool_t TMusrRunHeader::ExtractHeaderInformation(TObjArray *headerInfo, TString r
|
||||
// get type from map
|
||||
type = GetType(str);
|
||||
if (type == "n/a") // not a TMusrRunHeader object, hence ignore it
|
||||
continue;
|
||||
return true;
|
||||
|
||||
if (type == "TString") {
|
||||
Set(pathName, strValue);
|
||||
@@ -1016,7 +1030,7 @@ Bool_t TMusrRunHeader::ExtractHeaderInformation(TObjArray *headerInfo, TString r
|
||||
// 1st get the description if present
|
||||
tokens = strValue.Tokenize(";");
|
||||
if (tokens == nullptr) {
|
||||
std::cerr << std::endl << ">> **ERROR** Couldn't tokenize entry in Bool_t TMusrRunHeader::ExtractHeaderInformation(TObjArray *headerInfo, TString requestedPath)" << std::endl;
|
||||
std::cerr << std::endl << ">> **ERROR** Couldn't tokenize entry in Bool_t TMusrRunHeader::ExtractHeaderInformationData(TObjString *headerData, TString requestedPath)" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1058,7 +1072,7 @@ Bool_t TMusrRunHeader::ExtractHeaderInformation(TObjArray *headerInfo, TString r
|
||||
|
||||
tokens = strValue.Tokenize(" +;");
|
||||
if (tokens == nullptr) {
|
||||
std::cerr << std::endl << ">> **ERROR** Couldn't tokenize entry in Bool_t TMusrRunHeader::ExtractHeaderInformation(TObjArray *headerInfo, TString requestedPath)" << std::endl;
|
||||
std::cerr << std::endl << ">> **ERROR** Couldn't tokenize entry in Bool_t TMusrRunHeader::ExtractHeaderInformationData(TObjString *headerData, TString requestedPath)" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1119,7 +1133,7 @@ Bool_t TMusrRunHeader::ExtractHeaderInformation(TObjArray *headerInfo, TString r
|
||||
TStringVector svec;
|
||||
tokens = strValue.Tokenize(";");
|
||||
if (tokens == nullptr) {
|
||||
std::cerr << std::endl << ">> **ERROR** Couldn't tokenize entry in Bool_t TMusrRunHeader::ExtractHeaderInformation(TObjArray *headerInfo, TString requestedPath)" << std::endl;
|
||||
std::cerr << std::endl << ">> **ERROR** Couldn't tokenize entry in Bool_t TMusrRunHeader::ExtractHeaderInformationData(TObjString *headerData, TString requestedPath)" << std::endl;
|
||||
return false;
|
||||
}
|
||||
for (Int_t i=0; i<tokens->GetEntries(); i++) {
|
||||
@@ -1137,7 +1151,7 @@ Bool_t TMusrRunHeader::ExtractHeaderInformation(TObjArray *headerInfo, TString r
|
||||
TIntVector ivec;
|
||||
tokens = strValue.Tokenize(";");
|
||||
if (tokens == nullptr) {
|
||||
std::cerr << std::endl << ">> **ERROR** Couldn't tokenize entry in Bool_t TMusrRunHeader::ExtractHeaderInformation(TObjArray *headerInfo, TString requestedPath)" << std::endl;
|
||||
std::cerr << std::endl << ">> **ERROR** Couldn't tokenize entry in Bool_t TMusrRunHeader::ExtractHeaderInformationData(TObjString *headerData, TString requestedPath)" << std::endl;
|
||||
return false;
|
||||
}
|
||||
for (Int_t i=0; i<tokens->GetEntries(); i++) {
|
||||
@@ -1153,7 +1167,7 @@ Bool_t TMusrRunHeader::ExtractHeaderInformation(TObjArray *headerInfo, TString r
|
||||
TDoubleVector dvec;
|
||||
tokens = strValue.Tokenize(";");
|
||||
if (tokens == nullptr) {
|
||||
std::cerr << std::endl << ">> **ERROR** Couldn't tokenize entry in Bool_t TMusrRunHeader::ExtractHeaderInformation(TObjArray *headerInfo, TString requestedPath)" << std::endl;
|
||||
std::cerr << std::endl << ">> **ERROR** Couldn't tokenize entry in Bool_t TMusrRunHeader::ExtractHeaderInformationData(TObjString *headerData, TString requestedPath)" << std::endl;
|
||||
return false;
|
||||
}
|
||||
for (Int_t i=0; i<tokens->GetEntries(); i++) {
|
||||
@@ -1166,6 +1180,39 @@ Bool_t TMusrRunHeader::ExtractHeaderInformation(TObjArray *headerInfo, TString r
|
||||
}
|
||||
Set(pathName, dvec);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// ExtractHeaderInformation (public)
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* \param headerInfo
|
||||
* \param requestedPath
|
||||
*/
|
||||
Bool_t TMusrRunHeader::ExtractHeaderInformation(TObjArray *headerInfo, TString requestedPath)
|
||||
{
|
||||
TString label(""), path(""), pathName(""), str(""), strValue(""), type("");
|
||||
TObjString *ostr = nullptr;
|
||||
TObjArray *tokens = nullptr;
|
||||
Ssiz_t idx1;
|
||||
Int_t intValue;
|
||||
Double_t dval;
|
||||
|
||||
// go through all entries of this header information from the MUSR-ROOT file
|
||||
for (Int_t i=0; i<headerInfo->GetEntries(); i++) {
|
||||
// check if entry is a TObjArray, i.e. a sub tree
|
||||
str = TString(headerInfo->At(i)->ClassName());
|
||||
if (str == "TObjArray") { // sub tree
|
||||
path = requestedPath + "/" + TString(headerInfo->At(i)->GetName());
|
||||
ExtractHeaderInformation(dynamic_cast<TObjArray*>(headerInfo->At(i)), path);
|
||||
} else { // handle all the rest, i.e. already data
|
||||
ostr = dynamic_cast<TObjString*>(headerInfo->At(i));
|
||||
if (!ExtractHeaderInformationData(ostr, requestedPath))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
1
src/external/MusrRoot/TMusrRunHeader.h
vendored
1
src/external/MusrRoot/TMusrRunHeader.h
vendored
@@ -134,6 +134,7 @@ public:
|
||||
|
||||
virtual Bool_t ExtractAll(TFolder *folder);
|
||||
virtual Bool_t ExtractAll(TDirectory *dir);
|
||||
virtual Bool_t ExtractHeaderInformationData(TObjString *headerData, TString path);
|
||||
virtual Bool_t ExtractHeaderInformation(TObjArray *headerInfo, TString path);
|
||||
|
||||
virtual TString GetTypeOfPath(TString pathName);
|
||||
|
||||
Reference in New Issue
Block a user