mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-24 23:30:03 +02:00
slsReceiverSoftware: bitset storage in case the libarary changes contiguous representation, also changed hdf5 representation from 512 byte (to_string) to just passing char* to keep at 64 bytes
This commit is contained in:
parent
e9cc91698e
commit
73fcef5f6d
@ -86,10 +86,9 @@ class BinaryFileStatic {
|
|||||||
* @param fd file pointer
|
* @param fd file pointer
|
||||||
* @param buf buffer to write from
|
* @param buf buffer to write from
|
||||||
* @param bsize size of buffer
|
* @param bsize size of buffer
|
||||||
* @param fnum current image number
|
|
||||||
* @returns number of elements written
|
* @returns number of elements written
|
||||||
*/
|
*/
|
||||||
static int WriteDataFile(FILE* fd, char* buf, int bsize, uint64_t fnum)
|
static int WriteDataFile(FILE* fd, char* buf, int bsize)
|
||||||
{
|
{
|
||||||
if (!fd)
|
if (!fd)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -22,6 +22,7 @@ using namespace H5;
|
|||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <stdlib.h> //malloc
|
#include <stdlib.h> //malloc
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <cstring> //memset
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
class HDF5FileStatic: public virtual slsReceiverDefs {
|
class HDF5FileStatic: public virtual slsReceiverDefs {
|
||||||
@ -219,7 +220,23 @@ public:
|
|||||||
dset_para[10]->write(&header.roundRNumber, parameterDataTypes[10], memspace, *dspace_para);
|
dset_para[10]->write(&header.roundRNumber, parameterDataTypes[10], memspace, *dspace_para);
|
||||||
dset_para[11]->write(&header.detType, parameterDataTypes[11], memspace, *dspace_para);
|
dset_para[11]->write(&header.detType, parameterDataTypes[11], memspace, *dspace_para);
|
||||||
dset_para[12]->write(&header.version, parameterDataTypes[12], memspace, *dspace_para);
|
dset_para[12]->write(&header.version, parameterDataTypes[12], memspace, *dspace_para);
|
||||||
dset_para[13]->write(rheader->packetsMask.to_string().c_str(), parameterDataTypes[13], memspace, *dspace_para);
|
|
||||||
|
// contiguous bitset
|
||||||
|
if (sizeof(sls_bitset) == sizeof(bitset_storage)) {
|
||||||
|
dset_para[13]->write((char*)&(rheader->packetsMask), parameterDataTypes[13], memspace, *dspace_para);
|
||||||
|
}
|
||||||
|
|
||||||
|
// not contiguous bitset
|
||||||
|
else {
|
||||||
|
// get contiguous representation of bit mask
|
||||||
|
bitset_storage storage;
|
||||||
|
memset(storage, 0 , sizeof(bitset_storage));
|
||||||
|
sls_bitset bits = rheader->packetsMask;
|
||||||
|
for (int i = 0; i < MAX_NUM_PACKETS; ++i)
|
||||||
|
storage[i >> 3] |= (bits[i] << (i & 7));
|
||||||
|
// write bitmask
|
||||||
|
dset_para[13]->write((char*)storage, parameterDataTypes[13], memspace, *dspace_para);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch(Exception error){
|
catch(Exception error){
|
||||||
cprintf(RED,"Error in writing parameters to file in object %d\n",ind);
|
cprintf(RED,"Error in writing parameters to file in object %d\n",ind);
|
||||||
|
@ -169,11 +169,14 @@ public:
|
|||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
#define MAX_NUM_PACKETS 512
|
#define MAX_NUM_PACKETS 512
|
||||||
|
|
||||||
|
typedef std::bitset<MAX_NUM_PACKETS> sls_bitset;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
sls_detector_header detHeader; /**< is the detector header */
|
sls_detector_header detHeader; /**< is the detector header */
|
||||||
std::bitset<MAX_NUM_PACKETS> packetsMask; /**< is the packets caught bit mask */
|
sls_bitset packetsMask; /**< is the packets caught bit mask */
|
||||||
} sls_receiver_header;
|
} sls_receiver_header;
|
||||||
|
|
||||||
|
typedef uint8_t bitset_storage[MAX_NUM_PACKETS/8];
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
/**
|
/**
|
||||||
|
@ -77,11 +77,42 @@ int BinaryFile::WriteToFile(char* buffer, int buffersize, uint64_t fnum, uint32_
|
|||||||
}
|
}
|
||||||
numFramesInFile++;
|
numFramesInFile++;
|
||||||
numActualPacketsInFile += nump;
|
numActualPacketsInFile += nump;
|
||||||
if (BinaryFileStatic::WriteDataFile(filefd, buffer, buffersize, fnum) == buffersize)
|
|
||||||
return OK;
|
// write to file
|
||||||
cprintf(RED,"%d Error: Write to file failed for image number %lld\n", index, (long long int)fnum);
|
int ret = 0;
|
||||||
|
|
||||||
|
// contiguous bitset
|
||||||
|
if (sizeof(sls_bitset) == sizeof(bitset_storage)) {
|
||||||
|
ret = BinaryFileStatic::WriteDataFile(filefd, buffer, buffersize);
|
||||||
|
}
|
||||||
|
|
||||||
|
// not contiguous bitset
|
||||||
|
else {
|
||||||
|
// write detector header
|
||||||
|
ret = BinaryFileStatic::WriteDataFile(filefd, buffer, sizeof(sls_detector_header));
|
||||||
|
|
||||||
|
// get contiguous representation of bit mask
|
||||||
|
bitset_storage storage;
|
||||||
|
memset(storage, 0 , sizeof(bitset_storage));
|
||||||
|
sls_bitset bits = *(sls_bitset*)(buffer + sizeof(sls_detector_header));
|
||||||
|
for (int i = 0; i < MAX_NUM_PACKETS; ++i)
|
||||||
|
storage[i >> 3] |= (bits[i] << (i & 7));
|
||||||
|
// write bitmask
|
||||||
|
ret += BinaryFileStatic::WriteDataFile(filefd, (char*)storage, sizeof(bitset_storage));
|
||||||
|
|
||||||
|
// write data
|
||||||
|
ret += BinaryFileStatic::WriteDataFile(filefd,
|
||||||
|
buffer + sizeof(sls_detector_header), buffersize - sizeof(sls_receiver_header));
|
||||||
|
}
|
||||||
|
|
||||||
|
// if write error
|
||||||
|
if (ret != buffersize) {
|
||||||
|
cprintf(RED,"%d Error: Write to file failed for image number %lld\n",
|
||||||
|
index, (long long int)fnum);
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int BinaryFile::CreateMasterFile(bool en, uint32_t size,
|
int BinaryFile::CreateMasterFile(bool en, uint32_t size,
|
||||||
|
@ -375,16 +375,10 @@ void DataProcessor::ProcessAnImage(char* buf) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// frame padding
|
// frame padding
|
||||||
|
|
||||||
//std::string mystring = rheader->packetsMask.to_string<char,std::string::traits_type,std::string::allocator_type>();
|
|
||||||
// cprintf(BLUE, "%d: fnum:%llu mystring: %s nump:%u missing:%u \n",index, (long long unsigned int) fnum, mystring.c_str(), nump, generalData->packetsPerFrame-nump);
|
|
||||||
//if(!index)cprintf(BLUE, "%d: fnum:%llu nump:%u missing:%u \n",index, (long long unsigned int) fnum, nump, generalData->packetsPerFrame-nump);
|
|
||||||
|
|
||||||
|
|
||||||
if (*framePadding && nump < generalData->packetsPerFrame)
|
if (*framePadding && nump < generalData->packetsPerFrame)
|
||||||
PadMissingPackets(buf);
|
PadMissingPackets(buf);
|
||||||
|
|
||||||
|
// normal call back
|
||||||
if (rawDataReadyCallBack) {
|
if (rawDataReadyCallBack) {
|
||||||
rawDataReadyCallBack(
|
rawDataReadyCallBack(
|
||||||
(char*)rheader,
|
(char*)rheader,
|
||||||
@ -393,7 +387,8 @@ void DataProcessor::ProcessAnImage(char* buf) {
|
|||||||
pRawDataReady);
|
pRawDataReady);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (rawDataModifyReadyCallBack) {cprintf(BG_GREEN,"Calling rawdatamodify\n");
|
// call back with modified size
|
||||||
|
else if (rawDataModifyReadyCallBack) {
|
||||||
uint32_t revsize = (uint32_t)(*((uint32_t*)buf));
|
uint32_t revsize = (uint32_t)(*((uint32_t*)buf));
|
||||||
rawDataModifyReadyCallBack(
|
rawDataModifyReadyCallBack(
|
||||||
(char*)rheader,
|
(char*)rheader,
|
||||||
@ -403,7 +398,7 @@ void DataProcessor::ProcessAnImage(char* buf) {
|
|||||||
(*((uint32_t*)buf)) = revsize;
|
(*((uint32_t*)buf)) = revsize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// write to file
|
||||||
if (file)
|
if (file)
|
||||||
file->WriteToFile(buf + FIFO_HEADER_NUMBYTES,
|
file->WriteToFile(buf + FIFO_HEADER_NUMBYTES,
|
||||||
sizeof(sls_receiver_header) + (uint32_t)(*((uint32_t*)buf)),
|
sizeof(sls_receiver_header) + (uint32_t)(*((uint32_t*)buf)),
|
||||||
@ -475,12 +470,14 @@ void DataProcessor::PadMissingPackets(char* buf) {
|
|||||||
uint32_t pperFrame = generalData->packetsPerFrame;
|
uint32_t pperFrame = generalData->packetsPerFrame;
|
||||||
sls_receiver_header* header = (sls_receiver_header*) (buf + FIFO_HEADER_NUMBYTES);
|
sls_receiver_header* header = (sls_receiver_header*) (buf + FIFO_HEADER_NUMBYTES);
|
||||||
uint32_t nmissing = pperFrame - header->detHeader.packetNumber;
|
uint32_t nmissing = pperFrame - header->detHeader.packetNumber;
|
||||||
bitset<512> pmask = header->packetsMask;
|
sls_bitset pmask = header->packetsMask;
|
||||||
|
|
||||||
uint32_t dsize = generalData->dataSize;
|
uint32_t dsize = generalData->dataSize;
|
||||||
uint32_t fifohsize = generalData->fifoBufferHeaderSize;
|
uint32_t fifohsize = generalData->fifoBufferHeaderSize;
|
||||||
uint32_t corrected_dsize = dsize - ((pperFrame * dsize) - generalData->imageSize);
|
uint32_t corrected_dsize = dsize - ((pperFrame * dsize) - generalData->imageSize);
|
||||||
|
#ifdef VERBOSE
|
||||||
|
cprintf(RED,"bitmask:%s\n", pmask.to_string().c_str());
|
||||||
|
#endif
|
||||||
for (unsigned int pnum = 0; pnum < pperFrame; ++pnum) {
|
for (unsigned int pnum = 0; pnum < pperFrame; ++pnum) {
|
||||||
|
|
||||||
// not missing packet
|
// not missing packet
|
||||||
|
@ -87,7 +87,7 @@ HDF5File::HDF5File(int ind, uint32_t* maxf,
|
|||||||
parameterDataTypes.push_back(PredType::STD_U8LE);
|
parameterDataTypes.push_back(PredType::STD_U8LE);
|
||||||
|
|
||||||
parameterNames.push_back("packets caught bit mask");
|
parameterNames.push_back("packets caught bit mask");
|
||||||
StrType strdatatype(PredType::C_S1, MAX_NUM_PACKETS);
|
StrType strdatatype(PredType::C_S1, sizeof(bitset_storage));
|
||||||
parameterDataTypes.push_back(strdatatype);
|
parameterDataTypes.push_back(strdatatype);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user