start with the implementation of NeXus IDF V2.
This commit is contained in:
@@ -2284,198 +2284,6 @@ Bool_t PRunDataHandler::ReadNexusFile()
|
||||
// not yet implemented
|
||||
}
|
||||
}
|
||||
|
||||
/* //as35
|
||||
} else if (nxs_file->GetIdfVersion() == 2) {
|
||||
if (!nxs_file->IsValid()) {
|
||||
std::cout << std::endl << "**ERROR** invalid NeXus IDF 2 version file found." << std::endl;
|
||||
return false;
|
||||
}
|
||||
// get header information
|
||||
|
||||
// get/set laboratory
|
||||
str = TString(nxs_file->GetEntryIdf2()->GetInstrument()->GetSource()->GetName());
|
||||
runData.SetLaboratory(str);
|
||||
|
||||
// get/set beamline
|
||||
str = TString(nxs_file->GetEntryIdf2()->GetInstrument()->GetName());
|
||||
runData.SetBeamline(str);
|
||||
|
||||
// get/set instrument
|
||||
str = TString(nxs_file->GetEntryIdf2()->GetInstrument()->GetName());
|
||||
runData.SetInstrument(str);
|
||||
|
||||
// get/set muon source
|
||||
str = TString(nxs_file->GetEntryIdf2()->GetInstrument()->GetSource()->GetType());
|
||||
runData.SetMuonSource(str);
|
||||
|
||||
// get/set muon species
|
||||
str = TString(nxs_file->GetEntryIdf2()->GetInstrument()->GetSource()->GetProbe());
|
||||
runData.SetMuonSpecies(str);
|
||||
|
||||
// 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() + std::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 data, t0, fgb, lgb
|
||||
PDoubleVector data;
|
||||
PRawRunDataSet dataSet;
|
||||
UInt_t histoNo = 0;
|
||||
Int_t ival;
|
||||
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));
|
||||
}
|
||||
dataSet.Clear();
|
||||
dataSet.SetHistoNo(++histoNo); // i.e. histo numbers start with 1
|
||||
// get t0
|
||||
ival = nxs_file->GetEntryIdf2()->GetInstrument()->GetDetector()->GetT0(i,j);
|
||||
if (ival == -1) // i.e. single value only
|
||||
ival = nxs_file->GetEntryIdf2()->GetInstrument()->GetDetector()->GetT0();
|
||||
dataSet.SetTimeZeroBin(ival);
|
||||
// get first good bin
|
||||
ival = nxs_file->GetEntryIdf2()->GetInstrument()->GetDetector()->GetFirstGoodBin(i,j);
|
||||
if (ival == -1) // i.e. single value only
|
||||
ival = nxs_file->GetEntryIdf2()->GetInstrument()->GetDetector()->GetFirstGoodBin();
|
||||
dataSet.SetFirstGoodBin(ival);
|
||||
// get last good bin
|
||||
ival = nxs_file->GetEntryIdf2()->GetInstrument()->GetDetector()->GetLastGoodBin(i,j);
|
||||
if (ival == -1) // i.e. single value only
|
||||
ival = nxs_file->GetEntryIdf2()->GetInstrument()->GetDetector()->GetLastGoodBin();
|
||||
dataSet.SetLastGoodBin(ival);
|
||||
|
||||
dataSet.SetData(data);
|
||||
runData.SetDataSet(dataSet);
|
||||
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));
|
||||
}
|
||||
dataSet.Clear();
|
||||
dataSet.SetHistoNo(++histoNo); // i.e. histo numbers start with 1
|
||||
// get t0
|
||||
ival = nxs_file->GetEntryIdf2()->GetInstrument()->GetDetector()->GetT0(-1,i);
|
||||
if (ival == -1) // i.e. single value only
|
||||
ival = nxs_file->GetEntryIdf2()->GetInstrument()->GetDetector()->GetT0();
|
||||
dataSet.SetTimeZeroBin(ival);
|
||||
// get first good bin
|
||||
ival = nxs_file->GetEntryIdf2()->GetInstrument()->GetDetector()->GetFirstGoodBin(-1,i);
|
||||
if (ival == -1) // i.e. single value only
|
||||
ival = nxs_file->GetEntryIdf2()->GetInstrument()->GetDetector()->GetFirstGoodBin();
|
||||
dataSet.SetFirstGoodBin(ival);
|
||||
// get last good bin
|
||||
ival = nxs_file->GetEntryIdf2()->GetInstrument()->GetDetector()->GetLastGoodBin(-1,i);
|
||||
if (ival == -1) // i.e. single value only
|
||||
ival = nxs_file->GetEntryIdf2()->GetInstrument()->GetDetector()->GetLastGoodBin();
|
||||
dataSet.SetLastGoodBin(ival);
|
||||
|
||||
dataSet.SetData(data);
|
||||
runData.SetDataSet(dataSet);
|
||||
data.clear();
|
||||
}
|
||||
} else { // counts[]
|
||||
for (int i=0; i<nxs_file->GetEntryIdf2()->GetInstrument()->GetDetector()->GetNoOfBins(); i++) {
|
||||
data.push_back(*(histos+i));
|
||||
}
|
||||
dataSet.Clear();
|
||||
dataSet.SetHistoNo(++histoNo); // i.e. histo numbers start with 1
|
||||
// get t0
|
||||
ival = nxs_file->GetEntryIdf2()->GetInstrument()->GetDetector()->GetT0();
|
||||
dataSet.SetTimeZeroBin(ival);
|
||||
// get first good bin
|
||||
ival = nxs_file->GetEntryIdf2()->GetInstrument()->GetDetector()->GetFirstGoodBin();
|
||||
dataSet.SetFirstGoodBin(ival);
|
||||
// get last good bin
|
||||
ival = nxs_file->GetEntryIdf2()->GetInstrument()->GetDetector()->GetLastGoodBin();
|
||||
dataSet.SetLastGoodBin(ival);
|
||||
|
||||
dataSet.SetData(data);
|
||||
runData.SetDataSet(dataSet);
|
||||
data.clear();
|
||||
}
|
||||
}
|
||||
|
||||
// keep run name from the msr-file
|
||||
runData.SetRunName(fRunName);
|
||||
|
||||
// keep the information
|
||||
fData.push_back(runData);
|
||||
} else {
|
||||
std::cout << std::endl << ">> PRunDataHandler::ReadNexusFile(): IDF version " << nxs_file->GetIdfVersion() << ", not implemented." << std::endl;
|
||||
}
|
||||
*/ //as35
|
||||
#else
|
||||
std::cout << std::endl << ">> PRunDataHandler::ReadNexusFile(): Sorry, not enabled at configuration level, i.e. --enable-NeXus when executing configure" << std::endl << std::endl;
|
||||
#endif
|
||||
|
||||
@@ -685,6 +685,159 @@ Bool_t PRunDataHandler::ReadNexusFileIdf1(T& nxs_file)
|
||||
template <typename T>
|
||||
Bool_t PRunDataHandler::ReadNexusFileIdf2(T& nxs_file)
|
||||
{
|
||||
PRawRunData runData;
|
||||
PRawRunDataSet dataSet;
|
||||
TString str;
|
||||
std::string sstr;
|
||||
Int_t ival;
|
||||
Double_t dval, factor;
|
||||
bool ok;
|
||||
|
||||
// get header information
|
||||
|
||||
// get/set laboratory
|
||||
sstr = "n/a";
|
||||
if (nxs_file->HasDataset("/raw_data_1/instrument/source/name"))
|
||||
sstr = nxs_file->template GetDataset<std::string>("/raw_data_1/instrument/source/name").GetData()[0];
|
||||
runData.SetLaboratory(sstr);
|
||||
|
||||
// get/set beamline
|
||||
sstr = "n/a";
|
||||
if (nxs_file->HasDataset("/raw_data_1/instrument/name"))
|
||||
sstr = nxs_file->template GetDataset<std::string>("/raw_data_1/instrument/name").GetData()[0];
|
||||
runData.SetBeamline(sstr);
|
||||
runData.SetBeamline(sstr);
|
||||
|
||||
// get/set muon source
|
||||
sstr = "n/a";
|
||||
if (nxs_file->HasDataset("/raw_data_1/instrument/source/type"))
|
||||
sstr = nxs_file->template GetDataset<std::string>("/raw_data_1/instrument/source/type").GetData()[0];
|
||||
runData.SetMuonSource(sstr);
|
||||
|
||||
// get/set muon species
|
||||
sstr = "n/a";
|
||||
if (nxs_file->HasDataset("/raw_data_1/instrument/source/probe"))
|
||||
sstr = nxs_file->template GetDataset<std::string>("/raw_data_1/instrument/source/probe").GetData()[0];
|
||||
runData.SetMuonSpecies(sstr);
|
||||
|
||||
// get/set run title
|
||||
sstr = "n/a";
|
||||
if (nxs_file->HasDataset("/raw_data_1/title"))
|
||||
sstr = nxs_file->template GetDataset<std::string>("/raw_data_1/title").GetData()[0];
|
||||
runData.SetRunTitle(sstr);
|
||||
|
||||
// get/set run number
|
||||
ival = -1;
|
||||
if (nxs_file->HasDataset("/raw_data_1/run_number"))
|
||||
ival = nxs_file->template GetDataset<std::string>("/raw_data_1/run_number").GetData()[0];
|
||||
runData.SetRunNumber(ival);
|
||||
|
||||
// get/set temperature
|
||||
dval = PMUSR_UNDEFINED;
|
||||
sstr = "n/a";
|
||||
if (nxs_file->HasDataset("/raw_data_1/sample/temperature")) {
|
||||
auto tmp_ds = nxs_file->template GetDataset<float>("/raw_data_1/sample/temperature");
|
||||
dval = tmp_ds.GetData()[0];
|
||||
if (tmp_ds.HasAttribute("units"))
|
||||
sstr = std::any_cast<std::string>(tmp_ds.GetAttribute("units"));
|
||||
if (sstr == "Celcius")
|
||||
dval += 273.16;
|
||||
}
|
||||
runData.SetTemperature(0, dval, 0.0);
|
||||
|
||||
// get/set field
|
||||
dval = PMUSR_UNDEFINED;
|
||||
sstr = "n/a";
|
||||
factor = 1.0;
|
||||
if (nxs_file->HasDataset("/raw_data_1/sample/magnetic_field")) {
|
||||
auto mag_ds = nxs_file->template GetDataset<float>("/raw_data_1/sample/magnetic_field");
|
||||
dval = mag_ds.GetData()[0];
|
||||
if (mag_ds.HasAttribute("units"))
|
||||
sstr = std::any_cast<std::string>(mag_ds.GetAttribute("units"));
|
||||
if (sstr == "Tesla")
|
||||
factor = 1.0e4;
|
||||
}
|
||||
runData.SetField(dval*factor);
|
||||
|
||||
// get/set implantation energy
|
||||
runData.SetEnergy(PMUSR_UNDEFINED);
|
||||
|
||||
// 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
|
||||
sstr = "n/a";
|
||||
runData.SetSetup(str);
|
||||
|
||||
// get/set sample
|
||||
sstr = "n/a";
|
||||
if (nxs_file->HasDataset("/raw_data_1/sample/name"))
|
||||
sstr = nxs_file->template GetDataset<std::string>("/raw_data_1/sample/name").GetData()[0];
|
||||
runData.SetSample(sstr);
|
||||
|
||||
// get/set orientation
|
||||
runData.SetOrientation("n/a");
|
||||
|
||||
// get/set time resolution (ns)
|
||||
dval = PMUSR_UNDEFINED;
|
||||
sstr = "n/a";
|
||||
factor = 1.0;
|
||||
if (nxs_file->HasDataset("/raw_data_1/instrument/detector_1/resolution")) {
|
||||
auto res_ds = nxs_file->template GetDataset<int>("/raw_data_1/instrument/detector_1/resolution");
|
||||
dval = res_ds.GetData()[0];
|
||||
if (res_ds.HasAttribute("units"))
|
||||
sstr = std::any_cast<std::string>(res_ds.GetAttribute("units"));
|
||||
if ((sstr == "picoseconds") || (sstr == "pico.seconds"))
|
||||
factor = 1.0e-3; // ps -> ns
|
||||
}
|
||||
runData.SetTimeResolution(dval*factor);
|
||||
|
||||
// get/set start/stop time
|
||||
sstr = "n/a";
|
||||
TString date{"n/a"}, time{"n/a"};
|
||||
if (nxs_file->HasDataset("/raw_data_1/start_time"))
|
||||
sstr = nxs_file->template GetDataset<std::string>("/raw_data_1/start_time").GetData()[0];
|
||||
str = sstr;
|
||||
SplitTimeDate(str, time, date, ok);
|
||||
if (ok) {
|
||||
runData.SetStartTime(time);
|
||||
runData.SetStartDate(date);
|
||||
}
|
||||
|
||||
sstr = "n/a";
|
||||
date = "n/a";
|
||||
time = "n/a";
|
||||
if (nxs_file->HasDataset("/raw_data_1/end_time"))
|
||||
sstr = nxs_file->template GetDataset<std::string>("/raw_data_1/end_time").GetData()[0];
|
||||
str = sstr;
|
||||
SplitTimeDate(str, time, date, ok);
|
||||
if (ok) {
|
||||
runData.SetStopTime(time);
|
||||
runData.SetStopDate(date);
|
||||
}
|
||||
|
||||
// get/set deadtime relevant parameters
|
||||
if (nxs_file->HasDataset("/raw_data_1/instrument/detector1/dead_time")) {
|
||||
std::vector<float> dt;
|
||||
dt = nxs_file->template GetDataset<float>("/raw_data_1/instrument/detector1/dead_time").GetData();
|
||||
runData.SetDeadTimeParam(dt);
|
||||
}
|
||||
if (nxs_file->HasDataset("/raw_data_1/good_frames")) {
|
||||
ival = nxs_file->template GetDataset<float>("/raw_data_1/good_frames").GetData()[0];
|
||||
runData.SetNumberOfGoodFrames(ival);
|
||||
}
|
||||
|
||||
// data with its metadata
|
||||
|
||||
// *** STILL MISSING ***
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user