first full IDF V2 implementation.
This commit is contained in:
@@ -2281,7 +2281,8 @@ Bool_t PRunDataHandler::ReadNexusFile()
|
||||
if (!ReadNexusFileIdf1(nxs_file))
|
||||
return false;
|
||||
} else { // HDF5 IDF V2
|
||||
// not yet implemented
|
||||
if (!ReadNexusFileIdf2(nxs_file))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#else
|
||||
|
||||
12
src/external/nexus/PNeXus.cpp
vendored
12
src/external/nexus/PNeXus.cpp
vendored
@@ -2371,7 +2371,7 @@ 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()) {
|
||||
auto dead_time = std::any_cast<PNXdata<float>>(dataMap["/raw_data_1/detector_1/dead_time"]);
|
||||
const auto& dt_data = dead_time.GetData();
|
||||
@@ -2379,7 +2379,7 @@ nxH5::PNeXusDeadTime::PNeXusDeadTime(const PNeXus *nxs, bool debug) : fDebug(deb
|
||||
}
|
||||
fDeadTimeEstimated.resize(fDeadTime.size());
|
||||
|
||||
// get good_frames
|
||||
// get good_frames
|
||||
if (dataMap.find("/raw_data_1/good_frames") != dataMap.end()) {
|
||||
auto intData = std::any_cast<PNXdata<int>>(dataMap["/raw_data_1/good_frames"]);
|
||||
const auto& ival = intData.GetData();
|
||||
@@ -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/probe");
|
||||
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");
|
||||
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) {
|
||||
std::cerr << "Error in HandleIdfV2: " << err.getDetailMsg() << std::endl;
|
||||
throw;
|
||||
@@ -3797,7 +3797,7 @@ void nxH5::PNeXus::Dump()
|
||||
std::cout << std::endl << " counts:";
|
||||
std::cout << std::endl;
|
||||
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();
|
||||
std::cout << " counts dimensions: " << dims[0] << " x "
|
||||
<< 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;
|
||||
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();
|
||||
|
||||
// dump the first couple of raw_times
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user