From 634077d772f55278c12c5476251466e814c2b7db Mon Sep 17 00:00:00 2001 From: Andreas Suter Date: Thu, 12 Jan 2012 09:55:19 +0000 Subject: [PATCH] work in the direction of MusrROOT data file format. Use XSD instead of XML to validate. Work in progress ... --- src/tests/PsiRoot/Makefile | 32 +- ....TPsiRunHeader => Makefile.TMusrRunHeader} | 14 +- src/tests/PsiRoot/Makefile.arch | 2 +- src/tests/PsiRoot/TMusrRunHeader.cpp | 1358 +++++++++++++ .../{TPsiRunHeader.h => TMusrRunHeader.h} | 148 +- ...eaderLinkDef.h => TMusrRunHeaderLinkDef.h} | 9 +- src/tests/PsiRoot/TPsiRunHeader.cpp | 1705 ----------------- ...r_test.cpp => musrRoot_runHeader_test.cpp} | 86 +- src/tests/PsiRoot/psi_root.xml | 165 -- src/tests/PsiRoot/psi_root_test.xml | 85 - ...Header.cpp => read_musrRoot_runHeader.cpp} | 54 +- ...eader.cpp => write_musrRoot_runHeader.cpp} | 45 +- 12 files changed, 1519 insertions(+), 2184 deletions(-) rename src/tests/PsiRoot/{Makefile.TPsiRunHeader => Makefile.TMusrRunHeader} (94%) create mode 100644 src/tests/PsiRoot/TMusrRunHeader.cpp rename src/tests/PsiRoot/{TPsiRunHeader.h => TMusrRunHeader.h} (57%) rename src/tests/PsiRoot/{TPsiRunHeaderLinkDef.h => TMusrRunHeaderLinkDef.h} (89%) delete mode 100644 src/tests/PsiRoot/TPsiRunHeader.cpp rename src/tests/PsiRoot/{psi_runHeader_test.cpp => musrRoot_runHeader_test.cpp} (82%) delete mode 100644 src/tests/PsiRoot/psi_root.xml delete mode 100644 src/tests/PsiRoot/psi_root_test.xml rename src/tests/PsiRoot/{read_psi_runHeader.cpp => read_musrRoot_runHeader.cpp} (73%) rename src/tests/PsiRoot/{write_psi_runHeader.cpp => write_musrRoot_runHeader.cpp} (86%) diff --git a/src/tests/PsiRoot/Makefile b/src/tests/PsiRoot/Makefile index fe2d6bc2..0b193e27 100644 --- a/src/tests/PsiRoot/Makefile +++ b/src/tests/PsiRoot/Makefile @@ -61,36 +61,36 @@ LIBS = $(ROOTLIBS) -lXMLParser GLIBS = $(ROOTGLIBS) -lXMLParser # PSI libs -PSILIBS = -lTPsiRunHeader +PSILIBS = -lTMusrRunHeader EXEC = -EXEC += psi_runHeader_test -EXEC += write_psi_runHeader -EXEC += read_psi_runHeader +EXEC += musrRoot_runHeader_test +EXEC += write_musrRoot_runHeader +EXEC += read_musrRoot_runHeader # some definitions: headers (used to generate *Dict* stuff), sources, objects,... OBJS = -OBJS += psi_runHeader_test.o -OBJS += write_psi_runHeader.o -OBJS += read_psi_runHeader.o +OBJS += musrRoot_runHeader_test.o +OBJS += write_musrRoot_runHeader.o +OBJS += read_musrRoot_runHeader.o # make the executable: # all: $(EXEC) -psi_runHeader_test: psi_runHeader_test.o - @echo "---> Building psi_runHeader_test ..." - $(LD) psi_runHeader_test.o -o psi_runHeader_test $(GLIBS) $(PSILIBS) +musrRoot_runHeader_test: musrRoot_runHeader_test.o + @echo "---> Building musrRoot_runHeader_test ..." + $(LD) musrRoot_runHeader_test.o -o musrRoot_runHeader_test $(GLIBS) $(PSILIBS) @echo "done" -write_psi_runHeader: write_psi_runHeader.o - @echo "---> Building write_psi_runHeader ..." - $(LD) write_psi_runHeader.o -o write_psi_runHeader $(GLIBS) $(PSILIBS) +write_musrRoot_runHeader: write_musrRoot_runHeader.o + @echo "---> Building write_musrRoot_runHeader ..." + $(LD) write_musrRoot_runHeader.o -o write_musrRoot_runHeader $(GLIBS) $(PSILIBS) @echo "done" -read_psi_runHeader: read_psi_runHeader.o - @echo "---> Building read_psi_runHeader ..." - $(LD) read_psi_runHeader.o -o read_psi_runHeader $(GLIBS) $(PSILIBS) +read_musrRoot_runHeader: read_musrRoot_runHeader.o + @echo "---> Building read_musrRoot_runHeader ..." + $(LD) read_musrRoot_runHeader.o -o read_musrRoot_runHeader $(GLIBS) $(PSILIBS) @echo "done" # clean up: remove all object file (and core files) diff --git a/src/tests/PsiRoot/Makefile.TPsiRunHeader b/src/tests/PsiRoot/Makefile.TMusrRunHeader similarity index 94% rename from src/tests/PsiRoot/Makefile.TPsiRunHeader rename to src/tests/PsiRoot/Makefile.TMusrRunHeader index 9307f4a2..1026804d 100644 --- a/src/tests/PsiRoot/Makefile.TPsiRunHeader +++ b/src/tests/PsiRoot/Makefile.TMusrRunHeader @@ -1,18 +1,18 @@ -# Makefile for TPH1F +# Makefile for TMusrRunHeader # # Copyright (c) 2000 Rene Brun and Fons Rademakers # # Author: Fons Rademakers, 29/2/2000 # -# modified: Andreas Suter, 14/04/2004 -# modified: Thomas Prokscha, 30/01/2007 -# +# modified: Andreas Suter, 12/01/2012 +# +# $Id$ # include Makefile.arch #------------------------------------------------------------------------------ -# TPsiRunHeader -TNAME = TPsiRunHeader +# TMusrRunHeader +TNAME = TMusrRunHeader TLRHO = $(TNAME).$(ObjSuf) $(TNAME)Dict.$(ObjSuf) TLRHS = $(TNAME).$(SrcSuf) $(TNAME)Dict.$(SrcSuf) TLRHSO = lib$(TNAME).$(DllSuf) @@ -84,7 +84,7 @@ distclean: clean @rm -rf cxx_repository -@cd RootShower && $(MAKE) distclean -install: +install: $(TLRHS) $(TLRHSO) ifeq ($(ARCH),linux) cp -pv $(MYLIBS)/$(TLRHSO) $(ROOTSYS)/lib cp -pv $(MYINCLUDES)/$(TNAME).h $(ROOTSYS)/include diff --git a/src/tests/PsiRoot/Makefile.arch b/src/tests/PsiRoot/Makefile.arch index e1eb6fe5..afd8967f 100644 --- a/src/tests/PsiRoot/Makefile.arch +++ b/src/tests/PsiRoot/Makefile.arch @@ -10,7 +10,7 @@ ARCH := $(shell root-config --arch) CXX = ObjSuf = o -SrcSuf = cxx +SrcSuf = cpp ExeSuf = DllSuf = so OutPutOpt = -o # keep whitespace after "-o" diff --git a/src/tests/PsiRoot/TMusrRunHeader.cpp b/src/tests/PsiRoot/TMusrRunHeader.cpp new file mode 100644 index 00000000..a23221fd --- /dev/null +++ b/src/tests/PsiRoot/TMusrRunHeader.cpp @@ -0,0 +1,1358 @@ +/*************************************************************************** + + TMusrRunHeader.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 +#include +#include +#include +using namespace std; + +#include "TMusrRunHeader.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +ClassImp(TMusrRunPhysicalQuantity) + +//-------------------------------------------------------------------------- +// Constructor +//-------------------------------------------------------------------------- +/** + *

Constructor. + */ +TMusrRunPhysicalQuantity::TMusrRunPhysicalQuantity() +{ + fLabel = "n/a"; + fDemand = MRRH_UNDEFINED; + fValue = MRRH_UNDEFINED; + fError = MRRH_UNDEFINED; + fUnit = "n/a"; + fDescription = "n/a"; +} + +//-------------------------------------------------------------------------- +// Constructor +//-------------------------------------------------------------------------- +/** + *

Constructor. + * + * \param label of the physical quantity, e.g. 'Sample Temperature' + * \param demand value of the physical quantity + * \param value measured value of the physical quantity + * \param error estimated error of the physical quantity + * \param unit of the physical quantity, e.g. 'K'. + * \param description additional more detailed description of the physical quantity + */ +TMusrRunPhysicalQuantity::TMusrRunPhysicalQuantity(TString label, Double_t demand, Double_t value, Double_t error, TString unit, TString description) : + fLabel(label), fDemand(demand), fValue(value), fError(error), fUnit(unit) +{ + if (description.IsWhitespace()) + fDescription = "n/a"; + else + fDescription = description; +} + +//-------------------------------------------------------------------------- +// Constructor +//-------------------------------------------------------------------------- +/** + *

Constructor. + * + * \param label of the physical quantity, e.g. 'Sample Temperature' + * \param demand value of the physical quantity + * \param value measured value of the physical quantity + * \param unit of the physical quantity, e.g. 'K'. + * \param description additional more detailed description of the physical quantity + */ +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; + if (description.IsWhitespace()) + fDescription = "n/a"; + else + fDescription = description; +} + +//-------------------------------------------------------------------------- +// Constructor +//-------------------------------------------------------------------------- +/** + *

Constructor. + * + * \param label of the physical quantity, e.g. 'Sample Temperature' + * \param value measured value of the physical quantity + * \param unit of the physical quantity, e.g. 'K'. + * \param description additional more detailed description of the physical quantity + */ +TMusrRunPhysicalQuantity::TMusrRunPhysicalQuantity(TString label, Double_t value, TString unit, TString description) : + fLabel(label), fValue(value), fUnit(unit) +{ + fDemand = MRRH_UNDEFINED; + fError = MRRH_UNDEFINED; + if (description.IsWhitespace()) + fDescription = "n/a"; + else + fDescription = description; +} + +//-------------------------------------------------------------------------- +// Set (public) +//-------------------------------------------------------------------------- +/** + *

set a physical quantity. + * + * \param label of the physical quantity, e.g. 'Sample Temperature' + * \param demand value of the physical quantity + * \param value measured value of the physical quantity + * \param error estimated error of the physical quantity + * \param unit of the physical quantity, e.g. 'K'. + * \param description additional more detailed description of the physical quantity + */ +void TMusrRunPhysicalQuantity::Set(TString label, Double_t demand, Double_t value, Double_t error, TString unit, TString description) +{ + fLabel = label; + fDemand = demand; + fValue = value; + fError = error; + fUnit = unit; + if (description.IsWhitespace()) + fDescription = "n/a"; + else + fDescription = description; +} + +//-------------------------------------------------------------------------- +// Set (public) +//-------------------------------------------------------------------------- +/** + *

set a physical quantity. + * + * \param label of the physical quantity, e.g. 'Sample Temperature' + * \param demand value of the physical quantity + * \param value measured value of the physical quantity + * \param unit of the physical quantity, e.g. 'K'. + * \param description additional more detailed description of the physical quantity + */ +void TMusrRunPhysicalQuantity::Set(TString label, Double_t demand, Double_t value, TString unit, TString description) +{ + fLabel = label; + fDemand = demand; + fValue = value; + fError = MRRH_UNDEFINED; + fUnit = unit; + if (description.IsWhitespace()) + fDescription = "n/a"; + else + fDescription = description; +} + +//-------------------------------------------------------------------------- +// Set (public) +//-------------------------------------------------------------------------- +/** + *

set a physical quantity. + * + * \param label of the physical quantity, e.g. 'Sample Temperature' + * \param value measured value of the physical quantity + * \param unit of the physical quantity, e.g. 'K'. + * \param description additional more detailed description of the physical quantity + */ +void TMusrRunPhysicalQuantity::Set(TString label, Double_t value, TString unit, TString description) +{ + fLabel = label; + fDemand = MRRH_UNDEFINED; + fValue = value; + fError = MRRH_UNDEFINED; + fUnit = unit; + if (description.IsWhitespace()) + fDescription = "n/a"; + else + fDescription = description; +} + +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +ClassImp(TMusrRunHeader) + +//-------------------------------------------------------------------------- +// Constructor +//-------------------------------------------------------------------------- +/** + *

Constructor. + */ +TMusrRunHeader::TMusrRunHeader() +{ + Init(); +} + +//-------------------------------------------------------------------------- +// Constructor +//-------------------------------------------------------------------------- +/** + *

Constructor. + */ +TMusrRunHeader::TMusrRunHeader(const char *fileName) +{ + Init(); + fFileName = TString(fileName); +} + +//-------------------------------------------------------------------------- +// Destructor +//-------------------------------------------------------------------------- +/** + *

Destructor. + */ +TMusrRunHeader::~TMusrRunHeader() +{ + fStringObj.clear(); + fIntObj.clear(); + fDoubleObj.clear(); + fMusrRunPhysQuantityObj.clear(); + fStringVectorObj.clear(); + fIntVectorObj.clear(); + fDoubleVectorObj.clear(); + + fFolder.clear(); + + fMap.DeleteAll(); +} + + +//-------------------------------------------------------------------------- +// Init (private) +//-------------------------------------------------------------------------- +/** + *

Initializes variables. + */ +void TMusrRunHeader::Init() +{ + fMap.DeleteAll(); + fMap.SetName("__map"); + + fFileName = TString("n/a"); +} + +//-------------------------------------------------------------------------- +// GetHeaderInfo (public) +//-------------------------------------------------------------------------- +/** + *

Get MUSR-ROOT header information of 'path'. + * + * \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); + + 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()); + } + } + str.Form("%03d - %s", count++, tstr.Data()); + tostr = new TObjString(str); + content.AddLast(tostr); + } + } + for (UInt_t i=0; iGet TString 'value'. + * + * \param pathName path/name within the header, e.g. RunInfo/Run Title + * \param value TString return value + * \param ok flag telling if the TString value was found + */ +void TMusrRunHeader::GetValue(TString pathName, TString &value, Bool_t &ok) +{ + ok = false; + + for (UInt_t i=0; iGet Int_t 'value'. + * + * \param pathName path/name within the header, e.g. RunInfo/Run Number + * \param value Int_t return value + * \param ok flag telling if the Int_t value was found + */ +void TMusrRunHeader::GetValue(TString pathName, Int_t &value, Bool_t &ok) +{ + ok = false; + + for (UInt_t i=0; iGet Double_t 'value'. + * + * \param pathName path/name within the header, e.g. RunInfo/Time Zero Bin + * \param value Double_t return value + * \param ok flag telling if the Double_t value was found + */ +void TMusrRunHeader::GetValue(TString pathName, Double_t &value, Bool_t &ok) +{ + ok = false; + + for (UInt_t i=0; iGet TMusrRunPhysicalQuantity 'value'. + * + * \param pathName path/name within the header, e.g. RunInfo/Run Title + * \param value TMusrRunPhysicalQuantity return value + * \param ok flag telling if the TMusrRunPhysicalQuantity value was found + */ +void TMusrRunHeader::GetValue(TString pathName, TMusrRunPhysicalQuantity &value, Bool_t &ok) +{ + ok = false; + + for (UInt_t i=0; iGet TStringVector 'value'. + * + * \param pathName path/name within the header, e.g. RunInfo/Run Title + * \param value TStringVector return value + * \param ok flag telling if the TStringVector value was found + */ +void TMusrRunHeader::GetValue(TString pathName, TStringVector &value, Bool_t &ok) +{ + ok = false; + + for (UInt_t i=0; iGet TIntVector 'value'. + * + * \param pathName path/name within the header, e.g. RunInfo/Run Title + * \param value TIntVector return value + * \param ok flag telling if the TIntVector value was found + */ +void TMusrRunHeader::GetValue(TString pathName, TIntVector &value, Bool_t &ok) +{ + ok = false; + + for (UInt_t i=0; iGet TDoubleVector 'value'. + * + * \param pathName path/name within the header, e.g. RunInfo/Run Title + * \param value TDoubleVector return value + * \param ok flag telling if the TDoubleVector value was found + */ +void TMusrRunHeader::GetValue(TString pathName, TDoubleVector &value, Bool_t &ok) +{ + ok = false; + + for (UInt_t i=0; iSet 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) +//-------------------------------------------------------------------------- +/** + *

Set TString 'value'. + * + * \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) +{ + // check if pathName is already set, and if not add it as a new entry + UInt_t i=0; + for (i=0; i> **WARNING** " << pathName.Data() << " already exists, will replace it." << endl; + fStringObj[i].SetType("TString"); + fStringObj[i].SetValue(value); + break; + } + } + + // if not found in the previous loop, it is a new object + if (i == fStringObj.size()) { + 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")); + + } + } +} + +//-------------------------------------------------------------------------- +// Set (public) +//-------------------------------------------------------------------------- +/** + *

Set Int_t 'value'. + * + * \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) +{ + // check if pathName is already set, and if not add it as a new entry + UInt_t i=0; + for (i=0; i> **WARNING** " << pathName.Data() << " already exists, will replace it." << endl; + fIntObj[i].SetType("Int_t"); + fIntObj[i].SetValue(value); + break; + } + } + + // if not found in the previous loop, it is a new object + if (i == fIntObj.size()) { + 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")); + } +} + +//-------------------------------------------------------------------------- +// Set (public) +//-------------------------------------------------------------------------- +/** + *

Set Double_t 'value'. + * + * \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) +{ + // check if pathName is already set, and if not add it as a new entry + UInt_t i=0; + for (i=0; i> **WARNING** " << pathName.Data() << " already exists, will replace it." << endl; + fDoubleObj[i].SetType("Double_t"); + fDoubleObj[i].SetValue(value); + break; + } + } + + // if not found in the previous loop, it is a new object + if (i == fDoubleObj.size()) { + 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")); + } +} + +//-------------------------------------------------------------------------- +// Set (public) +//-------------------------------------------------------------------------- +/** + *

Set TMusrRunPhysicalQuantity 'value'. + * + * \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) +{ + // check if pathName is already set, and if not add it as a new entry + UInt_t i=0; + for (i=0; i> **WARNING** " << pathName.Data() << " already exists, will replace it." << endl; + fMusrRunPhysQuantityObj[i].SetType("TMusrRunHeader"); + fMusrRunPhysQuantityObj[i].SetValue(value); + break; + } + } + + // if not found in the previous loop, it is a new object + if (i == fMusrRunPhysQuantityObj.size()) { + 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")); + } +} + +//-------------------------------------------------------------------------- +// Set (public) +//-------------------------------------------------------------------------- +/** + *

Set TStringVector 'value'. + * + * \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) +{ + // check if pathName is already set, and if not add it as a new entry + UInt_t i=0; + for (i=0; i> **WARNING** " << pathName.Data() << " already exists, will replace it." << endl; + fStringVectorObj[i].SetType("TStringVector"); + fStringVectorObj[i].SetValue(value); + break; + } + } + + // if not found in the previous loop, it is a new object + if (i == fStringVectorObj.size()) { + 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")); + } +} + +//-------------------------------------------------------------------------- +// Set (public) +//-------------------------------------------------------------------------- +/** + *

Set TIntVector 'value'. + * + * \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) +{ + // check if pathName is already set, and if not add it as a new entry + UInt_t i=0; + for (i=0; i> **WARNING** " << pathName.Data() << " already exists, will replace it." << endl; + fIntVectorObj[i].SetType("TIntVector"); + fIntVectorObj[i].SetValue(value); + break; + } + } + + // if not found in the previous loop, it is a new object + if (i == fIntVectorObj.size()) { + 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")); + } +} + +//-------------------------------------------------------------------------- +// Set (public) +//-------------------------------------------------------------------------- +/** + *

Set TDoubleVector 'value'. + * + * \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) +{ + // check if pathName is already set, and if not add it as a new entry + UInt_t i=0; + for (i=0; i> **WARNING** " << pathName.Data() << " already exists, will replace it." << endl; + fDoubleVectorObj[i].SetType("TDoubleVector"); + fDoubleVectorObj[i].SetValue(value); + break; + } + } + + // if not found in the previous loop, it is a new object + if (i == fDoubleVectorObj.size()) { + 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")); + } +} + +//-------------------------------------------------------------------------- +// ExtractHeaderInformation (public) +//-------------------------------------------------------------------------- +/** + *

+ * + * \param headerInfo + * \param requestedPath + */ +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(""); + TObjString *ostr = 0; + TObjArray *tokens = 0; + Ssiz_t idx1, idx2; + 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(); + + // get header name + idx1 = str.First('-'); + idx2 = str.First(':'); + headerName = TString(""); + for (Int_t j=idx1+2; jGetString(); + + 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; + 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); + ostr = dynamic_cast(tokens->At(5)); + str = ostr->GetString(); + prop.SetDemand(str.Atof()); + break; + default: + break; + } + + 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; + } + 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); + } + } + + return true; +} + +//-------------------------------------------------------------------------- +// DumpHeader (public) +//-------------------------------------------------------------------------- +/** + *

+ */ +void TMusrRunHeader::DumpHeader() +{ + cout << endl << "***************************************"; + cout << endl << "header info of file : " << fFileName; + cout << endl << "***************************************"; + + TString tstr(""), fmt(""), path(""), name(""); + TMusrRunPhysicalQuantity prop; + + // go through all folders + for (UInt_t i=0; i + */ +void TMusrRunHeader::DrawHeader() +{ + TPaveText *pt; + TCanvas *ca; + + ca = new TCanvas("MusrRoot RunHeader","MusrRoot RunHeader", 147,37,699,527); + ca->Range(0., 0., 100., 100.); + + pt = new TPaveText(10.,10.,90.,90.,"br"); + pt->SetFillColor(19); + pt->SetTextAlign(12); + + pt->Draw(); + + ca->Modified(kTRUE); +} + +//-------------------------------------------------------------------------- +// GetDecimalPlace (private) +//-------------------------------------------------------------------------- +/** + *

Check decimal place of val. If val > 1.0, the function will return 0, otherwise + * the first decimal place found will be returned. + * + * \param val value from which the first significant digit shall be determined + */ +UInt_t TMusrRunHeader::GetDecimalPlace(Double_t val) +{ + UInt_t digit = 0; + + if (val < 1.0) { + UInt_t count=1; + do { + val *= 10.0; + if (val > 1.0) + digit = count; + count++; + } while ((digit == 0) && (count < 20)); + } + + return digit; +} + +//-------------------------------------------------------------------------- +// GetLeastSignificantDigit (private) +//-------------------------------------------------------------------------- +/** + *

returns the number of significant digits + * + * \param val value from which the lowest significant digit shall be determined + */ +UInt_t TMusrRunHeader::GetLeastSignificantDigit(Double_t val) const +{ + char cstr[1024]; + snprintf(cstr, sizeof(cstr), "%.10lf", val); + + int i=0, j=0; + for (i=strlen(cstr)-1; i>=0; i--) { + if (cstr[i] != '0') + break; + } + + for (j=strlen(cstr)-1; j>=0; j--) { + if (cstr[j] == '.') + break; + } + if (j==0) // no decimal point present, e.g. 321 + j=i; + + return i-j; +} + +//-------------------------------------------------------------------------- +// SplitPathName (private) +//-------------------------------------------------------------------------- +/** + *

splits a path name string into the path and the name. + * + * \param pathName path name to be split + * \param path of pathName + * \param name of pathName + */ +void TMusrRunHeader::SplitPathName(TString pathName, TString &path, TString &name) +{ + path = TString(""); + name = TString(""); + Ssiz_t idx = pathName.Last('/'); + + for (Int_t i=0; ichecks if a folder is present in the internal administration + * + * \param path of the folder + */ +Bool_t TMusrRunHeader::FolderPresent(TString &path) +{ + for (UInt_t i=0; i #include #include #include #include +#include #include -#define PRH_UNDEFINED -9.99e99 +#define MRRH_UNDEFINED -9.99e99 typedef vector TIntVector; +typedef vector TDoubleVector; typedef vector TStringVector; //------------------------------------------------------------------------- -template class TPsiRunObject : public TObject +template class TMusrRunObject : public TObject { public: - TPsiRunObject() { fPathName = "n/a"; fType = "n/a"; } - TPsiRunObject(TString pathName, TString type, T value) : fPathName(pathName), fType(type), fValue(value) {} - virtual ~TPsiRunObject() {} + TMusrRunObject() { fPathName = "n/a"; fType = "n/a"; } + TMusrRunObject(TString pathName, TString type, T value) : fPathName(pathName), fType(type), fValue(value) {} + virtual ~TMusrRunObject() {} virtual TString GetPathName() { return fPathName; } virtual TString GetType() { return fType; } @@ -67,14 +69,14 @@ private: }; //------------------------------------------------------------------------- -class TPsiRunProperty : public TObject +class TMusrRunPhysicalQuantity : public TObject { public: - TPsiRunProperty(); - TPsiRunProperty(TString label, Double_t demand, Double_t value, Double_t error, TString unit, TString description = TString("n/a")); - TPsiRunProperty(TString label, Double_t demand, Double_t value, TString unit, TString description = TString("n/a")); - TPsiRunProperty(TString label, Double_t value, TString unit, TString description = TString("n/a")); - virtual ~TPsiRunProperty() {} + TMusrRunPhysicalQuantity(); + TMusrRunPhysicalQuantity(TString label, Double_t demand, Double_t value, Double_t error, TString unit, TString description = TString("n/a")); + TMusrRunPhysicalQuantity(TString label, Double_t demand, Double_t value, TString unit, TString description = TString("n/a")); + TMusrRunPhysicalQuantity(TString label, Double_t value, TString unit, TString description = TString("n/a")); + virtual ~TMusrRunPhysicalQuantity() {} virtual TString GetLabel() const { return fLabel; } virtual Double_t GetDemand() const { return fDemand; } @@ -98,88 +100,47 @@ public: private: TString fLabel; ///< property label, like ’Sample Temperature’ etc. - Double_t fDemand; ///< demand value of the property, e.g. temperature setpoint - Double_t fValue; ///< measured value of the property - Double_t fError; ///< estimated error (standard deviation) of the measured property value - TString fUnit; ///< unit of the property - TString fDescription; ///< a more detailed description of the property + Double_t fDemand; ///< demand value of the physical quantity, e.g. temperature setpoint + Double_t fValue; ///< measured value of the physical quantity + Double_t fError; ///< estimated error (standard deviation) of the measured value + TString fUnit; ///< unit of the physical quantity + TString fDescription; ///< a more detailed description of the physical quantity - ClassDef(TPsiRunProperty, 1) + ClassDef(TMusrRunPhysicalQuantity, 1) }; //------------------------------------------------------------------------- -class TPsiEntry +class TMusrRunHeader : public TObject { public: - TPsiEntry() { fPathName = "n/a"; fType = "n/a"; } - TPsiEntry(TString pathName, TString type) : fPathName(pathName), fType(type) {} - virtual ~TPsiEntry() {} + TMusrRunHeader(); + TMusrRunHeader(const char *fileName); + virtual ~TMusrRunHeader(); - virtual TString GetPathName() { return fPathName; } - virtual TString GetType() { return fType; } - - virtual void SetPathName(TString pathName) { fPathName = pathName; } - virtual void SetType(TString type) { fType = type; } - -private: - TString fPathName; - TString fType; -}; - -//------------------------------------------------------------------------- -class TPsiStartupHandler : public TObject, public TQObject -{ -public: - TPsiStartupHandler(); - virtual ~TPsiStartupHandler(); - - virtual void OnStartDocument(); // SLOT - virtual void OnEndDocument(); // SLOT - virtual void OnStartElement(const Char_t*, const TList*); // SLOT - virtual void OnEndElement(const Char_t*); // SLOT - virtual void OnCharacters(const Char_t*); // SLOT - virtual void OnComment(const Char_t*); // SLOT - virtual void OnWarning(const Char_t*); // SLOT - virtual void OnError(const Char_t*); // SLOT - virtual void OnFatalError(const Char_t*); // SLOT - virtual void OnCdataBlock(const Char_t*, Int_t); // SLOT - - virtual TStringVector GetFolders() { return fFolder; } - virtual vector GetEntries() { return fEntry; } - -private: - enum EKeyWords {eEmpty, eFolder, eEntry, eName, eType}; - - EKeyWords fKey, fGroupKey; ///< xml filter key - - TStringVector fFolder; - vector fEntry; - - ClassDef(TPsiStartupHandler, 1) -}; - -//------------------------------------------------------------------------- -class TPsiRunHeader : public TObject -{ -public: - TPsiRunHeader(const char *headerDefinition); - virtual ~TPsiRunHeader(); - - virtual Bool_t IsValid(Bool_t strict = false); + virtual TString GetFileName() { return fFileName; } virtual void GetHeaderInfo(TString path, TObjArray &content); virtual void GetValue(TString pathName, TString &value, Bool_t &ok); virtual void GetValue(TString pathName, Int_t &value, Bool_t &ok); - virtual void GetValue(TString pathName, TPsiRunProperty &value, Bool_t &ok); + virtual void GetValue(TString pathName, Double_t &value, Bool_t &ok); + virtual void GetValue(TString pathName, TMusrRunPhysicalQuantity &value, Bool_t &ok); virtual void GetValue(TString pathName, TStringVector &value, Bool_t &ok); virtual void GetValue(TString pathName, TIntVector &value, Bool_t &ok); + virtual void GetValue(TString pathName, TDoubleVector &value, Bool_t &ok); - virtual void Set(TString pathName, TString value); - virtual void Set(TString pathName, Int_t value); - virtual void Set(TString pathName, TPsiRunProperty value); - virtual void Set(TString pathName, TStringVector value); - virtual void Set(TString pathName, TIntVector value); + 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); @@ -187,22 +148,27 @@ public: virtual void DrawHeader(); private: - TString fHeaderDefinition; + TString fFileName; - vector< TPsiRunObject > fStringObj; - vector< TPsiRunObject > fIntObj; - vector< TPsiRunObject > fPsiRunPropertyObj; - vector< TPsiRunObject > fStringVectorObj; - vector< TPsiRunObject > fIntVectorObj; + vector< TMusrRunObject > fStringObj; + vector< TMusrRunObject > fIntObj; + vector< TMusrRunObject > fDoubleObj; + vector< TMusrRunObject > fMusrRunPhysQuantityObj; + vector< TMusrRunObject > fStringVectorObj; + vector< TMusrRunObject > fIntVectorObj; + vector< TMusrRunObject > fDoubleVectorObj; TStringVector fFolder; - vector fEntry; + 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); - ClassDef(TPsiRunHeader, 1) + ClassDef(TMusrRunHeader, 1) }; -#endif // TPSIRUNHEADER_H +#endif // TMUSRRUNHEADER_H diff --git a/src/tests/PsiRoot/TPsiRunHeaderLinkDef.h b/src/tests/PsiRoot/TMusrRunHeaderLinkDef.h similarity index 89% rename from src/tests/PsiRoot/TPsiRunHeaderLinkDef.h rename to src/tests/PsiRoot/TMusrRunHeaderLinkDef.h index 546fbc2b..1594ae91 100644 --- a/src/tests/PsiRoot/TPsiRunHeaderLinkDef.h +++ b/src/tests/PsiRoot/TMusrRunHeaderLinkDef.h @@ -1,6 +1,6 @@ /*************************************************************************** - TPsiRunHeader2LinkDef.h + TMusrRunHeaderLinkDef.h Author: Andreas Suter e-mail: andreas.suter@psi.ch @@ -10,7 +10,7 @@ ***************************************************************************/ /*************************************************************************** - * Copyright (C) 2007-2011 by Andreas Suter * + * Copyright (C) 2007-2012 by Andreas Suter * * andreas.suter@psi.ch * * * * This program is free software; you can redistribute it and/or modify * @@ -35,8 +35,7 @@ #pragma link off all classes; #pragma link off all functions; -#pragma link C++ class TPsiRunProperty+; -#pragma link C++ class TPsiStartupHandler+; -#pragma link C++ class TPsiRunHeader+; +#pragma link C++ class TMusrRunPhysicalQuantity+; +#pragma link C++ class TMusrRunHeader+; #endif diff --git a/src/tests/PsiRoot/TPsiRunHeader.cpp b/src/tests/PsiRoot/TPsiRunHeader.cpp deleted file mode 100644 index c80bf7a2..00000000 --- a/src/tests/PsiRoot/TPsiRunHeader.cpp +++ /dev/null @@ -1,1705 +0,0 @@ -/*************************************************************************** - - TPsiRunHeader.cpp - - Author: Andreas Suter - e-mail: andreas.suter@psi.ch - - $Id$ - -***************************************************************************/ - -/*************************************************************************** - * Copyright (C) 2007-2011 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 -#include -#include -#include -using namespace std; - -#include "TPsiRunHeader.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -ClassImp(TPsiRunProperty) - -//-------------------------------------------------------------------------- -// Constructor -//-------------------------------------------------------------------------- -/** - *

Constructor. - */ -TPsiRunProperty::TPsiRunProperty() -{ - fLabel = "n/a"; - fDemand = PRH_UNDEFINED; - fValue = PRH_UNDEFINED; - fError = PRH_UNDEFINED; - fUnit = "n/a"; - fDescription = "n/a"; -} - -//-------------------------------------------------------------------------- -// Constructor -//-------------------------------------------------------------------------- -/** - *

Constructor. - * - * \param label of the physical property, e.g. 'Sample Temperature' - * \param demand value of the physical property - * \param value measured value of the physical property - * \param error estimated error of the physical property - * \param unit of the physical property, e.g. 'K'. - * \param description additional more detailed description of the physical property - */ -TPsiRunProperty::TPsiRunProperty(TString label, Double_t demand, Double_t value, Double_t error, TString unit, TString description) : - fLabel(label), fDemand(demand), fValue(value), fError(error), fUnit(unit) -{ - if (description.IsWhitespace()) - fDescription = "n/a"; - else - fDescription = description; -} - -//-------------------------------------------------------------------------- -// Constructor -//-------------------------------------------------------------------------- -/** - *

Constructor. - * - * \param label of the physical property, e.g. 'Sample Temperature' - * \param demand value of the physical property - * \param value measured value of the physical property - * \param unit of the physical property, e.g. 'K'. - * \param description additional more detailed description of the physical property - */ -TPsiRunProperty::TPsiRunProperty(TString label, Double_t demand, Double_t value, TString unit, TString description) : - fLabel(label), fDemand(demand), fValue(value), fUnit(unit) -{ - fError = PRH_UNDEFINED; - if (description.IsWhitespace()) - fDescription = "n/a"; - else - fDescription = description; -} - -//-------------------------------------------------------------------------- -// Constructor -//-------------------------------------------------------------------------- -/** - *

Constructor. - * - * \param label of the physical property, e.g. 'Sample Temperature' - * \param value measured value of the physical property - * \param unit of the physical property, e.g. 'K'. - * \param description additional more detailed description of the physical property - */ -TPsiRunProperty::TPsiRunProperty(TString label, Double_t value, TString unit, TString description) : - fLabel(label), fValue(value), fUnit(unit) -{ - fDemand = PRH_UNDEFINED; - fError = PRH_UNDEFINED; - if (description.IsWhitespace()) - fDescription = "n/a"; - else - fDescription = description; -} - -//-------------------------------------------------------------------------- -// Set (public) -//-------------------------------------------------------------------------- -/** - *

set a physical property. - * - * \param label of the physical property, e.g. 'Sample Temperature' - * \param demand value of the physical property - * \param value measured value of the physical property - * \param error estimated error of the physical property - * \param unit of the physical property, e.g. 'K'. - * \param description additional more detailed description of the physical property - */ -void TPsiRunProperty::Set(TString label, Double_t demand, Double_t value, Double_t error, TString unit, TString description) -{ - fLabel = label; - fDemand = demand; - fValue = value; - fError = error; - fUnit = unit; - if (description.IsWhitespace()) - fDescription = "n/a"; - else - fDescription = description; -} - -//-------------------------------------------------------------------------- -// Set (public) -//-------------------------------------------------------------------------- -/** - *

set a physical property. - * - * \param label of the physical property, e.g. 'Sample Temperature' - * \param demand value of the physical property - * \param value measured value of the physical property - * \param unit of the physical property, e.g. 'K'. - * \param description additional more detailed description of the physical property - */ -void TPsiRunProperty::Set(TString label, Double_t demand, Double_t value, TString unit, TString description) -{ - fLabel = label; - fDemand = demand; - fValue = value; - fError = PRH_UNDEFINED; - fUnit = unit; - if (description.IsWhitespace()) - fDescription = "n/a"; - else - fDescription = description; -} - -//-------------------------------------------------------------------------- -// Set (public) -//-------------------------------------------------------------------------- -/** - *

set a physical property. - * - * \param label of the physical property, e.g. 'Sample Temperature' - * \param value measured value of the physical property - * \param unit of the physical property, e.g. 'K'. - * \param description additional more detailed description of the physical property - */ -void TPsiRunProperty::Set(TString label, Double_t value, TString unit, TString description) -{ - fLabel = label; - fDemand = PRH_UNDEFINED; - fValue = value; - fError = PRH_UNDEFINED; - fUnit = unit; - if (description.IsWhitespace()) - fDescription = "n/a"; - else - fDescription = description; -} - -//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - -ClassImp(TPsiStartupHandler) - -//-------------------------------------------------------------------------- -// Constructor -//-------------------------------------------------------------------------- -/** - *

Constructor. - */ -TPsiStartupHandler::TPsiStartupHandler() -{ - fKey = eEmpty; -} - -//-------------------------------------------------------------------------- -// Destructor -//-------------------------------------------------------------------------- -/** - *

Destructor. - */ -TPsiStartupHandler::~TPsiStartupHandler() -{ - fFolder.clear(); - fEntry.clear(); -} - -//-------------------------------------------------------------------------- -// OnStartDocument -//-------------------------------------------------------------------------- -/** - *

Called on start of the XML file reading. Initializes all necessary variables. - */ -void TPsiStartupHandler::OnStartDocument() -{ - fKey = eEmpty; - fGroupKey = eEmpty; -} - -//-------------------------------------------------------------------------- -// OnEndDocument -//-------------------------------------------------------------------------- -/** - *

Called on end of XML file reading. - */ -void TPsiStartupHandler::OnEndDocument() -{ - -} - -//-------------------------------------------------------------------------- -// OnStartElement -//-------------------------------------------------------------------------- -/** - *

Called when a XML start element is found. Filters out the needed elements - * and sets a proper key. - * - * \param str XML element name - * \param attributes not used - */ -void TPsiStartupHandler::OnStartElement(const Char_t *str, const TList *attributes) -{ - if (!strcmp(str, "folder")) { - fGroupKey = eFolder; - } else if (!strcmp(str, "entry")) { - fGroupKey = eEntry; - } else if (!strcmp(str, "name")) { - fKey = eName; - } else if (!strcmp(str, "type")) { - fKey = eType; - } -} - -//-------------------------------------------------------------------------- -// OnEndElement -//-------------------------------------------------------------------------- -/** - *

Called when a XML end element is found. Resets the handler key. - * - * \param str not used - */ -void TPsiStartupHandler::OnEndElement(const Char_t *str) -{ - if (!strcmp(str, "folder") || !strcmp(str, "entry")) - fGroupKey = eEmpty; - fKey = eEmpty; -} - -//-------------------------------------------------------------------------- -// OnCharacters -//-------------------------------------------------------------------------- -/** - *

Content of a given XML element. Filters out the data and feeds them to - * the internal variables. - * - * \param str XML element string - */ -void TPsiStartupHandler::OnCharacters(const Char_t *str) -{ - static TPsiEntry entry; - static Int_t code = 0; - - switch (fGroupKey) { - case eFolder: - switch (fKey) { - case eName: - fFolder.push_back(str); - break; - default: - break; - } - break; - case eEntry: - switch (fKey) { - case eName: - entry.SetPathName(str); - code |= 1; - break; - case eType: - entry.SetType(str); - code |= 2; - break; - default: - break; - } - if (code == 3) { - fEntry.push_back(entry); - code = 0; - } - break; - default: - break; - } -} - -//-------------------------------------------------------------------------- -// OnComment -//-------------------------------------------------------------------------- -/** - *

Called when a XML comment is found. Not used. - * - * \param str not used. - */ -void TPsiStartupHandler::OnComment(const Char_t *str) -{ - // nothing to be done for now -} - -//-------------------------------------------------------------------------- -// OnWarning -//-------------------------------------------------------------------------- -/** - *

Called when the XML parser emits a warning. - * - * \param str warning string - */ -void TPsiStartupHandler::OnWarning(const Char_t *str) -{ - cerr << endl << ">> TPsiStartupHandler **WARNING** " << str; - cerr << endl; -} - -//-------------------------------------------------------------------------- -// OnError -//-------------------------------------------------------------------------- -/** - *

Called when the XML parser emits an error. - * - * \param str error string - */ -void TPsiStartupHandler::OnError(const Char_t *str) -{ - cerr << endl << ">> TPsiStartupHandler **ERROR** " << str; - cerr << endl; -} - -//-------------------------------------------------------------------------- -// OnFatalError -//-------------------------------------------------------------------------- -/** - *

Called when the XML parser emits a fatal error. - * - * \param str fatal error string - */ -void TPsiStartupHandler::OnFatalError(const Char_t *str) -{ - cerr << endl << ">> TPsiStartupHandler **FATAL ERROR** " << str; - cerr << endl; -} - -//-------------------------------------------------------------------------- -// OnCdataBlock -//-------------------------------------------------------------------------- -/** - *

Not used. - * - * \param str not used - * \param len not used - */ -void TPsiStartupHandler::OnCdataBlock(const Char_t *str, Int_t len) -{ - // nothing to be done for now -} - - -//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - -ClassImp(TPsiRunHeader) - -//-------------------------------------------------------------------------- -// Constructor -//-------------------------------------------------------------------------- -/** - *

Constructor. - */ -TPsiRunHeader::TPsiRunHeader(const char *headerDefinition) : fHeaderDefinition(headerDefinition) -{ - TSAXParser *saxParser = new TSAXParser(); - TPsiStartupHandler *startupHandler = new TPsiStartupHandler(); - - saxParser->ConnectToHandler("TPsiStartupHandler", startupHandler); - Int_t status = saxParser->ParseFile(headerDefinition); - - if (status) { // error - // not clear what to do yet ... - } else { - fFolder = startupHandler->GetFolders(); - fEntry = startupHandler->GetEntries(); - } - - if (startupHandler) { - delete startupHandler; - startupHandler = 0; - } - - if (saxParser) { - delete saxParser; - saxParser = 0; - } -} - -//-------------------------------------------------------------------------- -// Destructor -//-------------------------------------------------------------------------- -/** - *

Destructor. - */ -TPsiRunHeader::~TPsiRunHeader() -{ - fStringObj.clear(); - fIntObj.clear(); - fPsiRunPropertyObj.clear(); - fStringVectorObj.clear(); - fIntVectorObj.clear(); - - fFolder.clear(); - fEntry.clear(); -} - -//-------------------------------------------------------------------------- -// IsValid (public) -//-------------------------------------------------------------------------- -/** - *

validates the currently set header information. If strict is set to true - * a strict validation is carried out, otherwise a more sloppy one. - * - *

return: - * - true, if valid header information are present. - * - false, otherwise - * - * \param strict flag needed to tell on which level the validation has to be carried out. - */ -Bool_t TPsiRunHeader::IsValid(Bool_t strict) -{ - Bool_t result = true; - TIntVector found; - Int_t count = 0; - - found.resize(fEntry.size()); - for (UInt_t i=0; i> **ERROR** found entry: " << fEntry[i].GetPathName() << " is 'TString' (according to header/root-file) but is defined as '" << fEntry[i].GetType().Data() << "' (XML)" << endl; - return false; - } - } - } - for (UInt_t j=0; j> **ERROR** found entry: " << fEntry[i].GetPathName() << " is 'Int_t' (according to header/root-file) but is defined as '" << fEntry[i].GetType().Data() << "' (XML)" << endl; - return false; - } - } - } - for (UInt_t j=0; j> **ERROR** found entry: " << fEntry[i].GetPathName() << " is 'TPsiRunProperty' (according to header/root-file) but is defined as '" << fEntry[i].GetType().Data() << "' (XML)" << endl; - return false; - } - } - } - for (UInt_t j=0; j> **ERROR** found entry: " << fEntry[i].GetPathName() << " is 'TStringVector' (according to header/root-file) but is defined as '" << fEntry[i].GetType().Data() << "' (XML)" << endl; - return false; - } - } - } - for (UInt_t j=0; j> **ERROR** found entry: " << fEntry[i].GetPathName() << " is 'TIntVector' (according to header/root-file) but is defined as '" << fEntry[i].GetType().Data() << "' (XML)" << endl; - return false; - } - } - } - } - if (count != (Int_t)fEntry.size()) { - if (strict) { - result = false; - cerr << endl << ">> **ERROR** in validation: only found " << count << " entries. " << fEntry.size() << " are required!" << endl; - } else { - cerr << endl << ">> **WARNING** in validation: only found " << count << " entries. " << fEntry.size() << " are required!" << endl; - } - } - - for (UInt_t i=0; i> **ERROR** "; - } else { - cerr << endl << ">> **WARNING** "; - } - cerr << "Missing required entry: " << fEntry[i].GetPathName().Data() << ", type=" << fEntry[i].GetType().Data(); - } - } - - found.clear(); - - return result; -} - -//-------------------------------------------------------------------------- -// GetHeaderInfo (public) -//-------------------------------------------------------------------------- -/** - *

Get PSI-ROOT header information of 'path'. - * - * \param requestedPath of the PSI-ROOT header, e.g. RunInfo - * \param content of the requested PSI-ROOT header. - */ -void TPsiRunHeader::GetHeaderInfo(TString requestedPath, TObjArray &content) -{ - // make sure content is initialized - content.Delete(); - content.Expand(0); - - static UInt_t count = 1; - TString str(""), path(""), name(""), fmt(""), tstr(""); - TObjString *tostr; - TPsiRunProperty prop; - - // go first through all objects defined in psi_root.xml - 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() == PRH_UNDEFINED) && (prop.GetValue() != PRH_UNDEFINED) && (prop.GetError() != PRH_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() == PRH_UNDEFINED) && (prop.GetValue() != PRH_UNDEFINED) && (prop.GetError() == PRH_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() != PRH_UNDEFINED) && (prop.GetValue() != PRH_UNDEFINED) && (prop.GetError() == PRH_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", count++, tstr.Data()); - tostr = new TObjString(str); - content.AddLast(tostr); - } - } - 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() == PRH_UNDEFINED) && (prop.GetValue() != PRH_UNDEFINED) && (prop.GetError() != PRH_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() == PRH_UNDEFINED) && (prop.GetValue() != PRH_UNDEFINED) && (prop.GetError() == PRH_UNDEFINED) && - (prop.GetUnit() != "n/a") && (prop.GetDescription() == "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() != PRH_UNDEFINED) && (prop.GetValue() != PRH_UNDEFINED) && (prop.GetError() == PRH_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", count++, tstr.Data()); - tostr = new TObjString(str); - content.AddLast(tostr); - } - } - } - for (UInt_t i=0; iGet TString 'value'. - * - * \param pathName path/name within the header, e.g. RunInfo/Run Title - * \param value TString return value - * \param ok flag telling if the TString value was found - */ -void TPsiRunHeader::GetValue(TString pathName, TString &value, Bool_t &ok) -{ - ok = false; - - for (UInt_t i=0; iGet Int_t 'value'. - * - * \param pathName path/name within the header, e.g. RunInfo/Run Title - * \param value Int_t return value - * \param ok flag telling if the Int_t value was found - */ -void TPsiRunHeader::GetValue(TString pathName, Int_t &value, Bool_t &ok) -{ - ok = false; - - for (UInt_t i=0; iGet TPsiRunProperty 'value'. - * - * \param pathName path/name within the header, e.g. RunInfo/Run Title - * \param value TPsiRunProperty return value - * \param ok flag telling if the TPsiRunProperty value was found - */ -void TPsiRunHeader::GetValue(TString pathName, TPsiRunProperty &value, Bool_t &ok) -{ - ok = false; - - for (UInt_t i=0; iGet TStringVector 'value'. - * - * \param pathName path/name within the header, e.g. RunInfo/Run Title - * \param value TStringVector return value - * \param ok flag telling if the TStringVector value was found - */ -void TPsiRunHeader::GetValue(TString pathName, TStringVector &value, Bool_t &ok) -{ - ok = false; - - for (UInt_t i=0; iGet TIntVector 'value'. - * - * \param pathName path/name within the header, e.g. RunInfo/Run Title - * \param value TIntVector return value - * \param ok flag telling if the TIntVector value was found - */ -void TPsiRunHeader::GetValue(TString pathName, TIntVector &value, Bool_t &ok) -{ - ok = false; - - for (UInt_t i=0; iSet TString 'value'. - * - * \param pathName path/name within the header, e.g. RunInfo/Run Title - * \param value of the entry - */ -void TPsiRunHeader::Set(TString pathName, TString value) -{ - // check if pathName is already set, and if not add it as a new entry - UInt_t i=0; - for (i=0; i> **WARNING** " << pathName.Data() << " already exists, will replace it." << endl; - fStringObj[i].SetType("TString"); - fStringObj[i].SetValue(value); - break; - } - } - - // if not found in the previous loop, it is a new object - if (i == fStringObj.size()) { - TPsiRunObject obj(pathName, "TString", value); - fStringObj.push_back(obj); - } -} - -//-------------------------------------------------------------------------- -// Set (public) -//-------------------------------------------------------------------------- -/** - *

Set Int_t 'value'. - * - * \param pathName path/name within the header, e.g. RunInfo/Run number - * \param value of the entry - */ -void TPsiRunHeader::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; - for (i=0; i> **WARNING** " << pathName.Data() << " already exists, will replace it." << endl; - fIntObj[i].SetType("Int_t"); - fIntObj[i].SetValue(value); - break; - } - } - - // if not found in the previous loop, it is a new object - if (i == fIntObj.size()) { - TPsiRunObject obj(pathName, "Int_t", value); - fIntObj.push_back(obj); - } -} - -//-------------------------------------------------------------------------- -// Set (public) -//-------------------------------------------------------------------------- -/** - *

Set TPsiRunProperty 'value'. - * - * \param pathName path/name within the header, e.g. RunInfo/Muon Beam Momentum - * \param value of the entry - */ -void TPsiRunHeader::Set(TString pathName, TPsiRunProperty value) -{ - // check if pathName is already set, and if not add it as a new entry - UInt_t i=0; - for (i=0; i> **WARNING** " << pathName.Data() << " already exists, will replace it." << endl; - fPsiRunPropertyObj[i].SetType("TPsiRunProperty"); - fPsiRunPropertyObj[i].SetValue(value); - break; - } - } - - // if not found in the previous loop, it is a new object - if (i == fPsiRunPropertyObj.size()) { - TPsiRunObject obj(pathName, "TPsiRunProperty", value); - fPsiRunPropertyObj.push_back(obj); - } -} - -//-------------------------------------------------------------------------- -// Set (public) -//-------------------------------------------------------------------------- -/** - *

Set TStringVector 'value'. - * - * \param pathName path/name within the header, e.g. RunInfo/Histo names - * \param value of the entry - */ -void TPsiRunHeader::Set(TString pathName, TStringVector value) -{ - // check if pathName is already set, and if not add it as a new entry - UInt_t i=0; - for (i=0; i> **WARNING** " << pathName.Data() << " already exists, will replace it." << endl; - fStringVectorObj[i].SetType("TStringVector"); - fStringVectorObj[i].SetValue(value); - break; - } - } - - // if not found in the previous loop, it is a new object - if (i == fStringVectorObj.size()) { - TPsiRunObject obj(pathName, "TStringVector", value); - fStringVectorObj.push_back(obj); - } -} - -//-------------------------------------------------------------------------- -// Set (public) -//-------------------------------------------------------------------------- -/** - *

Set TIntVector 'value'. - * - * \param pathName path/name within the header, e.g. RunInfo/Time Zero Bin - * \param value of the entry - */ -void TPsiRunHeader::Set(TString pathName, TIntVector value) -{ - // check if pathName is already set, and if not add it as a new entry - UInt_t i=0; - for (i=0; i> **WARNING** " << pathName.Data() << " already exists, will replace it." << endl; - fIntVectorObj[i].SetType("TIntVector"); - fIntVectorObj[i].SetValue(value); - break; - } - } - - // if not found in the previous loop, it is a new object - if (i == fIntVectorObj.size()) { - TPsiRunObject obj(pathName, "TIntVector", value); - fIntVectorObj.push_back(obj); - } -} - -//-------------------------------------------------------------------------- -// ExtractHeaderInformation (public) -//-------------------------------------------------------------------------- -/** - *

- * - * \param headerInfo - * \param requestedPath - */ -Bool_t TPsiRunHeader::ExtractHeaderInformation(TObjArray *headerInfo, TString requestedPath) -{ - TString headerName(""), name(""), path(""), pathName(""), str(""), strValue(""); - TObjString *ostr = 0; - TObjArray *tokens = 0; - Bool_t required=false; - UInt_t idx; - Ssiz_t idx1, idx2; - Int_t intValue; - - // go through all entries of this header information from the PSI-ROOT file - for (Int_t i=0; iGetEntries(); i++) { - required=false; - ostr = dynamic_cast(headerInfo->At(i)); - str = ostr->GetString(); - // get header name - idx1 = str.First('-'); - idx2 = str.First(':'); - headerName = TString(""); - for (Int_t j=idx1+2; j> **ERROR** Couldn't tokenize entry in Bool_t TPsiRunHeader::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 TPsiRunHeader::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); - ostr = dynamic_cast(tokens->At(5)); - str = ostr->GetString(); - prop.SetDemand(str.Atof()); - break; - default: - break; - } - - if (tokens) { - delete tokens; - tokens = 0; - } - - Set(pathName, prop); - } else if (fEntry[idx].GetType() == "TStringVector") { - TStringVector svec; - tokens = strValue.Tokenize(";"); - if (tokens == 0) { - cerr << endl << ">> **ERROR** Couldn't tokenize entry in Bool_t TPsiRunHeader::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 (fEntry[idx].GetType() == "TIntVector") { - TIntVector ivec; - tokens = strValue.Tokenize(";"); - if (tokens == 0) { - cerr << endl << ">> **ERROR** Couldn't tokenize entry in Bool_t TPsiRunHeader::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); - } - } - } - - // go through all entries of this header information from the PSI-ROOT file - for (Int_t i=0; iGetEntries(); i++) { - required=false; - ostr = dynamic_cast(headerInfo->At(i)); - str = ostr->GetString(); - // get header name - idx1 = str.First('-'); - idx2 = str.First(':'); - headerName = TString(""); - for (Int_t j=idx1+2; j - */ -void TPsiRunHeader::DumpHeader() -{ - cout << endl << "***************************************"; - cout << endl << "used header definition: " << fHeaderDefinition.Data(); - cout << endl << "***************************************"; - - TString tstr(""), tstr1(""), fmt(""), path(""), name(""); - TPsiRunProperty prop; - - // go first through all objects defined in psi_root.xml - cout << endl << endl << "---------------"; - cout << endl << "Entries which are **PRESENT** in psi_root.xml"; - cout << endl << "---------------" << endl; - for (UInt_t i=0; i - */ -void TPsiRunHeader::DrawHeader() -{ - TPaveText *pt; - TCanvas *ca; - - ca = new TCanvas("PSI RunHeader","PSI RunHeader", 147,37,699,527); - ca->Range(0., 0., 100., 100.); - - pt = new TPaveText(10.,10.,90.,90.,"br"); - pt->SetFillColor(19); - pt->SetTextAlign(12); - - pt->Draw(); - - ca->Modified(kTRUE); -} - -//-------------------------------------------------------------------------- -// GetDecimalPlace (private) -//-------------------------------------------------------------------------- -/** - *

Check decimal place of val. If val > 1.0, the function will return 0, otherwise - * the first decimal place found will be returned. - * - * \param val value from which the first significant digit shall be determined - */ -UInt_t TPsiRunHeader::GetDecimalPlace(Double_t val) -{ - UInt_t digit = 0; - - if (val < 1.0) { - UInt_t count=1; - do { - val *= 10.0; - if (val > 1.0) - digit = count; - count++; - } while ((digit == 0) && (count < 20)); - } - - return digit; -} - -//-------------------------------------------------------------------------- -// GetLeastSignificantDigit (private) -//-------------------------------------------------------------------------- -/** - *

returns the number of significant digits - * - * \param val value from which the lowest significant digit shall be determined - */ -UInt_t TPsiRunHeader::GetLeastSignificantDigit(Double_t val) const -{ - char cstr[1024]; - snprintf(cstr, sizeof(cstr), "%.10lf", val); - - int i=0, j=0; - for (i=strlen(cstr)-1; i>=0; i--) { - if (cstr[i] != '0') - break; - } - - for (j=strlen(cstr)-1; j>=0; j--) { - if (cstr[j] == '.') - break; - } - if (j==0) // no decimal point present, e.g. 321 - j=i; - - return i-j; -} - -//-------------------------------------------------------------------------- -// SplitPathName (private) -//-------------------------------------------------------------------------- -/** - *

splits a path name string into the path and the name. - * - * \param pathName path name to be split - * \param path of pathName - * \param name of pathName - */ -void TPsiRunHeader::SplitPathName(TString pathName, TString &path, TString &name) -{ - path = TString(""); - name = TString(""); - Ssiz_t idx = pathName.Last('/'); - - for (Int_t i=0; i #include -#include "TPsiRunHeader.h" +#include "TMusrRunHeader.h" -void psi_runHeader_test_syntax() +void musrRoot_runHeader_test_syntax() { - cout << endl << "usage: psi_runHeader_test []"; + cout << endl << "usage: musrRoot_runHeader_test "; cout << endl << " is the file name including the extention root, e.g. test.root"; - cout << endl << " is the header definition XML-file."; - cout << endl << " 'strict'=strict validation; otherwise=less strict validation."; cout << endl << endl; } int main(int argc, char *argv[]) { - if ((argc != 3) && (argc != 4)) { - psi_runHeader_test_syntax(); + if (argc != 2) { + musrRoot_runHeader_test_syntax(); return 1; } - Bool_t strict = false; - if (argc == 4) { - if (!strcmp(argv[3], "strict")) - strict = true; - } - - // PSI Run Header object - TPsiRunHeader *header = new TPsiRunHeader(argv[2]); - TPsiRunProperty prop; + // 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 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"); @@ -80,7 +72,7 @@ int main(int argc, char *argv[]) prop.Set("Sample Temperature", 3.2, 3.21, 0.05, "K", "CF1"); header->Set("RunInfo/Sample Temperature", prop); - prop.Set("Muon Beam Momentum", PRH_UNDEFINED, 28.1, PRH_UNDEFINED, "MeV/c"); + prop.Set("Muon Beam Momentum", MRRH_UNDEFINED, 28.1, MRRH_UNDEFINED, "MeV/c"); header->Set("RunInfo/Muon Beam Momentum", prop); TStringVector detectorName; @@ -94,8 +86,8 @@ int main(int argc, char *argv[]) detectorName.push_back("bottom_up"); header->Set("RunInfo/Histo Names", detectorName); - TIntVector t0; - for (UInt_t i=0; i<8; i++) t0.push_back(3419); + TDoubleVector t0; + for (UInt_t i=0; i<8; i++) t0.push_back(3419.0); header->Set("RunInfo/Time Zero Bin", t0); TStringVector dummyTest; @@ -110,7 +102,7 @@ int main(int argc, char *argv[]) prop.Set("CF2", 3.2, 3.22, 0.04, "K"); header->Set("SampleEnv/CF2", prop); - prop.Set("CF3", PRH_UNDEFINED, 3.27, 0.09, "K", "strange temperature"); + 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"); @@ -134,26 +126,17 @@ int main(int argc, char *argv[]) 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); - if (!header->IsValid(strict)) { - cerr << endl << ">> **ERROR** run header validation failed." << endl; - if (strict) { // clean up and quit - delete header; - return -1; - } - } - - TFile *f = new TFile(argv[1], "RECREATE", "psi_runHeader_test"); + 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", "PSI Run Header Info"); + TFolder *runHeader = gROOT->GetRootFolder()->AddFolder("RunHeader", "MusrRoot Run Header Info"); gROOT->GetListOfBrowsables()->Add(runHeader, "RunHeader"); TObjArray runInfo; @@ -176,6 +159,9 @@ int main(int argc, char *argv[]) header->GetHeaderInfo("Scaler", scaler); runHeader->Add(&scaler); + TMap *map = header->GetMap(); + runHeader->Add(map); + runHeader->Write(); f->Close(); @@ -193,7 +179,7 @@ int main(int argc, char *argv[]) cout << endl << "++++++++++++++++++++++++++++" << endl; // read the file back and extract the header info - f = new TFile(argv[1], "READ", "psi_runHeader_test"); + f = new TFile(argv[1], "READ", "musrRoot_runHeader_test"); if (f->IsZombie()) { delete f; return -1; @@ -208,7 +194,15 @@ int main(int argc, char *argv[]) } TObjArray *oarray = 0; - header = new TPsiRunHeader(argv[2]); + 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"); @@ -248,14 +242,6 @@ int main(int argc, char *argv[]) f->Close(); delete f; - if (!header->IsValid(strict)) { - cerr << endl << ">> **ERROR** run header validation failed." << endl; - if (strict) { // clean up and quit - delete header; - return -1; - } - } - header->DumpHeader(); // get some information from the read file @@ -266,8 +252,8 @@ int main(int argc, char *argv[]) TString str(""); TStringVector strVec; Int_t ival; - TIntVector ivec; - TPsiRunProperty prop1; + TDoubleVector dvec; + TMusrRunPhysicalQuantity prop1; Bool_t ok; header->GetValue("RunInfo/Run Title", str, ok); @@ -293,13 +279,13 @@ int main(int argc, char *argv[]) cout << endl << "**ERROR** Couldn't obtain the 'Histo Names'."; } - header->GetValue("RunInfo/Time Zero Bin", ivec, ok); + header->GetValue("RunInfo/Time Zero Bin", dvec, ok); if (ok) { cout << endl << "Time Zero Bin: "; - for (UInt_t i=0; i - - - This is the generic PSI-ROOT header definition. - $Id$ - - - - - RunInfo - - - SampleEnv - - - MagFieldEnv - - - Beamline - - - Scaler - - - - - - RunInfo/Version - TString - - - RunInfo/Generator - TString - - - RunInfo/File Name - TString - - - RunInfo/Run Title - TString - - - RunInfo/Run Number - Int_t - - - RunInfo/Run Start Time - TString - - - RunInfo/Run Stop Time - TString - - - RunInfo/Run Duration - Int_t - - - RunInfo/Laboratory - TString - - - RunInfo/Area - TString - - - RunInfo/Instrument - TString - - - RunInfo/Muon Beam Momentum - TPsiRunProperty - - - RunInfo/Muon Species - TString - - - RunInfo/Setup - TString - - - RunInfo/Comment - TString - - - RunInfo/Sample Name - TString - - - RunInfo/Sample Temperature - TPsiRunProperty - - - RunInfo/Sample Magnetic Field - TPsiRunProperty - - - RunInfo/No of Histos - Int_t - - - RunInfo/Histo Names - TStringVector - - - RunInfo/Histo Length - Int_t - - - RunInfo/Time Resolution - TPsiRunProperty - - - RunInfo/Time Zero Bin - TIntVector - - - RunInfo/First Good Bin - TIntVector - - - RunInfo/Last Good Bin - TIntVector - - - RunInfo/Red-Green Offsets - TIntVector - - - RunInfo/Red-Green Description - TStringVector - - - RunInfo/Slow Control Histo Names - TStringVector - - - SampleEnv/Cryo - TString - - - SampleEnv/Insert - TString - - - SampleEnv/Orientation - TString - - - MagFieldEnv/Name - TString - - - MagFieldEnv/Current - TPsiRunProperty - - - Scaler/Ip - Int_t - - - - diff --git a/src/tests/PsiRoot/psi_root_test.xml b/src/tests/PsiRoot/psi_root_test.xml deleted file mode 100644 index 4b53c33c..00000000 --- a/src/tests/PsiRoot/psi_root_test.xml +++ /dev/null @@ -1,85 +0,0 @@ - - - - This is a test PSI-ROOT header definition. - $Id$ - - - - - RunInfo - - - SampleEnv - - - MagFieldEnv - - - Beamline - - - Scaler - - - - - - RunInfo/Version - TString - - - RunInfo/Generator - TString - - - RunInfo/File Name - TString - - - RunInfo/Run Title - TString - - - RunInfo/Run Number - Int_t - - - RunInfo/Sample Temperature - TPsiRunProperty - - - RunInfo/Time Resolution - TPsiRunProperty - - - RunInfo/Muon Beam Momentum - TPsiRunProperty - - - RunInfo/Histo Names - TStringVector - - - RunInfo/Time Zero Bin - TIntVector - - - SampleEnv/Cryo - TString - - - SampleEnv/CF2 - TPsiRunProperty - - - MagFieldEnv/Name - TString - - - MagFieldEnv/Current - TPsiRunProperty - - - - diff --git a/src/tests/PsiRoot/read_psi_runHeader.cpp b/src/tests/PsiRoot/read_musrRoot_runHeader.cpp similarity index 73% rename from src/tests/PsiRoot/read_psi_runHeader.cpp rename to src/tests/PsiRoot/read_musrRoot_runHeader.cpp index cb68e2be..7f694f08 100644 --- a/src/tests/PsiRoot/read_psi_runHeader.cpp +++ b/src/tests/PsiRoot/read_musrRoot_runHeader.cpp @@ -1,6 +1,6 @@ /*************************************************************************** - read_psi_runHeader.cpp + read_musrRoot_runHeader.cpp Author: Andreas Suter e-mail: andreas.suter@psi.ch @@ -10,7 +10,7 @@ ***************************************************************************/ /*************************************************************************** - * Copyright (C) 2007-2011 by Andreas Suter * + * Copyright (C) 2007-2012 by Andreas Suter * * andreas.suter@psi.ch * * * * This program is free software; you can redistribute it and/or modify * @@ -36,32 +36,24 @@ using namespace std; #include #include -#include "TPsiRunHeader.h" +#include "TMusrRunHeader.h" -void read_psi_runHeader_syntax() +void read_musrRoot_runHeader_syntax() { - cout << endl << "usage: read_psi_runHeader []"; + cout << endl << "usage: read_musrRoot_runHeader "; cout << endl << " is the file name including the extention root, e.g. test.root"; - cout << endl << " is the header definition XML-file."; - cout << endl << " 'strict'=strict validation; otherwise=less strict validation."; cout << endl << endl; } int main(int argc, char *argv[]) { - if ((argc != 3) && (argc != 4)) { - read_psi_runHeader_syntax(); + if (argc != 2) { + read_musrRoot_runHeader_syntax(); return 1; } - Bool_t strict = false; - if (argc == 4) { - if (!strcmp(argv[3], "strict")) - strict = true; - } - // read the file back and extract the header info - TFile *f = new TFile(argv[1], "READ", "read_psi_runHeader"); + TFile *f = new TFile(argv[1], "READ", "read_musrRoot_runHeader"); if (f->IsZombie()) { delete f; return -1; @@ -76,54 +68,56 @@ int main(int argc, char *argv[]) } TObjArray *oarray = 0; - TPsiRunHeader *header = new TPsiRunHeader(argv[2]); + 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(); + 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"); + 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; } - header->ExtractHeaderInformation(oarray, "SampleEnv"); + 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; } - header->ExtractHeaderInformation(oarray, "MagFieldEnv"); + 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; } - header->ExtractHeaderInformation(oarray, "Beamline"); + 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; } - header->ExtractHeaderInformation(oarray, "Scaler"); + if (!header->ExtractHeaderInformation(oarray, "Scaler")) return -1; f->Close(); delete f; - if (!header->IsValid(strict)) { - cerr << endl << ">> **ERROR** run header validation failed." << endl; - if (strict) { // clean up and quit - delete header; - return -1; - } - } - header->DumpHeader(); cout << endl << endl; diff --git a/src/tests/PsiRoot/write_psi_runHeader.cpp b/src/tests/PsiRoot/write_musrRoot_runHeader.cpp similarity index 86% rename from src/tests/PsiRoot/write_psi_runHeader.cpp rename to src/tests/PsiRoot/write_musrRoot_runHeader.cpp index 7bebda04..41b46416 100644 --- a/src/tests/PsiRoot/write_psi_runHeader.cpp +++ b/src/tests/PsiRoot/write_musrRoot_runHeader.cpp @@ -1,6 +1,6 @@ /*************************************************************************** - write_runHeader.cpp + write_musrRoot_runHeader.cpp Author: Andreas Suter e-mail: andreas.suter@psi.ch @@ -10,7 +10,7 @@ ***************************************************************************/ /*************************************************************************** - * Copyright (C) 2007-2011 by Andreas Suter * + * Copyright (C) 2007-2012 by Andreas Suter * * andreas.suter@psi.ch * * * * This program is free software; you can redistribute it and/or modify * @@ -40,33 +40,25 @@ using namespace std; #include #include -#include "TPsiRunHeader.h" +#include "TMusrRunHeader.h" -void write_psi_runHeader_syntax() +void write_musrRoot_runHeader_syntax() { - cout << endl << "usage: write_psi_runHeader []"; + cout << endl << "usage: write_musrRoot_runHeader "; cout << endl << " is the file name including the extention root, e.g. test.root"; - cout << endl << " is the header definition XML-file."; - cout << endl << " 'strict'=strict validation; otherwise=less strict validation."; cout << endl << endl; } int main(int argc, char *argv[]) { - if ((argc != 3) && (argc != 4)) { - write_psi_runHeader_syntax(); + if (argc != 2) { + write_musrRoot_runHeader_syntax(); return 1; } - Bool_t strict = false; - if (argc == 4) { - if (!strcmp(argv[3], "strict")) - strict = true; - } - - // PSI Run Header object - TPsiRunHeader *header = new TPsiRunHeader(argv[2]); - TPsiRunProperty prop; + // MusrRoot Run Header object + TMusrRunHeader *header = new TMusrRunHeader(argv[1]); + TMusrRunPhysicalQuantity prop; // run info header->Set("RunInfo/Version", "$Id$"); @@ -161,7 +153,7 @@ int main(int argc, char *argv[]) prop.Set("CF2", 3.2, 3.22, 0.04, "K"); header->Set("SampleEnv/CF2", prop); - prop.Set("CF3", PRH_UNDEFINED, 3.27, 0.09, "K", "strange temperature"); + 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"); @@ -189,22 +181,14 @@ int main(int argc, char *argv[]) // scaler header->Set("Scaler/Ip", 12332123); - if (!header->IsValid(strict)) { - cerr << endl << ">> **ERROR** run header validation failed." << endl; - if (strict) { // clean up and quit - delete header; - return -1; - } - } - - TFile *f = new TFile(argv[1], "RECREATE", "psi_runHeader_test"); + TFile *f = new TFile(argv[1], "RECREATE", "write_musrRoot_runHeader"); if (f->IsZombie()) { delete f; return -1; } // root file header related things - TFolder *runHeader = gROOT->GetRootFolder()->AddFolder("RunHeader", "PSI Run Header Info"); + TFolder *runHeader = gROOT->GetRootFolder()->AddFolder("RunHeader", "MusrRoot Run Header Info"); gROOT->GetListOfBrowsables()->Add(runHeader, "RunHeader"); TObjArray runInfo; @@ -227,6 +211,9 @@ int main(int argc, char *argv[]) header->GetHeaderInfo("Scaler", scaler); runHeader->Add(&scaler); + TMap *map = header->GetMap(); + runHeader->Add(map); + runHeader->Write(); f->Close();