diff --git a/slsReceiverSoftware/src/BinaryFile.cpp b/slsReceiverSoftware/src/BinaryFile.cpp index 867d7ee12..8a4c8b990 100755 --- a/slsReceiverSoftware/src/BinaryFile.cpp +++ b/slsReceiverSoftware/src/BinaryFile.cpp @@ -74,7 +74,7 @@ void BinaryFile::CloseCurrentFile() { void BinaryFile::CloseAllFiles() { CloseCurrentFile(); - if (master && (*detIndex==0)) { + if (master) { if (masterfd) fclose(masterfd); masterfd = 0; @@ -137,7 +137,7 @@ void BinaryFile::CreateMasterFile(bool mfwenable, masterAttributes& attr) { numFramesInFile = 0; numActualPacketsInFile = 0; - if (mfwenable && master && (*detIndex==0)) { + if (mfwenable && master) { std::ostringstream os; os << *filePath << "/" << *fileNamePrefix << "_master" diff --git a/slsReceiverSoftware/src/DataProcessor.cpp b/slsReceiverSoftware/src/DataProcessor.cpp index 7cdba016c..4d53b4cd3 100755 --- a/slsReceiverSoftware/src/DataProcessor.cpp +++ b/slsReceiverSoftware/src/DataProcessor.cpp @@ -140,7 +140,8 @@ void DataProcessor::SetupFileWriter(bool fwe, int* nd, uint32_t* maxf, if (file != nullptr) { - delete file; file = nullptr; + delete file; + file = nullptr; } if (fileWriteEnable) { diff --git a/slsReceiverSoftware/src/HDF5File.cpp b/slsReceiverSoftware/src/HDF5File.cpp index fc345b6e7..ef319754b 100755 --- a/slsReceiverSoftware/src/HDF5File.cpp +++ b/slsReceiverSoftware/src/HDF5File.cpp @@ -118,7 +118,7 @@ void HDF5File::CreateFile() { } void HDF5File::CloseCurrentFile() { - CloseFile(filefd, false, false); + CloseFile(filefd, false); for (unsigned int i = 0; i < dataset_para.size(); ++i) delete dataset_para[i]; dataset_para.clear(); @@ -139,10 +139,17 @@ void HDF5File::CloseCurrentFile() { void HDF5File::CloseAllFiles() { numFilesinAcquisition = 0; { - CloseFile(filefd, false, false); + CloseFile(filefd, false); if (master) { - CloseFile(masterfd, false, true); - CloseFile(nullptr, true, false); + CloseFile(masterfd, true); + // close virtual file + // c code due to only c implementation of H5Pset_virtual available + if (virtualfd != 0) { + if (H5Fclose(virtualfd) < 0 ) { + LOG(logERROR) << "Could not close virtual HDF5 handles"; + } + virtualfd = 0; + } } } for (unsigned int i = 0; i < dataset_para.size(); ++i) @@ -151,7 +158,6 @@ void HDF5File::CloseAllFiles() { if(dataspace_para) delete dataspace_para; if(dataset) delete dataset; if(dataspace) delete dataspace; - if(filefd) delete filefd; } void HDF5File::WriteToFile(char* buffer, int bufferSize, uint64_t currentFrameNumber, uint32_t numPacketsCaught) { @@ -217,30 +223,20 @@ void HDF5File::EndofAcquisition(bool anyPacketsCaught, uint64_t numImagesCaught) numFilesinAcquisition = 0; } -void HDF5File::CloseFile(H5File* fd, bool virtualFile, bool masterFile) { +void HDF5File::CloseFile(H5File*& fd, bool masterFile) { std::lock_guard lock(HDF5File::hdf5Lib); - - // c code due to only c implementation of H5Pset_virtual available - if (virtualFile) { - if (virtualfd != 0) { - if (H5Fclose(virtualfd) < 0 ) { - LOG(logERROR) << "Could not close virtual HDF5 handles"; - } - virtualfd = 0; - } - } else { - try { - Exception::dontPrint(); // to handle errors - if (fd) { - delete fd; - fd = 0; - } - } catch(const Exception& error) { - LOG(logERROR) << "Could not close " - << (masterFile ? "master" : "data") - << " HDF5 handles of index " << index; - error.printErrorStack(); + try { + Exception::dontPrint(); // to handle errors + if (fd) { + fd->close(); + delete fd; + fd = 0; } + } catch(const Exception& error) { + LOG(logERROR) << "Could not close " + << (masterFile ? "master" : "data") + << " HDF5 handles of index " << index; + error.printErrorStack(); } } @@ -462,7 +458,9 @@ void HDF5File::CreateDataFile() { } catch(const Exception& error){ error.printErrorStack(); - if (filefd) filefd->close(); + if (filefd) { + filefd->close(); + } throw sls::RuntimeError("Could not create HDF5 handles in object " + index); } if(!(*silentMode)) { @@ -686,7 +684,9 @@ void HDF5File::CreateMasterDataFile(masterAttributes& masterFileAttributes) { } catch(const Exception& error) { error.printErrorStack(); - if (masterfd) masterfd->close(); + if (masterfd) { + masterfd->close(); + } throw sls::RuntimeError("Could not create master HDF5 handles"); } } diff --git a/slsReceiverSoftware/src/HDF5File.h b/slsReceiverSoftware/src/HDF5File.h index 0862ba6a2..5db6596d8 100755 --- a/slsReceiverSoftware/src/HDF5File.h +++ b/slsReceiverSoftware/src/HDF5File.h @@ -57,7 +57,7 @@ class HDF5File : private virtual slsDetectorDefs, public File { private: - void CloseFile(H5File* fd, bool virtualFile, bool masterFile); + void CloseFile(H5File*& fd, bool masterFile); void WriteDataFile(uint64_t currentFrameNumber, char* buffer); void WriteParameterDatasets(uint64_t currentFrameNumber, sls_receiver_header* rheader); void ExtendDataset();