some more work on PSI-ROOT

This commit is contained in:
nemu 2011-08-31 12:36:26 +00:00
parent b4728250d7
commit 956fd23a10
3 changed files with 1615 additions and 179 deletions

File diff suppressed because it is too large Load Diff

View File

@ -32,6 +32,7 @@
#ifndef TPSIRUNHEADER_H
#define TPSIRUNHEADER_H
#include <TDatime.h>
#include <TObject.h>
#include <TObjString.h>
#include <TObjArray.h>
@ -40,25 +41,28 @@ class TPsiRunProperty : public TObject
{
public:
TPsiRunProperty();
TPsiRunProperty(TString &name, Double_t demand, Double_t value, Double_t error, TString &unit, TString &description);
virtual ~TPsiRunProperty();
TPsiRunProperty(TString &name, Double_t demand, Double_t value, Double_t error, TString &unit, TString &description, TString &path);
virtual ~TPsiRunProperty() {}
virtual TString GetLabel() const { return fLabel; }
virtual TString GetLabel() const { return fLabel; }
virtual Double_t GetDemand() const { return fDemand; }
virtual Double_t GetValue() const { return fValue; }
virtual Double_t GetError() const { return fError; }
virtual TString GetUnit() const { return fUnit; }
virtual TString GetDescription() const { return fDescription; }
virtual TString GetPath() const { return fPath; }
virtual void SetLabel(TString &label) { fLabel = label; }
virtual void SetLabel(const char *label) { fLabel = label; }
virtual void SetDemand(Double_t val) { fDemand = val; }
virtual void SetValue(Double_t val) { fValue = val; }
virtual void SetError(Double_t err) { fError = err; }
virtual void SetUnit(TString &unit) { fUnit = unit.Data(); }
virtual void SetUnit(TString &unit) { fUnit = unit; }
virtual void SetUnit(const char *unit) { fUnit = unit; }
virtual void SetDescription(TString &str) { fDescription = str.Data(); }
virtual void SetDescription(TString &str) { fDescription = str; }
virtual void SetDescription(const char *str) { fDescription = str; }
virtual void SetPath(TString &str) { fPath = str; }
virtual void SetPath(const char *str) { fPath = str; }
private:
TString fLabel; ///< property label, like Sample Temperature etc.
@ -67,6 +71,7 @@ private:
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
TString fPath; ///< ROOT file path where to place the physical property
ClassDef(TPsiRunProperty, 1)
};
@ -77,52 +82,136 @@ public:
TPsiRunHeader();
virtual ~TPsiRunHeader();
virtual Bool_t IsValid(Bool_t strict = false);
virtual TString GetVersion() const { return fVersion; }
virtual TString GetGenerator() const { return fGenerator; }
virtual TString GetFileName() const { return fFileName; }
virtual TString GetRunTitle() const { return fRunTitle; }
virtual Int_t GetRunNumber() const { return fRunNumber; }
virtual TString GetLab() const { return fLaboratory; }
virtual TDatime GetStartTime() const { return fStartTime; }
virtual const char* GetStartTimeString() const { return fStartTime.AsSQLString(); }
virtual TDatime GetStopTime() const { return fStopTime; }
virtual const char* GetStopTimeString() const { return fStopTime.AsSQLString(); }
virtual TString GetLaboratory() const { return fLaboratory; }
virtual TString GetArea() const { return fArea; }
virtual TString GetInstrument() const { return fInstrument; }
virtual TString GetMuonSpecies() const { return fMuonSpecies; }
virtual TString GetSetup() const { return fSetup; }
virtual TString GetSample() const { return fSample; }
virtual TString GetOrientation() const { return fOrientation; }
virtual TPsiRunProperty* GetProperty(TString name);
virtual vector<TPsiRunProperty> *GetProperties() { return &fProperties; }
virtual TString GetSampleCryo() const { return fSampleCryo; }
virtual TString GetSampleCryoInsert() const { return fSampleCryoInsert; }
virtual TString GetSampleMagnetName() const { return fMagnetName; }
virtual Int_t GetNoOfHistos() const { return fNoOfHistos; }
virtual UInt_t GetNoOfHistoNames() const { return fHistoName.size(); }
virtual const vector<TString>* GetHistoNames() const { return &fHistoName; }
virtual TString GetHistoName(UInt_t idx, Bool_t &ok) const;
virtual Int_t GetHistoLength() const { return fHistoLength; }
virtual Double_t GetTimeResolution(const char *units) const;
virtual UInt_t GetNoOfTimeZeroBins() const { return fTimeZeroBin.size(); }
virtual const vector<UInt_t>* GetTimeZeroBins() const { return &fTimeZeroBin; }
virtual UInt_t GetTimeZeroBin(UInt_t idx, Bool_t &ok) const;
virtual const vector<UInt_t>* GetFirstGoodBins() const { return &fFirstGoodBin;}
virtual UInt_t GetFirstGoodBin(UInt_t idx, Bool_t &ok) const;
virtual const vector<UInt_t>* GetLastGoodBins() const { return &fLastGoodBin;}
virtual UInt_t GetLastGoodBin(UInt_t idx, Bool_t &ok) const;
virtual UInt_t GetNoOfRedGreenHistoOffsets() const { return fRedGreenOffset.size(); }
virtual const vector<UInt_t>* GetRedGreenHistoOffsets() const { return &fRedGreenOffset; }
virtual UInt_t GetRedGreenHistoOffset(UInt_t idx, Bool_t &ok) const;
virtual const vector<TString>* GetRedGreenHistoDescriptions() const { return &fRedGreenDescription; }
virtual TString GetRedGreenHistoDescription(UInt_t idx, Bool_t &ok) const;
virtual const TPsiRunProperty* GetProperty(TString name) const;
virtual const vector<TPsiRunProperty> *GetProperties() const { return &fProperties; }
virtual TObjArray *GetHeader();
virtual Bool_t ExtractHeaderInformation(TObjArray *runHeader);
virtual TObjArray *GetHeader(UInt_t &count);
virtual TObjArray *GetSampleEnv(UInt_t &count);
virtual TObjArray *GetMagFieldEnv(UInt_t &count);
virtual TObjArray *GetBeamline(UInt_t &count);
virtual TObjArray *GetScaler(UInt_t &count);
virtual Bool_t ExtractHeaderInformation(TObjArray *headerInfo, TString path="/");
virtual void SetGenerator(TString generator) { fGenerator = generator; }
virtual void SetFileName(TString fileName) { fFileName = fileName; }
virtual void SetRunTitle(TString runTitle) { fRunTitle = runTitle; }
virtual void SetRunNumber(Int_t runNumber) { fRunNumber = runNumber; }
virtual void SetLab(TString lab) { fLaboratory = lab; }
virtual void SetStartTime(TString startTime);
virtual void SetStopTime(TString stopTime);
virtual void SetLaboratory(TString lab) { fLaboratory = lab; }
virtual void SetArea(TString area) { fArea = area;}
virtual void SetInstrument(TString insturment) { fInstrument = insturment; }
virtual void SetMuonSpecies(TString muonSpecies) { fMuonSpecies = muonSpecies; }
virtual void SetSetup(TString setup) { fSetup = setup; }
virtual void SetSample(TString sample) { fSample = sample; }
virtual void SetOrientation(TString orientation) { fOrientation = orientation; }
virtual void SetSampleCryo(TString cryoName) { fSampleCryo = cryoName; }
virtual void SetSampleCryoInsert(TString cryoInsert) { fSampleCryoInsert = cryoInsert; }
virtual void SetSampleMagnetName(TString name) { fMagnetName = name; }
virtual void SetNoOfHistos(UInt_t noHistos) { fNoOfHistos = noHistos; }
virtual void SetHistoNames(vector<TString> names) { fHistoName = names; }
virtual void SetHistoName(TString name, Int_t idx=-1);
virtual void SetHistoLength(UInt_t length) { fHistoLength = (Int_t)length; }
virtual void SetTimeResolution(Double_t value, TString units);
virtual void SetTimeZeroBins(vector<UInt_t> timeZeroBins) { fTimeZeroBin = timeZeroBins; }
virtual void SetTimeZeroBin(UInt_t timeZeroBin, Int_t idx=-1);
virtual void SetFirstGoodBins(vector<UInt_t> fgb) { fFirstGoodBin = fgb; }
virtual void SetFirstGoodBin(UInt_t fgb, Int_t idx=-1);
virtual void SetLastGoodBins(vector<UInt_t> lgb) { fLastGoodBin = lgb; }
virtual void SetLastGoodBin(UInt_t lgb, Int_t idx=-1);
virtual void SetRedGreenHistogramOffsets(vector<UInt_t> offsets) { fRedGreenOffset = offsets; }
virtual void SetRedGreenHistogramOffset(UInt_t offset, Int_t idx=-1);
virtual void SetRedGreenDescriptions(vector<TString> description) { fRedGreenDescription = description; }
virtual void SetRedGreenDescription(TString description, Int_t idx=-1);
virtual void AddProperty(TPsiRunProperty &property);
virtual void AddProperty(TString name, Double_t demand, Double_t value, Double_t error, TString unit, TString desciption=TString(""));
virtual void AddProperty(TString name, Double_t demand, Double_t value, Double_t error, TString unit, TString desciption=TString(""), TString path=TString("/"));
virtual void DumpHeader() const;
virtual void DrawHeader() const;
private:
TString fVersion; /// SVN version of the TPsiRunHeader
TString fRunTitle; /// run title
Int_t fRunNumber; /// run number
TString fLaboratory; /// laboratory: PSI
TString fInstrument; /// instrument name like: GPS, LEM, ....
TString fSetup; /// setup
TString fSample; /// sample name
TString fOrientation; /// sample orientation
TString fVersion; ///< SVN version of the TPsiRunHeader
TString fGenerator; ///< program which generated the PSI-ROOT file
TString fFileName; ///< file name of the PSI-ROOT file
TString fRunTitle; ///< run title
Int_t fRunNumber; ///< run number
TDatime fStartTime; ///< run start time
TDatime fStopTime; ///< run stop time
TString fLaboratory; ///< laboratory: PSI
TString fArea; ///< secondary beamline label, e.g. piM3.2
TString fInstrument; ///< instrument name like: GPS, LEM, ....
TString fMuonSpecies; ///< postive muon or negative muon
TString fSetup; ///< setup
TString fSample; ///< sample name
TString fOrientation; ///< sample orientation
TString fSampleCryo; ///< sample cryo
TString fSampleCryoInsert; ///< sample cryo insert
TString fMagnetName; ///< name of the magnet used
Int_t fNoOfHistos; ///< number of histos
vector<TString> fHistoName; ///< names of the individual histograms
Int_t fHistoLength; ///< length of the histograms in bins
Double_t fTimeResolution; ///< time resolution in ps
vector<UInt_t> fTimeZeroBin; ///< time zero bins
vector<UInt_t> fFirstGoodBin; ///< first good bins
vector<UInt_t> fLastGoodBin; ///< last good bins
vector<UInt_t> fRedGreenOffset; ///< red/green mode histogram offsets
vector<TString> fRedGreenDescription; ///< red/green mode description
vector<TPsiRunProperty> fProperties;
TObjArray fHeader; /// header as TObjString array for dumping into a ROOT file
TObjArray fHeader; ///< header as TObjString array for dumping into a ROOT file
TObjArray fSampleEnv; ///< sample environment as TObjString array for dumping into a ROOT file
TObjArray fMagFieldEnv; ///< sample magnetic field environment as TObjString array for dumping into a ROOT file
TObjArray fBeamline; ///< beamline info as TObjString array for dumping into a ROOT file
TObjArray fScalers; ///< scaler info as TObjString array for dumping into a ROOT file
virtual Bool_t DecodePhyscialPorperty(TObjString *ostr, TPsiRunProperty &prop);
virtual Bool_t DecodePhyscialPorperty(TObjString *ostr, TPsiRunProperty &prop, TString &path);
virtual UInt_t GetDecimalPlace(Double_t val);
virtual UInt_t GetLeastSignificantDigit(Double_t val) const;
virtual void CleanUp(TObject *obj);
ClassDef(TPsiRunHeader, 1)
};

View File

@ -55,20 +55,56 @@ int main(int argc, char *argv[])
// PSI Run Header object
TPsiRunHeader *header = new TPsiRunHeader();
header->SetGenerator("psi_runHeader_test");
header->SetFileName(argv[1]);
header->SetRunTitle("This is a run title");
header->SetRunNumber(12345);
header->SetLab("PSI");
header->SetStartTime("2011-08-31 08:03:23");
header->SetStopTime("2011-08-31 10:46:48");
header->SetLaboratory("PSI");
header->SetInstrument("LEM");
header->SetArea("muE4");
header->AddProperty("Muon Beam Momentum", 28.0, 28.0, 0.7, "MeV/c");
header->SetMuonSpecies("positive Muon");
header->SetSetup("Konti-4, WEW");
header->SetSample("Eu2CuO4 MOD thin film");
header->SetOrientation("c-axis perp to spin");
header->AddProperty("Sample Temperature", 30.0, 30.01, 0.05, "K");
header->AddProperty("T1", 30.0, 30.003, 0.003, "K", "sample stick temperature");
header->AddProperty("Field", 3.0, 3.0003, 0.000025, "T");
header->AddProperty("BigError", 12.5, 13.2, 1.2, "Something", "Explain it");
header->AddProperty("ThisIsAVeryLongPropertyName", 3.001, 3.03, 0.03, "SI-Unit", "another interesting property");
header->AddProperty("This Is A Property With Spaces", 3.0, 3.03, 0.03, "SI-Unit", "yet another interesting property");
header->AddProperty("Sample Magnetic Field", 3.0, 3.0003, 0.000025, "T");
header->SetOrientation("c-axis perp to spin");
header->AddProperty("T1", 30.0, 30.003, 0.003, "K", "sample stick temperature", "/SampleEnv/");
header->SetSampleCryo("Konti-4");
header->SetSampleCryoInsert("n/a");
header->SetSampleMagnetName("Bpar");
header->AddProperty("Current", 1.54, 1.54, 0.003, "A", "Danfysik", "/MagFieldEnv/");
header->SetNoOfHistos(8);
header->SetHistoName("left/forward");
header->SetHistoName("top/forward");
header->SetHistoName("right/forward");
header->SetHistoName("bottom/forward");
header->SetHistoName("left/backward");
header->SetHistoName("top/backward");
header->SetHistoName("right/backward");
header->SetHistoName("bottom/backward");
header->SetHistoLength(66601);
header->SetTimeResolution(0.1953125, "ns");
for (Int_t i=0; i<header->GetNoOfHistos(); i++) {
header->SetTimeZeroBin(3419);
header->SetFirstGoodBin(3419);
header->SetLastGoodBin(65000);
}
header->SetRedGreenHistogramOffset(0);
header->SetRedGreenHistogramOffset(20);
header->SetRedGreenDescription("NPP");
header->SetRedGreenDescription("PPC");
if (!header->IsValid()) {
cerr << endl << ">> **ERROR** PSI-ROOT run header is not valid/complete." << endl;
delete header;
return -1;
}
TFile *f = new TFile(argv[1], "RECREATE", "psi_runHeader_test");
if (f->IsZombie()) {
@ -77,25 +113,85 @@ int main(int argc, char *argv[])
}
// root file header related things
UInt_t count = 1;
TFolder *runInfo = gROOT->GetRootFolder()->AddFolder("RunInfo", "PSI RunInfo");
gROOT->GetListOfBrowsables()->Add(runInfo, "RunInfo");
runInfo->Add(header->GetHeader());
runInfo->Add(header->GetHeader(count));
runInfo->Add(header->GetSampleEnv(count));
runInfo->Add(header->GetMagFieldEnv(count));
runInfo->Add(header->GetBeamline(count));
runInfo->Add(header->GetScaler(count));
runInfo->Write();
/*
f->mkdir("RunInfo");
f->cd("RunInfo");
header->GetHeader()->Write();
*/
f->Close();
delete f;
f = 0;
header->ExtractHeaderInformation(header->GetHeader());
header->DumpHeader();
delete header;
header = 0;
cout << endl << ">> read back " << argv[1] << endl;
// read the file back and extract the header info
f = new TFile(argv[1], "READ", "psi_runHeader_test");
if (f->IsZombie()) {
delete f;
return -1;
}
runInfo = 0;
f->GetObject("RunInfo", runInfo);
if (runInfo == 0) {
cerr << endl << ">> **ERROR** Couldn't get top folder RunInfo";
f->Close();
return -1;
}
TObjArray *oarray = 0;
header = new TPsiRunHeader();
// get RunHeader
oarray = (TObjArray*) runInfo->FindObjectAny("RunHeader");
if (oarray == 0) {
cerr << endl << ">> **ERROR** Couldn't get RunHeader" << endl;
}
header->ExtractHeaderInformation(oarray);
// get SampleEnv
oarray = (TObjArray*) runInfo->FindObjectAny("SampleEnv");
if (oarray == 0) {
cerr << endl << ">> **ERROR** Couldn't get SampleEnv" << endl;
}
header->ExtractHeaderInformation(oarray, "/SampleEnv/");
// get MagFieldEnv
oarray = (TObjArray*) runInfo->FindObjectAny("MagFieldEnv");
if (oarray == 0) {
cerr << endl << ">> **ERROR** Couldn't get MagFieldEnv" << endl;
}
header->ExtractHeaderInformation(oarray, "/MagFieldEnv/");
// get Beamline
oarray = (TObjArray*) runInfo->FindObjectAny("Beamline");
if (oarray == 0) {
cerr << endl << ">> **ERROR** Couldn't get Beamline" << endl;
}
header->ExtractHeaderInformation(oarray, "/Beamline/");
// get Scaler
oarray = (TObjArray*) runInfo->FindObjectAny("Scalers");
if (oarray == 0) {
cerr << endl << ">> **ERROR** Couldn't get Scalers" << endl;
}
header->ExtractHeaderInformation(oarray, "/Scalers/");
header->DumpHeader();
f->Close();
delete f;
return 0;
}