mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-12-31 16:41:18 +01:00
WIP
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <string.h>
|
||||
|
||||
FILE* BinaryFile::masterfd = nullptr;
|
||||
|
||||
@@ -106,13 +107,13 @@ void BinaryFile::WriteToFile(char* buffer, int buffersize, uint64_t fnum, uint32
|
||||
|
||||
// contiguous bitset
|
||||
if (sizeof(sls_bitset) == sizeof(bitset_storage)) {
|
||||
ret = BinaryFileStatic::WriteData(buffer, buffersize);
|
||||
ret = WriteData(buffer, buffersize);
|
||||
}
|
||||
|
||||
// not contiguous bitset
|
||||
else {
|
||||
// write detector header
|
||||
ret = BinaryFileStatic::WriteData(buffer, sizeof(sls_detector_header));
|
||||
ret = WriteData(buffer, sizeof(sls_detector_header));
|
||||
|
||||
// get contiguous representation of bit mask
|
||||
bitset_storage storage;
|
||||
@@ -121,10 +122,10 @@ void BinaryFile::WriteToFile(char* buffer, int buffersize, uint64_t fnum, uint32
|
||||
for (int i = 0; i < MAX_NUM_PACKETS; ++i)
|
||||
storage[i >> 3] |= (bits[i] << (i & 7));
|
||||
// write bitmask
|
||||
ret += BinaryFileStatic::WriteData((char*)storage, sizeof(bitset_storage));
|
||||
ret += WriteData((char*)storage, sizeof(bitset_storage));
|
||||
|
||||
// write data
|
||||
ret += BinaryFileStatic::WriteData(buffer + sizeof(sls_detector_header),
|
||||
ret += WriteData(buffer + sizeof(sls_detector_header),
|
||||
buffersize - sizeof(sls_receiver_header));
|
||||
}
|
||||
|
||||
@@ -150,8 +151,94 @@ void BinaryFile::CreateMasterFile(bool mfwenable, masterAttributes& attr) {
|
||||
LOG(logINFO) << "Master File: " << masterFileName;
|
||||
}
|
||||
attr.version = BINARY_WRITER_VERSION;
|
||||
BinaryFileStatic::CreateMasterDataFile(masterfd, masterFileName,
|
||||
*overWriteEnable, attr);
|
||||
|
||||
// create master file
|
||||
if (!(*overWriteEnable)){
|
||||
if (NULL == (masterfd = fopen((const char *) masterFileName.c_str(), "wx"))) {
|
||||
masterfd = 0;
|
||||
throw sls::RuntimeError("Could not create binary master file "
|
||||
"(without overwrite enable) " + masterFileName);
|
||||
}
|
||||
}else if (NULL == (masterfd = fopen((const char *) masterFileName.c_str(), "w"))) {
|
||||
masterfd = 0;
|
||||
throw sls::RuntimeError("Could not create binary master file "
|
||||
"(with overwrite enable) " + masterFileName);
|
||||
}
|
||||
// create master file data
|
||||
time_t t = time(0);
|
||||
char message[maxMasterFileSize];
|
||||
sprintf(message,
|
||||
"Version : %.1f\n"
|
||||
"Detector Type : %d\n"
|
||||
"Dynamic Range : %d\n"
|
||||
"Ten Giga : %d\n"
|
||||
"Image Size : %d bytes\n"
|
||||
"nPixelsX : %d pixels\n"
|
||||
"nPixelsY : %d pixels\n"
|
||||
"Max Frames Per File : %u\n"
|
||||
"Total Frames : %lld\n"
|
||||
"Exptime (ns) : %lld\n"
|
||||
"SubExptime (ns) : %lld\n"
|
||||
"SubPeriod(ns) : %lld\n"
|
||||
"Period (ns) : %lld\n"
|
||||
"Quad Enable : %d\n"
|
||||
"Analog Flag : %d\n"
|
||||
"Digital Flag : %d\n"
|
||||
"ADC Mask : %d\n"
|
||||
"Dbit Offset : %d\n"
|
||||
"Dbit Bitset : %lld\n"
|
||||
"Roi (xmin, xmax) : %d %d\n"
|
||||
"Timestamp : %s\n\n"
|
||||
|
||||
"#Frame Header\n"
|
||||
"Frame Number : 8 bytes\n"
|
||||
"SubFrame Number/ExpLength : 4 bytes\n"
|
||||
"Packet Number : 4 bytes\n"
|
||||
"Bunch ID : 8 bytes\n"
|
||||
"Timestamp : 8 bytes\n"
|
||||
"Module Id : 2 bytes\n"
|
||||
"Row : 2 bytes\n"
|
||||
"Column : 2 bytes\n"
|
||||
"Reserved : 2 bytes\n"
|
||||
"Debug : 4 bytes\n"
|
||||
"Round Robin Number : 2 bytes\n"
|
||||
"Detector Type : 1 byte\n"
|
||||
"Header Version : 1 byte\n"
|
||||
"Packets Caught Mask : 64 bytes\n"
|
||||
,
|
||||
attr.version,
|
||||
attr.detectorType,
|
||||
attr.dynamicRange,
|
||||
attr.tenGiga,
|
||||
attr.imageSize,
|
||||
attr.nPixelsX,
|
||||
attr.nPixelsY,
|
||||
attr.maxFramesPerFile,
|
||||
(long long int)attr.totalFrames,
|
||||
(long long int)attr.exptimeNs,
|
||||
(long long int)attr.subExptimeNs,
|
||||
(long long int)attr.subPeriodNs,
|
||||
(long long int)attr.periodNs,
|
||||
attr.quadEnable,
|
||||
attr.analogFlag,
|
||||
attr.digitalFlag,
|
||||
attr.adcmask,
|
||||
attr.dbitoffset,
|
||||
(long long int)attr.dbitlist,
|
||||
attr.roiXmin,
|
||||
attr.roiXmax,
|
||||
ctime(&t));
|
||||
if (strlen(message) > maxMasterFileSize) {
|
||||
throw sls::RuntimeError("Master File Size " + std::to_string(strlen(message)) +
|
||||
" is greater than max str size " + std::to_string(maxMasterFileSize));
|
||||
}
|
||||
// write and close file
|
||||
if (fwrite((void*)message, 1, strlen(message), masterfd) != strlen(message)) {
|
||||
throw sls::RuntimeError("Master binary file incorrect number of bytes written to file");
|
||||
}
|
||||
if (masterfd)
|
||||
fclose(masterfd);
|
||||
masterfd = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user