mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2026-02-17 04:38:41 +01:00
Rxclassmembers (#503)
* gui message doesnt show if it has a '>' symbol in error msg * minor refactoring for readability (size_t calc fifo size) * refactoring listening udp socket code: activated and datastream dont create udp sockets anyway, rc<=- should be discarded in any case * wip * refactoring memory structure access * wip: bugfix write header + data to binary * wip * wip * wip * wip * wip * wip * wip * wip * wip * portRoi no roi effecto on progress * fail at receiver progress, wip * segfaults for char pointer in struct * reference to header to get header and data * refactoring * use const defined for size of header of fifo * updated release notes * remove pointer in callback for sls_receiver_header pointer * rx same name arguments in constructors * rx: same name arguments in constructor * rx: removing the '_' suffix in class data members * merge fix * merge fix * review fix refactoring
This commit is contained in:
@@ -4,88 +4,93 @@
|
||||
|
||||
namespace sls {
|
||||
|
||||
BinaryDataFile::BinaryDataFile(const int index) : File(BINARY), index_(index) {}
|
||||
BinaryDataFile::BinaryDataFile(const int index) : index(index) {}
|
||||
|
||||
BinaryDataFile::~BinaryDataFile() { CloseFile(); }
|
||||
|
||||
slsDetectorDefs::fileFormat BinaryDataFile::GetFileFormat() const {
|
||||
return BINARY;
|
||||
}
|
||||
|
||||
void BinaryDataFile::CloseFile() {
|
||||
if (fd_) {
|
||||
fclose(fd_);
|
||||
if (fd) {
|
||||
fclose(fd);
|
||||
}
|
||||
fd_ = nullptr;
|
||||
fd = nullptr;
|
||||
}
|
||||
|
||||
void BinaryDataFile::CreateFirstBinaryDataFile(
|
||||
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) {
|
||||
const std::string fPath, const std::string fNamePrefix,
|
||||
const uint64_t fIndex, const bool ovEnable, const bool sMode,
|
||||
const int modulePos, const int nUnitsPerReadout,
|
||||
const uint32_t uPortNumber, const uint32_t mFramesPerFile) {
|
||||
|
||||
subFileIndex_ = 0;
|
||||
numFramesInFile_ = 0;
|
||||
subFileIndex = 0;
|
||||
numFramesInFile = 0;
|
||||
|
||||
filePath_ = filePath;
|
||||
fileNamePrefix_ = fileNamePrefix;
|
||||
fileIndex_ = fileIndex;
|
||||
overWriteEnable_ = overWriteEnable;
|
||||
silentMode_ = silentMode;
|
||||
detIndex_ = modulePos;
|
||||
numUnitsPerReadout_ = numUnitsPerReadout;
|
||||
udpPortNumber_ = udpPortNumber;
|
||||
maxFramesPerFile_ = maxFramesPerFile;
|
||||
filePath = fPath;
|
||||
fileNamePrefix = fNamePrefix;
|
||||
fileIndex = fIndex;
|
||||
overWriteEnable = ovEnable;
|
||||
|
||||
silentMode = sMode;
|
||||
detIndex = modulePos;
|
||||
numUnitsPerReadout = nUnitsPerReadout;
|
||||
udpPortNumber = uPortNumber;
|
||||
maxFramesPerFile = mFramesPerFile;
|
||||
|
||||
CreateFile();
|
||||
}
|
||||
|
||||
void BinaryDataFile::CreateFile() {
|
||||
numFramesInFile_ = 0;
|
||||
numFramesInFile = 0;
|
||||
|
||||
std::ostringstream os;
|
||||
os << filePath_ << "/" << fileNamePrefix_ << "_d"
|
||||
<< (detIndex_ * numUnitsPerReadout_ + index_) << "_f" << subFileIndex_
|
||||
<< '_' << fileIndex_ << ".raw";
|
||||
fileName_ = os.str();
|
||||
os << filePath << "/" << fileNamePrefix << "_d"
|
||||
<< (detIndex * numUnitsPerReadout + index) << "_f" << subFileIndex
|
||||
<< '_' << fileIndex << ".raw";
|
||||
fileName = os.str();
|
||||
|
||||
if (!overWriteEnable_) {
|
||||
if (nullptr == (fd_ = fopen((const char *)fileName_.c_str(), "wx"))) {
|
||||
fd_ = nullptr;
|
||||
if (!overWriteEnable) {
|
||||
if (nullptr == (fd = fopen(fileName.c_str(), "wx"))) {
|
||||
fd = nullptr;
|
||||
throw RuntimeError("Could not create/overwrite file " +
|
||||
fileName_);
|
||||
fileName);
|
||||
}
|
||||
} else if (nullptr == (fd_ = fopen((const char *)fileName_.c_str(), "w"))) {
|
||||
fd_ = nullptr;
|
||||
throw RuntimeError("Could not create file " + fileName_);
|
||||
} else if (nullptr == (fd = fopen(fileName.c_str(), "w"))) {
|
||||
fd = nullptr;
|
||||
throw RuntimeError("Could not create file " + fileName);
|
||||
}
|
||||
// setting to no file buffering
|
||||
setvbuf(fd_, nullptr, _IONBF, 0);
|
||||
setvbuf(fd, nullptr, _IONBF, 0);
|
||||
|
||||
if (!silentMode_) {
|
||||
LOG(logINFO) << "[" << udpPortNumber_
|
||||
<< "]: Binary File created: " << fileName_;
|
||||
if (!silentMode) {
|
||||
LOG(logINFO) << "[" << udpPortNumber
|
||||
<< "]: Binary File created: " << fileName;
|
||||
}
|
||||
}
|
||||
|
||||
void BinaryDataFile::WriteToFile(char *imageData, sls_receiver_header& header, const int imageSize, const uint64_t currentFrameNumber, const uint32_t numPacketsCaught) {
|
||||
// check if maxframesperfile = 0 for infinite
|
||||
if (maxFramesPerFile_ && (numFramesInFile_ >= maxFramesPerFile_)) {
|
||||
if (maxFramesPerFile && (numFramesInFile >= maxFramesPerFile)) {
|
||||
CloseFile();
|
||||
++subFileIndex_;
|
||||
++subFileIndex;
|
||||
CreateFile();
|
||||
}
|
||||
++numFramesInFile_;
|
||||
++numFramesInFile;
|
||||
|
||||
// write to file
|
||||
size_t ret = 0;
|
||||
|
||||
// contiguous bitset (write header + image)
|
||||
if (sizeof(sls_bitset) == sizeof(bitset_storage)) {
|
||||
ret = fwrite(&header, sizeof(sls_receiver_header) + imageSize, 1, fd_);
|
||||
ret = fwrite(&header, sizeof(sls_receiver_header) + imageSize, 1, fd);
|
||||
}
|
||||
|
||||
// not contiguous bitset
|
||||
else {
|
||||
// write detector header
|
||||
ret = fwrite(&header, sizeof(sls_detector_header), 1, fd_);
|
||||
ret = fwrite(&header, sizeof(sls_detector_header), 1, fd);
|
||||
|
||||
// get contiguous representation of bit mask
|
||||
bitset_storage storage;
|
||||
@@ -94,15 +99,15 @@ void BinaryDataFile::WriteToFile(char *imageData, sls_receiver_header& header, c
|
||||
for (int i = 0; i < MAX_NUM_PACKETS; ++i)
|
||||
storage[i >> 3] |= (bits[i] << (i & 7));
|
||||
// write bitmask
|
||||
ret += fwrite(storage, sizeof(bitset_storage), 1, fd_);
|
||||
ret += fwrite(storage, sizeof(bitset_storage), 1, fd);
|
||||
|
||||
// write data
|
||||
ret += fwrite(imageData, imageSize, 1, fd_);
|
||||
ret += fwrite(imageData, imageSize, 1, fd);
|
||||
}
|
||||
|
||||
// if write error
|
||||
if (ret != imageSize + sizeof(sls_receiver_header)) {
|
||||
throw RuntimeError(std::to_string(index_) + " : Write to file failed for image number " + std::to_string(currentFrameNumber) + ". Wrote " + std::to_string(ret) + " bytes instead of " + std::to_string(imageSize + sizeof(sls_receiver_header)));
|
||||
throw RuntimeError(std::to_string(index) + " : Write to file failed for image number " + std::to_string(currentFrameNumber) + ". Wrote " + std::to_string(ret) + " bytes instead of " + std::to_string(imageSize + sizeof(sls_receiver_header)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user