added minimal NeXus IDF 2 support.

This commit is contained in:
nemu 2011-08-23 17:22:29 +00:00
parent b67a19d406
commit 03b9fe1e71
12 changed files with 5355 additions and 1845 deletions

View File

@ -6,6 +6,7 @@
changes since 0.9.0
===================================
NEW added minimal NeXus IDF 2 support.
NEW Added the online documentation to the repository. It can be found under "doc/html".
NEW added chisq per run block information (all fit types). The same output rules as for the expected chisq are in place.
NEW calculate expected chisq (Pearson's chisq) for single histogram fits. It always will send this information to the stdout

Binary file not shown.

View File

@ -0,0 +1,74 @@
nc-ZnO T=80 F=69
###############################################################
FITPARAMETER
# No Name Value Step Pos_Error Boundaries
1 zero 0 0 none
2 phase 2.84 -0.43 0.43 0 100
3 field 70.996 -0.035 0.035 0 none
4 asym 0.1698 -0.0016 0.0017 0 0.3
5 rate 0.1523 -0.0023 0.0023 0 100
6 beta 1.261 -0.046 0.047
7 Norm_L 2409.7 -1.2 1.2
8 BG_L 0 0 none 0 none
9 Norm_R 2120.7 -1.1 1.1 0 none
10 BG_R 0 0 none 0 none
11 relPhase 182.26 -0.44 0.44 0 none
###############################################################
THEORY
asymmetry 4
generExpo 5 6 (rate exponent)
TFieldCos fun1 fun2 (phase frequency)
###############################################################
FUNCTIONS
fun1 = par2 + map1
fun2 = gamma_mu * par3
###############################################################
RUN data/emu00005989_v2 XXXX ISIS NEXUS (name beamline institute data-file-format)
fittype 0 (single histogram fit)
norm 7
backgr.fit 8
lifetimecorrection
map 1 0 0 0 0 0 0 0 0 0
forward 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
data 40 1500
fit 0.2 14
packing 1
RUN data/emu00005989_v2 XXXX ISIS NEXUS (name beamline institute data-file-format)
fittype 0 (single histogram fit)
norm 9
backgr.fit 10
lifetimecorrection
map 11 0 0 0 0 0 0 0 0 0
forward 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
data 40 1500
fit 0.2 14
packing 1
###############################################################
COMMANDS
MINIMIZE
MINOS
SAVE
###############################################################
FOURIER
units Gauss # units either 'Gauss', 'MHz', or 'Mc/s'
fourier_power 10
apodization STRONG # NONE, WEAK, MEDIUM, STRONG
plot REAL # REAL, IMAG, REAL_AND_IMAG, POWER, PHASE
range 0 100
phase par2
###############################################################
PLOT 0 (single histo plot)
runs 1 2
range 0 14 -0.22 0.22
view_packing 5
###############################################################
STATISTIC --- 2011-08-23 14:56:52
chisq = 2643.1, NDF = 1696, chisq/NDF = 1.558403

View File

@ -64,9 +64,10 @@ void any2many_syntax()
cout << endl << " etc., or a sequence of runs <runStart>-<runEnd>, e.g. 111-222";
cout << endl << " -c <convert-options> : <inFormat> <outFormat>";
cout << endl << " <inFormat> : input data file format. Supported formats are:";
cout << endl << " PSI-BIN, ROOT (LEM), MUD, NeXus, PSI-MDU, WKM";
cout << endl << " PSI-BIN, ROOT (LEM), MUD, NeXus1, NeXus2, PSI-MDU, WKM";
cout << endl << " <outFormat> : ouput data file format. Supported formats are:";
cout << endl << " PSI-BIN, ROOT (LEM), MUD, NeXus-HDF4, NeXus-HDF5, NeXus-XML, WKM, ASCII";
cout << endl << " PSI-BIN, ROOT (LEM), MUD, NeXus1-HDF4, NeXus1-HDF5, NeXus1-XML,";
cout << endl << " NeXus2-HDF4, NeXus2-HDF5, NeXus2-XML, WKM, ASCII";
cout << endl << " -p <output-path> : where <output-path> is the output path for the";
cout << endl << " converted files. If nothing is given, the current directory";
cout << endl << " will be used, unless the option '-s' is used.";
@ -149,9 +150,12 @@ int main(int argc, char *argv[])
outputFormat.push_back("psi-bin");
outputFormat.push_back("root");
outputFormat.push_back("mud");
outputFormat.push_back("nexus-hdf4");
outputFormat.push_back("nexus-hdf5");
outputFormat.push_back("nexus-xml");
outputFormat.push_back("nexus1-hdf4");
outputFormat.push_back("nexus1-hdf5");
outputFormat.push_back("nexus1-xml");
outputFormat.push_back("nexus2-hdf4");
outputFormat.push_back("nexus2-hdf5");
outputFormat.push_back("nexus2-xml");
outputFormat.push_back("wkm");
outputFormat.push_back("ascii");
@ -159,6 +163,7 @@ int main(int argc, char *argv[])
info.useStandardOutput = false;
info.rebin = 1;
info.compressionTag = 0; // no compression as default
info.idf = 0; // undefined
// call any2many without arguments
if (argc == 1) {
@ -404,6 +409,12 @@ int main(int argc, char *argv[])
show_syntax = true;
}
// check if the output format is nexus
if (info.outFormat.Contains("nexus1", TString::kIgnoreCase))
info.idf = 1;
if (info.outFormat.Contains("nexus2", TString::kIgnoreCase))
info.idf = 2;
if (show_syntax) {
info.runList.clear();
any2many_syntax();

View File

@ -1346,7 +1346,9 @@ Bool_t PRunDataHandler::ReadNexusFile()
PDoubleVector histoData;
PRawRunData runData;
TString str;
string sstr;
Double_t dval;
bool ok;
PNeXus *nxs_file = new PNeXus(fRunPathName.Data());
if (!nxs_file->IsValid()) {
@ -1355,81 +1357,265 @@ Bool_t PRunDataHandler::ReadNexusFile()
return false;
}
// get header information
// get/set run title
str = TString(nxs_file->GetRunTitle());
runData.SetRunTitle(str);
// get/set run number
runData.SetRunNumber(nxs_file->GetRunNumber());
// get/set temperature
runData.SetTemperature(0, nxs_file->GetSampleTemperature(), 0.0);
// get/set field
dval = nxs_file->GetMagneticField();
str = TString(nxs_file->GetMagneticFieldUnits());
// since field has to be given in Gauss, check the units
Double_t factor=1.0;
if (!str.CompareTo("gauss", TString::kIgnoreCase))
factor=1.0;
else if (!str.CompareTo("tesla", TString::kIgnoreCase))
factor=1.0e4;
else
factor=1.0;
runData.SetField(factor*dval);
// get/set implantation energy
runData.SetEnergy(PMUSR_UNDEFINED);
// get/set moderator HV
runData.SetTransport(PMUSR_UNDEFINED);
// get/set RA HV's (LEM specific)
for (UInt_t i=0; i<4; i++)
runData.SetRingAnode(i, PMUSR_UNDEFINED);
// get/set setup
runData.SetSetup(nxs_file->GetRunNotes());
// get/set sample
runData.SetSample(nxs_file->GetSampleName());
// get/set orientation
runData.SetOrientation("??");
// get/set time resolution (ns)
runData.SetTimeResolution(nxs_file->GetTimeResolution());
// get/set start/stop time
runData.SetStartTime(nxs_file->GetStartTime());
runData.SetStartDate(nxs_file->GetStartDate());
runData.SetStopTime(nxs_file->GetStopTime());
runData.SetStopDate(nxs_file->GetStopDate());
// get t0, firstGoodBin, lastGoodBin, data
UInt_t t0=nxs_file->GetT0();
PIntPair goodDataBin;
goodDataBin.first = nxs_file->GetFirstGoodBin();
goodDataBin.second = nxs_file->GetLastGoodBin();
PDoubleVector data;
for (Int_t i=0; i<nxs_file->GetNoHistos(); i++) {
runData.AppendT0(t0);
runData.AppendGoodDataBin(goodDataBin);
data.clear();
for (UInt_t j=0; j<nxs_file->GetHisto(i)->size(); j++) {
data.push_back((Double_t)nxs_file->GetHisto(i)->at(j));
if (nxs_file->GetIdfVersion() == 1) {
if (!nxs_file->IsValid()) {
cout << endl << "**ERROR** invalid NeXus IDF 2 version file found." << endl;
return false;
}
runData.AppendDataBin(data);
// get header information
// get/set run title
str = TString(nxs_file->GetEntryIdf1()->GetTitle());
runData.SetRunTitle(str);
// get/set run number
runData.SetRunNumber(nxs_file->GetEntryIdf1()->GetRunNumber());
// get/set temperature
dval = nxs_file->GetEntryIdf1()->GetSample()->GetPhysPropValue("temperature", ok);
if (ok)
runData.SetTemperature(0, dval, 0.0);
// get/set field
dval = nxs_file->GetEntryIdf1()->GetSample()->GetPhysPropValue("magnetic_field", ok);
nxs_file->GetEntryIdf1()->GetSample()->GetPhysPropUnit("magnetic_field", sstr, ok);
str = sstr;
// since field has to be given in Gauss, check the units
Double_t factor=1.0;
if (!str.CompareTo("gauss", TString::kIgnoreCase))
factor=1.0;
else if (!str.CompareTo("tesla", TString::kIgnoreCase))
factor=1.0e4;
else
factor=1.0;
runData.SetField(factor*dval);
// get/set implantation energy
runData.SetEnergy(PMUSR_UNDEFINED);
// get/set moderator HV
runData.SetTransport(PMUSR_UNDEFINED);
// get/set RA HV's (LEM specific)
for (UInt_t i=0; i<4; i++)
runData.SetRingAnode(i, PMUSR_UNDEFINED);
// get/set setup
runData.SetSetup(nxs_file->GetEntryIdf1()->GetNotes());
// get/set sample
runData.SetSample(nxs_file->GetEntryIdf1()->GetSample()->GetName());
// get/set orientation
runData.SetOrientation("??");
// get/set time resolution (ns)
runData.SetTimeResolution(nxs_file->GetEntryIdf1()->GetData()->GetTimeResolution("ns"));
// get/set start/stop time
sstr = nxs_file->GetEntryIdf1()->GetStartTime();
str = sstr;
TString date, time;
SplitTimeDate(str, time, date, ok);
if (ok) {
runData.SetStartTime(time);
runData.SetStartDate(date);
}
sstr = nxs_file->GetEntryIdf1()->GetStopTime();
str = sstr;
SplitTimeDate(str, time, date, ok);
if (ok) {
runData.SetStopTime(time);
runData.SetStopDate(date);
}
// get/set t0, firstGoodBin, lastGoodBin
vector<unsigned int> *t0 = nxs_file->GetEntryIdf1()->GetData()->GetT0s();
vector<unsigned int> *fgb = nxs_file->GetEntryIdf1()->GetData()->GetFirstGoodBins();
vector<unsigned int> *lgb = nxs_file->GetEntryIdf1()->GetData()->GetLastGoodBins();
PIntPair goodDataBin;
for (UInt_t i=0; i<nxs_file->GetEntryIdf1()->GetData()->GetNoOfHistos(); i++) {
if (i<t0->size()) {
runData.AppendT0(t0->at(i));
} else {
runData.AppendT0(t0->at(0));
}
if (i<fgb->size()) {
goodDataBin.first = fgb->at(i);
goodDataBin.second = lgb->at(i);
} else {
goodDataBin.first = fgb->at(0);
goodDataBin.second = lgb->at(0);
}
runData.AppendGoodDataBin(goodDataBin);
}
// get/set data
vector<unsigned int> *pdata;
PDoubleVector data;
for (UInt_t i=0; i<nxs_file->GetEntryIdf1()->GetData()->GetNoOfHistos(); i++) {
pdata = nxs_file->GetEntryIdf1()->GetData()->GetHisto(i);
for (UInt_t j=0; j<pdata->size(); j++)
data.push_back(pdata->at(j));
runData.AppendDataBin(data);
data.clear();
}
// keep run name from the msr-file
runData.SetRunName(fRunName);
// keep the information
fData.push_back(runData);
} else if (nxs_file->GetIdfVersion() == 2) {
if (!nxs_file->IsValid()) {
cout << endl << "**ERROR** invalid NeXus IDF 2 version file found." << endl;
return false;
}
// get header information
// get/set run title
str = TString(nxs_file->GetEntryIdf2()->GetTitle());
runData.SetRunTitle(str);
// get/set run number
runData.SetRunNumber(nxs_file->GetEntryIdf2()->GetRunNumber());
// get/set temperature
dval = nxs_file->GetEntryIdf2()->GetSample()->GetPhysPropValue("temperature", ok);
if (ok)
runData.SetTemperature(0, dval, 0.0);
// get/set field
dval = nxs_file->GetEntryIdf2()->GetSample()->GetPhysPropValue("magnetic_field", ok);
nxs_file->GetEntryIdf2()->GetSample()->GetPhysPropUnit("magnetic_field", sstr, ok);
str = sstr;
// since field has to be given in Gauss, check the units
Double_t factor=1.0;
if (!str.CompareTo("gauss", TString::kIgnoreCase))
factor=1.0;
else if (!str.CompareTo("tesla", TString::kIgnoreCase))
factor=1.0e4;
else
factor=1.0;
runData.SetField(factor*dval);
// get/set implantation energy
runData.SetEnergy(PMUSR_UNDEFINED);
// get/set moderator HV
runData.SetTransport(PMUSR_UNDEFINED);
// get/set RA HV's (LEM specific)
for (UInt_t i=0; i<4; i++)
runData.SetRingAnode(i, PMUSR_UNDEFINED);
// get/set setup take NXsample/temperature_1_env and NXsample/magnetic_field_1_env
sstr = nxs_file->GetEntryIdf2()->GetSample()->GetEnvironmentTemp() + string("/");
sstr += nxs_file->GetEntryIdf2()->GetSample()->GetEnvironmentField();
str = sstr;
runData.SetSetup(str);
// get/set sample
runData.SetSample(nxs_file->GetEntryIdf2()->GetSample()->GetName());
// get/set orientation
runData.SetOrientation("??");
// get/set time resolution (ns)
runData.SetTimeResolution(nxs_file->GetEntryIdf2()->GetInstrument()->GetDetector()->GetTimeResolution("ns"));
// get/set start/stop time
sstr = nxs_file->GetEntryIdf2()->GetStartTime();
str = sstr;
TString date, time;
SplitTimeDate(str, time, date, ok);
if (ok) {
runData.SetStartTime(time);
runData.SetStartDate(date);
}
sstr = nxs_file->GetEntryIdf2()->GetStopTime();
str = sstr;
SplitTimeDate(str, time, date, ok);
if (ok) {
runData.SetStopTime(time);
runData.SetStopDate(date);
}
// get/set t0, firstGoodBin, lastGoodBin
int *t0 = nxs_file->GetEntryIdf2()->GetInstrument()->GetDetector()->GetT0s();
int *fgb = nxs_file->GetEntryIdf2()->GetInstrument()->GetDetector()->GetFirstGoodBins();
int *lgb = nxs_file->GetEntryIdf2()->GetInstrument()->GetDetector()->GetLastGoodBins();
PIntPair goodDataBin;
if (nxs_file->GetEntryIdf2()->GetInstrument()->GetDetector()->GetT0Tag() == 2) { // t0, fgb, lgb: [][]
for (int i=0; i<nxs_file->GetEntryIdf2()->GetInstrument()->GetDetector()->GetNoOfPeriods(); i++) {
for (int j=0; j<nxs_file->GetEntryIdf2()->GetInstrument()->GetDetector()->GetNoOfSpectra(); j++) {
if (fgb && lgb) {
goodDataBin.first = *(fgb+i*nxs_file->GetEntryIdf2()->GetInstrument()->GetDetector()->GetNoOfSpectra()+j);
goodDataBin.second = *(lgb+i*nxs_file->GetEntryIdf2()->GetInstrument()->GetDetector()->GetNoOfSpectra()+j);
}
runData.AppendT0(*(t0+i*nxs_file->GetEntryIdf2()->GetInstrument()->GetDetector()->GetNoOfSpectra()+j));
if (fgb && lgb) {
runData.AppendGoodDataBin(goodDataBin);
}
}
}
} else { // t0, fgb, lgb: single numbers
if (fgb && lgb) {
goodDataBin.first = *fgb;
goodDataBin.second = *lgb;
}
for (int i=0; i<nxs_file->GetEntryIdf2()->GetInstrument()->GetDetector()->GetNoOfPeriods(); i++) {
for (int j=0; j<nxs_file->GetEntryIdf2()->GetInstrument()->GetDetector()->GetNoOfSpectra(); j++) {
runData.AppendT0(*t0);
if (fgb && lgb)
runData.AppendGoodDataBin(goodDataBin);
}
}
}
// get/set data
PDoubleVector data;
int *histos = nxs_file->GetEntryIdf2()->GetInstrument()->GetDetector()->GetHistos();
if (nxs_file->GetEntryIdf2()->GetInstrument()->GetDetector()->GetNoOfPeriods() > 0) { // counts[][][]
for (int i=0; i<nxs_file->GetEntryIdf2()->GetInstrument()->GetDetector()->GetNoOfPeriods(); i++) {
for (int j=0; j<nxs_file->GetEntryIdf2()->GetInstrument()->GetDetector()->GetNoOfSpectra(); j++) {
for (int k=0; k<nxs_file->GetEntryIdf2()->GetInstrument()->GetDetector()->GetNoOfBins(); k++) {
data.push_back(*(histos+i*nxs_file->GetEntryIdf2()->GetInstrument()->GetDetector()->GetNoOfSpectra()+j*nxs_file->GetEntryIdf2()->GetInstrument()->GetDetector()->GetNoOfBins()+k));
}
runData.AppendDataBin(data);
data.clear();
}
}
} else {
if (nxs_file->GetEntryIdf2()->GetInstrument()->GetDetector()->GetNoOfSpectra() > 0) { // counts[][]
for (int i=0; i<nxs_file->GetEntryIdf2()->GetInstrument()->GetDetector()->GetNoOfSpectra(); i++) {
for (int j=0; j<nxs_file->GetEntryIdf2()->GetInstrument()->GetDetector()->GetNoOfBins(); j++) {
data.push_back(*(histos+i*nxs_file->GetEntryIdf2()->GetInstrument()->GetDetector()->GetNoOfBins()+j));
}
runData.AppendDataBin(data);
data.clear();
}
} else { // counts[]
for (int i=0; i<nxs_file->GetEntryIdf2()->GetInstrument()->GetDetector()->GetNoOfBins(); i++) {
data.push_back(*(histos+i));
}
runData.AppendDataBin(data);
data.clear();
}
}
// keep run name from the msr-file
runData.SetRunName(fRunName);
// keep the information
fData.push_back(runData);
} else {
cout << endl << ">> PRunDataHandler::ReadNexusFile(): IDF version " << nxs_file->GetIdfVersion() << ", not implemented." << endl;
}
data.clear();
// keep run name from the msr-file
runData.SetRunName(fRunName);
// keep the information
fData.push_back(runData);
// clean up
if (nxs_file) {
@ -3405,8 +3591,11 @@ Bool_t PRunDataHandler::WriteRootFile(TString fln)
* \param fln file name. If empty, the routine will try to construct one
*/
Bool_t PRunDataHandler::WriteNexusFile(TString fln)
{
{
#ifdef PNEXUS_ENABLED
int *t0=0, *fgb=0, *lgb=0, *histo=0;
// generate output file name
if (fln.Length() == 0) {
Bool_t ok = false;
@ -3429,65 +3618,151 @@ Bool_t PRunDataHandler::WriteNexusFile(TString fln)
return false;
}
// fill necessary data structures
nxs->SetFileName(fln.Data());
nxs->SetIDFVersion(1);
nxs->SetProgramName("any2many");
nxs->SetProgramVersion("$Id$");
nxs->SetRunNumber(fData[0].GetRunNumber());
nxs->SetRunTitle(fData[0].GetRunTitle()->Data());
nxs->SetRunNotes("n/a");
nxs->SetAnalysisTag("n/a");
nxs->SetLab("PSI");
nxs->SetBeamline("n/a");
nxs->SetStartDate(fData[0].GetStartDate()->Data());
nxs->SetStartTime(fData[0].GetStartTime()->Data());
nxs->SetStopDate(fData[0].GetStopDate()->Data());
nxs->SetStopTime(fData[0].GetStopTime()->Data());
nxs->SetSwitchingState(0);
nxs->SetUser("n/a");
nxs->SetExperimentNumber("n/a");
nxs->SetSampleName(fData[0].GetSample()->Data());
nxs->SetSampleTemperature(fData[0].GetTemperature(0));
nxs->SetSampleTemperatureUints("Kelvin");
nxs->SetMagneticField(fData[0].GetField());
nxs->SetMagneticFieldUnits("Gauss");
nxs->SetSampleEnvironment("n/a");
nxs->SetSampleShape("n/a");
nxs->SetMagneticFieldVectorAvailable(0);
nxs->SetExperimentName("n/a");
nxs->SetNoDetectors(fData[0].GetNoOfHistos());
nxs->SetCollimatorType("n/a");
nxs->SetTimeResolution(fData[0].GetTimeResolution());
if (fData[0].GetT0(0) == -1)
nxs->SetT0(0);
else
nxs->SetT0(fData[0].GetT0(0)); // this needs to be changed in the long term, since for continous sources each detector has its one t0!!
if (fData[0].GetGoodDataBin(0).first == -1) {
nxs->SetFirstGoodBin(0);
nxs->SetLastGoodBin(0);
} else {
nxs->SetFirstGoodBin(fData[0].GetGoodDataBin(0).first);
nxs->SetLastGoodBin(fData[0].GetGoodDataBin(0).second);
}
// feed real histogram data
PUIntVector data;
for (UInt_t i=0; i<fData[0].GetNoOfHistos(); i++) {
for (UInt_t j=0; j<fData[0].GetDataBin(i)->size(); j++) {
data.push_back((UInt_t)fData[0].GetDataBin(i)->at(j));
// set IDF version
nxs->SetIdfVersion(fAny2ManyInfo->idf);
if (fAny2ManyInfo->idf == 1) {
// fill necessary data structures
nxs->SetFileName(fln.Data());
// set file creating time
time_t now;
struct tm *tm;
time(&now);
tm = localtime(&now);
string str("");
char cstr[128];
sprintf(cstr, "%04d-%02d-%02d %02d:%02d:%02d", 1900+tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_hour, tm->tm_sec);
str = string(cstr);
nxs->SetFileTime(str);
nxs->GetEntryIdf1()->SetProgramName("any2many");
nxs->GetEntryIdf1()->SetProgramVersion("$Id$");
nxs->GetEntryIdf1()->SetRunNumber(fData[0].GetRunNumber());
nxs->GetEntryIdf1()->SetTitle(fData[0].GetRunTitle()->Data());
nxs->GetEntryIdf1()->SetNotes("n/a");
nxs->GetEntryIdf1()->SetAnalysis("n/a");
nxs->GetEntryIdf1()->SetLaboratory("PSI");
nxs->GetEntryIdf1()->SetBeamline("n/a");
str = string(fData[0].GetStartDate()->Data()) + string(" ") + string(fData[0].GetStartTime()->Data());
nxs->GetEntryIdf1()->SetStartTime(str);
str = string(fData[0].GetStopDate()->Data()) + string(" ") + string(fData[0].GetStopTime()->Data());
nxs->GetEntryIdf1()->SetStopTime(str);
nxs->GetEntryIdf1()->SetSwitchingState(0);
nxs->GetEntryIdf1()->GetUser()->SetName("n/a");
nxs->GetEntryIdf1()->GetUser()->SetExperimentNumber("n/a");
nxs->GetEntryIdf1()->GetSample()->SetName(fData[0].GetSample()->Data());
nxs->GetEntryIdf1()->GetSample()->SetPhysProp("temperature", fData[0].GetTemperature(0), "Kelvin");
nxs->GetEntryIdf1()->GetSample()->SetPhysProp("magnetic_field", fData[0].GetField(), "Gauss");
nxs->GetEntryIdf1()->GetSample()->SetEnvironment("n/a");
nxs->GetEntryIdf1()->GetSample()->SetShape("n/a");
nxs->GetEntryIdf1()->GetSample()->SetMagneticFieldVectorAvailable(0);
nxs->GetEntryIdf1()->GetInstrument()->SetName("n/a");
nxs->GetEntryIdf1()->GetInstrument()->GetDetector()->SetNumber(fData[0].GetNoOfHistos());
nxs->GetEntryIdf1()->GetInstrument()->GetCollimator()->SetType("n/a");
nxs->GetEntryIdf1()->GetData()->SetTimeResolution(fData[0].GetTimeResolution(), "ns");
if (fData[0].GetT0(0) == -1)
nxs->GetEntryIdf1()->GetData()->SetT0(0);
else
nxs->GetEntryIdf1()->GetData()->SetT0(fData[0].GetT0(0)); // this needs to be changed in the long term, since for continous sources each detector has its one t0!!
if (fData[0].GetGoodDataBin(0).first == -1) {
nxs->GetEntryIdf1()->GetData()->SetFirstGoodBin(0);
nxs->GetEntryIdf1()->GetData()->SetLastGoodBin(0);
} else {
nxs->GetEntryIdf1()->GetData()->SetFirstGoodBin(fData[0].GetGoodDataBin(0).first);
nxs->GetEntryIdf1()->GetData()->SetLastGoodBin(fData[0].GetGoodDataBin(0).second);
}
nxs->SetHisto(i, data);
data.clear();
// feed real histogram data
PUIntVector data;
for (UInt_t i=0; i<fData[0].GetNoOfHistos(); i++) {
for (UInt_t j=0; j<fData[0].GetDataBin(i)->size(); j++) {
data.push_back((UInt_t)fData[0].GetDataBin(i)->at(j));
}
nxs->GetEntryIdf1()->GetData()->SetHisto(data, i);
data.clear();
}
} else if (fAny2ManyInfo->idf == 2) {
// fill necessary data structures
nxs->SetFileName(fln.Data());
// set file creating time
time_t now;
struct tm *tm;
time(&now);
tm = localtime(&now);
string str("");
char cstr[128];
sprintf(cstr, "%04d-%02d-%02d %02d:%02d:%02d", 1900+tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_hour, tm->tm_sec);
str = string(cstr);
nxs->SetFileTime(str);
nxs->SetCreator("PSI - any2many");
nxs->GetEntryIdf2()->SetDefinition("pulsedTD");
nxs->GetEntryIdf2()->SetRunNumber(fData[0].GetRunNumber());
nxs->GetEntryIdf2()->SetTitle(fData[0].GetRunTitle()->Data());
str = string(fData[0].GetStartDate()->Data()) + string(" ") + string(fData[0].GetStartTime()->Data());
nxs->GetEntryIdf2()->SetStartTime(str);
str = string(fData[0].GetStopDate()->Data()) + string(" ") + string(fData[0].GetStopTime()->Data());
nxs->GetEntryIdf2()->SetStopTime(str);
nxs->GetEntryIdf2()->SetExperimentIdentifier("n/a");
nxs->GetEntryIdf2()->GetUser()->SetName("n/a");
nxs->GetEntryIdf2()->GetSample()->SetName(fData[0].GetSample()->Data());
nxs->GetEntryIdf2()->GetSample()->SetDescription("n/a");
nxs->GetEntryIdf2()->GetSample()->SetPhysProp("temperature_1", fData[0].GetTemperature(0), "Kelvin");
nxs->GetEntryIdf2()->GetSample()->SetPhysProp("magnetic_field_1", fData[0].GetField(), "Gauss");
nxs->GetEntryIdf2()->GetSample()->SetEnvironmentTemp("n/a");
nxs->GetEntryIdf2()->GetSample()->SetEnvironmentField("n/a");
// here would be the information for NXinstrument. Currently there are not enough information to feed this
nxs->GetEntryIdf2()->GetInstrument()->GetDetector()->SetDescription("n/a");
nxs->GetEntryIdf2()->GetInstrument()->GetDetector()->SetNoOfPeriods(1); // currently red/green is not distinguished
nxs->GetEntryIdf2()->GetInstrument()->GetDetector()->SetNoOfSpectra(fData[0].GetNoOfHistos());
nxs->GetEntryIdf2()->GetInstrument()->GetDetector()->SetNoOfBins(fData[0].GetDataBin(0)->size());
nxs->GetEntryIdf2()->GetInstrument()->GetDetector()->SetTimeResolution(fData[0].GetTimeResolution(), "ns");
histo = new int[fData[0].GetNoOfHistos()*fData[0].GetDataBin(0)->size()];
for (int i=0; i<nxs->GetEntryIdf2()->GetInstrument()->GetDetector()->GetNoOfSpectra(); i++) {
for (unsigned int j=0; j<fData[0].GetDataBin(0)->size(); j++) {
*(histo+i*fData[0].GetDataBin(0)->size()+j) = (int) fData[0].GetDataBin(i)->at(j);
}
}
nxs->GetEntryIdf2()->GetInstrument()->GetDetector()->SetHisto(histo);
for (int i=0; i<nxs->GetEntryIdf2()->GetInstrument()->GetDetector()->GetNoOfSpectra(); i++)
nxs->GetEntryIdf2()->GetInstrument()->GetDetector()->SetSpectrumIndex(i+1);
nxs->GetEntryIdf2()->GetInstrument()->GetDetector()->SetT0Tag(2);
int *t0 = new int[fData[0].GetT0Size()];
for (unsigned int i=0; i<fData[0].GetNoOfHistos(); i++) {
if (i<fData[0].GetT0Size())
*(t0+i) = fData[0].GetT0(i);
else
*(t0+i) = fData[0].GetT0(0);
}
nxs->GetEntryIdf2()->GetInstrument()->GetDetector()->SetT0(t0);
// first_good_bin - still missing
// last_good_bin - still missing
} else {
// clean up
if (nxs != 0) {
delete nxs;
nxs = 0;
}
return false;
}
// filter out the proper file type, i.e. HDF4, HDF5, or XML
char fileType[32];
memset(fileType, '\0', 32);
if (!fAny2ManyInfo->outFormat.CompareTo("nexus-hdf4", TString::kIgnoreCase))
if (!fAny2ManyInfo->outFormat.CompareTo("nexus1-hdf4", TString::kIgnoreCase) || !fAny2ManyInfo->outFormat.CompareTo("nexus2-hdf4", TString::kIgnoreCase))
strncpy(fileType, "hdf4", sizeof(fileType));
else if (!fAny2ManyInfo->outFormat.CompareTo("nexus-hdf5", TString::kIgnoreCase))
else if (!fAny2ManyInfo->outFormat.CompareTo("nexus1-hdf5", TString::kIgnoreCase) || !fAny2ManyInfo->outFormat.CompareTo("nexus2-hdf5", TString::kIgnoreCase))
strncpy(fileType, "hdf5", sizeof(fileType));
else if (!fAny2ManyInfo->outFormat.CompareTo("nexus-xml", TString::kIgnoreCase))
else if (!fAny2ManyInfo->outFormat.CompareTo("nexus1-xml", TString::kIgnoreCase) || !fAny2ManyInfo->outFormat.CompareTo("nexus2-xml", TString::kIgnoreCase))
strncpy(fileType, "xml", sizeof(fileType));
else {
cerr << endl << ">> PRunDataHandler::WriteNexusFile(): **ERROR** undefined output NeXus format " << fAny2ManyInfo->outFormat.Data() << " found.";
@ -3500,9 +3775,25 @@ Bool_t PRunDataHandler::WriteNexusFile(TString fln)
}
// write file
nxs->WriteFile(fln, fileType);
nxs->WriteFile(fln, fileType, fAny2ManyInfo->idf);
// clean up
if (t0) {
delete [] t0;
t0 = 0;
}
if (fgb) {
delete [] fgb;
fgb = 0;
}
if (lgb) {
delete [] lgb;
lgb = 0;
}
if (histo) {
delete [] histo;
histo = 0;
}
if (nxs != 0) {
delete nxs;
nxs = 0;
@ -3510,6 +3801,7 @@ Bool_t PRunDataHandler::WriteNexusFile(TString fln)
#else
cout << endl << ">> PRunDataHandler::WriteNexusFile(): Sorry, not enabled at configuration level, i.e. --enable-NeXus when executing configure" << endl << endl;
#endif
return true;
}
@ -4567,3 +4859,32 @@ TString PRunDataHandler::GetMonth(Int_t month)
return mm;
}
//--------------------------------------------------------------------------
// SplitTimeData (private)
//--------------------------------------------------------------------------
/**
* <p>splits an ISO 8601 timeDate into seperate time and data. The flag ok
* shows if it was successfull.
*
* \param timeData ISO 8601 timeData
* \param time part of timeData
* \param date part of timeData
* \param ok flag showing if the splitting was successfull
*/
void PRunDataHandler::SplitTimeDate(TString timeData, TString &time, TString &date, Bool_t &ok)
{
struct tm tm;
memset(&tm, 0, sizeof(tm));
strptime(timeData.Data(), "%Y-%m-%d %H:%M:S", &tm);
if (tm.tm_year == 0)
strptime(timeData.Data(), "%Y-%m-%dT%H:%M:S", &tm);
if (tm.tm_year == 0) {
ok = false;
return;
}
time = TString::Format("%02d:%02d:%02d", tm.tm_hour, tm.tm_min, tm.tm_sec);
date = TString::Format("%04d-%02d-%02d", tm.tm_year+1900, tm.tm_mon, tm.tm_mday);
}

View File

@ -5,7 +5,7 @@ h_sources = \
PNeXus.h
cpp_sources = \
PNeXus.cpp
PNeXus.cpp
include_HEADERS = $(h_sources)

File diff suppressed because it is too large Load Diff

View File

@ -32,7 +32,6 @@
#ifndef _PNEXUS_H_
#define _PNEXUS_H_
#include <iostream>
#include <string>
#include <vector>
using namespace std;
@ -43,271 +42,581 @@ using namespace std;
#define VGNAMELENMAX 64
#endif /* VGNAMELENMAX */
#define PNEXUS_FILE_OPEN_ERROR 0
#define PNEXUS_GROUP_OPEN_ERROR 1
#define PNEXUS_OPEN_DATA_ERROR 2
#define PNEXUS_GET_DATA_ERROR 3
#define PNEXUS_GET_ATTR_ERROR 4
#define PNEXUS_CLOSE_DATA_ERROR 5
#define PNEXUS_GET_META_INFO_ERROR 6
#define PNEXUS_WRONG_META_INFO 7
#define PNEXUS_WRONG_DATE_FORMAT 8
#define PNEXUS_WRONG_TIME_FORMAT 9
#define PNEXUS_INIT_GROUPDIR_ERROR 10
#define PNEXUS_GET_GROUP_INFO_ERROR 11
#define PNEXUS_GET_NEXT_ENTRY_ERROR 12
#define PNEXUS_HISTO_ERROR 13
#define PNEXUS_SET_ATTR_ERROR 14
#define PNEXUS_CREATE_GROUP_ERROR 15
#define PNEXUS_MAKE_DATA_ERROR 16
#define PNEXUS_PUT_DATA_ERROR 17
#define PNEXUS_PUT_ATTR_ERROR 18
#define PNEXUS_NO_ERROR 0
#define PNEXUS_NXENTRY_NOT_FOUND 1
#define PNEXUS_FILE_OPEN_ERROR 2
#define PNEXUS_GROUP_OPEN_ERROR 3
#define PNEXUS_OPEN_DATA_ERROR 4
#define PNEXUS_GET_DATA_ERROR 5
#define PNEXUS_GET_ATTR_ERROR 6
#define PNEXUS_CLOSE_DATA_ERROR 7
#define PNEXUS_GET_META_INFO_ERROR 8
#define PNEXUS_WRONG_META_INFO 9
#define PNEXUS_WRONG_DATE_FORMAT 10
#define PNEXUS_WRONG_TIME_FORMAT 11
#define PNEXUS_INIT_GROUPDIR_ERROR 12
#define PNEXUS_GET_GROUP_INFO_ERROR 13
#define PNEXUS_GET_NEXT_ENTRY_ERROR 14
#define PNEXUS_HISTO_ERROR 15
#define PNEXUS_SET_ATTR_ERROR 16
#define PNEXUS_CREATE_GROUP_ERROR 17
#define PNEXUS_MAKE_DATA_ERROR 18
#define PNEXUS_PUT_DATA_ERROR 19
#define PNEXUS_PUT_ATTR_ERROR 20
#define PNEXUS_IDF_NOT_IMPLEMENTED 21
#define PNEXUS_VAILD_READ_IDF1_FILE 22
#define PNEXUS_VAILD_READ_IDF2_FILE 23
#define PNEXUS_OBJECT_INVOK_ERROR 24
#define PNEXUS_TIME_FORMAT_ERROR 25
#define PNEXUS_DATA_ERROR 26
#define PNEXUS_NXUSER_NOT_FOUND 27
#define PNEXUS_LINKING_ERROR 28
//-----------------------------------------------------------------------------
/**
*
*/
typedef struct {
string fUserName;
string fExperimentNumber;
} PNeXusUser;
class PNeXusProp {
public:
PNeXusProp();
virtual ~PNeXusProp() {}
//-----------------------------------------------------------------------------
/**
*
*/
typedef struct {
string fName;
double fTemperature;
string fTemperatureUnit;
double fMagneticField;
string fMagneticFieldUnit;
string fShape;
string fMagneticFieldState; ///< ZF, TF, LF
int fMagneticFieldVectorAvailable;
vector<double> fMagneticFieldVector;
string fMagneticFieldVectorUnits;
string fMagneticFieldVectorCoordinateSystem;
string fEnvironment;
} PNeXusSample;
virtual string GetName() { return fName; }
virtual double GetValue() { return fValue; }
virtual string GetUnit() { return fUnit; }
//-----------------------------------------------------------------------------
/**
* <p> currently only put in the requiered ones.
*/
typedef struct {
int number;
} PNeXusDetector;
virtual void SetName(string name) { fName = name; }
virtual void SetValue(double val) { fValue = val; }
virtual void SetUnit(string unit) { fUnit = unit; }
//-----------------------------------------------------------------------------
/**
* <p> currently only put in the requiered ones.
*/
typedef struct {
string type;
} PNeXusCollimator;
private:
string fName;
double fValue;
string fUnit;
};
//-----------------------------------------------------------------------------
/**
* <p> currently only put in the requiered ones.
*/
typedef struct {
double total_counts;
string total_counts_units;
} PNeXusBeam;
class PNeXusBeam1 {
public:
PNeXusBeam1() { fTotalCounts = 0; fUnits = "n/a"; }
virtual ~PNeXusBeam1() {}
//-----------------------------------------------------------------------------
/**
*
*/
typedef struct {
string name;
PNeXusDetector detector;
PNeXusCollimator collimator;
PNeXusBeam beam;
} PNeXusInstrument;
virtual bool IsValid(bool strict);
//-----------------------------------------------------------------------------
/**
*
*/
typedef struct {
unsigned int fGroupFirst;
unsigned int fGroupSecond;
double fAlphaVal;
} PNeXusAlpha;
virtual double GetTotalCounts() { return fTotalCounts; }
virtual string GetUnits() { return fUnits; }
//-----------------------------------------------------------------------------
/**
*
*/
typedef struct {
double fTimeResolution; ///< time resolution in (ns)
unsigned int fNumberOfHistos;
vector<unsigned int> fT0;
vector<unsigned int> fFirstGoodBin;
vector<unsigned int> fLastGoodBin;
vector<string> fHistoName;
vector< vector<unsigned int> > fHisto;
vector<unsigned int> fGrouping;
vector<PNeXusAlpha> fAlpha;
} PNeXusData;
virtual void SetTotalCounts(double counts) { fTotalCounts = counts; }
virtual void SetUnits(string units) { fUnits = units; }
private:
double fTotalCounts; ///< total number of counts
string fUnits; ///< 'units' in which total counts is given, e.g. 'Mev'
};
class PNeXusCollimator1 {
public:
PNeXusCollimator1() { fType = "n/a"; }
virtual ~PNeXusCollimator1() {}
virtual bool IsValid(bool strict) { return true; } // currently only a dummy
virtual string GetType() { return fType; }
virtual void SetType(string type) { fType = type; }
private:
string fType;
};
class PNeXusDetector1 {
public:
PNeXusDetector1() { fNumber = 0; }
virtual ~PNeXusDetector1() {}
virtual bool IsValid(bool strict);
virtual int GetNumber() { return fNumber; }
virtual void SetNumber(int number) { fNumber = number; }
private:
int fNumber;
};
class PNeXusInstrument1 {
public:
PNeXusInstrument1() { fName = "n/a"; }
virtual ~PNeXusInstrument1() {}
virtual bool IsValid(bool strict);
virtual string GetName() { return fName; }
virtual PNeXusDetector1* GetDetector() { return &fDetector; }
virtual PNeXusCollimator1* GetCollimator() { return &fCollimator; }
virtual PNeXusBeam1* GetBeam() { return &fBeam; }
virtual void SetName(string name) { fName = name; }
virtual void SetDetector(PNeXusDetector1 &detector) { fDetector = detector; }
virtual void SetCollimator(PNeXusCollimator1 &collimator) { fCollimator = collimator; }
virtual void SetBeam(PNeXusBeam1 &beam) { fBeam = beam; }
private:
string fName; ///< instrument name
PNeXusDetector1 fDetector;
PNeXusCollimator1 fCollimator;
PNeXusBeam1 fBeam;
};
class PNeXusSample1 {
public:
PNeXusSample1();
virtual ~PNeXusSample1();
virtual bool IsValid(bool strict);
virtual string GetName() { return fName; }
virtual string GetShape() { return fShape; }
virtual string GetMagneticFieldState() { return fMagneticFieldState; }
virtual string GetEnvironment() { return fEnvironment; }
virtual double GetPhysPropValue(string name, bool &ok);
virtual void GetPhysPropUnit(string name, string &unit, bool &ok);
virtual int IsMagneticFieldVectorAvailable() { return fMagneticFieldVectorAvailable; }
virtual vector<double> GetMagneticFieldVector() { return fMagneticFieldVector; }
virtual string GetMagneticFieldVectorUnits() { return fMagneticFieldVectorUnits; }
virtual string GetMagneticFieldVectorCoordinateSystem() { return fMagneticFieldVectorCoordinateSystem; }
virtual void SetName(string name) { fName = name; }
virtual void SetShape(string shape) { fShape = shape; }
virtual void SetMagneticFieldState(string magFieldState) { fMagneticFieldState = magFieldState; }
virtual void SetEnvironment(string env) { fEnvironment = env; }
virtual void SetPhysProp(string name, double value, string unit, int idx=-1);
virtual void SetMagneticFieldVectorAvailable(int avail) { fMagneticFieldVectorAvailable = avail; }
virtual void SetMagneticFieldVector(vector<double> &magVec) { fMagneticFieldVector = magVec; }
virtual void SetMagneticFieldVectorCoordinateSystem(string coord) { fMagneticFieldVectorCoordinateSystem = coord; }
virtual void SetMagneticFieldUnits(string units) { fMagneticFieldVectorUnits = units; }
private:
string fName; ///< sample name
string fShape; ///< sample orientation
string fMagneticFieldState; ///< magnetic field state, e.g. TF, ZF, ...
string fEnvironment; ///< sample environment, e.g. CCR, Konti-1, ...
vector<PNeXusProp> fPhysProp; ///< collects the temperature, magnetic field
int fMagneticFieldVectorAvailable; ///< flag '0' magnetic field vector not available, '1' magnetic field vector available
vector<double> fMagneticFieldVector; ///< magnetic field vector
string fMagneticFieldVectorUnits; ///< units in which the magnetic field vector is given
string fMagneticFieldVectorCoordinateSystem; ///< coordinate system, e.g. 'cartesian'
};
class PNeXusUser1 {
public:
PNeXusUser1();
virtual ~PNeXusUser1() {}
virtual bool IsValid(bool strict) { return true; } // currently only a dummy
virtual string GetName() { return fName; }
virtual string GetExperimentNumber() { return fExperimentNumber; }
virtual void SetName(string name) { fName = name; }
virtual void SetExperimentNumber(string expNum) { fExperimentNumber = expNum; }
private:
string fName; ///< user name
string fExperimentNumber; ///< experiment number, RB number at ISIS
};
class PNeXusAlpha1 {
public:
PNeXusAlpha1();
virtual ~PNeXusAlpha1() {}
virtual unsigned int GetGroupFirst() { return fGroupFirst; }
virtual unsigned int GetGroupSecond() { return fGroupSecond; }
virtual double GetAlpha() { return fAlphaVal; }
virtual void SetGroupFirst(unsigned int val) { fGroupFirst = val; }
virtual void SetGroupSecond(unsigned int val) { fGroupSecond = val; }
virtual void SetAlpha(double val) { fAlphaVal = val; }
private:
unsigned int fGroupFirst;
unsigned int fGroupSecond;
double fAlphaVal;
};
class PNeXusData1 {
public:
PNeXusData1() { fTimeResolution = 0.0; }
virtual ~PNeXusData1();
virtual bool IsValid(bool strict);
virtual double GetTimeResolution(string units);
virtual vector<unsigned int> *GetT0s() { return &fT0; }
virtual int GetT0(unsigned int idx);
virtual vector<unsigned int> *GetFirstGoodBins() { return &fFirstGoodBin; }
virtual int GetFirstGoodBin(unsigned int idx);
virtual vector<unsigned int> *GetLastGoodBins() { return &fLastGoodBin; }
virtual int GetLastGoodBin(unsigned int idx);
virtual vector<string> *GetHistoNames() { return &fHistoName; }
virtual void GetHistoName(unsigned int idx, string &name, bool &ok);
virtual unsigned int GetNoOfHistos() { return fHisto.size(); }
virtual vector<unsigned int> *GetHisto(unsigned int histoNo);
virtual vector<int> *GetGrouping() { return &fGrouping; }
virtual vector<PNeXusAlpha1> *GetAlpha() { return &fAlpha; }
virtual void SetTimeResolution(double val, string units);
virtual void SetT0(unsigned int t0, int idx=-1);
virtual void SetFirstGoodBin(unsigned int fgb, int idx=-1);
virtual void SetLastGoodBin(unsigned int lgb, int idx=-1);
virtual void FlushHistos();
virtual void SetHisto(vector<unsigned int> &data, int histoNo=-1);
virtual void FlushGrouping() { fGrouping.clear(); }
virtual void SetGrouping(vector<int> &grouping) { fGrouping = grouping; }
virtual void FlushAlpha() { fAlpha.clear(); }
virtual void SetAlpha(vector<PNeXusAlpha1> &alpha) { fAlpha = alpha; }
private:
double fTimeResolution; ///< time resolution in (ps)
vector<unsigned int> fT0;
vector<unsigned int> fFirstGoodBin;
vector<unsigned int> fLastGoodBin;
vector<string> fHistoName;
vector< vector<unsigned int> > fHisto;
vector<int> fGrouping;
vector<PNeXusAlpha1> fAlpha;
};
class PNeXusEntry1 {
public:
PNeXusEntry1();
virtual ~PNeXusEntry1() {}
virtual bool IsValid(bool strict);
virtual string GetProgramName() { return fProgramName; }
virtual string GetProgramVersion() { return fProgramVersion; }
virtual int GetRunNumber() { return fRunNumber; }
virtual string GetTitle() { return fTitle; }
virtual string GetNotes() { return fNotes; }
virtual string GetAnalysis() { return fAnalysis; }
virtual string GetLaboratory() { return fLaboratory; }
virtual string GetBeamline() { return fBeamline; }
virtual string GetStartTime() { return fStartTime; }
virtual string GetStopTime() { return fStopTime; }
virtual int GetSwitchingState() { return fSwitchingState; }
virtual PNeXusUser1* GetUser() { return &fUser; }
virtual PNeXusSample1* GetSample() { return &fSample; }
virtual PNeXusInstrument1* GetInstrument() { return &fInstrument; }
virtual PNeXusData1* GetData() { return &fData; }
virtual void SetProgramName(string name) { fProgramName = name; }
virtual void SetProgramVersion(string version) { fProgramVersion = version; }
virtual void SetRunNumber(int number) { fRunNumber = number; }
virtual void SetTitle(string title) { fTitle = title; }
virtual void SetNotes(string notes) { fNotes = notes; }
virtual void SetAnalysis(string analysis) { fAnalysis = analysis; }
virtual void SetLaboratory(string lab) { fLaboratory = lab; }
virtual void SetBeamline(string beamline) { fBeamline = beamline; }
virtual int SetStartTime(string time);
virtual int SetStopTime(string time);
virtual int SetSwitchingState(int state);
virtual void SetUser(PNeXusUser1 &user) { fUser = user; }
virtual void SetSample(PNeXusSample1 &sample) { fSample = sample; }
virtual void SetInstrument(PNeXusInstrument1 &instrument) { fInstrument = instrument; }
virtual void SetData(PNeXusData1 &data) { fData = data; }
private:
string fProgramName; ///< name of the creating program
string fProgramVersion; ///< version of the creating program
int fRunNumber; ///< run number
string fTitle; ///< string containing the run title
string fNotes; ///< comments
string fAnalysis; ///< type of muon experiment "muonTD", "ALC", ...
string fLaboratory; ///< name of the laboratory where the data are taken, e.g. PSI, triumf, ISIS, J-Parc
string fBeamline; ///< name of the beamline used for the experiment, e.g. muE4
string fStartTime; ///< start date/time of the run
string fStopTime; ///< stop date/time of the run
int fSwitchingState; ///< '1' normal data collection, '2' Red/Green mode
PNeXusUser1 fUser; ///< NXuser info IDF Version 1
PNeXusSample1 fSample; ///< NXsample info IDF Version 1
PNeXusInstrument1 fInstrument; ///< NXinstrument info IDF Version 1
PNeXusData1 fData; ///< NXdata info IDF Version 1
};
class PNeXusSource2 {
public:
PNeXusSource2();
virtual ~PNeXusSource2() {}
virtual bool IsValid(bool strict);
virtual string GetName() { return fName; }
virtual string GetType() { return fType; }
virtual string GetProbe() { return fProbe; }
virtual void SetName(string name) { fName = name; }
virtual void SetType(string type) { fType = type; }
virtual void SetProbe(string probe) { fProbe = probe; }
private:
string fName; ///< facility name
string fType; ///< continous muon source, pulsed muon source, low energy muon source, ...
string fProbe; ///< positive muon, negative muon
};
class PNeXusBeamline2 {
public:
PNeXusBeamline2() { fName = "n/a"; }
virtual ~PNeXusBeamline2() {}
virtual bool IsValid(bool strict);
virtual string GetName() { return fName; }
virtual void SetName(string name) { fName = name; }
private:
string fName;
};
class PNeXusDetector2 {
public:
PNeXusDetector2();
virtual ~PNeXusDetector2();
virtual bool IsValid(bool strict);
virtual string GetDescription() { return fDescription; }
virtual double GetTimeResolution(string units);
virtual bool IsT0Present() { return (fT0 == 0) ? false : true; }
virtual int GetT0Tag() { return fT0Tag; }
virtual int GetT0(int idxp=-1, int idxs=-1);
virtual int* GetT0s() { return fT0; }
virtual bool IsFirstGoodBinPresent() { return (fFirstGoodBin == 0) ? false : true; }
virtual int GetFirstGoodBin(int idxp=-1, int idxs=-1);
virtual int* GetFirstGoodBins() { return fFirstGoodBin; }
virtual bool IsLastGoodBinPresent() { return (fFirstGoodBin == 0) ? false : true; }
virtual int GetLastGoodBin(int idxp=-1, int idxs=-1);
virtual int* GetLastGoodBins() { return fLastGoodBin; }
virtual int GetNoOfPeriods() { return fNoOfPeriods; }
virtual int GetNoOfSpectra() { return fNoOfSpectra; }
virtual int GetNoOfBins() { return fNoOfBins; }
virtual int GetHistoValue(int idx_p, int idx_s, int idx_b);
virtual int* GetHistos() { return fHisto; }
virtual unsigned int GetSpectrumIndexSize() { return fSpectrumIndex.size(); }
virtual vector<int> *GetSpectrumIndex() { return &fSpectrumIndex; }
virtual int GetSpectrumIndex(unsigned int idx);
virtual void SetDescription(string description) { fDescription = description; }
virtual void SetTimeResolution(double val, string units);
virtual void SetT0Tag(int tag) { fT0Tag = tag; }
virtual void SetT0(int *t0) { fT0 = t0; }
virtual void SetFirstGoodBin(int *fgb) { fFirstGoodBin = fgb; }
virtual void SetLastGoodBin(int *lgb) { fLastGoodBin = lgb; }
virtual void SetNoOfPeriods(int val) { fNoOfPeriods = val; }
virtual void SetNoOfSpectra(int val) { fNoOfSpectra = val; }
virtual void SetNoOfBins(int val) { fNoOfBins = val; }
virtual void SetHisto(int *histo) { fHisto = histo; }
virtual void SetSpectrumIndex(vector<int> spectIdx) { fSpectrumIndex = spectIdx; }
virtual void SetSpectrumIndex(int spectIdx, int idx=-1);
private:
string fDescription; ///< description of the detector
double fTimeResolution; ///< keeps the time resolution in (ps)
vector<int> fSpectrumIndex; ///< list of global spectra
int fNoOfPeriods; ///< number of periods or -1 if not defined
int fNoOfSpectra; ///< number of spectra or -1 if not defined
int fNoOfBins; ///< number of bins of a spectrum or -1 if not defined
int fT0Tag; ///< tag for t0, fgb, lgb structure. -1==not present, 1==NX_INT, 2=NX_INT[np][ns]
int *fT0;
int *fFirstGoodBin;
int *fLastGoodBin;
int *fHisto;
};
class PNeXusInstrument2 {
public:
PNeXusInstrument2() { fName = "n/a"; }
virtual ~PNeXusInstrument2() {}
virtual bool IsValid(bool strict);
virtual string GetName() { return fName; }
virtual PNeXusSource2* GetSource() { return &fSource; }
virtual PNeXusBeamline2* GetBeamline() { return &fBeamline; }
virtual PNeXusDetector2* GetDetector() { return &fDetector; }
virtual void SetName(string name) { fName = name; }
virtual void SetSource(PNeXusSource2 &source) { fSource = source; }
virtual void SetBeamline(PNeXusBeamline2 &beamline) { fBeamline = beamline; }
virtual void SetDetector(PNeXusDetector2 &detector) { fDetector = detector; }
private:
string fName; ///< name of the instrument
PNeXusSource2 fSource; ///< details of the muon source used
PNeXusBeamline2 fBeamline; ///< beamline description
PNeXusDetector2 fDetector; ///< details of the detectors which also includes the data!!
};
class PNeXusSample2 {
public:
PNeXusSample2();
virtual ~PNeXusSample2();
virtual bool IsValid(bool strict);
virtual string GetName() { return fName; }
virtual string GetDescription() { return fDescription; }
virtual string GetMagneticFieldState() { return fMagneticFieldState; }
virtual string GetEnvironmentTemp() { return fEnvironmentTemp; }
virtual string GetEnvironmentField() { return fEnvironmentField; }
virtual double GetPhysPropValue(string name, bool &ok);
virtual void GetPhysPropUnit(string name, string &unit, bool &ok);
virtual void SetName(string name) { fName = name; }
virtual void SetDescription(string description) { fDescription = description; }
virtual void SetMagneticFieldState(string magFieldState) { fMagneticFieldState = magFieldState; }
virtual void SetEnvironmentTemp(string env) { fEnvironmentTemp = env; }
virtual void SetEnvironmentField(string env) { fEnvironmentField = env; }
virtual void SetPhysProp(string name, double value, string unit, int idx=-1);
private:
string fName; ///< sample name
string fDescription; ///< sample description
string fMagneticFieldState; ///< magnetic field state, e.g. TF, ZF, ...
string fEnvironmentTemp; ///< sample environment related to temperature, e.g. CCR, Konti-1, ...
string fEnvironmentField; ///< sample environment related to field, e.g. WEW-Bruker
vector<PNeXusProp> fPhysProp; ///< collects the temperature, magnetic field
};
class PNeXusUser2 {
public:
PNeXusUser2() { fName = "n/a"; }
virtual ~PNeXusUser2() {}
virtual bool IsValid(bool strict) { return true; } // currently only a dummy
virtual string GetName() { return fName; }
virtual void SetName(string name) { fName = name; }
private:
string fName; ///< user name
};
class PNeXusEntry2 {
public:
PNeXusEntry2();
virtual ~PNeXusEntry2() {}
virtual bool IsValid(bool strict);
virtual string GetDefinition() { return fDefinition; }
virtual string GetProgramName() { return fProgramName; }
virtual string GetProgramVersion() { return fProgramVersion; }
virtual int GetRunNumber() { return fRunNumber; }
virtual string GetTitle() { return fTitle; }
virtual string GetStartTime() { return fStartTime; }
virtual string GetStopTime() { return fStopTime; }
virtual string GetExperimentIdentifier() { return fExperimentIdentifier; }
virtual PNeXusUser2* GetUser() { return &fUser; }
virtual PNeXusSample2* GetSample() { return &fSample; }
virtual PNeXusInstrument2* GetInstrument() { return &fInstrument; }
virtual void SetDefinition(string def) { fDefinition = def; }
virtual void SetProgramName(string name) { fProgramName = name; }
virtual void SetProgramVersion(string version) { fProgramVersion = version; }
virtual void SetRunNumber(int number) { fRunNumber = number; }
virtual void SetTitle(string title) { fTitle = title; }
virtual int SetStartTime(string time);
virtual int SetStopTime(string time);
virtual void SetExperimentIdentifier(string expId) { fExperimentIdentifier = expId; }
virtual void SetUser(PNeXusUser2 &user) { fUser = user; }
virtual void SetSample(PNeXusSample2 &sample) { fSample = sample; }
virtual void SetInstrument(PNeXusInstrument2 &instrument) { fInstrument = instrument; }
private:
string fDefinition; ///< the template (DTD name) on which the entry was based, e.g. 'pulsedTD'
string fProgramName; ///< name of the creating program
string fProgramVersion; ///< version of the creating program
int fRunNumber; ///< run number
string fTitle; ///< string containing the run title
string fStartTime; ///< start date/time of the run
string fStopTime; ///< stop date/time of the run
string fExperimentIdentifier; ///< experiment number, (for ISIS, the RB number)
PNeXusUser2 fUser; ///< NXuser info IDF Version 2
PNeXusSample2 fSample; ///< NXsample info IDF Version 2
PNeXusInstrument2 fInstrument; ///< NXinstrument inf IDF Version 2
};
//-----------------------------------------------------------------------------
/**
*
*/
class PNeXus {
public:
PNeXus();
PNeXus(const char* fileName);
virtual ~PNeXus();
virtual bool IsValid() { return fIsValid; }
virtual int GetIdfVersion() { return fIdfVersion; }
virtual string GetFileName() { return fFileName; }
virtual string GetFileTime() { return fFileTime; }
virtual void SetIdfVersion(unsigned int idf);
virtual void SetFileName(string name) { fFileName = name; }
virtual void SetFileTime(string time) { fFileTime = time; }
virtual PNeXusEntry1* GetEntryIdf1() { return fNxEntry1; }
virtual PNeXusEntry2* GetEntryIdf2() { return fNxEntry2; }
virtual bool IsValid(bool strict=false);
virtual int GetErrorCode() { return fErrorCode; }
virtual string GetErrorMsg() { return fErrorMsg; }
virtual vector<unsigned int>* GetGroupedHisto(unsigned int idx);
virtual int ReadFile(const char *fileName);
virtual int WriteFile(const char *fileName, const char *fileType="hdf4");
virtual int WriteFile(const char *fileName, const char *fileType="hdf4", const unsigned int idf=2);
virtual void SetCreator(string str) { fCreator = str; }
virtual void Dump();
virtual int GetErrorCode() { return fErrorCode; }
virtual string GetErrorMsg() { return fErrorMsg; }
virtual string GetFileName() { return fFileName; }
virtual int GetIDFVersion() { return fIDFVersion; }
virtual string GetProgramName() { return fProgramName; }
virtual string GetProgramVersion() { return fProgramVersion; }
virtual int GetRunNumber() { return fRunNumber; }
virtual string GetRunTitle() { return fRunTitle; }
virtual string GetRunNotes() { return fNotes; }
virtual string GetAnalysisTag() { return fAnalysisTag; }
virtual string GetLab() { return fLab; }
virtual string GetBeamline() { return fBeamLine; }
virtual string GetStartDate() { return fStartDate; }
virtual string GetStartTime() { return fStartTime; }
virtual string GetStopDate() { return fStopDate; }
virtual string GetStopTime() { return fStopTime; }
virtual int GetSwitchingState() { return fSwitchingState; }
virtual string GetUser() { return fUser.fUserName; }
virtual string GetExperimentNumber() { return fUser.fExperimentNumber; }
virtual string GetSampleName() { return fSample.fName; }
virtual double GetSampleTemperature() { return fSample.fTemperature; }
virtual string GetSampleTemperartureUnits() { return fSample.fTemperatureUnit; }
virtual double GetMagneticField() { return fSample.fMagneticField; }
virtual string GetMagneticFieldUnits() { return fSample.fMagneticFieldUnit; }
virtual string GetMagneticFieldState() { return fSample.fMagneticFieldState; }
virtual int IsMagneticFieldVectorAvailable() { return fSample.fMagneticFieldVectorAvailable; }
virtual vector<double>& GetMagneticFieldVector() { return fSample.fMagneticFieldVector; }
virtual string GetMagneticFieldVectorCoordSystem() { return fSample.fMagneticFieldVectorCoordinateSystem; }
virtual string GetMagneticFieldVectorUnits() { return fSample.fMagneticFieldVectorUnits; }
virtual string GetSampleEnvironment() { return fSample.fEnvironment; }
virtual string GetSampleShape() { return fSample.fShape; }
virtual string GetExperimentName() { return fInstrument.name; }
virtual int GetNoDetectors() { return fInstrument.detector.number; }
virtual string GetCollimatorType() { return fInstrument.collimator.type; }
virtual double GetTotalNoEvents() { return fInstrument.beam.total_counts; }
virtual string GetTotalNoEventsUnits() { return fInstrument.beam.total_counts_units; }
virtual double GetTimeResolution() { return fData.fTimeResolution; }
virtual int GetNoHistos() { return fData.fNumberOfHistos; }
virtual int IsAlphaAvailable() { return fData.fAlpha.size(); }
virtual vector<PNeXusAlpha> *GetAlpha() { if (fData.fAlpha.size()) return &fData.fAlpha; else return 0; }
virtual unsigned int GetT0() { if (fData.fT0.size()) return fData.fT0[0]; else return 0; }
virtual unsigned int GetFirstGoodBin() { if (fData.fFirstGoodBin.size()) return fData.fFirstGoodBin[0]; else return 0; }
virtual unsigned int GetLastGoodBin() { if (fData.fLastGoodBin.size()) return fData.fLastGoodBin[0]; else return 0; }
virtual vector<unsigned int> *GetHisto(unsigned int histoNo) { if (fData.fHisto.size() > histoNo) return &fData.fHisto[histoNo]; else return 0;}
virtual vector<unsigned int> *GetGroupedHisto(unsigned int histoNo) { if (fGroupedData.size() > histoNo) return &fGroupedData[histoNo]; else return 0; }
virtual void SetFileName(const char* fileName) { fFileName = fileName; }
virtual void SetFileName(string fileName) { fFileName = fileName; }
virtual void SetIDFVersion(int idfVersion) { fIDFVersion = idfVersion; }
virtual void SetProgramName(const char* progName) { fProgramName = progName; }
virtual void SetProgramName(string progName) { fProgramName = progName; }
virtual void SetProgramVersion(const char* progVersion) { fProgramVersion = progVersion; }
virtual void SetProgramVersion(string progVersion) { fProgramVersion = progVersion; }
virtual void SetRunNumber(int runNumber) { fRunNumber = runNumber; }
virtual void SetRunTitle(const char* runTitle) { fRunTitle = runTitle; }
virtual void SetRunTitle(string runTitle) { fRunTitle = runTitle; }
virtual void SetRunNotes(const char* notes) { fNotes = notes; }
virtual void SetRunNotes(string notes) { fNotes = notes; }
virtual void SetAnalysisTag(const char* analysisTag) { fAnalysisTag = analysisTag; }
virtual void SetAnalysisTag(string analysisTag) { fAnalysisTag = analysisTag; }
virtual void SetLab(const char *lab) { fLab = lab; }
virtual void SetLab(string lab) { fLab = lab; }
virtual void SetBeamline(const char *beamline) { fBeamLine = beamline; }
virtual void SetBeamline(string beamline) { fBeamLine = beamline; }
virtual bool SetStartDate(const char *date);
virtual bool SetStartDate(string date);
virtual bool SetStartTime(const char *time);
virtual bool SetStartTime(string time);
virtual bool SetStopDate(const char *date);
virtual bool SetStopDate(string date);
virtual bool SetStopTime(const char *time);
virtual bool SetStopTime(string time);
virtual void SetSwitchingState(int state) { fSwitchingState=state; }
virtual void SetUser(string user) { fUser.fUserName = user; }
virtual void SetExperimentNumber(string number) { fUser.fExperimentNumber = number; }
virtual void SetSampleName(string name) { fSample.fName = name; }
virtual void SetSampleTemperature(double temp) { fSample.fTemperature = temp; }
virtual void SetSampleTemperatureUints(string units) { fSample.fTemperatureUnit = units; }
virtual void SetMagneticField(double field) { fSample.fMagneticField = field; }
virtual void SetMagneticFieldUnits(string units) { fSample.fMagneticFieldUnit = units; }
virtual void SetMagneticFieldState(string state) { fSample.fMagneticFieldState = state; }
virtual void SetSampleEnvironment(string env) { fSample.fEnvironment = env; }
virtual void SetSampleShape(string shape) { fSample.fShape = shape; }
virtual void SetMagneticFieldVectorAvailable(int available) { fSample.fMagneticFieldVectorAvailable = available; }
virtual void SetMagneticFieldVector(vector<double>& vec) {fSample.fMagneticFieldVectorAvailable = 1; fSample.fMagneticFieldVector = vec;}
virtual void SetMagneticFieldVectorCoordSystem(string coord) { fSample.fMagneticFieldVectorCoordinateSystem = coord; }
virtual void SetMagneticFieldVectorUnits(string units) { fSample.fMagneticFieldVectorUnits = units; }
virtual void SetExperimentName(string name) { fInstrument.name = name; }
virtual void SetNoDetectors(unsigned int no) { fInstrument.detector.number = no; }
virtual void SetCollimatorType(string type) { fInstrument.collimator.type = type; }
virtual void SetTimeResolution(double timeResolution) { fData.fTimeResolution = timeResolution; } // given in ns
virtual void SetT0(unsigned int t0, unsigned int idx=0);
virtual void SetFirstGoodBin(unsigned int fgb, unsigned int idx=0);
virtual void SetLastGoodBin(unsigned int lgb, unsigned int idx=0);
virtual void SetHisto(unsigned int histoNo, vector<unsigned int> &data);
private:
bool fIsValid;
string fFileName; ///< read/write file name
NXhandle fFileHandle; ///< nexus file handle
bool fValid;
int fErrorCode;
string fErrorMsg;
string fErrorMsg; ///< stores the current error message
int fErrorCode; ///< indicates the current error code
string fNeXusVersion; ///< version of the NeXus API used in writing the file
string fFileFormatVersion; ///< version of the HDF, HDF5, or XML library used to create the file (IDF 2 only)
int fIDFVersion;
string fProgramName;
string fProgramVersion;
unsigned int fIdfVersion; ///< version of the instrument definition
string fFileName; ///< file name of the original NeXus file to assist identification if the external name has been changed
string fFileTime; ///< date and time of file creating (IDF 2 only)
NXhandle fFileHandle;
int fRunNumber;
string fRunTitle;
string fNotes;
string fAnalysisTag; ///< type of muon experiment
string fLab;
string fBeamLine;
string fStartDate;
string fStartTime;
string fStopDate;
string fStopTime;
int fSwitchingState; ///< red/green mode
string fCreator; ///< facility of program where the file originated
PNeXusUser fUser;
PNeXusSample fSample;
PNeXusInstrument fInstrument;
PNeXusData fData;
vector< vector<unsigned int> > fGroupedData;
PNeXusEntry1 *fNxEntry1; ///< NXentry for IDF 1
PNeXusEntry2 *fNxEntry2; ///< NXentry for IDF 2
vector< vector<unsigned int> > fGroupedHisto;
virtual void Init();
virtual void CleanUp();
virtual bool ErrorHandler(NXstatus status, int errCode, const string &errMsg);
virtual NXstatus GetStringData(string &str);
virtual NXstatus GetStringAttr(string attr, string &str);
virtual int GetDataSize(int type);
virtual NXstatus GetDoubleVectorData(vector<double> &data);
virtual NXstatus GetIntVectorData(vector<int> &data);
virtual int ReadFileIdf1();
virtual int ReadFileIdf2();
virtual int WriteFileIdf1(const char* fileName, const NXaccess access);
virtual int WriteFileIdf2(const char* fileName, const NXaccess access);
virtual NXstatus GroupHistoData();
virtual string TransformDate(string date, bool &ok);
virtual int GetMonth(const string month);
virtual bool IsValidIdf1(bool strict);
virtual bool IsValidIdf2(bool strict);
virtual bool SearchInGroup(string str, string tag, NXname &nxname, NXname &nxclass, int &dataType);
};
#endif // _PNEXUS_H_

View File

@ -609,6 +609,7 @@ typedef struct {
UInt_t rebin; ///< holds the number of bins to be packed
UInt_t compressionTag; ///< 0=no compression, 1=gzip compression, 2=bzip2 compression
TString compressFileName; ///< holds the name of the outputfile name in case of compression is used
UInt_t idf; ///< IDF version for NeXus files.
} PAny2ManyInfo;
#endif // _PMUSR_H_

View File

@ -96,6 +96,7 @@ class PRunDataHandler
virtual TString GetFileName(const TString extension, Bool_t &ok);
virtual TString FileNameFromTemplate(TString &fileNameTemplate, Int_t run, TString &year, Bool_t &ok);
virtual TString GetMonth(Int_t month);
virtual void SplitTimeDate(TString timeDate, TString &time, TString &date, Bool_t &ok);
};
#endif // _PRUNDATAHANDLER_H_

View File

@ -11,7 +11,7 @@ LD = g++
LDFLAGS = -g
LIBS = -L /usr/local/lib -lNeXus
LIBS += -L /opt/hdf5/lib -lhdf5
LIBS += -L /usr/lib -lhdf5
EXEC = nexus_read_test

View File

@ -30,6 +30,7 @@
***************************************************************************/
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
@ -37,8 +38,6 @@
#include <vector>
using namespace std;
#include "napi.h"
#include "PNeXus.h"
//---------------------------------------------------------------------------------------
@ -46,12 +45,13 @@ using namespace std;
void nexus_read_test_syntax()
{
cout << endl << ">>---------------------------------------------------------------------------------------";
cout << endl << ">> usage: nexus_read_test <nexus-in-filename> <nexus-out-filename> <nexus-write-format>";
cout << endl << ">> usage: nexus_read_test <nexus-in-filename> [<nexus-out-filename> <nexus-write-format> <idf>]";
cout << endl << ">> This will try to read a nexus-files <nexus-in-filename> and send the relevant";
cout << endl << ">> information to the standard output.";
cout << endl << ">> At the same time the read file is written back to <nexus-out-filename>, where";
cout << endl << ">> the extension will be added based on the <nexus-write-format>.";
cout << endl << ">> <nexus-write-format>: hdf4, hdf5, xml";
cout << endl << ">> <idf>: 1 | 2";
cout << endl << ">>---------------------------------------------------------------------------------------";
cout << endl << endl;
}
@ -60,29 +60,39 @@ void nexus_read_test_syntax()
int main(int argc, char *argv[])
{
if (argc != 4) {
if ((argc != 5) && (argc !=2)) {
nexus_read_test_syntax();
return -1;
}
PNeXus *nxs_file = new PNeXus(argv[1]);
if (nxs_file->IsValid()) {
if (nxs_file->IsValid(true)) {
nxs_file->Dump();
char filename[128];
if (strstr(argv[3], "hdf") || strstr(argv[3], "xml")) {
snprintf(filename, sizeof(filename), "%s.%s", argv[2], argv[3]);
} else {
cerr << endl << "**ERROR** unkown nexus write format found" << endl;
nexus_read_test_syntax();
return -1;
}
if (argc == 5) {
long int idf = strtol(argv[4], (char **)NULL, 10);
if ((idf != 1) && (idf != 2)) {
if (nxs_file)
delete nxs_file;
nexus_read_test_syntax();
return -1;
}
if (nxs_file->WriteFile(filename, argv[3]) != NX_OK) {
cerr << endl << nxs_file->GetErrorMsg() << " (" << nxs_file->GetErrorCode() << ")" << endl << endl;
} else {
cout << endl << "file " << filename << " written successfully." << endl << endl;
char filename[128];
if (strstr(argv[3], "hdf") || strstr(argv[3], "xml")) {
snprintf(filename, sizeof(filename), "%s.%s", argv[2], argv[3]);
} else {
cerr << endl << "**ERROR** unkown nexus write format found" << endl;
nexus_read_test_syntax();
return -1;
}
if (nxs_file->WriteFile(filename, argv[3], (unsigned int)idf) != NX_OK) {
cerr << endl << nxs_file->GetErrorMsg() << " (" << nxs_file->GetErrorCode() << ")" << endl << endl;
} else {
cout << endl << "file " << filename << " written successfully." << endl << endl;
}
}
}