From ed5a1cdf1c098757bc1ecd112e5b029aab525c99 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Tue, 15 Mar 2022 17:17:28 +0100 Subject: [PATCH 1/7] eiger: get nextframenumber for 10g fixed (was connected to 1g registers for get), eiger/jungfrau/ctb/moench: if after a stop the next framenumbers are inconsistent, then it will get their max value andf set to +1 --- slsDetectorServers/eigerDetectorServer/Beb.c | 10 +++++----- slsDetectorSoftware/src/Detector.cpp | 20 +++++++++++++++++++- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/slsDetectorServers/eigerDetectorServer/Beb.c b/slsDetectorServers/eigerDetectorServer/Beb.c index 90512c7b1..ab602b475 100644 --- a/slsDetectorServers/eigerDetectorServer/Beb.c +++ b/slsDetectorServers/eigerDetectorServer/Beb.c @@ -1251,20 +1251,20 @@ int Beb_GetNextFrameNumber(uint64_t *retval, int tengigaEnable) { else { uint64_t left10g = - Beb_Read32(csp0base, UDP_HEADER_GET_FNUM_1G_LEFT_MSB_OFST); - temp = Beb_Read32(csp0base, UDP_HEADER_GET_FNUM_1G_LEFT_LSB_OFST); + Beb_Read32(csp0base, UDP_HEADER_GET_FNUM_10G_LEFT_MSB_OFST); + temp = Beb_Read32(csp0base, UDP_HEADER_GET_FNUM_10G_LEFT_LSB_OFST); left10g = ((left10g << 32) | temp) >> 16; ++left10g; // increment for firmware uint64_t right10g = - Beb_Read32(csp0base, UDP_HEADER_GET_FNUM_1G_LEFT_MSB_OFST); - temp = Beb_Read32(csp0base, UDP_HEADER_GET_FNUM_1G_LEFT_LSB_OFST); + Beb_Read32(csp0base, UDP_HEADER_GET_FNUM_10G_LEFT_MSB_OFST); + temp = Beb_Read32(csp0base, UDP_HEADER_GET_FNUM_10G_LEFT_LSB_OFST); right10g = ((right10g << 32) | temp) >> 16; Beb_close(fd, csp0base); ++right10g; // increment for firmware if (left10g != right10g) { - LOG(logERROR, ("Retrieved inconsistent frame numbers from `0g left " + LOG(logERROR, ("Retrieved inconsistent frame numbers from 10g left " "%llu and right %llu\n", (long long int)left10g, (long long int)right10g)); *retval = (left10g > right10g) diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index 025370bf7..94b4630cb 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -783,6 +783,25 @@ void Detector::startDetectorReadout() { void Detector::stopDetector(Positions pos) { pimpl->Parallel(&Module::stopAcquisition, pos); + + // validate consistent frame numbers + switch (getDetectorType().squash()) { + case defs::EIGER: + case defs::JUNGFRAU: + case defs::MOENCH: + case defs::CHIPTESTBOARD: { + auto res = getNextFrameNumber(pos); + if (!res.equal()) { + uint64_t maxVal = 0; + for (auto it : res) { + maxVal = std::max(maxVal, it); + } + setNextFrameNumber(maxVal + 1); + } + } break; + default: + break; + } } Result Detector::getDetectorStatus(Positions pos) const { @@ -1563,7 +1582,6 @@ std::vector Detector::getGainModeList() const { return std::vector{ defs::DYNAMIC, defs::FORCE_SWITCH_G1, defs::FORCE_SWITCH_G2, defs::FIX_G1, defs::FIX_G2, defs::FIX_G0}; - break; default: throw RuntimeError("Gain mode is not implemented for this detector."); } From 9e050060f3c75c33cf85b1d13e4c9cc39908e460 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Tue, 15 Mar 2022 17:18:56 +0100 Subject: [PATCH 2/7] eiger binary in --- .../bin/eigerDetectorServer_developer | Bin 413415 -> 413415 bytes slsSupportLib/include/sls/versionAPI.h | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_developer b/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_developer index 8f791e4b0d9f46cbcde467f778bab09d397d443f..3eb68629edbf82c343199a255138b941d90a18dc 100755 GIT binary patch delta 157 zcmaDpSMvE>$qiOAOw6Lw12`E~CL73b0ojum*hx>em*txLRz|3KvCQ_xGK>yRic35g z*g0zwq$?)KGniN~FfagVg9dp9ml|f~3X2AYmgy|$qiOAOiaqt12`E~CL73b0ojum*hx>em*txLRz|3KvCQ_xGK>yRiYguq z?3^_T(iIcr8B8n~7#M)GL4!PlOARw~g+&7c%XF4_#(0o2woa%r8>li1WM$i1;u)h1 ifY!7>=w}3CrtJ^ Date: Wed, 16 Mar 2022 11:35:27 +0100 Subject: [PATCH 3/7] added tests --- RELEASE.txt | 2 ++ slsDetectorSoftware/tests/test-CmdProxy.cpp | 35 +++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/RELEASE.txt b/RELEASE.txt index 23e0e1ade..2f9b0e55b 100755 --- a/RELEASE.txt +++ b/RELEASE.txt @@ -42,6 +42,8 @@ This document describes the differences between v7.0.0 and v6.x.x - start non blocking acquisition at modular level - hostname cmd failed when connecting to servers in update mode (ctb, moench, jungfrau, eiger) - missingpackets signed (negative => extra packets) +- 10g eiger nextframenumber get fixed. +- stop, able to set nextframenumber to a consistent (max + 1) for all modules if different (eiger/ctb/jungfrau/moench) 2. Resolved Issues diff --git a/slsDetectorSoftware/tests/test-CmdProxy.cpp b/slsDetectorSoftware/tests/test-CmdProxy.cpp index 4a593eb95..c0565d471 100644 --- a/slsDetectorSoftware/tests/test-CmdProxy.cpp +++ b/slsDetectorSoftware/tests/test-CmdProxy.cpp @@ -2126,6 +2126,41 @@ TEST_CASE("nextframenumber", "[.cmd]") { proxy.Call("nextframenumber", {"1"}, -1, PUT, oss); REQUIRE(oss.str() == "nextframenumber 1\n"); } + + auto prev_timing = + det.getTimingMode().tsquash("inconsistent timing mode in test"); + auto prev_frames = + det.getNumberOfFrames().tsquash("inconsistent #frames in test"); + auto prev_exptime = + det.getExptime().tsquash("inconsistent exptime in test"); + auto prev_period = + det.getPeriod().tsquash("inconsistent period in test"); + det.setTimingMode(defs::AUTO_TIMING); + det.setNumberOfFrames(1); + det.setExptime(std::chrono::microseconds(200)); + det.setPeriod(std::chrono::milliseconds(1)); + det.startDetector(); + std::this_thread::sleep_for(std::chrono::seconds(2)); + auto currentfnum = + det.getNextFrameNumber().tsquash("inconsistent frame nr in test"); + REQUIRE(currentfnum == 2); + if (det_type == defs::EIGER) { + auto prev_tengiga = + det.getTenGiga().tsquash("inconsistent ten giga enable"); + det.setTenGiga(true); + det.setNextFrameNumber(1); + det.startDetector(); + std::this_thread::sleep_for(std::chrono::seconds(2)); + auto currentfnum = det.getNextFrameNumber().tsquash( + "inconsistent frame nr in test"); + REQUIRE(currentfnum == 2); + det.setTenGiga(prev_tengiga); + } + + det.setTimingMode(prev_timing); + det.setNumberOfFrames(prev_frames); + det.setExptime(prev_exptime); + det.setPeriod(prev_period); for (int i = 0; i != det.size(); ++i) { det.setNextFrameNumber(prev_sfnum[i], {i}); } From c17914e0a15bba975e7d7f27e0f94c6917be8ac2 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Wed, 16 Mar 2022 15:49:06 +0100 Subject: [PATCH 4/7] split MasterAtrributes into cpp --- slsReceiverSoftware/CMakeLists.txt | 1 + slsReceiverSoftware/src/MasterAttributes.cpp | 660 ++++++++++++++++++ slsReceiverSoftware/src/MasterAttributes.h | 690 +------------------ 3 files changed, 697 insertions(+), 654 deletions(-) create mode 100644 slsReceiverSoftware/src/MasterAttributes.cpp diff --git a/slsReceiverSoftware/CMakeLists.txt b/slsReceiverSoftware/CMakeLists.txt index d93a2c027..ef1bfb56d 100755 --- a/slsReceiverSoftware/CMakeLists.txt +++ b/slsReceiverSoftware/CMakeLists.txt @@ -13,6 +13,7 @@ set(SOURCES src/DataStreamer.cpp src/Fifo.cpp src/Arping.cpp + src/MasterAttributes.cpp ) set(PUBLICHEADERS diff --git a/slsReceiverSoftware/src/MasterAttributes.cpp b/slsReceiverSoftware/src/MasterAttributes.cpp new file mode 100644 index 000000000..cae3668cf --- /dev/null +++ b/slsReceiverSoftware/src/MasterAttributes.cpp @@ -0,0 +1,660 @@ +// SPDX-License-Identifier: LGPL-3.0-or-other +// Copyright (C) 2021 Contributors to the SLS Detector Package +#include "MasterAttributes.h" + +void MasterAttributes::WriteMasterBinaryAttributes(FILE *fd) { + LOG(logERROR) << "WriteMasterBinaryAttributes should have been called " + "by a child class"; +} + +std::string MasterAttributes::GetBinaryMasterAttributes() { + time_t t = time(nullptr); + std::ostringstream oss; + oss << "Version : " << std::setprecision(2) + << BINARY_WRITER_VERSION << '\n' + << "TimeStamp : " << ctime(&t) << '\n' + << "Detector Type : " << sls::ToString(detType) << '\n' + << "Timing Mode : " << sls::ToString(timingMode) << '\n' + << "Image Size : " << imageSize << " bytes" << '\n' + << "Pixels : " << sls::ToString(nPixels) << '\n' + << "Max Frames Per File : " << maxFramesPerFile << '\n' + << "Frame Discard Policy : " << sls::ToString(frameDiscardMode) + << '\n' + << "Frame Padding : " << framePadding << '\n' + << "Scan Parameters : " << sls::ToString(scanParams) << '\n' + << "Total Frames : " << totalFrames << '\n'; + return oss.str(); +}; + +void MasterAttributes::WriteBinaryAttributes(FILE *fd, std::string message) { + 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"); + } +}; + +void MasterAttributes::WriteFinalBinaryAttributes(FILE *fd) { + // adding few common parameters to the end + std::ostringstream oss; + + if (!additionalJsonHeader.empty()) { + oss << "Additional Json Header : " + << sls::ToString(additionalJsonHeader) << '\n'; + } + oss << "Frames in File : " << framesInFile << '\n'; + + // adding sls_receiver header format + oss << '\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'; + + std::string message = oss.str(); + + // writing to file + 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"); + } +}; + +#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) { + 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 = + 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 = + 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 = + group->createDataSet("Timing Mode", strdatatype, dataspace); + sls::strcpy_safe(c, sls::ToString(timingMode)); + dataset.write(c, strdatatype); + } + // 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? + // 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); + } + // 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); + }; +#endif + + void GotthardMasterAttributes::WriteMasterBinaryAttributes(FILE *fd) { + std::ostringstream oss; + oss << MasterAttributes::GetBinaryMasterAttributes() + << "Exptime : " << sls::ToString(exptime) << '\n' + << "Period : " << sls::ToString(period) << '\n' + << "Roi (xmin, xmax) : " << sls::ToString(roi) << '\n'; + std::string message = oss.str(); + MasterAttributes::WriteBinaryAttributes(fd, message); + }; + +#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); + } + }; +#endif + + void JungfrauMasterAttributes::WriteMasterBinaryAttributes(FILE *fd) { + std::ostringstream oss; + oss << MasterAttributes::GetBinaryMasterAttributes() + << "Exptime : " << sls::ToString(exptime) << '\n' + << "Period : " << sls::ToString(period) << '\n' + << "Number of UDP Interfaces : " << numUDPInterfaces << '\n' + << "Number of rows : " << readNRows << '\n'; + std::string message = oss.str(); + MasterAttributes::WriteBinaryAttributes(fd, message); + }; + +#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); + } + }; +#endif + + void EigerMasterAttributes::WriteMasterBinaryAttributes(FILE *fd) { + std::ostringstream oss; + oss << MasterAttributes::GetBinaryMasterAttributes() + << "Dynamic Range : " << dynamicRange << '\n' + << "Ten Giga : " << tenGiga << '\n' + << "Exptime : " << sls::ToString(exptime) << '\n' + << "Period : " << sls::ToString(period) << '\n' + << "Threshold Energy : " << thresholdEnergyeV << '\n' + << "SubExptime : " << sls::ToString(subExptime) + << '\n' + << "SubPeriod : " << sls::ToString(subPeriod) + << '\n' + << "Quad : " << quad << '\n' + << "Number of rows : " << readNRows << '\n' + << "Rate Corrections : " << sls::ToString(ratecorr) + << '\n'; + std::string message = oss.str(); + MasterAttributes::WriteBinaryAttributes(fd, message); + }; + +#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); + } + }; +#endif + + void Mythen3MasterAttributes::WriteMasterBinaryAttributes(FILE *fd) { + std::ostringstream oss; + oss << MasterAttributes::GetBinaryMasterAttributes() + << "Dynamic Range : " << dynamicRange << '\n' + << "Ten Giga : " << tenGiga << '\n' + << "Period : " << sls::ToString(period) << '\n' + << "Counter Mask : " << sls::ToStringHex(counterMask) + << '\n' + << "Exptime1 : " << sls::ToString(exptime1) + << '\n' + << "Exptime2 : " << sls::ToString(exptime2) + << '\n' + << "Exptime3 : " << sls::ToString(exptime3) + << '\n' + << "GateDelay1 : " << sls::ToString(gateDelay1) + << '\n' + << "GateDelay2 : " << sls::ToString(gateDelay2) + << '\n' + << "GateDelay3 : " << sls::ToString(gateDelay3) + << '\n' + << "Gates : " << gates << '\n' + << "Threshold Energies : " + << sls::ToString(thresholdAllEnergyeV) << '\n'; + std::string message = oss.str(); + MasterAttributes::WriteBinaryAttributes(fd, message); + }; + +#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); + } + }; +#endif + + void Gotthard2MasterAttributes::WriteMasterBinaryAttributes(FILE *fd) { + std::ostringstream oss; + oss << MasterAttributes::GetBinaryMasterAttributes() + << "Exptime : " << sls::ToString(exptime) << '\n' + << "Period : " << sls::ToString(period) << '\n' + << "Burst Mode : " << sls::ToString(burstMode) + << '\n'; + std::string message = oss.str(); + MasterAttributes::WriteBinaryAttributes(fd, message); + }; + +#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); + } + }; +#endif + + void MoenchMasterAttributes::WriteMasterBinaryAttributes(FILE *fd) { + 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' + << "Analog Samples : " << analogSamples << '\n'; + std::string message = oss.str(); + MasterAttributes::WriteBinaryAttributes(fd, message); + }; + +#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); + } + }; +#endif + + void CtbMasterAttributes::WriteMasterBinaryAttributes(FILE *fd) { + 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' + << "Analog Flag : " << analog << '\n' + << "Analog Samples : " << analogSamples << '\n' + << "Digital Flag : " << digital << '\n' + << "Digital Samples : " << digitalSamples << '\n' + << "Dbit Offset : " << dbitoffset << '\n' + << "Dbit Bitset : " << dbitlist << '\n'; + std::string message = oss.str(); + MasterAttributes::WriteBinaryAttributes(fd, message); + }; + +#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); + } + }; +#endif diff --git a/slsReceiverSoftware/src/MasterAttributes.h b/slsReceiverSoftware/src/MasterAttributes.h index 992a73381..f12e17f99 100644 --- a/slsReceiverSoftware/src/MasterAttributes.h +++ b/slsReceiverSoftware/src/MasterAttributes.h @@ -17,7 +17,8 @@ using namespace H5; #include using ns = std::chrono::nanoseconds; -struct MasterAttributes { +class MasterAttributes { + public: // (before acquisition) slsDetectorDefs::detectorType detType{slsDetectorDefs::GENERIC}; slsDetectorDefs::timingMode timingMode{slsDetectorDefs::AUTO_TIMING}; @@ -63,701 +64,82 @@ struct MasterAttributes { // Final Attributes (after acquisition) uint64_t framesInFile{0}; - MasterAttributes(){}; - virtual ~MasterAttributes(){}; - - 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) - << BINARY_WRITER_VERSION << '\n' - << "TimeStamp : " << ctime(&t) << '\n' - << "Detector Type : " << sls::ToString(detType) << '\n' - << "Timing Mode : " << sls::ToString(timingMode) - << '\n' - << "Image Size : " << imageSize << " bytes" << '\n' - << "Pixels : " << sls::ToString(nPixels) << '\n' - << "Max Frames Per File : " << maxFramesPerFile << '\n' - << "Frame Discard Policy : " - << sls::ToString(frameDiscardMode) << '\n' - << "Frame Padding : " << framePadding << '\n' - << "Scan Parameters : " << sls::ToString(scanParams) - << '\n' - << "Total Frames : " << totalFrames << '\n'; - return oss.str(); - }; - - void WriteBinaryAttributes(FILE *fd, std::string message) { - 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"); - } - }; - - void WriteFinalBinaryAttributes(FILE *fd) { - // adding few common parameters to the end - std::ostringstream oss; - - if (!additionalJsonHeader.empty()) { - oss << "Additional Json Header : " - << sls::ToString(additionalJsonHeader) << '\n'; - } - oss << "Frames in File : " << framesInFile << '\n'; - - // adding sls_receiver header format - oss << '\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'; - - std::string message = oss.str(); - - // writing to file - 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"); - } - }; - + MasterAttributes() = default; + virtual ~MasterAttributes() = default; + virtual void WriteMasterBinaryAttributes(FILE *fd); + std::string GetBinaryMasterAttributes(); + void WriteBinaryAttributes(FILE *fd, std::string message); + void WriteFinalBinaryAttributes(FILE *fd); #ifdef HDF5C - virtual void WriteMasterHDF5Attributes(H5File *fd, Group *group) { - LOG(logERROR) << "WriteMasterHdf5Attributes should have been called " - "by a child class"; - }; - - void WriteHDF5Attributes(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 = - 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 = - 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 = - group->createDataSet("Timing Mode", strdatatype, dataspace); - sls::strcpy_safe(c, sls::ToString(timingMode)); - dataset.write(c, strdatatype); - } - // 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? - // 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); - } - // 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 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 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 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 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 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); - }; + virtual void WriteMasterHDF5Attributes(H5File *fd, Group *group); + void WriteHDF5Attributes(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); #endif }; -// clang-format on class GotthardMasterAttributes : public MasterAttributes { public: - GotthardMasterAttributes(){}; - - 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'; - std::string message = oss.str(); - MasterAttributes::WriteBinaryAttributes(fd, message); - }; - + GotthardMasterAttributes() = default; + void WriteMasterBinaryAttributes(FILE *fd) override; #ifdef HDF5C - void WriteMasterHDF5Attributes(H5File *fd, Group *group) override { - 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); - } - }; + void WriteMasterHDF5Attributes(H5File *fd, Group *group) override; #endif }; class JungfrauMasterAttributes : public MasterAttributes { public: - JungfrauMasterAttributes(){}; - - void WriteMasterBinaryAttributes(FILE *fd) override { - std::ostringstream oss; - oss << MasterAttributes::GetBinaryMasterAttributes() - << "Exptime : " << sls::ToString(exptime) << '\n' - << "Period : " << sls::ToString(period) << '\n' - << "Number of UDP Interfaces : " << numUDPInterfaces << '\n' - << "Number of rows : " << readNRows << '\n'; - std::string message = oss.str(); - MasterAttributes::WriteBinaryAttributes(fd, message); - }; - + JungfrauMasterAttributes() = default; + void WriteMasterBinaryAttributes(FILE *fd) override; #ifdef HDF5C - void WriteMasterHDF5Attributes(H5File *fd, Group *group) override { - 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); - } - }; + void WriteMasterHDF5Attributes(H5File *fd, Group *group) override; #endif }; class EigerMasterAttributes : public MasterAttributes { public: - EigerMasterAttributes(){}; - - void WriteMasterBinaryAttributes(FILE *fd) override { - std::ostringstream oss; - oss << MasterAttributes::GetBinaryMasterAttributes() - << "Dynamic Range : " << dynamicRange << '\n' - << "Ten Giga : " << tenGiga << '\n' - << "Exptime : " << sls::ToString(exptime) << '\n' - << "Period : " << sls::ToString(period) << '\n' - << "Threshold Energy : " << thresholdEnergyeV << '\n' - << "SubExptime : " << sls::ToString(subExptime) - << '\n' - << "SubPeriod : " << sls::ToString(subPeriod) - << '\n' - << "Quad : " << quad << '\n' - << "Number of rows : " << readNRows << '\n' - << "Rate Corrections : " << sls::ToString(ratecorr) - << '\n'; - std::string message = oss.str(); - MasterAttributes::WriteBinaryAttributes(fd, message); - }; - + EigerMasterAttributes() = default; + void WriteMasterBinaryAttributes(FILE *fd) override; #ifdef HDF5C - void WriteMasterHDF5Attributes(H5File *fd, Group *group) override { - 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); - } - }; + void WriteMasterHDF5Attributes(H5File *fd, Group *group) override; #endif }; class Mythen3MasterAttributes : public MasterAttributes { public: - Mythen3MasterAttributes(){}; - - void WriteMasterBinaryAttributes(FILE *fd) override { - std::ostringstream oss; - oss << MasterAttributes::GetBinaryMasterAttributes() - << "Dynamic Range : " << dynamicRange << '\n' - << "Ten Giga : " << tenGiga << '\n' - << "Period : " << sls::ToString(period) << '\n' - << "Counter Mask : " << sls::ToStringHex(counterMask) - << '\n' - << "Exptime1 : " << sls::ToString(exptime1) - << '\n' - << "Exptime2 : " << sls::ToString(exptime2) - << '\n' - << "Exptime3 : " << sls::ToString(exptime3) - << '\n' - << "GateDelay1 : " << sls::ToString(gateDelay1) - << '\n' - << "GateDelay2 : " << sls::ToString(gateDelay2) - << '\n' - << "GateDelay3 : " << sls::ToString(gateDelay3) - << '\n' - << "Gates : " << gates << '\n' - << "Threshold Energies : " - << sls::ToString(thresholdAllEnergyeV) << '\n'; - std::string message = oss.str(); - MasterAttributes::WriteBinaryAttributes(fd, message); - }; - + Mythen3MasterAttributes() = default; + void WriteMasterBinaryAttributes(FILE *fd) override; #ifdef HDF5C - void WriteMasterHDF5Attributes(H5File *fd, Group *group) override { - 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); - } - }; + void WriteMasterHDF5Attributes(H5File *fd, Group *group) override; #endif }; class Gotthard2MasterAttributes : public MasterAttributes { public: - Gotthard2MasterAttributes(){}; - - void WriteMasterBinaryAttributes(FILE *fd) override { - std::ostringstream oss; - oss << MasterAttributes::GetBinaryMasterAttributes() - << "Exptime : " << sls::ToString(exptime) << '\n' - << "Period : " << sls::ToString(period) << '\n' - << "Burst Mode : " << sls::ToString(burstMode) - << '\n'; - std::string message = oss.str(); - MasterAttributes::WriteBinaryAttributes(fd, message); - }; - + Gotthard2MasterAttributes() = default; + void WriteMasterBinaryAttributes(FILE *fd) override; #ifdef HDF5C - void WriteMasterHDF5Attributes(H5File *fd, Group *group) override { - 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); - } - }; + void WriteMasterHDF5Attributes(H5File *fd, Group *group) override; #endif }; class MoenchMasterAttributes : public MasterAttributes { public: - MoenchMasterAttributes(){}; - - 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' - << "Analog Samples : " << analogSamples << '\n'; - std::string message = oss.str(); - MasterAttributes::WriteBinaryAttributes(fd, message); - }; - + MoenchMasterAttributes() = default; + void WriteMasterBinaryAttributes(FILE *fd) override; #ifdef HDF5C - void WriteMasterHDF5Attributes(H5File *fd, Group *group) override { - 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); - } - }; + void WriteMasterHDF5Attributes(H5File *fd, Group *group) override; #endif }; class CtbMasterAttributes : public MasterAttributes { public: - CtbMasterAttributes(){}; - - 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' - << "Analog Flag : " << analog << '\n' - << "Analog Samples : " << analogSamples << '\n' - << "Digital Flag : " << digital << '\n' - << "Digital Samples : " << digitalSamples << '\n' - << "Dbit Offset : " << dbitoffset << '\n' - << "Dbit Bitset : " << dbitlist << '\n'; - std::string message = oss.str(); - MasterAttributes::WriteBinaryAttributes(fd, message); - }; - + CtbMasterAttributes() = default; + void WriteMasterBinaryAttributes(FILE *fd) override; #ifdef HDF5C - void WriteMasterHDF5Attributes(H5File *fd, Group *group) override { - 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); - } - }; + void WriteMasterHDF5Attributes(H5File *fd, Group *group) override; #endif }; From 9c1bc262e5fe6e43a25b940920a0bf7f41b1baa3 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Wed, 16 Mar 2022 16:09:50 +0100 Subject: [PATCH 5/7] added geometry to master file --- slsReceiverSoftware/src/Implementation.cpp | 6 ++++++ slsReceiverSoftware/src/MasterAttributes.cpp | 20 ++++++++++++++++++-- slsReceiverSoftware/src/MasterAttributes.h | 1 + slsReceiverSoftware/src/receiver_defs.h | 4 ++-- 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/slsReceiverSoftware/src/Implementation.cpp b/slsReceiverSoftware/src/Implementation.cpp index b5d6b31ef..bf3df34be 100644 --- a/slsReceiverSoftware/src/Implementation.cpp +++ b/slsReceiverSoftware/src/Implementation.cpp @@ -784,6 +784,12 @@ void Implementation::SetupWriter() { } 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 = xy(generalData->nPixelsX, generalData->nPixelsY); diff --git a/slsReceiverSoftware/src/MasterAttributes.cpp b/slsReceiverSoftware/src/MasterAttributes.cpp index cae3668cf..447495fce 100644 --- a/slsReceiverSoftware/src/MasterAttributes.cpp +++ b/slsReceiverSoftware/src/MasterAttributes.cpp @@ -15,6 +15,7 @@ std::string MasterAttributes::GetBinaryMasterAttributes() { << "TimeStamp : " << ctime(&t) << '\n' << "Detector Type : " << sls::ToString(detType) << '\n' << "Timing Mode : " << sls::ToString(timingMode) << '\n' + << "Geometry : " << sls::ToString(geometry) << '\n' << "Image Size : " << imageSize << " bytes" << '\n' << "Pixels : " << sls::ToString(nPixels) << '\n' << "Max Frames Per File : " << maxFramesPerFile << '\n' @@ -118,6 +119,21 @@ void MasterAttributes::WriteHDF5Attributes(H5File *fd, Group *group) { 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); @@ -132,14 +148,14 @@ void MasterAttributes::WriteHDF5Attributes(H5File *fd, Group *group) { attribute.write(strdatatype, c); } //TODO: make this into an array? - // x + // 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); } - // y + // npixels y { DataSpace dataspace = DataSpace(H5S_SCALAR); DataSet dataset = group->createDataSet( diff --git a/slsReceiverSoftware/src/MasterAttributes.h b/slsReceiverSoftware/src/MasterAttributes.h index f12e17f99..945ac7756 100644 --- a/slsReceiverSoftware/src/MasterAttributes.h +++ b/slsReceiverSoftware/src/MasterAttributes.h @@ -22,6 +22,7 @@ class MasterAttributes { // (before acquisition) slsDetectorDefs::detectorType detType{slsDetectorDefs::GENERIC}; slsDetectorDefs::timingMode timingMode{slsDetectorDefs::AUTO_TIMING}; + slsDetectorDefs::xy geometry{}; uint32_t imageSize{0}; slsDetectorDefs::xy nPixels{}; uint32_t maxFramesPerFile{0}; diff --git a/slsReceiverSoftware/src/receiver_defs.h b/slsReceiverSoftware/src/receiver_defs.h index 7e1982d62..53cc31d2f 100644 --- a/slsReceiverSoftware/src/receiver_defs.h +++ b/slsReceiverSoftware/src/receiver_defs.h @@ -17,8 +17,8 @@ // files // versions -#define HDF5_WRITER_VERSION (6.3) // 1 decimal places -#define BINARY_WRITER_VERSION (6.3) // 1 decimal places +#define HDF5_WRITER_VERSION (6.4) // 1 decimal places +#define BINARY_WRITER_VERSION (6.4) // 1 decimal places #define MAX_FRAMES_PER_FILE 20000 #define SHORT_MAX_FRAMES_PER_FILE 100000 From 7663d4ef53168acd6bf5dd8a1c1bcc809333141f Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Wed, 16 Mar 2022 16:12:58 +0100 Subject: [PATCH 6/7] udpated release notes --- RELEASE.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/RELEASE.txt b/RELEASE.txt index 23e0e1ade..ecf3fd3b2 100755 --- a/RELEASE.txt +++ b/RELEASE.txt @@ -42,6 +42,7 @@ This document describes the differences between v7.0.0 and v6.x.x - start non blocking acquisition at modular level - hostname cmd failed when connecting to servers in update mode (ctb, moench, jungfrau, eiger) - missingpackets signed (negative => extra packets) +- added geometry to metadata 2. Resolved Issues From 78823760b37b1d93aef97262d0ec78ef3b2fb148 Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Thu, 17 Mar 2022 09:52:39 +0100 Subject: [PATCH 7/7] more checks in generate functions --- python/scripts/generate_functions.py | 128 ++++++++++++++++++--------- 1 file changed, 85 insertions(+), 43 deletions(-) diff --git a/python/scripts/generate_functions.py b/python/scripts/generate_functions.py index 9f91af962..7be880913 100644 --- a/python/scripts/generate_functions.py +++ b/python/scripts/generate_functions.py @@ -6,57 +6,57 @@ sls::Detector class. The tool needs the libclang bindings to be installed. When the Detector API is updated this file should be run -manually +manually. """ from clang import cindex import subprocess import argparse import sys - +import time +from pathlib import Path from parse import system_include_paths, clang_format_version -required_version = 12 -RED = '\033[91m' +REDC = '\033[91m' +GREENC = '\033[92m' ENDC = '\033[0m' -if (ver := clang_format_version()) != required_version: - print(f'{RED}Clang format version {required_version} required, detected: {ver}. Bye!{ENDC}') - sys.exit(1) +def red(msg): + return f'{REDC}{msg}{ENDC}' + +def green(msg): + return f'{GREENC}{msg}{ENDC}' + +def check_clang_format_version(required_version): + if (ver := clang_format_version()) != required_version: + msg = red(f'Clang format version {required_version} required, detected: {ver}. Bye!') + print(msg) + sys.exit(1) + else: + msg = green(f'Found clang-format version {ver}') + print(msg) + +def check_for_compile_commands_json(path): + # print(f"Looking for compile data base in: {path}") + compile_data_base_file = path/'compile_commands.json' + if not compile_data_base_file.exists(): + msg = red(f"No compile_commands.json file found in {path}. Bye!") + print(msg) + sys.exit(1) + else: + msg = green(f'Found: {compile_data_base_file}') + print(msg) default_build_path = "/home/l_frojdh/sls/build/" fpath = "../../slsDetectorSoftware/src/Detector.cpp" -parser = argparse.ArgumentParser() -parser.add_argument( - "-p", - "--build_path", - help="Path to the build database", - type=str, - default=default_build_path, -) -cargs = parser.parse_args() -db = cindex.CompilationDatabase.fromDirectory(cargs.build_path) -index = cindex.Index.create() -args = db.getCompileCommands(fpath) -args = list(iter(args).__next__().arguments)[0:-1] -args = args + "-x c++ --std=c++11".split() -syspath = system_include_paths("clang++") -incargs = ["-I" + inc for inc in syspath] -args = args + incargs - - -tu = index.parse(fpath, args=args) m = [] ag = [] - lines = [] - ag2 = [] - cn = [] def get_arguments(node): @@ -119,25 +119,67 @@ def visit(node): lines.append( f'.def("{child.spelling}",{fs} &Detector::{child.spelling}{args})' ) - print(f'&Detector::{child.spelling}{args})') + if cargs.verbose: + print(f'&Detector::{child.spelling}{args})') cn.append(child) for child in node.get_children(): visit(child) -visit(tu.cursor) +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument( + "-p", + "--build_path", + help="Path to the build database", + type=Path, + default=default_build_path, + ) + parser.add_argument( + "-v", + "--verbose", + help="more output", + action='store_true', + ) + cargs = parser.parse_args() + + check_clang_format_version(12) + check_for_compile_commands_json(cargs.build_path) + print("Parsing functions in Detector.h - ", end = "", flush = True) + t0 = time.perf_counter() + #parse functions + db = cindex.CompilationDatabase.fromDirectory(cargs.build_path) + index = cindex.Index.create() + args = db.getCompileCommands(fpath) + args = list(iter(args).__next__().arguments)[0:-1] + args = args + "-x c++ --std=c++11".split() + syspath = system_include_paths("clang++") + incargs = ["-I" + inc for inc in syspath] + args = args + incargs + tu = index.parse(fpath, args=args) + visit(tu.cursor) + print(green('OK')) + print(f'Parsing took {time.perf_counter()-t0:.3f}s') -with open("../src/detector_in.cpp") as f: - data = f.read() -s = "".join(lines) -s += ";" -text = data.replace("[[FUNCTIONS]]", s) -warning = "/* WARINING This file is auto generated any edits might be overwritten without warning */\n\n" -with open("../src/detector.cpp", "w") as f: - f.write(warning) - f.write(text) + print("Read detector_in.cpp - ", end = "") + with open("../src/detector_in.cpp") as f: + data = f.read() + s = "".join(lines) + s += ";" + text = data.replace("[[FUNCTIONS]]", s) + warning = "/* WARINING This file is auto generated any edits might be overwritten without warning */\n\n" + print(green("OK")) + print("Writing to detector.cpp - ", end = "") + with open("../src/detector.cpp", "w") as f: + f.write(warning) + f.write(text) + print(green('OK')) -# run clang format on the output -subprocess.run(["clang-format", "../src/detector.cpp", "-i"]) + # run clang format on the output + print('Running clang format on generated source -', end = "") + subprocess.run(["clang-format", "../src/detector.cpp", "-i"]) + print(green(" OK")) + print("Changes since last commit:") + subprocess.run(['git', 'diff', '../src/detector.cpp'])