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) " +
|
||||
masterFileName);
|
||||
}
|
||||
// create master file data
|
||||
std::string strAttributes = attr->GetBinaryMasterAttributes();
|
||||
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");
|
||||
}
|
||||
|
||||
attr->WriteMasterBinaryAttributes(masterfd);
|
||||
if (masterfd)
|
||||
fclose(masterfd);
|
||||
masterfd = nullptr;
|
||||
|
@ -55,7 +55,4 @@ class BinaryFile : private virtual slsDetectorDefs, public File {
|
||||
static FILE *masterfd;
|
||||
uint32_t numFramesInFile = 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 "Fifo.h"
|
||||
#include "MasterAttributes.h"
|
||||
#include "receiver_defs.h"
|
||||
|
||||
#include <iomanip>
|
||||
@ -152,7 +153,7 @@ void HDF5File::WriteToFile(char *buffer, int bufferSize,
|
||||
}
|
||||
|
||||
void HDF5File::CreateMasterFile(bool masterFileWriteEnable,
|
||||
masterAttributes &masterFileAttributes) {
|
||||
MasterAttributes &attr) {
|
||||
|
||||
// beginning of every acquisition
|
||||
numFramesInFile = 0;
|
||||
@ -161,7 +162,7 @@ void HDF5File::CreateMasterFile(bool masterFileWriteEnable,
|
||||
|
||||
if (masterFileWriteEnable && master) {
|
||||
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;
|
||||
os << *filePath << "/" << *fileNamePrefix << "_master"
|
||||
|
@ -51,7 +51,7 @@ class HDF5File : private virtual slsDetectorDefs, public File {
|
||||
void WriteToFile(char *buffer, int bufferSize, uint64_t currentFrameNumber,
|
||||
uint32_t numPacketsCaught);
|
||||
void CreateMasterFile(bool masterFileWriteEnable,
|
||||
masterAttributes &masterFileAttributes);
|
||||
MasterAttributes &attr) override;
|
||||
void EndofAcquisition(bool anyPacketsCaught, uint64_t numImagesCaught);
|
||||
|
||||
private:
|
||||
@ -61,7 +61,7 @@ class HDF5File : private virtual slsDetectorDefs, public File {
|
||||
sls_receiver_header *rheader);
|
||||
void ExtendDataset();
|
||||
void CreateDataFile();
|
||||
void CreateMasterDataFile(masterAttributes &masterFileAttributes);
|
||||
void CreateMasterDataFile(MasterAttributes &attr);
|
||||
void CreateVirtualDataFile(uint32_t maxFramesPerFile, uint64_t numf);
|
||||
void LinkVirtualInMaster(std::string fname, std::string dsetname);
|
||||
hid_t GetDataTypeinC(DataType dtype);
|
||||
|
@ -3,6 +3,14 @@
|
||||
#include "ToString.h"
|
||||
#include "logger.h"
|
||||
#include "sls_detector_defs.h"
|
||||
|
||||
#ifdef HDF5C
|
||||
#include "H5Cpp.h"
|
||||
#ifndef H5_NO_NAMESPACE
|
||||
using namespace H5;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <chrono>
|
||||
using ns = std::chrono::nanoseconds;
|
||||
|
||||
@ -11,7 +19,6 @@ using ns = std::chrono::nanoseconds;
|
||||
#define BINARY_WRITER_VERSION (6.1) // 1 decimal places
|
||||
|
||||
class MasterAttributes {
|
||||
|
||||
public:
|
||||
slsDetectorDefs::detectorType detType{slsDetectorDefs::GENERIC};
|
||||
uint32_t imageSize{0};
|
||||
@ -42,7 +49,12 @@ class MasterAttributes {
|
||||
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);
|
||||
std::ostringstream oss;
|
||||
oss << "Version : " << std::setprecision(2)
|
||||
@ -56,8 +68,8 @@ class MasterAttributes {
|
||||
return oss.str();
|
||||
};
|
||||
|
||||
std::string GetBinaryFrameHeaderFormat() {
|
||||
return std::string("\n#Frame Header\n"
|
||||
void WriteBinaryAttributes(FILE *fd, std::string message) {
|
||||
message += std::string("\n#Frame Header\n"
|
||||
"Frame Number : 8 bytes\n"
|
||||
"SubFrame Number/ExpLength : 4 bytes\n"
|
||||
"Packet Number : 4 bytes\n"
|
||||
@ -72,23 +84,31 @@ class MasterAttributes {
|
||||
"Detector Type : 1 byte\n"
|
||||
"Header Version : 1 byte\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 {
|
||||
public:
|
||||
GotthardMasterAttributes(){};
|
||||
|
||||
std::string GetBinaryMasterAttributes() override {
|
||||
void WriteMasterBinaryAttributes(FILE *fd) override {
|
||||
std::ostringstream oss;
|
||||
oss << MasterAttributes::GetBinaryMasterAttributes()
|
||||
<< "Exptime : " << sls::ToString(exptime) << '\n'
|
||||
<< "Period : " << sls::ToString(period) << '\n'
|
||||
<< "Roi (xmin, xmax) : " << sls::ToString(roi) << '\n'
|
||||
<< GetBinaryFrameHeaderFormat();
|
||||
return oss.str();
|
||||
<< "Roi (xmin, xmax) : " << sls::ToString(roi) << '\n';
|
||||
std::string message = oss.str();
|
||||
MasterAttributes::WriteBinaryAttributes(fd, message);
|
||||
};
|
||||
};
|
||||
|
||||
@ -96,13 +116,13 @@ class JungfrauMasterAttributes : public MasterAttributes {
|
||||
public:
|
||||
JungfrauMasterAttributes(){};
|
||||
|
||||
std::string GetBinaryMasterAttributes() override {
|
||||
void WriteMasterBinaryAttributes(FILE *fd) override {
|
||||
std::ostringstream oss;
|
||||
oss << MasterAttributes::GetBinaryMasterAttributes()
|
||||
<< "Exptime : " << sls::ToString(exptime) << '\n'
|
||||
<< "Period : " << sls::ToString(period) << '\n'
|
||||
<< GetBinaryFrameHeaderFormat();
|
||||
return oss.str();
|
||||
<< "Period : " << sls::ToString(period) << '\n';
|
||||
std::string message = oss.str();
|
||||
MasterAttributes::WriteBinaryAttributes(fd, message);
|
||||
};
|
||||
};
|
||||
|
||||
@ -110,7 +130,7 @@ class EigerMasterAttributes : public MasterAttributes {
|
||||
public:
|
||||
EigerMasterAttributes(){};
|
||||
|
||||
std::string GetBinaryMasterAttributes() override {
|
||||
void WriteMasterBinaryAttributes(FILE *fd) override {
|
||||
std::ostringstream oss;
|
||||
oss << MasterAttributes::GetBinaryMasterAttributes()
|
||||
<< "Dynamic Range : " << dynamicRange << '\n'
|
||||
@ -121,9 +141,9 @@ class EigerMasterAttributes : public MasterAttributes {
|
||||
<< '\n'
|
||||
<< "SubPeriod : " << sls::ToString(subPeriod)
|
||||
<< '\n'
|
||||
<< "Quad : " << quad << '\n'
|
||||
<< GetBinaryFrameHeaderFormat();
|
||||
return oss.str();
|
||||
<< "Quad : " << quad << '\n';
|
||||
std::string message = oss.str();
|
||||
MasterAttributes::WriteBinaryAttributes(fd, message);
|
||||
};
|
||||
};
|
||||
|
||||
@ -131,7 +151,7 @@ class Mythen3MasterAttributes : public MasterAttributes {
|
||||
public:
|
||||
Mythen3MasterAttributes(){};
|
||||
|
||||
std::string GetBinaryMasterAttributes() override {
|
||||
void WriteMasterBinaryAttributes(FILE *fd) override {
|
||||
std::ostringstream oss;
|
||||
oss << MasterAttributes::GetBinaryMasterAttributes()
|
||||
<< "Dynamic Range : " << dynamicRange << '\n'
|
||||
@ -149,9 +169,9 @@ class Mythen3MasterAttributes : public MasterAttributes {
|
||||
<< '\n'
|
||||
<< "GateDelay3 : " << sls::ToString(gateDelay3)
|
||||
<< '\n'
|
||||
<< "Gates : " << gates << '\n'
|
||||
<< GetBinaryFrameHeaderFormat();
|
||||
return oss.str();
|
||||
<< "Gates : " << gates << '\n';
|
||||
std::string message = oss.str();
|
||||
MasterAttributes::WriteBinaryAttributes(fd, message);
|
||||
};
|
||||
};
|
||||
|
||||
@ -159,13 +179,13 @@ class Gotthard2MasterAttributes : public MasterAttributes {
|
||||
public:
|
||||
Gotthard2MasterAttributes(){};
|
||||
|
||||
std::string GetBinaryMasterAttributes() override {
|
||||
void WriteMasterBinaryAttributes(FILE *fd) override {
|
||||
std::ostringstream oss;
|
||||
oss << MasterAttributes::GetBinaryMasterAttributes()
|
||||
<< "Exptime : " << sls::ToString(exptime) << '\n'
|
||||
<< "Period : " << sls::ToString(period) << '\n'
|
||||
<< GetBinaryFrameHeaderFormat();
|
||||
return oss.str();
|
||||
<< "Period : " << sls::ToString(period) << '\n';
|
||||
std::string message = oss.str();
|
||||
MasterAttributes::WriteBinaryAttributes(fd, message);
|
||||
};
|
||||
};
|
||||
|
||||
@ -173,16 +193,16 @@ class MoenchMasterAttributes : public MasterAttributes {
|
||||
public:
|
||||
MoenchMasterAttributes(){};
|
||||
|
||||
std::string GetBinaryMasterAttributes() override {
|
||||
void WriteMasterBinaryAttributes(FILE *fd) override {
|
||||
std::ostringstream oss;
|
||||
oss << MasterAttributes::GetBinaryMasterAttributes()
|
||||
<< "Exptime : " << sls::ToString(exptime) << '\n'
|
||||
<< "Period : " << sls::ToString(period) << '\n'
|
||||
<< "Ten Giga : " << tenGiga << '\n'
|
||||
<< "ADC Mask : " << sls::ToStringHex(adcmask)
|
||||
<< '\n'
|
||||
<< GetBinaryFrameHeaderFormat();
|
||||
return oss.str();
|
||||
<< '\n';
|
||||
std::string message = oss.str();
|
||||
MasterAttributes::WriteBinaryAttributes(fd, message);
|
||||
};
|
||||
};
|
||||
|
||||
@ -190,7 +210,7 @@ class CtbMasterAttributes : public MasterAttributes {
|
||||
public:
|
||||
CtbMasterAttributes(){};
|
||||
|
||||
std::string GetBinaryMasterAttributes() override {
|
||||
void WriteMasterBinaryAttributes(FILE *fd) override {
|
||||
std::ostringstream oss;
|
||||
oss << MasterAttributes::GetBinaryMasterAttributes()
|
||||
<< "Exptime : " << sls::ToString(exptime) << '\n'
|
||||
@ -201,8 +221,8 @@ class CtbMasterAttributes : public MasterAttributes {
|
||||
<< "Analog Flag : " << analog << '\n'
|
||||
<< "Digital Flag : " << digital << '\n'
|
||||
<< "Dbit Offset : " << dbitoffset << '\n'
|
||||
<< "Dbit Bitset : " << dbitlist << '\n'
|
||||
<< GetBinaryFrameHeaderFormat();
|
||||
return oss.str();
|
||||
<< "Dbit Bitset : " << dbitlist << '\n';
|
||||
std::string message = oss.str();
|
||||
MasterAttributes::WriteBinaryAttributes(fd, message);
|
||||
};
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user