work in the direction of MusrROOT data file format. Use XSD instead of XML to validate. Work in progress ...

This commit is contained in:
suter_a 2012-01-12 09:55:19 +00:00
parent d2e6eacad2
commit 634077d772
12 changed files with 1519 additions and 2184 deletions

View File

@ -61,36 +61,36 @@ LIBS = $(ROOTLIBS) -lXMLParser
GLIBS = $(ROOTGLIBS) -lXMLParser GLIBS = $(ROOTGLIBS) -lXMLParser
# PSI libs # PSI libs
PSILIBS = -lTPsiRunHeader PSILIBS = -lTMusrRunHeader
EXEC = EXEC =
EXEC += psi_runHeader_test EXEC += musrRoot_runHeader_test
EXEC += write_psi_runHeader EXEC += write_musrRoot_runHeader
EXEC += read_psi_runHeader EXEC += read_musrRoot_runHeader
# some definitions: headers (used to generate *Dict* stuff), sources, objects,... # some definitions: headers (used to generate *Dict* stuff), sources, objects,...
OBJS = OBJS =
OBJS += psi_runHeader_test.o OBJS += musrRoot_runHeader_test.o
OBJS += write_psi_runHeader.o OBJS += write_musrRoot_runHeader.o
OBJS += read_psi_runHeader.o OBJS += read_musrRoot_runHeader.o
# make the executable: # make the executable:
# #
all: $(EXEC) all: $(EXEC)
psi_runHeader_test: psi_runHeader_test.o musrRoot_runHeader_test: musrRoot_runHeader_test.o
@echo "---> Building psi_runHeader_test ..." @echo "---> Building musrRoot_runHeader_test ..."
$(LD) psi_runHeader_test.o -o psi_runHeader_test $(GLIBS) $(PSILIBS) $(LD) musrRoot_runHeader_test.o -o musrRoot_runHeader_test $(GLIBS) $(PSILIBS)
@echo "done" @echo "done"
write_psi_runHeader: write_psi_runHeader.o write_musrRoot_runHeader: write_musrRoot_runHeader.o
@echo "---> Building write_psi_runHeader ..." @echo "---> Building write_musrRoot_runHeader ..."
$(LD) write_psi_runHeader.o -o write_psi_runHeader $(GLIBS) $(PSILIBS) $(LD) write_musrRoot_runHeader.o -o write_musrRoot_runHeader $(GLIBS) $(PSILIBS)
@echo "done" @echo "done"
read_psi_runHeader: read_psi_runHeader.o read_musrRoot_runHeader: read_musrRoot_runHeader.o
@echo "---> Building read_psi_runHeader ..." @echo "---> Building read_musrRoot_runHeader ..."
$(LD) read_psi_runHeader.o -o read_psi_runHeader $(GLIBS) $(PSILIBS) $(LD) read_musrRoot_runHeader.o -o read_musrRoot_runHeader $(GLIBS) $(PSILIBS)
@echo "done" @echo "done"
# clean up: remove all object file (and core files) # clean up: remove all object file (and core files)

View File

@ -1,18 +1,18 @@
# Makefile for TPH1F # Makefile for TMusrRunHeader
# #
# Copyright (c) 2000 Rene Brun and Fons Rademakers # Copyright (c) 2000 Rene Brun and Fons Rademakers
# #
# Author: Fons Rademakers, 29/2/2000 # Author: Fons Rademakers, 29/2/2000
# #
# modified: Andreas Suter, 14/04/2004 # modified: Andreas Suter, 12/01/2012
# modified: Thomas Prokscha, 30/01/2007 #
# # $Id$
# #
include Makefile.arch include Makefile.arch
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# TPsiRunHeader # TMusrRunHeader
TNAME = TPsiRunHeader TNAME = TMusrRunHeader
TLRHO = $(TNAME).$(ObjSuf) $(TNAME)Dict.$(ObjSuf) TLRHO = $(TNAME).$(ObjSuf) $(TNAME)Dict.$(ObjSuf)
TLRHS = $(TNAME).$(SrcSuf) $(TNAME)Dict.$(SrcSuf) TLRHS = $(TNAME).$(SrcSuf) $(TNAME)Dict.$(SrcSuf)
TLRHSO = lib$(TNAME).$(DllSuf) TLRHSO = lib$(TNAME).$(DllSuf)
@ -84,7 +84,7 @@ distclean: clean
@rm -rf cxx_repository @rm -rf cxx_repository
-@cd RootShower && $(MAKE) distclean -@cd RootShower && $(MAKE) distclean
install: install: $(TLRHS) $(TLRHSO)
ifeq ($(ARCH),linux) ifeq ($(ARCH),linux)
cp -pv $(MYLIBS)/$(TLRHSO) $(ROOTSYS)/lib cp -pv $(MYLIBS)/$(TLRHSO) $(ROOTSYS)/lib
cp -pv $(MYINCLUDES)/$(TNAME).h $(ROOTSYS)/include cp -pv $(MYINCLUDES)/$(TNAME).h $(ROOTSYS)/include

View File

@ -10,7 +10,7 @@ ARCH := $(shell root-config --arch)
CXX = CXX =
ObjSuf = o ObjSuf = o
SrcSuf = cxx SrcSuf = cpp
ExeSuf = ExeSuf =
DllSuf = so DllSuf = so
OutPutOpt = -o # keep whitespace after "-o" OutPutOpt = -o # keep whitespace after "-o"

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
/*************************************************************************** /***************************************************************************
TPsiRunHeader.h TMusrRunHeader.h
Author: Andreas Suter Author: Andreas Suter
e-mail: andreas.suter@psi.ch 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 * * andreas.suter@psi.ch *
* * * *
* This program is free software; you can redistribute it and/or modify * * This program is free software; you can redistribute it and/or modify *
@ -29,28 +29,30 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifndef TPSIRUNHEADER_H #ifndef TMUSRRUNHEADER_H
#define TPSIRUNHEADER_H #define TMUSRRUNHEADER_H
#include <TDatime.h> #include <TDatime.h>
#include <TObject.h> #include <TObject.h>
#include <TQObject.h> #include <TQObject.h>
#include <TObjString.h> #include <TObjString.h>
#include <TObjArray.h> #include <TObjArray.h>
#include <TMap.h>
#include <TSAXParser.h> #include <TSAXParser.h>
#define PRH_UNDEFINED -9.99e99 #define MRRH_UNDEFINED -9.99e99
typedef vector<Int_t> TIntVector; typedef vector<Int_t> TIntVector;
typedef vector<Double_t> TDoubleVector;
typedef vector<TString> TStringVector; typedef vector<TString> TStringVector;
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
template <class T> class TPsiRunObject : public TObject template <class T> class TMusrRunObject : public TObject
{ {
public: public:
TPsiRunObject() { fPathName = "n/a"; fType = "n/a"; } TMusrRunObject() { fPathName = "n/a"; fType = "n/a"; }
TPsiRunObject(TString pathName, TString type, T value) : fPathName(pathName), fType(type), fValue(value) {} TMusrRunObject(TString pathName, TString type, T value) : fPathName(pathName), fType(type), fValue(value) {}
virtual ~TPsiRunObject() {} virtual ~TMusrRunObject() {}
virtual TString GetPathName() { return fPathName; } virtual TString GetPathName() { return fPathName; }
virtual TString GetType() { return fType; } virtual TString GetType() { return fType; }
@ -67,14 +69,14 @@ private:
}; };
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
class TPsiRunProperty : public TObject class TMusrRunPhysicalQuantity : public TObject
{ {
public: public:
TPsiRunProperty(); TMusrRunPhysicalQuantity();
TPsiRunProperty(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, 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")); TMusrRunPhysicalQuantity(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")); TMusrRunPhysicalQuantity(TString label, Double_t value, TString unit, TString description = TString("n/a"));
virtual ~TPsiRunProperty() {} virtual ~TMusrRunPhysicalQuantity() {}
virtual TString GetLabel() const { return fLabel; } virtual TString GetLabel() const { return fLabel; }
virtual Double_t GetDemand() const { return fDemand; } virtual Double_t GetDemand() const { return fDemand; }
@ -98,88 +100,47 @@ public:
private: private:
TString fLabel; ///< property label, like Sample Temperature etc. TString fLabel; ///< property label, like Sample Temperature etc.
Double_t fDemand; ///< demand value of the property, e.g. temperature setpoint Double_t fDemand; ///< demand value of the physical quantity, e.g. temperature setpoint
Double_t fValue; ///< measured value of the property Double_t fValue; ///< measured value of the physical quantity
Double_t fError; ///< estimated error (standard deviation) of the measured property value Double_t fError; ///< estimated error (standard deviation) of the measured value
TString fUnit; ///< unit of the property TString fUnit; ///< unit of the physical quantity
TString fDescription; ///< a more detailed description of the property TString fDescription; ///< a more detailed description of the physical quantity
ClassDef(TPsiRunProperty, 1) ClassDef(TMusrRunPhysicalQuantity, 1)
}; };
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
class TPsiEntry class TMusrRunHeader : public TObject
{ {
public: public:
TPsiEntry() { fPathName = "n/a"; fType = "n/a"; } TMusrRunHeader();
TPsiEntry(TString pathName, TString type) : fPathName(pathName), fType(type) {} TMusrRunHeader(const char *fileName);
virtual ~TPsiEntry() {} virtual ~TMusrRunHeader();
virtual TString GetPathName() { return fPathName; } virtual TString GetFileName() { return fFileName; }
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<TPsiEntry> GetEntries() { return fEntry; }
private:
enum EKeyWords {eEmpty, eFolder, eEntry, eName, eType};
EKeyWords fKey, fGroupKey; ///< xml filter key
TStringVector fFolder;
vector<TPsiEntry> fEntry;
ClassDef(TPsiStartupHandler, 1)
};
//-------------------------------------------------------------------------
class TPsiRunHeader : public TObject
{
public:
TPsiRunHeader(const char *headerDefinition);
virtual ~TPsiRunHeader();
virtual Bool_t IsValid(Bool_t strict = false);
virtual void GetHeaderInfo(TString path, TObjArray &content); virtual void GetHeaderInfo(TString path, TObjArray &content);
virtual void GetValue(TString pathName, TString &value, Bool_t &ok); 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, 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, TStringVector &value, Bool_t &ok);
virtual void GetValue(TString pathName, TIntVector &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 TMap* GetMap() { return &fMap; }
virtual void Set(TString pathName, Int_t value);
virtual void Set(TString pathName, TPsiRunProperty value); virtual void SetFileName(TString fln) { fFileName = fln; }
virtual void Set(TString pathName, TStringVector value); virtual void SetMap(TMap* map);
virtual void Set(TString pathName, TIntVector value);
virtual void Set(TString pathName, TString value, Bool_t addMap=true);
virtual void Set(TString pathName, Int_t value, Bool_t addMap=true);
virtual void Set(TString pathName, Double_t value, Bool_t addMap=true);
virtual void Set(TString pathName, TMusrRunPhysicalQuantity value, Bool_t addMap=true);
virtual void Set(TString pathName, TStringVector value, Bool_t addMap=true);
virtual void Set(TString pathName, TIntVector value, Bool_t addMap=true);
virtual void Set(TString pathName, TDoubleVector value, Bool_t addMap=true);
virtual Bool_t ExtractHeaderInformation(TObjArray *headerInfo, TString path); virtual Bool_t ExtractHeaderInformation(TObjArray *headerInfo, TString path);
@ -187,22 +148,27 @@ public:
virtual void DrawHeader(); virtual void DrawHeader();
private: private:
TString fHeaderDefinition; TString fFileName;
vector< TPsiRunObject<TString> > fStringObj; vector< TMusrRunObject<TString> > fStringObj;
vector< TPsiRunObject<Int_t> > fIntObj; vector< TMusrRunObject<Int_t> > fIntObj;
vector< TPsiRunObject<TPsiRunProperty> > fPsiRunPropertyObj; vector< TMusrRunObject<Double_t> > fDoubleObj;
vector< TPsiRunObject<TStringVector> > fStringVectorObj; vector< TMusrRunObject<TMusrRunPhysicalQuantity> > fMusrRunPhysQuantityObj;
vector< TPsiRunObject<TIntVector> > fIntVectorObj; vector< TMusrRunObject<TStringVector> > fStringVectorObj;
vector< TMusrRunObject<TIntVector> > fIntVectorObj;
vector< TMusrRunObject<TDoubleVector> > fDoubleVectorObj;
TStringVector fFolder; TStringVector fFolder;
vector<TPsiEntry> 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 GetDecimalPlace(Double_t val);
virtual UInt_t GetLeastSignificantDigit(Double_t val) const; virtual UInt_t GetLeastSignificantDigit(Double_t val) const;
virtual void SplitPathName(TString pathName, TString &path, TString &name); 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

View File

@ -1,6 +1,6 @@
/*************************************************************************** /***************************************************************************
TPsiRunHeader2LinkDef.h TMusrRunHeaderLinkDef.h
Author: Andreas Suter Author: Andreas Suter
e-mail: andreas.suter@psi.ch 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 * * andreas.suter@psi.ch *
* * * *
* This program is free software; you can redistribute it and/or modify * * 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 classes;
#pragma link off all functions; #pragma link off all functions;
#pragma link C++ class TPsiRunProperty+; #pragma link C++ class TMusrRunPhysicalQuantity+;
#pragma link C++ class TPsiStartupHandler+; #pragma link C++ class TMusrRunHeader+;
#pragma link C++ class TPsiRunHeader+;
#endif #endif

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
/*************************************************************************** /***************************************************************************
psi_runHeader_test.cpp musrRoot_runHeader_test.cpp
Author: Andreas Suter Author: Andreas Suter
e-mail: andreas.suter@psi.ch 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 * * andreas.suter@psi.ch *
* * * *
* This program is free software; you can redistribute it and/or modify * * This program is free software; you can redistribute it and/or modify *
@ -36,39 +36,31 @@ using namespace std;
#include <TFile.h> #include <TFile.h>
#include <TFolder.h> #include <TFolder.h>
#include "TPsiRunHeader.h" #include "TMusrRunHeader.h"
void psi_runHeader_test_syntax() void musrRoot_runHeader_test_syntax()
{ {
cout << endl << "usage: psi_runHeader_test <fileName> <headerDefinition> [<strict>]"; cout << endl << "usage: musrRoot_runHeader_test <fileName>";
cout << endl << " <fileName> is the file name including the extention root, e.g. test.root"; cout << endl << " <fileName> is the file name including the extention root, e.g. test.root";
cout << endl << " <headerDefinition> is the header definition XML-file.";
cout << endl << " <strict> 'strict'=strict validation; otherwise=less strict validation.";
cout << endl << endl; cout << endl << endl;
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
if ((argc != 3) && (argc != 4)) { if (argc != 2) {
psi_runHeader_test_syntax(); musrRoot_runHeader_test_syntax();
return 1; return 1;
} }
Bool_t strict = false; // MusrRoot Run Header object
if (argc == 4) { TMusrRunHeader *header = new TMusrRunHeader(argv[1]);
if (!strcmp(argv[3], "strict")) TMusrRunPhysicalQuantity prop;
strict = true;
}
// PSI Run Header object
TPsiRunHeader *header = new TPsiRunHeader(argv[2]);
TPsiRunProperty prop;
// run info // run info
header->Set("RunInfo/Version", "$Id$"); header->Set("RunInfo/Version", "$Id$");
header->Set("RunInfo/Generator", "any2many"); header->Set("RunInfo/Generator", "any2many");
header->Set("RunInfo/File Name", "thisIsAFileName"); 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", 576);
header->Set("RunInfo/Run Number", 577); header->Set("RunInfo/Run Number", 577);
header->Set("RunInfo/Run Start Time", "2011-04-19 14:25:22"); 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"); prop.Set("Sample Temperature", 3.2, 3.21, 0.05, "K", "CF1");
header->Set("RunInfo/Sample Temperature", prop); 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); header->Set("RunInfo/Muon Beam Momentum", prop);
TStringVector detectorName; TStringVector detectorName;
@ -94,8 +86,8 @@ int main(int argc, char *argv[])
detectorName.push_back("bottom_up"); detectorName.push_back("bottom_up");
header->Set("RunInfo/Histo Names", detectorName); header->Set("RunInfo/Histo Names", detectorName);
TIntVector t0; TDoubleVector t0;
for (UInt_t i=0; i<8; i++) t0.push_back(3419); for (UInt_t i=0; i<8; i++) t0.push_back(3419.0);
header->Set("RunInfo/Time Zero Bin", t0); header->Set("RunInfo/Time Zero Bin", t0);
TStringVector dummyTest; TStringVector dummyTest;
@ -110,7 +102,7 @@ int main(int argc, char *argv[])
prop.Set("CF2", 3.2, 3.22, 0.04, "K"); prop.Set("CF2", 3.2, 3.22, 0.04, "K");
header->Set("SampleEnv/CF2", prop); 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); header->Set("SampleEnv/CF3", prop);
prop.Set("CF4", 3.25, 3.28, "K"); 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); for (UInt_t i=0; i<3; i++) dummyInt.push_back(i+1000);
header->Set("Beamline/Dummy Int", dummyInt); header->Set("Beamline/Dummy Int", dummyInt);
// scaler // scaler
header->Set("Scaler/Ip", 12332123); header->Set("Scaler/Ip", 12332123);
if (!header->IsValid(strict)) { TFile *f = new TFile(argv[1], "RECREATE", "musrRoot_runHeader_test");
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");
if (f->IsZombie()) { if (f->IsZombie()) {
delete f; delete f;
return -1; return -1;
} }
// root file header related things // 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"); gROOT->GetListOfBrowsables()->Add(runHeader, "RunHeader");
TObjArray runInfo; TObjArray runInfo;
@ -176,6 +159,9 @@ int main(int argc, char *argv[])
header->GetHeaderInfo("Scaler", scaler); header->GetHeaderInfo("Scaler", scaler);
runHeader->Add(&scaler); runHeader->Add(&scaler);
TMap *map = header->GetMap();
runHeader->Add(map);
runHeader->Write(); runHeader->Write();
f->Close(); f->Close();
@ -193,7 +179,7 @@ int main(int argc, char *argv[])
cout << endl << "++++++++++++++++++++++++++++" << endl; cout << endl << "++++++++++++++++++++++++++++" << endl;
// read the file back and extract the header info // 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()) { if (f->IsZombie()) {
delete f; delete f;
return -1; return -1;
@ -208,7 +194,15 @@ int main(int argc, char *argv[])
} }
TObjArray *oarray = 0; 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 // get RunHeader
oarray = (TObjArray*) runHeader->FindObjectAny("RunInfo"); oarray = (TObjArray*) runHeader->FindObjectAny("RunInfo");
@ -248,14 +242,6 @@ int main(int argc, char *argv[])
f->Close(); f->Close();
delete f; 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(); header->DumpHeader();
// get some information from the read file // get some information from the read file
@ -266,8 +252,8 @@ int main(int argc, char *argv[])
TString str(""); TString str("");
TStringVector strVec; TStringVector strVec;
Int_t ival; Int_t ival;
TIntVector ivec; TDoubleVector dvec;
TPsiRunProperty prop1; TMusrRunPhysicalQuantity prop1;
Bool_t ok; Bool_t ok;
header->GetValue("RunInfo/Run Title", str, 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'."; 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) { if (ok) {
cout << endl << "Time Zero Bin: "; cout << endl << "Time Zero Bin: ";
for (UInt_t i=0; i<ivec.size()-1; i++) { for (UInt_t i=0; i<dvec.size()-1; i++) {
cout << ivec[i] << ", "; cout << dvec[i] << ", ";
} }
cout << ivec[ivec.size()-1]; cout << dvec[dvec.size()-1];
} else { } else {
cout << endl << "**ERROR** Couldn't obtain the 'Time Zero Bin'."; cout << endl << "**ERROR** Couldn't obtain the 'Time Zero Bin'.";
} }

View File

@ -1,165 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<psi_root xmlns="http://lmu.web.psi.ch/facilities/software/psi-root.html">
<commet>
This is the generic PSI-ROOT header definition.
$Id$
</commet>
<folder_structure>
<folder>
<name>RunInfo</name>
</folder>
<folder>
<name>SampleEnv</name>
</folder>
<folder>
<name>MagFieldEnv</name>
</folder>
<folder>
<name>Beamline</name>
</folder>
<folder>
<name>Scaler</name>
</folder>
</folder_structure>
<header_info>
<entry>
<name>RunInfo/Version</name>
<type>TString</type>
</entry>
<entry>
<name>RunInfo/Generator</name>
<type>TString</type>
</entry>
<entry>
<name>RunInfo/File Name</name>
<type>TString</type>
</entry>
<entry>
<name>RunInfo/Run Title</name>
<type>TString</type>
</entry>
<entry>
<name>RunInfo/Run Number</name>
<type>Int_t</type>
</entry>
<entry>
<name>RunInfo/Run Start Time</name>
<type>TString</type>
</entry>
<entry>
<name>RunInfo/Run Stop Time</name>
<type>TString</type>
</entry>
<entry>
<name>RunInfo/Run Duration</name>
<type>Int_t</type>
</entry>
<entry>
<name>RunInfo/Laboratory</name>
<type>TString</type>
</entry>
<entry>
<name>RunInfo/Area</name>
<type>TString</type>
</entry>
<entry>
<name>RunInfo/Instrument</name>
<type>TString</type>
</entry>
<entry>
<name>RunInfo/Muon Beam Momentum</name>
<type>TPsiRunProperty</type>
</entry>
<entry>
<name>RunInfo/Muon Species</name>
<type>TString</type>
</entry>
<entry>
<name>RunInfo/Setup</name>
<type>TString</type>
</entry>
<entry>
<name>RunInfo/Comment</name>
<type>TString</type>
</entry>
<entry>
<name>RunInfo/Sample Name</name>
<type>TString</type>
</entry>
<entry>
<name>RunInfo/Sample Temperature</name>
<type>TPsiRunProperty</type>
</entry>
<entry>
<name>RunInfo/Sample Magnetic Field</name>
<type>TPsiRunProperty</type>
</entry>
<entry>
<name>RunInfo/No of Histos</name>
<type>Int_t</type>
</entry>
<entry>
<name>RunInfo/Histo Names</name>
<type>TStringVector</type>
</entry>
<entry>
<name>RunInfo/Histo Length</name>
<type>Int_t</type>
</entry>
<entry>
<name>RunInfo/Time Resolution</name>
<type>TPsiRunProperty</type>
</entry>
<entry>
<name>RunInfo/Time Zero Bin</name>
<type>TIntVector</type>
</entry>
<entry>
<name>RunInfo/First Good Bin</name>
<type>TIntVector</type>
</entry>
<entry>
<name>RunInfo/Last Good Bin</name>
<type>TIntVector</type>
</entry>
<entry>
<name>RunInfo/Red-Green Offsets</name>
<type>TIntVector</type>
</entry>
<entry>
<name>RunInfo/Red-Green Description</name>
<type>TStringVector</type>
</entry>
<entry>
<name>RunInfo/Slow Control Histo Names</name>
<type>TStringVector</type>
</entry>
<entry>
<name>SampleEnv/Cryo</name>
<type>TString</type>
</entry>
<entry>
<name>SampleEnv/Insert</name>
<type>TString</type>
</entry>
<entry>
<name>SampleEnv/Orientation</name>
<type>TString</type>
</entry>
<entry>
<name>MagFieldEnv/Name</name>
<type>TString</type>
</entry>
<entry>
<name>MagFieldEnv/Current</name>
<type>TPsiRunProperty</type>
</entry>
<entry>
<name>Scaler/Ip</name>
<type>Int_t</type>
</entry>
</header_info>
</psi_root>

View File

@ -1,85 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<psi_root xmlns="http://lmu.web.psi.ch/facilities/software/psi-root.html">
<commet>
This is a test PSI-ROOT header definition.
$Id$
</commet>
<folder_structure>
<folder>
<name>RunInfo</name>
</folder>
<folder>
<name>SampleEnv</name>
</folder>
<folder>
<name>MagFieldEnv</name>
</folder>
<folder>
<name>Beamline</name>
</folder>
<folder>
<name>Scaler</name>
</folder>
</folder_structure>
<header_info>
<entry>
<name>RunInfo/Version</name>
<type>TString</type>
</entry>
<entry>
<name>RunInfo/Generator</name>
<type>TString</type>
</entry>
<entry>
<name>RunInfo/File Name</name>
<type>TString</type>
</entry>
<entry>
<name>RunInfo/Run Title</name>
<type>TString</type>
</entry>
<entry>
<name>RunInfo/Run Number</name>
<type>Int_t</type>
</entry>
<entry>
<name>RunInfo/Sample Temperature</name>
<type>TPsiRunProperty</type>
</entry>
<entry>
<name>RunInfo/Time Resolution</name>
<type>TPsiRunProperty</type>
</entry>
<entry>
<name>RunInfo/Muon Beam Momentum</name>
<type>TPsiRunProperty</type>
</entry>
<entry>
<name>RunInfo/Histo Names</name>
<type>TStringVector</type>
</entry>
<entry>
<name>RunInfo/Time Zero Bin</name>
<type>TIntVector</type>
</entry>
<entry>
<name>SampleEnv/Cryo</name>
<type>TString</type>
</entry>
<entry>
<name>SampleEnv/CF2</name>
<type>TPsiRunProperty</type>
</entry>
<entry>
<name>MagFieldEnv/Name</name>
<type>TString</type>
</entry>
<entry>
<name>MagFieldEnv/Current</name>
<type>TPsiRunProperty</type>
</entry>
</header_info>
</psi_root>

View File

@ -1,6 +1,6 @@
/*************************************************************************** /***************************************************************************
read_psi_runHeader.cpp read_musrRoot_runHeader.cpp
Author: Andreas Suter Author: Andreas Suter
e-mail: andreas.suter@psi.ch 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 * * andreas.suter@psi.ch *
* * * *
* This program is free software; you can redistribute it and/or modify * * This program is free software; you can redistribute it and/or modify *
@ -36,32 +36,24 @@ using namespace std;
#include <TFile.h> #include <TFile.h>
#include <TFolder.h> #include <TFolder.h>
#include "TPsiRunHeader.h" #include "TMusrRunHeader.h"
void read_psi_runHeader_syntax() void read_musrRoot_runHeader_syntax()
{ {
cout << endl << "usage: read_psi_runHeader <fileName> <headerDefinition> [<strict>]"; cout << endl << "usage: read_musrRoot_runHeader <fileName>";
cout << endl << " <fileName> is the file name including the extention root, e.g. test.root"; cout << endl << " <fileName> is the file name including the extention root, e.g. test.root";
cout << endl << " <headerDefinition> is the header definition XML-file.";
cout << endl << " <strict> 'strict'=strict validation; otherwise=less strict validation.";
cout << endl << endl; cout << endl << endl;
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
if ((argc != 3) && (argc != 4)) { if (argc != 2) {
read_psi_runHeader_syntax(); read_musrRoot_runHeader_syntax();
return 1; 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 // 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()) { if (f->IsZombie()) {
delete f; delete f;
return -1; return -1;
@ -76,54 +68,56 @@ int main(int argc, char *argv[])
} }
TObjArray *oarray = 0; 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 // get RunHeader
oarray = (TObjArray*) runHeader->FindObjectAny("RunInfo"); oarray = (TObjArray*) runHeader->FindObjectAny("RunInfo");
if (oarray == 0) { if (oarray == 0) {
cerr << endl << ">> **ERROR** Couldn't get RunInfo" << endl; cerr << endl << ">> **ERROR** Couldn't get RunInfo" << endl;
} }
header->ExtractHeaderInformation(oarray, "RunInfo"); if (!header->ExtractHeaderInformation(oarray, "RunInfo")) return -1;
// get SampleEnv // get SampleEnv
oarray = (TObjArray*) runHeader->FindObjectAny("SampleEnv"); oarray = (TObjArray*) runHeader->FindObjectAny("SampleEnv");
if (oarray == 0) { if (oarray == 0) {
cerr << endl << ">> **ERROR** Couldn't get SampleEnv" << endl; cerr << endl << ">> **ERROR** Couldn't get SampleEnv" << endl;
} }
header->ExtractHeaderInformation(oarray, "SampleEnv"); if (!header->ExtractHeaderInformation(oarray, "SampleEnv")) return -1;
// get MagFieldEnv // get MagFieldEnv
oarray = (TObjArray*) runHeader->FindObjectAny("MagFieldEnv"); oarray = (TObjArray*) runHeader->FindObjectAny("MagFieldEnv");
if (oarray == 0) { if (oarray == 0) {
cerr << endl << ">> **ERROR** Couldn't get MagFieldEnv" << endl; cerr << endl << ">> **ERROR** Couldn't get MagFieldEnv" << endl;
} }
header->ExtractHeaderInformation(oarray, "MagFieldEnv"); if (!header->ExtractHeaderInformation(oarray, "MagFieldEnv")) return -1;
// get Beamline // get Beamline
oarray = (TObjArray*) runHeader->FindObjectAny("Beamline"); oarray = (TObjArray*) runHeader->FindObjectAny("Beamline");
if (oarray == 0) { if (oarray == 0) {
cerr << endl << ">> **ERROR** Couldn't get Beamline" << endl; cerr << endl << ">> **ERROR** Couldn't get Beamline" << endl;
} }
header->ExtractHeaderInformation(oarray, "Beamline"); if (!header->ExtractHeaderInformation(oarray, "Beamline")) return -1;
// get Scaler // get Scaler
oarray = (TObjArray*) runHeader->FindObjectAny("Scaler"); oarray = (TObjArray*) runHeader->FindObjectAny("Scaler");
if (oarray == 0) { if (oarray == 0) {
cerr << endl << ">> **ERROR** Couldn't get Scaler" << endl; cerr << endl << ">> **ERROR** Couldn't get Scaler" << endl;
} }
header->ExtractHeaderInformation(oarray, "Scaler"); if (!header->ExtractHeaderInformation(oarray, "Scaler")) return -1;
f->Close(); f->Close();
delete f; 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(); header->DumpHeader();
cout << endl << endl; cout << endl << endl;

View File

@ -1,6 +1,6 @@
/*************************************************************************** /***************************************************************************
write_runHeader.cpp write_musrRoot_runHeader.cpp
Author: Andreas Suter Author: Andreas Suter
e-mail: andreas.suter@psi.ch 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 * * andreas.suter@psi.ch *
* * * *
* This program is free software; you can redistribute it and/or modify * * This program is free software; you can redistribute it and/or modify *
@ -40,33 +40,25 @@ using namespace std;
#include <TFile.h> #include <TFile.h>
#include <TFolder.h> #include <TFolder.h>
#include "TPsiRunHeader.h" #include "TMusrRunHeader.h"
void write_psi_runHeader_syntax() void write_musrRoot_runHeader_syntax()
{ {
cout << endl << "usage: write_psi_runHeader <fileName> <headerDefinition> [<strict>]"; cout << endl << "usage: write_musrRoot_runHeader <fileName>";
cout << endl << " <fileName> is the file name including the extention root, e.g. test.root"; cout << endl << " <fileName> is the file name including the extention root, e.g. test.root";
cout << endl << " <headerDefinition> is the header definition XML-file.";
cout << endl << " <strict> 'strict'=strict validation; otherwise=less strict validation.";
cout << endl << endl; cout << endl << endl;
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
if ((argc != 3) && (argc != 4)) { if (argc != 2) {
write_psi_runHeader_syntax(); write_musrRoot_runHeader_syntax();
return 1; return 1;
} }
Bool_t strict = false; // MusrRoot Run Header object
if (argc == 4) { TMusrRunHeader *header = new TMusrRunHeader(argv[1]);
if (!strcmp(argv[3], "strict")) TMusrRunPhysicalQuantity prop;
strict = true;
}
// PSI Run Header object
TPsiRunHeader *header = new TPsiRunHeader(argv[2]);
TPsiRunProperty prop;
// run info // run info
header->Set("RunInfo/Version", "$Id$"); 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"); prop.Set("CF2", 3.2, 3.22, 0.04, "K");
header->Set("SampleEnv/CF2", prop); 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); header->Set("SampleEnv/CF3", prop);
prop.Set("CF4", 3.25, 3.28, "K"); prop.Set("CF4", 3.25, 3.28, "K");
@ -189,22 +181,14 @@ int main(int argc, char *argv[])
// scaler // scaler
header->Set("Scaler/Ip", 12332123); header->Set("Scaler/Ip", 12332123);
if (!header->IsValid(strict)) { TFile *f = new TFile(argv[1], "RECREATE", "write_musrRoot_runHeader");
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");
if (f->IsZombie()) { if (f->IsZombie()) {
delete f; delete f;
return -1; return -1;
} }
// root file header related things // 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"); gROOT->GetListOfBrowsables()->Add(runHeader, "RunHeader");
TObjArray runInfo; TObjArray runInfo;
@ -227,6 +211,9 @@ int main(int argc, char *argv[])
header->GetHeaderInfo("Scaler", scaler); header->GetHeaderInfo("Scaler", scaler);
runHeader->Add(&scaler); runHeader->Add(&scaler);
TMap *map = header->GetMap();
runHeader->Add(map);
runHeader->Write(); runHeader->Write();
f->Close(); f->Close();