This commit is contained in:
maliakal_d 2022-03-30 16:47:43 +02:00
parent c57e528447
commit e1988bf088
6 changed files with 28 additions and 43 deletions

View File

@ -111,7 +111,7 @@ void DataProcessor::SetupFileWriter(const bool filewriteEnable,
} }
void DataProcessor::CreateFirstFiles( 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 uint64_t fileIndex, const bool overWriteEnable, const bool silentMode,
const int modulePos, const int numUnitsPerReadout, const int modulePos, const int numUnitsPerReadout,
const uint32_t udpPortNumber, const uint32_t maxFramesPerFile, const uint32_t udpPortNumber, const uint32_t maxFramesPerFile,

View File

@ -48,8 +48,8 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject {
const fileFormat fileFormatType, const fileFormat fileFormatType,
std::mutex *hdf5LibMutex); std::mutex *hdf5LibMutex);
void CreateFirstFiles(const std::string filePath, void CreateFirstFiles(const std::string &filePath,
const std::string fileNamePrefix, const std::string &fileNamePrefix,
const uint64_t fileIndex, const bool overWriteEnable, const uint64_t fileIndex, const bool overWriteEnable,
const bool silentMode, const int modulePos, const bool silentMode, const int modulePos,
const int numUnitsPerReadout, const int numUnitsPerReadout,

View File

@ -84,10 +84,7 @@ class File : private virtual slsDetectorDefs {
virtual void WriteToFile(char *buffer, const int buffersize, virtual void WriteToFile(char *buffer, const int buffersize,
const uint64_t currentFrameNumber, const uint64_t currentFrameNumber,
const uint32_t numPacketsCaught) { const uint32_t numPacketsCaught) = 0;
LOG(logERROR) << "This is a generic function WriteToFile that "
"should be overloaded by a derived class";
};
protected: protected:
slsDetectorDefs::fileFormat format_; slsDetectorDefs::fileFormat format_;

View File

@ -155,8 +155,7 @@ void MasterAttributes::GetFinalBinaryAttributes(
#ifdef HDF5C #ifdef HDF5C
void MasterAttributes::WriteCommonHDF5Attributes(H5File *fd, Group *group) { void MasterAttributes::WriteCommonHDF5Attributes(H5File *fd, Group *group) {
char c[1024]; char c[1024]{};
memset(c, 0, sizeof(c));
// version // version
{ {
double version = BINARY_WRITER_VERSION; double version = BINARY_WRITER_VERSION;
@ -278,8 +277,7 @@ void MasterAttributes::WriteCommonHDF5Attributes(H5File *fd, Group *group) {
} }
void MasterAttributes::WriteFinalHDF5Attributes(H5File *fd, Group *group) { void MasterAttributes::WriteFinalHDF5Attributes(H5File *fd, Group *group) {
char c[1024]; char c[1024]{};
memset(c, 0, sizeof(c));
// Total Frames in file // Total Frames in file
{ {
DataSpace dataspace = DataSpace(H5S_SCALAR); DataSpace dataspace = DataSpace(H5S_SCALAR);
@ -304,8 +302,7 @@ void MasterAttributes::WriteHDF5Exptime(H5File *fd, Group *group) {
StrType strdatatype(PredType::C_S1, 256); StrType strdatatype(PredType::C_S1, 256);
DataSet dataset = DataSet dataset =
group->createDataSet("Exposure Time", strdatatype, dataspace); group->createDataSet("Exposure Time", strdatatype, dataspace);
char c[1024]; char c[1024]{};
memset(c, 0, sizeof(c));
sls::strcpy_safe(c, sls::ToString(exptime)); sls::strcpy_safe(c, sls::ToString(exptime));
dataset.write(c, strdatatype); dataset.write(c, strdatatype);
} }
@ -315,8 +312,7 @@ void MasterAttributes::WriteHDF5Period(H5File *fd, Group *group) {
StrType strdatatype(PredType::C_S1, 256); StrType strdatatype(PredType::C_S1, 256);
DataSet dataset = DataSet dataset =
group->createDataSet("Acquisition Period", strdatatype, dataspace); group->createDataSet("Acquisition Period", strdatatype, dataspace);
char c[1024]; char c[1024]{};
memset(c, 0, sizeof(c));
sls::strcpy_safe(c, sls::ToString(period)); sls::strcpy_safe(c, sls::ToString(period));
dataset.write(c, strdatatype); dataset.write(c, strdatatype);
} }
@ -373,7 +369,7 @@ void MasterAttributes::WriteHDF5ReadNRows(H5File *fd, Group *group) {
} }
void MasterAttributes::WriteHDF5ThresholdEnergy(H5File *fd, Group *group) { void MasterAttributes::WriteHDF5ThresholdEnergy(H5File *fd, Group *group) {
char c[1024]{0}; char c[1024]{};
DataSpace dataspace = DataSpace(H5S_SCALAR); DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet("Threshold Energy", DataSet dataset = group->createDataSet("Threshold Energy",
PredType::NATIVE_INT, dataspace); PredType::NATIVE_INT, dataspace);
@ -387,7 +383,7 @@ void MasterAttributes::WriteHDF5ThresholdEnergy(H5File *fd, Group *group) {
} }
void MasterAttributes::WriteHDF5ThresholdEnergies(H5File *fd, Group *group) { void MasterAttributes::WriteHDF5ThresholdEnergies(H5File *fd, Group *group) {
char c[1024]{0}; char c[1024]{};
DataSpace dataspace = DataSpace(H5S_SCALAR); DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 1024); StrType strdatatype(PredType::C_S1, 1024);
DataSet dataset = DataSet dataset =
@ -397,7 +393,7 @@ void MasterAttributes::WriteHDF5ThresholdEnergies(H5File *fd, Group *group) {
} }
void MasterAttributes::WriteHDF5SubExpTime(H5File *fd, Group *group) { void MasterAttributes::WriteHDF5SubExpTime(H5File *fd, Group *group) {
char c[1024]{0}; char c[1024]{};
DataSpace dataspace = DataSpace(H5S_SCALAR); DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256); StrType strdatatype(PredType::C_S1, 256);
DataSet dataset = DataSet dataset =
@ -407,7 +403,7 @@ void MasterAttributes::WriteHDF5SubExpTime(H5File *fd, Group *group) {
} }
void MasterAttributes::WriteHDF5SubPeriod(H5File *fd, Group *group) { void MasterAttributes::WriteHDF5SubPeriod(H5File *fd, Group *group) {
char c[1024]{0}; char c[1024]{};
DataSpace dataspace = DataSpace(H5S_SCALAR); DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256); StrType strdatatype(PredType::C_S1, 256);
DataSet dataset = DataSet dataset =
@ -424,7 +420,7 @@ void MasterAttributes::WriteHDF5SubQuad(H5File *fd, Group *group) {
} }
void MasterAttributes::WriteHDF5RateCorrections(H5File *fd, Group *group) { void MasterAttributes::WriteHDF5RateCorrections(H5File *fd, Group *group) {
char c[1024]{0}; char c[1024]{};
DataSpace dataspace = DataSpace(H5S_SCALAR); DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 1024); StrType strdatatype(PredType::C_S1, 1024);
DataSet dataset = DataSet dataset =
@ -442,7 +438,7 @@ void MasterAttributes::WriteHDF5CounterMask(H5File *fd, Group *group) {
void MasterAttributes::WriteHDF5ExptimeArray(H5File *fd, Group *group) { void MasterAttributes::WriteHDF5ExptimeArray(H5File *fd, Group *group) {
for (int i = 0; i != 3; ++i) { for (int i = 0; i != 3; ++i) {
char c[1024]{0}; char c[1024]{};
DataSpace dataspace = DataSpace(H5S_SCALAR); DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256); StrType strdatatype(PredType::C_S1, 256);
DataSet dataset = DataSet dataset =
@ -454,7 +450,7 @@ void MasterAttributes::WriteHDF5ExptimeArray(H5File *fd, Group *group) {
void MasterAttributes::WriteHDF5GateDelayArray(H5File *fd, Group *group) { void MasterAttributes::WriteHDF5GateDelayArray(H5File *fd, Group *group) {
for (int i = 0; i != 3; ++i) { for (int i = 0; i != 3; ++i) {
char c[1024]{0}; char c[1024]{};
DataSpace dataspace = DataSpace(H5S_SCALAR); DataSpace dataspace = DataSpace(H5S_SCALAR);
StrType strdatatype(PredType::C_S1, 256); StrType strdatatype(PredType::C_S1, 256);
DataSet dataset = DataSet dataset =
@ -476,8 +472,7 @@ void MasterAttributes::WriteHDF5BurstMode(H5File *fd, Group *group) {
StrType strdatatype(PredType::C_S1, 256); StrType strdatatype(PredType::C_S1, 256);
DataSet dataset = DataSet dataset =
group->createDataSet("Burst Mode", strdatatype, dataspace); group->createDataSet("Burst Mode", strdatatype, dataspace);
char c[1024]; char c[1024]{};
memset(c, 0, sizeof(c));
sls::strcpy_safe(c, sls::ToString(burstMode)); sls::strcpy_safe(c, sls::ToString(burstMode));
dataset.write(c, strdatatype); dataset.write(c, strdatatype);
} }

View File

@ -7,38 +7,31 @@
namespace masterFileUtility { namespace masterFileUtility {
std::string CreateMasterBinaryFile(const std::string filePath, std::string CreateMasterBinaryFile(const std::string &filePath,
const std::string fileNamePrefix, const std::string &fileNamePrefix,
const uint64_t fileIndex, const uint64_t fileIndex,
const bool overWriteEnable, const bool overWriteEnable,
const bool silentMode, const bool silentMode,
MasterAttributes *attr) { MasterAttributes *attr) {
// create file name
std::ostringstream os; std::ostringstream os;
os << filePath << "/" << fileNamePrefix << "_master" os << filePath << "/" << fileNamePrefix << "_master"
<< "_" << fileIndex << ".json"; << "_" << fileIndex << ".json";
std::string fileName = os.str(); std::string fileName = os.str();
// create file std::string mode = "w";
FILE *fd{nullptr}; if (!overWriteEnable)
if (!overWriteEnable) { mode = "wx";
if (nullptr == (fd = fopen((const char *)fileName.c_str(), "wx"))) { FILE *fd = fopen(fileName.c_str(), mode.c_str());
fd = nullptr; if(!fd) {
throw sls::RuntimeError("Could not create binary master file " + throw sls::RuntimeError("Could not create/overwrite binary master file " +
fileName); 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::StringBuffer s;
rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(s); rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(s);
attr->GetBinaryAttributes(&writer); attr->GetBinaryAttributes(&writer);
std::string message = s.GetString(); if (fwrite(s.GetString(), 1, strlen(s.GetString()), fd) !=
if (fwrite((void *)message.c_str(), 1, message.length(), fd) != strlen(s.GetString())) {
message.length()) {
throw sls::RuntimeError( throw sls::RuntimeError(
"Master binary file incorrect number of bytes written to file"); "Master binary file incorrect number of bytes written to file");
} }

View File

@ -14,8 +14,8 @@ using namespace H5;
namespace masterFileUtility { namespace masterFileUtility {
std::string CreateMasterBinaryFile(const std::string filePath, std::string CreateMasterBinaryFile(const std::string &filePath,
const std::string fileNamePrefix, const std::string &fileNamePrefix,
const uint64_t fileIndex, const uint64_t fileIndex,
const bool overWriteEnable, const bool overWriteEnable,
const bool silentMode, const bool silentMode,