diff --git a/src/tests/PsiRoot/TPsiRunHeader.cpp b/src/tests/PsiRoot/TPsiRunHeader.cpp index 1905fd0b..fa1d5dc4 100644 --- a/src/tests/PsiRoot/TPsiRunHeader.cpp +++ b/src/tests/PsiRoot/TPsiRunHeader.cpp @@ -37,6 +37,9 @@ using namespace std; #include #include +#include +#include +#include #define TPRH_VERSION_IDX 0 #define TPRH_RUN_TITLE_IDX 1 @@ -49,6 +52,8 @@ using namespace std; #define TPRH_OFFSET 9 +#define TPRH_MIN_NO_REQUIRED_ENTRIES 10 + ClassImp(TPsiRunProperty) //-------------------------------------------------------------------------- @@ -188,10 +193,10 @@ TObjArray* TPsiRunHeader::GetHeader() for (UInt_t i=0; i> TPsiRunHeader::ExtractHeaderInformation(..) **ERROR** runHeader object pointer is 0" << endl << endl; + return false; + } + + // check if the minimum of required entries is present + if (runHeader->GetEntries() < TPRH_MIN_NO_REQUIRED_ENTRIES) { + cerr << endl << ">> TPsiRunHeader::ExtractHeaderInformation(..) **ERROR** runHeader object has " << runHeader->GetEntries() << " entries."; + cerr << endl << ">> minimum number of required entries = " << TPRH_MIN_NO_REQUIRED_ENTRIES << "!" << endl << endl; + return false; + } + + // start extracting entries + TObjString *ostr; + TString str(""); + Int_t idx, status, ival; + + // not TPsiRunProperty header variables + for (Int_t i=0; i(runHeader->At(i)); + str = ostr->GetString(); + + if (str.BeginsWith("01 - Version: ")) { + idx = str.Index(":"); + str.Remove(0, idx+2); + fVersion = str; + } else if (str.BeginsWith("02 - Run Title: ")) { + idx = str.Index(":"); + str.Remove(0, idx+2); + fRunTitle = str; + } else if (str.BeginsWith("03 - Run Number: ")) { + status = sscanf(str.Data(), "03 - Run Number: %d", &ival); + if (status != 1) { + cerr << endl << ">> TPsiRunHeader::ExtractHeaderInformation(..) **ERROR** " << str.Data() << " doesn't contain a valid run number" << endl << endl; + return false; + } + fRunNumber = ival; + } else if (str.BeginsWith("04 - Laboratory: ")) { + idx = str.Index(":"); + str.Remove(0, idx+2); + fLaboratory = str; + } else if (str.BeginsWith("05 - Instrument: ")) { + idx = str.Index(":"); + str.Remove(0, idx+2); + fInstrument = str; + } else if (str.BeginsWith("06 - Setup: ")) { + idx = str.Index(":"); + str.Remove(0, idx+2); + fSetup = str; + } else if (str.BeginsWith("07 - Sample: ")) { + idx = str.Index(":"); + str.Remove(0, idx+2); + fSample = str; + } else if (str.BeginsWith("08 - Orientation: ")) { + idx = str.Index(":"); + str.Remove(0, idx+2); + fOrientation = str; + } + } + + // TPsiRunProperty header variables + + // remove potential left over properties + fProperties.clear(); + + Double_t dval, derr; + TString name(""), unit(""); + char cstr[128]; + for (Int_t i=TPRH_OFFSET-1; iGetEntries(); i++) { + ostr = dynamic_cast(runHeader->At(i)); + str = ostr->GetString(); + + name = TString(""); + unit = TString(""); + + // 1st get the name + idx = str.Index("-"); + str.Remove(0, idx+2); + idx = str.Index(":"); + str.Remove(idx, str.Length()); + name = str; + + // 2nd get the value + str = ostr->GetString(); + idx = str.Index(":"); + str.Remove(0, idx+2); + idx = str.Index("+-"); + str.Remove(idx, str.Length()); + if (!str.IsFloat()) { + cerr << endl << ">> TPsiRunHeader::ExtractHeaderInformation(..) **ERROR** in TPsiRunProperty:"; + cerr << endl << ">> found " << ostr->GetString().Data() << ", which has an invalid format." << endl << endl; + return false; + } + dval = str.Atof(); + + // 3rd get the error, and unit + str = ostr->GetString(); + idx = str.Index("+-"); + str.Remove(0, idx+3); + memset(cstr, 0, sizeof(cstr)); + status = sscanf(str.Data(), "%lf %s", &derr, cstr); + if (status < 2) { + cerr << endl << ">> TPsiRunHeader::ExtractHeaderInformation(..) **ERROR** in TPsiRunProperty:"; + cerr << endl << ">> found " << ostr->GetString().Data() << ", which has an invalid format." << endl << endl; + return false; + } + if (strlen(cstr) > 0) + unit = TString(cstr); + + AddProperty(name, dval, derr, unit); + } + return true; } diff --git a/src/tests/PsiRoot/psi_runHeader_test.cpp b/src/tests/PsiRoot/psi_runHeader_test.cpp index 5c1f8ca3..d3e3a9e3 100644 --- a/src/tests/PsiRoot/psi_runHeader_test.cpp +++ b/src/tests/PsiRoot/psi_runHeader_test.cpp @@ -68,8 +68,7 @@ int main(int argc, char *argv[]) header->AddProperty("Field", 3.00003, 0.0003, "T"); header->AddProperty("BigError", 13.2, 1.2, "Something"); header->AddProperty("ThisIsAVeryLongPropertyName", 3.03, 0.03, "SI-Unit"); - - header->DumpHeader(); + header->AddProperty("This Is A Property With Spaces", 3.03, 0.03, "SI-Unit"); TFile *f = new TFile(argv[1], "RECREATE", "psi_runHeader_test"); if (f->IsZombie()) { @@ -93,5 +92,10 @@ int main(int argc, char *argv[]) delete f; + header->ExtractHeaderInformation(header->GetHeader()); + header->DumpHeader(); + + delete header; + return 0; }