mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-22 03:40:04 +02:00
binary master attributes done, hdf5 WIP
This commit is contained in:
parent
68c0f76bd9
commit
ea2e7839d0
@ -166,17 +166,8 @@ void BinaryFile::CreateMasterFile(bool masterFileWriteEnable,
|
|||||||
"(with overwrite enable) " +
|
"(with overwrite enable) " +
|
||||||
masterFileName);
|
masterFileName);
|
||||||
}
|
}
|
||||||
// create master file data
|
|
||||||
std::string strAttributes = attr->GetBinaryMasterAttributes();
|
attr->WriteMasterBinaryAttributes(masterfd);
|
||||||
char message[maxMasterFileSize];
|
|
||||||
memset(message, 0, maxMasterFileSize);
|
|
||||||
sls::strcpy_safe(message, strAttributes.c_str());
|
|
||||||
// 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)
|
if (masterfd)
|
||||||
fclose(masterfd);
|
fclose(masterfd);
|
||||||
masterfd = nullptr;
|
masterfd = nullptr;
|
||||||
|
@ -55,7 +55,4 @@ class BinaryFile : private virtual slsDetectorDefs, public File {
|
|||||||
static FILE *masterfd;
|
static FILE *masterfd;
|
||||||
uint32_t numFramesInFile = 0;
|
uint32_t numFramesInFile = 0;
|
||||||
uint64_t numActualPacketsInFile = 0;
|
uint64_t numActualPacketsInFile = 0;
|
||||||
// Make sure this is known at compile time
|
|
||||||
// TODO! Later away from stack allocation of message
|
|
||||||
static constexpr size_t maxMasterFileSize = 2000;
|
|
||||||
};
|
};
|
@ -5,6 +5,7 @@
|
|||||||
***********************************************/
|
***********************************************/
|
||||||
#include "HDF5File.h"
|
#include "HDF5File.h"
|
||||||
#include "Fifo.h"
|
#include "Fifo.h"
|
||||||
|
#include "MasterAttributes.h"
|
||||||
#include "receiver_defs.h"
|
#include "receiver_defs.h"
|
||||||
|
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
@ -152,7 +153,7 @@ void HDF5File::WriteToFile(char *buffer, int bufferSize,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void HDF5File::CreateMasterFile(bool masterFileWriteEnable,
|
void HDF5File::CreateMasterFile(bool masterFileWriteEnable,
|
||||||
masterAttributes &masterFileAttributes) {
|
MasterAttributes &attr) {
|
||||||
|
|
||||||
// beginning of every acquisition
|
// beginning of every acquisition
|
||||||
numFramesInFile = 0;
|
numFramesInFile = 0;
|
||||||
@ -161,7 +162,7 @@ void HDF5File::CreateMasterFile(bool masterFileWriteEnable,
|
|||||||
|
|
||||||
if (masterFileWriteEnable && master) {
|
if (masterFileWriteEnable && master) {
|
||||||
virtualfd = 0;
|
virtualfd = 0;
|
||||||
CreateMasterDataFile(masterFileAttributes);
|
CreateMasterDataFile(attr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -458,7 +459,7 @@ void HDF5File::CreateDataFile() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HDF5File::CreateMasterDataFile(masterAttributes &masterFileAttributes) {
|
void HDF5File::CreateMasterDataFile(MasterAttributes &attr) {
|
||||||
|
|
||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
os << *filePath << "/" << *fileNamePrefix << "_master"
|
os << *filePath << "/" << *fileNamePrefix << "_master"
|
||||||
|
@ -51,7 +51,7 @@ class HDF5File : private virtual slsDetectorDefs, public File {
|
|||||||
void WriteToFile(char *buffer, int bufferSize, uint64_t currentFrameNumber,
|
void WriteToFile(char *buffer, int bufferSize, uint64_t currentFrameNumber,
|
||||||
uint32_t numPacketsCaught);
|
uint32_t numPacketsCaught);
|
||||||
void CreateMasterFile(bool masterFileWriteEnable,
|
void CreateMasterFile(bool masterFileWriteEnable,
|
||||||
masterAttributes &masterFileAttributes);
|
MasterAttributes &attr) override;
|
||||||
void EndofAcquisition(bool anyPacketsCaught, uint64_t numImagesCaught);
|
void EndofAcquisition(bool anyPacketsCaught, uint64_t numImagesCaught);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -61,7 +61,7 @@ class HDF5File : private virtual slsDetectorDefs, public File {
|
|||||||
sls_receiver_header *rheader);
|
sls_receiver_header *rheader);
|
||||||
void ExtendDataset();
|
void ExtendDataset();
|
||||||
void CreateDataFile();
|
void CreateDataFile();
|
||||||
void CreateMasterDataFile(masterAttributes &masterFileAttributes);
|
void CreateMasterDataFile(MasterAttributes &attr);
|
||||||
void CreateVirtualDataFile(uint32_t maxFramesPerFile, uint64_t numf);
|
void CreateVirtualDataFile(uint32_t maxFramesPerFile, uint64_t numf);
|
||||||
void LinkVirtualInMaster(std::string fname, std::string dsetname);
|
void LinkVirtualInMaster(std::string fname, std::string dsetname);
|
||||||
hid_t GetDataTypeinC(DataType dtype);
|
hid_t GetDataTypeinC(DataType dtype);
|
||||||
|
@ -3,6 +3,14 @@
|
|||||||
#include "ToString.h"
|
#include "ToString.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "sls_detector_defs.h"
|
#include "sls_detector_defs.h"
|
||||||
|
|
||||||
|
#ifdef HDF5C
|
||||||
|
#include "H5Cpp.h"
|
||||||
|
#ifndef H5_NO_NAMESPACE
|
||||||
|
using namespace H5;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
using ns = std::chrono::nanoseconds;
|
using ns = std::chrono::nanoseconds;
|
||||||
|
|
||||||
@ -11,7 +19,6 @@ using ns = std::chrono::nanoseconds;
|
|||||||
#define BINARY_WRITER_VERSION (6.1) // 1 decimal places
|
#define BINARY_WRITER_VERSION (6.1) // 1 decimal places
|
||||||
|
|
||||||
class MasterAttributes {
|
class MasterAttributes {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
slsDetectorDefs::detectorType detType{slsDetectorDefs::GENERIC};
|
slsDetectorDefs::detectorType detType{slsDetectorDefs::GENERIC};
|
||||||
uint32_t imageSize{0};
|
uint32_t imageSize{0};
|
||||||
@ -42,7 +49,12 @@ class MasterAttributes {
|
|||||||
MasterAttributes(){};
|
MasterAttributes(){};
|
||||||
virtual ~MasterAttributes(){};
|
virtual ~MasterAttributes(){};
|
||||||
|
|
||||||
virtual std::string GetBinaryMasterAttributes() {
|
virtual void WriteMasterBinaryAttributes(FILE *fd) {
|
||||||
|
LOG(logERROR) << "WriteMasterBinaryAttributes should have been called "
|
||||||
|
"by a child class";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string GetBinaryMasterAttributes() {
|
||||||
time_t t = time(nullptr);
|
time_t t = time(nullptr);
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << "Version : " << std::setprecision(2)
|
oss << "Version : " << std::setprecision(2)
|
||||||
@ -56,39 +68,47 @@ class MasterAttributes {
|
|||||||
return oss.str();
|
return oss.str();
|
||||||
};
|
};
|
||||||
|
|
||||||
std::string GetBinaryFrameHeaderFormat() {
|
void WriteBinaryAttributes(FILE *fd, std::string message) {
|
||||||
return std::string("\n#Frame Header\n"
|
message += std::string("\n#Frame Header\n"
|
||||||
"Frame Number : 8 bytes\n"
|
"Frame Number : 8 bytes\n"
|
||||||
"SubFrame Number/ExpLength : 4 bytes\n"
|
"SubFrame Number/ExpLength : 4 bytes\n"
|
||||||
"Packet Number : 4 bytes\n"
|
"Packet Number : 4 bytes\n"
|
||||||
"Bunch ID : 8 bytes\n"
|
"Bunch ID : 8 bytes\n"
|
||||||
"Timestamp : 8 bytes\n"
|
"Timestamp : 8 bytes\n"
|
||||||
"Module Id : 2 bytes\n"
|
"Module Id : 2 bytes\n"
|
||||||
"Row : 2 bytes\n"
|
"Row : 2 bytes\n"
|
||||||
"Column : 2 bytes\n"
|
"Column : 2 bytes\n"
|
||||||
"Reserved : 2 bytes\n"
|
"Reserved : 2 bytes\n"
|
||||||
"Debug : 4 bytes\n"
|
"Debug : 4 bytes\n"
|
||||||
"Round Robin Number : 2 bytes\n"
|
"Round Robin Number : 2 bytes\n"
|
||||||
"Detector Type : 1 byte\n"
|
"Detector Type : 1 byte\n"
|
||||||
"Header Version : 1 byte\n"
|
"Header Version : 1 byte\n"
|
||||||
"Packets Caught Mask : 64 bytes\n");
|
"Packets Caught Mask : 64 bytes\n");
|
||||||
|
|
||||||
|
if (fwrite((void *)message.c_str(), 1, message.length(), fd) !=
|
||||||
|
message.length()) {
|
||||||
|
throw sls::RuntimeError(
|
||||||
|
"Master binary file incorrect number of bytes written to file");
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// hdf5
|
#ifdef HDF5C
|
||||||
|
virtual void Write
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
class GotthardMasterAttributes : public MasterAttributes {
|
class GotthardMasterAttributes : public MasterAttributes {
|
||||||
public:
|
public:
|
||||||
GotthardMasterAttributes(){};
|
GotthardMasterAttributes(){};
|
||||||
|
|
||||||
std::string GetBinaryMasterAttributes() override {
|
void WriteMasterBinaryAttributes(FILE *fd) override {
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << MasterAttributes::GetBinaryMasterAttributes()
|
oss << MasterAttributes::GetBinaryMasterAttributes()
|
||||||
<< "Exptime : " << sls::ToString(exptime) << '\n'
|
<< "Exptime : " << sls::ToString(exptime) << '\n'
|
||||||
<< "Period : " << sls::ToString(period) << '\n'
|
<< "Period : " << sls::ToString(period) << '\n'
|
||||||
<< "Roi (xmin, xmax) : " << sls::ToString(roi) << '\n'
|
<< "Roi (xmin, xmax) : " << sls::ToString(roi) << '\n';
|
||||||
<< GetBinaryFrameHeaderFormat();
|
std::string message = oss.str();
|
||||||
return oss.str();
|
MasterAttributes::WriteBinaryAttributes(fd, message);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -96,13 +116,13 @@ class JungfrauMasterAttributes : public MasterAttributes {
|
|||||||
public:
|
public:
|
||||||
JungfrauMasterAttributes(){};
|
JungfrauMasterAttributes(){};
|
||||||
|
|
||||||
std::string GetBinaryMasterAttributes() override {
|
void WriteMasterBinaryAttributes(FILE *fd) override {
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << MasterAttributes::GetBinaryMasterAttributes()
|
oss << MasterAttributes::GetBinaryMasterAttributes()
|
||||||
<< "Exptime : " << sls::ToString(exptime) << '\n'
|
<< "Exptime : " << sls::ToString(exptime) << '\n'
|
||||||
<< "Period : " << sls::ToString(period) << '\n'
|
<< "Period : " << sls::ToString(period) << '\n';
|
||||||
<< GetBinaryFrameHeaderFormat();
|
std::string message = oss.str();
|
||||||
return oss.str();
|
MasterAttributes::WriteBinaryAttributes(fd, message);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -110,7 +130,7 @@ class EigerMasterAttributes : public MasterAttributes {
|
|||||||
public:
|
public:
|
||||||
EigerMasterAttributes(){};
|
EigerMasterAttributes(){};
|
||||||
|
|
||||||
std::string GetBinaryMasterAttributes() override {
|
void WriteMasterBinaryAttributes(FILE *fd) override {
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << MasterAttributes::GetBinaryMasterAttributes()
|
oss << MasterAttributes::GetBinaryMasterAttributes()
|
||||||
<< "Dynamic Range : " << dynamicRange << '\n'
|
<< "Dynamic Range : " << dynamicRange << '\n'
|
||||||
@ -121,9 +141,9 @@ class EigerMasterAttributes : public MasterAttributes {
|
|||||||
<< '\n'
|
<< '\n'
|
||||||
<< "SubPeriod : " << sls::ToString(subPeriod)
|
<< "SubPeriod : " << sls::ToString(subPeriod)
|
||||||
<< '\n'
|
<< '\n'
|
||||||
<< "Quad : " << quad << '\n'
|
<< "Quad : " << quad << '\n';
|
||||||
<< GetBinaryFrameHeaderFormat();
|
std::string message = oss.str();
|
||||||
return oss.str();
|
MasterAttributes::WriteBinaryAttributes(fd, message);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -131,7 +151,7 @@ class Mythen3MasterAttributes : public MasterAttributes {
|
|||||||
public:
|
public:
|
||||||
Mythen3MasterAttributes(){};
|
Mythen3MasterAttributes(){};
|
||||||
|
|
||||||
std::string GetBinaryMasterAttributes() override {
|
void WriteMasterBinaryAttributes(FILE *fd) override {
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << MasterAttributes::GetBinaryMasterAttributes()
|
oss << MasterAttributes::GetBinaryMasterAttributes()
|
||||||
<< "Dynamic Range : " << dynamicRange << '\n'
|
<< "Dynamic Range : " << dynamicRange << '\n'
|
||||||
@ -149,9 +169,9 @@ class Mythen3MasterAttributes : public MasterAttributes {
|
|||||||
<< '\n'
|
<< '\n'
|
||||||
<< "GateDelay3 : " << sls::ToString(gateDelay3)
|
<< "GateDelay3 : " << sls::ToString(gateDelay3)
|
||||||
<< '\n'
|
<< '\n'
|
||||||
<< "Gates : " << gates << '\n'
|
<< "Gates : " << gates << '\n';
|
||||||
<< GetBinaryFrameHeaderFormat();
|
std::string message = oss.str();
|
||||||
return oss.str();
|
MasterAttributes::WriteBinaryAttributes(fd, message);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -159,13 +179,13 @@ class Gotthard2MasterAttributes : public MasterAttributes {
|
|||||||
public:
|
public:
|
||||||
Gotthard2MasterAttributes(){};
|
Gotthard2MasterAttributes(){};
|
||||||
|
|
||||||
std::string GetBinaryMasterAttributes() override {
|
void WriteMasterBinaryAttributes(FILE *fd) override {
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << MasterAttributes::GetBinaryMasterAttributes()
|
oss << MasterAttributes::GetBinaryMasterAttributes()
|
||||||
<< "Exptime : " << sls::ToString(exptime) << '\n'
|
<< "Exptime : " << sls::ToString(exptime) << '\n'
|
||||||
<< "Period : " << sls::ToString(period) << '\n'
|
<< "Period : " << sls::ToString(period) << '\n';
|
||||||
<< GetBinaryFrameHeaderFormat();
|
std::string message = oss.str();
|
||||||
return oss.str();
|
MasterAttributes::WriteBinaryAttributes(fd, message);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -173,16 +193,16 @@ class MoenchMasterAttributes : public MasterAttributes {
|
|||||||
public:
|
public:
|
||||||
MoenchMasterAttributes(){};
|
MoenchMasterAttributes(){};
|
||||||
|
|
||||||
std::string GetBinaryMasterAttributes() override {
|
void WriteMasterBinaryAttributes(FILE *fd) override {
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << MasterAttributes::GetBinaryMasterAttributes()
|
oss << MasterAttributes::GetBinaryMasterAttributes()
|
||||||
<< "Exptime : " << sls::ToString(exptime) << '\n'
|
<< "Exptime : " << sls::ToString(exptime) << '\n'
|
||||||
<< "Period : " << sls::ToString(period) << '\n'
|
<< "Period : " << sls::ToString(period) << '\n'
|
||||||
<< "Ten Giga : " << tenGiga << '\n'
|
<< "Ten Giga : " << tenGiga << '\n'
|
||||||
<< "ADC Mask : " << sls::ToStringHex(adcmask)
|
<< "ADC Mask : " << sls::ToStringHex(adcmask)
|
||||||
<< '\n'
|
<< '\n';
|
||||||
<< GetBinaryFrameHeaderFormat();
|
std::string message = oss.str();
|
||||||
return oss.str();
|
MasterAttributes::WriteBinaryAttributes(fd, message);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -190,7 +210,7 @@ class CtbMasterAttributes : public MasterAttributes {
|
|||||||
public:
|
public:
|
||||||
CtbMasterAttributes(){};
|
CtbMasterAttributes(){};
|
||||||
|
|
||||||
std::string GetBinaryMasterAttributes() override {
|
void WriteMasterBinaryAttributes(FILE *fd) override {
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << MasterAttributes::GetBinaryMasterAttributes()
|
oss << MasterAttributes::GetBinaryMasterAttributes()
|
||||||
<< "Exptime : " << sls::ToString(exptime) << '\n'
|
<< "Exptime : " << sls::ToString(exptime) << '\n'
|
||||||
@ -201,8 +221,8 @@ class CtbMasterAttributes : public MasterAttributes {
|
|||||||
<< "Analog Flag : " << analog << '\n'
|
<< "Analog Flag : " << analog << '\n'
|
||||||
<< "Digital Flag : " << digital << '\n'
|
<< "Digital Flag : " << digital << '\n'
|
||||||
<< "Dbit Offset : " << dbitoffset << '\n'
|
<< "Dbit Offset : " << dbitoffset << '\n'
|
||||||
<< "Dbit Bitset : " << dbitlist << '\n'
|
<< "Dbit Bitset : " << dbitlist << '\n';
|
||||||
<< GetBinaryFrameHeaderFormat();
|
std::string message = oss.str();
|
||||||
return oss.str();
|
MasterAttributes::WriteBinaryAttributes(fd, message);
|
||||||
};
|
};
|
||||||
};
|
};
|
Loading…
x
Reference in New Issue
Block a user