mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-22 03:40:04 +02:00
created detector dependant master file attributes
This commit is contained in:
parent
bd221fefe5
commit
4eaa9588ba
@ -6,6 +6,7 @@
|
||||
|
||||
#include "BinaryFile.h"
|
||||
#include "Fifo.h"
|
||||
#include "MasterAttributes.h"
|
||||
#include "receiver_defs.h"
|
||||
|
||||
#include <iomanip>
|
||||
@ -133,7 +134,7 @@ void BinaryFile::WriteToFile(char *buffer, int buffersize,
|
||||
}
|
||||
|
||||
void BinaryFile::CreateMasterFile(bool masterFileWriteEnable,
|
||||
masterAttributes &masterFileAttributes) {
|
||||
MasterAttributes *attr) {
|
||||
// beginning of every acquisition
|
||||
numFramesInFile = 0;
|
||||
numActualPacketsInFile = 0;
|
||||
@ -147,7 +148,6 @@ void BinaryFile::CreateMasterFile(bool masterFileWriteEnable,
|
||||
if (!(*silentMode)) {
|
||||
LOG(logINFO) << "Master File: " << masterFileName;
|
||||
}
|
||||
masterFileAttributes.version = BINARY_WRITER_VERSION;
|
||||
|
||||
// create master file
|
||||
if (!(*overWriteEnable)) {
|
||||
@ -167,84 +167,10 @@ void BinaryFile::CreateMasterFile(bool masterFileWriteEnable,
|
||||
masterFileName);
|
||||
}
|
||||
// create master file data
|
||||
time_t t = time(nullptr);
|
||||
std::string strAttributes = attr->GetBinaryMasterAttributes();
|
||||
char message[maxMasterFileSize];
|
||||
sprintf(message,
|
||||
"Version : %.1f\n"
|
||||
"Detector Type : %d\n"
|
||||
"Dynamic Range : %d\n"
|
||||
"Ten Giga : %d\n"
|
||||
"Image Size : %d bytes\n"
|
||||
"nPixelsX : %d pixels\n"
|
||||
"nPixelsY : %d pixels\n"
|
||||
"Max Frames Per File : %u\n"
|
||||
"Total Frames : %lld\n"
|
||||
"Exptime (ns) : %lld\n"
|
||||
"SubExptime (ns) : %lld\n"
|
||||
"SubPeriod (ns) : %lld\n"
|
||||
"Period (ns) : %lld\n"
|
||||
"Quad Enable : %d\n"
|
||||
"Analog Flag : %d\n"
|
||||
"Digital Flag : %d\n"
|
||||
"ADC Mask : %d\n"
|
||||
"Dbit Offset : %d\n"
|
||||
"Dbit Bitset : %lld\n"
|
||||
"Roi (xmin, xmax) : %d %d\n"
|
||||
"Exptime1 (ns) : %lld\n"
|
||||
"Exptime2 (ns) : %lld\n"
|
||||
"Exptime3 (ns) : %lld\n"
|
||||
"GateDelay1 (ns) : %lld\n"
|
||||
"GateDelay2 (ns) : %lld\n"
|
||||
"GateDelay3 (ns) : %lld\n"
|
||||
"Gates : %d\n"
|
||||
"Timestamp : %s\n\n"
|
||||
|
||||
"#Frame Header\n"
|
||||
"Frame Number : 8 bytes\n"
|
||||
"SubFrame Number/ExpLength : 4 bytes\n"
|
||||
"Packet Number : 4 bytes\n"
|
||||
"Bunch ID : 8 bytes\n"
|
||||
"Timestamp : 8 bytes\n"
|
||||
"Module Id : 2 bytes\n"
|
||||
"Row : 2 bytes\n"
|
||||
"Column : 2 bytes\n"
|
||||
"Reserved : 2 bytes\n"
|
||||
"Debug : 4 bytes\n"
|
||||
"Round Robin Number : 2 bytes\n"
|
||||
"Detector Type : 1 byte\n"
|
||||
"Header Version : 1 byte\n"
|
||||
"Packets Caught Mask : 64 bytes\n",
|
||||
masterFileAttributes.version, masterFileAttributes.detectorType,
|
||||
masterFileAttributes.dynamicRange, masterFileAttributes.tenGiga,
|
||||
masterFileAttributes.imageSize, masterFileAttributes.nPixelsX,
|
||||
masterFileAttributes.nPixelsY,
|
||||
masterFileAttributes.maxFramesPerFile,
|
||||
(long long int)masterFileAttributes.totalFrames,
|
||||
(long long int)masterFileAttributes.exptimeNs,
|
||||
(long long int)masterFileAttributes.subExptimeNs,
|
||||
(long long int)masterFileAttributes.subPeriodNs,
|
||||
(long long int)masterFileAttributes.periodNs,
|
||||
masterFileAttributes.quadEnable,
|
||||
masterFileAttributes.analogFlag,
|
||||
masterFileAttributes.digitalFlag, masterFileAttributes.adcmask,
|
||||
masterFileAttributes.dbitoffset,
|
||||
(long long int)masterFileAttributes.dbitlist,
|
||||
masterFileAttributes.roiXmin, masterFileAttributes.roiXmax,
|
||||
(long long int)masterFileAttributes.exptime1Ns,
|
||||
(long long int)masterFileAttributes.exptime2Ns,
|
||||
(long long int)masterFileAttributes.exptime3Ns,
|
||||
(long long int)masterFileAttributes.gateDelay1Ns,
|
||||
(long long int)masterFileAttributes.gateDelay2Ns,
|
||||
(long long int)masterFileAttributes.gateDelay3Ns,
|
||||
masterFileAttributes.gates, ctime(&t));
|
||||
|
||||
//TODO! snprintf? This would already have been a buffer overflow
|
||||
if (strlen(message) > maxMasterFileSize) {
|
||||
throw sls::RuntimeError("Master File Size " +
|
||||
std::to_string(strlen(message)) +
|
||||
" is greater than max str size " +
|
||||
std::to_string(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)) {
|
||||
|
@ -42,7 +42,7 @@ class BinaryFile : private virtual slsDetectorDefs, public File {
|
||||
void PrintMembers(TLogLevel level = logDEBUG1) override;
|
||||
void CreateFile() override;
|
||||
void CreateMasterFile(bool masterFileWriteEnable,
|
||||
masterAttributes &masterFileAttributes) override;
|
||||
MasterAttributes *attr) override;
|
||||
void CloseCurrentFile() override;
|
||||
void CloseAllFiles() override;
|
||||
void WriteToFile(char *buffer, int buffersize, uint64_t currentFrameNumber,
|
||||
@ -55,8 +55,7 @@ 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;
|
||||
|
||||
// Make sure this is known at compile time
|
||||
// TODO! Later away from stack allocation of message
|
||||
static constexpr size_t maxMasterFileSize = 2000;
|
||||
};
|
@ -9,6 +9,7 @@
|
||||
#include "BinaryFile.h"
|
||||
#include "Fifo.h"
|
||||
#include "GeneralData.h"
|
||||
#include "MasterAttributes.h"
|
||||
#ifdef HDF5C
|
||||
#include "HDF5File.h"
|
||||
#endif
|
||||
@ -143,7 +144,7 @@ void DataProcessor::SetupFileWriter(bool fwe, int *nd, uint32_t *maxf,
|
||||
}
|
||||
|
||||
// only the first file
|
||||
void DataProcessor::CreateNewFile(masterAttributes &attr) {
|
||||
void DataProcessor::CreateNewFile(MasterAttributes *attr) {
|
||||
if (file == nullptr) {
|
||||
throw sls::RuntimeError("file object not contstructed");
|
||||
}
|
||||
@ -411,7 +412,7 @@ void DataProcessor::PadMissingPackets(char *buf) {
|
||||
|
||||
/** ctb specific */
|
||||
void DataProcessor::RearrangeDbitData(char *buf) {
|
||||
//TODO! (Erik) Refactor and add tests
|
||||
// TODO! (Erik) Refactor and add tests
|
||||
int totalSize = (int)(*((uint32_t *)buf));
|
||||
int ctbDigitalDataBytes =
|
||||
totalSize - (*ctbAnalogDataBytes) - (*ctbDbitOffset);
|
||||
|
@ -16,6 +16,7 @@ class GeneralData;
|
||||
class Fifo;
|
||||
class File;
|
||||
class DataStreamer;
|
||||
class MasterAttributes;
|
||||
|
||||
#include <atomic>
|
||||
#include <vector>
|
||||
@ -134,7 +135,7 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject {
|
||||
* Create New File
|
||||
* @param attr master file attributes
|
||||
*/
|
||||
void CreateNewFile(masterAttributes &attr);
|
||||
void CreateNewFile(MasterAttributes *attr);
|
||||
|
||||
/**
|
||||
* Closes files
|
||||
|
@ -15,6 +15,8 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
class MasterAttributes;
|
||||
|
||||
class File : private virtual slsDetectorDefs {
|
||||
|
||||
public:
|
||||
@ -86,7 +88,7 @@ class File : private virtual slsDetectorDefs {
|
||||
* @param mfwenable master file write enable
|
||||
* @param attr master file attributes
|
||||
*/
|
||||
virtual void CreateMasterFile(bool mfwenable, masterAttributes &attr) = 0;
|
||||
virtual void CreateMasterFile(bool mfwenable, MasterAttributes *attr) = 0;
|
||||
|
||||
// HDf5 specific
|
||||
/**
|
||||
|
@ -4,10 +4,10 @@
|
||||
#include "Fifo.h"
|
||||
#include "GeneralData.h"
|
||||
#include "Listener.h"
|
||||
#include "MasterAttributes.h"
|
||||
#include "ToString.h"
|
||||
#include "ZmqSocket.h" //just for the zmq port define
|
||||
#include "file_utils.h"
|
||||
#include "masterFileAttributes.h"
|
||||
|
||||
#include <cerrno> //eperm
|
||||
#include <chrono>
|
||||
@ -906,45 +906,71 @@ void Implementation::CreateUDPSockets() {
|
||||
|
||||
void Implementation::SetupWriter() {
|
||||
LOG(logDEBUG3) << __SHORT_AT__ << " called";
|
||||
masterAttributes attr;
|
||||
attr.detectorType = myDetectorType;
|
||||
attr.dynamicRange = dynamicRange;
|
||||
attr.tenGiga = tengigaEnable;
|
||||
attr.imageSize = generalData->imageSize;
|
||||
attr.nPixelsX = generalData->nPixelsX;
|
||||
attr.nPixelsY = generalData->nPixelsY;
|
||||
attr.maxFramesPerFile = framesPerFile;
|
||||
attr.totalFrames = numberOfTotalFrames;
|
||||
attr.exptimeNs = acquisitionTime;
|
||||
attr.subExptimeNs = subExpTime;
|
||||
attr.subPeriodNs = subPeriod;
|
||||
attr.periodNs = acquisitionPeriod;
|
||||
attr.quadEnable = quadEnable;
|
||||
attr.analogFlag =
|
||||
std::unique_ptr<MasterAttributes> masterAttributes;
|
||||
switch (myDetectorType) {
|
||||
case GOTTHARD:
|
||||
masterAttributes = sls::make_unique<GotthardMasterAttributes>();
|
||||
break;
|
||||
case JUNGFRAU:
|
||||
masterAttributes = sls::make_unique<JungfrauMasterAttributes>();
|
||||
break;
|
||||
case EIGER:
|
||||
masterAttributes = sls::make_unique<EigerMasterAttributes>();
|
||||
break;
|
||||
case MYTHEN3:
|
||||
masterAttributes = sls::make_unique<Mythen3MasterAttributes>();
|
||||
break;
|
||||
case GOTTHARD2:
|
||||
masterAttributes = sls::make_unique<Gotthard2MasterAttributes>();
|
||||
break;
|
||||
case MOENCH:
|
||||
masterAttributes = sls::make_unique<MoenchMasterAttributes>();
|
||||
break;
|
||||
case CHIPTESTBOARD:
|
||||
masterAttributes = sls::make_unique<CtbMasterAttributes>();
|
||||
break;
|
||||
default:
|
||||
throw sls::RuntimeError(
|
||||
"Unknown detector type to set up master file attributes");
|
||||
}
|
||||
masterAttributes->detType = myDetectorType;
|
||||
masterAttributes->imageSize = generalData->imageSize;
|
||||
masterAttributes->nPixels =
|
||||
xy(generalData->nPixelsX, generalData->nPixelsY);
|
||||
masterAttributes->maxFramesPerFile = framesPerFile;
|
||||
masterAttributes->totalFrames = numberOfTotalFrames;
|
||||
masterAttributes->exptime = std::chrono::nanoseconds(acquisitionTime);
|
||||
masterAttributes->period = std::chrono::nanoseconds(acquisitionPeriod);
|
||||
masterAttributes->dynamicRange = dynamicRange;
|
||||
masterAttributes->tenGiga = tengigaEnable;
|
||||
masterAttributes->subExptime = std::chrono::nanoseconds(subExpTime);
|
||||
masterAttributes->subPeriod = std::chrono::nanoseconds(subPeriod);
|
||||
masterAttributes->quad = quadEnable;
|
||||
masterAttributes->adcmask =
|
||||
tengigaEnable ? adcEnableMaskTenGiga : adcEnableMaskOneGiga;
|
||||
masterAttributes->analog =
|
||||
(readoutType == ANALOG_ONLY || readoutType == ANALOG_AND_DIGITAL) ? 1
|
||||
: 0;
|
||||
attr.digitalFlag =
|
||||
masterAttributes->digital =
|
||||
(readoutType == DIGITAL_ONLY || readoutType == ANALOG_AND_DIGITAL) ? 1
|
||||
: 0;
|
||||
attr.adcmask = tengigaEnable ? adcEnableMaskTenGiga : adcEnableMaskOneGiga;
|
||||
attr.dbitoffset = ctbDbitOffset;
|
||||
attr.dbitlist = 0;
|
||||
attr.roiXmin = roi.xmin;
|
||||
attr.roiXmax = roi.xmax;
|
||||
masterAttributes->dbitoffset = ctbDbitOffset;
|
||||
masterAttributes->dbitlist = 0;
|
||||
for (auto &i : ctbDbitList) {
|
||||
attr.dbitlist |= (1 << i);
|
||||
masterAttributes->dbitlist |= (1 << i);
|
||||
}
|
||||
attr.exptime1Ns = acquisitionTime1;
|
||||
attr.exptime2Ns = acquisitionTime2;
|
||||
attr.exptime3Ns = acquisitionTime3;
|
||||
attr.gateDelay1Ns = gateDelay1;
|
||||
attr.gateDelay2Ns = gateDelay2;
|
||||
attr.gateDelay3Ns = gateDelay3;
|
||||
attr.gates = numberOfGates;
|
||||
masterAttributes->roi = roi;
|
||||
masterAttributes->exptime1 = std::chrono::nanoseconds(acquisitionTime1);
|
||||
masterAttributes->exptime2 = std::chrono::nanoseconds(acquisitionTime2);
|
||||
masterAttributes->exptime3 = std::chrono::nanoseconds(acquisitionTime3);
|
||||
masterAttributes->gateDelay1 = std::chrono::nanoseconds(gateDelay1);
|
||||
masterAttributes->gateDelay2 = std::chrono::nanoseconds(gateDelay2);
|
||||
masterAttributes->gateDelay3 = std::chrono::nanoseconds(gateDelay3);
|
||||
masterAttributes->gates = numberOfGates;
|
||||
|
||||
try {
|
||||
for (unsigned int i = 0; i < dataProcessor.size(); ++i) {
|
||||
dataProcessor[i]->CreateNewFile(attr);
|
||||
dataProcessor[i]->CreateNewFile(masterAttributes.get());
|
||||
}
|
||||
} catch (const sls::RuntimeError &e) {
|
||||
shutDownUDPSockets();
|
||||
|
@ -1,116 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "sls_detector_defs.h"
|
||||
#include "logger.h"
|
||||
#include "ToString.h"
|
||||
|
||||
// versions
|
||||
#define HDF5_WRITER_VERSION (6.1) // 1 decimal places
|
||||
#define BINARY_WRITER_VERSION (6.1) // 1 decimal places
|
||||
|
||||
class masterFileAttributes {
|
||||
|
||||
public:
|
||||
double version{0.0};
|
||||
slsDetectorDefs::detectorType detType{slsDetectorDefs::GENERIC};
|
||||
uint32_t imageSize{0};
|
||||
slsDetectorDefs::xy nPixels{};
|
||||
uint32_t maxFramesPerFile{0};
|
||||
uint64_t totalFrames{0};
|
||||
uint64_t exptimeNs{0};
|
||||
uint64_t periodNs{0};
|
||||
uint32_t dynamicRange{0};
|
||||
uint32_t tenGiga{0};
|
||||
uint64_t subExptimeNs{0};
|
||||
uint64_t subPeriodNs{0};
|
||||
uint32_t quadEnable{0};
|
||||
uint32_t adcmask{0};
|
||||
uint32_t analogFlag{0};
|
||||
uint32_t digitalFlag{0};
|
||||
uint32_t dbitoffset{0};
|
||||
uint64_t dbitlist{0};
|
||||
slsDetectorDefs::ROI roi{};
|
||||
uint64_t exptime1Ns{0};
|
||||
uint64_t exptime2Ns{0};
|
||||
uint64_t exptime3Ns{0};
|
||||
uint64_t gateDelay1Ns{0};
|
||||
uint64_t gateDelay2Ns{0};
|
||||
uint64_t gateDelay3Ns{0};
|
||||
uint32_t gates;
|
||||
/*
|
||||
double version{0.0};
|
||||
slsDetectorDefs::detectorType myDetectorType{slsDetectorDefs::GENERIC};
|
||||
uint32_t imageSize{0};
|
||||
uint32_t nPixelsX{0};
|
||||
uint32_t nPixelsY{0};
|
||||
uint32_t maxFramesPerFile{0};
|
||||
uint64_t totalFrames{0};
|
||||
uint64_t exptimeNs{0};
|
||||
uint64_t periodNs{0};
|
||||
*/
|
||||
/* eiger
|
||||
uint32_t dynamicRange{0};
|
||||
uint32_t tenGiga{0};
|
||||
uint64_t subExptimeNs{0};
|
||||
uint64_t subPeriodNs{0};
|
||||
uint32_t quadEnable{0};
|
||||
*/
|
||||
/** moench
|
||||
uint32_t tenGiga{0};
|
||||
uint32_t adcmask{0};
|
||||
*/
|
||||
/* ctb
|
||||
uint32_t tenGiga{0};
|
||||
uint32_t adcmask{0};
|
||||
uint32_t analogFlag{0};
|
||||
uint32_t digitalFlag{0};
|
||||
uint32_t dbitoffset{0};
|
||||
uint64_t dbitlist{0};
|
||||
*/
|
||||
/* gotthard
|
||||
uint32_t roiXmin{0};
|
||||
uint32_t roiXmax{0};
|
||||
*/
|
||||
/* mythen3
|
||||
uint32_t dynamicRange{0};
|
||||
uint32_t tenGiga{0};
|
||||
uint64_t exptime1Ns{0};
|
||||
uint64_t exptime2Ns{0};
|
||||
uint64_t exptime3Ns{0};
|
||||
uint64_t gateDelay1Ns{0};
|
||||
uint64_t gateDelay2Ns{0};
|
||||
uint64_t gateDelay3Ns{0};
|
||||
uint32_t gates;
|
||||
*/
|
||||
masterFileAttributes(){};
|
||||
virtual ~masterFileAttributes(){};
|
||||
|
||||
std::string GetBinaryMasterFileAttributes() {
|
||||
std::ostringstream oss;
|
||||
oss << "Version : " << std::setprecision(2) << version << '\n'
|
||||
<< "Detector Type : " << sls::ToString(detType) << '\n'
|
||||
<< "Image Size : " << imageSize << " bytes" << '\n'
|
||||
<< "nPixels : " << sls::ToString(nPixels) << " pixels" << '\n'
|
||||
<< "Max Frames Per File : " << maxFramesPerFile << '\n'
|
||||
<< "Total Frames : " << totalFrames << '\n'
|
||||
<< "Exptime (ns) : " << exptimeNs << '\n'
|
||||
<< "Period (ns) : " << periodNs << '\n';
|
||||
return oss.str();
|
||||
};
|
||||
|
||||
// hdf5
|
||||
};
|
||||
|
||||
class GotthardMasterFileAttributes : public masterFileAttributes {
|
||||
|
||||
public:
|
||||
GotthardMasterFileAttributes() {};
|
||||
|
||||
std::string GetBinaryMasterFileAttributes() {
|
||||
std::ostringstream oss;
|
||||
oss << masterFileAttributes::GetBinaryMasterFileAttributes()
|
||||
<< "Roi (xmin, xmax) : " << sls::ToString(roi) << '\n';
|
||||
return oss.str();
|
||||
};
|
||||
};
|
||||
|
@ -53,7 +53,7 @@
|
||||
#define STREAMER_PRIORITY (10)
|
||||
#define TCP_PRIORITY (10)
|
||||
|
||||
|
||||
/*
|
||||
#define HDF5_WRITER_VERSION (6.1) // 1 decimal places
|
||||
#define BINARY_WRITER_VERSION (6.1) // 1 decimal places
|
||||
struct masterAttributes {
|
||||
@ -86,3 +86,4 @@ struct masterAttributes {
|
||||
uint64_t gateDelay3Ns;
|
||||
uint32_t gates;
|
||||
};
|
||||
*/
|
Loading…
x
Reference in New Issue
Block a user