first full IDF V2 implementation.

This commit is contained in:
2026-02-05 10:59:15 +01:00
parent 43cb8b2460
commit 810306cb2a
3 changed files with 56 additions and 12 deletions

View File

@@ -685,6 +685,7 @@ Bool_t PRunDataHandler::ReadNexusFileIdf1(T& nxs_file)
template <typename T>
Bool_t PRunDataHandler::ReadNexusFileIdf2(T& nxs_file)
{
std::cerr << "as35> in ReadNexusFileIdf2." << std::endl;
PRawRunData runData;
PRawRunDataSet dataSet;
TString str;
@@ -729,7 +730,7 @@ Bool_t PRunDataHandler::ReadNexusFileIdf2(T& nxs_file)
// 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];
ival = nxs_file->template GetDataset<int>("/raw_data_1/run_number").GetData()[0];
runData.SetRunNumber(ival);
// get/set temperature
@@ -745,7 +746,7 @@ Bool_t PRunDataHandler::ReadNexusFileIdf2(T& nxs_file)
}
runData.SetTemperature(0, dval, 0.0);
// get/set field
// get/set field
dval = PMUSR_UNDEFINED;
sstr = "n/a";
factor = 1.0;
@@ -785,7 +786,7 @@ Bool_t PRunDataHandler::ReadNexusFileIdf2(T& nxs_file)
// get/set orientation
runData.SetOrientation("n/a");
// get/set time resolution (ns)
// get/set time resolution (ns)
dval = PMUSR_UNDEFINED;
sstr = "n/a";
factor = 1.0;
@@ -830,13 +831,55 @@ Bool_t PRunDataHandler::ReadNexusFileIdf2(T& nxs_file)
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];
ival = nxs_file->template GetDataset<int>("/raw_data_1/good_frames").GetData()[0];
runData.SetNumberOfGoodFrames(ival);
}
// data with its metadata
if (nxs_file->HasDataset("/raw_data_1/instrument/detector_1/counts")) {
int t0_bin{-1}, fgb{-1}, lgb{-1}, noOfHistos{-1}, histoLength{-1};
auto count_ds = nxs_file->template GetDataset<int>("/raw_data_1/instrument/detector_1/counts");
auto count = count_ds.GetData();
auto dims = count_ds.GetDimensions();
if (dims.size() < 3) {
std::cerr << std::endl << "**ERROR** PNeXus data dimension error! dims.size()=" << dims.size() << ", expecting == 3." << std::endl;
return false;
}
noOfHistos = dims[1];
histoLength = dims[2];
// get all necessary attributes
if (count_ds.HasAttribute("t0_bin"))
t0_bin = std::any_cast<int>(count_ds.GetAttribute("t0_bin"));
if (count_ds.HasAttribute("first_good_bin"))
fgb = std::any_cast<int>(count_ds.GetAttribute("first_good_bin"));
if (count_ds.HasAttribute("last_good_bin"))
lgb = std::any_cast<int>(count_ds.GetAttribute("last_good_bin"));
if (static_cast<int>(count.size()) != noOfHistos*histoLength) {
std::cerr << std::endl << "**ERROR** PNeXus data size error! count.size()=" << count.size() << ", #histos=" << noOfHistos << ", length=" << histoLength << "." << std::endl;
return false;
}
// *** STILL MISSING ***
// fill dataSet
PDoubleVector data;
for (int i=0; i<noOfHistos; i++) {
dataSet.Clear();
dataSet.SetHistoNo(i+1); // i.e. histo numbers start with 1
dataSet.SetTimeZeroBin(t0_bin);
dataSet.SetFirstGoodBin(fgb);
dataSet.SetLastGoodBin(lgb);
for (int j=0; j<histoLength; j++)
data.push_back(count[i*histoLength+j]);
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);
}
return true;
}