From 2243c8e7dcc79bbc3144d7891efd2ad9fc3554f8 Mon Sep 17 00:00:00 2001 From: Andreas Suter Date: Wed, 18 Jan 2012 07:43:50 +0000 Subject: [PATCH] more work toward MusrRoot --- src/tests/{PsiRoot => MusrRoot}/Makefile | 2 +- .../Makefile.TMusrRunHeader | 0 src/tests/{PsiRoot => MusrRoot}/Makefile.arch | 0 .../{PsiRoot => MusrRoot}/TMusrRunHeader.cpp | 1384 +++++++++++------ .../{PsiRoot => MusrRoot}/TMusrRunHeader.h | 57 +- .../TMusrRunHeaderLinkDef.h | 0 .../MusrRoot/musrRoot_runHeader_test.cpp | 144 ++ .../read_musrRoot_runHeader.cpp | 59 +- .../write_musrRoot_runHeader.cpp | 85 +- src/tests/PsiRoot/musrRoot_runHeader_test.cpp | 303 ---- 10 files changed, 1133 insertions(+), 901 deletions(-) rename src/tests/{PsiRoot => MusrRoot}/Makefile (98%) rename src/tests/{PsiRoot => MusrRoot}/Makefile.TMusrRunHeader (100%) rename src/tests/{PsiRoot => MusrRoot}/Makefile.arch (100%) rename src/tests/{PsiRoot => MusrRoot}/TMusrRunHeader.cpp (50%) rename src/tests/{PsiRoot => MusrRoot}/TMusrRunHeader.h (82%) rename src/tests/{PsiRoot => MusrRoot}/TMusrRunHeaderLinkDef.h (100%) create mode 100644 src/tests/MusrRoot/musrRoot_runHeader_test.cpp rename src/tests/{PsiRoot => MusrRoot}/read_musrRoot_runHeader.cpp (64%) rename src/tests/{PsiRoot => MusrRoot}/write_musrRoot_runHeader.cpp (77%) delete mode 100644 src/tests/PsiRoot/musrRoot_runHeader_test.cpp diff --git a/src/tests/PsiRoot/Makefile b/src/tests/MusrRoot/Makefile similarity index 98% rename from src/tests/PsiRoot/Makefile rename to src/tests/MusrRoot/Makefile index 0b193e27..c76bbc08 100644 --- a/src/tests/PsiRoot/Makefile +++ b/src/tests/MusrRoot/Makefile @@ -4,7 +4,7 @@ # Author: Andreas Suter # e-mail: andreas.suter@psi.ch # -# $Id$ +# $Id: Makefile 5052 2012-01-12 09:55:19Z suter_a $ # #--------------------------------------------------- diff --git a/src/tests/PsiRoot/Makefile.TMusrRunHeader b/src/tests/MusrRoot/Makefile.TMusrRunHeader similarity index 100% rename from src/tests/PsiRoot/Makefile.TMusrRunHeader rename to src/tests/MusrRoot/Makefile.TMusrRunHeader diff --git a/src/tests/PsiRoot/Makefile.arch b/src/tests/MusrRoot/Makefile.arch similarity index 100% rename from src/tests/PsiRoot/Makefile.arch rename to src/tests/MusrRoot/Makefile.arch diff --git a/src/tests/PsiRoot/TMusrRunHeader.cpp b/src/tests/MusrRoot/TMusrRunHeader.cpp similarity index 50% rename from src/tests/PsiRoot/TMusrRunHeader.cpp rename to src/tests/MusrRoot/TMusrRunHeader.cpp index a23221fd..f940f89c 100644 --- a/src/tests/PsiRoot/TMusrRunHeader.cpp +++ b/src/tests/MusrRoot/TMusrRunHeader.cpp @@ -44,8 +44,6 @@ using namespace std; #include #include #include -#include -#include ClassImp(TMusrRunPhysicalQuantity) @@ -58,9 +56,9 @@ ClassImp(TMusrRunPhysicalQuantity) TMusrRunPhysicalQuantity::TMusrRunPhysicalQuantity() { fLabel = "n/a"; - fDemand = MRRH_UNDEFINED; - fValue = MRRH_UNDEFINED; - fError = MRRH_UNDEFINED; + fDemand = MRH_UNDEFINED; + fValue = MRH_UNDEFINED; + fError = MRH_UNDEFINED; fUnit = "n/a"; fDescription = "n/a"; } @@ -102,7 +100,7 @@ TMusrRunPhysicalQuantity::TMusrRunPhysicalQuantity(TString label, Double_t deman TMusrRunPhysicalQuantity::TMusrRunPhysicalQuantity(TString label, Double_t demand, Double_t value, TString unit, TString description) : fLabel(label), fDemand(demand), fValue(value), fUnit(unit) { - fError = MRRH_UNDEFINED; + fError = MRH_UNDEFINED; if (description.IsWhitespace()) fDescription = "n/a"; else @@ -123,8 +121,8 @@ TMusrRunPhysicalQuantity::TMusrRunPhysicalQuantity(TString label, Double_t deman TMusrRunPhysicalQuantity::TMusrRunPhysicalQuantity(TString label, Double_t value, TString unit, TString description) : fLabel(label), fValue(value), fUnit(unit) { - fDemand = MRRH_UNDEFINED; - fError = MRRH_UNDEFINED; + fDemand = MRH_UNDEFINED; + fError = MRH_UNDEFINED; if (description.IsWhitespace()) fDescription = "n/a"; else @@ -174,7 +172,7 @@ void TMusrRunPhysicalQuantity::Set(TString label, Double_t demand, Double_t valu fLabel = label; fDemand = demand; fValue = value; - fError = MRRH_UNDEFINED; + fError = MRH_UNDEFINED; fUnit = unit; if (description.IsWhitespace()) fDescription = "n/a"; @@ -196,9 +194,9 @@ void TMusrRunPhysicalQuantity::Set(TString label, Double_t demand, Double_t valu void TMusrRunPhysicalQuantity::Set(TString label, Double_t value, TString unit, TString description) { fLabel = label; - fDemand = MRRH_UNDEFINED; + fDemand = MRH_UNDEFINED; fValue = value; - fError = MRRH_UNDEFINED; + fError = MRH_UNDEFINED; fUnit = unit; if (description.IsWhitespace()) fDescription = "n/a"; @@ -218,7 +216,7 @@ ClassImp(TMusrRunHeader) */ TMusrRunHeader::TMusrRunHeader() { - Init(); + fFileName = TString("n/a"); } //-------------------------------------------------------------------------- @@ -229,7 +227,6 @@ TMusrRunHeader::TMusrRunHeader() */ TMusrRunHeader::TMusrRunHeader(const char *fileName) { - Init(); fFileName = TString(fileName); } @@ -249,24 +246,92 @@ TMusrRunHeader::~TMusrRunHeader() fIntVectorObj.clear(); fDoubleVectorObj.clear(); - fFolder.clear(); - - fMap.DeleteAll(); + fPathNameOrder.clear(); } - //-------------------------------------------------------------------------- -// Init (private) +// FillFolder (public) //-------------------------------------------------------------------------- /** - *

Initializes variables. - */ -void TMusrRunHeader::Init() + *

Fills the RunHeader folder. This is needed to write it to a ROOT file. + * It walks through all information and attaches it to folder. + * + * \param folder to be filled + */ +Bool_t TMusrRunHeader::FillFolder(TFolder *folder) { - fMap.DeleteAll(); - fMap.SetName("__map"); + TObjArray *oarray, *tokens; + vector content; + TObjString ostr; + TString path, name, pathName; - fFileName = TString("n/a"); + if (folder == 0) { + cerr << endl << ">> TMusrRunHeader::FillFolder(): **ERROR** folder == 0!!" << endl; + return false; + } + + folder->SetOwner(); // folder takes ownership of all added objects! + + for (UInt_t i=0; i> TMusrRunHeader::FillFolder(): **ERROR** couldn't tokenize string " << fPathNameOrder[i] << endl; + return false; + } + + Int_t idx; + if (tokens->GetEntries() == 2) { // / + path = ((TObjString*)tokens->At(0))->GetString(); + idx = ObjectPresent(content, path); + if (idx == -1) { + // add object array + oarray = new TObjArray(); + oarray->SetName(path); + content.push_back(oarray); + idx = content.size()-1; + } + // add value + ostr = GetHeaderString(i); + content[idx]->AddLast(ostr.Clone()); + } else { // /..// + path = ((TObjString*)tokens->At(0))->GetString(); + idx = ObjectPresent(content, path); + if (idx == -1) { + // add object array + oarray = new TObjArray(); + oarray->SetName(path); + content.push_back(oarray); + idx = content.size()-1; + } + + // add necessary sub object arrays + pathName = fPathNameOrder[i]; + RemoveFirst(pathName, '/'); + AddSubTrees(content[idx], pathName); + + // get header string + ostr = GetHeaderString(i); + + // set object string on the right position within content + SetSubTreeObject(content[idx], ostr, i); + } + + // clean up + if (tokens) { + delete tokens; + tokens = 0; + } + } + + // fill folder with all run header information + for (UInt_t i=0; iAdd(content[i]); + } + + // clean up + content.clear(); + + return true; } //-------------------------------------------------------------------------- @@ -278,136 +343,162 @@ void TMusrRunHeader::Init() * \param requestedPath of the MUSR-ROOT header, e.g. RunInfo * \param content of the requested MUSR-ROOT header. */ +/* void TMusrRunHeader::GetHeaderInfo(TString requestedPath, TObjArray &content) { // make sure content is initialized content.Delete(); content.Expand(0); + content.SetOwner(); // takes ownership of the attached objects!! - static UInt_t count = 1; TString str(""), path(""), name(""), fmt(""), tstr(""); TObjString *tostr; TMusrRunPhysicalQuantity prop; - for (UInt_t i=0; i +- ; SP: [; ] - digit = GetDecimalPlace(prop.GetError()); - digit_d = GetLeastSignificantDigit(prop.GetDemand()); - if (prop.GetDescription() != "n/a") { - fmt.Form("%%s: %%.%dlf +- %%.%dlf %%s; SP: %%.%dlf; %%s", digit, digit, digit_d); - tstr.Form(fmt, prop.GetLabel().Data(), prop.GetValue(), prop.GetError(), prop.GetUnit().Data(), prop.GetDemand(), prop.GetDescription().Data()); - } else { - fmt.Form("%%s: %%.%dlf +- %%.%dlf %%s; SP: %%.%dlf", digit, digit, digit_d); - tstr.Form(fmt, prop.GetLabel().Data(), prop.GetValue(), prop.GetError(), prop.GetUnit().Data(), prop.GetDemand()); - } - } else if ((prop.GetDemand() == MRRH_UNDEFINED) && (prop.GetValue() != MRRH_UNDEFINED) && (prop.GetError() != MRRH_UNDEFINED) && - (prop.GetUnit() != "n/a")) { // +- [; ] - digit = GetDecimalPlace(prop.GetError()); - if (prop.GetDescription() != "n/a") { - fmt.Form("%%s: %%.%dlf +- %%.%dlf %%s; %%s", digit, digit); - tstr.Form(fmt, prop.GetLabel().Data(), prop.GetValue(), prop.GetError(), prop.GetUnit().Data(), prop.GetDescription().Data()); - } else { - fmt.Form("%%s: %%.%dlf +- %%.%dlf %%s", digit, digit); - tstr.Form(fmt, prop.GetLabel().Data(), prop.GetValue(), prop.GetError(), prop.GetUnit().Data()); - } - } else if ((prop.GetDemand() == MRRH_UNDEFINED) && (prop.GetValue() != MRRH_UNDEFINED) && (prop.GetError() == MRRH_UNDEFINED) && - (prop.GetUnit() != "n/a")) { // [; ] - digit = GetLeastSignificantDigit(prop.GetValue()); - if (prop.GetDescription() != "n/a") { - fmt.Form("%%s: %%.%dlf %%s; %%s", digit); - tstr.Form(fmt, prop.GetLabel().Data(), prop.GetValue(), prop.GetUnit().Data(), prop.GetDescription().Data()); - } else { - fmt.Form("%%s: %%.%dlf %%s", digit); - tstr.Form(fmt, prop.GetLabel().Data(), prop.GetValue(), prop.GetUnit().Data()); - } - } else if ((prop.GetDemand() != MRRH_UNDEFINED) && (prop.GetValue() != MRRH_UNDEFINED) && (prop.GetError() == MRRH_UNDEFINED) && - (prop.GetUnit() != "n/a")) { // ; SP: [; ] - digit = GetLeastSignificantDigit(prop.GetValue()); - digit_d = GetLeastSignificantDigit(prop.GetDemand()); - if (prop.GetDescription() != "n/a") { - fmt.Form("%%s: %%.%dlf %%s; SP: %%.%dlf; %%s", digit, digit_d); - tstr.Form(fmt, prop.GetLabel().Data(), prop.GetValue(), prop.GetUnit().Data(), prop.GetDemand(), prop.GetDescription().Data()); - } else { - fmt.Form("%%s: %%.%dlf %%s; SP: %%.%dlf", digit, digit_d); - tstr.Form(fmt, prop.GetLabel().Data(), prop.GetValue(), prop.GetUnit().Data(), prop.GetDemand()); + for (UInt_t i=0; i +- ; SP: [; ] + digit = GetDecimalPlace(prop.GetError()); + digit_d = GetLeastSignificantDigit(prop.GetDemand()); + if (prop.GetDescription() != "n/a") { + fmt.Form("%%s: %%.%dlf +- %%.%dlf %%s; SP: %%.%dlf; %%s", digit, digit, digit_d); + + tstr.Form(fmt, prop.GetLabel().Data(), prop.GetValue(), prop.GetError(), prop.GetUnit().Data(), prop.GetDemand(), prop.GetDescription().Data()); + } else { + fmt.Form("%%s: %%.%dlf +- %%.%dlf %%s; SP: %%.%dlf", digit, digit, digit_d); + tstr.Form(fmt, prop.GetLabel().Data(), prop.GetValue(), prop.GetError(), prop.GetUnit().Data(), prop.GetDemand()); + } + } else if ((prop.GetDemand() == MRH_UNDEFINED) && (prop.GetValue() != MRH_UNDEFINED) && (prop.GetError() != MRH_UNDEFINED) && + (prop.GetUnit() != "n/a")) { // +- [; ] + digit = GetDecimalPlace(prop.GetError()); + if (prop.GetDescription() != "n/a") { + fmt.Form("%%s: %%.%dlf +- %%.%dlf %%s; %%s", digit, digit); + tstr.Form(fmt, prop.GetLabel().Data(), prop.GetValue(), prop.GetError(), prop.GetUnit().Data(), prop.GetDescription().Data()); + } else { + fmt.Form("%%s: %%.%dlf +- %%.%dlf %%s", digit, digit); + tstr.Form(fmt, prop.GetLabel().Data(), prop.GetValue(), prop.GetError(), prop.GetUnit().Data()); + } + } else if ((prop.GetDemand() == MRH_UNDEFINED) && (prop.GetValue() != MRH_UNDEFINED) && (prop.GetError() == MRH_UNDEFINED) && + (prop.GetUnit() != "n/a")) { // [; ] + digit = GetLeastSignificantDigit(prop.GetValue()); + if (prop.GetDescription() != "n/a") { + fmt.Form("%%s: %%.%dlf %%s; %%s", digit); + tstr.Form(fmt, prop.GetLabel().Data(), prop.GetValue(), prop.GetUnit().Data(), prop.GetDescription().Data()); + } else { + fmt.Form("%%s: %%.%dlf %%s", digit); + tstr.Form(fmt, prop.GetLabel().Data(), prop.GetValue(), prop.GetUnit().Data()); + } + } else if ((prop.GetDemand() != MRH_UNDEFINED) && (prop.GetValue() != MRH_UNDEFINED) && (prop.GetError() == MRH_UNDEFINED) && + (prop.GetUnit() != "n/a")) { // ; SP: [; ] + digit = GetLeastSignificantDigit(prop.GetValue()); + digit_d = GetLeastSignificantDigit(prop.GetDemand()); + if (prop.GetDescription() != "n/a") { + fmt.Form("%%s: %%.%dlf %%s; SP: %%.%dlf; %%s", digit, digit_d); + tstr.Form(fmt, prop.GetLabel().Data(), prop.GetValue(), prop.GetUnit().Data(), prop.GetDemand(), prop.GetDescription().Data()); + } else { + fmt.Form("%%s: %%.%dlf %%s; SP: %%.%dlf", digit, digit_d); + tstr.Form(fmt, prop.GetLabel().Data(), prop.GetValue(), prop.GetUnit().Data(), prop.GetDemand()); + } + } + str.Form("%03d - %s -@%d", i, tstr.Data(), MRH_TMUSR_RUN_PHYSICAL_QUANTITY); + tostr = new TObjString(str); + content.AddLast(tostr); + } + } + // 5th check TStringVector + for (UInt_t j=0; jSet map which links the entry to a data type. - * - * \param map pointer to the maps. - */ -void TMusrRunHeader::SetMap(TMap* map) -{ - // perform some checks - if (map == 0) { - cerr << endl << ">> TMusrRunHeader::SetMap(): **ERROR** map points to 0." << endl; - return; - } - - TMapIter iter(map); - TObjString *key; - - // remove all previous entries - fMap.DeleteAll(); - // set the name - fMap.SetName("__map"); - - while ((key = (TObjString*) iter.Next())) { - fMap.Add(key, (TObjString*)map->GetValue(key->GetString())); - } -} - //-------------------------------------------------------------------------- // Set (public) //-------------------------------------------------------------------------- @@ -600,9 +662,8 @@ void TMusrRunHeader::SetMap(TMap* map) * * \param pathName path/name within the header, e.g. RunInfo/Run Title * \param value of the entry - * \param addAdminInfo if true add map information (needed for writting), otherwise do not add map information (needed for reading, since there the map is already present) */ -void TMusrRunHeader::Set(TString pathName, TString value, Bool_t addAdminInfo) +void TMusrRunHeader::Set(TString pathName, TString value) { // check if pathName is already set, and if not add it as a new entry UInt_t i=0; @@ -617,20 +678,12 @@ void TMusrRunHeader::Set(TString pathName, TString value, Bool_t addAdminInfo) // if not found in the previous loop, it is a new object if (i == fStringObj.size()) { + // feed object TMusrRunObject obj(pathName, "TString", value); fStringObj.push_back(obj); - // check if new folder, and if yes keep it - TString path(""), name(""); - SplitPathName(pathName, path, name); - if (!FolderPresent(path)) - fFolder.push_back(path); - - // add the mapping information if needed - if (addAdminInfo) { - fMap.Add(new TObjString(pathName), new TObjString("TString")); - - } + // feed path-name to keep track of the order + fPathNameOrder.push_back(pathName); } } @@ -642,9 +695,8 @@ void TMusrRunHeader::Set(TString pathName, TString value, Bool_t addAdminInfo) * * \param pathName path/name within the header, e.g. RunInfo/Run number * \param value of the entry - * \param addMap if true add map information (needed for writting), otherwise do not add map information (needed for reading, since there the map is already present) */ -void TMusrRunHeader::Set(TString pathName, Int_t value, Bool_t addMap) +void TMusrRunHeader::Set(TString pathName, Int_t value) { // check if pathName is already set, and if not add it as a new entry UInt_t i=0; @@ -659,18 +711,12 @@ void TMusrRunHeader::Set(TString pathName, Int_t value, Bool_t addMap) // if not found in the previous loop, it is a new object if (i == fIntObj.size()) { + // feed object TMusrRunObject obj(pathName, "Int_t", value); fIntObj.push_back(obj); - // check if new folder, and if yes keep it - TString path(""), name(""); - SplitPathName(pathName, path, name); - if (!FolderPresent(path)) - fFolder.push_back(path); - - // add the mapping information if needed - if (addMap) - fMap.Add(new TObjString(pathName), new TObjString("Int_t")); + // feed path-name to keep track of the order + fPathNameOrder.push_back(pathName); } } @@ -682,9 +728,8 @@ void TMusrRunHeader::Set(TString pathName, Int_t value, Bool_t addMap) * * \param pathName path/name within the header, e.g. RunInfo/DoubleValue * \param value of the entry - * \param addMap if true add map information (needed for writting), otherwise do not add map information (needed for reading, since there the map is already present) */ -void TMusrRunHeader::Set(TString pathName, Double_t value, Bool_t addMap) +void TMusrRunHeader::Set(TString pathName, Double_t value) { // check if pathName is already set, and if not add it as a new entry UInt_t i=0; @@ -699,18 +744,12 @@ void TMusrRunHeader::Set(TString pathName, Double_t value, Bool_t addMap) // if not found in the previous loop, it is a new object if (i == fDoubleObj.size()) { + // feed object TMusrRunObject obj(pathName, "Double_t", value); fDoubleObj.push_back(obj); - // check if new folder, and if yes keep it - TString path(""), name(""); - SplitPathName(pathName, path, name); - if (!FolderPresent(path)) - fFolder.push_back(path); - - // add the mapping information if needed - if (addMap) - fMap.Add(new TObjString(pathName), new TObjString("Double_t")); + // feed path-name to keep track of the order + fPathNameOrder.push_back(pathName); } } @@ -722,9 +761,8 @@ void TMusrRunHeader::Set(TString pathName, Double_t value, Bool_t addMap) * * \param pathName path/name within the header, e.g. RunInfo/Muon Beam Momentum * \param value of the entry - * \param addMap if true add map information (needed for writting), otherwise do not add map information (needed for reading, since there the map is already present) */ -void TMusrRunHeader::Set(TString pathName, TMusrRunPhysicalQuantity value, Bool_t addMap) +void TMusrRunHeader::Set(TString pathName, TMusrRunPhysicalQuantity value) { // check if pathName is already set, and if not add it as a new entry UInt_t i=0; @@ -739,18 +777,12 @@ void TMusrRunHeader::Set(TString pathName, TMusrRunPhysicalQuantity value, Bool_ // if not found in the previous loop, it is a new object if (i == fMusrRunPhysQuantityObj.size()) { + // feed object TMusrRunObject obj(pathName, "TMusrRunPhysicalQuantity", value); fMusrRunPhysQuantityObj.push_back(obj); - // check if new folder, and if yes keep it - TString path(""), name(""); - SplitPathName(pathName, path, name); - if (!FolderPresent(path)) - fFolder.push_back(path); - - // add the mapping information if needed - if (addMap) - fMap.Add(new TObjString(pathName), new TObjString("TMusrRunPhysicalQuantity")); + // feed path-name to keep track of the order + fPathNameOrder.push_back(pathName); } } @@ -762,9 +794,8 @@ void TMusrRunHeader::Set(TString pathName, TMusrRunPhysicalQuantity value, Bool_ * * \param pathName path/name within the header, e.g. RunInfo/Histo names * \param value of the entry - * \param addMap if true add map information (needed for writting), otherwise do not add map information (needed for reading, since there the map is already present) */ -void TMusrRunHeader::Set(TString pathName, TStringVector value, Bool_t addMap) +void TMusrRunHeader::Set(TString pathName, TStringVector value) { // check if pathName is already set, and if not add it as a new entry UInt_t i=0; @@ -779,18 +810,12 @@ void TMusrRunHeader::Set(TString pathName, TStringVector value, Bool_t addMap) // if not found in the previous loop, it is a new object if (i == fStringVectorObj.size()) { + // feed object TMusrRunObject obj(pathName, "TStringVector", value); fStringVectorObj.push_back(obj); - // check if new folder, and if yes keep it - TString path(""), name(""); - SplitPathName(pathName, path, name); - if (!FolderPresent(path)) - fFolder.push_back(path); - - // add the mapping information if needed - if (addMap) - fMap.Add(new TObjString(pathName), new TObjString("TStringVector")); + // feed path-name to keep track of the order + fPathNameOrder.push_back(pathName); } } @@ -802,9 +827,8 @@ void TMusrRunHeader::Set(TString pathName, TStringVector value, Bool_t addMap) * * \param pathName path/name within the header, e.g. RunInfo/Time Zero Bin * \param value of the entry - * \param addMap if true add map information (needed for writting), otherwise do not add map information (needed for reading, since there the map is already present) */ -void TMusrRunHeader::Set(TString pathName, TIntVector value, Bool_t addMap) +void TMusrRunHeader::Set(TString pathName, TIntVector value) { // check if pathName is already set, and if not add it as a new entry UInt_t i=0; @@ -819,18 +843,12 @@ void TMusrRunHeader::Set(TString pathName, TIntVector value, Bool_t addMap) // if not found in the previous loop, it is a new object if (i == fIntVectorObj.size()) { + // feed object TMusrRunObject obj(pathName, "TIntVector", value); fIntVectorObj.push_back(obj); - // check if new folder, and if yes keep it - TString path(""), name(""); - SplitPathName(pathName, path, name); - if (!FolderPresent(path)) - fFolder.push_back(path); - - // add the mapping information if needed - if (addMap) - fMap.Add(new TObjString(pathName), new TObjString("TIntVector")); + // feed path-name to keep track of the order + fPathNameOrder.push_back(pathName); } } @@ -842,9 +860,8 @@ void TMusrRunHeader::Set(TString pathName, TIntVector value, Bool_t addMap) * * \param pathName path/name within the header, e.g. RunInfo/Time Zero Bin * \param value of the entry - * \param addMap if true add map information (needed for writting), otherwise do not add map information (needed for reading, since there the map is already present) */ -void TMusrRunHeader::Set(TString pathName, TDoubleVector value, Bool_t addMap) +void TMusrRunHeader::Set(TString pathName, TDoubleVector value) { // check if pathName is already set, and if not add it as a new entry UInt_t i=0; @@ -859,21 +876,36 @@ void TMusrRunHeader::Set(TString pathName, TDoubleVector value, Bool_t addMap) // if not found in the previous loop, it is a new object if (i == fDoubleVectorObj.size()) { + // feed object TMusrRunObject obj(pathName, "TDoubleVector", value); fDoubleVectorObj.push_back(obj); - // check if new folder, and if yes keep it - TString path(""), name(""); - SplitPathName(pathName, path, name); - if (!FolderPresent(path)) - fFolder.push_back(path); - - // add the mapping information if needed - if (addMap) - fMap.Add(new TObjString(pathName), new TObjString("TDoubleVector")); + // feed path-name to keep track of the order + fPathNameOrder.push_back(pathName); } } + +//-------------------------------------------------------------------------- +// ExtractAll (public) +//-------------------------------------------------------------------------- +/** + *

Reads all data from an open ROOT-file structure and feeds all the necessary + * internal data objects. + * + * \param folder + */ +Bool_t TMusrRunHeader::ExtractAll(TFolder *folder) +{ + TIter next(folder->GetListOfFolders()); + TObjArray* entry; + + while ((entry = (TObjArray*)next())) { + ExtractHeaderInformation(entry, entry->GetName()); + } + return true; +} + //-------------------------------------------------------------------------- // ExtractHeaderInformation (public) //-------------------------------------------------------------------------- @@ -885,213 +917,206 @@ void TMusrRunHeader::Set(TString pathName, TDoubleVector value, Bool_t addMap) */ Bool_t TMusrRunHeader::ExtractHeaderInformation(TObjArray *headerInfo, TString requestedPath) { - // make sure fMap has been set - if (fMap.IsEmpty()) { - cerr << endl << ">> TMusrRunHeader::ExtractHeaderInformation(): **FATAL ERROR** no fMap present."; - cerr << endl << ">> Either the file is corrupted, or the reader routine forgot the read the __map entry first."; - cerr << endl << endl; - return false; - } - - TString headerName(""), name(""), pathName(""), str(""), strValue(""), type(""); + TString label(""), path(""), pathName(""), str(""), strValue(""), type(""); TObjString *ostr = 0; TObjArray *tokens = 0; - Ssiz_t idx1, idx2; + Ssiz_t idx1; Int_t intValue; Double_t dval; - Bool_t noMap = true; // go through all entries of this header information from the MUSR-ROOT file for (Int_t i=0; iGetEntries(); i++) { - ostr = dynamic_cast(headerInfo->At(i)); - str = ostr->GetString(); + // 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((TObjArray*)headerInfo->At(i), path); + } else { // handle all the rest, i.e. already data - // get header name - idx1 = str.First('-'); - idx2 = str.First(':'); - headerName = TString(""); - for (Int_t j=idx1+2; j(headerInfo->At(i)); + str = ostr->GetString(); - // get the name - idx1 = str.First('-'); - idx2 = str.First(':'); - name = TString(""); - for (Int_t i=idx1+2; iGetString(); - - if (type == "TString") { - Set(pathName, strValue, noMap); - } else if (type == "Int_t") { - intValue = strValue.Atoi(); - Set(pathName, intValue, noMap); - } else if (type == "Double_t") { - dval = strValue.Atof(); - Set(pathName, dval, noMap); - } else if (type == "TMusrRunPhysicalQuantity") { - TMusrRunPhysicalQuantity prop; - prop.SetLabel(name); - - // 1st get the description if present - tokens = strValue.Tokenize(";"); - if (tokens == 0) { - cerr << endl << ">> **ERROR** Couldn't tokenize entry in Bool_t TMusrRunHeader::ExtractHeaderInformation(TObjArray *headerInfo, TString requestedPath)" << endl; + // get the run header label + label = GetLabel(str); + if (label == "n/a") return false; - } - switch (tokens->GetEntries()) { - case 2: - ostr = dynamic_cast(tokens->At(1)); - str = ostr->GetString(); - if (!str.Contains("SP:")) { // make sure that it is not a demand value token - prop.SetDescription(str); - } - break; - case 3: - ostr = dynamic_cast(tokens->At(2)); - str = ostr->GetString(); - break; - default: - break; - } - - if (tokens) { - delete tokens; - tokens = 0; - } - - // 2nd collect all the other properties, this is easier when first a potential description is removed - idx1 = strValue.Last(';'); - if (idx1 > 0) { - TString last(""); - for (Int_t i=idx1+2; i or SP: - if (!last.Contains("SP:")) { - str = ""; - for (Int_t i=0; i> **ERROR** Couldn't tokenize entry in Bool_t TMusrRunHeader::ExtractHeaderInformation(TObjArray *headerInfo, TString requestedPath)" << endl; + // get the run header 'value' + strValue = GetStrValue(str); + if (strValue == "n/a") return false; - } - switch (tokens->GetEntries()) { - case 2: // - ostr = dynamic_cast(tokens->At(0)); - str = ostr->GetString(); - prop.SetValue(str.Atof()); - ostr = dynamic_cast(tokens->At(1)); - str = ostr->GetString(); - prop.SetUnit(str); - break; - case 4: // +- , or ; SP: - ostr = dynamic_cast(tokens->At(0)); - str = ostr->GetString(); - prop.SetValue(str.Atof()); - ostr = dynamic_cast(tokens->At(1)); - str = ostr->GetString(); - if (str == "-") { // +- + // construct path name + pathName = requestedPath + TString("/") + label; + + // get type from map + type = GetType(str); + + if (type == "TString") { + Set(pathName, strValue); + } else if (type == "Int_t") { + intValue = strValue.Atoi(); + Set(pathName, intValue); + } else if (type == "Double_t") { + dval = strValue.Atof(); + Set(pathName, dval); + } else if (type == "TMusrRunPhysicalQuantity") { + TMusrRunPhysicalQuantity prop; + prop.SetLabel(label); + + // 1st get the description if present + tokens = strValue.Tokenize(";"); + if (tokens == 0) { + cerr << endl << ">> **ERROR** Couldn't tokenize entry in Bool_t TMusrRunHeader::ExtractHeaderInformation(TObjArray *headerInfo, TString requestedPath)" << endl; + return false; + } + + switch (tokens->GetEntries()) { + case 2: + ostr = dynamic_cast(tokens->At(1)); + str = ostr->GetString(); + if (!str.Contains("SP:")) { // make sure that it is not a demand value token + prop.SetDescription(str); + } + break; + case 3: + ostr = dynamic_cast(tokens->At(2)); + str = ostr->GetString(); + break; + default: + break; + } + + if (tokens) { + delete tokens; + tokens = 0; + } + + // 2nd collect all the other properties, this is easier when first a potential description is removed + idx1 = strValue.Last(';'); + if (idx1 > 0) { + TString last(""); + for (Int_t i=idx1+2; i or SP: + if (!last.Contains("SP:")) { + str = ""; + for (Int_t i=0; i> **ERROR** Couldn't tokenize entry in Bool_t TMusrRunHeader::ExtractHeaderInformation(TObjArray *headerInfo, TString requestedPath)" << endl; + return false; + } + + switch (tokens->GetEntries()) { + case 2: // + ostr = dynamic_cast(tokens->At(0)); + str = ostr->GetString(); + prop.SetValue(str.Atof()); + ostr = dynamic_cast(tokens->At(1)); + str = ostr->GetString(); + prop.SetUnit(str); + break; + case 4: // +- , or ; SP: + ostr = dynamic_cast(tokens->At(0)); + str = ostr->GetString(); + prop.SetValue(str.Atof()); + ostr = dynamic_cast(tokens->At(1)); + str = ostr->GetString(); + if (str == "-") { // +- + ostr = dynamic_cast(tokens->At(2)); + str = ostr->GetString(); + prop.SetError(str.Atof()); + ostr = dynamic_cast(tokens->At(3)); + str = ostr->GetString(); + prop.SetUnit(str); + } else { // ; SP: + prop.SetUnit(str); + ostr = dynamic_cast(tokens->At(3)); + str = ostr->GetString(); + prop.SetDemand(str.Atof()); + } + break; + case 6: // +- ; SP: + ostr = dynamic_cast(tokens->At(0)); + str = ostr->GetString(); + prop.SetValue(str.Atof()); ostr = dynamic_cast(tokens->At(2)); str = ostr->GetString(); prop.SetError(str.Atof()); ostr = dynamic_cast(tokens->At(3)); str = ostr->GetString(); prop.SetUnit(str); - } else { // ; SP: - prop.SetUnit(str); - ostr = dynamic_cast(tokens->At(3)); + ostr = dynamic_cast(tokens->At(5)); str = ostr->GetString(); prop.SetDemand(str.Atof()); + break; + default: + break; } - break; - case 6: // +- ; SP: - ostr = dynamic_cast(tokens->At(0)); - str = ostr->GetString(); - prop.SetValue(str.Atof()); - ostr = dynamic_cast(tokens->At(2)); - str = ostr->GetString(); - prop.SetError(str.Atof()); - ostr = dynamic_cast(tokens->At(3)); - str = ostr->GetString(); - prop.SetUnit(str); - ostr = dynamic_cast(tokens->At(5)); - str = ostr->GetString(); - prop.SetDemand(str.Atof()); - break; - default: - break; - } - if (tokens) { - delete tokens; - tokens = 0; - } + if (tokens) { + delete tokens; + tokens = 0; + } - Set(pathName, prop, noMap); - } else if (type == "TStringVector") { - TStringVector svec; - tokens = strValue.Tokenize(";"); - if (tokens == 0) { - cerr << endl << ">> **ERROR** Couldn't tokenize entry in Bool_t TMusrRunHeader::ExtractHeaderInformation(TObjArray *headerInfo, TString requestedPath)" << endl; - return false; + Set(pathName, prop); + } else if (type == "TStringVector") { + TStringVector svec; + tokens = strValue.Tokenize(";"); + if (tokens == 0) { + cerr << endl << ">> **ERROR** Couldn't tokenize entry in Bool_t TMusrRunHeader::ExtractHeaderInformation(TObjArray *headerInfo, TString requestedPath)" << endl; + return false; + } + for (Int_t i=0; iGetEntries(); i++) { + ostr = dynamic_cast(tokens->At(i)); + str = ostr->GetString(); + str.Remove(TString::kBoth, ' '); + svec.push_back(str); + } + if (tokens) { + delete tokens; + tokens = 0; + } + Set(pathName, svec); + } else if (type == "TIntVector") { + TIntVector ivec; + tokens = strValue.Tokenize(";"); + if (tokens == 0) { + cerr << endl << ">> **ERROR** Couldn't tokenize entry in Bool_t TMusrRunHeader::ExtractHeaderInformation(TObjArray *headerInfo, TString requestedPath)" << endl; + return false; + } + for (Int_t i=0; iGetEntries(); i++) { + ostr = dynamic_cast(tokens->At(i)); + ivec.push_back(ostr->GetString().Atoi()); + } + if (tokens) { + delete tokens; + tokens = 0; + } + Set(pathName, ivec); + } else if (type == "TDoubleVector") { + TDoubleVector dvec; + tokens = strValue.Tokenize(";"); + if (tokens == 0) { + cerr << endl << ">> **ERROR** Couldn't tokenize entry in Bool_t TMusrRunHeader::ExtractHeaderInformation(TObjArray *headerInfo, TString requestedPath)" << endl; + return false; + } + for (Int_t i=0; iGetEntries(); i++) { + ostr = dynamic_cast(tokens->At(i)); + dvec.push_back(ostr->GetString().Atoi()); + } + if (tokens) { + delete tokens; + tokens = 0; + } + Set(pathName, dvec); } - for (Int_t i=0; iGetEntries(); i++) { - ostr = dynamic_cast(tokens->At(i)); - str = ostr->GetString(); - str.Remove(TString::kBoth, ' '); - svec.push_back(str); - } - if (tokens) { - delete tokens; - tokens = 0; - } - Set(pathName, svec, noMap); - } else if (type == "TIntVector") { - TIntVector ivec; - tokens = strValue.Tokenize(";"); - if (tokens == 0) { - cerr << endl << ">> **ERROR** Couldn't tokenize entry in Bool_t TMusrRunHeader::ExtractHeaderInformation(TObjArray *headerInfo, TString requestedPath)" << endl; - return false; - } - for (Int_t i=0; iGetEntries(); i++) { - ostr = dynamic_cast(tokens->At(i)); - ivec.push_back(ostr->GetString().Atoi()); - } - if (tokens) { - delete tokens; - tokens = 0; - } - Set(pathName, ivec, noMap); - } else if (type == "TDoubleVector") { - TDoubleVector dvec; - tokens = strValue.Tokenize(";"); - if (tokens == 0) { - cerr << endl << ">> **ERROR** Couldn't tokenize entry in Bool_t TMusrRunHeader::ExtractHeaderInformation(TObjArray *headerInfo, TString requestedPath)" << endl; - return false; - } - for (Int_t i=0; iGetEntries(); i++) { - ostr = dynamic_cast(tokens->At(i)); - dvec.push_back(ostr->GetString().Atoi()); - } - if (tokens) { - delete tokens; - tokens = 0; - } - Set(pathName, dvec, noMap); } } @@ -1110,57 +1135,62 @@ void TMusrRunHeader::DumpHeader() cout << endl << "header info of file : " << fFileName; cout << endl << "***************************************"; - TString tstr(""), fmt(""), path(""), name(""); + TString str(""), tstr(""), fmt(""), path(""), name(""), currentPath(""); TMusrRunPhysicalQuantity prop; - // go through all folders - for (UInt_t i=0; i +- ; SP: [; ] digit = GetDecimalPlace(prop.GetError()); digit_d = GetLeastSignificantDigit(prop.GetDemand()); if (prop.GetDescription() != "n/a") { fmt.Form("%%s: %%.%dlf +- %%.%dlf %%s; SP: %%.%dlf; %%s", digit, digit, digit_d); + tstr.Form(fmt, prop.GetLabel().Data(), prop.GetValue(), prop.GetError(), prop.GetUnit().Data(), prop.GetDemand(), prop.GetDescription().Data()); } else { fmt.Form("%%s: %%.%dlf +- %%.%dlf %%s; SP: %%.%dlf", digit, digit, digit_d); tstr.Form(fmt, prop.GetLabel().Data(), prop.GetValue(), prop.GetError(), prop.GetUnit().Data(), prop.GetDemand()); } - } else if ((prop.GetDemand() == MRRH_UNDEFINED) && (prop.GetValue() != MRRH_UNDEFINED) && (prop.GetError() != MRRH_UNDEFINED) && - (prop.GetUnit() != "n/a")) { + } else if ((prop.GetDemand() == MRH_UNDEFINED) && (prop.GetValue() != MRH_UNDEFINED) && (prop.GetError() != MRH_UNDEFINED) && + (prop.GetUnit() != "n/a")) { // +- [; ] digit = GetDecimalPlace(prop.GetError()); if (prop.GetDescription() != "n/a") { fmt.Form("%%s: %%.%dlf +- %%.%dlf %%s; %%s", digit, digit); @@ -1169,8 +1199,8 @@ void TMusrRunHeader::DumpHeader() fmt.Form("%%s: %%.%dlf +- %%.%dlf %%s", digit, digit); tstr.Form(fmt, prop.GetLabel().Data(), prop.GetValue(), prop.GetError(), prop.GetUnit().Data()); } - } else if ((prop.GetDemand() == MRRH_UNDEFINED) && (prop.GetValue() != MRRH_UNDEFINED) && (prop.GetError() == MRRH_UNDEFINED) && - (prop.GetUnit() != "n/a")) { + } else if ((prop.GetDemand() == MRH_UNDEFINED) && (prop.GetValue() != MRH_UNDEFINED) && (prop.GetError() == MRH_UNDEFINED) && + (prop.GetUnit() != "n/a")) { // [; ] digit = GetLeastSignificantDigit(prop.GetValue()); if (prop.GetDescription() != "n/a") { fmt.Form("%%s: %%.%dlf %%s; %%s", digit); @@ -1179,8 +1209,8 @@ void TMusrRunHeader::DumpHeader() fmt.Form("%%s: %%.%dlf %%s", digit); tstr.Form(fmt, prop.GetLabel().Data(), prop.GetValue(), prop.GetUnit().Data()); } - } else if ((prop.GetDemand() != MRRH_UNDEFINED) && (prop.GetValue() != MRRH_UNDEFINED) && (prop.GetError() == MRRH_UNDEFINED) && - (prop.GetUnit() != "n/a")) { + } else if ((prop.GetDemand() != MRH_UNDEFINED) && (prop.GetValue() != MRH_UNDEFINED) && (prop.GetError() == MRH_UNDEFINED) && + (prop.GetUnit() != "n/a")) { // ; SP: [; ] digit = GetLeastSignificantDigit(prop.GetValue()); digit_d = GetLeastSignificantDigit(prop.GetDemand()); if (prop.GetDescription() != "n/a") { @@ -1191,51 +1221,63 @@ void TMusrRunHeader::DumpHeader() tstr.Form(fmt, prop.GetLabel().Data(), prop.GetValue(), prop.GetUnit().Data(), prop.GetDemand()); } } - cout << endl << " " << tstr.Data(); + str.Form(" %03d - %s -@%d", i, tstr.Data(), MRH_TMUSR_RUN_PHYSICAL_QUANTITY); + cout << endl << str; } } - - // TStringVector + // 5th check TStringVector for (UInt_t j=0; jchecks if a folder is present in the internal administration + *

extracts form the run header line, as written to the MusrROOT file, the run header label, e.g. Run Number. * - * \param path of the folder + * \param str runHeader string as written to the MusrROOT file. */ -Bool_t TMusrRunHeader::FolderPresent(TString &path) +TString TMusrRunHeader::GetLabel(TString str) { - for (UInt_t i=0; i - : -@ + + TString label = TString("n/a"); + Ssiz_t idx1 = str.First('-'); + Ssiz_t idx2 = str.First(':'); + if ((idx1 == -1) || (idx2 == -1)) { + cerr << endl << ">> TMusrRunHeader::GetLabel(): **ERROR** str='" << str << "', seems not correctly encoded." << endl; + return label; + } + + label = TString(""); + for (Int_t j=idx1+2; jextracts form the run header line, as written to the MusrROOT file, the run header str value, e.g. 557 (for Run Number). + * + * \param str runHeader string as written to the MusrROOT file. + */ +TString TMusrRunHeader::GetStrValue(TString str) +{ + // get run header string value + // the string 'str' should have the structure + // - : -@ + + TString strValue = TString("n/a"); + Ssiz_t idx1 = str.First(':'); + Ssiz_t idx2 = str.Last('-'); + if ((idx1 == -1) || (idx2 == -1)) { + cerr << endl << ">> TMusrRunHeader::GetStrValue(): **ERROR** str='" << str << "', seems not correctly encoded." << endl; + return strValue; + } + + strValue = TString(""); + for (Int_t j=idx1+2; jextracts form the run header line, as written to the MusrROOT file, the encoded type and retruns it. + * + * \param str runHeader string with encoded type + */ +TString TMusrRunHeader::GetType(TString str) +{ + TString result = "n/a"; + + // the string 'str' should have the structure + // - : -@ + Ssiz_t pos = str.Last('@'); + + if (pos == -1) { // i.e. NOT found + cerr << endl << ">> TMusrRunHeader::GetType(): **ERROR** str=" << str << " seems to be an invalid MusrROOT run header string." << endl; + return result; + } + + // filter out the encoded type declaration, i.e. -@, where is the encoded type + TString typeStr(str); + typeStr.Remove(0, pos+1); + Int_t typeVal; + if (!typeStr.IsDigit()) { + cerr << endl << ">> TMusrRunHeader::GetType(): **ERROR** typeStr=" << typeStr << " is not supported." << endl; + return result; + } + + typeVal = typeStr.Atoi(); + + switch (typeVal) { + case MRH_TSTRING: + result = "TString"; + break; + case MRH_INT: + result = "Int_t"; + break; + case MRH_DOUBLE: + result = "Double_t"; + break; + case MRH_TMUSR_RUN_PHYSICAL_QUANTITY: + result = "TMusrRunPhysicalQuantity"; + break; + case MRH_TSTRING_VECTOR: + result = "TStringVector"; + break; + case MRH_INT_VECTOR: + result = "TIntVector"; + break; + case MRH_DOUBLE_VECTOR: + result = "TDoubleVector"; + break; + default: + cerr << endl << ">> TMusrRunHeader::GetType(): **ERROR** found unsupport type encoded with: " << typeVal << "." << endl; + break; + } + + return result; +} + +//-------------------------------------------------------------------------- +// ObjectPresent (private) +//-------------------------------------------------------------------------- +/** + *

+ * + * \param content + * \param path + */ +Int_t TMusrRunHeader::ObjectPresent(vector &content, TString &path) +{ + for (UInt_t i=0; iGetName() == path) { + return (Int_t)i; + } + } + + return -1; +} + +//-------------------------------------------------------------------------- +// GetHeaderString (private) +//-------------------------------------------------------------------------- +/** + *

+ * + * \param pathName + */ +TObjString TMusrRunHeader::GetHeaderString(UInt_t idx) +{ + TObjString tostr("n/a"); + + TString str(""), path(""), name(""), fmt(""), tstr(""); + TMusrRunPhysicalQuantity prop; + + // go through all objects and try to find it + // 1st check TString + for (UInt_t j=0; j +- ; SP: [; ] + digit = GetDecimalPlace(prop.GetError()); + digit_d = GetLeastSignificantDigit(prop.GetDemand()); + if (prop.GetDescription() != "n/a") { + fmt.Form("%%s: %%.%dlf +- %%.%dlf %%s; SP: %%.%dlf; %%s", digit, digit, digit_d); + + tstr.Form(fmt, prop.GetLabel().Data(), prop.GetValue(), prop.GetError(), prop.GetUnit().Data(), prop.GetDemand(), prop.GetDescription().Data()); + } else { + fmt.Form("%%s: %%.%dlf +- %%.%dlf %%s; SP: %%.%dlf", digit, digit, digit_d); + tstr.Form(fmt, prop.GetLabel().Data(), prop.GetValue(), prop.GetError(), prop.GetUnit().Data(), prop.GetDemand()); + } + } else if ((prop.GetDemand() == MRH_UNDEFINED) && (prop.GetValue() != MRH_UNDEFINED) && (prop.GetError() != MRH_UNDEFINED) && + (prop.GetUnit() != "n/a")) { // +- [; ] + digit = GetDecimalPlace(prop.GetError()); + if (prop.GetDescription() != "n/a") { + fmt.Form("%%s: %%.%dlf +- %%.%dlf %%s; %%s", digit, digit); + tstr.Form(fmt, prop.GetLabel().Data(), prop.GetValue(), prop.GetError(), prop.GetUnit().Data(), prop.GetDescription().Data()); + } else { + fmt.Form("%%s: %%.%dlf +- %%.%dlf %%s", digit, digit); + tstr.Form(fmt, prop.GetLabel().Data(), prop.GetValue(), prop.GetError(), prop.GetUnit().Data()); + } + } else if ((prop.GetDemand() == MRH_UNDEFINED) && (prop.GetValue() != MRH_UNDEFINED) && (prop.GetError() == MRH_UNDEFINED) && + (prop.GetUnit() != "n/a")) { // [; ] + digit = GetLeastSignificantDigit(prop.GetValue()); + if (prop.GetDescription() != "n/a") { + fmt.Form("%%s: %%.%dlf %%s; %%s", digit); + tstr.Form(fmt, prop.GetLabel().Data(), prop.GetValue(), prop.GetUnit().Data(), prop.GetDescription().Data()); + } else { + fmt.Form("%%s: %%.%dlf %%s", digit); + tstr.Form(fmt, prop.GetLabel().Data(), prop.GetValue(), prop.GetUnit().Data()); + } + } else if ((prop.GetDemand() != MRH_UNDEFINED) && (prop.GetValue() != MRH_UNDEFINED) && (prop.GetError() == MRH_UNDEFINED) && + (prop.GetUnit() != "n/a")) { // ; SP: [; ] + digit = GetLeastSignificantDigit(prop.GetValue()); + digit_d = GetLeastSignificantDigit(prop.GetDemand()); + if (prop.GetDescription() != "n/a") { + fmt.Form("%%s: %%.%dlf %%s; SP: %%.%dlf; %%s", digit, digit_d); + tstr.Form(fmt, prop.GetLabel().Data(), prop.GetValue(), prop.GetUnit().Data(), prop.GetDemand(), prop.GetDescription().Data()); + } else { + fmt.Form("%%s: %%.%dlf %%s; SP: %%.%dlf", digit, digit_d); + tstr.Form(fmt, prop.GetLabel().Data(), prop.GetValue(), prop.GetUnit().Data(), prop.GetDemand()); + } + } + str.Form("%03d - %s -@%d", idx, tstr.Data(), MRH_TMUSR_RUN_PHYSICAL_QUANTITY); + tostr.SetString(str); + } + } + // 5th check TStringVector + for (UInt_t j=0; j + * + * \param str + * \param splitter + */ +void TMusrRunHeader::RemoveFirst(TString &str, const char splitter) +{ + Ssiz_t idx = str.First(splitter); + str.Remove(0, idx+1); +} + +//-------------------------------------------------------------------------- +// GetFirst (private) +//-------------------------------------------------------------------------- +/** + *

+ * + * \param str + * \param splitter + */ +TString TMusrRunHeader::GetFirst(TString &str, const char splitter) +{ + TString result = str; + + Ssiz_t idx = str.First(splitter); + result.Remove(idx, str.Length()); + + return result; +} + +//-------------------------------------------------------------------------- +// AddSubTrees (private) +//-------------------------------------------------------------------------- +/** + *

+ * + * \param content + * \param pathName + */ +void TMusrRunHeader::AddSubTrees(TObjArray *content, TString pathName) +{ + // check if element is already present + TString objName = GetFirst(pathName, '/'); + if (!content->FindObject(objName.Data())) { // object array not present yet, add it + TObjArray *oarray = new TObjArray(); + oarray->SetName(objName); + content->AddLast(oarray); + } + + // check if more sub trees are needed + TObjArray *tok = pathName.Tokenize('/'); + + if (tok->GetEntries() > 2) { // still sub trees present + RemoveFirst(pathName, '/'); + AddSubTrees((TObjArray*)content->FindObject(objName.Data()), pathName); + } + + if (tok) + delete tok; +} + +//-------------------------------------------------------------------------- +// SetSubTreeObject (private) +//-------------------------------------------------------------------------- +/** + *

+ * + * \param content + * \param ostr + */ +void TMusrRunHeader::SetSubTreeObject(TObjArray *content, TObjString ostr, Int_t idx) +{ + TObjArray *tok = fPathNameOrder[idx].Tokenize('/'); + TObjArray *pos = content; + + for (Int_t i=1; iGetEntries()-1; i++) { + pos = (TObjArray*)pos->FindObject(((TObjString*)tok->At(i))->GetString()); // go down the proper tree + if (pos == 0) { + cerr << endl << "TMusrRunHeader::SetSubTreeObject(): **ERROR** couldn't reach requested path: " << fPathNameOrder[idx]; + if (tok) + delete tok; + return; + } + } + TObjString *value = new TObjString(); + value = (TObjString*)ostr.Clone(); + pos->AddLast(value); + + if (tok) + delete tok; } // end --------------------------------------------------------------------- diff --git a/src/tests/PsiRoot/TMusrRunHeader.h b/src/tests/MusrRoot/TMusrRunHeader.h similarity index 82% rename from src/tests/PsiRoot/TMusrRunHeader.h rename to src/tests/MusrRoot/TMusrRunHeader.h index 5548d10b..c0b3fc86 100644 --- a/src/tests/PsiRoot/TMusrRunHeader.h +++ b/src/tests/MusrRoot/TMusrRunHeader.h @@ -37,10 +37,19 @@ #include #include #include -#include -#include +#include -#define MRRH_UNDEFINED -9.99e99 +#define MRH_UNDEFINED -9.99e99 + +#define MRH_DOUBLE_PREC 6 + +#define MRH_TSTRING 0 +#define MRH_INT 1 +#define MRH_DOUBLE 2 +#define MRH_TMUSR_RUN_PHYSICAL_QUANTITY 3 +#define MRH_TSTRING_VECTOR 4 +#define MRH_INT_VECTOR 5 +#define MRH_DOUBLE_VECTOR 6 typedef vector TIntVector; typedef vector TDoubleVector; @@ -119,7 +128,10 @@ public: virtual TString GetFileName() { return fFileName; } - virtual void GetHeaderInfo(TString path, TObjArray &content); + virtual Bool_t FillFolder(TFolder *folder); + + virtual Bool_t ExtractAll(TFolder *folder); + virtual Bool_t ExtractHeaderInformation(TObjArray *headerInfo, TString path); virtual void GetValue(TString pathName, TString &value, Bool_t &ok); virtual void GetValue(TString pathName, Int_t &value, Bool_t &ok); @@ -129,20 +141,15 @@ public: virtual void GetValue(TString pathName, TIntVector &value, Bool_t &ok); virtual void GetValue(TString pathName, TDoubleVector &value, Bool_t &ok); - virtual TMap* GetMap() { return &fMap; } - virtual void SetFileName(TString fln) { fFileName = fln; } - virtual void SetMap(TMap* map); - virtual void Set(TString pathName, TString value, Bool_t addMap=true); - virtual void Set(TString pathName, Int_t value, Bool_t addMap=true); - virtual void Set(TString pathName, Double_t value, Bool_t addMap=true); - virtual void Set(TString pathName, TMusrRunPhysicalQuantity value, Bool_t addMap=true); - virtual void Set(TString pathName, TStringVector value, Bool_t addMap=true); - virtual void Set(TString pathName, TIntVector value, Bool_t addMap=true); - virtual void Set(TString pathName, TDoubleVector value, Bool_t addMap=true); - - virtual Bool_t ExtractHeaderInformation(TObjArray *headerInfo, TString path); + virtual void Set(TString pathName, TString value); + virtual void Set(TString pathName, Int_t value); + virtual void Set(TString pathName, Double_t value); + virtual void Set(TString pathName, TMusrRunPhysicalQuantity value); + virtual void Set(TString pathName, TStringVector value); + virtual void Set(TString pathName, TIntVector value); + virtual void Set(TString pathName, TDoubleVector value); virtual void DumpHeader(); virtual void DrawHeader(); @@ -158,15 +165,23 @@ private: vector< TMusrRunObject > fIntVectorObj; vector< TMusrRunObject > fDoubleVectorObj; - TStringVector fFolder; + vector< TString > fPathNameOrder; ///< keeps the path-name as they or set and hence its ordering - TMap fMap; ///< maps run header label to its root type, e.g. 'Run Number' -> 'Int_t' or 'Time Resolution' -> 'TMusrRunPhysicalQuantity' - - virtual void Init(); virtual UInt_t GetDecimalPlace(Double_t val); virtual UInt_t GetLeastSignificantDigit(Double_t val) const; virtual void SplitPathName(TString pathName, TString &path, TString &name); - virtual Bool_t FolderPresent(TString &path); + + virtual TString GetLabel(TString str); + virtual TString GetStrValue(TString str); + virtual TString GetType(TString str); + + virtual Int_t ObjectPresent(vector &content, TString &path); + virtual TObjString GetHeaderString(UInt_t idx); + + virtual void RemoveFirst(TString &str, const char splitter); + virtual TString GetFirst(TString &str, const char splitter); + virtual void AddSubTrees(TObjArray *content, TString pathName); + virtual void SetSubTreeObject(TObjArray *content, TObjString ostr, Int_t idx); ClassDef(TMusrRunHeader, 1) }; diff --git a/src/tests/PsiRoot/TMusrRunHeaderLinkDef.h b/src/tests/MusrRoot/TMusrRunHeaderLinkDef.h similarity index 100% rename from src/tests/PsiRoot/TMusrRunHeaderLinkDef.h rename to src/tests/MusrRoot/TMusrRunHeaderLinkDef.h diff --git a/src/tests/MusrRoot/musrRoot_runHeader_test.cpp b/src/tests/MusrRoot/musrRoot_runHeader_test.cpp new file mode 100644 index 00000000..0165877a --- /dev/null +++ b/src/tests/MusrRoot/musrRoot_runHeader_test.cpp @@ -0,0 +1,144 @@ +/*************************************************************************** + + musrRoot_runHeader_test.cpp + + Author: Andreas Suter + e-mail: andreas.suter@psi.ch + + $Id$ + +***************************************************************************/ + +/*************************************************************************** + * Copyright (C) 2007-2012 by Andreas Suter * + * andreas.suter@psi.ch * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include +using namespace std; + +#include +#include +#include + +#include "TMusrRunHeader.h" + +void musrRoot_runHeader_test_syntax() +{ + cout << endl << "usage: musrRoot_runHeader_test "; + cout << endl << " is the file name including the extention root, e.g. test.root"; + cout << endl << endl; +} + +int main(int argc, char *argv[]) +{ + if (argc != 2) { + musrRoot_runHeader_test_syntax(); + return 1; + } + + // read the file and extract the header info + TFile *f = new TFile(argv[1], "READ", "musrRoot_runHeader_test"); + if (f->IsZombie()) { + delete f; + return -1; + } + + TFolder *runHeader = 0; + f->GetObject("RunHeader", runHeader); + if (runHeader == 0) { + cerr << endl << ">> **ERROR** Couldn't get top folder RunHeader"; + f->Close(); + return -1; + } + + // MusrRoot Run Header object + TMusrRunHeader *header = new TMusrRunHeader(argv[1]); + header->ExtractAll(runHeader); + + f->Close(); + delete f; + + header->DumpHeader(); + + // get some information from the read file + cout << endl << "++++++++++++++++++++++++++++"; + cout << endl << ">> get header infos " << argv[1]; + cout << endl << "++++++++++++++++++++++++++++" << endl; + + TString str(""); + TStringVector strVec; + Int_t ival; + TDoubleVector dvec; + TMusrRunPhysicalQuantity prop; + Bool_t ok; + + header->GetValue("RunInfo/Run Title", str, ok); + if (ok) + cout << endl << "Run Title: " << str.Data(); + else + cout << endl << "**ERROR** Couldn't obtain the 'Run Title'."; + + header->GetValue("RunInfo/Run Number", ival, ok); + if (ok) + cout << endl << "Run Number: " << ival; + else + cout << endl << "**ERROR** Couldn't obtain the 'Run Number'."; + + header->GetValue("RunInfo/Histo Names", strVec, ok); + if (ok) { + cout << endl << "Histo Names: "; + for (UInt_t i=0; iGetValue("RunInfo/Time Zero Bin", dvec, ok); + if (ok) { + cout << endl << "Time Zero Bin: "; + for (UInt_t i=0; iGetValue("RunInfo/Sample Temperature", prop, ok); + if (ok) { + cout << endl << "Sample Temperature: " << prop.GetValue() << " +- " << prop.GetError() << " " << prop.GetUnit().Data() << "; SP: " << prop.GetDemand() << "; " << prop.GetDescription().Data(); + } else { + cout << endl << "**ERROR** Couldn't obtain the 'Sample Temperature'."; + } + + header->GetValue("Detectors/Detector000/Name", str, ok); + if (ok) { + cout << endl << "Detectors/Detector000: Name=" << str; + } else { + cout << endl << "**ERROR** Couldn't obtain 'Detector/Detector000/Name'."; + } + + cout << endl << endl; + + delete header; + + return 0; +} diff --git a/src/tests/PsiRoot/read_musrRoot_runHeader.cpp b/src/tests/MusrRoot/read_musrRoot_runHeader.cpp similarity index 64% rename from src/tests/PsiRoot/read_musrRoot_runHeader.cpp rename to src/tests/MusrRoot/read_musrRoot_runHeader.cpp index 7f694f08..d54a3927 100644 --- a/src/tests/PsiRoot/read_musrRoot_runHeader.cpp +++ b/src/tests/MusrRoot/read_musrRoot_runHeader.cpp @@ -38,6 +38,15 @@ using namespace std; #include "TMusrRunHeader.h" +void closeFile(TFile *f) +{ + if (f == 0) + return; + + f->Close(); + delete f; +} + void read_musrRoot_runHeader_syntax() { cout << endl << "usage: read_musrRoot_runHeader "; @@ -63,63 +72,25 @@ int main(int argc, char *argv[]) f->GetObject("RunHeader", runHeader); if (runHeader == 0) { cerr << endl << ">> **ERROR** Couldn't get top folder RunHeader"; - f->Close(); + closeFile(f); return -1; } - TObjArray *oarray = 0; TMusrRunHeader *header = new TMusrRunHeader(argv[1]); - // first read map!! - TMap *map = (TMap*) runHeader->FindObjectAny("__map"); - if (map == 0) { - cerr << endl << ">> **ERROR** couldn't find required __map :-(" << endl; - f->Close(); + if (!header->ExtractAll(runHeader)) { + cerr << endl << ">> **ERROR** couldn't extract all RunHeader information :-(" << endl << endl; + closeFile(f); return -1; } - header->SetMap(map); - - // get RunHeader - oarray = (TObjArray*) runHeader->FindObjectAny("RunInfo"); - if (oarray == 0) { - cerr << endl << ">> **ERROR** Couldn't get RunInfo" << endl; - } - if (!header->ExtractHeaderInformation(oarray, "RunInfo")) return -1; - - - // get SampleEnv - oarray = (TObjArray*) runHeader->FindObjectAny("SampleEnv"); - if (oarray == 0) { - cerr << endl << ">> **ERROR** Couldn't get SampleEnv" << endl; - } - if (!header->ExtractHeaderInformation(oarray, "SampleEnv")) return -1; - - // get MagFieldEnv - oarray = (TObjArray*) runHeader->FindObjectAny("MagFieldEnv"); - if (oarray == 0) { - cerr << endl << ">> **ERROR** Couldn't get MagFieldEnv" << endl; - } - if (!header->ExtractHeaderInformation(oarray, "MagFieldEnv")) return -1; - - // get Beamline - oarray = (TObjArray*) runHeader->FindObjectAny("Beamline"); - if (oarray == 0) { - cerr << endl << ">> **ERROR** Couldn't get Beamline" << endl; - } - if (!header->ExtractHeaderInformation(oarray, "Beamline")) return -1; - - // get Scaler - oarray = (TObjArray*) runHeader->FindObjectAny("Scaler"); - if (oarray == 0) { - cerr << endl << ">> **ERROR** Couldn't get Scaler" << endl; - } - if (!header->ExtractHeaderInformation(oarray, "Scaler")) return -1; f->Close(); delete f; header->DumpHeader(); + delete header; + cout << endl << endl; return 0; diff --git a/src/tests/PsiRoot/write_musrRoot_runHeader.cpp b/src/tests/MusrRoot/write_musrRoot_runHeader.cpp similarity index 77% rename from src/tests/PsiRoot/write_musrRoot_runHeader.cpp rename to src/tests/MusrRoot/write_musrRoot_runHeader.cpp index 41b46416..0288b1f3 100644 --- a/src/tests/PsiRoot/write_musrRoot_runHeader.cpp +++ b/src/tests/MusrRoot/write_musrRoot_runHeader.cpp @@ -112,13 +112,14 @@ int main(int argc, char *argv[]) prop.Set("Time Resolution", 0.1953125, "ns", "TDC 9999"); header->Set("RunInfo/Time Resolution", prop); - TIntVector t0; - for (UInt_t i=0; i<4; i++) t0.push_back(215+(Int_t)(5.0*(Double_t)rand()/(Double_t)RAND_MAX)); + TDoubleVector t0; + TIntVector ivec; + for (UInt_t i=0; i<4; i++) t0.push_back(215.0+5.0*(Double_t)rand()/(Double_t)RAND_MAX); header->Set("RunInfo/Time Zero Bin", t0); - for (UInt_t i=0; i<4; i++) t0[i] += 12; - header->Set("RunInfo/First Good Bin", t0); - for (UInt_t i=0; i<4; i++) t0[i] = 8191; - header->Set("RunInfo/Last Good Bin", t0); + for (UInt_t i=0; i<4; i++) ivec.push_back((Int_t)t0[i] + 12); + header->Set("RunInfo/First Good Bin", ivec); + for (UInt_t i=0; i<4; i++) ivec[i] = 8191; + header->Set("RunInfo/Last Good Bin", ivec); TIntVector readGreenOffset; readGreenOffset.push_back(0); @@ -146,40 +147,54 @@ int main(int argc, char *argv[]) header->Set("RunInfo/Dummy Test", dummyTest); // sample environment - header->Set("SampleEnv/Cryo", "Konti-1"); - header->Set("SampleEnv/Insert", "X123"); - header->Set("SampleEnv/Orientation", "c-axis perp spin, perp field. spin perp field"); + header->Set("SampleEnvironmentInfo/Cryo", "Konti-1"); + header->Set("SampleEnvironmentInfo/Insert", "X123"); + header->Set("SampleEnvironmentInfo/Orientation", "c-axis perp spin, perp field. spin perp field"); prop.Set("CF2", 3.2, 3.22, 0.04, "K"); - header->Set("SampleEnv/CF2", prop); + header->Set("SampleEnvironmentInfo/CF2", prop); - prop.Set("CF3", MRRH_UNDEFINED, 3.27, 0.09, "K", "strange temperature"); - header->Set("SampleEnv/CF3", prop); + prop.Set("CF3", MRH_UNDEFINED, 3.27, 0.09, "K", "strange temperature"); + header->Set("SampleEnvironmentInfo/CF3", prop); prop.Set("CF4", 3.25, 3.28, "K"); - header->Set("SampleEnv/CF4", prop); + header->Set("SampleEnvironmentInfo/CF4", prop); prop.Set("CF5", 3.26, 3.29, "K", "another strange temperature"); - header->Set("SampleEnv/CF5", prop); + header->Set("SampleEnvironmentInfo/CF5", prop); prop.Set("Dummy Prop", -2.0, -2.001, 0.002, "SI-unit"); - header->Set("SampleEnv/Dummy Prop", prop); + header->Set("SampleEnvironmentInfo/Dummy Prop", prop); // magnetic field environment - header->Set("MagFieldEnv/Name", "Bpar"); + header->Set("MagneticFieldEnvironmentInfo/Name", "Bpar"); prop.Set("Current", 1.34, "A"); - header->Set("MagFieldEnv/Current", prop); + header->Set("MagneticFieldEnvironmentInfo/Current", prop); + + // detector forward + header->Set("Detectors/Detector000/Name", "forward"); + header->Set("Detectors/Detector000/Histo Number", 0); + header->Set("Detectors/Detector000/Histo Length", 8192); + + // detector backward + header->Set("Detectors/Detector001/Name", "backward"); + header->Set("Detectors/Detector001/Histo Number", 0); + header->Set("Detectors/Detector001/Histo Length", 8192); // beamline - header->Set("Beamline/WSX61a", "DAC = 3289, ADC = 0.800"); + header->Set("BeamlineInfo/WSX61a", "DAC = 3289, ADC = 0.800"); TIntVector dummyInt; for (UInt_t i=0; i<3; i++) dummyInt.push_back(i+1000); - header->Set("Beamline/Dummy Int", dummyInt); + header->Set("BeamlineInfo/Dummy Int", dummyInt); // scaler - header->Set("Scaler/Ip", 12332123); + header->Set("ScalerInfo/Ip", 12332123); + + // funny sub/sub/../sub-structure + header->Set("aa/bb/cc/dd/ee/ff/name", "funny"); + header->Set("aa/bb/cc/dd/ee/ff/gg/xyz", 123); TFile *f = new TFile(argv[1], "RECREATE", "write_musrRoot_runHeader"); if (f->IsZombie()) { @@ -191,35 +206,15 @@ int main(int argc, char *argv[]) TFolder *runHeader = gROOT->GetRootFolder()->AddFolder("RunHeader", "MusrRoot Run Header Info"); gROOT->GetListOfBrowsables()->Add(runHeader, "RunHeader"); - TObjArray runInfo; - header->GetHeaderInfo("RunInfo", runInfo); - runHeader->Add(&runInfo); - - TObjArray sampleEnv; - header->GetHeaderInfo("SampleEnv", sampleEnv); - runHeader->Add(&sampleEnv); - - TObjArray magFieldEnv; - header->GetHeaderInfo("MagFieldEnv", magFieldEnv); - runHeader->Add(&magFieldEnv); - - TObjArray beamline; - header->GetHeaderInfo("Beamline", beamline); - runHeader->Add(&beamline); - - TObjArray scaler; - header->GetHeaderInfo("Scaler", scaler); - runHeader->Add(&scaler); - - TMap *map = header->GetMap(); - runHeader->Add(map); - - runHeader->Write(); + if (header->FillFolder(runHeader)) { + runHeader->Write(); + } f->Close(); + // clean up delete f; - f = 0; + delete header; return 0; } diff --git a/src/tests/PsiRoot/musrRoot_runHeader_test.cpp b/src/tests/PsiRoot/musrRoot_runHeader_test.cpp deleted file mode 100644 index 8a7cf5b0..00000000 --- a/src/tests/PsiRoot/musrRoot_runHeader_test.cpp +++ /dev/null @@ -1,303 +0,0 @@ -/*************************************************************************** - - musrRoot_runHeader_test.cpp - - Author: Andreas Suter - e-mail: andreas.suter@psi.ch - - $Id$ - -***************************************************************************/ - -/*************************************************************************** - * Copyright (C) 2007-2012 by Andreas Suter * - * andreas.suter@psi.ch * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -using namespace std; - -#include -#include -#include - -#include "TMusrRunHeader.h" - -void musrRoot_runHeader_test_syntax() -{ - cout << endl << "usage: musrRoot_runHeader_test "; - cout << endl << " is the file name including the extention root, e.g. test.root"; - cout << endl << endl; -} - -int main(int argc, char *argv[]) -{ - if (argc != 2) { - musrRoot_runHeader_test_syntax(); - return 1; - } - - // MusrRoot Run Header object - TMusrRunHeader *header = new TMusrRunHeader(argv[1]); - TMusrRunPhysicalQuantity prop; - - // run info - header->Set("RunInfo/Version", "$Id$"); - header->Set("RunInfo/Generator", "any2many"); - header->Set("RunInfo/File Name", "thisIsAFileName"); - header->Set("RunInfo/Run Title", "here comes the run title"); - header->Set("RunInfo/Run Number", 576); - header->Set("RunInfo/Run Number", 577); - header->Set("RunInfo/Run Start Time", "2011-04-19 14:25:22"); - header->Set("RunInfo/Run Stop Time", "2011-04-19 19:13:47"); - - prop.Set("Time Resolution", 0.1953125, "ns", "TDC 9999"); - header->Set("RunInfo/Time Resolution", prop); - - prop.Set("Sample Temperature", 3.2, 3.21, 0.05, "K", "CF1"); - header->Set("RunInfo/Sample Temperature", prop); - - prop.Set("Muon Beam Momentum", MRRH_UNDEFINED, 28.1, MRRH_UNDEFINED, "MeV/c"); - header->Set("RunInfo/Muon Beam Momentum", prop); - - TStringVector detectorName; - detectorName.push_back("left_down"); - detectorName.push_back("left_up"); - detectorName.push_back("top_down"); - detectorName.push_back("top_up"); - detectorName.push_back("right_down"); - detectorName.push_back("right_up"); - detectorName.push_back("bottom_down"); - detectorName.push_back("bottom_up"); - header->Set("RunInfo/Histo Names", detectorName); - - TDoubleVector t0; - for (UInt_t i=0; i<8; i++) t0.push_back(3419.0); - header->Set("RunInfo/Time Zero Bin", t0); - - TStringVector dummyTest; - dummyTest.push_back("dummy1"); - dummyTest.push_back("dummy2"); - dummyTest.push_back("dummy3"); - header->Set("RunInfo/Dummy Test", dummyTest); - - // sample environment - header->Set("SampleEnv/Cryo", "Konti-1"); - - prop.Set("CF2", 3.2, 3.22, 0.04, "K"); - header->Set("SampleEnv/CF2", prop); - - prop.Set("CF3", MRRH_UNDEFINED, 3.27, 0.09, "K", "strange temperature"); - header->Set("SampleEnv/CF3", prop); - - prop.Set("CF4", 3.25, 3.28, "K"); - header->Set("SampleEnv/CF4", prop); - - prop.Set("CF5", 3.26, 3.29, "K", "another strange temperature"); - header->Set("SampleEnv/CF5", prop); - - prop.Set("Dummy Prop", -2.0, -2.001, 0.002, "SI-unit"); - header->Set("SampleEnv/Dummy Prop", prop); - - // magnetic field environment - header->Set("MagFieldEnv/Name", "Bpar"); - prop.Set("Current", 1.34, "A"); - header->Set("MagFieldEnv/Current", prop); - - // beamline - header->Set("Beamline/WSX61a", "DAC = 3289, ADC = 0.800"); - - TIntVector dummyInt; - for (UInt_t i=0; i<3; i++) dummyInt.push_back(i+1000); - header->Set("Beamline/Dummy Int", dummyInt); - - // scaler - header->Set("Scaler/Ip", 12332123); - - TFile *f = new TFile(argv[1], "RECREATE", "musrRoot_runHeader_test"); - if (f->IsZombie()) { - delete f; - return -1; - } - - // root file header related things - TFolder *runHeader = gROOT->GetRootFolder()->AddFolder("RunHeader", "MusrRoot Run Header Info"); - gROOT->GetListOfBrowsables()->Add(runHeader, "RunHeader"); - - TObjArray runInfo; - header->GetHeaderInfo("RunInfo", runInfo); - runHeader->Add(&runInfo); - - TObjArray sampleEnv; - header->GetHeaderInfo("SampleEnv", sampleEnv); - runHeader->Add(&sampleEnv); - - TObjArray magFieldEnv; - header->GetHeaderInfo("MagFieldEnv", magFieldEnv); - runHeader->Add(&magFieldEnv); - - TObjArray beamline; - header->GetHeaderInfo("Beamline", beamline); - runHeader->Add(&beamline); - - TObjArray scaler; - header->GetHeaderInfo("Scaler", scaler); - runHeader->Add(&scaler); - - TMap *map = header->GetMap(); - runHeader->Add(map); - - runHeader->Write(); - - f->Close(); - - delete f; - f = 0; - - header->DumpHeader(); - - delete header; - header = 0; - - cout << endl << "++++++++++++++++++++++++++++"; - cout << endl << ">> read back " << argv[1]; - cout << endl << "++++++++++++++++++++++++++++" << endl; - - // read the file back and extract the header info - f = new TFile(argv[1], "READ", "musrRoot_runHeader_test"); - if (f->IsZombie()) { - delete f; - return -1; - } - - runHeader = 0; - f->GetObject("RunHeader", runHeader); - if (runHeader == 0) { - cerr << endl << ">> **ERROR** Couldn't get top folder RunHeader"; - f->Close(); - return -1; - } - - TObjArray *oarray = 0; - header = new TMusrRunHeader(argv[1]); - - map = (TMap*) runHeader->FindObjectAny("__map"); - if (map == 0) { - cerr << endl << ">> **ERROR** couldn't find required __map :-(" << endl; - f->Close(); - return -1; - } - header->SetMap(map); - - // get RunHeader - oarray = (TObjArray*) runHeader->FindObjectAny("RunInfo"); - if (oarray == 0) { - cerr << endl << ">> **ERROR** Couldn't get RunInfo" << endl; - } - header->ExtractHeaderInformation(oarray, "RunInfo"); - - // get SampleEnv - oarray = (TObjArray*) runHeader->FindObjectAny("SampleEnv"); - if (oarray == 0) { - cerr << endl << ">> **ERROR** Couldn't get SampleEnv" << endl; - } - header->ExtractHeaderInformation(oarray, "SampleEnv"); - - // get MagFieldEnv - oarray = (TObjArray*) runHeader->FindObjectAny("MagFieldEnv"); - if (oarray == 0) { - cerr << endl << ">> **ERROR** Couldn't get MagFieldEnv" << endl; - } - header->ExtractHeaderInformation(oarray, "MagFieldEnv"); - - // get Beamline - oarray = (TObjArray*) runHeader->FindObjectAny("Beamline"); - if (oarray == 0) { - cerr << endl << ">> **ERROR** Couldn't get Beamline" << endl; - } - header->ExtractHeaderInformation(oarray, "Beamline"); - - // get Scaler - oarray = (TObjArray*) runHeader->FindObjectAny("Scaler"); - if (oarray == 0) { - cerr << endl << ">> **ERROR** Couldn't get Scaler" << endl; - } - header->ExtractHeaderInformation(oarray, "Scaler"); - - f->Close(); - delete f; - - header->DumpHeader(); - - // get some information from the read file - cout << endl << "++++++++++++++++++++++++++++"; - cout << endl << ">> get header infos " << argv[1]; - cout << endl << "++++++++++++++++++++++++++++" << endl; - - TString str(""); - TStringVector strVec; - Int_t ival; - TDoubleVector dvec; - TMusrRunPhysicalQuantity prop1; - Bool_t ok; - - header->GetValue("RunInfo/Run Title", str, ok); - if (ok) - cout << endl << "Run Title: " << str.Data(); - else - cout << endl << "**ERROR** Couldn't obtain the 'Run Title'."; - - header->GetValue("RunInfo/Run Number", ival, ok); - if (ok) - cout << endl << "Run Number: " << ival; - else - cout << endl << "**ERROR** Couldn't obtain the 'Run Number'."; - - header->GetValue("RunInfo/Histo Names", strVec, ok); - if (ok) { - cout << endl << "Histo Names: "; - for (UInt_t i=0; iGetValue("RunInfo/Time Zero Bin", dvec, ok); - if (ok) { - cout << endl << "Time Zero Bin: "; - for (UInt_t i=0; iGetValue("RunInfo/Sample Temperature", prop1, ok); - if (ok) { - cout << endl << "Sample Temperature: " << prop1.GetValue() << " +- " << prop1.GetError() << " " << prop1.GetUnit().Data() << "; SP: " << prop1.GetDemand() << "; " << prop1.GetDescription().Data(); - } else { - cout << endl << "**ERROR** Couldn't obtain the 'Sample Temperature'."; - } - - cout << endl << endl; - - return 0; -}