From 6cd780ae9920e681b4ebaa77524116bbd902fecd Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Tue, 29 Mar 2022 11:49:30 +0200 Subject: [PATCH] wip --- slsReceiverSoftware/src/BinaryMasterFile.cpp | 8 +- slsReceiverSoftware/src/BinaryMasterFile.h | 1 - slsReceiverSoftware/src/DataProcessor.cpp | 2 +- slsReceiverSoftware/src/DataProcessor.h | 2 +- slsReceiverSoftware/src/HDF5MasterFile.cpp | 2 +- slsReceiverSoftware/src/HDF5MasterFile.h | 6 +- slsReceiverSoftware/src/Implementation.cpp | 119 +- slsReceiverSoftware/src/MasterAttributes.cpp | 1228 +++++++++--------- slsReceiverSoftware/src/MasterAttributes.h | 113 +- 9 files changed, 701 insertions(+), 780 deletions(-) diff --git a/slsReceiverSoftware/src/BinaryMasterFile.cpp b/slsReceiverSoftware/src/BinaryMasterFile.cpp index f6d0942fc..04fc0f2d7 100644 --- a/slsReceiverSoftware/src/BinaryMasterFile.cpp +++ b/slsReceiverSoftware/src/BinaryMasterFile.cpp @@ -47,12 +47,6 @@ std::string BinaryMasterFile::CreateMasterFile(const std::string filePath, std::string BinaryMasterFile::GetMasterAttributes(MasterAttributes *attr) { rapidjson::StringBuffer s; rapidjson::Writer writer(s); - writer.StartObject(); - - attr->GetCommonBinaryAttributes(&writer); - attr->GetSpecificBinaryAttributes(&writer); - attr->GetFinalBinaryAttributes(&writer); - - writer.EndObject(); + attr->GetBinaryAttributes(&writer); return s.GetString(); } diff --git a/slsReceiverSoftware/src/BinaryMasterFile.h b/slsReceiverSoftware/src/BinaryMasterFile.h index aaac736ab..9bfb4504a 100644 --- a/slsReceiverSoftware/src/BinaryMasterFile.h +++ b/slsReceiverSoftware/src/BinaryMasterFile.h @@ -2,7 +2,6 @@ // Copyright (C) 2021 Contributors to the SLS Detector Package #pragma once -#include "File.h" #include "MasterAttributes.h" class BinaryMasterFile : private virtual slsDetectorDefs { diff --git a/slsReceiverSoftware/src/DataProcessor.cpp b/slsReceiverSoftware/src/DataProcessor.cpp index 78985eaef..ed6788981 100644 --- a/slsReceiverSoftware/src/DataProcessor.cpp +++ b/slsReceiverSoftware/src/DataProcessor.cpp @@ -200,7 +200,7 @@ void DataProcessor::CreateVirtualFile( dataFile_->GetParameterNames(), dataFile_->GetParameterDataTypes()); } -void DataProcessor::LinkDataInMasterFile(const string &masterFileName, +void DataProcessor::LinkDataInMasterFile(const std::string &masterFileName, const bool silentMode, std::mutex *hdf5LibMutex) { std::string fname, datasetName; diff --git a/slsReceiverSoftware/src/DataProcessor.h b/slsReceiverSoftware/src/DataProcessor.h index 2b8aacb9f..2c8feed3d 100644 --- a/slsReceiverSoftware/src/DataProcessor.h +++ b/slsReceiverSoftware/src/DataProcessor.h @@ -68,7 +68,7 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject { const uint64_t numImages, const uint32_t dynamicRange, const int numModX, const int numModY, std::mutex *hdf5LibMutex); - void LinkDataInMasterFile(const string &masterFileName, + void LinkDataInMasterFile(const std::string &masterFileName, const bool silentMode, std::mutex *hdf5LibMutex); #endif diff --git a/slsReceiverSoftware/src/HDF5MasterFile.cpp b/slsReceiverSoftware/src/HDF5MasterFile.cpp index ea425f14d..35f15826e 100644 --- a/slsReceiverSoftware/src/HDF5MasterFile.cpp +++ b/slsReceiverSoftware/src/HDF5MasterFile.cpp @@ -99,7 +99,7 @@ std::string HDF5MasterFile::CreateMasterFile( Group group5(group3.createGroup("detector")); Group group6(group1.createGroup("sample")); - attr->WriteMasterHDF5Attributes(&fd, &group5); + attr->WriteHDF5Attributes(&fd, &group5); fd.close(); } catch (const Exception &error) { error.printErrorStack(); diff --git a/slsReceiverSoftware/src/HDF5MasterFile.h b/slsReceiverSoftware/src/HDF5MasterFile.h index bb5431ab7..4a9c3ae7c 100644 --- a/slsReceiverSoftware/src/HDF5MasterFile.h +++ b/slsReceiverSoftware/src/HDF5MasterFile.h @@ -2,15 +2,15 @@ // Copyright (C) 2021 Contributors to the SLS Detector Package #pragma once -#include "File.h" +#include "MasterAttributes.h" #include -class HDF5MasterFile : private virtual slsDetectorDefs, public File { +class HDF5MasterFile : private virtual slsDetectorDefs { public: void LinkDataFile(const std::string &masterFileName, const std::string &dataFilename, - const &std::string dataSetname, + const std::string &dataSetname, const std::vector parameterNames, const bool silentMode, std::mutex *hdf5LibMutex); std::string CreateMasterFile(const std::string &filePath, diff --git a/slsReceiverSoftware/src/Implementation.cpp b/slsReceiverSoftware/src/Implementation.cpp index 4d979f7da..ffa10e806 100644 --- a/slsReceiverSoftware/src/Implementation.cpp +++ b/slsReceiverSoftware/src/Implementation.cpp @@ -745,95 +745,68 @@ void Implementation::StartMasterWriter() { std::string masterFileName; // master file if (masterFileWriteEnable) { - std::unique_ptr masterAttributes{nullptr}; - switch (detType) { - case GOTTHARD: - masterAttributes = sls::make_unique(); - break; - case JUNGFRAU: - masterAttributes = sls::make_unique(); - break; - case EIGER: - masterAttributes = sls::make_unique(); - break; - case MYTHEN3: - masterAttributes = sls::make_unique(); - break; - case GOTTHARD2: - masterAttributes = - sls::make_unique(); - break; - case MOENCH: - masterAttributes = sls::make_unique(); - break; - case CHIPTESTBOARD: - masterAttributes = sls::make_unique(); - break; - default: - throw sls::RuntimeError( - "Unknown detector type to set up master file attributes"); - } - masterAttributes->detType = detType; - masterAttributes->timingMode = timingMode; + MasterAttributes masterAttributes; + masterAttributes.detType = detType; + masterAttributes.timingMode = timingMode; xy nm{numModules.x, numModules.y}; if (quadEnable) { nm.x = 1; nm.y = 2; } - masterAttributes->geometry = xy(nm.x, nm.y); - masterAttributes->imageSize = generalData->imageSize; - masterAttributes->nPixels = + masterAttributes.geometry = xy(nm.x, nm.y); + masterAttributes.imageSize = generalData->imageSize; + masterAttributes.nPixels = xy(generalData->nPixelsX, generalData->nPixelsY); - masterAttributes->maxFramesPerFile = framesPerFile; - masterAttributes->frameDiscardMode = frameDiscardMode; - masterAttributes->framePadding = framePadding; - masterAttributes->scanParams = scanParams; - masterAttributes->totalFrames = numberOfTotalFrames; - masterAttributes->exptime = acquisitionTime; - masterAttributes->period = acquisitionPeriod; - masterAttributes->burstMode = burstMode; - masterAttributes->numUDPInterfaces = numUDPInterfaces; - masterAttributes->dynamicRange = dynamicRange; - masterAttributes->tenGiga = tengigaEnable; - masterAttributes->thresholdEnergyeV = thresholdEnergyeV; - masterAttributes->thresholdAllEnergyeV = thresholdAllEnergyeV; - masterAttributes->subExptime = subExpTime; - masterAttributes->subPeriod = subPeriod; - masterAttributes->quad = quadEnable; - masterAttributes->readNRows = readNRows; - masterAttributes->ratecorr = rateCorrections; - masterAttributes->adcmask = + masterAttributes.maxFramesPerFile = framesPerFile; + masterAttributes.frameDiscardMode = frameDiscardMode; + masterAttributes.framePadding = framePadding; + masterAttributes.scanParams = scanParams; + masterAttributes.totalFrames = numberOfTotalFrames; + masterAttributes.exptime = acquisitionTime; + masterAttributes.period = acquisitionPeriod; + masterAttributes.burstMode = burstMode; + masterAttributes.numUDPInterfaces = numUDPInterfaces; + masterAttributes.dynamicRange = dynamicRange; + masterAttributes.tenGiga = tengigaEnable; + masterAttributes.thresholdEnergyeV = thresholdEnergyeV; + masterAttributes.thresholdAllEnergyeV = thresholdAllEnergyeV; + masterAttributes.subExptime = subExpTime; + masterAttributes.subPeriod = subPeriod; + masterAttributes.quad = quadEnable; + masterAttributes.readNRows = readNRows; + masterAttributes.ratecorr = rateCorrections; + masterAttributes.adcmask = tengigaEnable ? adcEnableMaskTenGiga : adcEnableMaskOneGiga; - masterAttributes->analog = (readoutType == ANALOG_ONLY || + masterAttributes.analog = (readoutType == ANALOG_ONLY || + readoutType == ANALOG_AND_DIGITAL) + ? 1 + : 0; + masterAttributes.analogSamples = numberOfAnalogSamples; + masterAttributes.digital = (readoutType == DIGITAL_ONLY || readoutType == ANALOG_AND_DIGITAL) ? 1 : 0; - masterAttributes->analogSamples = numberOfAnalogSamples; - masterAttributes->digital = (readoutType == DIGITAL_ONLY || - readoutType == ANALOG_AND_DIGITAL) - ? 1 - : 0; - masterAttributes->digitalSamples = numberOfDigitalSamples; - masterAttributes->dbitoffset = ctbDbitOffset; - masterAttributes->dbitlist = 0; + masterAttributes.digitalSamples = numberOfDigitalSamples; + masterAttributes.dbitoffset = ctbDbitOffset; + masterAttributes.dbitlist = 0; for (auto &i : ctbDbitList) { - masterAttributes->dbitlist |= (1 << i); + masterAttributes.dbitlist |= (1 << i); } - masterAttributes->roi = roi; - masterAttributes->counterMask = counterMask; - masterAttributes->exptime1 = acquisitionTime1; - masterAttributes->exptime2 = acquisitionTime2; - masterAttributes->exptime3 = acquisitionTime3; - masterAttributes->gateDelay1 = gateDelay1; - masterAttributes->gateDelay2 = gateDelay2; - masterAttributes->gateDelay3 = gateDelay3; - masterAttributes->gates = numberOfGates; - masterAttributes->additionalJsonHeader = additionalJsonHeader; + masterAttributes.roi = roi; + masterAttributes.counterMask = counterMask; + masterAttributes.exptimeArray[0] = acquisitionTime1; + masterAttributes.exptimeArray[1] = acquisitionTime2; + masterAttributes.exptimeArray[2] = acquisitionTime3; + masterAttributes.gateDelayArray[0] = gateDelay1; + masterAttributes.gateDelayArray[1] = gateDelay2; + masterAttributes.gateDelayArray[2] = gateDelay3; + masterAttributes.gates = numberOfGates; + masterAttributes.additionalJsonHeader = additionalJsonHeader; // create master file masterFileName = dataProcessor[0]->CreateMasterFile( filePath, fileName, fileIndex, overwriteEnable, silentMode, - fileFormatType, masterAttributes.get(), &hdf5LibMutex); + fileFormatType, &masterAttributes, &hdf5LibMutex); } #ifdef HDF5C if (fileFormatType == HDF5) { diff --git a/slsReceiverSoftware/src/MasterAttributes.cpp b/slsReceiverSoftware/src/MasterAttributes.cpp index f57c8aab6..250806cb6 100644 --- a/slsReceiverSoftware/src/MasterAttributes.cpp +++ b/slsReceiverSoftware/src/MasterAttributes.cpp @@ -2,29 +2,85 @@ // Copyright (C) 2021 Contributors to the SLS Detector Package #include "MasterAttributes.h" -void MasterAttributes::GetSpecificBinaryAttributes( +void MasterAttributes::GetBinaryAttributes( rapidjson::Writer *w) { - LOG(logERROR) << "WriteMasterBinaryAttributes should have been called " - "by a child class"; + w->StartObject(); + GetCommonBinaryAttributes(w); + switch (detType) { + case slsDetectorDefs::GOTTHARD: + GetGotthardBinaryAttributes(w); + break; + case slsDetectorDefs::JUNGFRAU: + GetJungfrauBinaryAttributes(w); + break; + case slsDetectorDefs::EIGER: + GetEigerBinaryAttributes(w); + break; + case slsDetectorDefs::MYTHEN3: + GetMythen3BinaryAttributes(w); + break; + case slsDetectorDefs::GOTTHARD2: + GetGotthard2BinaryAttributes(w); + break; + case slsDetectorDefs::MOENCH: + GetMoenchBinaryAttributes(w); + break; + case slsDetectorDefs::CHIPTESTBOARD: + GetCtbBinaryAttributes(w); + break; + default: + throw sls::RuntimeError( + "Unknown Detector type to get master attributes"); + } + GetFinalBinaryAttributes(w); + w->EndObject(); } +#ifdef HDF5C +void MasterAttributes::WriteHDF5Attributes(H5File *fd, Group *group) { + WriteCommonHDF5Attributes(fd, group); + switch (detType) { + case slsDetectorDefs::GOTTHARD: + WriteGotthardHDF5Attributes(fd, group); + break; + case slsDetectorDefs::JUNGFRAU: + WriteJungfrauHDF5Attributes(fd, group); + break; + case slsDetectorDefs::EIGER: + WriteEigerHDF5Attributes(fd, group); + break; + case slsDetectorDefs::MYTHEN3: + WriteMythen3HDF5Attributes(fd, group); + break; + case slsDetectorDefs::GOTTHARD2: + WriteGotthard2HDF5Attributes(fd, group); + break; + case slsDetectorDefs::MOENCH: + WriteMoenchHDF5Attributes(fd, group); + break; + case slsDetectorDefs::CHIPTESTBOARD: + WriteCtbHDF5Attributes(fd, group); + break; + default: + throw sls::RuntimeError( + "Unknown Detector type to get master attributes"); + } + WriteFinalHDF5Attributes(fd, group); +} +#endif + void MasterAttributes::GetCommonBinaryAttributes( rapidjson::Writer *w) { - w->Key("Version"); w->SetMaxDecimalPlaces(2); w->Double(BINARY_WRITER_VERSION); - w->Key("Timestamp"); time_t t = time(nullptr); w->String(ctime(&t)); - w->Key("Detector Type"); w->String(sls::ToString(detType).c_str()); - w->Key("Timing Mode"); w->String(sls::ToString(timingMode).c_str()); - w->Key("Geometry"); w->StartObject(); w->Key("x"); @@ -32,10 +88,8 @@ void MasterAttributes::GetCommonBinaryAttributes( w->Key("y"); w->Uint(geometry.y); w->EndObject(); - w->Key("Image Size in bytes"); w->Uint(imageSize); - w->Key("Pixels"); w->StartObject(); w->Key("x"); @@ -43,35 +97,27 @@ void MasterAttributes::GetCommonBinaryAttributes( w->Key("y"); w->Uint(nPixels.y); w->EndObject(); - w->Key("Max Frames Per File"); w->Uint(maxFramesPerFile); - w->Key("Frame Discard Policy"); w->String(sls::ToString(frameDiscardMode).c_str()); - w->Key("Frame Padding"); w->Uint(framePadding); - w->Key("Scan Parameters"); w->String(sls::ToString(scanParams).c_str()); - w->Key("Total Frames"); w->Uint64(totalFrames); -}; +} void MasterAttributes::GetFinalBinaryAttributes( rapidjson::Writer *w) { // adding few common parameters to the end - if (!additionalJsonHeader.empty()) { w->Key("Additional Json Header"); w->String(sls::ToString(additionalJsonHeader).c_str()); } - w->Key("Frames in File"); w->Uint64(framesInFile); - w->Key("Frame Header Format"); w->StartObject(); w->Key("Frame Number"); @@ -103,658 +149,578 @@ void MasterAttributes::GetFinalBinaryAttributes( w->Key("Packets Caught Mask"); w->String("64 bytes"); w->EndObject(); -}; +} #ifdef HDF5C -void MasterAttributes::WriteMasterHDF5Attributes(H5File *fd, Group *group) { - LOG(logERROR) << "WriteMasterHdf5Attributes should have been called " - "by a child class"; -}; - -void MasterAttributes::WriteHDF5Attributes(H5File *fd, Group *group) { +void MasterAttributes::WriteCommonHDF5Attributes(H5File *fd, Group *group) { char c[1024]; memset(c, 0, sizeof(c)); - // clang-format off - // version - { - double version = BINARY_WRITER_VERSION; - DataSpace dataspace = DataSpace(H5S_SCALAR); - Attribute attribute = fd->createAttribute( - "Version", PredType::NATIVE_DOUBLE, dataspace); - attribute.write(PredType::NATIVE_DOUBLE, &version); - } - // timestamp - { - time_t t = time(nullptr); - StrType strdatatype(PredType::C_S1, 256); - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = + // version + { + double version = BINARY_WRITER_VERSION; + DataSpace dataspace = DataSpace(H5S_SCALAR); + Attribute attribute = + fd->createAttribute("Version", PredType::NATIVE_DOUBLE, dataspace); + attribute.write(PredType::NATIVE_DOUBLE, &version); + } + // timestamp + { + time_t t = time(nullptr); + StrType strdatatype(PredType::C_S1, 256); + DataSpace dataspace = DataSpace(H5S_SCALAR); + DataSet dataset = group->createDataSet("Timestamp", strdatatype, dataspace); - sls::strcpy_safe(c, std::string(ctime(&t))); - dataset.write(c, strdatatype); - } - // detector type - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - StrType strdatatype(PredType::C_S1, 256); - DataSet dataset = + sls::strcpy_safe(c, std::string(ctime(&t))); + dataset.write(c, strdatatype); + } + // detector type + { + DataSpace dataspace = DataSpace(H5S_SCALAR); + StrType strdatatype(PredType::C_S1, 256); + DataSet dataset = group->createDataSet("Detector Type", strdatatype, dataspace); - sls::strcpy_safe(c, sls::ToString(detType)); - dataset.write(c, strdatatype); - } - // timing mode - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - StrType strdatatype(PredType::C_S1, 256); - DataSet dataset = + sls::strcpy_safe(c, sls::ToString(detType)); + dataset.write(c, strdatatype); + } + // timing mode + { + DataSpace dataspace = DataSpace(H5S_SCALAR); + StrType strdatatype(PredType::C_S1, 256); + DataSet dataset = group->createDataSet("Timing Mode", strdatatype, dataspace); - sls::strcpy_safe(c, sls::ToString(timingMode)); - dataset.write(c, strdatatype); - } - //TODO: make this into an array? - // geometry x - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group->createDataSet( - "Geometry in x axis", PredType::NATIVE_INT, dataspace); - dataset.write(&geometry.x, PredType::NATIVE_INT); - } - // geometry y - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group->createDataSet( - "Geometry in y axis", PredType::NATIVE_INT, dataspace); - dataset.write(&geometry.y, PredType::NATIVE_INT); - } - // Image Size - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group->createDataSet( - "Image Size", PredType::NATIVE_INT, dataspace); - dataset.write(&imageSize, PredType::NATIVE_INT); - DataSpace dataspaceAttr = DataSpace(H5S_SCALAR); - StrType strdatatype(PredType::C_S1, 256); - Attribute attribute = - dataset.createAttribute("Unit", strdatatype, dataspaceAttr); - sls::strcpy_safe(c, "bytes"); - attribute.write(strdatatype, c); - } - //TODO: make this into an array? - // npixels x - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group->createDataSet( - "Number of pixels in x axis", PredType::NATIVE_INT, dataspace); - dataset.write(&nPixels.x, PredType::NATIVE_INT); - } - // npixels y - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group->createDataSet( - "Number of pixels in y axis", PredType::NATIVE_INT, dataspace); - dataset.write(&nPixels.y, PredType::NATIVE_INT); - } - // Maximum frames per file - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group->createDataSet( - "Maximum frames per file", PredType::NATIVE_INT, dataspace); - dataset.write(&maxFramesPerFile, PredType::NATIVE_INT); - } - // Frame Discard Policy - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - StrType strdatatype(PredType::C_S1, 256); - DataSet dataset = - group->createDataSet("Frame Discard Policy", strdatatype, dataspace); - sls::strcpy_safe(c, sls::ToString(frameDiscardMode)); - dataset.write(c, strdatatype); - } - // Frame Padding - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group->createDataSet( - "Frame Padding", PredType::NATIVE_INT, dataspace); - dataset.write(&framePadding, PredType::NATIVE_INT); - } - // Scan Parameters - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - StrType strdatatype(PredType::C_S1, 256); - DataSet dataset = - group->createDataSet("Scan Parameters", strdatatype, dataspace); - sls::strcpy_safe(c, sls::ToString(scanParams)); - dataset.write(c, strdatatype); - } - // Total Frames - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group->createDataSet( - "Total Frames", PredType::STD_U64LE, dataspace); - dataset.write(&totalFrames, PredType::STD_U64LE); - } - }; - - void MasterAttributes::WriteFinalHDF5Attributes(H5File *fd, Group *group) { - char c[1024]; - memset(c, 0, sizeof(c)); - // Total Frames in file - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group->createDataSet( - "Frames in File", PredType::STD_U64LE, dataspace); - dataset.write(&framesInFile, PredType::STD_U64LE); - } - // additional json header - if (!additionalJsonHeader.empty()) { - std::string json = sls::ToString(additionalJsonHeader); - StrType strdatatype(PredType::C_S1, json.length()); - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = - group->createDataSet("Additional JSON Header", strdatatype, dataspace); - sls::strcpy_safe(c, sls::ToString(additionalJsonHeader)); - dataset.write(c, strdatatype); - } - }; - - void MasterAttributes::WriteHDF5Exptime(H5File *fd, Group *group) { - DataSpace dataspace = DataSpace(H5S_SCALAR); - StrType strdatatype(PredType::C_S1, 256); - DataSet dataset = - group->createDataSet("Exposure Time", strdatatype, dataspace); - char c[1024]; - memset(c, 0, sizeof(c)); - sls::strcpy_safe(c, sls::ToString(exptime)); + sls::strcpy_safe(c, sls::ToString(timingMode)); dataset.write(c, strdatatype); - }; - - void MasterAttributes::WriteHDF5Period(H5File *fd, Group *group) { + } + // TODO: make this into an array? + // geometry x + { + DataSpace dataspace = DataSpace(H5S_SCALAR); + DataSet dataset = group->createDataSet("Geometry in x axis", + PredType::NATIVE_INT, dataspace); + dataset.write(&geometry.x, PredType::NATIVE_INT); + } + // geometry y + { + DataSpace dataspace = DataSpace(H5S_SCALAR); + DataSet dataset = group->createDataSet("Geometry in y axis", + PredType::NATIVE_INT, dataspace); + dataset.write(&geometry.y, PredType::NATIVE_INT); + } + // Image Size + { DataSpace dataspace = DataSpace(H5S_SCALAR); - StrType strdatatype(PredType::C_S1, 256); DataSet dataset = - group->createDataSet("Acquisition Period", strdatatype, dataspace); - char c[1024]; - memset(c, 0, sizeof(c)); - sls::strcpy_safe(c, sls::ToString(period)); - dataset.write(c, strdatatype); - }; - - void MasterAttributes::WriteHDF5DynamicRange(H5File *fd, Group *group) { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group->createDataSet( - "Dynamic Range", PredType::NATIVE_INT, dataspace); - dataset.write(&dynamicRange, PredType::NATIVE_INT); + group->createDataSet("Image Size", PredType::NATIVE_INT, dataspace); + dataset.write(&imageSize, PredType::NATIVE_INT); DataSpace dataspaceAttr = DataSpace(H5S_SCALAR); StrType strdatatype(PredType::C_S1, 256); Attribute attribute = - dataset.createAttribute("Unit", strdatatype, dataspaceAttr); - char c[1024] = "bits"; - attribute.write( strdatatype, c); - }; - - void MasterAttributes::WriteHDF5TenGiga(H5File *fd, Group *group) { + dataset.createAttribute("Unit", strdatatype, dataspaceAttr); + sls::strcpy_safe(c, "bytes"); + attribute.write(strdatatype, c); + } + // TODO: make this into an array? + // npixels x + { DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group->createDataSet( - "Ten Giga Enable", PredType::NATIVE_INT, dataspace); - dataset.write(&tenGiga, PredType::NATIVE_INT); - }; + DataSet dataset = group->createDataSet("Number of pixels in x axis", + PredType::NATIVE_INT, dataspace); + dataset.write(&nPixels.x, PredType::NATIVE_INT); + } + // npixels y + { + DataSpace dataspace = DataSpace(H5S_SCALAR); + DataSet dataset = group->createDataSet("Number of pixels in y axis", + PredType::NATIVE_INT, dataspace); + dataset.write(&nPixels.y, PredType::NATIVE_INT); + } + // Maximum frames per file + { + DataSpace dataspace = DataSpace(H5S_SCALAR); + DataSet dataset = group->createDataSet("Maximum frames per file", + PredType::NATIVE_INT, dataspace); + dataset.write(&maxFramesPerFile, PredType::NATIVE_INT); + } + // Frame Discard Policy + { + DataSpace dataspace = DataSpace(H5S_SCALAR); + StrType strdatatype(PredType::C_S1, 256); + DataSet dataset = group->createDataSet("Frame Discard Policy", + strdatatype, dataspace); + sls::strcpy_safe(c, sls::ToString(frameDiscardMode)); + dataset.write(c, strdatatype); + } + // Frame Padding + { + DataSpace dataspace = DataSpace(H5S_SCALAR); + DataSet dataset = group->createDataSet("Frame Padding", + PredType::NATIVE_INT, dataspace); + dataset.write(&framePadding, PredType::NATIVE_INT); + } + // Scan Parameters + { + DataSpace dataspace = DataSpace(H5S_SCALAR); + StrType strdatatype(PredType::C_S1, 256); + DataSet dataset = + group->createDataSet("Scan Parameters", strdatatype, dataspace); + sls::strcpy_safe(c, sls::ToString(scanParams)); + dataset.write(c, strdatatype); + } + // Total Frames + { + DataSpace dataspace = DataSpace(H5S_SCALAR); + DataSet dataset = group->createDataSet("Total Frames", + PredType::STD_U64LE, dataspace); + dataset.write(&totalFrames, PredType::STD_U64LE); + } +} + +void MasterAttributes::WriteFinalHDF5Attributes(H5File *fd, Group *group) { + char c[1024]; + memset(c, 0, sizeof(c)); + // Total Frames in file + { + DataSpace dataspace = DataSpace(H5S_SCALAR); + DataSet dataset = group->createDataSet("Frames in File", + PredType::STD_U64LE, dataspace); + dataset.write(&framesInFile, PredType::STD_U64LE); + } + // additional json header + if (!additionalJsonHeader.empty()) { + std::string json = sls::ToString(additionalJsonHeader); + StrType strdatatype(PredType::C_S1, json.length()); + DataSpace dataspace = DataSpace(H5S_SCALAR); + DataSet dataset = group->createDataSet("Additional JSON Header", + strdatatype, dataspace); + sls::strcpy_safe(c, sls::ToString(additionalJsonHeader)); + dataset.write(c, strdatatype); + } +} + +void MasterAttributes::WriteHDF5Exptime(H5File *fd, Group *group) { + DataSpace dataspace = DataSpace(H5S_SCALAR); + StrType strdatatype(PredType::C_S1, 256); + DataSet dataset = + group->createDataSet("Exposure Time", strdatatype, dataspace); + char c[1024]; + memset(c, 0, sizeof(c)); + sls::strcpy_safe(c, sls::ToString(exptime)); + dataset.write(c, strdatatype); +} + +void MasterAttributes::WriteHDF5Period(H5File *fd, Group *group) { + DataSpace dataspace = DataSpace(H5S_SCALAR); + StrType strdatatype(PredType::C_S1, 256); + DataSet dataset = + group->createDataSet("Acquisition Period", strdatatype, dataspace); + char c[1024]; + memset(c, 0, sizeof(c)); + sls::strcpy_safe(c, sls::ToString(period)); + dataset.write(c, strdatatype); +} + +void MasterAttributes::WriteHDF5DynamicRange(H5File *fd, Group *group) { + DataSpace dataspace = DataSpace(H5S_SCALAR); + DataSet dataset = + group->createDataSet("Dynamic Range", PredType::NATIVE_INT, dataspace); + dataset.write(&dynamicRange, PredType::NATIVE_INT); + DataSpace dataspaceAttr = DataSpace(H5S_SCALAR); + StrType strdatatype(PredType::C_S1, 256); + Attribute attribute = + dataset.createAttribute("Unit", strdatatype, dataspaceAttr); + char c[1024] = "bits"; + attribute.write(strdatatype, c); +} + +void MasterAttributes::WriteHDF5TenGiga(H5File *fd, Group *group) { + DataSpace dataspace = DataSpace(H5S_SCALAR); + DataSet dataset = group->createDataSet("Ten Giga Enable", + PredType::NATIVE_INT, dataspace); + dataset.write(&tenGiga, PredType::NATIVE_INT); +} + +void MasterAttributes::WriteHDF5ROI(H5File *fd, Group *group) { + // Roi xmin + { + DataSpace dataspace = DataSpace(H5S_SCALAR); + DataSet dataset = + group->createDataSet("roi xmin", PredType::NATIVE_INT, dataspace); + dataset.write(&roi.xmin, PredType::NATIVE_INT); + } + // Roi xmax + { + DataSpace dataspace = DataSpace(H5S_SCALAR); + DataSet dataset = + group->createDataSet("roi xmax", PredType::NATIVE_INT, dataspace); + dataset.write(&roi.xmax, PredType::NATIVE_INT); + } +} + +void MasterAttributes::WriteHDF5NumUDPInterfaces(H5File *fd, Group *group) { + DataSpace dataspace = DataSpace(H5S_SCALAR); + DataSet dataset = group->createDataSet("Number of UDP Interfaces", + PredType::NATIVE_INT, dataspace); + dataset.write(&numUDPInterfaces, PredType::NATIVE_INT); +} + +void MasterAttributes::WriteHDF5ReadNRows(H5File *fd, Group *group) { + DataSpace dataspace = DataSpace(H5S_SCALAR); + DataSet dataset = + group->createDataSet("Number of rows", PredType::NATIVE_INT, dataspace); + dataset.write(&readNRows, PredType::NATIVE_INT); +} + +void MasterAttributes::WriteHDF5ThresholdEnergy(H5File *fd, Group *group) { + char c[1024]{0}; + DataSpace dataspace = DataSpace(H5S_SCALAR); + DataSet dataset = group->createDataSet("Threshold Energy", + PredType::NATIVE_INT, dataspace); + dataset.write(&thresholdEnergyeV, PredType::NATIVE_INT); + DataSpace dataspaceAttr = DataSpace(H5S_SCALAR); + StrType strdatatype(PredType::C_S1, 256); + Attribute attribute = + dataset.createAttribute("Unit", strdatatype, dataspaceAttr); + sls::strcpy_safe(c, "eV"); + attribute.write(strdatatype, c); +} + +void MasterAttributes::WriteHDF5ThresholdEnergies(H5File *fd, Group *group) { + DataSpace dataspace = DataSpace(H5S_SCALAR); + StrType strdatatype(PredType::C_S1, 1024); + DataSet dataset = + group->createDataSet("Threshold Energies", strdatatype, dataspace); + sls::strcpy_safe(c, sls::ToString(thresholdAllEnergyeV)); + dataset.write(c, strdatatype); +} + +void MasterAttributes::WriteHDF5SubExpTime(H5File *fd, Group *group) { + char c[1024]{0}; + DataSpace dataspace = DataSpace(H5S_SCALAR); + StrType strdatatype(PredType::C_S1, 256); + DataSet dataset = + group->createDataSet("Sub Exposure Time", strdatatype, dataspace); + sls::strcpy_safe(c, sls::ToString(subExptime)); + dataset.write(c, strdatatype); +} + +void MasterAttributes::WriteHDF5SubPeriod(H5File *fd, Group *group) { + char c[1024]{0}; + DataSpace dataspace = DataSpace(H5S_SCALAR); + StrType strdatatype(PredType::C_S1, 256); + DataSet dataset = + group->createDataSet("Sub Period", strdatatype, dataspace); + sls::strcpy_safe(c, sls::ToString(subPeriod)); + dataset.write(c, strdatatype); +} + +void MasterAttributes::WriteHDF5SubQuad(H5File *fd, Group *group) { + DataSpace dataspace = DataSpace(H5S_SCALAR); + DataSet dataset = + group->createDataSet("Quad", PredType::NATIVE_INT, dataspace); + dataset.write(&quad, PredType::NATIVE_INT); +} + +void MasterAttributes::WriteHDF5RateCorrections(H5File *fd, Group *group) { + char c[1024]{0}; + DataSpace dataspace = DataSpace(H5S_SCALAR); + StrType strdatatype(PredType::C_S1, 1024); + DataSet dataset = + group->createDataSet("Rate Corrections", strdatatype, dataspace); + sls::strcpy_safe(c, sls::ToString(ratecorr)); + dataset.write(c, strdatatype); +} + +void MasterAttributes::WriteHDF5CounterMask(H5File *fd, Group *group) { + DataSpace dataspace = DataSpace(H5S_SCALAR); + DataSet dataset = + group->createDataSet("Counter Mask", PredType::STD_U32LE, dataspace); + dataset.write(&counterMask, PredType::STD_U32LE); +} + +void MasterAttributes::WriteHDF5ExptimeArray(H5File *fd, Group *group) { + for (int i = 0; i != 3; ++i) { + char c[1024]{0}; + DataSpace dataspace = DataSpace(H5S_SCALAR); + StrType strdatatype(PredType::C_S1, 256); + DataSet dataset = + group->createDataSet("Exposure Time1", strdatatype, dataspace); + sls::strcpy_safe(c, sls::ToString(exptimeArray[i])); + dataset.write(c, strdatatype); + } +} + +void MasterAttributes::WriteHDF5GateDelayArray(H5File *fd, Group *group) { + for (int i = 0; i != 3; ++i) { + char c[1024]{0}; + DataSpace dataspace = DataSpace(H5S_SCALAR); + StrType strdatatype(PredType::C_S1, 256); + DataSet dataset = + group->createDataSet("Gate Delay1", strdatatype, dataspace); + sls::strcpy_safe(c, sls::ToString(gateDelayArray[i])); + dataset.write(c, strdatatype); + } +} + +void MasterAttributes::WriteHDF5Gates(H5File *fd, Group *group) { + DataSpace dataspace = DataSpace(H5S_SCALAR); + DataSet dataset = + group->createDataSet("Gates", PredType::STD_U32LE, dataspace); + dataset.write(&gates, PredType::STD_U32LE); +} + +void MasterAttributes::WriteHDF5BurstMode(H5File *fd, Group *group) { + DataSpace dataspace = DataSpace(H5S_SCALAR); + StrType strdatatype(PredType::C_S1, 256); + DataSet dataset = + group->createDataSet("Burst Mode", strdatatype, dataspace); + char c[1024]; + memset(c, 0, sizeof(c)); + sls::strcpy_safe(c, sls::ToString(burstMode)); + dataset.write(c, strdatatype); +} + +void MasterAttributes::WriteHDF5AdcMask(H5File *fd, Group *group) { + DataSpace dataspace = DataSpace(H5S_SCALAR); + DataSet dataset = + group->createDataSet("ADC Mask", PredType::NATIVE_INT, dataspace); + dataset.write(&adcmask, PredType::NATIVE_INT); +} + +void MasterAttributes::WriteHDF5AnalogFlag(H5File *fd, Group *group) { + DataSpace dataspace = DataSpace(H5S_SCALAR); + DataSet dataset = + group->createDataSet("Analog Flag", PredType::NATIVE_INT, dataspace); + dataset.write(&analog, PredType::NATIVE_INT); +} + +void MasterAttributes::WriteHDF5AnalogSamples(H5File *fd, Group *group) { + DataSpace dataspace = DataSpace(H5S_SCALAR); + DataSet dataset = + group->createDataSet("Analog Samples", PredType::NATIVE_INT, dataspace); + dataset.write(&analogSamples, PredType::NATIVE_INT); +} + +void MasterAttributes::WriteHDF5DigitalFlag(H5File *fd, Group *group) { + DataSpace dataspace = DataSpace(H5S_SCALAR); + DataSet dataset = + group->createDataSet("Digital Flag", PredType::NATIVE_INT, dataspace); + dataset.write(&digital, PredType::NATIVE_INT); +} + +void MasterAttributes::WriteHDF5DigitalSamples(H5File *fd, Group *group) { + DataSpace dataspace = DataSpace(H5S_SCALAR); + DataSet dataset = group->createDataSet("Digital Samples", + PredType::NATIVE_INT, dataspace); + dataset.write(&digitalSamples, PredType::NATIVE_INT); +} + +void MasterAttributes::WriteHDF5DbitOffset(H5File *fd, Group *group) { + DataSpace dataspace = DataSpace(H5S_SCALAR); + DataSet dataset = + group->createDataSet("Dbit Offset", PredType::NATIVE_INT, dataspace); + dataset.write(&dbitoffset, PredType::NATIVE_INT); +} + +void MasterAttributes::WriteHDF5DbitList(H5File *fd, Group *group) { + DataSpace dataspace = DataSpace(H5S_SCALAR); + DataSet dataset = group->createDataSet("Dbit Bitset List", + PredType::STD_U64LE, dataspace); + dataset.write(&dbitlist, PredType::STD_U64LE); +} #endif - void GotthardMasterAttributes::GetSpecificBinaryAttributes(rapidjson::Writer *w) { - w->Key("Exptime"); - w->String(sls::ToString(exptime).c_str()); - - w->Key("Period"); - w->String(sls::ToString(period).c_str()); - - w->Key("Roi (xmin, xmax)"); - w->String(sls::ToString(roi).c_str()); - }; +void MasterAttributes::GetGotthardBinaryAttributes( + rapidjson::Writer *w) { + w->Key("Exptime"); + w->String(sls::ToString(exptime).c_str()); + w->Key("Period"); + w->String(sls::ToString(period).c_str()); + w->Key("Roi (xmin, xmax)"); + w->String(sls::ToString(roi).c_str()); +}; #ifdef HDF5C - void GotthardMasterAttributes::WriteMasterHDF5Attributes(H5File *fd, Group *group) { - MasterAttributes::WriteHDF5Attributes(fd, group); - MasterAttributes::WriteHDF5Exptime(fd, group); - MasterAttributes::WriteHDF5Period(fd, group); - // Roi xmin - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group->createDataSet( - "roi xmin", PredType::NATIVE_INT, dataspace); - dataset.write(&roi.xmin, PredType::NATIVE_INT); - } - // Roi xmax - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group->createDataSet( - "roi xmax", PredType::NATIVE_INT, dataspace); - dataset.write(&roi.xmax, PredType::NATIVE_INT); - } - MasterAttributes::WriteFinalHDF5Attributes(fd, group); - }; +void MasterAttributes::WriteGotthardHDF5Attributes(H5File *fd, Group *group) { + MasterAttributes::WriteHDF5Exptime(fd, group); + MasterAttributes::WriteHDF5Period(fd, group); + MasterAttributes::WriteHDF5ROI(fd, group); +} #endif - void JungfrauMasterAttributes::GetSpecificBinaryAttributes(rapidjson::Writer *w) { - w->Key("Exptime"); - w->String(sls::ToString(exptime).c_str()); - - w->Key("Period"); - w->String(sls::ToString(period).c_str()); - - w->Key("Number of UDP Interfaces"); - w->Uint(numUDPInterfaces); - - w->Key("Number of rows"); - w->Uint(readNRows); - }; +void MasterAttributes::GetJungfrauBinaryAttributes( + rapidjson::Writer *w) { + w->Key("Exptime"); + w->String(sls::ToString(exptime).c_str()); + w->Key("Period"); + w->String(sls::ToString(period).c_str()); + w->Key("Number of UDP Interfaces"); + w->Uint(numUDPInterfaces); + w->Key("Number of rows"); + w->Uint(readNRows); +} #ifdef HDF5C - void JungfrauMasterAttributes::WriteMasterHDF5Attributes(H5File *fd, Group *group) { - MasterAttributes::WriteHDF5Attributes(fd, group); - MasterAttributes::WriteHDF5Exptime(fd, group); - MasterAttributes::WriteHDF5Period(fd, group); - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group->createDataSet( - "Number of UDP Interfaces", PredType::NATIVE_INT, dataspace); - dataset.write(&numUDPInterfaces, PredType::NATIVE_INT); - } - // readNRows - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group->createDataSet( - "Number of rows", PredType::NATIVE_INT, dataspace); - dataset.write(&readNRows, PredType::NATIVE_INT); - } - MasterAttributes::WriteFinalHDF5Attributes(fd, group); - }; +void MasterAttributes::WriteJungfrauHDF5Attributes(H5File *fd, Group *group) { + MasterAttributes::WriteHDF5Exptime(fd, group); + MasterAttributes::WriteHDF5Period(fd, group); + MasterAttributes::WriteHDF5NumUDPInterfaces(fd, group); + MasterAttributes::WriteHDF5ReadNRows(fd, group); +} #endif - void EigerMasterAttributes::GetSpecificBinaryAttributes(rapidjson::Writer *w) { - w->Key("Dynamic Range"); - w->Uint(dynamicRange); - - w->Key("Ten Giga"); - w->Uint(tenGiga); - - w->Key("Exptime"); - w->String(sls::ToString(exptime).c_str()); - - w->Key("Period"); - w->String(sls::ToString(period).c_str()); - - w->Key("Threshold Energy"); - w->Int(thresholdEnergyeV); - - w->Key("Sub Exptime"); - w->String(sls::ToString(subExptime).c_str()); - - w->Key("Sub Period"); - w->String(sls::ToString(subPeriod).c_str()); - - w->Key("Quad"); - w->Int(quad); - - w->Key("Number of rows"); - w->Int(readNRows); - - w->Key("Rate Corrections"); - w->String(sls::ToString(ratecorr).c_str()); - }; +void MasterAttributes::GetEigerBinaryAttributes( + rapidjson::Writer *w) { + w->Key("Dynamic Range"); + w->Uint(dynamicRange); + w->Key("Ten Giga"); + w->Uint(tenGiga); + w->Key("Exptime"); + w->String(sls::ToString(exptime).c_str()); + w->Key("Period"); + w->String(sls::ToString(period).c_str()); + w->Key("Threshold Energy"); + w->Int(thresholdEnergyeV); + w->Key("Sub Exptime"); + w->String(sls::ToString(subExptime).c_str()); + w->Key("Sub Period"); + w->String(sls::ToString(subPeriod).c_str()); + w->Key("Quad"); + w->Int(quad); + w->Key("Number of rows"); + w->Int(readNRows); + w->Key("Rate Corrections"); + w->String(sls::ToString(ratecorr).c_str()); +} #ifdef HDF5C - void EigerMasterAttributes::WriteMasterHDF5Attributes(H5File *fd, Group *group) { - MasterAttributes::WriteHDF5Attributes(fd, group); - MasterAttributes::WriteHDF5DynamicRange(fd, group); - MasterAttributes::WriteHDF5TenGiga(fd, group); - MasterAttributes::WriteHDF5Exptime(fd, group); - MasterAttributes::WriteHDF5Period(fd, group); - char c[1024]; - memset(c, 0, sizeof(c)); - // threshold - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group->createDataSet( - "Threshold Energy", PredType::NATIVE_INT, dataspace); - dataset.write(&thresholdEnergyeV, PredType::NATIVE_INT); - DataSpace dataspaceAttr = DataSpace(H5S_SCALAR); - StrType strdatatype(PredType::C_S1, 256); - Attribute attribute = - dataset.createAttribute("Unit", strdatatype, dataspaceAttr); - sls::strcpy_safe(c, "eV"); - attribute.write(strdatatype, c); - } - // SubExptime - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - StrType strdatatype(PredType::C_S1, 256); - DataSet dataset = group->createDataSet("Sub Exposure Time", - strdatatype, dataspace); - sls::strcpy_safe(c, sls::ToString(subExptime)); - dataset.write(c, strdatatype); - } - // SubPeriod - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - StrType strdatatype(PredType::C_S1, 256); - DataSet dataset = - group->createDataSet("Sub Period", strdatatype, dataspace); - sls::strcpy_safe(c, sls::ToString(subPeriod)); - dataset.write(c, strdatatype); - } - // Quad - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = - group->createDataSet("Quad", PredType::NATIVE_INT, dataspace); - dataset.write(&quad, PredType::NATIVE_INT); - } - // readNRows - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group->createDataSet( - "Number of rows", PredType::NATIVE_INT, dataspace); - dataset.write(&readNRows, PredType::NATIVE_INT); - } - // Rate corrections - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - StrType strdatatype(PredType::C_S1, 1024); - DataSet dataset = group->createDataSet("Rate Corrections", - strdatatype, dataspace); - sls::strcpy_safe(c, sls::ToString(ratecorr)); - dataset.write(c, strdatatype); - } - MasterAttributes::WriteFinalHDF5Attributes(fd, group); - }; +void MasterAttributes::WriteEigerHDF5Attributes(H5File *fd, Group *group) { + MasterAttributes::WriteHDF5DynamicRange(fd, group); + MasterAttributes::WriteHDF5TenGiga(fd, group); + MasterAttributes::WriteHDF5Exptime(fd, group); + MasterAttributes::WriteHDF5Period(fd, group); + MasterAttributes::WriteHDF5ThresholdEnergy(fd, group); + MasterAttributes::WriteHDF5SubExpTime(fd, group); + MasterAttributes::WriteHDF5SubPeriod(fd, group); + MasterAttributes::WriteHDF5SubQuad(fd, group); + MasterAttributes::WriteHDF5ReadNRows(fd, group); + MasterAttributes::WriteHDF5RateCorrections(fd, group); +} #endif - void Mythen3MasterAttributes::GetSpecificBinaryAttributes(rapidjson::Writer *w) { - w->Key("Dynamic Range"); - w->Uint(dynamicRange); - - w->Key("Ten Giga"); - w->Uint(tenGiga); - - w->Key("Period"); - w->String(sls::ToString(period).c_str()); - - w->Key("Counter Mask"); - w->String(sls::ToStringHex(counterMask).c_str()); - - w->Key("Exptime1"); - w->String(sls::ToString(exptime1).c_str()); - - w->Key("Exptime2"); - w->String(sls::ToString(exptime2).c_str()); - - w->Key("Exptime3"); - w->String(sls::ToString(exptime3).c_str()); - - w->Key("GateDelay1"); - w->String(sls::ToString(gateDelay1).c_str()); - - w->Key("GateDelay2"); - w->String(sls::ToString(gateDelay2).c_str()); - - w->Key("GateDelay3"); - w->String(sls::ToString(gateDelay3).c_str()); - - w->Key("Gates"); - w->Uint(gates); - - w->Key("Threshold Energies"); - w->String(sls::ToString(thresholdAllEnergyeV).c_str()); - }; +void MasterAttributes::GetMythen3BinaryAttributes( + rapidjson::Writer *w) { + w->Key("Dynamic Range"); + w->Uint(dynamicRange); + w->Key("Ten Giga"); + w->Uint(tenGiga); + w->Key("Period"); + w->String(sls::ToString(period).c_str()); + w->Key("Counter Mask"); + w->String(sls::ToStringHex(counterMask).c_str()); + for (int i = 0; i != 3; ++i) { + w->Key((std::string("Exptime") + std::to_string(i + 1)).c_str()); + w->String(sls::ToString(exptimeArray[i]).c_str()); + } + for (int i = 0; i != 3; ++i) { + w->Key((std::string("GateDelay") + std::to_string(i + 1)).c_str()); + w->String(sls::ToString(gateDelayArray[i]).c_str()); + } + w->Key("Gates"); + w->Uint(gates); + w->Key("Threshold Energies"); + w->String(sls::ToString(thresholdAllEnergyeV).c_str()); +} #ifdef HDF5C - void Mythen3MasterAttributes::WriteMasterHDF5Attributes(H5File *fd, Group *group) { - MasterAttributes::WriteHDF5Attributes(fd, group); - MasterAttributes::WriteHDF5DynamicRange(fd, group); - MasterAttributes::WriteHDF5TenGiga(fd, group); - MasterAttributes::WriteHDF5Period(fd, group); - char c[1024]; - memset(c, 0, sizeof(c)); - // Counter Mask - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group->createDataSet( - "Counter Mask", PredType::STD_U32LE, dataspace); - dataset.write(&counterMask, PredType::STD_U32LE); - } - // Exptime1 - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - StrType strdatatype(PredType::C_S1, 256); - DataSet dataset = - group->createDataSet("Exposure Time1", strdatatype, dataspace); - sls::strcpy_safe(c, sls::ToString(exptime1)); - dataset.write(c, strdatatype); - } - // Exptime2 - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - StrType strdatatype(PredType::C_S1, 256); - DataSet dataset = - group->createDataSet("Exposure Time2", strdatatype, dataspace); - sls::strcpy_safe(c, sls::ToString(exptime2)); - dataset.write(c, strdatatype); - } - // Exptime3 - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - StrType strdatatype(PredType::C_S1, 256); - DataSet dataset = - group->createDataSet("Exposure Time3", strdatatype, dataspace); - sls::strcpy_safe(c, sls::ToString(exptime3)); - dataset.write(c, strdatatype); - } - // GateDelay1 - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - StrType strdatatype(PredType::C_S1, 256); - DataSet dataset = - group->createDataSet("Gate Delay1", strdatatype, dataspace); - sls::strcpy_safe(c, sls::ToString(gateDelay1)); - dataset.write(c, strdatatype); - } - // GateDelay2 - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - StrType strdatatype(PredType::C_S1, 256); - DataSet dataset = - group->createDataSet("Gate Delay2", strdatatype, dataspace); - sls::strcpy_safe(c, sls::ToString(gateDelay2)); - dataset.write(c, strdatatype); - } - // GateDelay3 - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - StrType strdatatype(PredType::C_S1, 256); - DataSet dataset = - group->createDataSet("Gate Delay3", strdatatype, dataspace); - sls::strcpy_safe(c, sls::ToString(gateDelay3)); - dataset.write(c, strdatatype); - } - // Gates - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = - group->createDataSet("Gates", PredType::STD_U32LE, dataspace); - dataset.write(&gates, PredType::STD_U32LE); - } - // Threshold Energies - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - StrType strdatatype(PredType::C_S1, 1024); - DataSet dataset = group->createDataSet("Threshold Energies", - strdatatype, dataspace); - sls::strcpy_safe(c, sls::ToString(thresholdAllEnergyeV)); - dataset.write(c, strdatatype); - } - MasterAttributes::WriteFinalHDF5Attributes(fd, group); - }; +void MasterAttributes::WriteMythen3HDF5Attributes(H5File *fd, Group *group) { + MasterAttributes::WriteHDF5DynamicRange(fd, group); + MasterAttributes::WriteHDF5TenGiga(fd, group); + MasterAttributes::WriteHDF5Period(fd, group); + MasterAttributes::WriteHDF5CounterMask(fd, group); + MasterAttributes::WriteHDF5ExptimeArray(fd, group); + MasterAttributes::WriteHDF5GateDelayArray(fd, group); + MasterAttributes::WriteHDF5Gates(fd, group); + MasterAttributes::WriteHDF5ThresholdEnergies(fd, group); +} #endif - void Gotthard2MasterAttributes::GetSpecificBinaryAttributes(rapidjson::Writer *w) { - w->Key("Exptime"); - w->String(sls::ToString(exptime).c_str()); - - w->Key("Period"); - w->String(sls::ToString(period).c_str()); - - w->Key("Burst Mode"); - w->String(sls::ToString(burstMode).c_str()); - }; +void MasterAttributes::GetGotthard2BinaryAttributes( + rapidjson::Writer *w) { + w->Key("Exptime"); + w->String(sls::ToString(exptime).c_str()); + w->Key("Period"); + w->String(sls::ToString(period).c_str()); + w->Key("Burst Mode"); + w->String(sls::ToString(burstMode).c_str()); +} #ifdef HDF5C - void Gotthard2MasterAttributes::WriteMasterHDF5Attributes(H5File *fd, Group *group) { - MasterAttributes::WriteHDF5Attributes(fd, group); - MasterAttributes::WriteHDF5Exptime(fd, group); - MasterAttributes::WriteHDF5Period(fd, group); - // burst mode - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - StrType strdatatype(PredType::C_S1, 256); - DataSet dataset = - group->createDataSet("Burst Mode", strdatatype, dataspace); - char c[1024]; - memset(c, 0, sizeof(c)); - sls::strcpy_safe(c, sls::ToString(burstMode)); - dataset.write(c, strdatatype); - } - MasterAttributes::WriteFinalHDF5Attributes(fd, group); - }; +void MasterAttributes::WriteGotthard2HDF5Attributes(H5File *fd, Group *group) { + MasterAttributes::WriteHDF5Exptime(fd, group); + MasterAttributes::WriteHDF5Period(fd, group); + MasterAttributes::WriteHDF5BurstMode(fd, group); +} #endif - void MoenchMasterAttributes::GetSpecificBinaryAttributes(rapidjson::Writer *w) { - w->Key("Exptime"); - w->String(sls::ToString(exptime).c_str()); - - w->Key("Period"); - w->String(sls::ToString(period).c_str()); - - w->Key("Ten Giga"); - w->Uint(tenGiga); - - w->Key("ADC Mask"); - w->String(sls::ToStringHex(adcmask).c_str()); - - w->Key("Analog Samples"); - w->Uint(analogSamples); - }; +void MasterAttributes::GetMoenchBinaryAttributes( + rapidjson::Writer *w) { + w->Key("Exptime"); + w->String(sls::ToString(exptime).c_str()); + w->Key("Period"); + w->String(sls::ToString(period).c_str()); + w->Key("Ten Giga"); + w->Uint(tenGiga); + w->Key("ADC Mask"); + w->String(sls::ToStringHex(adcmask).c_str()); + w->Key("Analog Samples"); + w->Uint(analogSamples); +} #ifdef HDF5C - void MoenchMasterAttributes::WriteMasterHDF5Attributes(H5File *fd, Group *group) { - MasterAttributes::WriteHDF5Attributes(fd, group); - MasterAttributes::WriteHDF5Exptime(fd, group); - MasterAttributes::WriteHDF5Period(fd, group); - MasterAttributes::WriteHDF5TenGiga(fd, group); - // ADC Mask - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group->createDataSet( - "ADC Mask", PredType::NATIVE_INT, dataspace); - dataset.write(&adcmask, PredType::NATIVE_INT); - } - // Analog Samples - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group->createDataSet( - "Analog Samples", PredType::NATIVE_INT, dataspace); - dataset.write(&analogSamples, PredType::NATIVE_INT); - } - MasterAttributes::WriteFinalHDF5Attributes(fd, group); - }; +void MasterAttributes::WriteMoenchHDF5Attributes(H5File *fd, Group *group) { + MasterAttributes::WriteHDF5Exptime(fd, group); + MasterAttributes::WriteHDF5Period(fd, group); + MasterAttributes::WriteHDF5TenGiga(fd, group); + MasterAttributes::WriteHDF5AdcMask(fd, group); + MasterAttributes::WriteHDF5AnalogSamples(fd, group); +} #endif - void CtbMasterAttributes::GetSpecificBinaryAttributes(rapidjson::Writer *w) { - w->Key("Exptime"); - w->String(sls::ToString(exptime).c_str()); - - w->Key("Period"); - w->String(sls::ToString(period).c_str()); - - w->Key("Ten Giga"); - w->Uint(tenGiga); - - w->Key("ADC Mask"); - w->String(sls::ToStringHex(adcmask).c_str()); - - w->Key("Analog Flag"); - w->Uint(analog); - - w->Key("Analog Samples"); - w->Uint(analogSamples); - - w->Key("Digital Flag"); - w->Uint(digital); - - w->Key("Digital Samples"); - w->Uint(digitalSamples); - - w->Key("Dbit Offset"); - w->Uint(dbitoffset); - - w->Key("Dbit Bitset"); - w->Uint64(dbitlist); - }; +void MasterAttributes::GetCtbBinaryAttributes( + rapidjson::Writer *w) { + w->Key("Exptime"); + w->String(sls::ToString(exptime).c_str()); + w->Key("Period"); + w->String(sls::ToString(period).c_str()); + w->Key("Ten Giga"); + w->Uint(tenGiga); + w->Key("ADC Mask"); + w->String(sls::ToStringHex(adcmask).c_str()); + w->Key("Analog Flag"); + w->Uint(analog); + w->Key("Analog Samples"); + w->Uint(analogSamples); + w->Key("Digital Flag"); + w->Uint(digital); + w->Key("Digital Samples"); + w->Uint(digitalSamples); + w->Key("Dbit Offset"); + w->Uint(dbitoffset); + w->Key("Dbit Bitset"); + w->Uint64(dbitlist); +} #ifdef HDF5C - void CtbMasterAttributes::WriteMasterHDF5Attributes(H5File *fd, Group *group) { - MasterAttributes::WriteHDF5Attributes(fd, group); - MasterAttributes::WriteHDF5Exptime(fd, group); - MasterAttributes::WriteHDF5Period(fd, group); - MasterAttributes::WriteHDF5TenGiga(fd, group); - // ADC Mask - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group->createDataSet( - "ADC mMsk", PredType::NATIVE_INT, dataspace); - dataset.write(&adcmask, PredType::NATIVE_INT); - } - // Analog Flag - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group->createDataSet( - "Analog Flag", PredType::NATIVE_INT, dataspace); - dataset.write(&analog, PredType::NATIVE_INT); - } - // Analog Samples - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group->createDataSet( - "Analog Samples", PredType::NATIVE_INT, dataspace); - dataset.write(&analogSamples, PredType::NATIVE_INT); - } - // Digital Flag - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group->createDataSet( - "Digital Flag", PredType::NATIVE_INT, dataspace); - dataset.write(&digital, PredType::NATIVE_INT); - } - // Digital Samples - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group->createDataSet( - "Digital Samples", PredType::NATIVE_INT, dataspace); - dataset.write(&digitalSamples, PredType::NATIVE_INT); - } - // Dbit Offset - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group->createDataSet( - "Dbit Offset", PredType::NATIVE_INT, dataspace); - dataset.write(&dbitoffset, PredType::NATIVE_INT); - } - // Dbit List - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group->createDataSet( - "Dbit Bitset List", PredType::STD_U64LE, dataspace); - dataset.write(&dbitlist, PredType::STD_U64LE); - } - MasterAttributes::WriteFinalHDF5Attributes(fd, group); - }; +void MasterAttributes::WriteCtbHDF5Attributes(H5File *fd, Group *group) { + MasterAttributes::WriteHDF5Exptime(fd, group); + MasterAttributes::WriteHDF5Period(fd, group); + MasterAttributes::WriteHDF5TenGiga(fd, group); + MasterAttributes::WriteHDF5AdcMask(fd, group); + MasterAttributes::WriteHDF5AnalogFlag(fd, group); + MasterAttributes::WriteHDF5AnalogSamples(fd, group); + MasterAttributes::WriteHDF5DigitalFlag(fd, group); + MasterAttributes::WriteHDF5DigitalSamples(fd, group); + MasterAttributes::WriteHDF5DbitOffset(fd, group); + MasterAttributes::WriteHDF5DbitList(fd, group); +} #endif diff --git a/slsReceiverSoftware/src/MasterAttributes.h b/slsReceiverSoftware/src/MasterAttributes.h index 27c7ba13b..66ae25016 100644 --- a/slsReceiverSoftware/src/MasterAttributes.h +++ b/slsReceiverSoftware/src/MasterAttributes.h @@ -56,103 +56,92 @@ class MasterAttributes { uint64_t dbitlist{0}; slsDetectorDefs::ROI roi{}; uint32_t counterMask{0}; - ns exptime1{0}; - ns exptime2{0}; - ns exptime3{0}; - ns gateDelay1{0}; - ns gateDelay2{0}; - ns gateDelay3{0}; + std::array exptimeArray{}; + std::array gateDelayArray{}; uint32_t gates; std::map additionalJsonHeader; - - // Final Attributes (after acquisition) uint64_t framesInFile{0}; MasterAttributes() = default; - virtual ~MasterAttributes() = default; - virtual void - GetSpecificBinaryAttributes(rapidjson::Writer *w); + ~MasterAttributes() = default; + + void GetBinaryAttributes(rapidjson::Writer *w); +#ifdef HDF5C + void WriteHDF5Attributes(H5File *fd, Group *group); +#endif + void GetCommonBinaryAttributes(rapidjson::Writer *w); void GetFinalBinaryAttributes(rapidjson::Writer *w); #ifdef HDF5C - virtual void WriteMasterHDF5Attributes(H5File *fd, Group *group); - void WriteHDF5Attributes(H5File *fd, Group *group); + void WriteCommonHDF5Attributes(H5File *fd, Group *group); void WriteFinalHDF5Attributes(H5File *fd, Group *group); void WriteHDF5Exptime(H5File *fd, Group *group); void WriteHDF5Period(H5File *fd, Group *group); void WriteHDF5DynamicRange(H5File *fd, Group *group); void WriteHDF5TenGiga(H5File *fd, Group *group); + void WriteHDF5ROI(H5File *fd, Group *group); + void WriteHDF5NumUDPInterfaces(H5File *fd, Group *group); + void WriteHDF5ReadNRows(H5File *fd, Group *group); + void WriteHDF5ThresholdEnergy(H5File *fd, Group *group); + void WriteHDF5ThresholdEnergies(H5File *fd, Group *group); + void WriteHDF5SubExpTime(H5File *fd, Group *group); + void WriteHDF5SubPeriod(H5File *fd, Group *group); + void WriteHDF5SubQuad(H5File *fd, Group *group); + void WriteHDF5RateCorrections(H5File *fd, Group *group); + void WriteHDF5CounterMask(H5File *fd, Group *group); + void WriteHDF5ExptimeArray(H5File *fd, Group *group); + void WriteHDF5GateDelayArray(H5File *fd, Group *group); + void WriteHDF5Gates(H5File *fd, Group *group); + void WriteHDF5BurstMode(H5File *fd, Group *group); + void WriteHDF5AdcMask(H5File *fd, Group *group); + void WriteHDF5AnalogFlag(H5File *fd, Group *group); + void WriteHDF5AnalogSamples(H5File *fd, Group *group); + void WriteHDF5DigitalFlag(H5File *fd, Group *group); + void WriteHDF5DigitalSamples(H5File *fd, Group *group); + void WriteHDF5DbitOffset(H5File *fd, Group *group); + void WriteHDF5DbitList(H5File *fd, Group *group); #endif -}; -class GotthardMasterAttributes : public MasterAttributes { - public: - GotthardMasterAttributes() = default; - void GetSpecificBinaryAttributes( - rapidjson::Writer *w) override; + void + GetGotthardBinaryAttributes(rapidjson::Writer *w); #ifdef HDF5C - void WriteMasterHDF5Attributes(H5File *fd, Group *group) override; + void WriteGotthardHDF5Attributes(H5File *fd, Group *group); #endif -}; -class JungfrauMasterAttributes : public MasterAttributes { - public: - JungfrauMasterAttributes() = default; - void GetSpecificBinaryAttributes( - rapidjson::Writer *w) override; + void + GetJungfrauBinaryAttributes(rapidjson::Writer *w); #ifdef HDF5C - void WriteMasterHDF5Attributes(H5File *fd, Group *group) override; + void WriteJungfrauHDF5Attributes(H5File *fd, Group *group); #endif -}; -class EigerMasterAttributes : public MasterAttributes { - public: - EigerMasterAttributes() = default; - void GetSpecificBinaryAttributes( - rapidjson::Writer *w) override; + void + GetEigerBinaryAttributes(rapidjson::Writer *w); #ifdef HDF5C - void WriteMasterHDF5Attributes(H5File *fd, Group *group) override; + void WriteEigerHDF5Attributes(H5File *fd, Group *group); #endif -}; -class Mythen3MasterAttributes : public MasterAttributes { - public: - Mythen3MasterAttributes() = default; - void GetSpecificBinaryAttributes( - rapidjson::Writer *w) override; + void + GetMythen3BinaryAttributes(rapidjson::Writer *w); #ifdef HDF5C - void WriteMasterHDF5Attributes(H5File *fd, Group *group) override; + void WriteMythen3HDF5Attributes(H5File *fd, Group *group); #endif -}; -class Gotthard2MasterAttributes : public MasterAttributes { - public: - Gotthard2MasterAttributes() = default; - void GetSpecificBinaryAttributes( - rapidjson::Writer *w) override; + void + GetGotthard2BinaryAttributes(rapidjson::Writer *w); #ifdef HDF5C - void WriteMasterHDF5Attributes(H5File *fd, Group *group) override; + void WriteGotthard2HDF5Attributes(H5File *fd, Group *group); #endif -}; -class MoenchMasterAttributes : public MasterAttributes { - public: - MoenchMasterAttributes() = default; - void GetSpecificBinaryAttributes( - rapidjson::Writer *w) override; + void + GetMoenchBinaryAttributes(rapidjson::Writer *w); #ifdef HDF5C - void WriteMasterHDF5Attributes(H5File *fd, Group *group) override; + void WriteMoenchHDF5Attributes(H5File *fd, Group *group); #endif -}; -class CtbMasterAttributes : public MasterAttributes { - public: - CtbMasterAttributes() = default; - void GetSpecificBinaryAttributes( - rapidjson::Writer *w) override; + void GetCtbBinaryAttributes(rapidjson::Writer *w); #ifdef HDF5C - void WriteMasterHDF5Attributes(H5File *fd, Group *group) override; + void WriteCtbHDF5Attributes(H5File *fd, Group *group); #endif };