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

@@ -2281,7 +2281,8 @@ Bool_t PRunDataHandler::ReadNexusFile()
if (!ReadNexusFileIdf1(nxs_file)) if (!ReadNexusFileIdf1(nxs_file))
return false; return false;
} else { // HDF5 IDF V2 } else { // HDF5 IDF V2
// not yet implemented if (!ReadNexusFileIdf2(nxs_file))
return false;
} }
} }
#else #else

View File

@@ -3206,10 +3206,10 @@ void nxH5::PNeXus::HandleIdfV2(H5::H5File &file)
ReadStringDataset(file, "/raw_data_1/instrument/source/type"); ReadStringDataset(file, "/raw_data_1/instrument/source/type");
ReadStringDataset(file, "/raw_data_1/instrument/source/probe"); ReadStringDataset(file, "/raw_data_1/instrument/source/probe");
ReadIntDataset(file, "/raw_data_1/instrument/detector_1/resolution"); ReadIntDataset(file, "/raw_data_1/instrument/detector_1/resolution");
ReadIntDataset(file, "/raw_data_1/detector_1/counts"); ReadIntDataset(file, "/raw_data_1/instrument/detector_1/counts");
ReadFloatDataset(file, "/raw_data_1/detector_1/raw_time"); ReadFloatDataset(file, "/raw_data_1/detector_1/raw_time");
ReadIntDataset(file, "/raw_data_1/detector_1/spectrum_index"); ReadIntDataset(file, "/raw_data_1/detector_1/spectrum_index");
ReadFloatDataset(file, "/raw_data_1/detector_1/dead_time"); ReadFloatDataset(file, "/raw_data_1/instrument/detector_1/dead_time");
} catch (const H5::Exception& err) { } catch (const H5::Exception& err) {
std::cerr << "Error in HandleIdfV2: " << err.getDetailMsg() << std::endl; std::cerr << "Error in HandleIdfV2: " << err.getDetailMsg() << std::endl;
throw; throw;
@@ -3797,7 +3797,7 @@ void nxH5::PNeXus::Dump()
std::cout << std::endl << " counts:"; std::cout << std::endl << " counts:";
std::cout << std::endl; std::cout << std::endl;
try { try {
auto counts_data = std::any_cast<PNXdata<int>>(fDataMap["/raw_data_1/detector_1/counts"]); auto counts_data = std::any_cast<PNXdata<int>>(fDataMap["/raw_data_1/instrument/detector_1/counts"]);
auto dims = counts_data.GetDimensions(); auto dims = counts_data.GetDimensions();
std::cout << " counts dimensions: " << dims[0] << " x " std::cout << " counts dimensions: " << dims[0] << " x "
<< dims[1] << " x " << dims[2] << std::endl; << dims[1] << " x " << dims[2] << std::endl;
@@ -3931,7 +3931,7 @@ void nxH5::PNeXus::Dump()
std::cout << std::endl << " dead_time:"; std::cout << std::endl << " dead_time:";
std::cout << std::endl; std::cout << std::endl;
try { try {
auto dead_time = std::any_cast<PNXdata<float>>(fDataMap["/raw_data_1/detector_1/dead_time"]); auto dead_time = std::any_cast<PNXdata<float>>(fDataMap["/raw_data_1/instrument/detector_1/dead_time"]);
const auto& data = dead_time.GetData(); const auto& data = dead_time.GetData();
// dump the first couple of raw_times // dump the first couple of raw_times

View File

@@ -685,6 +685,7 @@ Bool_t PRunDataHandler::ReadNexusFileIdf1(T& nxs_file)
template <typename T> template <typename T>
Bool_t PRunDataHandler::ReadNexusFileIdf2(T& nxs_file) Bool_t PRunDataHandler::ReadNexusFileIdf2(T& nxs_file)
{ {
std::cerr << "as35> in ReadNexusFileIdf2." << std::endl;
PRawRunData runData; PRawRunData runData;
PRawRunDataSet dataSet; PRawRunDataSet dataSet;
TString str; TString str;
@@ -729,7 +730,7 @@ Bool_t PRunDataHandler::ReadNexusFileIdf2(T& nxs_file)
// get/set run number // get/set run number
ival = -1; ival = -1;
if (nxs_file->HasDataset("/raw_data_1/run_number")) 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); runData.SetRunNumber(ival);
// get/set temperature // get/set temperature
@@ -830,13 +831,55 @@ Bool_t PRunDataHandler::ReadNexusFileIdf2(T& nxs_file)
runData.SetDeadTimeParam(dt); runData.SetDeadTimeParam(dt);
} }
if (nxs_file->HasDataset("/raw_data_1/good_frames")) { 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); runData.SetNumberOfGoodFrames(ival);
} }
// data with its metadata // 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; return true;
} }