created detector dependant master file attributes

This commit is contained in:
maliakal_d 2020-07-31 12:15:28 +02:00
parent bd221fefe5
commit 4eaa9588ba
8 changed files with 76 additions and 236 deletions

View File

@ -6,6 +6,7 @@
#include "BinaryFile.h" #include "BinaryFile.h"
#include "Fifo.h" #include "Fifo.h"
#include "MasterAttributes.h"
#include "receiver_defs.h" #include "receiver_defs.h"
#include <iomanip> #include <iomanip>
@ -133,7 +134,7 @@ void BinaryFile::WriteToFile(char *buffer, int buffersize,
} }
void BinaryFile::CreateMasterFile(bool masterFileWriteEnable, void BinaryFile::CreateMasterFile(bool masterFileWriteEnable,
masterAttributes &masterFileAttributes) { MasterAttributes *attr) {
// beginning of every acquisition // beginning of every acquisition
numFramesInFile = 0; numFramesInFile = 0;
numActualPacketsInFile = 0; numActualPacketsInFile = 0;
@ -147,7 +148,6 @@ void BinaryFile::CreateMasterFile(bool masterFileWriteEnable,
if (!(*silentMode)) { if (!(*silentMode)) {
LOG(logINFO) << "Master File: " << masterFileName; LOG(logINFO) << "Master File: " << masterFileName;
} }
masterFileAttributes.version = BINARY_WRITER_VERSION;
// create master file // create master file
if (!(*overWriteEnable)) { if (!(*overWriteEnable)) {
@ -167,84 +167,10 @@ void BinaryFile::CreateMasterFile(bool masterFileWriteEnable,
masterFileName); masterFileName);
} }
// create master file data // create master file data
time_t t = time(nullptr); std::string strAttributes = attr->GetBinaryMasterAttributes();
char message[maxMasterFileSize]; char message[maxMasterFileSize];
sprintf(message, memset(message, 0, maxMasterFileSize);
"Version : %.1f\n" sls::strcpy_safe(message, strAttributes.c_str());
"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));
}
// write and close file // write and close file
if (fwrite((void *)message, 1, strlen(message), masterfd) != if (fwrite((void *)message, 1, strlen(message), masterfd) !=
strlen(message)) { strlen(message)) {

View File

@ -42,7 +42,7 @@ class BinaryFile : private virtual slsDetectorDefs, public File {
void PrintMembers(TLogLevel level = logDEBUG1) override; void PrintMembers(TLogLevel level = logDEBUG1) override;
void CreateFile() override; void CreateFile() override;
void CreateMasterFile(bool masterFileWriteEnable, void CreateMasterFile(bool masterFileWriteEnable,
masterAttributes &masterFileAttributes) override; MasterAttributes *attr) override;
void CloseCurrentFile() override; void CloseCurrentFile() override;
void CloseAllFiles() override; void CloseAllFiles() override;
void WriteToFile(char *buffer, int buffersize, uint64_t currentFrameNumber, void WriteToFile(char *buffer, int buffersize, uint64_t currentFrameNumber,
@ -55,8 +55,7 @@ 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 // Make sure this is known at compile time
//TODO! Later away from stack allocation of message // TODO! Later away from stack allocation of message
static constexpr size_t maxMasterFileSize = 2000; static constexpr size_t maxMasterFileSize = 2000;
}; };

View File

@ -9,6 +9,7 @@
#include "BinaryFile.h" #include "BinaryFile.h"
#include "Fifo.h" #include "Fifo.h"
#include "GeneralData.h" #include "GeneralData.h"
#include "MasterAttributes.h"
#ifdef HDF5C #ifdef HDF5C
#include "HDF5File.h" #include "HDF5File.h"
#endif #endif
@ -143,7 +144,7 @@ void DataProcessor::SetupFileWriter(bool fwe, int *nd, uint32_t *maxf,
} }
// only the first file // only the first file
void DataProcessor::CreateNewFile(masterAttributes &attr) { void DataProcessor::CreateNewFile(MasterAttributes *attr) {
if (file == nullptr) { if (file == nullptr) {
throw sls::RuntimeError("file object not contstructed"); throw sls::RuntimeError("file object not contstructed");
} }
@ -411,7 +412,7 @@ void DataProcessor::PadMissingPackets(char *buf) {
/** ctb specific */ /** ctb specific */
void DataProcessor::RearrangeDbitData(char *buf) { void DataProcessor::RearrangeDbitData(char *buf) {
//TODO! (Erik) Refactor and add tests // TODO! (Erik) Refactor and add tests
int totalSize = (int)(*((uint32_t *)buf)); int totalSize = (int)(*((uint32_t *)buf));
int ctbDigitalDataBytes = int ctbDigitalDataBytes =
totalSize - (*ctbAnalogDataBytes) - (*ctbDbitOffset); totalSize - (*ctbAnalogDataBytes) - (*ctbDbitOffset);

View File

@ -16,6 +16,7 @@ class GeneralData;
class Fifo; class Fifo;
class File; class File;
class DataStreamer; class DataStreamer;
class MasterAttributes;
#include <atomic> #include <atomic>
#include <vector> #include <vector>
@ -134,7 +135,7 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject {
* Create New File * Create New File
* @param attr master file attributes * @param attr master file attributes
*/ */
void CreateNewFile(masterAttributes &attr); void CreateNewFile(MasterAttributes *attr);
/** /**
* Closes files * Closes files

View File

@ -15,6 +15,8 @@
#include <string> #include <string>
class MasterAttributes;
class File : private virtual slsDetectorDefs { class File : private virtual slsDetectorDefs {
public: public:
@ -86,7 +88,7 @@ class File : private virtual slsDetectorDefs {
* @param mfwenable master file write enable * @param mfwenable master file write enable
* @param attr master file attributes * @param attr master file attributes
*/ */
virtual void CreateMasterFile(bool mfwenable, masterAttributes &attr) = 0; virtual void CreateMasterFile(bool mfwenable, MasterAttributes *attr) = 0;
// HDf5 specific // HDf5 specific
/** /**

View File

@ -4,10 +4,10 @@
#include "Fifo.h" #include "Fifo.h"
#include "GeneralData.h" #include "GeneralData.h"
#include "Listener.h" #include "Listener.h"
#include "MasterAttributes.h"
#include "ToString.h" #include "ToString.h"
#include "ZmqSocket.h" //just for the zmq port define #include "ZmqSocket.h" //just for the zmq port define
#include "file_utils.h" #include "file_utils.h"
#include "masterFileAttributes.h"
#include <cerrno> //eperm #include <cerrno> //eperm
#include <chrono> #include <chrono>
@ -906,45 +906,71 @@ void Implementation::CreateUDPSockets() {
void Implementation::SetupWriter() { void Implementation::SetupWriter() {
LOG(logDEBUG3) << __SHORT_AT__ << " called"; LOG(logDEBUG3) << __SHORT_AT__ << " called";
masterAttributes attr; std::unique_ptr<MasterAttributes> masterAttributes;
attr.detectorType = myDetectorType; switch (myDetectorType) {
attr.dynamicRange = dynamicRange; case GOTTHARD:
attr.tenGiga = tengigaEnable; masterAttributes = sls::make_unique<GotthardMasterAttributes>();
attr.imageSize = generalData->imageSize; break;
attr.nPixelsX = generalData->nPixelsX; case JUNGFRAU:
attr.nPixelsY = generalData->nPixelsY; masterAttributes = sls::make_unique<JungfrauMasterAttributes>();
attr.maxFramesPerFile = framesPerFile; break;
attr.totalFrames = numberOfTotalFrames; case EIGER:
attr.exptimeNs = acquisitionTime; masterAttributes = sls::make_unique<EigerMasterAttributes>();
attr.subExptimeNs = subExpTime; break;
attr.subPeriodNs = subPeriod; case MYTHEN3:
attr.periodNs = acquisitionPeriod; masterAttributes = sls::make_unique<Mythen3MasterAttributes>();
attr.quadEnable = quadEnable; break;
attr.analogFlag = 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 (readoutType == ANALOG_ONLY || readoutType == ANALOG_AND_DIGITAL) ? 1
: 0; : 0;
attr.digitalFlag = masterAttributes->digital =
(readoutType == DIGITAL_ONLY || readoutType == ANALOG_AND_DIGITAL) ? 1 (readoutType == DIGITAL_ONLY || readoutType == ANALOG_AND_DIGITAL) ? 1
: 0; : 0;
attr.adcmask = tengigaEnable ? adcEnableMaskTenGiga : adcEnableMaskOneGiga; masterAttributes->dbitoffset = ctbDbitOffset;
attr.dbitoffset = ctbDbitOffset; masterAttributes->dbitlist = 0;
attr.dbitlist = 0;
attr.roiXmin = roi.xmin;
attr.roiXmax = roi.xmax;
for (auto &i : ctbDbitList) { for (auto &i : ctbDbitList) {
attr.dbitlist |= (1 << i); masterAttributes->dbitlist |= (1 << i);
} }
attr.exptime1Ns = acquisitionTime1; masterAttributes->roi = roi;
attr.exptime2Ns = acquisitionTime2; masterAttributes->exptime1 = std::chrono::nanoseconds(acquisitionTime1);
attr.exptime3Ns = acquisitionTime3; masterAttributes->exptime2 = std::chrono::nanoseconds(acquisitionTime2);
attr.gateDelay1Ns = gateDelay1; masterAttributes->exptime3 = std::chrono::nanoseconds(acquisitionTime3);
attr.gateDelay2Ns = gateDelay2; masterAttributes->gateDelay1 = std::chrono::nanoseconds(gateDelay1);
attr.gateDelay3Ns = gateDelay3; masterAttributes->gateDelay2 = std::chrono::nanoseconds(gateDelay2);
attr.gates = numberOfGates; masterAttributes->gateDelay3 = std::chrono::nanoseconds(gateDelay3);
masterAttributes->gates = numberOfGates;
try { try {
for (unsigned int i = 0; i < dataProcessor.size(); ++i) { for (unsigned int i = 0; i < dataProcessor.size(); ++i) {
dataProcessor[i]->CreateNewFile(attr); dataProcessor[i]->CreateNewFile(masterAttributes.get());
} }
} catch (const sls::RuntimeError &e) { } catch (const sls::RuntimeError &e) {
shutDownUDPSockets(); shutDownUDPSockets();

View File

@ -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();
};
};

View File

@ -53,7 +53,7 @@
#define STREAMER_PRIORITY (10) #define STREAMER_PRIORITY (10)
#define TCP_PRIORITY (10) #define TCP_PRIORITY (10)
/*
#define HDF5_WRITER_VERSION (6.1) // 1 decimal places #define HDF5_WRITER_VERSION (6.1) // 1 decimal places
#define BINARY_WRITER_VERSION (6.1) // 1 decimal places #define BINARY_WRITER_VERSION (6.1) // 1 decimal places
struct masterAttributes { struct masterAttributes {
@ -86,3 +86,4 @@ struct masterAttributes {
uint64_t gateDelay3Ns; uint64_t gateDelay3Ns;
uint32_t gates; uint32_t gates;
}; };
*/