NeXus IDF V2 detector_1 -> instrument/detector_1 where possible.

This commit is contained in:
2026-02-05 12:08:40 +01:00
parent 810306cb2a
commit 88b5e492dd

View File

@@ -137,8 +137,8 @@ nxH4::PNeXusDeadTime::PNeXusDeadTime(const nxH4::PNeXus *nxs, bool debug) : fDeb
// not yet implemented // not yet implemented
} else { // idfVersion == 2 } else { // idfVersion == 2
// get counts // get counts
if (dataMap.find("/raw_data_1/detector_1/counts") != dataMap.end()) { if (dataMap.find("/raw_data_1/instrument/detector_1/counts") != dataMap.end()) {
auto counts_data = std::any_cast<PNXdata<int>>(dataMap["/raw_data_1/detector_1/counts"]); auto counts_data = std::any_cast<PNXdata<int>>(dataMap["/raw_data_1/instrument/detector_1/counts"]);
const auto& counts = counts_data.GetData(); const auto& counts = counts_data.GetData();
fCounts = counts; fCounts = counts;
auto dims = counts_data.GetDimensions(); auto dims = counts_data.GetDimensions();
@@ -154,8 +154,8 @@ nxH4::PNeXusDeadTime::PNeXusDeadTime(const nxH4::PNeXus *nxs, bool debug) : fDeb
} }
// get time_resolution // get time_resolution
if (dataMap.find("/raw_data_1/detector_1/time_resolution") != dataMap.end()) { if (dataMap.find("/raw_data_1/instrument/detector_1/time_resolution") != dataMap.end()) {
auto time_res_data = std::any_cast<PNXdata<float>>(dataMap["/raw_data_1/detector_1/time_resolution"]); auto time_res_data = std::any_cast<PNXdata<float>>(dataMap["/raw_data_1/instrument/detector_1/time_resolution"]);
const auto& time_res = time_res_data.GetData(); const auto& time_res = time_res_data.GetData();
if (time_res.size() > 0) { if (time_res.size() > 0) {
fTimeResolution = time_res[0]; fTimeResolution = time_res[0];
@@ -186,8 +186,8 @@ nxH4::PNeXusDeadTime::PNeXusDeadTime(const nxH4::PNeXus *nxs, bool debug) : fDeb
} }
// get t0_bin, first_good_bin, last_good_bin // get t0_bin, first_good_bin, last_good_bin
if (dataMap.find("/raw_data_1/detector_1/spectrum_index") != dataMap.end()) { if (dataMap.find("/raw_data_1/instrument/detector_1/spectrum_index") != dataMap.end()) {
auto spec_idx_data = std::any_cast<PNXdata<int>>(dataMap["/raw_data_1/detector_1/spectrum_index"]); auto spec_idx_data = std::any_cast<PNXdata<int>>(dataMap["/raw_data_1/instrument/detector_1/spectrum_index"]);
if (spec_idx_data.HasAttribute("t0_bin")) { if (spec_idx_data.HasAttribute("t0_bin")) {
try { try {
fT0Bin = std::any_cast<int>(spec_idx_data.GetAttribute("t0_bin")); fT0Bin = std::any_cast<int>(spec_idx_data.GetAttribute("t0_bin"));
@@ -581,16 +581,16 @@ void nxH4::PNeXus::HandleIdfV2(int32 sd_id)
// These are typical datasets found in muon NeXus files // These are typical datasets found in muon NeXus files
std::vector<std::string> int_datasets = { std::vector<std::string> int_datasets = {
"/raw_data_1/detector_1/counts", "/raw_data_1/instrument/detector_1/counts",
"/raw_data_1/detector_1/spectrum_index", "/raw_data_1/instrument/detector_1/spectrum_index",
"/raw_data_1/good_frames", "/raw_data_1/good_frames",
"/raw_data_1/detector_1/raw_time", "/raw_data_1/instrument/detector_1/raw_time",
"/raw_data_1/run_number" "/raw_data_1/run_number"
}; };
std::vector<std::string> float_datasets = { std::vector<std::string> float_datasets = {
"/raw_data_1/detector_1/time_resolution", "/raw_data_1/instrument/detector_1/resolution",
"/raw_data_1/detector_1/time_zero" "/raw_data_1/instrument/detector_1/time_zero"
}; };
std::vector<std::string> string_datasets = { std::vector<std::string> string_datasets = {
@@ -1553,7 +1553,7 @@ void nxH4::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;
@@ -1645,7 +1645,7 @@ void nxH4::PNeXus::Dump()
std::cout << std::endl << " raw_time:"; std::cout << std::endl << " raw_time:";
std::cout << std::endl; std::cout << std::endl;
try { try {
auto raw_time = std::any_cast<PNXdata<float>>(fDataMap["/raw_data_1/detector_1/raw_time"]); auto raw_time = std::any_cast<PNXdata<float>>(fDataMap["/raw_data_1/instrument/detector_1/raw_time"]);
const auto& data = raw_time.GetData(); const auto& data = raw_time.GetData();
// Check for attributes // Check for attributes
@@ -1671,7 +1671,7 @@ void nxH4::PNeXus::Dump()
std::cout << std::endl << " spectrum_index:"; std::cout << std::endl << " spectrum_index:";
std::cout << std::endl; std::cout << std::endl;
try { try {
auto spectrum_index = std::any_cast<PNXdata<int>>(fDataMap["/raw_data_1/detector_1/spectrum_index"]); auto spectrum_index = std::any_cast<PNXdata<int>>(fDataMap["/raw_data_1/instrument/detector_1/spectrum_index"]);
const auto& data = spectrum_index.GetData(); const auto& data = spectrum_index.GetData();
// dump the first couple of raw_times // dump the first couple of raw_times
@@ -1687,7 +1687,7 @@ void nxH4::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
@@ -2325,8 +2325,8 @@ nxH5::PNeXusDeadTime::PNeXusDeadTime(const PNeXus *nxs, bool debug) : fDebug(deb
// not yet implemented // not yet implemented
} else { // idfVersion == 2 } else { // idfVersion == 2
// get counts // get counts
if (dataMap.find("/raw_data_1/detector_1/counts") != dataMap.end()) { if (dataMap.find("/raw_data_1/instrument/detector_1/counts") != dataMap.end()) {
auto counts_data = std::any_cast<PNXdata<int>>(dataMap["/raw_data_1/detector_1/counts"]); auto counts_data = std::any_cast<PNXdata<int>>(dataMap["/raw_data_1/instrument/detector_1/counts"]);
const auto& counts = counts_data.GetData(); const auto& counts = counts_data.GetData();
fCounts = counts; fCounts = counts;
auto dims = counts_data.GetDimensions(); auto dims = counts_data.GetDimensions();
@@ -2372,8 +2372,8 @@ nxH5::PNeXusDeadTime::PNeXusDeadTime(const PNeXus *nxs, bool debug) : fDebug(deb
} }
// get dead time parameters // get dead time parameters
if (dataMap.find("/raw_data_1/detector_1/dead_time") != dataMap.end()) { if (dataMap.find("/raw_data_1/instrument/detector_1/dead_time") != dataMap.end()) {
auto dead_time = std::any_cast<PNXdata<float>>(dataMap["/raw_data_1/detector_1/dead_time"]); auto dead_time = std::any_cast<PNXdata<float>>(dataMap["/raw_data_1/instrument/detector_1/dead_time"]);
const auto& dt_data = dead_time.GetData(); const auto& dt_data = dead_time.GetData();
fDeadTime = dt_data; fDeadTime = dt_data;
} }
@@ -3207,9 +3207,9 @@ void nxH5::PNeXus::HandleIdfV2(H5::H5File &file)
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/instrument/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/instrument/detector_1/raw_time");
ReadIntDataset(file, "/raw_data_1/detector_1/spectrum_index"); ReadIntDataset(file, "/raw_data_1/instrument/detector_1/spectrum_index");
ReadFloatDataset(file, "/raw_data_1/instrument/detector_1/dead_time"); ReadFloatDataset(file, "/raw_data_1/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;
@@ -3889,7 +3889,7 @@ void nxH5::PNeXus::Dump()
std::cout << std::endl << " raw_time:"; std::cout << std::endl << " raw_time:";
std::cout << std::endl; std::cout << std::endl;
try { try {
auto raw_time = std::any_cast<PNXdata<float>>(fDataMap["/raw_data_1/detector_1/raw_time"]); auto raw_time = std::any_cast<PNXdata<float>>(fDataMap["/raw_data_1/instrument/detector_1/raw_time"]);
const auto& data = raw_time.GetData(); const auto& data = raw_time.GetData();
// Check for attributes // Check for attributes
@@ -3915,7 +3915,7 @@ void nxH5::PNeXus::Dump()
std::cout << std::endl << " spectrum_index:"; std::cout << std::endl << " spectrum_index:";
std::cout << std::endl; std::cout << std::endl;
try { try {
auto spectrum_index = std::any_cast<PNXdata<int>>(fDataMap["/raw_data_1/detector_1/spectrum_index"]); auto spectrum_index = std::any_cast<PNXdata<int>>(fDataMap["/raw_data_1/instrument/detector_1/spectrum_index"]);
const auto& data = spectrum_index.GetData(); const auto& data = spectrum_index.GetData();
// dump the first couple of raw_times // dump the first couple of raw_times