diff --git a/RELEASE.txt b/RELEASE.txt index 01bbd7781..1f0efd8a2 100755 --- a/RELEASE.txt +++ b/RELEASE.txt @@ -58,6 +58,7 @@ This document describes the differences between v7.0.0 and v6.x.x - fpga/kernel programming, checks if drive is a special file and not a normal file - gotthard 25 um image reconstructed in gui and virtual hdf5 (firmware updated for slave to reverse channels) - master binary file in json format now +- fixed bug introduced in 6.0.0: hdf5 files created 1 file per frame after the initial file which had maxframesperfile 2. Resolved Issues ================== diff --git a/slsReceiverSoftware/src/BinaryDataFile.cpp b/slsReceiverSoftware/src/BinaryDataFile.cpp index d93fbc46c..99bf2e42e 100644 --- a/slsReceiverSoftware/src/BinaryDataFile.cpp +++ b/slsReceiverSoftware/src/BinaryDataFile.cpp @@ -72,7 +72,7 @@ void BinaryDataFile::WriteToFile(char *buffer, const int buffersize, ++subFileIndex_; CreateFile(); } - numFramesInFile_++; + ++numFramesInFile_; // write to file int ret = 0; diff --git a/slsReceiverSoftware/src/DataProcessor.cpp b/slsReceiverSoftware/src/DataProcessor.cpp index a14e57509..d6b801e3f 100644 --- a/slsReceiverSoftware/src/DataProcessor.cpp +++ b/slsReceiverSoftware/src/DataProcessor.cpp @@ -111,7 +111,7 @@ void DataProcessor::SetupFileWriter(const bool filewriteEnable, } void DataProcessor::CreateFirstFiles( - const std::string filePath, const std::string fileNamePrefix, + const std::string &filePath, const std::string &fileNamePrefix, const uint64_t fileIndex, const bool overWriteEnable, const bool silentMode, const int modulePos, const int numUnitsPerReadout, const uint32_t udpPortNumber, const uint32_t maxFramesPerFile, diff --git a/slsReceiverSoftware/src/DataProcessor.h b/slsReceiverSoftware/src/DataProcessor.h index adab81aac..b62bb9d1f 100644 --- a/slsReceiverSoftware/src/DataProcessor.h +++ b/slsReceiverSoftware/src/DataProcessor.h @@ -48,8 +48,8 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject { const fileFormat fileFormatType, std::mutex *hdf5LibMutex); - void CreateFirstFiles(const std::string filePath, - const std::string fileNamePrefix, + void CreateFirstFiles(const std::string &filePath, + const std::string &fileNamePrefix, const uint64_t fileIndex, const bool overWriteEnable, const bool silentMode, const int modulePos, const int numUnitsPerReadout, diff --git a/slsReceiverSoftware/src/File.h b/slsReceiverSoftware/src/File.h index 57282c46a..9b386a640 100644 --- a/slsReceiverSoftware/src/File.h +++ b/slsReceiverSoftware/src/File.h @@ -84,10 +84,7 @@ class File : private virtual slsDetectorDefs { virtual void WriteToFile(char *buffer, const int buffersize, const uint64_t currentFrameNumber, - const uint32_t numPacketsCaught) { - LOG(logERROR) << "This is a generic function WriteToFile that " - "should be overloaded by a derived class"; - }; + const uint32_t numPacketsCaught) = 0; protected: slsDetectorDefs::fileFormat format_; diff --git a/slsReceiverSoftware/src/HDF5DataFile.cpp b/slsReceiverSoftware/src/HDF5DataFile.cpp index 0ffe0d525..e9b2c9212 100644 --- a/slsReceiverSoftware/src/HDF5DataFile.cpp +++ b/slsReceiverSoftware/src/HDF5DataFile.cpp @@ -128,7 +128,7 @@ void HDF5DataFile::CreateFirstHDF5DataFile( } void HDF5DataFile::CreateFile() { - + numFramesInFile_ = 0; numFilesInAcquisition_++; std::ostringstream os; @@ -237,7 +237,7 @@ void HDF5DataFile::WriteToFile(char *buffer, const int buffersize, ++subFileIndex_; CreateFile(); } - numFramesInFile_++; + ++numFramesInFile_; // extend dataset (when receiver start followed by many status starts // (jungfrau))) diff --git a/slsReceiverSoftware/src/MasterAttributes.cpp b/slsReceiverSoftware/src/MasterAttributes.cpp index 59de67ccd..b82cc0e42 100644 --- a/slsReceiverSoftware/src/MasterAttributes.cpp +++ b/slsReceiverSoftware/src/MasterAttributes.cpp @@ -3,7 +3,7 @@ #include "MasterAttributes.h" void MasterAttributes::GetBinaryAttributes( - rapidjson::Writer *w) { + rapidjson::PrettyWriter *w) { w->StartObject(); GetCommonBinaryAttributes(w); switch (detType) { @@ -70,13 +70,15 @@ void MasterAttributes::WriteHDF5Attributes(H5File *fd, Group *group) { #endif void MasterAttributes::GetCommonBinaryAttributes( - rapidjson::Writer *w) { + rapidjson::PrettyWriter *w) { w->Key("Version"); w->SetMaxDecimalPlaces(2); w->Double(BINARY_WRITER_VERSION); w->Key("Timestamp"); time_t t = time(nullptr); - w->String(ctime(&t)); + std::string sTime(ctime(&t)); + std::replace(sTime.begin(), sTime.end(), '\n', '\0'); + w->String(sTime.c_str()); w->Key("Detector Type"); w->String(sls::ToString(detType).c_str()); w->Key("Timing Mode"); @@ -110,7 +112,7 @@ void MasterAttributes::GetCommonBinaryAttributes( } void MasterAttributes::GetFinalBinaryAttributes( - rapidjson::Writer *w) { + rapidjson::PrettyWriter *w) { // adding few common parameters to the end if (!additionalJsonHeader.empty()) { w->Key("Additional Json Header"); @@ -153,8 +155,7 @@ void MasterAttributes::GetFinalBinaryAttributes( #ifdef HDF5C void MasterAttributes::WriteCommonHDF5Attributes(H5File *fd, Group *group) { - char c[1024]; - memset(c, 0, sizeof(c)); + char c[1024]{}; // version { double version = BINARY_WRITER_VERSION; @@ -276,8 +277,7 @@ void MasterAttributes::WriteCommonHDF5Attributes(H5File *fd, Group *group) { } void MasterAttributes::WriteFinalHDF5Attributes(H5File *fd, Group *group) { - char c[1024]; - memset(c, 0, sizeof(c)); + char c[1024]{}; // Total Frames in file { DataSpace dataspace = DataSpace(H5S_SCALAR); @@ -302,8 +302,7 @@ void MasterAttributes::WriteHDF5Exptime(H5File *fd, Group *group) { StrType strdatatype(PredType::C_S1, 256); DataSet dataset = group->createDataSet("Exposure Time", strdatatype, dataspace); - char c[1024]; - memset(c, 0, sizeof(c)); + char c[1024]{}; sls::strcpy_safe(c, sls::ToString(exptime)); dataset.write(c, strdatatype); } @@ -313,8 +312,7 @@ void MasterAttributes::WriteHDF5Period(H5File *fd, Group *group) { StrType strdatatype(PredType::C_S1, 256); DataSet dataset = group->createDataSet("Acquisition Period", strdatatype, dataspace); - char c[1024]; - memset(c, 0, sizeof(c)); + char c[1024]{}; sls::strcpy_safe(c, sls::ToString(period)); dataset.write(c, strdatatype); } @@ -371,7 +369,7 @@ void MasterAttributes::WriteHDF5ReadNRows(H5File *fd, Group *group) { } void MasterAttributes::WriteHDF5ThresholdEnergy(H5File *fd, Group *group) { - char c[1024]{0}; + char c[1024]{}; DataSpace dataspace = DataSpace(H5S_SCALAR); DataSet dataset = group->createDataSet("Threshold Energy", PredType::NATIVE_INT, dataspace); @@ -385,7 +383,7 @@ void MasterAttributes::WriteHDF5ThresholdEnergy(H5File *fd, Group *group) { } void MasterAttributes::WriteHDF5ThresholdEnergies(H5File *fd, Group *group) { - char c[1024]{0}; + char c[1024]{}; DataSpace dataspace = DataSpace(H5S_SCALAR); StrType strdatatype(PredType::C_S1, 1024); DataSet dataset = @@ -395,7 +393,7 @@ void MasterAttributes::WriteHDF5ThresholdEnergies(H5File *fd, Group *group) { } void MasterAttributes::WriteHDF5SubExpTime(H5File *fd, Group *group) { - char c[1024]{0}; + char c[1024]{}; DataSpace dataspace = DataSpace(H5S_SCALAR); StrType strdatatype(PredType::C_S1, 256); DataSet dataset = @@ -405,7 +403,7 @@ void MasterAttributes::WriteHDF5SubExpTime(H5File *fd, Group *group) { } void MasterAttributes::WriteHDF5SubPeriod(H5File *fd, Group *group) { - char c[1024]{0}; + char c[1024]{}; DataSpace dataspace = DataSpace(H5S_SCALAR); StrType strdatatype(PredType::C_S1, 256); DataSet dataset = @@ -422,7 +420,7 @@ void MasterAttributes::WriteHDF5SubQuad(H5File *fd, Group *group) { } void MasterAttributes::WriteHDF5RateCorrections(H5File *fd, Group *group) { - char c[1024]{0}; + char c[1024]{}; DataSpace dataspace = DataSpace(H5S_SCALAR); StrType strdatatype(PredType::C_S1, 1024); DataSet dataset = @@ -440,7 +438,7 @@ void MasterAttributes::WriteHDF5CounterMask(H5File *fd, Group *group) { void MasterAttributes::WriteHDF5ExptimeArray(H5File *fd, Group *group) { for (int i = 0; i != 3; ++i) { - char c[1024]{0}; + char c[1024]{}; DataSpace dataspace = DataSpace(H5S_SCALAR); StrType strdatatype(PredType::C_S1, 256); DataSet dataset = @@ -452,7 +450,7 @@ void MasterAttributes::WriteHDF5ExptimeArray(H5File *fd, Group *group) { void MasterAttributes::WriteHDF5GateDelayArray(H5File *fd, Group *group) { for (int i = 0; i != 3; ++i) { - char c[1024]{0}; + char c[1024]{}; DataSpace dataspace = DataSpace(H5S_SCALAR); StrType strdatatype(PredType::C_S1, 256); DataSet dataset = @@ -474,8 +472,7 @@ void MasterAttributes::WriteHDF5BurstMode(H5File *fd, Group *group) { StrType strdatatype(PredType::C_S1, 256); DataSet dataset = group->createDataSet("Burst Mode", strdatatype, dataspace); - char c[1024]; - memset(c, 0, sizeof(c)); + char c[1024]{}; sls::strcpy_safe(c, sls::ToString(burstMode)); dataset.write(c, strdatatype); } @@ -531,7 +528,7 @@ void MasterAttributes::WriteHDF5DbitList(H5File *fd, Group *group) { #endif void MasterAttributes::GetGotthardBinaryAttributes( - rapidjson::Writer *w) { + rapidjson::PrettyWriter *w) { w->Key("Exptime"); w->String(sls::ToString(exptime).c_str()); w->Key("Period"); @@ -549,7 +546,7 @@ void MasterAttributes::WriteGotthardHDF5Attributes(H5File *fd, Group *group) { #endif void MasterAttributes::GetJungfrauBinaryAttributes( - rapidjson::Writer *w) { + rapidjson::PrettyWriter *w) { w->Key("Exptime"); w->String(sls::ToString(exptime).c_str()); w->Key("Period"); @@ -570,7 +567,7 @@ void MasterAttributes::WriteJungfrauHDF5Attributes(H5File *fd, Group *group) { #endif void MasterAttributes::GetEigerBinaryAttributes( - rapidjson::Writer *w) { + rapidjson::PrettyWriter *w) { w->Key("Dynamic Range"); w->Uint(dynamicRange); w->Key("Ten Giga"); @@ -609,7 +606,7 @@ void MasterAttributes::WriteEigerHDF5Attributes(H5File *fd, Group *group) { #endif void MasterAttributes::GetMythen3BinaryAttributes( - rapidjson::Writer *w) { + rapidjson::PrettyWriter *w) { w->Key("Dynamic Range"); w->Uint(dynamicRange); w->Key("Ten Giga"); @@ -646,7 +643,7 @@ void MasterAttributes::WriteMythen3HDF5Attributes(H5File *fd, Group *group) { #endif void MasterAttributes::GetGotthard2BinaryAttributes( - rapidjson::Writer *w) { + rapidjson::PrettyWriter *w) { w->Key("Exptime"); w->String(sls::ToString(exptime).c_str()); w->Key("Period"); @@ -664,7 +661,7 @@ void MasterAttributes::WriteGotthard2HDF5Attributes(H5File *fd, Group *group) { #endif void MasterAttributes::GetMoenchBinaryAttributes( - rapidjson::Writer *w) { + rapidjson::PrettyWriter *w) { w->Key("Exptime"); w->String(sls::ToString(exptime).c_str()); w->Key("Period"); @@ -688,7 +685,7 @@ void MasterAttributes::WriteMoenchHDF5Attributes(H5File *fd, Group *group) { #endif void MasterAttributes::GetCtbBinaryAttributes( - rapidjson::Writer *w) { + rapidjson::PrettyWriter *w) { w->Key("Exptime"); w->String(sls::ToString(exptime).c_str()); w->Key("Period"); diff --git a/slsReceiverSoftware/src/MasterAttributes.h b/slsReceiverSoftware/src/MasterAttributes.h index 66ae25016..34479bfb0 100644 --- a/slsReceiverSoftware/src/MasterAttributes.h +++ b/slsReceiverSoftware/src/MasterAttributes.h @@ -8,7 +8,7 @@ #include "sls/sls_detector_defs.h" #include -#include +#include #ifdef HDF5C #include "H5Cpp.h" @@ -65,15 +65,15 @@ class MasterAttributes { MasterAttributes() = default; ~MasterAttributes() = default; - void GetBinaryAttributes(rapidjson::Writer *w); + void GetBinaryAttributes(rapidjson::PrettyWriter *w); #ifdef HDF5C void WriteHDF5Attributes(H5File *fd, Group *group); #endif void - GetCommonBinaryAttributes(rapidjson::Writer *w); + GetCommonBinaryAttributes(rapidjson::PrettyWriter *w); void - GetFinalBinaryAttributes(rapidjson::Writer *w); + GetFinalBinaryAttributes(rapidjson::PrettyWriter *w); #ifdef HDF5C void WriteCommonHDF5Attributes(H5File *fd, Group *group); void WriteFinalHDF5Attributes(H5File *fd, Group *group); @@ -105,42 +105,42 @@ class MasterAttributes { #endif void - GetGotthardBinaryAttributes(rapidjson::Writer *w); + GetGotthardBinaryAttributes(rapidjson::PrettyWriter *w); #ifdef HDF5C void WriteGotthardHDF5Attributes(H5File *fd, Group *group); #endif void - GetJungfrauBinaryAttributes(rapidjson::Writer *w); + GetJungfrauBinaryAttributes(rapidjson::PrettyWriter *w); #ifdef HDF5C void WriteJungfrauHDF5Attributes(H5File *fd, Group *group); #endif void - GetEigerBinaryAttributes(rapidjson::Writer *w); + GetEigerBinaryAttributes(rapidjson::PrettyWriter *w); #ifdef HDF5C void WriteEigerHDF5Attributes(H5File *fd, Group *group); #endif void - GetMythen3BinaryAttributes(rapidjson::Writer *w); + GetMythen3BinaryAttributes(rapidjson::PrettyWriter *w); #ifdef HDF5C void WriteMythen3HDF5Attributes(H5File *fd, Group *group); #endif void - GetGotthard2BinaryAttributes(rapidjson::Writer *w); + GetGotthard2BinaryAttributes(rapidjson::PrettyWriter *w); #ifdef HDF5C void WriteGotthard2HDF5Attributes(H5File *fd, Group *group); #endif void - GetMoenchBinaryAttributes(rapidjson::Writer *w); + GetMoenchBinaryAttributes(rapidjson::PrettyWriter *w); #ifdef HDF5C void WriteMoenchHDF5Attributes(H5File *fd, Group *group); #endif - void GetCtbBinaryAttributes(rapidjson::Writer *w); + void GetCtbBinaryAttributes(rapidjson::PrettyWriter *w); #ifdef HDF5C void WriteCtbHDF5Attributes(H5File *fd, Group *group); #endif diff --git a/slsReceiverSoftware/src/MasterFileUtility.cpp b/slsReceiverSoftware/src/MasterFileUtility.cpp index 0ae1dc57d..506ba7b83 100644 --- a/slsReceiverSoftware/src/MasterFileUtility.cpp +++ b/slsReceiverSoftware/src/MasterFileUtility.cpp @@ -7,38 +7,31 @@ namespace masterFileUtility { -std::string CreateMasterBinaryFile(const std::string filePath, - const std::string fileNamePrefix, +std::string CreateMasterBinaryFile(const std::string &filePath, + const std::string &fileNamePrefix, const uint64_t fileIndex, const bool overWriteEnable, const bool silentMode, MasterAttributes *attr) { - // create file name std::ostringstream os; os << filePath << "/" << fileNamePrefix << "_master" << "_" << fileIndex << ".json"; std::string fileName = os.str(); - // create file - FILE *fd{nullptr}; - if (!overWriteEnable) { - if (nullptr == (fd = fopen((const char *)fileName.c_str(), "wx"))) { - fd = nullptr; - throw sls::RuntimeError("Could not create binary master file " + + std::string mode = "w"; + if (!overWriteEnable) + mode = "wx"; + FILE *fd = fopen(fileName.c_str(), mode.c_str()); + if(!fd) { + throw sls::RuntimeError("Could not create/overwrite binary master file " + fileName); - } - } else if (nullptr == (fd = fopen((const char *)fileName.c_str(), "w"))) { - fd = nullptr; - throw sls::RuntimeError( - "Could not create/overwrite binary master file " + fileName); } rapidjson::StringBuffer s; - rapidjson::Writer writer(s); + rapidjson::PrettyWriter writer(s); attr->GetBinaryAttributes(&writer); - std::string message = s.GetString(); - if (fwrite((void *)message.c_str(), 1, message.length(), fd) != - message.length()) { + if (fwrite(s.GetString(), 1, strlen(s.GetString()), fd) != + strlen(s.GetString())) { throw sls::RuntimeError( "Master binary file incorrect number of bytes written to file"); } diff --git a/slsReceiverSoftware/src/MasterFileUtility.h b/slsReceiverSoftware/src/MasterFileUtility.h index d0a74b04f..ed90cc52e 100644 --- a/slsReceiverSoftware/src/MasterFileUtility.h +++ b/slsReceiverSoftware/src/MasterFileUtility.h @@ -14,8 +14,8 @@ using namespace H5; namespace masterFileUtility { -std::string CreateMasterBinaryFile(const std::string filePath, - const std::string fileNamePrefix, +std::string CreateMasterBinaryFile(const std::string &filePath, + const std::string &fileNamePrefix, const uint64_t fileIndex, const bool overWriteEnable, const bool silentMode,