10 Commits

11 changed files with 504 additions and 391 deletions

View File

@ -5,7 +5,7 @@ if (CMAKE_VERSION GREATER_EQUAL 3.12)
cmake_policy(SET CMP0075 NEW) cmake_policy(SET CMP0075 NEW)
endif (CMAKE_VERSION GREATER_EQUAL 3.12) endif (CMAKE_VERSION GREATER_EQUAL 3.12)
project(musrfit VERSION 1.7.2 LANGUAGES C CXX) project(musrfit VERSION 1.7.4 LANGUAGES C CXX)
#--- musrfit specific options ------------------------------------------------- #--- musrfit specific options -------------------------------------------------
option(nexus "build optional NeXus support. Needed for ISIS" OFF) option(nexus "build optional NeXus support. Needed for ISIS" OFF)

View File

@ -12,6 +12,17 @@ or
https://bitbucket.org/muonspin/musrfit/commits/all https://bitbucket.org/muonspin/musrfit/commits/all
Release of V1.7.4, 2021/06/16
=============================
allow in asymmetry fits #forward groups != #backward groups
Release of V1.7.3, 2021/06/01
=============================
making musrfit Apple Silicon M1 ready. Currently there is still an open issue
with NeXus (HDF4 only).
Release of V1.7.2, 2021/04/16 Release of V1.7.2, 2021/04/16
============================= =============================

View File

@ -6334,16 +6334,7 @@ Bool_t PMsrHandler::CheckHistoGrouping()
{ {
Bool_t result = true; Bool_t result = true;
for (UInt_t i=0; i<fRuns.size(); i++) { for (UInt_t i=0; i<fRuns.size(); i++) {
if (fRuns[i].GetFitType() == MSR_FITTYPE_ASYM || fRuns[i].GetFitType() == MSR_FITTYPE_BNMR) {
if (fRuns[i].GetForwardHistoNoSize() != fRuns[i].GetBackwardHistoNoSize()) {
std::cerr << std::endl << ">> PMsrHandler::CheckHistoGrouping: **ERROR** # of forward histos != # of backward histos.";
std::cerr << std::endl << ">> Run #" << i+1;
std::cerr << std::endl;
result = false;
break;
}
}
// check grouping entries are not identical, e.g. forward 1 1 2 // check grouping entries are not identical, e.g. forward 1 1 2
if (fRuns[i].GetForwardHistoNoSize() > 1) { if (fRuns[i].GetForwardHistoNoSize() > 1) {
for (UInt_t j=0; j<fRuns[i].GetForwardHistoNoSize(); j++) { for (UInt_t j=0; j<fRuns[i].GetForwardHistoNoSize(); j++) {

View File

@ -602,17 +602,7 @@ Bool_t PRunAsymmetry::PrepareData()
return false; return false;
} }
} }
if (forwardHistoNo.size() != backwardHistoNo.size()) {
std::cerr << std::endl << ">> PRunAsymmetry::PrepareData(): **PANIC ERROR**:";
std::cerr << std::endl << ">> # of forward histograms different from # of backward histograms.";
std::cerr << std::endl << ">> Will quit :-(";
std::cerr << std::endl;
// clean up
forwardHistoNo.clear();
backwardHistoNo.clear();
return false;
}
// keep the time resolution in (us) // keep the time resolution in (us)
fTimeResolution = runData->GetTimeResolution()/1.0e3; fTimeResolution = runData->GetTimeResolution()/1.0e3;
std::cout.precision(10); std::cout.precision(10);
@ -626,11 +616,13 @@ Bool_t PRunAsymmetry::PrepareData()
// keep the histo of each group at this point (addruns handled below) // keep the histo of each group at this point (addruns handled below)
std::vector<PDoubleVector> forward, backward; std::vector<PDoubleVector> forward, backward;
forward.resize(forwardHistoNo.size()); // resize to number of groups forward.resize(forwardHistoNo.size()); // resize to number of groups
backward.resize(backwardHistoNo.size()); // resize to numer of groups
for (UInt_t i=0; i<forwardHistoNo.size(); i++) { for (UInt_t i=0; i<forwardHistoNo.size(); i++) {
forward[i].resize(runData->GetDataBin(forwardHistoNo[i])->size()); forward[i].resize(runData->GetDataBin(forwardHistoNo[i])->size());
backward[i].resize(runData->GetDataBin(backwardHistoNo[i])->size());
forward[i] = *runData->GetDataBin(forwardHistoNo[i]); forward[i] = *runData->GetDataBin(forwardHistoNo[i]);
}
backward.resize(backwardHistoNo.size()); // resize to number of groups
for (UInt_t i=0; i<backwardHistoNo.size(); i++) {
backward[i].resize(runData->GetDataBin(backwardHistoNo[i])->size());
backward[i] = *runData->GetDataBin(backwardHistoNo[i]); backward[i] = *runData->GetDataBin(backwardHistoNo[i]);
} }
@ -676,9 +668,11 @@ Bool_t PRunAsymmetry::PrepareData()
// set forward/backward histo data of the first group // set forward/backward histo data of the first group
fForward.resize(forward[0].size()); fForward.resize(forward[0].size());
fBackward.resize(backward[0].size());
for (UInt_t i=0; i<fForward.size(); i++) { for (UInt_t i=0; i<fForward.size(); i++) {
fForward[i] = forward[0][i]; fForward[i] = forward[0][i];
}
fBackward.resize(backward[0].size());
for (UInt_t i=0; i<fBackward.size(); i++) {
fBackward[i] = backward[0][i]; fBackward[i] = backward[0][i];
} }
@ -781,7 +775,21 @@ Bool_t PRunAsymmetry::PrepareData()
*/ */
Bool_t PRunAsymmetry::SubtractFixBkg() Bool_t PRunAsymmetry::SubtractFixBkg()
{ {
if (fRunInfo->GetBkgFix(0) == PMUSR_UNDEFINED) {
std::cerr << "PRunAsymmetry::SubtractFixBkg(): **ERROR** no fixed bkg for forward set. Will do nothing here." << std::endl;
return false;
}
if (fRunInfo->GetBkgFix(1) == PMUSR_UNDEFINED) {
std::cerr << "PRunAsymmetry::SubtractFixBkg(): **ERROR** no fixed bkg for backward set. Will do nothing here." << std::endl;
std::cerr << " you need an entry like:" << std::endl;
std::cerr << " backgr.fix 2 3" << std::endl;
std::cerr << " i.e. two entries for forward and backward." << std::endl;
return false;
}
Double_t dval; Double_t dval;
for (UInt_t i=0; i<fForward.size(); i++) { for (UInt_t i=0; i<fForward.size(); i++) {
// keep the error, and make sure that the bin is NOT empty // keep the error, and make sure that the bin is NOT empty
if (fForward[i] != 0.0) if (fForward[i] != 0.0)
@ -1005,8 +1013,8 @@ Bool_t PRunAsymmetry::PrepareFitData()
Double_t asym; Double_t asym;
Double_t f, b, ef, eb; Double_t f, b, ef, eb;
// fill data time start, and step // fill data time start, and step
// data start at data_start-t0 shifted by (pack-1)/2 // data start time = (binStart - 0.5) + pack/2 - t0, with pack and binStart used as double
fData.SetDataTimeStart(fTimeResolution*(static_cast<Double_t>(fGoodBins[0])-fT0s[0]+static_cast<Double_t>(fPacking-1)/2.0)); fData.SetDataTimeStart(fTimeResolution*((static_cast<Double_t>(fGoodBins[0])-0.5) + static_cast<Double_t>(fPacking)/2.0 - static_cast<Double_t>(fT0s[0])));
fData.SetDataTimeStep(fTimeResolution*static_cast<Double_t>(fPacking)); fData.SetDataTimeStep(fTimeResolution*static_cast<Double_t>(fPacking));
for (UInt_t i=0; i<noOfBins; i++) { for (UInt_t i=0; i<noOfBins; i++) {
// to make the formulae more readable // to make the formulae more readable
@ -1207,8 +1215,8 @@ Bool_t PRunAsymmetry::PrepareViewData(PRawRunData* runData, UInt_t histoNo[2])
Double_t asym; Double_t asym;
Double_t f, b, ef, eb, alpha = 1.0, beta = 1.0; Double_t f, b, ef, eb, alpha = 1.0, beta = 1.0;
// set data time start, and step // set data time start, and step
// data start at data_start-t0 // data start time = (binStart - 0.5) + pack/2 - t0, with pack and binStart used as double
fData.SetDataTimeStart(fTimeResolution*(static_cast<Double_t>(start[0])-t0[0]+static_cast<Double_t>(packing-1)/2.0)); fData.SetDataTimeStart(fTimeResolution*((static_cast<Double_t>(start[0])-0.5) + static_cast<Double_t>(packing)/2.0 - static_cast<Double_t>(t0[0])));
fData.SetDataTimeStep(fTimeResolution*static_cast<Double_t>(packing)); fData.SetDataTimeStep(fTimeResolution*static_cast<Double_t>(packing));
// get the proper alpha and beta // get the proper alpha and beta
@ -1586,8 +1594,8 @@ Bool_t PRunAsymmetry::PrepareRRFViewData(PRawRunData* runData, UInt_t histoNo[2]
} }
// set data time start, and step // set data time start, and step
// data start at data_start-t0 // data start time = (binStart - 0.5) + pack/2 - t0, with pack and binStart used as double
fData.SetDataTimeStart(fTimeResolution*(start[0]-t0[0]+static_cast<Double_t>(packing-1)/2.0)); fData.SetDataTimeStart(fTimeResolution*((static_cast<Double_t>(start[0])-0.5) + static_cast<Double_t>(packing)/2.0 - static_cast<Double_t>(t0[0])));
fData.SetDataTimeStep(fTimeResolution*static_cast<Double_t>(packing)); fData.SetDataTimeStep(fTimeResolution*static_cast<Double_t>(packing));
// ------------------------------------------------------------ // ------------------------------------------------------------
@ -1663,7 +1671,7 @@ Bool_t PRunAsymmetry::PrepareRRFViewData(PRawRunData* runData, UInt_t histoNo[2]
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
/** /**
* <p>Get the proper t0 for the single histogram run. * <p>Get the proper t0 for the single histogram run.
* -# the t0 vector size = number of detectors (grouping) for forward. * -# the t0 vector size = number of detectors (grouping) for forward + backward.
* -# initialize t0's with -1 * -# initialize t0's with -1
* -# fill t0's from RUN block * -# fill t0's from RUN block
* -# if t0's are missing (i.e. t0 == -1), try to fill from the GLOBAL block. * -# if t0's are missing (i.e. t0 == -1), try to fill from the GLOBAL block.
@ -1684,7 +1692,11 @@ Bool_t PRunAsymmetry::GetProperT0(PRawRunData* runData, PMsrGlobalBlock *globalB
// feed all T0's // feed all T0's
// first init T0's, T0's are stored as (forward T0, backward T0, etc.) // first init T0's, T0's are stored as (forward T0, backward T0, etc.)
fT0s.clear(); fT0s.clear();
fT0s.resize(2*forwardHistoNo.size()); // this strange fT0 size estimate is needed in case #forw histos != #back histos
size_t size = 2*forwardHistoNo.size();
if (backwardHistoNo.size() > forwardHistoNo.size())
size = 2*backwardHistoNo.size();
fT0s.resize(size);
for (UInt_t i=0; i<fT0s.size(); i++) { for (UInt_t i=0; i<fT0s.size(); i++) {
fT0s[i] = -1.0; fT0s[i] = -1.0;
} }
@ -1751,6 +1763,8 @@ Bool_t PRunAsymmetry::GetProperT0(PRawRunData* runData, PMsrGlobalBlock *globalB
std::cerr << std::endl; std::cerr << std::endl;
return false; return false;
} }
}
for (UInt_t i=0; i<backwardHistoNo.size(); i++) {
if ((fT0s[2*i+1] < 0) || (fT0s[2*i+1] > static_cast<Int_t>(runData->GetDataBin(backwardHistoNo[i])->size()))) { if ((fT0s[2*i+1] < 0) || (fT0s[2*i+1] > static_cast<Int_t>(runData->GetDataBin(backwardHistoNo[i])->size()))) {
std::cerr << std::endl << ">> PRunAsymmetry::PrepareData(): **ERROR** t0 data bin (" << fT0s[2*i+1] << ") doesn't make any sense!"; std::cerr << std::endl << ">> PRunAsymmetry::PrepareData(): **ERROR** t0 data bin (" << fT0s[2*i+1] << ") doesn't make any sense!";
std::cerr << std::endl << ">> backwardHistoNo " << backwardHistoNo[i]; std::cerr << std::endl << ">> backwardHistoNo " << backwardHistoNo[i];

View File

@ -640,6 +640,7 @@ Bool_t PRunAsymmetryBNMR::PrepareData()
return false; return false;
} }
} }
/* //as35
if (forwardHistoNo.size() != backwardHistoNo.size()) { if (forwardHistoNo.size() != backwardHistoNo.size()) {
std::cerr << std::endl << ">> PRunAsymmetryBNMR::PrepareData(): **PANIC ERROR**:"; std::cerr << std::endl << ">> PRunAsymmetryBNMR::PrepareData(): **PANIC ERROR**:";
std::cerr << std::endl << ">> # of forward histograms different from # of backward histograms."; std::cerr << std::endl << ">> # of forward histograms different from # of backward histograms.";
@ -650,7 +651,8 @@ Bool_t PRunAsymmetryBNMR::PrepareData()
backwardHistoNo.clear(); backwardHistoNo.clear();
return false; return false;
} }
*/ //as35
// keep the time resolution in (s) // keep the time resolution in (s)
fTimeResolution = runData->GetTimeResolution()/1.0e3; fTimeResolution = runData->GetTimeResolution()/1.0e3;
std::cout.precision(10); std::cout.precision(10);
@ -664,11 +666,13 @@ Bool_t PRunAsymmetryBNMR::PrepareData()
// keep the histo of each group at this point (addruns handled below) // keep the histo of each group at this point (addruns handled below)
std::vector<PDoubleVector> forward, backward; std::vector<PDoubleVector> forward, backward;
forward.resize(forwardHistoNo.size()); // resize to number of groups forward.resize(forwardHistoNo.size()); // resize to number of groups
backward.resize(backwardHistoNo.size()); // resize to numer of groups
for (UInt_t i=0; i<forwardHistoNo.size(); i++) { for (UInt_t i=0; i<forwardHistoNo.size(); i++) {
forward[i].resize(runData->GetDataBin(forwardHistoNo[i])->size()); forward[i].resize(runData->GetDataBin(forwardHistoNo[i])->size());
backward[i].resize(runData->GetDataBin(backwardHistoNo[i])->size());
forward[i] = *runData->GetDataBin(forwardHistoNo[i]); forward[i] = *runData->GetDataBin(forwardHistoNo[i]);
}
backward.resize(backwardHistoNo.size()); // resize to number of groups
for (UInt_t i=0; i<backwardHistoNo.size(); i++) {
backward[i].resize(runData->GetDataBin(backwardHistoNo[i])->size());
backward[i] = *runData->GetDataBin(backwardHistoNo[i]); backward[i] = *runData->GetDataBin(backwardHistoNo[i]);
} }
@ -712,15 +716,18 @@ Bool_t PRunAsymmetryBNMR::PrepareData()
} }
} }
// set forward/backward histo data of the first group // set forward histo data of the first group
fForwardp.resize(forward[0].size()); fForwardp.resize(forward[0].size());
fBackwardp.resize(backward[0].size());
fForwardm.resize(forward[0].size()); fForwardm.resize(forward[0].size());
fBackwardm.resize(backward[0].size());
for (UInt_t i=0; i<fForwardp.size(); i++) { for (UInt_t i=0; i<fForwardp.size(); i++) {
fForwardp[i] = forward[0][i]; fForwardp[i] = forward[0][i];
fBackwardp[i] = backward[0][i];
fForwardm[i] = forward[1][i]; fForwardm[i] = forward[1][i];
}
// set backward histo data of the first group
fBackwardp.resize(backward[0].size());
fBackwardm.resize(backward[0].size());
for (UInt_t i=0; i<fBackwardp.size(); i++) {
fBackwardp[i] = backward[0][i];
fBackwardm[i] = backward[1][i]; fBackwardm[i] = backward[1][i];
} }
@ -1529,7 +1536,11 @@ Bool_t PRunAsymmetryBNMR::GetProperT0(PRawRunData* runData, PMsrGlobalBlock *glo
// feed all T0's // feed all T0's
// first init T0's, T0's are stored as (forward T0, backward T0, etc.) // first init T0's, T0's are stored as (forward T0, backward T0, etc.)
fT0s.clear(); fT0s.clear();
fT0s.resize(2*forwardHistoNo.size()); // this strange fT0 size estimate is needed in case #forw histos != #back histos
size_t size = 2*forwardHistoNo.size();
if (backwardHistoNo.size() > forwardHistoNo.size())
size = 2*backwardHistoNo.size();
fT0s.resize(size);
for (UInt_t i=0; i<fT0s.size(); i++) { for (UInt_t i=0; i<fT0s.size(); i++) {
fT0s[i] = -1.0; fT0s[i] = -1.0;
} }
@ -1596,6 +1607,8 @@ Bool_t PRunAsymmetryBNMR::GetProperT0(PRawRunData* runData, PMsrGlobalBlock *glo
std::cerr << std::endl; std::cerr << std::endl;
return false; return false;
} }
}
for (UInt_t i=0; i<backwardHistoNo.size(); i++) {
if ((fT0s[2*i+1] < 0) || (fT0s[2*i+1] > static_cast<Int_t>(runData->GetDataBin(backwardHistoNo[i])->size()))) { if ((fT0s[2*i+1] < 0) || (fT0s[2*i+1] > static_cast<Int_t>(runData->GetDataBin(backwardHistoNo[i])->size()))) {
std::cerr << std::endl << ">> PRunAsymmetryBNMR::PrepareData(): **ERROR** t0 data bin (" << fT0s[2*i+1] << ") doesn't make any sense!"; std::cerr << std::endl << ">> PRunAsymmetryBNMR::PrepareData(): **ERROR** t0 data bin (" << fT0s[2*i+1] << ") doesn't make any sense!";
std::cerr << std::endl << ">> backwardHistoNo " << backwardHistoNo[i]; std::cerr << std::endl << ">> backwardHistoNo " << backwardHistoNo[i];

View File

@ -584,16 +584,6 @@ Bool_t PRunAsymmetryRRF::PrepareData()
return false; return false;
} }
} }
if (forwardHistoNo.size() != backwardHistoNo.size()) {
std::cerr << std::endl << ">> PRunAsymmetryRRF::PrepareData(): **PANIC ERROR**:";
std::cerr << std::endl << ">> # of forward histograms different from # of backward histograms.";
std::cerr << std::endl << ">> Will quit :-(";
std::cerr << std::endl;
// clean up
forwardHistoNo.clear();
backwardHistoNo.clear();
return false;
}
// keep the time resolution in (us) // keep the time resolution in (us)
fTimeResolution = runData->GetTimeResolution()/1.0e3; fTimeResolution = runData->GetTimeResolution()/1.0e3;
@ -608,11 +598,13 @@ Bool_t PRunAsymmetryRRF::PrepareData()
// keep the histo of each group at this point (addruns handled below) // keep the histo of each group at this point (addruns handled below)
std::vector<PDoubleVector> forward, backward; std::vector<PDoubleVector> forward, backward;
forward.resize(forwardHistoNo.size()); // resize to number of groups forward.resize(forwardHistoNo.size()); // resize to number of groups
backward.resize(backwardHistoNo.size()); // resize to numer of groups
for (UInt_t i=0; i<forwardHistoNo.size(); i++) { for (UInt_t i=0; i<forwardHistoNo.size(); i++) {
forward[i].resize(runData->GetDataBin(forwardHistoNo[i])->size()); forward[i].resize(runData->GetDataBin(forwardHistoNo[i])->size());
backward[i].resize(runData->GetDataBin(backwardHistoNo[i])->size());
forward[i] = *runData->GetDataBin(forwardHistoNo[i]); forward[i] = *runData->GetDataBin(forwardHistoNo[i]);
}
backward.resize(backwardHistoNo.size()); // resize to number of groups
for (UInt_t i=0; i<backwardHistoNo.size(); i++) {
backward[i].resize(runData->GetDataBin(backwardHistoNo[i])->size());
backward[i] = *runData->GetDataBin(backwardHistoNo[i]); backward[i] = *runData->GetDataBin(backwardHistoNo[i]);
} }
@ -1281,7 +1273,11 @@ Bool_t PRunAsymmetryRRF::GetProperT0(PRawRunData* runData, PMsrGlobalBlock *glob
// feed all T0's // feed all T0's
// first init T0's, T0's are stored as (forward T0, backward T0, etc.) // first init T0's, T0's are stored as (forward T0, backward T0, etc.)
fT0s.clear(); fT0s.clear();
fT0s.resize(2*forwardHistoNo.size()); // this strange fT0 size estimate is needed in case #forw histos != #back histos
size_t size = 2*forwardHistoNo.size();
if (backwardHistoNo.size() > forwardHistoNo.size())
size = 2*backwardHistoNo.size();
fT0s.resize(size);
for (UInt_t i=0; i<fT0s.size(); i++) { for (UInt_t i=0; i<fT0s.size(); i++) {
fT0s[i] = -1.0; fT0s[i] = -1.0;
} }
@ -1348,6 +1344,8 @@ Bool_t PRunAsymmetryRRF::GetProperT0(PRawRunData* runData, PMsrGlobalBlock *glob
std::cerr << std::endl; std::cerr << std::endl;
return false; return false;
} }
}
for (UInt_t i=0; i<backwardHistoNo.size(); i++) {
if ((fT0s[2*i+1] < 0) || (fT0s[2*i+1] > static_cast<Int_t>(runData->GetDataBin(backwardHistoNo[i])->size()))) { if ((fT0s[2*i+1] < 0) || (fT0s[2*i+1] > static_cast<Int_t>(runData->GetDataBin(backwardHistoNo[i])->size()))) {
std::cerr << std::endl << ">> PRunAsymmetryRRF::PrepareData(): **ERROR** t0 data bin (" << fT0s[2*i+1] << ") doesn't make any sense!"; std::cerr << std::endl << ">> PRunAsymmetryRRF::PrepareData(): **ERROR** t0 data bin (" << fT0s[2*i+1] << ") doesn't make any sense!";
std::cerr << std::endl << ">> backwardHistoNo " << backwardHistoNo[i]; std::cerr << std::endl << ">> backwardHistoNo " << backwardHistoNo[i];

View File

@ -604,8 +604,8 @@ Bool_t PRunMuMinus::PrepareFitData(PRawRunData* runData, const UInt_t histoNo)
Int_t t0 = static_cast<Int_t>(fT0s[0]); Int_t t0 = static_cast<Int_t>(fT0s[0]);
Double_t value = 0.0; Double_t value = 0.0;
// data start at data_start-t0 // data start at data_start-t0
// time shifted so that packing is included correctly, i.e. t0 == t0 after packing // data start time = (binStart - 0.5) + pack/2 - t0, with pack and binStart used as double
fData.SetDataTimeStart(fTimeResolution*(static_cast<Double_t>(fGoodBins[0])-static_cast<Double_t>(t0)+static_cast<Double_t>(fPacking-1)/2.0)); fData.SetDataTimeStart(fTimeResolution*((static_cast<Double_t>(fGoodBins[0])-0.5) + static_cast<Double_t>(fPacking)/2.0 - static_cast<Double_t>(t0)));
fData.SetDataTimeStep(fTimeResolution*fPacking); fData.SetDataTimeStep(fTimeResolution*fPacking);
for (Int_t i=fGoodBins[0]; i<fGoodBins[1]; i++) { for (Int_t i=fGoodBins[0]; i<fGoodBins[1]; i++) {
if (fPacking == 1) { if (fPacking == 1) {
@ -710,9 +710,8 @@ Bool_t PRunMuMinus::PrepareRawViewData(PRawRunData* runData, const UInt_t histoN
// everything looks fine, hence fill data set // everything looks fine, hence fill data set
Int_t t0 = static_cast<Int_t>(fT0s[0]); Int_t t0 = static_cast<Int_t>(fT0s[0]);
Double_t value = 0.0; Double_t value = 0.0;
// data start at data_start-t0 // data start time = (binStart - 0.5) + pack/2 - t0, with pack and binStart used as double
// time shifted so that packing is included correctly, i.e. t0 == t0 after packing fData.SetDataTimeStart(fTimeResolution*((static_cast<Double_t>(start)-0.5) + static_cast<Double_t>(packing)/2.0 - static_cast<Double_t>(t0)));
fData.SetDataTimeStart(fTimeResolution*(static_cast<Double_t>(start)-static_cast<Double_t>(t0)+static_cast<Double_t>(packing-1)/2.0));
fData.SetDataTimeStep(fTimeResolution*packing); fData.SetDataTimeStep(fTimeResolution*packing);
for (Int_t i=start; i<end; i++) { for (Int_t i=start; i<end; i++) {

View File

@ -888,7 +888,7 @@ Bool_t PRunSingleHisto::PrepareFitData(PRawRunData* runData, const UInt_t histoN
normalizer = fPacking * (fTimeResolution * 1.0e3); // fTimeResolution us->ns normalizer = fPacking * (fTimeResolution * 1.0e3); // fTimeResolution us->ns
// data start at data_start-t0 // data start at data_start-t0
// time shifted so that packing is included correctly, i.e. t0 == t0 after packing // time shifted so that packing is included correctly, i.e. t0 == t0 after packing
fData.SetDataTimeStart(fTimeResolution*(static_cast<Double_t>(fGoodBins[0])-static_cast<Double_t>(t0)+static_cast<Double_t>(fPacking-1)/2.0)); fData.SetDataTimeStart(fTimeResolution*((static_cast<Double_t>(fGoodBins[0])-0.5) + static_cast<Double_t>(fPacking)/2.0 - static_cast<Double_t>(t0)));
fData.SetDataTimeStep(fTimeResolution*fPacking); fData.SetDataTimeStep(fTimeResolution*fPacking);
for (Int_t i=fGoodBins[0]; i<fGoodBins[1]; i++) { for (Int_t i=fGoodBins[0]; i<fGoodBins[1]; i++) {
if (fPacking == 1) { if (fPacking == 1) {
@ -991,9 +991,8 @@ Bool_t PRunSingleHisto::PrepareRawViewData(PRawRunData* runData, const UInt_t hi
// everything looks fine, hence fill data set // everything looks fine, hence fill data set
Int_t t0 = static_cast<Int_t>(fT0s[0]); Int_t t0 = static_cast<Int_t>(fT0s[0]);
Double_t value = 0.0; Double_t value = 0.0;
// data start at data_start-t0 // data start time = (binStart - 0.5) + pack/2 - t0, with pack and binStart used as double
// time shifted so that packing is included correctly, i.e. t0 == t0 after packing fData.SetDataTimeStart(fTimeResolution*((static_cast<Double_t>(start)-0.5) + static_cast<Double_t>(packing)/2.0 - static_cast<Double_t>(t0)));
fData.SetDataTimeStart(fTimeResolution*(static_cast<Double_t>(start)-static_cast<Double_t>(t0)+static_cast<Double_t>(packing-1)/2.0));
fData.SetDataTimeStep(fTimeResolution*packing); fData.SetDataTimeStep(fTimeResolution*packing);
for (Int_t i=start; i<end; i++) { for (Int_t i=start; i<end; i++) {
@ -1247,8 +1246,8 @@ Bool_t PRunSingleHisto::PrepareViewData(PRawRunData* runData, const UInt_t histo
Double_t rrf_val = 0.0; Double_t rrf_val = 0.0;
Double_t time = 0.0; Double_t time = 0.0;
// data start at data_start-t0 shifted by (pack-1)/2 // data start time = (binStart - 0.5) + pack/2 - t0, with pack and binStart used as double
fData.SetDataTimeStart(fTimeResolution*(static_cast<Double_t>(start)-static_cast<Double_t>(t0)+static_cast<Double_t>(packing-1)/2.0)); fData.SetDataTimeStart(fTimeResolution*((static_cast<Double_t>(start)-0.5) + static_cast<Double_t>(packing)/2.0 - static_cast<Double_t>(t0)));
fData.SetDataTimeStep(fTimeResolution*packing); fData.SetDataTimeStep(fTimeResolution*packing);
// data is always normalized to (per nsec!!) // data is always normalized to (per nsec!!)
@ -1257,7 +1256,8 @@ Bool_t PRunSingleHisto::PrepareViewData(PRawRunData* runData, const UInt_t histo
for (Int_t i=start; i<end; i++) { for (Int_t i=start; i<end; i++) {
if (((i-start) % packing == 0) && (i != start)) { // fill data if (((i-start) % packing == 0) && (i != start)) { // fill data
value *= dataNorm; value *= dataNorm;
time = ((static_cast<Double_t>(i)-static_cast<Double_t>(packing-1)/2.0)-t0)*fTimeResolution; // since the packing counter is already at the end of the bin, the time needs be shifted back by pack*time_resolution
time = (((static_cast<Double_t>(i)-0.5) + static_cast<Double_t>(packing)/2.0 - static_cast<Double_t>(t0)))*fTimeResolution - static_cast<Double_t>(packing)*fTimeResolution;
expval = TMath::Exp(+time/tau)/N0; expval = TMath::Exp(+time/tau)/N0;
fData.AppendValue(-1.0+expval*(value-bkg)); fData.AppendValue(-1.0+expval*(value-bkg));
fData.AppendErrorValue(expval*TMath::Sqrt(value*dataNorm)); fData.AppendErrorValue(expval*TMath::Sqrt(value*dataNorm));
@ -1316,7 +1316,7 @@ Bool_t PRunSingleHisto::PrepareViewData(PRawRunData* runData, const UInt_t histo
// calculate theory // calculate theory
Double_t theoryValue; Double_t theoryValue;
UInt_t size = fForward.size()/packing; UInt_t size = fForward.size()/packing;
Int_t factor = 8; // 8 times more points for the theory (if fTheoAsData == false) const Int_t factor = 8; // 8 times more points for the theory (if fTheoAsData == false)
UInt_t rebinRRF = 0; UInt_t rebinRRF = 0;
if (wRRF == 0) { // no RRF if (wRRF == 0) { // no RRF

View File

@ -447,7 +447,8 @@ int dump_header_mud(const std::string fileName, const std::string fileFormat)
// start time // start time
time_t tval; time_t tval;
struct tm *dt; struct tm *dt;
success = MUD_getTimeBegin( fh, (UINT32*)&tval ); success = MUD_getTimeBegin( fh, &val );
tval = static_cast<time_t>(val);
if (success) { if (success) {
dt = localtime(static_cast<const time_t*>(&tval)); dt = localtime(static_cast<const time_t*>(&tval));
assert(dt); assert(dt);
@ -457,7 +458,8 @@ int dump_header_mud(const std::string fileName, const std::string fileFormat)
std::cout << std::endl << "Run Start Time : ???"; std::cout << std::endl << "Run Start Time : ???";
} }
// stop time // stop time
success = MUD_getTimeEnd( fh, (UINT32*)&tval ); success = MUD_getTimeEnd( fh, &val );
tval = static_cast<time_t>(val);
if (success) { if (success) {
dt = localtime(static_cast<const time_t*>(&tval)); dt = localtime(static_cast<const time_t*>(&tval));
assert(dt); assert(dt);

View File

@ -422,9 +422,7 @@ MUD_read( FILE* fin, MUD_IO_OPT io_opt )
*/ */
if( ( pos = ftell( fin ) ) == EOF ) return( NULL ); if( ( pos = ftell( fin ) ) == EOF ) return( NULL );
if( fread( &size, 4, 1, fin ) == 0 ) return( NULL ); if( fread( &size, 4, 1, fin ) == 0 ) return( NULL );
#if !defined(__arm64)
bdecode_4( &size, &size ); /* byte ordering !!! */ bdecode_4( &size, &size ); /* byte ordering !!! */
#endif // !defined(__arm64)
if( fseek( fin, pos, 0 ) == EOF ) return( NULL ); if( fseek( fin, pos, 0 ) == EOF ) return( NULL );
#ifdef DEBUG #ifdef DEBUG

View File

@ -818,10 +818,10 @@ PNeXusDetector2::PNeXusDetector2()
fNoOfBins = -1; fNoOfBins = -1;
fT0Tag = -1; fT0Tag = -1;
fT0 = 0; fT0 = nullptr;
fFirstGoodBin = 0; fFirstGoodBin = nullptr;
fLastGoodBin = 0; fLastGoodBin = nullptr;
fHisto = 0; fHisto = nullptr;
} }
//------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------
@ -837,19 +837,19 @@ PNeXusDetector2::~PNeXusDetector2()
if (fT0) { if (fT0) {
delete [] fT0; delete [] fT0;
fT0 = 0; fT0 = nullptr;
} }
if (fFirstGoodBin) { if (fFirstGoodBin) {
delete [] fFirstGoodBin; delete [] fFirstGoodBin;
fFirstGoodBin = 0; fFirstGoodBin = nullptr;
} }
if (fLastGoodBin) { if (fLastGoodBin) {
delete [] fLastGoodBin; delete [] fLastGoodBin;
fLastGoodBin = 0; fLastGoodBin = nullptr;
} }
if (fHisto) { if (fHisto) {
delete [] fHisto; delete [] fHisto;
fHisto = 0; fHisto = nullptr;
} }
} }
@ -919,10 +919,16 @@ bool PNeXusDetector2::IsValid(bool strict)
*/ */
int PNeXusDetector2::GetT0(int idxp, int idxs) int PNeXusDetector2::GetT0(int idxp, int idxs)
{ {
int result = -1; int result = -1;
if (fT0Tag == 1) { // there is only ONE t0 present
if (fT0 != nullptr)
result = *fT0;
return result;
}
if ((idxp < 0) && (idxs < 0)) { // assumption: there is only ONE t0 for all spectra if ((idxp < 0) && (idxs < 0)) { // assumption: there is only ONE t0 for all spectra
if (fT0 != 0) { if (fT0 != nullptr) {
result = *fT0; result = *fT0;
} }
} else if ((idxp < 0) && (idxs >= 0)) { // assumption: t0's are represented as t0[ns] } else if ((idxp < 0) && (idxs >= 0)) { // assumption: t0's are represented as t0[ns]
@ -1031,17 +1037,24 @@ int PNeXusDetector2::GetFirstGoodBin(int idxp, int idxs)
{ {
int result = -1; int result = -1;
if (fT0Tag == 1) { // there is only ONE t0 present
if (fT0 != nullptr)
result = *fFirstGoodBin;
return result;
}
if ((idxp < 0) && (idxs < 0)) { // assumption: there is only ONE t0 for all spectra if ((idxp < 0) && (idxs < 0)) { // assumption: there is only ONE t0 for all spectra
if (fFirstGoodBin != 0) { if (fFirstGoodBin != nullptr) {
result = *fFirstGoodBin; result = *fFirstGoodBin;
} }
} else if ((idxp < 0) && (idxs >= 0)) { // assumptions: fgb's are represented as fgb[ns] } else if ((idxp < 0) && (idxs >= 0)) { // assumptions: fgb's are represented as fgb[ns]
if (idxs < fNoOfSpectra) { if ((idxs < fNoOfSpectra) && (fFirstGoodBin != nullptr)) {
result = *(fFirstGoodBin+idxs); result = *(fFirstGoodBin+idxs);
} }
} else if ((idxp >= 0) && (idxs >= 0)) { // assumption: fgb's are represented as fgb[np][ns] } else if ((idxp >= 0) && (idxs >= 0)) { // assumption: fgb's are represented as fgb[np][ns]
if ((idxp < fNoOfPeriods) || (idxs < fNoOfSpectra)) { if ((idxp < fNoOfPeriods) || (idxs < fNoOfSpectra)) {
result = *(fFirstGoodBin+idxp*fNoOfSpectra+idxs); if (fFirstGoodBin != nullptr)
result = *(fFirstGoodBin+idxp*fNoOfSpectra+idxs);
} }
} else { } else {
result = -1; result = -1;
@ -1141,17 +1154,24 @@ int PNeXusDetector2::GetLastGoodBin(int idxp, int idxs)
{ {
int result = -1; int result = -1;
if (fT0Tag == 1) { // there is only ONE t0 present
if (fT0 != nullptr)
result = *fLastGoodBin;
return result;
}
if ((idxp < 0) && (idxs < 0)) { // assumption: there is only ONE t0 for all spectra if ((idxp < 0) && (idxs < 0)) { // assumption: there is only ONE t0 for all spectra
if (fLastGoodBin != 0) { if (fLastGoodBin != nullptr) {
result = *fLastGoodBin; result = *fLastGoodBin;
} }
} else if ((idxp < 0) && (idxs >= 0)) { // assumption: lgb's are represented as lgb[ns] } else if ((idxp < 0) && (idxs >= 0)) { // assumption: lgb's are represented as lgb[ns]
if (idxs < fNoOfSpectra) { if ((idxs < fNoOfSpectra) && (fLastGoodBin != nullptr)) {
result = *(fLastGoodBin+idxs); result = *(fLastGoodBin+idxs);
} }
} else if ((idxp >= 0) && (idxs >= 0)) { // assumption: lgb's are represented as lgb[np][ns] } else if ((idxp >= 0) && (idxs >= 0)) { // assumption: lgb's are represented as lgb[np][ns]
if ((idxp < fNoOfPeriods) || (idxs < fNoOfSpectra)) { if ((idxp < fNoOfPeriods) || (idxs < fNoOfSpectra)) {
result = *(fLastGoodBin+idxp*fNoOfSpectra+idxs); if (fLastGoodBin != nullptr)
result = *(fLastGoodBin+idxp*fNoOfSpectra+idxs);
} }
} else { } else {
result = -1; result = -1;
@ -3398,6 +3418,14 @@ int PNeXus::ReadFileIdf2()
return NX_ERROR; return NX_ERROR;
} }
// beamline
if (SearchInGroup("beamline", "name", nxname, nxclass, dataType)) {
if (!ErrorHandler(NXopendata(fFileHandle, "beamline"), PNEXUS_OPEN_DATA_ERROR, "couldn't open 'beamline' data in NXentry!")) return NX_ERROR;
if (!ErrorHandler(GetStringData(str), PNEXUS_GET_DATA_ERROR, "couldn't read 'beamline' data in NXentry!")) return NX_ERROR;
if (!ErrorHandler(NXclosedata(fFileHandle), PNEXUS_CLOSE_DATA_ERROR, "couldn't close 'beamline' data in NXentry!")) return NX_ERROR;
fNxEntry2->GetInstrument()->GetBeamline()->SetName(str);
}
// definition // definition
if (!ErrorHandler(NXopendata(fFileHandle, "definition"), PNEXUS_OPEN_DATA_ERROR, "couldn't open 'definition' data in NXentry!")) return NX_ERROR; if (!ErrorHandler(NXopendata(fFileHandle, "definition"), PNEXUS_OPEN_DATA_ERROR, "couldn't open 'definition' data in NXentry!")) return NX_ERROR;
if (!ErrorHandler(GetStringData(str), PNEXUS_GET_DATA_ERROR, "couldn't read 'definition' data in NXentry!")) return NX_ERROR; if (!ErrorHandler(GetStringData(str), PNEXUS_GET_DATA_ERROR, "couldn't read 'definition' data in NXentry!")) return NX_ERROR;
@ -3576,26 +3604,37 @@ int PNeXus::ReadFileIdf2()
// close group NXsource // close group NXsource
NXclosegroup(fFileHandle); NXclosegroup(fFileHandle);
// open group NXbeamline // open group NXbeamline
if (!ErrorHandler(NXopengroup(fFileHandle, "beamline", "NXbeamline"), PNEXUS_GROUP_OPEN_ERROR, "couldn't open NeXus subgroup beamline in NXinstrument!")) return NX_ERROR; if (SearchInGroup("beamline", "name", nxname, nxclass, dataType)) {
if (!ErrorHandler(NXopengroup(fFileHandle, "beamline", "NXbeamline"), PNEXUS_GROUP_OPEN_ERROR, "couldn't open NeXus subgroup beamline in NXinstrument!")) return NX_ERROR;
// beamline name // beamline name
if (!ErrorHandler(NXopendata(fFileHandle, "beamline"), PNEXUS_OPEN_DATA_ERROR, "couldn't open 'beamline' data in NXbeamline!")) return NX_ERROR; if (!ErrorHandler(NXopendata(fFileHandle, "beamline"), PNEXUS_OPEN_DATA_ERROR, "couldn't open 'beamline' data in NXbeamline!")) return NX_ERROR;
if (!ErrorHandler(GetStringData(str), PNEXUS_GET_DATA_ERROR, "couldn't read 'beamline' data in NXbeamline!")) return NX_ERROR; if (!ErrorHandler(GetStringData(str), PNEXUS_GET_DATA_ERROR, "couldn't read 'beamline' data in NXbeamline!")) return NX_ERROR;
if (!ErrorHandler(NXclosedata(fFileHandle), PNEXUS_CLOSE_DATA_ERROR, "couldn't close 'beamline' data in NXbeamline!")) return NX_ERROR; if (!ErrorHandler(NXclosedata(fFileHandle), PNEXUS_CLOSE_DATA_ERROR, "couldn't close 'beamline' data in NXbeamline!")) return NX_ERROR;
fNxEntry2->GetInstrument()->GetBeamline()->SetName(str); fNxEntry2->GetInstrument()->GetBeamline()->SetName(str);
// close group NXbeamline // close group NXbeamline
NXclosegroup(fFileHandle); NXclosegroup(fFileHandle);
} else {
std::cerr << "**WARNING** in class NXinstrument the object NXbeamline with name 'beamline' is missing!" << std::endl;
std::cerr << " Complain at the facility where you got this data file from!" << std::endl;
}
// open group NXdetector // open group NXdetector in instrument (NXinstrument)
if (!ErrorHandler(NXopengroup(fFileHandle, "detector_1", "NXdetector"), PNEXUS_GROUP_OPEN_ERROR, "couldn't open NeXus subgroup detector_1 in NXinstrument!")) return NX_ERROR; if (!ErrorHandler(NXopengroup(fFileHandle, "detector_1", "NXdetector"), PNEXUS_GROUP_OPEN_ERROR, "couldn't open NeXus subgroup detector_1 in NXinstrument!")) return NX_ERROR;
// description // description
if (!ErrorHandler(NXopendata(fFileHandle, "description"), PNEXUS_OPEN_DATA_ERROR, "couldn't open 'description' data in NXdetector!")) return NX_ERROR; if (SearchInGroup("description", "name", nxname, nxclass, dataType)) {
if (!ErrorHandler(GetStringData(str), PNEXUS_GET_DATA_ERROR, "couldn't read 'description' data in NXdetector!")) return NX_ERROR; if (!ErrorHandler(NXopendata(fFileHandle, "description"), PNEXUS_OPEN_DATA_ERROR, "couldn't open 'description' data in NXdetector!")) return NX_ERROR;
if (!ErrorHandler(NXclosedata(fFileHandle), PNEXUS_CLOSE_DATA_ERROR, "couldn't close 'description' data in NXdetector!")) return NX_ERROR; if (!ErrorHandler(GetStringData(str), PNEXUS_GET_DATA_ERROR, "couldn't read 'description' data in NXdetector!")) return NX_ERROR;
fNxEntry2->GetInstrument()->GetDetector()->SetDescription(str); if (!ErrorHandler(NXclosedata(fFileHandle), PNEXUS_CLOSE_DATA_ERROR, "couldn't close 'description' data in NXdetector!")) return NX_ERROR;
fNxEntry2->GetInstrument()->GetDetector()->SetDescription(str);
} else {
std::cerr << "**WARNING** in class NXdetector to object NX_CHAR with name 'description' is missing!" << std::endl;
std::cerr << " Complain at the facility where you got this data file from!" << std::endl;
}
// get the time resolution. This is a little bit complicated since it is either present as 'histogram_resolution' or needs to be extracted from the 'raw_time' vector // get the time resolution. This is a little bit complicated since it is either present as 'histogram_resolution' or needs to be extracted from the 'raw_time' vector
// 1st check if 'histogram_resolution' is found // 1st check if 'histogram_resolution' is found
@ -3607,10 +3646,10 @@ int PNeXus::ReadFileIdf2()
fNxEntry2->GetInstrument()->GetDetector()->SetTimeResolution((double)fval, str); fNxEntry2->GetInstrument()->GetDetector()->SetTimeResolution((double)fval, str);
} else if (SearchInGroup("resolution", "name", nxname, nxclass, dataType)) { // 2nd check if 'resolution' is found } else if (SearchInGroup("resolution", "name", nxname, nxclass, dataType)) { // 2nd check if 'resolution' is found
if (!ErrorHandler(NXopendata(fFileHandle, "resolution"), PNEXUS_OPEN_DATA_ERROR, "couldn't open 'resolution' data in NXdetector!")) return NX_ERROR; if (!ErrorHandler(NXopendata(fFileHandle, "resolution"), PNEXUS_OPEN_DATA_ERROR, "couldn't open 'resolution' data in NXdetector!")) return NX_ERROR;
if (!ErrorHandler(NXgetdata(fFileHandle, &fval), PNEXUS_GET_DATA_ERROR, "couldn't read 'resolution' data in NXdetector!")) return NX_ERROR; if (!ErrorHandler(NXgetdata(fFileHandle, &ival), PNEXUS_GET_DATA_ERROR, "couldn't read 'resolution' data in NXdetector!")) return NX_ERROR;
if (!ErrorHandler(GetStringAttr("units", str), PNEXUS_GET_ATTR_ERROR, "couldn't read time resolution units in NXdetector!")) return NX_ERROR; if (!ErrorHandler(GetStringAttr("units", str), PNEXUS_GET_ATTR_ERROR, "couldn't read time resolution units in NXdetector!")) return NX_ERROR;
if (!ErrorHandler(NXclosedata(fFileHandle), PNEXUS_CLOSE_DATA_ERROR, "couldn't close 'resolution' data in NXdetector!")) return NX_ERROR; if (!ErrorHandler(NXclosedata(fFileHandle), PNEXUS_CLOSE_DATA_ERROR, "couldn't close 'resolution' data in NXdetector!")) return NX_ERROR;
fNxEntry2->GetInstrument()->GetDetector()->SetTimeResolution((double)fval, str); fNxEntry2->GetInstrument()->GetDetector()->SetTimeResolution((double)ival, str);
} else { // 3nd 'histogram_resolution' is not present, hence extract the time resolution from the 'raw_time' vector } else { // 3nd 'histogram_resolution' is not present, hence extract the time resolution from the 'raw_time' vector
if (!ErrorHandler(NXopendata(fFileHandle, "raw_time"), PNEXUS_OPEN_DATA_ERROR, "couldn't open 'raw_time' data in NXdetector!")) return NX_ERROR; if (!ErrorHandler(NXopendata(fFileHandle, "raw_time"), PNEXUS_OPEN_DATA_ERROR, "couldn't open 'raw_time' data in NXdetector!")) return NX_ERROR;
std::vector<double> rawTime; std::vector<double> rawTime;
@ -3626,6 +3665,51 @@ int PNeXus::ReadFileIdf2()
// check the dimensions of 'counts' // check the dimensions of 'counts'
if (!ErrorHandler(NXgetinfo(fFileHandle, &rank, dims, &type), PNEXUS_GET_META_INFO_ERROR, "couldn't get 'counts' info in NXdetector!")) return NX_ERROR; if (!ErrorHandler(NXgetinfo(fFileHandle, &rank, dims, &type), PNEXUS_GET_META_INFO_ERROR, "couldn't get 'counts' info in NXdetector!")) return NX_ERROR;
// check if last_good_bin, first_good_bin, and t0_bins are defined as attributes
int attLen = 1, attType = NX_INT32;
if (SearchAttrInData("first_good_bin", attLen, attType)) {
char cstr[1204];
memset(cstr, '\0', sizeof(cstr));
strncpy(cstr, "first_good_bin", sizeof(cstr));
status = NXgetattr(fFileHandle, cstr, (void*)&ival, &attLen, &attType);
fNxEntry2->GetInstrument()->GetDetector()->SetT0Tag(1); // a single set for t0, fgb, lgb is likely given
int *i_data_ptr = new int;
*i_data_ptr = ival;
if (!fNxEntry2->GetInstrument()->GetDetector()->SetFirstGoodBin(i_data_ptr)) {
std::cerr << std::endl << ">> **ERROR** " << fNxEntry2->GetInstrument()->GetDetector()->GetErrorMsg() << std::endl;
return NX_ERROR;
}
}
if (SearchAttrInData("last_good_bin", attLen, attType)) {
char cstr[1204];
memset(cstr, '\0', sizeof(cstr));
strncpy(cstr, "last_good_bin", sizeof(cstr));
status = NXgetattr(fFileHandle, cstr, (void*)&ival, &attLen, &attType);
fNxEntry2->GetInstrument()->GetDetector()->SetT0Tag(1); // a single set for t0, fgb, lgb is likely given
int *i_data_ptr = new int;
*i_data_ptr = ival;
if (!fNxEntry2->GetInstrument()->GetDetector()->SetLastGoodBin(i_data_ptr)) {
std::cerr << std::endl << ">> **ERROR** " << fNxEntry2->GetInstrument()->GetDetector()->GetErrorMsg() << std::endl;
return NX_ERROR;
}
}
if (SearchAttrInData("t0_bin", attLen, attType)) {
char cstr[1204];
memset(cstr, '\0', sizeof(cstr));
strncpy(cstr, "t0_bin", sizeof(cstr));
status = NXgetattr(fFileHandle, cstr, (void*)&ival, &attLen, &attType);
fNxEntry2->GetInstrument()->GetDetector()->SetT0Tag(1); // a single set for t0, fgb, lgb is likely given
int *i_data_ptr = new int;
*i_data_ptr = ival;
if (!fNxEntry2->GetInstrument()->GetDetector()->SetT0(i_data_ptr)) {
std::cerr << std::endl << ">> **ERROR** " << fNxEntry2->GetInstrument()->GetDetector()->GetErrorMsg() << std::endl;
return NX_ERROR;
}
}
// calculate the needed size // calculate the needed size
size = dims[0]; size = dims[0];
for (int i=1; i<rank; i++) for (int i=1; i<rank; i++)
@ -3713,320 +3797,323 @@ int PNeXus::ReadFileIdf2()
if (!ErrorHandler(NXclosedata(fFileHandle), PNEXUS_CLOSE_DATA_ERROR, "couldn't close 'spectrum_index' data in NXdetector!")) return NX_ERROR; if (!ErrorHandler(NXclosedata(fFileHandle), PNEXUS_CLOSE_DATA_ERROR, "couldn't close 'spectrum_index' data in NXdetector!")) return NX_ERROR;
// handle t0's // only handle t0, fgb, lgb, if they are not already set as an attribute of /raw_data_1/instrument/detector_1/counts
if (SearchInGroup("time_zero_bin", "name", nxname, nxclass, dataType)) { // check for 'time_zero_bin' if (fNxEntry2->GetInstrument()->GetDetector()->GetT0Tag() == -1) {
if (!ErrorHandler(NXopendata(fFileHandle, "time_zero_bin"), PNEXUS_OPEN_DATA_ERROR, "couldn't open 'time_zero_bin' data in NXdetector!")) return NX_ERROR; // handle t0's
if (SearchInGroup("time_zero_bin", "name", nxname, nxclass, dataType)) { // check for 'time_zero_bin'
if (!ErrorHandler(NXopendata(fFileHandle, "time_zero_bin"), PNEXUS_OPEN_DATA_ERROR, "couldn't open 'time_zero_bin' data in NXdetector!")) return NX_ERROR;
// check the dimensions of the 'time_zero_bin' vector // check the dimensions of the 'time_zero_bin' vector
if (!ErrorHandler(NXgetinfo(fFileHandle, &rank, dims, &type), PNEXUS_GET_META_INFO_ERROR, "couldn't get 'time_zero_bin' info in NXdetector!")) return NX_ERROR; if (!ErrorHandler(NXgetinfo(fFileHandle, &rank, dims, &type), PNEXUS_GET_META_INFO_ERROR, "couldn't get 'time_zero_bin' info in NXdetector!")) return NX_ERROR;
if ((rank == 1) && (dims[0] == 1)) { // single t0 entry if ((rank == 1) && (dims[0] == 1)) { // single t0 entry
fNxEntry2->GetInstrument()->GetDetector()->SetT0Tag(1); fNxEntry2->GetInstrument()->GetDetector()->SetT0Tag(1);
} else if ((rank == 1) && (dims[0] > 1)) { // t0 of the form t0[ns] } else if ((rank == 1) && (dims[0] > 1)) { // t0 of the form t0[ns]
fNxEntry2->GetInstrument()->GetDetector()->SetT0Tag(2); fNxEntry2->GetInstrument()->GetDetector()->SetT0Tag(2);
} else if (rank == 2) { // t0 of the form t0[np][ns] } else if (rank == 2) { // t0 of the form t0[np][ns]
fNxEntry2->GetInstrument()->GetDetector()->SetT0Tag(3); fNxEntry2->GetInstrument()->GetDetector()->SetT0Tag(3);
} else {
std::cerr << std::endl << ">> **ERROR** found 'time_zero_bin' info in NXdetector with rank=" << rank << ". Do not know how to handle." << std::endl;
return NX_ERROR;
}
// calculate the needed size
size = dims[0];
for (int i=1; i<rank; i++)
size *= dims[i];
noOfElements = size;
size *= GetDataSize(type);
// allocate locale memory to get the data
char *data_ptr = new char[size];
if (data_ptr == nullptr) {
return NX_ERROR;
}
// get the data
int *i_data_ptr = (int*) data_ptr;
int status = NXgetdata(fFileHandle, i_data_ptr);
if (status != NX_OK) {
return NX_ERROR;
}
if (!fNxEntry2->GetInstrument()->GetDetector()->SetT0(i_data_ptr)) {
std::cerr << std::endl << ">> **ERROR** " << fNxEntry2->GetInstrument()->GetDetector()->GetErrorMsg() << std::endl;
return NX_ERROR;
}
// clean up
if (data_ptr) {
delete [] data_ptr;
data_ptr = nullptr;
}
if (!ErrorHandler(NXclosedata(fFileHandle), PNEXUS_CLOSE_DATA_ERROR, "couldn't close 'time_zero_bin' data in NXdetector!")) return NX_ERROR;
} else if (SearchInGroup("time_zero", "name", nxname, nxclass, dataType)) { // check for 'time_zero'
if (!ErrorHandler(NXopendata(fFileHandle, "time_zero"), PNEXUS_OPEN_DATA_ERROR, "couldn't open 'time_zero' data in NXdetector!")) return NX_ERROR;
// check the dimensions of the 'time_zero' vector
if (!ErrorHandler(NXgetinfo(fFileHandle, &rank, dims, &type), PNEXUS_GET_META_INFO_ERROR, "couldn't get 'time_zero' info in NXdetector!")) return NX_ERROR;
if ((rank == 1) && (dims[0] == 1)) { // single t0 entry
fNxEntry2->GetInstrument()->GetDetector()->SetT0Tag(1);
} else if ((rank == 1) && (dims[0] > 1)) { // t0 of the form t0[ns]
fNxEntry2->GetInstrument()->GetDetector()->SetT0Tag(2);
} else if (rank == 2) { // t0 of the form t0[np][ns]
fNxEntry2->GetInstrument()->GetDetector()->SetT0Tag(3);
} else {
std::cerr << std::endl << ">> **ERROR** found 'time_zero' info in NXdetector with rank=" << rank << ". Do not know how to handle." << std::endl;
return NX_ERROR;
}
// calculate the needed size
size = dims[0];
for (int i=1; i<rank; i++)
size *= dims[i];
noOfElements = size;
size *= GetDataSize(type);
// allocate locale memory to get the data
char *data_ptr = new char[size];
if (data_ptr == nullptr) {
return NX_ERROR;
}
// get the data
float *f_data_ptr = (float*) data_ptr;
int status = NXgetdata(fFileHandle, f_data_ptr);
if (status != NX_OK) {
return NX_ERROR;
}
if (!ErrorHandler(GetStringAttr("units", str), PNEXUS_GET_ATTR_ERROR, "couldn't read 'time_zero' units in NXdetector!")) return NX_ERROR;
// Set T0's
// check that the necessary time resolution is present
if (fNxEntry2->GetInstrument()->GetDetector()->GetTimeResolution(str) == 0.0) {
std::cerr << std::endl << ">> **ERROR** trying to set T0's based on 'time_zero'. Need a valid time resolution to do so, but this is not given." << std::endl;
return NX_ERROR;
}
// set the t0's based on the t0 time stamp and the time resolution
int *pt0 = nullptr;
if (rank == 1) {
pt0 = new int;
*pt0 = (int)(*f_data_ptr / (float)fNxEntry2->GetInstrument()->GetDetector()->GetTimeResolution(str));
} else { // rank == 2
pt0 = new int[noOfElements];
for (int i=0; i<noOfElements; i++) {
*(pt0+i) = (int)(*(f_data_ptr+i) / (float)fNxEntry2->GetInstrument()->GetDetector()->GetTimeResolution(str));
}
}
if (!fNxEntry2->GetInstrument()->GetDetector()->SetT0(pt0)) {
std::cerr << std::endl << ">> **ERROR** " << fNxEntry2->GetInstrument()->GetDetector()->GetErrorMsg() << std::endl;
return NX_ERROR;
}
// clean up
if (data_ptr) {
delete [] data_ptr;
data_ptr = nullptr;
}
std::cerr << std::endl << ">> **WARNING** found only 'time_zero' will convert it to 'time_zero_bin' values" << std::endl;
if (!ErrorHandler(NXclosedata(fFileHandle), PNEXUS_CLOSE_DATA_ERROR, "couldn't close 'time_zero' data in NXdetector!")) return NX_ERROR;
} else { } else {
std::cerr << std::endl << ">> **ERROR** found 'time_zero_bin' info in NXdetector with rank=" << rank << ". Do not know how to handle." << std::endl; std::cerr << std::endl << ">> **WARNING** found neither 'time_zero_bin' nor 'time_zero' values ..." << std::endl;
return NX_ERROR;
} }
// calculate the needed size // handle first good bin
size = dims[0]; if (SearchInGroup("first_good_bin", "name", nxname, nxclass, dataType)) {
for (int i=1; i<rank; i++) if (!ErrorHandler(NXopendata(fFileHandle, "first_good_bin"), PNEXUS_OPEN_DATA_ERROR, "couldn't open 'first_good_bin' data in NXdetector!")) return NX_ERROR;
size *= dims[i];
noOfElements = size;
size *= GetDataSize(type);
// allocate locale memory to get the data // check the dimensions of the 'first_good_bin' vector
char *data_ptr = new char[size]; if (!ErrorHandler(NXgetinfo(fFileHandle, &rank, dims, &type), PNEXUS_GET_META_INFO_ERROR, "couldn't get 'first_good_bin' info in NXdetector!")) return NX_ERROR;
if (data_ptr == nullptr) {
return NX_ERROR;
}
// get the data // calculate the needed size
int *i_data_ptr = (int*) data_ptr; size = dims[0];
int status = NXgetdata(fFileHandle, i_data_ptr); for (int i=1; i<rank; i++)
if (status != NX_OK) { size *= dims[i];
return NX_ERROR; noOfElements = size;
} size *= GetDataSize(type);
if (!fNxEntry2->GetInstrument()->GetDetector()->SetT0(i_data_ptr)) { // allocate locale memory to get the data
std::cerr << std::endl << ">> **ERROR** " << fNxEntry2->GetInstrument()->GetDetector()->GetErrorMsg() << std::endl; char *data_ptr = new char[size];
return NX_ERROR; if (data_ptr == nullptr) {
} return NX_ERROR;
}
// clean up // get the data
if (data_ptr) { int *i_data_ptr = (int*) data_ptr;
delete [] data_ptr; int status = NXgetdata(fFileHandle, i_data_ptr);
data_ptr = nullptr; if (status != NX_OK) {
} return NX_ERROR;
}
if (!ErrorHandler(NXclosedata(fFileHandle), PNEXUS_CLOSE_DATA_ERROR, "couldn't close 'time_zero_bin' data in NXdetector!")) return NX_ERROR; if (!fNxEntry2->GetInstrument()->GetDetector()->SetFirstGoodBin(i_data_ptr)) {
} else if (SearchInGroup("time_zero", "name", nxname, nxclass, dataType)) { // check for 'time_zero' std::cerr << std::endl << ">> **ERROR** " << fNxEntry2->GetInstrument()->GetDetector()->GetErrorMsg() << std::endl;
if (!ErrorHandler(NXopendata(fFileHandle, "time_zero"), PNEXUS_OPEN_DATA_ERROR, "couldn't open 'time_zero' data in NXdetector!")) return NX_ERROR; return NX_ERROR;
// check the dimensions of the 'time_zero' vector }
if (!ErrorHandler(NXgetinfo(fFileHandle, &rank, dims, &type), PNEXUS_GET_META_INFO_ERROR, "couldn't get 'time_zero' info in NXdetector!")) return NX_ERROR;
if ((rank == 1) && (dims[0] == 1)) { // single t0 entry if (data_ptr) {
fNxEntry2->GetInstrument()->GetDetector()->SetT0Tag(1); delete [] data_ptr;
} else if ((rank == 1) && (dims[0] > 1)) { // t0 of the form t0[ns] data_ptr = nullptr;
fNxEntry2->GetInstrument()->GetDetector()->SetT0Tag(2); }
} else if (rank == 2) { // t0 of the form t0[np][ns]
fNxEntry2->GetInstrument()->GetDetector()->SetT0Tag(3); if (!ErrorHandler(NXclosedata(fFileHandle), PNEXUS_CLOSE_DATA_ERROR, "couldn't close 'first_good_bin' data in NXdetector!")) return NX_ERROR;
} else if (SearchInGroup("first_good_time", "name", nxname, nxclass, dataType)) {
if (!ErrorHandler(NXopendata(fFileHandle, "first_good_time"), PNEXUS_OPEN_DATA_ERROR, "couldn't open 'first_good_time' data in NXdetector!")) return NX_ERROR;
// check the dimensions of the 'first_good_time' vector
if (!ErrorHandler(NXgetinfo(fFileHandle, &rank, dims, &type), PNEXUS_GET_META_INFO_ERROR, "couldn't get 'first_good_time' info in NXdetector!")) return NX_ERROR;
// calculate the needed size
size = dims[0];
for (int i=1; i<rank; i++)
size *= dims[i];
noOfElements = size;
size *= GetDataSize(type);
// allocate locale memory to get the data
char *data_ptr = new char[size];
if (data_ptr == nullptr) {
return NX_ERROR;
}
// get the data
float *f_data_ptr = (float*) data_ptr;
int status = NXgetdata(fFileHandle, f_data_ptr);
if (status != NX_OK) {
return NX_ERROR;
}
// set the fgb's based on the fgb time stamp and the time resolution
int *p_fgb = nullptr;
if (rank == 1) {
p_fgb = new int;
*p_fgb = (int)(*f_data_ptr / (float)fNxEntry2->GetInstrument()->GetDetector()->GetTimeResolution(str));
} else { // rank == 2
p_fgb = new int[noOfElements];
for (int i=0; i<noOfElements; i++) {
*(p_fgb+i) = (int)(*(f_data_ptr+i) / (float)fNxEntry2->GetInstrument()->GetDetector()->GetTimeResolution(str));
}
}
if (!fNxEntry2->GetInstrument()->GetDetector()->SetFirstGoodBin(p_fgb)) {
std::cerr << std::endl << ">> **ERROR** " << fNxEntry2->GetInstrument()->GetDetector()->GetErrorMsg() << std::endl;
return NX_ERROR;
}
// clean up
if (p_fgb) {
delete [] p_fgb;
p_fgb = 0;
}
if (data_ptr) {
delete [] data_ptr;
data_ptr = nullptr;
}
if (!ErrorHandler(NXclosedata(fFileHandle), PNEXUS_CLOSE_DATA_ERROR, "couldn't close 'first_good_time' data in NXdetector!")) return NX_ERROR;
} else { } else {
std::cerr << std::endl << ">> **ERROR** found 'time_zero' info in NXdetector with rank=" << rank << ". Do not know how to handle." << std::endl; std::cerr << std::endl << ">> **WARNING** found neither 'first_good_bin' nor 'first_good_time' values ..." << std::endl;
return NX_ERROR;
} }
// calculate the needed size // handle last good bin
size = dims[0]; if (SearchInGroup("last_good_bin", "name", nxname, nxclass, dataType)) {
for (int i=1; i<rank; i++) if (!ErrorHandler(NXopendata(fFileHandle, "last_good_bin"), PNEXUS_OPEN_DATA_ERROR, "couldn't open 'last_good_bin' data in NXdetector!")) return NX_ERROR;
size *= dims[i];
noOfElements = size;
size *= GetDataSize(type);
// allocate locale memory to get the data // check the dimensions of the 'last_good_bin' vector
char *data_ptr = new char[size]; if (!ErrorHandler(NXgetinfo(fFileHandle, &rank, dims, &type), PNEXUS_GET_META_INFO_ERROR, "couldn't get 'last_good_bin' info in NXdetector!")) return NX_ERROR;
if (data_ptr == nullptr) {
return NX_ERROR;
}
// get the data // calculate the needed size
float *f_data_ptr = (float*) data_ptr; size = dims[0];
int status = NXgetdata(fFileHandle, f_data_ptr); for (int i=1; i<rank; i++)
if (status != NX_OK) { size *= dims[i];
return NX_ERROR; noOfElements = size;
} size *= GetDataSize(type);
if (!ErrorHandler(GetStringAttr("units", str), PNEXUS_GET_ATTR_ERROR, "couldn't read 'time_zero' units in NXdetector!")) return NX_ERROR; // allocate locale memory to get the data
char *data_ptr = new char[size];
// Set T0's if (data_ptr == nullptr) {
// check that the necessary time resolution is present return NX_ERROR;
if (fNxEntry2->GetInstrument()->GetDetector()->GetTimeResolution(str) == 0.0) {
std::cerr << std::endl << ">> **ERROR** trying to set T0's based on 'time_zero'. Need a valid time resolution to do so, but this is not given." << std::endl;
return NX_ERROR;
}
// set the t0's based on the t0 time stamp and the time resolution
int *pt0 = nullptr;
if (rank == 1) {
pt0 = new int;
*pt0 = (int)(*f_data_ptr / (float)fNxEntry2->GetInstrument()->GetDetector()->GetTimeResolution(str));
} else { // rank == 2
pt0 = new int[noOfElements];
for (int i=0; i<noOfElements; i++) {
*(pt0+i) = (int)(*(f_data_ptr+i) / (float)fNxEntry2->GetInstrument()->GetDetector()->GetTimeResolution(str));
} }
}
if (!fNxEntry2->GetInstrument()->GetDetector()->SetT0(pt0)) { // get the data
std::cerr << std::endl << ">> **ERROR** " << fNxEntry2->GetInstrument()->GetDetector()->GetErrorMsg() << std::endl; int *i_data_ptr = (int*) data_ptr;
return NX_ERROR; int status = NXgetdata(fFileHandle, i_data_ptr);
} if (status != NX_OK) {
return NX_ERROR;
// clean up
if (data_ptr) {
delete [] data_ptr;
data_ptr = nullptr;
}
std::cerr << std::endl << ">> **WARNING** found only 'time_zero' will convert it to 'time_zero_bin' values" << std::endl;
if (!ErrorHandler(NXclosedata(fFileHandle), PNEXUS_CLOSE_DATA_ERROR, "couldn't close 'time_zero' data in NXdetector!")) return NX_ERROR;
} else {
std::cerr << std::endl << ">> **WARNING** found neither 'time_zero_bin' nor 'time_zero' values ..." << std::endl;
}
// handle first good bin
if (SearchInGroup("first_good_bin", "name", nxname, nxclass, dataType)) {
if (!ErrorHandler(NXopendata(fFileHandle, "first_good_bin"), PNEXUS_OPEN_DATA_ERROR, "couldn't open 'first_good_bin' data in NXdetector!")) return NX_ERROR;
// check the dimensions of the 'first_good_bin' vector
if (!ErrorHandler(NXgetinfo(fFileHandle, &rank, dims, &type), PNEXUS_GET_META_INFO_ERROR, "couldn't get 'first_good_bin' info in NXdetector!")) return NX_ERROR;
// calculate the needed size
size = dims[0];
for (int i=1; i<rank; i++)
size *= dims[i];
noOfElements = size;
size *= GetDataSize(type);
// allocate locale memory to get the data
char *data_ptr = new char[size];
if (data_ptr == nullptr) {
return NX_ERROR;
}
// get the data
int *i_data_ptr = (int*) data_ptr;
int status = NXgetdata(fFileHandle, i_data_ptr);
if (status != NX_OK) {
return NX_ERROR;
}
if (!fNxEntry2->GetInstrument()->GetDetector()->SetFirstGoodBin(i_data_ptr)) {
std::cerr << std::endl << ">> **ERROR** " << fNxEntry2->GetInstrument()->GetDetector()->GetErrorMsg() << std::endl;
return NX_ERROR;
}
if (data_ptr) {
delete [] data_ptr;
data_ptr = nullptr;
}
if (!ErrorHandler(NXclosedata(fFileHandle), PNEXUS_CLOSE_DATA_ERROR, "couldn't close 'first_good_bin' data in NXdetector!")) return NX_ERROR;
} else if (SearchInGroup("first_good_time", "name", nxname, nxclass, dataType)) {
if (!ErrorHandler(NXopendata(fFileHandle, "first_good_time"), PNEXUS_OPEN_DATA_ERROR, "couldn't open 'first_good_time' data in NXdetector!")) return NX_ERROR;
// check the dimensions of the 'first_good_time' vector
if (!ErrorHandler(NXgetinfo(fFileHandle, &rank, dims, &type), PNEXUS_GET_META_INFO_ERROR, "couldn't get 'first_good_time' info in NXdetector!")) return NX_ERROR;
// calculate the needed size
size = dims[0];
for (int i=1; i<rank; i++)
size *= dims[i];
noOfElements = size;
size *= GetDataSize(type);
// allocate locale memory to get the data
char *data_ptr = new char[size];
if (data_ptr == nullptr) {
return NX_ERROR;
}
// get the data
float *f_data_ptr = (float*) data_ptr;
int status = NXgetdata(fFileHandle, f_data_ptr);
if (status != NX_OK) {
return NX_ERROR;
}
// set the fgb's based on the fgb time stamp and the time resolution
int *p_fgb = nullptr;
if (rank == 1) {
p_fgb = new int;
*p_fgb = (int)(*f_data_ptr / (float)fNxEntry2->GetInstrument()->GetDetector()->GetTimeResolution(str));
} else { // rank == 2
p_fgb = new int[noOfElements];
for (int i=0; i<noOfElements; i++) {
*(p_fgb+i) = (int)(*(f_data_ptr+i) / (float)fNxEntry2->GetInstrument()->GetDetector()->GetTimeResolution(str));
} }
}
if (!fNxEntry2->GetInstrument()->GetDetector()->SetFirstGoodBin(p_fgb)) { if (!fNxEntry2->GetInstrument()->GetDetector()->SetLastGoodBin(i_data_ptr)) {
std::cerr << std::endl << ">> **ERROR** " << fNxEntry2->GetInstrument()->GetDetector()->GetErrorMsg() << std::endl; std::cerr << std::endl << ">> **ERROR** " << fNxEntry2->GetInstrument()->GetDetector()->GetErrorMsg() << std::endl;
return NX_ERROR; return NX_ERROR;
}
// clean up
if (p_fgb) {
delete [] p_fgb;
p_fgb = 0;
}
if (data_ptr) {
delete [] data_ptr;
data_ptr = nullptr;
}
if (!ErrorHandler(NXclosedata(fFileHandle), PNEXUS_CLOSE_DATA_ERROR, "couldn't close 'first_good_time' data in NXdetector!")) return NX_ERROR;
} else {
std::cerr << std::endl << ">> **WARNING** found neither 'first_good_bin' nor 'first_good_time' values ..." << std::endl;
}
// handle last good bin
if (SearchInGroup("last_good_bin", "name", nxname, nxclass, dataType)) {
if (!ErrorHandler(NXopendata(fFileHandle, "last_good_bin"), PNEXUS_OPEN_DATA_ERROR, "couldn't open 'last_good_bin' data in NXdetector!")) return NX_ERROR;
// check the dimensions of the 'last_good_bin' vector
if (!ErrorHandler(NXgetinfo(fFileHandle, &rank, dims, &type), PNEXUS_GET_META_INFO_ERROR, "couldn't get 'last_good_bin' info in NXdetector!")) return NX_ERROR;
// calculate the needed size
size = dims[0];
for (int i=1; i<rank; i++)
size *= dims[i];
noOfElements = size;
size *= GetDataSize(type);
// allocate locale memory to get the data
char *data_ptr = new char[size];
if (data_ptr == nullptr) {
return NX_ERROR;
}
// get the data
int *i_data_ptr = (int*) data_ptr;
int status = NXgetdata(fFileHandle, i_data_ptr);
if (status != NX_OK) {
return NX_ERROR;
}
if (!fNxEntry2->GetInstrument()->GetDetector()->SetLastGoodBin(i_data_ptr)) {
std::cerr << std::endl << ">> **ERROR** " << fNxEntry2->GetInstrument()->GetDetector()->GetErrorMsg() << std::endl;
return NX_ERROR;
}
// clean up
if (data_ptr) {
delete [] data_ptr;
data_ptr = nullptr;
}
if (!ErrorHandler(NXclosedata(fFileHandle), PNEXUS_CLOSE_DATA_ERROR, "couldn't close 'last_good_bin' data in NXdetector!")) return NX_ERROR;
} else if (SearchInGroup("last_good_time", "name", nxname, nxclass, dataType)) {
if (!ErrorHandler(NXopendata(fFileHandle, "last_good_time"), PNEXUS_OPEN_DATA_ERROR, "couldn't open 'last_good_time' data in NXdetector!")) return NX_ERROR;
// check the dimensions of the 'last_good_time' vector
if (!ErrorHandler(NXgetinfo(fFileHandle, &rank, dims, &type), PNEXUS_GET_META_INFO_ERROR, "couldn't get 'last_good_time' info in NXdetector!")) return NX_ERROR;
// calculate the needed size
size = dims[0];
for (int i=1; i<rank; i++)
size *= dims[i];
noOfElements = size;
size *= GetDataSize(type);
// allocate locale memory to get the data
char *data_ptr = new char[size];
if (data_ptr == nullptr) {
return NX_ERROR;
}
// get the data
float *f_data_ptr = (float*) data_ptr;
int status = NXgetdata(fFileHandle, f_data_ptr);
if (status != NX_OK) {
return NX_ERROR;
}
// set the lgb's based on the lgb time stamp and the time resolution
int *p_lgb = nullptr;
if (rank == 1) {
p_lgb = new int;
*p_lgb = (int)(*f_data_ptr / (float)fNxEntry2->GetInstrument()->GetDetector()->GetTimeResolution(str));
} else { // rank == 2
p_lgb = new int[noOfElements];
for (int i=0; i<noOfElements; i++) {
*(p_lgb+i) = (int)(*(f_data_ptr+i) / (float)fNxEntry2->GetInstrument()->GetDetector()->GetTimeResolution(str));
} }
}
if (fNxEntry2->GetInstrument()->GetDetector()->SetFirstGoodBin(p_lgb)) { // clean up
std::cerr << std::endl << ">> **ERROR** " << fNxEntry2->GetInstrument()->GetDetector()->GetErrorMsg() << std::endl; if (data_ptr) {
return NX_ERROR; delete [] data_ptr;
} data_ptr = nullptr;
}
// clean up if (!ErrorHandler(NXclosedata(fFileHandle), PNEXUS_CLOSE_DATA_ERROR, "couldn't close 'last_good_bin' data in NXdetector!")) return NX_ERROR;
if (p_lgb) { } else if (SearchInGroup("last_good_time", "name", nxname, nxclass, dataType)) {
delete [] p_lgb; if (!ErrorHandler(NXopendata(fFileHandle, "last_good_time"), PNEXUS_OPEN_DATA_ERROR, "couldn't open 'last_good_time' data in NXdetector!")) return NX_ERROR;
p_lgb = 0;
}
if (data_ptr) {
delete [] data_ptr;
data_ptr = nullptr;
}
if (!ErrorHandler(NXclosedata(fFileHandle), PNEXUS_CLOSE_DATA_ERROR, "couldn't close 'last_good_time' data in NXdetector!")) return NX_ERROR; // check the dimensions of the 'last_good_time' vector
} else { if (!ErrorHandler(NXgetinfo(fFileHandle, &rank, dims, &type), PNEXUS_GET_META_INFO_ERROR, "couldn't get 'last_good_time' info in NXdetector!")) return NX_ERROR;
std::cerr << std::endl << ">> **WARNING** found neither 'last_good_bin' nor 'last_good_time' values ..." << std::endl;
// calculate the needed size
size = dims[0];
for (int i=1; i<rank; i++)
size *= dims[i];
noOfElements = size;
size *= GetDataSize(type);
// allocate locale memory to get the data
char *data_ptr = new char[size];
if (data_ptr == nullptr) {
return NX_ERROR;
}
// get the data
float *f_data_ptr = (float*) data_ptr;
int status = NXgetdata(fFileHandle, f_data_ptr);
if (status != NX_OK) {
return NX_ERROR;
}
// set the lgb's based on the lgb time stamp and the time resolution
int *p_lgb = nullptr;
if (rank == 1) {
p_lgb = new int;
*p_lgb = (int)(*f_data_ptr / (float)fNxEntry2->GetInstrument()->GetDetector()->GetTimeResolution(str));
} else { // rank == 2
p_lgb = new int[noOfElements];
for (int i=0; i<noOfElements; i++) {
*(p_lgb+i) = (int)(*(f_data_ptr+i) / (float)fNxEntry2->GetInstrument()->GetDetector()->GetTimeResolution(str));
}
}
if (fNxEntry2->GetInstrument()->GetDetector()->SetFirstGoodBin(p_lgb)) {
std::cerr << std::endl << ">> **ERROR** " << fNxEntry2->GetInstrument()->GetDetector()->GetErrorMsg() << std::endl;
return NX_ERROR;
}
// clean up
if (p_lgb) {
delete [] p_lgb;
p_lgb = 0;
}
if (data_ptr) {
delete [] data_ptr;
data_ptr = nullptr;
}
if (!ErrorHandler(NXclosedata(fFileHandle), PNEXUS_CLOSE_DATA_ERROR, "couldn't close 'last_good_time' data in NXdetector!")) return NX_ERROR;
} else {
std::cerr << std::endl << ">> **WARNING** found neither 'last_good_bin' nor 'last_good_time' values ..." << std::endl;
}
} }
// close group NXdetector // close group NXdetector