fix of wrong cherry-pick.

This commit is contained in:
2026-07-15 10:47:43 +02:00
parent e2a42eadd5
commit bb6af7b632
+151 -311
View File
@@ -530,155 +530,21 @@ Bool_t PRunDataHandler::ReadNexusFileIdf1(T& nxs_file)
ival = nxs_file->template GetDataset<int>("/run/number").GetData()[0];
runData.SetRunNumber(ival);
// get/set temperature
dval = PMUSR_UNDEFINED;
sstr = "n/a";
if (nxs_file->HasDataset("/run/sample/temperature")) {
auto tmp_ds = nxs_file->template GetDataset<float>("/run/sample/temperature");
dval = tmp_ds.GetData()[0];
if (tmp_ds.HasAttribute("units")) {
try {
sstr = std::any_cast<std::string>(tmp_ds.GetAttribute("units"));
} catch (const std::bad_any_cast&) {
std::cerr << std::endl << "**WARNING** ReadNexusFileIdf1: temperature 'units' attribute has unexpected type." << std::endl;
}
}
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("/run/sample/magnetic_field")) {
auto mag_ds = nxs_file->template GetDataset<float>("/run/sample/magnetic_field");
dval = mag_ds.GetData()[0];
if (mag_ds.HasAttribute("units")) {
try {
sstr = std::any_cast<std::string>(mag_ds.GetAttribute("units"));
} catch (const std::bad_any_cast&) {
std::cerr << std::endl << "**WARNING** ReadNexusFileIdf1: magnetic_field 'units' attribute has unexpected type." << std::endl;
}
}
if (sstr == "Tesla")
factor = 1.0e4;
}
runData.SetField(dval*factor);
// 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";
if (nxs_file->HasDataset("/run/notes"))
sstr = nxs_file->template GetDataset<std::string>("/run/notes").GetData()[0];
runData.SetSetup(sstr);
// get/set sample
sstr = "n/a";
if (nxs_file->HasDataset("/run/sample/name"))
sstr = nxs_file->template GetDataset<std::string>("/run/sample/name").GetData()[0];
runData.SetSample(sstr);
// get/set orientation
runData.SetOrientation("??");
// get/set time resolution (ns)
dval = PMUSR_UNDEFINED;
sstr = "n/a";
factor = 1.0;
if (nxs_file->HasDataset("/run/histogram_data_1/resolution")) {
auto res_ds = nxs_file->template GetDataset<int>("/run/histogram_data_1/resolution");
dval = res_ds.GetData()[0];
if (res_ds.HasAttribute("units")) {
try {
sstr = std::any_cast<std::string>(res_ds.GetAttribute("units"));
} catch (const std::bad_any_cast&) {
std::cerr << std::endl << "**WARNING** ReadNexusFileIdf1: resolution 'units' attribute has unexpected type." << std::endl;
}
}
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("/run/start_time"))
sstr = nxs_file->template GetDataset<std::string>("/run/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("/run/stop_time"))
sstr = nxs_file->template GetDataset<std::string>("/run/stop_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("/run/instrument/detector/deadtimes")) {
std::vector<float> dt;
dt = nxs_file->template GetDataset<float>("/run/instrument/detector/deadtimes").GetData();
runData.SetDeadTimeParam(dt);
}
if (nxs_file->HasDataset("/run/instrument/beam/frames_good")) {
ival = nxs_file->template GetDataset<int>("/run/instrument/beam/frames_good").GetData()[0];
runData.SetNumberOfGoodFrames(ival);
}
// data with its metadata
if (nxs_file->HasDataset("/run/histogram_data_1/counts")) {
int t0_bin{-1}, fgb{-1}, lgb{-1}, noOfHistos{-1}, histoLength{-1};
auto count_ds = nxs_file->template GetDataset<int>("/run/histogram_data_1/counts");
auto count = count_ds.GetData();
// get all necessary attributes
auto castIntAttr = [](const std::any& val, const std::string& name) -> int {
try {
return std::any_cast<int>(val);
} catch (const std::bad_any_cast&) {
try {
// Attribute may be stored as vector<int> when HDF4 attr_count > 1
return std::any_cast<std::vector<int>>(val)[0];
} catch (const std::bad_any_cast&) {
std::cerr << std::endl << "**WARNING** ReadNexusFileIdf1: counts attribute '" << name
<< "' has unexpected type; defaulting to -1." << std::endl;
return -1;
// get/set temperature
dval = PMUSR_UNDEFINED;
sstr = "n/a";
if (nxs_file->HasDataset("/run/sample/temperature")) {
auto tmp_ds = nxs_file->template GetDataset<float>("/run/sample/temperature");
dval = tmp_ds.GetData()[0];
if (tmp_ds.HasAttribute("units")) {
try {
sstr = std::any_cast<std::string>(tmp_ds.GetAttribute("units"));
} catch (const std::bad_any_cast&) {
std::cerr << std::endl << "**WARNING** ReadNexusFileIdf1: temperature 'units' attribute has unexpected type." << std::endl;
}
}
}
};
if (count_ds.HasAttribute("t0_bin"))
t0_bin = castIntAttr(count_ds.GetAttribute("t0_bin"), "t0_bin");
if (count_ds.HasAttribute("first_good_bin"))
fgb = castIntAttr(count_ds.GetAttribute("first_good_bin"), "first_good_bin");
if (count_ds.HasAttribute("last_good_bin"))
lgb = castIntAttr(count_ds.GetAttribute("last_good_bin"), "last_good_bin");
if (count_ds.HasAttribute("number"))
noOfHistos = castIntAttr(count_ds.GetAttribute("number"), "number");
if (count_ds.HasAttribute("length"))
histoLength = castIntAttr(count_ds.GetAttribute("length"), "length");
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;
if (sstr == "Celcius")
dval += 273.16;
}
runData.SetTemperature(0, dval, 0.0);
@@ -689,8 +555,13 @@ Bool_t PRunDataHandler::ReadNexusFileIdf1(T& nxs_file)
if (nxs_file->HasDataset("/run/sample/magnetic_field")) {
auto mag_ds = nxs_file->template GetDataset<float>("/run/sample/magnetic_field");
dval = mag_ds.GetData()[0];
if (mag_ds.HasAttribute("units"))
sstr = std::any_cast<std::string>(mag_ds.GetAttribute("units"));
if (mag_ds.HasAttribute("units")) {
try {
sstr = std::any_cast<std::string>(mag_ds.GetAttribute("units"));
} catch (const std::bad_any_cast&) {
std::cerr << std::endl << "**WARNING** ReadNexusFileIdf1: magnetic_field 'units' attribute has unexpected type." << std::endl;
}
}
if (sstr == "Tesla")
factor = 1.0e4;
}
@@ -728,8 +599,13 @@ Bool_t PRunDataHandler::ReadNexusFileIdf1(T& nxs_file)
if (nxs_file->HasDataset("/run/histogram_data_1/resolution")) {
auto res_ds = nxs_file->template GetDataset<int>("/run/histogram_data_1/resolution");
dval = res_ds.GetData()[0];
if (res_ds.HasAttribute("units"))
sstr = std::any_cast<std::string>(res_ds.GetAttribute("units"));
if (res_ds.HasAttribute("units")) {
try {
sstr = std::any_cast<std::string>(res_ds.GetAttribute("units"));
} catch (const std::bad_any_cast&) {
std::cerr << std::endl << "**WARNING** ReadNexusFileIdf1: resolution 'units' attribute has unexpected type." << std::endl;
}
}
if ((sstr == "picoseconds") || (sstr == "pico.seconds"))
factor = 1.0e-3; // ps -> ns
}
@@ -766,7 +642,7 @@ Bool_t PRunDataHandler::ReadNexusFileIdf1(T& nxs_file)
runData.SetDeadTimeParam(dt);
}
if (nxs_file->HasDataset("/run/instrument/beam/frames_good")) {
ival = nxs_file->template GetDataset<float>("/run/instrument/beam/frames_good").GetData()[0];
ival = nxs_file->template GetDataset<int>("/run/instrument/beam/frames_good").GetData()[0];
runData.SetNumberOfGoodFrames(ival);
}
@@ -776,16 +652,30 @@ Bool_t PRunDataHandler::ReadNexusFileIdf1(T& nxs_file)
auto count_ds = nxs_file->template GetDataset<int>("/run/histogram_data_1/counts");
auto count = count_ds.GetData();
// get all necessary attributes
auto castIntAttr = [](const std::any& val, const std::string& name) -> int {
try {
return std::any_cast<int>(val);
} catch (const std::bad_any_cast&) {
try {
// Attribute may be stored as vector<int> when HDF4 attr_count > 1
return std::any_cast<std::vector<int>>(val)[0];
} catch (const std::bad_any_cast&) {
std::cerr << std::endl << "**WARNING** ReadNexusFileIdf1: counts attribute '" << name
<< "' has unexpected type; defaulting to -1." << std::endl;
return -1;
}
}
};
if (count_ds.HasAttribute("t0_bin"))
t0_bin = std::any_cast<int>(count_ds.GetAttribute("t0_bin"));
t0_bin = castIntAttr(count_ds.GetAttribute("t0_bin"), "t0_bin");
if (count_ds.HasAttribute("first_good_bin"))
fgb = std::any_cast<int>(count_ds.GetAttribute("first_good_bin"));
fgb = castIntAttr(count_ds.GetAttribute("first_good_bin"), "first_good_bin");
if (count_ds.HasAttribute("last_good_bin"))
lgb = std::any_cast<int>(count_ds.GetAttribute("last_good_bin"));
lgb = castIntAttr(count_ds.GetAttribute("last_good_bin"), "last_good_bin");
if (count_ds.HasAttribute("number"))
noOfHistos = std::any_cast<int>(count_ds.GetAttribute("number"));
noOfHistos = castIntAttr(count_ds.GetAttribute("number"), "number");
if (count_ds.HasAttribute("length"))
histoLength = std::any_cast<int>(count_ds.GetAttribute("length"));
histoLength = castIntAttr(count_ds.GetAttribute("length"), "length");
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;
@@ -871,148 +761,95 @@ Bool_t PRunDataHandler::ReadNexusFileIdf2(T& nxs_file)
ival = nxs_file->template GetDataset<int>("/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/detector_1/dead_time")) {
std::vector<float> dt;
dt = nxs_file->template GetDataset<float>("/raw_data_1/instrument/detector_1/dead_time").GetData();
runData.SetDeadTimeParam(dt);
}
if (nxs_file->HasDataset("/raw_data_1/good_frames")) {
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}, noOfPeriods{-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;
// 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;
}
noOfPeriods = dims[0];
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()) != noOfPeriods*noOfHistos*histoLength) {
std::cerr << std::endl << "**ERROR** PNeXus data size error! count.size()=" << count.size() << ", #periods=" << noOfPeriods << ", #histos=" << noOfHistos << ", length=" << histoLength << "." << std::endl;
return false;
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);
}
// fill dataSet
PDoubleVector data;
for (int i=0; i<noOfPeriods; i++) {
for (int j=0; j<noOfHistos; j++) {
dataSet.Clear();
dataSet.SetHistoNo(i*10000+j+1); // i.e. histo numbers start with 1
dataSet.SetTimeZeroBin(t0_bin);
dataSet.SetFirstGoodBin(fgb);
dataSet.SetLastGoodBin(lgb);
for (int k=0; k<histoLength; k++)
data.push_back(count[i*noOfHistos*histoLength+j*histoLength+k]);
dataSet.SetData(data);
runData.SetDataSet(dataSet);
data.clear();
}
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
@@ -1028,7 +865,7 @@ Bool_t PRunDataHandler::ReadNexusFileIdf2(T& nxs_file)
// 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};
int t0_bin{-1}, fgb{-1}, lgb{-1}, noOfPeriods{-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();
@@ -1036,6 +873,7 @@ Bool_t PRunDataHandler::ReadNexusFileIdf2(T& nxs_file)
std::cerr << std::endl << "**ERROR** PNeXus data dimension error! dims.size()=" << dims.size() << ", expecting == 3." << std::endl;
return false;
}
noOfPeriods = dims[0];
noOfHistos = dims[1];
histoLength = dims[2];
// get all necessary attributes
@@ -1045,24 +883,26 @@ Bool_t PRunDataHandler::ReadNexusFileIdf2(T& nxs_file)
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;
if (static_cast<int>(count.size()) != noOfPeriods*noOfHistos*histoLength) {
std::cerr << std::endl << "**ERROR** PNeXus data size error! count.size()=" << count.size() << ", #periods=" << noOfPeriods << ", #histos=" << noOfHistos << ", length=" << histoLength << "." << std::endl;
return false;
}
// 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();
for (int i=0; i<noOfPeriods; i++) {
for (int j=0; j<noOfHistos; j++) {
dataSet.Clear();
dataSet.SetHistoNo(i*10000+j+1); // i.e. histo numbers start with 1
dataSet.SetTimeZeroBin(t0_bin);
dataSet.SetFirstGoodBin(fgb);
dataSet.SetLastGoodBin(lgb);
for (int k=0; k<histoLength; k++)
data.push_back(count[i*noOfHistos*histoLength+j*histoLength+k]);
dataSet.SetData(data);
runData.SetDataSet(dataSet);
data.clear();
}
}
// keep run name from the msr-file