start implementing the NeXus write routines, needed by any2many.

This commit is contained in:
2026-02-07 08:05:42 +01:00
parent 4dcef1a835
commit 300c9200df
2 changed files with 49 additions and 21 deletions

View File

@@ -408,9 +408,9 @@ Bool_t PRunDataHandler::WriteData(TString fileName)
break;
case A2M_NEXUS:
if (fAny2ManyInfo->outFileName.Length() == 0)
success = WriteNexusFile(fileName);
success = WriteNexusFile(fAny2ManyInfo->outFormat, fileName);
else
success = WriteNexusFile(fAny2ManyInfo->outFileName);
success = WriteNexusFile(fAny2ManyInfo->outFormat, fAny2ManyInfo->outFileName);
break;
default:
break;
@@ -684,9 +684,9 @@ Bool_t PRunDataHandler::ReadWriteFilesList()
break;
case A2M_NEXUS:
if (fAny2ManyInfo->outFileName.Length() == 0)
success = WriteNexusFile();
success = WriteNexusFile(fAny2ManyInfo->outFormat);
else
success = WriteNexusFile(fAny2ManyInfo->outFileName);
success = WriteNexusFile(fAny2ManyInfo->outFormat, fAny2ManyInfo->outFileName);
break;
case A2M_MUD:
if (fAny2ManyInfo->outFileName.Length() == 0)
@@ -787,7 +787,7 @@ Bool_t PRunDataHandler::ReadWriteFilesList()
success = WritePsiBinFile(fln);
break;
case A2M_NEXUS:
success = WriteNexusFile(fln);
success = WriteNexusFile(fAny2ManyInfo->outFormat, fln);
break;
case A2M_MUD:
success = WriteMudFile(fln);
@@ -4706,7 +4706,7 @@ Bool_t PRunDataHandler::WriteRootFile(TString fln)
for (UInt_t i=0; i<fData[0].GetNoOfHistos(); i++) {
dataSet = fData[0].GetDataSet(i, false); // i.e. the false means, that i is the index and NOT the histo number
if (dataSet == nullptr) { // something is really wrong
std::cerr << std::endl << ">> PRunDataHandler::WriteNexusFile: **ERROR** Couldn't get data set (idx=0" << i << ")";
std::cerr << std::endl << ">> PRunDataHandler::WriteRootFile: **ERROR** Couldn't get data set (idx=0" << i << ")";
std::cerr << std::endl << ">> something is really wrong!" << std::endl;
return false;
}
@@ -4800,16 +4800,14 @@ Bool_t PRunDataHandler::WriteRootFile(TString fln)
/**
* <p> Write the nexus-file format.
*
* <b>return:</b>
* - true on successful writting,
* - otherwise false.
*
* \param fln file name. If empty, the routine will try to construct one
* \return true on successful writting, otherwise false.
*/
Bool_t PRunDataHandler::WriteNexusFile(TString fln)
Bool_t PRunDataHandler::WriteNexusFile(TString format, TString fln)
{
#ifdef PNEXUS_ENABLED
/* //as35
Bool_t ok = false;
fln = GenerateOutputFileName(fln, ".nxs", ok);
if (!ok)
@@ -4818,19 +4816,49 @@ Bool_t PRunDataHandler::WriteNexusFile(TString fln)
if (!fAny2ManyInfo->useStandardOutput)
std::cout << std::endl << ">> PRunDataHandler::WriteNexusFile(): writing a NeXus data file (" << fln.Data() << ") ... " << std::endl;
if (format.Contains("HDF4", TString::kIgnoreCase)) { // HDF4
#ifdef HAVE_HDF4
std::cerr << "**ERROR** not yet implemented!" << std::endl;
return false;
#endif
} else { // HDF5
try {
// create NeXus object
std::unique_ptr<PNeXus> nxs = std::make_unique<PNeXus>();
std::unique_ptr<nxH5::PNeXus> nxs = std::make_unique<nxH5::PNeXus>();
if (nxs == nullptr) {
std::cerr << std::endl << ">> PRunDataHandler::WriteNexusFile(): **ERROR** couldn't invoke the NeXus object." << std::endl;
return false;
}
if (fAny2ManyInfo->idf == 1) { // IDF V1
// set NeXus version
nxs->AddGroupAttribute("/", "NeXus_version", std::string("4.3.0"));
// set HDF5 version
nxs->AddGroupAttribute("/", "HDF_version", nxs->GetHdf5LibVersion());
// set file name
nxs->AddGroupAttribute("/", "file_name", std::string(fln.Data()));
// set IDF version
nxs->SetIdfVersion(fAny2ManyInfo->idf);
nxs->AddDataset<int>("/run/IDF_version", {(int)fAny2ManyInfo->idf}, {1}, H5::PredType::NATIVE_INT32);
} else { // IDF V2
// set IDF version
nxs->AddDataset<int>("/raw_data_1/IDF_version", {(int)fAny2ManyInfo->idf}, {1}, H5::PredType::NATIVE_INT32);
}
int result = nxs->WriteNexusFile(fln.Data(), fAny2ManyInfo->idf);
if (result != 0) {
std::cerr << std::endl << "**ERROR** PRunDataHandler::WriteNexusFile, fln=" << fln << std::endl;
return false;
}
} catch (const H5::Exception& e) {
std::cerr << std::endl << "HDF5 error: " << e.getDetailMsg() << std::endl;
}
}
return true;
/* //as35
if (fAny2ManyInfo->idf == 1) {
// fill necessary data structures
nxs->SetFileName(fln.Data());
// set file creating time
time_t now;
@@ -5121,7 +5149,7 @@ Bool_t PRunDataHandler::WriteNexusFile(TString fln)
nxs->WriteFile(fln, fileType, fAny2ManyInfo->idf);
*/ //as35
#else
std::cout << std::endl << ">> PRunDataHandler::WriteNexusFile(): Sorry, not enabled at configuration level, i.e. --enable-NeXus when executing configure" << std::endl << std::endl;
std::cout << std::endl << ">> PRunDataHandler::WriteNexusFile(): Sorry, not enabled at configuration level, i.e. -Dnexus=1 when executing configure" << std::endl << std::endl;
#endif
return true;

View File

@@ -449,7 +449,7 @@ class PRunDataHandler
virtual Bool_t WriteMusrRootFile(Int_t tag=A2M_MUSR_ROOT_DIR, TString fln="");
virtual Bool_t WriteRootFile(TString fln="");
virtual Bool_t WriteNexusFile(TString fln="");
virtual Bool_t WriteNexusFile(TString format, TString fln="");
virtual Bool_t WriteWkmFile(TString fln="");
virtual Bool_t WritePsiBinFile(TString fln="");
virtual Bool_t WriteMudFile(TString fln="");