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(
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,

View File

@ -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,

View File

@ -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_;

View File

@ -155,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;
@ -278,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);
@ -304,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);
}
@ -315,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);
}
@ -373,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);
@ -387,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 =
@ -397,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 =
@ -407,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 =
@ -424,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 =
@ -442,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 =
@ -454,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 =
@ -476,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);
}

View File

@ -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::PrettyWriter<rapidjson::StringBuffer> 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");
}

View File

@ -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,