mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-19 00:07:13 +02:00
WIP
This commit is contained in:
@ -9,7 +9,7 @@
|
|||||||
#include "receiver_defs.h"
|
#include "receiver_defs.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <iomanip>
|
||||||
|
|
||||||
FILE* BinaryFile::masterfd = nullptr;
|
FILE* BinaryFile::masterfd = nullptr;
|
||||||
|
|
||||||
@ -20,7 +20,8 @@ BinaryFile::BinaryFile(int ind, uint32_t* maxf,
|
|||||||
File(ind, maxf, nd, fname, fpath, findex, owenable, dindex, nunits, nf, dr, portno, smode),
|
File(ind, maxf, nd, fname, fpath, findex, owenable, dindex, nunits, nf, dr, portno, smode),
|
||||||
filefd(nullptr),
|
filefd(nullptr),
|
||||||
numFramesInFile(0),
|
numFramesInFile(0),
|
||||||
numActualPacketsInFile(0)
|
numActualPacketsInFile(0),
|
||||||
|
maxMasterFileSize(2000)
|
||||||
{
|
{
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
PrintMembers();
|
PrintMembers();
|
||||||
@ -41,15 +42,27 @@ slsDetectorDefs::fileFormat BinaryFile::GetFileType() {
|
|||||||
return BINARY;
|
return BINARY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void BinaryFile::CreateFile() {
|
void BinaryFile::CreateFile() {
|
||||||
numFramesInFile = 0;
|
numFramesInFile = 0;
|
||||||
numActualPacketsInFile = 0;
|
numActualPacketsInFile = 0;
|
||||||
|
|
||||||
currentFileName = BinaryFileStatic::CreateFileName(*filePath, *fileNamePrefix, *fileIndex,
|
std::ostringstream os;
|
||||||
subFileIndex, *detIndex, *numUnitsPerDetector, index);
|
os << *filePath << "/" << *fileNamePrefix << "_d"
|
||||||
|
<< (*detIndex * (*numUnitsPerDetector) + index) << "_f" << subFileIndex << '_'
|
||||||
|
<< *fileIndex << ".raw";
|
||||||
|
currentFileName = os.str();
|
||||||
|
|
||||||
BinaryFileStatic::CreateDataFile(filefd, *overWriteEnable, currentFileName);
|
if (!(*overWriteEnable)){
|
||||||
|
if (NULL == (filefd = fopen((const char *) currentFileName.c_str(), "wx"))){
|
||||||
|
filefd = 0;
|
||||||
|
throw sls::RuntimeError("Could not create/overwrite file " + currentFileName);
|
||||||
|
}
|
||||||
|
} else if (NULL == (filefd = fopen((const char *) currentFileName.c_str(), "w"))){
|
||||||
|
filefd = 0;
|
||||||
|
throw sls::RuntimeError("Could not create file " + currentFileName);
|
||||||
|
}
|
||||||
|
//setting to no file buffering
|
||||||
|
setvbuf(filefd, NULL, _IONBF, 0);
|
||||||
|
|
||||||
if(!(*silentMode)) {
|
if(!(*silentMode)) {
|
||||||
LOG(logINFO) << "[" << *udpPortNumber << "]: Binary File created: " << currentFileName;
|
LOG(logINFO) << "[" << *udpPortNumber << "]: Binary File created: " << currentFileName;
|
||||||
@ -57,15 +70,27 @@ void BinaryFile::CreateFile() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void BinaryFile::CloseCurrentFile() {
|
void BinaryFile::CloseCurrentFile() {
|
||||||
BinaryFileStatic::CloseDataFile(filefd);
|
if (filefd)
|
||||||
|
fclose(filefd);
|
||||||
|
filefd = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BinaryFile::CloseAllFiles() {
|
void BinaryFile::CloseAllFiles() {
|
||||||
BinaryFileStatic::CloseDataFile(filefd);
|
CloseCurrentFile();
|
||||||
if (master && (*detIndex==0))
|
if (master && (*detIndex==0)) {
|
||||||
BinaryFileStatic::CloseDataFile(masterfd);
|
if (masterfd)
|
||||||
|
fclose(masterfd);
|
||||||
|
masterfd = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int BinaryFile::WriteData(char* buf, int bsize) {
|
||||||
|
if (!filefd)
|
||||||
|
return 0;
|
||||||
|
return fwrite(buf, 1, bsize, filefd);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void BinaryFile::WriteToFile(char* buffer, int buffersize, uint64_t fnum, uint32_t nump) {
|
void BinaryFile::WriteToFile(char* buffer, int buffersize, uint64_t fnum, uint32_t nump) {
|
||||||
// check if maxframesperfile = 0 for infinite
|
// check if maxframesperfile = 0 for infinite
|
||||||
if ((*maxFramesPerFile) && (numFramesInFile >= (*maxFramesPerFile))) {
|
if ((*maxFramesPerFile) && (numFramesInFile >= (*maxFramesPerFile))) {
|
||||||
@ -81,13 +106,13 @@ void BinaryFile::WriteToFile(char* buffer, int buffersize, uint64_t fnum, uint32
|
|||||||
|
|
||||||
// contiguous bitset
|
// contiguous bitset
|
||||||
if (sizeof(sls_bitset) == sizeof(bitset_storage)) {
|
if (sizeof(sls_bitset) == sizeof(bitset_storage)) {
|
||||||
ret = BinaryFileStatic::WriteDataFile(filefd, buffer, buffersize);
|
ret = BinaryFileStatic::WriteData(buffer, buffersize);
|
||||||
}
|
}
|
||||||
|
|
||||||
// not contiguous bitset
|
// not contiguous bitset
|
||||||
else {
|
else {
|
||||||
// write detector header
|
// write detector header
|
||||||
ret = BinaryFileStatic::WriteDataFile(filefd, buffer, sizeof(sls_detector_header));
|
ret = BinaryFileStatic::WriteData(buffer, sizeof(sls_detector_header));
|
||||||
|
|
||||||
// get contiguous representation of bit mask
|
// get contiguous representation of bit mask
|
||||||
bitset_storage storage;
|
bitset_storage storage;
|
||||||
@ -96,11 +121,11 @@ void BinaryFile::WriteToFile(char* buffer, int buffersize, uint64_t fnum, uint32
|
|||||||
for (int i = 0; i < MAX_NUM_PACKETS; ++i)
|
for (int i = 0; i < MAX_NUM_PACKETS; ++i)
|
||||||
storage[i >> 3] |= (bits[i] << (i & 7));
|
storage[i >> 3] |= (bits[i] << (i & 7));
|
||||||
// write bitmask
|
// write bitmask
|
||||||
ret += BinaryFileStatic::WriteDataFile(filefd, (char*)storage, sizeof(bitset_storage));
|
ret += BinaryFileStatic::WriteData((char*)storage, sizeof(bitset_storage));
|
||||||
|
|
||||||
// write data
|
// write data
|
||||||
ret += BinaryFileStatic::WriteDataFile(filefd,
|
ret += BinaryFileStatic::WriteData(buffer + sizeof(sls_detector_header),
|
||||||
buffer + sizeof(sls_detector_header), buffersize - sizeof(sls_receiver_header));
|
buffersize - sizeof(sls_receiver_header));
|
||||||
}
|
}
|
||||||
|
|
||||||
// if write error
|
// if write error
|
||||||
@ -116,8 +141,11 @@ void BinaryFile::CreateMasterFile(bool mfwenable, masterAttributes& attr) {
|
|||||||
numActualPacketsInFile = 0;
|
numActualPacketsInFile = 0;
|
||||||
|
|
||||||
if (mfwenable && master && (*detIndex==0)) {
|
if (mfwenable && master && (*detIndex==0)) {
|
||||||
masterFileName = BinaryFileStatic::CreateMasterFileName(*filePath,
|
|
||||||
*fileNamePrefix, *fileIndex);
|
std::ostringstream os;
|
||||||
|
os << *filePath << "/" << *fileNamePrefix << "_master"
|
||||||
|
<< "_" << *fileIndex << ".raw";
|
||||||
|
masterFileName = os.str();
|
||||||
if(!(*silentMode)) {
|
if(!(*silentMode)) {
|
||||||
LOG(logINFO) << "Master File: " << masterFileName;
|
LOG(logINFO) << "Master File: " << masterFileName;
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "File.h"
|
#include "File.h"
|
||||||
#include "BinaryFileStatic.h"
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
@ -38,39 +37,18 @@ class BinaryFile : private virtual slsDetectorDefs, public File, public BinaryFi
|
|||||||
int* nd, std::string* fname, std::string* fpath, uint64_t* findex, bool* owenable,
|
int* nd, std::string* fname, std::string* fpath, uint64_t* findex, bool* owenable,
|
||||||
int* dindex, int* nunits, uint64_t* nf, uint32_t* dr, uint32_t* portno,
|
int* dindex, int* nunits, uint64_t* nf, uint32_t* dr, uint32_t* portno,
|
||||||
bool* smode);
|
bool* smode);
|
||||||
|
|
||||||
/**
|
|
||||||
* Destructor
|
|
||||||
*/
|
|
||||||
~BinaryFile();
|
~BinaryFile();
|
||||||
|
|
||||||
/**
|
|
||||||
* Print all member values
|
|
||||||
*/
|
|
||||||
void PrintMembers(TLogLevel level = logDEBUG1) override;
|
void PrintMembers(TLogLevel level = logDEBUG1) override;
|
||||||
|
|
||||||
/**
|
|
||||||
* Create file
|
|
||||||
*/
|
|
||||||
void CreateFile() override;
|
void CreateFile() override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create master file
|
* Create master file
|
||||||
* @param mfwenable master file write enable
|
* @param mfwenable master file write enable
|
||||||
* @param attr master file attributes
|
* @param attr master file attributes
|
||||||
*/
|
*/
|
||||||
void CreateMasterFile(bool mfwenable, masterAttributes& attr) override;
|
void CreateMasterFile(bool mfwenable, masterAttributes& attr) override;
|
||||||
|
|
||||||
/**
|
|
||||||
* Close Current File
|
|
||||||
*/
|
|
||||||
void CloseCurrentFile() override;
|
void CloseCurrentFile() override;
|
||||||
|
|
||||||
/**
|
|
||||||
* Close all Files
|
|
||||||
*/
|
|
||||||
void CloseAllFiles() override;
|
void CloseAllFiles() override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write data to file
|
* Write data to file
|
||||||
* @param buffer buffer to write from
|
* @param buffer buffer to write from
|
||||||
@ -80,29 +58,16 @@ class BinaryFile : private virtual slsDetectorDefs, public File, public BinaryFi
|
|||||||
*/
|
*/
|
||||||
void WriteToFile(char* buffer, int buffersize, uint64_t fnum, uint32_t nump) override;
|
void WriteToFile(char* buffer, int buffersize, uint64_t fnum, uint32_t nump) override;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
/**
|
fileFormat GetFileType() override;
|
||||||
* Get Type
|
int WriteData(char* buf, int bsize);
|
||||||
* @return type
|
|
||||||
*/
|
|
||||||
fileFormat GetFileType() override;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** File Descriptor */
|
|
||||||
FILE* filefd;
|
FILE* filefd;
|
||||||
|
|
||||||
/** Master File Descriptor */
|
|
||||||
static FILE* masterfd;
|
static FILE* masterfd;
|
||||||
|
|
||||||
/** Number of frames in file */
|
|
||||||
uint32_t numFramesInFile;
|
uint32_t numFramesInFile;
|
||||||
|
|
||||||
/** Number of actual packets caught in file */
|
|
||||||
uint64_t numActualPacketsInFile;
|
uint64_t numActualPacketsInFile;
|
||||||
|
const int maxMasterFileSize;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -15,80 +15,12 @@
|
|||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#define MAX_MASTER_FILE_LENGTH 2000
|
|
||||||
|
|
||||||
|
|
||||||
class BinaryFileStatic {
|
class BinaryFileStatic {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/** Constructor */
|
|
||||||
BinaryFileStatic(){};
|
|
||||||
/** Destructor */
|
|
||||||
virtual ~BinaryFileStatic(){};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create File Name in format fpath/fnameprefix_fx_dy_z.raw,
|
|
||||||
* where x is fnum, y is (dindex * numunits + unitindex) and z is findex
|
|
||||||
* @param fpath file path
|
|
||||||
* @param fnameprefix file name prefix
|
|
||||||
* @param findex file index
|
|
||||||
* @param subfindex sub file index
|
|
||||||
* @param dindex readout index
|
|
||||||
* @param numunits number of units per readout. eg. eiger has 2 udp units per readout
|
|
||||||
* @param unitindex unit index
|
|
||||||
* @returns complete file name created
|
|
||||||
*/
|
|
||||||
static std::string CreateFileName(std::string fpath, std::string fprefix,
|
|
||||||
uint64_t findex, uint64_t subfindex,
|
|
||||||
int dindex, int numunits = 1,
|
|
||||||
int unitindex = 0) {
|
|
||||||
std::ostringstream os;
|
|
||||||
os << fpath << "/" << fprefix << "_d"
|
|
||||||
<< (dindex * numunits + unitindex) << "_f" << subfindex << '_'
|
|
||||||
<< findex << ".raw";
|
|
||||||
return os.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create file names for master file
|
|
||||||
* @param fpath file path
|
|
||||||
* @param fnameprefix file name prefix
|
|
||||||
* @param findex file index
|
|
||||||
* @returns master file name
|
|
||||||
*/
|
|
||||||
static std::string CreateMasterFileName(std::string fpath, std::string fnameprefix,
|
|
||||||
uint64_t findex) {
|
|
||||||
std::ostringstream os;
|
|
||||||
os << fpath << "/" << fnameprefix << "_master"
|
|
||||||
<< "_" << findex << ".raw";
|
|
||||||
return os.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Close File
|
|
||||||
* @param fd file pointer
|
|
||||||
*/
|
|
||||||
static void CloseDataFile(FILE*& fd)
|
|
||||||
{
|
|
||||||
if (fd)
|
|
||||||
fclose(fd);
|
|
||||||
fd = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Write data to file
|
|
||||||
* @param fd file pointer
|
|
||||||
* @param buf buffer to write from
|
|
||||||
* @param bsize size of buffer
|
|
||||||
* @returns number of elements written
|
|
||||||
*/
|
|
||||||
static int WriteDataFile(FILE* fd, char* buf, int bsize)
|
|
||||||
{
|
|
||||||
if (!fd)
|
|
||||||
return 0;
|
|
||||||
return fwrite(buf, 1, bsize, fd);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -188,27 +120,3 @@ class BinaryFileStatic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create File
|
|
||||||
* @param fd file pointer
|
|
||||||
* @param owenable overwrite enable
|
|
||||||
* @param fname complete file name
|
|
||||||
* @returns 0 for success and 1 for fail
|
|
||||||
*/
|
|
||||||
static void CreateDataFile(FILE*& fd, bool owenable, std::string fname)
|
|
||||||
{
|
|
||||||
if(!owenable){
|
|
||||||
if (NULL == (fd = fopen((const char *) fname.c_str(), "wx"))){
|
|
||||||
fd = 0;
|
|
||||||
throw sls::RuntimeError("Could not create/overwrite file " + fname);
|
|
||||||
}
|
|
||||||
} else if (NULL == (fd = fopen((const char *) fname.c_str(), "w"))){
|
|
||||||
fd = 0;
|
|
||||||
throw sls::RuntimeError("Could not create file " + fname);
|
|
||||||
}
|
|
||||||
//setting to no file buffering
|
|
||||||
setvbuf(fd, NULL, _IONBF, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user