From 99ec7f0046bff42018aabe3802c7320cd7208db4 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Tue, 28 Jul 2020 17:06:46 +0200 Subject: [PATCH 01/26] eiger: always change speed when changing dr --- slsDetectorSoftware/src/Module.cpp | 60 ++++++++++++++++++------------ 1 file changed, 37 insertions(+), 23 deletions(-) diff --git a/slsDetectorSoftware/src/Module.cpp b/slsDetectorSoftware/src/Module.cpp index a282fd41f..27621ad8a 100644 --- a/slsDetectorSoftware/src/Module.cpp +++ b/slsDetectorSoftware/src/Module.cpp @@ -187,7 +187,7 @@ void Module::setAllTrimbits(int val) { sendToDetector(F_SET_ALL_TRIMBITS, val); } -int64_t Module::getNumberOfFrames() const{ +int64_t Module::getNumberOfFrames() const { return sendToDetector(F_GET_NUM_FRAMES); } @@ -198,7 +198,7 @@ void Module::setNumberOfFrames(int64_t value) { } } -int64_t Module::getNumberOfTriggers() const{ +int64_t Module::getNumberOfTriggers() const { return sendToDetector(F_GET_NUM_TRIGGERS); } @@ -209,7 +209,7 @@ void Module::setNumberOfTriggers(int64_t value) { } } -int64_t Module::getExptime(int gateIndex) const{ +int64_t Module::getExptime(int gateIndex) const { return sendToDetector(F_GET_EXPTIME, gateIndex); } @@ -228,7 +228,9 @@ void Module::setExptime(int gateIndex, int64_t value) { } } -int64_t Module::getPeriod() const { return sendToDetector(F_GET_PERIOD); } +int64_t Module::getPeriod() const { + return sendToDetector(F_GET_PERIOD); +} void Module::setPeriod(int64_t value) { sendToDetector(F_SET_PERIOD, value, nullptr); @@ -276,18 +278,21 @@ void Module::setDynamicRange(int dr) { sendToReceiver(F_SET_RECEIVER_DYNAMIC_RANGE, retval); } - // EIGER only, update speed and rate correction when dr changes - if (dr != prev_val) { + // update speed + if (shm()->myDetectorType == EIGER) { if (dr == 32) { LOG(logINFO) << "Setting Clock to Quarter Speed to cope with " "Dynamic Range of 32"; setClockDivider(RUN_CLOCK, 2); - } else if (prev_val == 32) { + } else { LOG(logINFO) << "Setting Clock to Full Speed for Dynamic Range of " << dr; setClockDivider(RUN_CLOCK, 0); } - updateRateCorrection(); + // EIGER only, update speed and rate correction when dr changes + if (dr != prev_val) { + updateRateCorrection(); + } } } @@ -321,7 +326,7 @@ void Module::setClockPhase(int clkIndex, int value, bool inDegrees) { sendToDetector(F_SET_CLOCK_PHASE, args, nullptr); } -int Module::getMaxClockPhaseShift(int clkIndex) const{ +int Module::getMaxClockPhaseShift(int clkIndex) const { return sendToDetector(F_GET_MAX_CLOCK_PHASE_SHIFT, clkIndex); } @@ -498,11 +503,11 @@ std::string Module::getScanErrorMessage() const { // Network Configuration (Detector<->Receiver) -int Module::getNumberofUDPInterfacesFromShm() const{ +int Module::getNumberofUDPInterfacesFromShm() const { return shm()->numUDPInterfaces; } -int Module::getNumberofUDPInterfaces() const{ +int Module::getNumberofUDPInterfaces() const { shm()->numUDPInterfaces = sendToDetector(F_GET_NUM_INTERFACES); return shm()->numUDPInterfaces; } @@ -534,7 +539,7 @@ void Module::setSourceUDPIP(const IpAddr ip) { sendToDetector(F_SET_SOURCE_UDP_IP, ip, nullptr); } -sls::IpAddr Module::getSourceUDPIP2() const{ +sls::IpAddr Module::getSourceUDPIP2() const { return sendToDetector(F_GET_SOURCE_UDP_IP2); } @@ -638,7 +643,7 @@ void Module::setDestinationUDPPort(const int port) { } } -int Module::getDestinationUDPPort2() const{ +int Module::getDestinationUDPPort2() const { return sendToDetector(F_GET_DEST_UDP_PORT2); } @@ -831,7 +836,8 @@ void Module::setReceiverSilentMode(bool enable) { nullptr); } -slsDetectorDefs::frameDiscardPolicy Module::getReceiverFramesDiscardPolicy() const { +slsDetectorDefs::frameDiscardPolicy +Module::getReceiverFramesDiscardPolicy() const { return static_cast( sendToReceiver(F_GET_RECEIVER_DISCARD_POLICY)); } @@ -880,7 +886,7 @@ std::array Module::getReceiverThreadIds() const { // File -slsDetectorDefs::fileFormat Module::getFileFormat() const{ +slsDetectorDefs::fileFormat Module::getFileFormat() const { return static_cast( sendToReceiver(F_GET_RECEIVER_FILE_FORMAT)); } @@ -1103,7 +1109,9 @@ void Module::setThresholdEnergy(int e_eV, detectorSettings isettings, } } -std::string Module::getSettingsDir() const { return std::string(shm()->settingsDir); } +std::string Module::getSettingsDir() const { + return std::string(shm()->settingsDir); +} std::string Module::setSettingsDir(const std::string &dir) { sls::strcpy_safe(shm()->settingsDir, dir.c_str()); @@ -1173,7 +1181,9 @@ void Module::setRateCorrection(int64_t t) { sendToDetector(F_SET_RATE_CORRECT, t, nullptr); } -int Module::getReadNLines() const { return sendToDetector(F_GET_READ_N_LINES); } +int Module::getReadNLines() const { + return sendToDetector(F_GET_READ_N_LINES); +} void Module::setReadNLines(const int value) { sendToDetector(F_SET_READ_N_LINES, value, nullptr); @@ -1231,7 +1241,8 @@ void Module::setDeactivatedRxrPaddingMode(bool padding) { } bool Module::getCounterBit() const { - return (!static_cast(sendToDetector(F_SET_COUNTER_BIT, GET_FLAG))); + return ( + !static_cast(sendToDetector(F_SET_COUNTER_BIT, GET_FLAG))); } void Module::setCounterBit(bool cb) { @@ -1294,8 +1305,9 @@ void Module::resetTemperatureEvent() { sendToDetectorStop(F_TEMP_EVENT, 0); } -bool Module::getAutoComparatorDisableMode() const{ - return static_cast(sendToDetector(F_AUTO_COMP_DISABLE, GET_FLAG)); +bool Module::getAutoComparatorDisableMode() const { + return static_cast( + sendToDetector(F_AUTO_COMP_DISABLE, GET_FLAG)); } void Module::setAutoComparatorDisableMode(bool val) { @@ -1591,7 +1603,7 @@ void Module::setVetoFile(const int chipIndex, const std::string &fname) { } } -slsDetectorDefs::burstMode Module::getBurstMode() const{ +slsDetectorDefs::burstMode Module::getBurstMode() const { auto r = sendToDetector(F_GET_BURST_MODE); return static_cast(r); } @@ -1750,7 +1762,9 @@ void Module::setCounterMask(uint32_t countermask) { } } -int Module::getNumberOfGates() const { return sendToDetector(F_GET_NUM_GATES); } +int Module::getNumberOfGates() const { + return sendToDetector(F_GET_NUM_GATES); +} void Module::setNumberOfGates(int value) { sendToDetector(F_SET_NUM_GATES, value, nullptr); @@ -1885,7 +1899,7 @@ int Module::setExternalSamplingSource(int value) { return sendToDetector(F_EXTERNAL_SAMPLING_SOURCE, value); } -bool Module::getExternalSampling() const{ +bool Module::getExternalSampling() const { return sendToDetector(F_EXTERNAL_SAMPLING, GET_FLAG); } From 6846939f927ca846a3e6d6035a83dc32f5efd7a1 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Wed, 29 Jul 2020 09:56:03 +0200 Subject: [PATCH 02/26] eiger rxr: space between subperiod(ns) in master file --- slsReceiverSoftware/src/BinaryFile.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slsReceiverSoftware/src/BinaryFile.cpp b/slsReceiverSoftware/src/BinaryFile.cpp index cf6baaf35..1c6ba8b1c 100644 --- a/slsReceiverSoftware/src/BinaryFile.cpp +++ b/slsReceiverSoftware/src/BinaryFile.cpp @@ -183,7 +183,7 @@ void BinaryFile::CreateMasterFile(bool masterFileWriteEnable, "Total Frames : %lld\n" "Exptime (ns) : %lld\n" "SubExptime (ns) : %lld\n" - "SubPeriod(ns) : %lld\n" + "SubPeriod (ns) : %lld\n" "Period (ns) : %lld\n" "Quad Enable : %d\n" "Analog Flag : %d\n" From 89da671ae207056bdb3e36dac64ed68e693dac0f Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Wed, 29 Jul 2020 15:10:54 +0200 Subject: [PATCH 03/26] m3: numpackets to 2 or 20 depending on ten giga enable --- .../slsDetectorFunctionList.c | 27 ++++++++++++------- .../slsDetectorServer_defs.h | 3 ++- .../src/slsDetectorServer_funcs.c | 3 ++- slsReceiverSoftware/src/GeneralData.h | 1 + 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c index d95875dfd..cc80aa5fd 100644 --- a/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c @@ -2055,21 +2055,28 @@ void *start_timer(void *arg) { return NULL; } - int64_t periodNs = getPeriod(); - int numFrames = (getNumFrames() * getNumTriggers()); - int64_t expUs = getGatePeriod() / 1000; + const int64_t periodNs = getPeriod(); + const int numFrames = (getNumFrames() * getNumTriggers()); + const int64_t expUs = getGatePeriod() / 1000; - int imagesize = calculateDataBytes(); - int dataSize = imagesize / PACKETS_PER_FRAME; - int packetSize = dataSize + sizeof(sls_detector_header); + const int imagesize = calculateDataBytes(); + const int tgEnable = enableTenGigabitEthernet(-1); + const int packetsPerFrame = + tgEnable ? PACKETS_PER_FRAME_10G : PACKETS_PER_FRAME_1G; + const int dataSize = imagesize / packetsPerFrame; + const int packetSize = dataSize + sizeof(sls_detector_header); + + LOG(logDEBUG1, + ("imagesize:%d tg:%d packets/Frame:%d datasize:%d packetSize:%d\n", + imagesize, tgEnable, packetsPerFrame, dataSize, packetSize)); // Generate data char imageData[imagesize]; memset(imageData, 0, imagesize); { - int dr = setDynamicRange(-1); - int numCounters = __builtin_popcount(getCounterMask()); - int nchannels = NCHAN_1_COUNTER * NCHIP * numCounters; + const int dr = setDynamicRange(-1); + const int numCounters = __builtin_popcount(getCounterMask()); + const int nchannels = NCHAN_1_COUNTER * NCHIP * numCounters; switch (dr) { /*case 1: // TODO: Not implemented in firmware yet @@ -2111,7 +2118,7 @@ void *start_timer(void *arg) { int srcOffset = 0; // loop packet - for (int i = 0; i != PACKETS_PER_FRAME; ++i) { + for (int i = 0; i != packetsPerFrame; ++i) { char packetData[packetSize]; memset(packetData, 0, packetSize); diff --git a/slsDetectorServers/mythen3DetectorServer/slsDetectorServer_defs.h b/slsDetectorServers/mythen3DetectorServer/slsDetectorServer_defs.h index 8f170e0dd..7b5529140 100644 --- a/slsDetectorServers/mythen3DetectorServer/slsDetectorServer_defs.h +++ b/slsDetectorServers/mythen3DetectorServer/slsDetectorServer_defs.h @@ -133,7 +133,8 @@ typedef struct udp_header_struct { uint16_t udp_destport; } udp_header; #define UDP_IP_HEADER_LENGTH_BYTES (28) -#define PACKETS_PER_FRAME (2) +#define PACKETS_PER_FRAME_10G (2) +#define PACKETS_PER_FRAME_1G (20) /** Signal Definitions */ #define SIGNAL_TBLoad_1 (0) diff --git a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c index 1225b3192..a9a51f053 100644 --- a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c +++ b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c @@ -7029,7 +7029,8 @@ int get_receiver_parameters(int file_des) { return printSocketReadError(); // 10 gbe -#if defined(EIGERD) || defined(CHIPTESTBOARDD) || defined(MOENCHD) +#if defined(EIGERD) || defined(CHIPTESTBOARDD) || defined(MOENCHD) || \ + defined(MYTHEN3D) i32 = enableTenGigabitEthernet(GET_FLAG); #else i32 = 0; diff --git a/slsReceiverSoftware/src/GeneralData.h b/slsReceiverSoftware/src/GeneralData.h index 687a6f065..90e126cc9 100644 --- a/slsReceiverSoftware/src/GeneralData.h +++ b/slsReceiverSoftware/src/GeneralData.h @@ -462,6 +462,7 @@ class Mythen3Data : public GeneralData { */ void SetDynamicRange(int dr, bool tgEnable) { imageSize = nPixelsX * nPixelsY * ((double)dr / 8.00); + packetsPerFrame = tgEnable ? 2 : 20; dataSize = imageSize / packetsPerFrame; packetSize = headerSizeinPacket + dataSize; LOG(logINFO) << "PacketSize: " << packetSize; From 7dfeb987db7b1706f9c28d7edf228e007bd5f0af Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Thu, 30 Jul 2020 11:50:03 +0200 Subject: [PATCH 04/26] changing command from vhighvoltage to highvoltage --- examples/gotthard.config | 2 +- examples/gotthard_two.config | 6 +- examples/jctb_moench03_T1.config | 2 +- examples/jungfrau.config | 2 +- examples/jungfrau_two.config | 2 +- examples/moench03_T1.config | 2 +- examples/two_gotthard.config | 4 +- manual/manual-client/Eiger_short.tex | 18 ++-- manual/manual-client/commands.txt | 2 +- .../manual-client/slsDetectorClientHowTo.tex | 6 +- manual/manual-main/slsDetectorClientHowTo.tex | 4 +- slsDetectorGui/forms/form_tab_developer.ui | 8 +- slsDetectorSoftware/src/CmdProxy.h | 5 +- slsDetectorSoftware/tests/test-CmdProxy.cpp | 86 +++++++++---------- slsSupportLib/src/ToString.cpp | 4 +- 15 files changed, 77 insertions(+), 76 deletions(-) diff --git a/examples/gotthard.config b/examples/gotthard.config index f2c290df0..ed73f49e0 100755 --- a/examples/gotthard.config +++ b/examples/gotthard.config @@ -12,7 +12,7 @@ hostname bchip007 0:rx_udpip 129.129.202.98 0:rx_hostname pc6898 0:outdir /bigRAID/datadir_gotthard/rec_test_data -0:vhighvoltage 120 +0:highvoltage 120 master -1 sync none outdir /bigRAID/datadir_gotthard/rec_test_data diff --git a/examples/gotthard_two.config b/examples/gotthard_two.config index 655d4f457..9830095ca 100755 --- a/examples/gotthard_two.config +++ b/examples/gotthard_two.config @@ -6,12 +6,12 @@ hostname bchip074+bchip075+ 0:extsig:0 trigger_in_rising_edge 0:rx_tcpport 1954 0:rx_udpport 50001 -0:vhighvoltage 0 +0:highvoltage 0 1:extsig:0 trigger_in_rising_edge 1:rx_tcpport 1955 1:rx_udpport 50002 -1:vhighvoltage 0 +1:highvoltage 0 ############################################################################## ######### @@ -53,5 +53,5 @@ settings veryhighgain exptime 0.000005 period 0.0001 -vhighvoltage 90 +highvoltage 90 diff --git a/examples/jctb_moench03_T1.config b/examples/jctb_moench03_T1.config index ce99d8be7..d21dd2b26 100644 --- a/examples/jctb_moench03_T1.config +++ b/examples/jctb_moench03_T1.config @@ -498,4 +498,4 @@ rx_jsonpara detectorMode analog reg 0x5e 0x00010000 #powerchip 1 -vhighvoltage 90 +highvoltage 90 diff --git a/examples/jungfrau.config b/examples/jungfrau.config index b09fa4818..a8ae9c971 100755 --- a/examples/jungfrau.config +++ b/examples/jungfrau.config @@ -6,7 +6,7 @@ hostname localhost rx_hostname localhost #powerchip 1 -#vhighvoltage 200 +#highvoltage 200 #extsig:0 trigger_in_rising_edge #timing trigger diff --git a/examples/jungfrau_two.config b/examples/jungfrau_two.config index ea92dee1d..2198f03f6 100755 --- a/examples/jungfrau_two.config +++ b/examples/jungfrau_two.config @@ -17,7 +17,7 @@ hostname bchip048+bchip052+ rx_hostname pcmoench01 powerchip 1 -vhighvoltage 200 +highvoltage 200 #extsig:0 trigger_in_rising_edge #timing trigger diff --git a/examples/moench03_T1.config b/examples/moench03_T1.config index d062ebb58..add227a02 100644 --- a/examples/moench03_T1.config +++ b/examples/moench03_T1.config @@ -56,7 +56,7 @@ rx_discardpolicy discardpartial adcpipeline 15 powerchip 1 -vhighvoltage 90 +highvoltage 90 #adcreg 0x14 0x40 diff --git a/examples/two_gotthard.config b/examples/two_gotthard.config index 3f9763d57..c46375aa6 100755 --- a/examples/two_gotthard.config +++ b/examples/two_gotthard.config @@ -19,7 +19,7 @@ hostname bchip007+bchip009+ 0:rx_udpip 10.1.1.1 0:rx_hostname 129.129.202.134 0:outdir /data/speedt -0:vhighvoltage 120 +0:highvoltage 120 #1:hostname bchip009 @@ -37,7 +37,7 @@ hostname bchip007+bchip009+ 1:rx_udpip 10.1.2.1 1:rx_hostname 129.129.202.134 1:outdir /data/speedt -1:vhighvoltage 120 +1:highvoltage 120 master -1 diff --git a/manual/manual-client/Eiger_short.tex b/manual/manual-client/Eiger_short.tex index 00b50fcaf..f3341fc85 100755 --- a/manual/manual-client/Eiger_short.tex +++ b/manual/manual-client/Eiger_short.tex @@ -196,7 +196,7 @@ sls_detector_put 0-parameters setup.det \end{verbatim} Note that the parameter file for any realease before 4.1.1 has not the possibility to understand parameters to be set differently for different half modules, i.e. {\tt{0:txndelay\_left xxxxx},\tt{1:txndelay\_left yyyyy}}. -In the case of \E, the proper bias voltage of the sensor has to be setup, i.e. the {\tt{setup.det}} file needs to contain the line {\tt{vhighvoltage 150}}. Other detector functionality, which are rarely changed can be setup here. +In the case of \E, the proper bias voltage of the sensor has to be setup, i.e. the {\tt{setup.det}} file needs to contain the line {\tt{highvoltage 150}}. Other detector functionality, which are rarely changed can be setup here. Other important settings that are configured in the {\tt{setup.det}} file are: \begin{itemize} \item {\tt{tengiga 0/1}}, which sets whether the detector is enabled to send data through the 1~or the 10~Gb Ethernet. @@ -1156,10 +1156,10 @@ In 500k--2M pixel systems there is a hardware temperature safety switch, which w The HV can also be set and read through the software: \begin{verbatim} -./sls_detector_put vhighvoltage 150 -./sls_detector_get vhighvoltage +./sls_detector_put highvoltage 150 +./sls_detector_get highvoltage \end{verbatim} -Note that the get {\tt{vhighvoltage}} would return the measured HV from the master module only. If getting the vhighvoltage for individual halfmodules, only the master will have a value different from -999. +Note that the get {\tt{highvoltage}} would return the measured HV from the master module only. If getting the highvoltage for individual halfmodules, only the master will have a value different from -999. \appendix @@ -1411,7 +1411,7 @@ Environment variable SLSDETNAME can be set for using 2 different detectors from \subsection{Measure the HV} For every system: \begin{itemize} -\item Software-wise measure it (now the software returns the measured value), with {\tt{sls\_detector\_get vhighvoltage}}. The returned value is the HV (for proper Eiger setting is approximately 150~V) if it is correctly set. If two master modules are presents (multi systems), the average is returned (still to be tested). If one asks for the individual $n$ half module bias voltage through {\tt{sls\_detector\_get n:vhighvoltage}}, if the $n$ module is a master, the actual voltage will be returned. If it is a slave, -999 will be returned. +\item Software-wise measure it (now the software returns the measured value), with {\tt{sls\_detector\_get highvoltage}}. The returned value is the HV (for proper Eiger setting is approximately 150~V) if it is correctly set. If two master modules are presents (multi systems), the average is returned (still to be tested). If one asks for the individual $n$ half module bias voltage through {\tt{sls\_detector\_get n:highvoltage}}, if the $n$ module is a master, the actual voltage will be returned. If it is a slave, -999 will be returned. \item Hardware-wise (opening the detector) measure value of HV on C14 on the power distribution board. Check also that the small HV connector cable is really connected. \end{itemize} @@ -1462,7 +1462,7 @@ Scroll up in the terminal till you find:\\ There is also an easier way, that is that only the master module will return the real value of the HV. If you have more than 1 detector system, then you will have more than 1 physical master, as the HV needs to be applied to all the systems. \begin{verbatim} -for i in $(seq 0 36); do sls_detector_put $i:vhighvoltage; done +for i in $(seq 0 36); do sls_detector_put $i:highvoltage; done \end{verbatim} Only the master will return to you a sensible number (150 normally). the others will return -999. @@ -1623,10 +1623,10 @@ ratecorr number where {\tt{number}} is a string that should be interpreted as a float in s. 0.000000 means correction off. Values above zero are the value of $\tau$ in ns. \item \begin{verbatim} -sls_detector_get vhighvoltage -vhighvoltage number +sls_detector_get highvoltage +highvoltage number \end{verbatim} -where {\tt{number}} is a string that should be interpreted as an int and for proper Eiger setting is approximately 150~V if it is correctly set. If two master modules are presents (multi systems), the average is returned (still to be tested). If one asks for the individual $n$ half module bias voltage through {\tt{sls\_detector\_get n:vhighvoltage}}, if the $n$ module is a master, the actual voltage will be returned. If it is a slave, -999 will be returned. +where {\tt{number}} is a string that should be interpreted as an int and for proper Eiger setting is approximately 150~V if it is correctly set. If two master modules are presents (multi systems), the average is returned (still to be tested). If one asks for the individual $n$ half module bias voltage through {\tt{sls\_detector\_get n:highvoltage}}, if the $n$ module is a master, the actual voltage will be returned. If it is a slave, -999 will be returned. \item \begin{verbatim} sls_detector_get busy diff --git a/manual/manual-client/commands.txt b/manual/manual-client/commands.txt index bde305796..ce54d5906 100755 --- a/manual/manual-client/commands.txt +++ b/manual/manual-client/commands.txt @@ -142,7 +142,7 @@ "vpreamp"; // sets/get vpreamp value (advanced! Mythen) "vshaper1"; // sets/get vshaper1 value (advanced! Mythen) "vshaper2"; // sets/get vshaper2 value (advanced! Mythen) - "vhighvoltage"; // sets/get vhighvoltage value (advanced! Chiptest board and Eiger) + "highvoltage"; // sets/get highvoltage value (advanced! Chiptest board and Eiger) "vapower"; // sets/get vapower value (advanced! Chiptest board) "vddpower"; // sets/get vddpower value (advanced! Chiptest board) "vshpower"; // sets/get vshpower value (advanced! Chiptest board) diff --git a/manual/manual-client/slsDetectorClientHowTo.tex b/manual/manual-client/slsDetectorClientHowTo.tex index 0f9ed3190..d21f2f2dd 100755 --- a/manual/manual-client/slsDetectorClientHowTo.tex +++ b/manual/manual-client/slsDetectorClientHowTo.tex @@ -335,7 +335,7 @@ Advanced settings changing the analog or digital performance of the acquisition. \item[vpreamp n] Sets the DAC value of the preamp feedback to n. \item[vshaper1 n] Sets the DAC value of the shaper1 feedback to n. \item[vshaper2 n] Sets the DAC value of the shaper2 feedback to n. -\item[vhighvoltage n] Sets the DAC value of the high voltage to n (in V). +\item[highvoltage n] Sets the DAC value of the high voltage to n (in V). \item[vapower n] CHIPTEST BOARD ONLY - Sets the DAC value of the analog voltage to n. \item[vddpower n] CHIPTEST BOARD ONLY - Sets the DAC value of the analog voltage to n. \item[vshpower n] CHIPTEST BOARD ONLY - Sets the comparator power supply in dac units (0-1024). @@ -648,7 +648,7 @@ Advanced settings changing the analog or digital performance of the acquisition. \item[vpreamp] Returns the DAC value of the preamp feedback to n. \item[vshaper1] Returns the DAC value of the shaper1 feedback to n. \item[vshaper2] Returns the DAC value of the shaper2 feedback to n. -\item[vhighvoltage] Returns the DAC value of the high voltage to n. +\item[highvoltage] Returns the DAC value of the high voltage to n. \item[vapower] CHIPTEST BOARD ONLY - Returns the DAC value of the analog voltage to n. \item[vddpower] CHIPTEST BOARD ONLY - Returns the DAC value of the analog voltage to n. \item[vshpower] CHIPTEST BOARD ONLY - Returns the comparator power supply in dac units (0-1024). @@ -714,7 +714,7 @@ One can configure all the detector settings in a parameter file {\tt{setup.det}} sls_detector_put parameters setup.det \end{verbatim} -In the case of \E, the parameter file ({\tt{setup.det}} needs to setup the proper bias voltage of the sensor, i.e. needs to contain the line {\tt{vhighvoltage 150}}. +In the case of \E, the parameter file ({\tt{setup.det}} needs to setup the proper bias voltage of the sensor, i.e. needs to contain the line {\tt{highvoltage 150}}. \subsection{Standard acquisition} diff --git a/manual/manual-main/slsDetectorClientHowTo.tex b/manual/manual-main/slsDetectorClientHowTo.tex index 6f411c84a..e97bea1eb 100755 --- a/manual/manual-main/slsDetectorClientHowTo.tex +++ b/manual/manual-main/slsDetectorClientHowTo.tex @@ -322,7 +322,7 @@ Advanced settings changing the analog or digital performance of the acquisition. \item[vpreamp n] Sets the DAC value of the preamp feedback to n. \item[vshaper1 n] Sets the DAC value of the shaper1 feedback to n. \item[vshaper2 n] Sets the DAC value of the shaper2 feedback to n. -\item[vhighvoltage n] CHIPTEST BOARD ONLY - Sets the DAC value of the high voltage to n. +\item[highvoltage n] CHIPTEST BOARD ONLY - Sets the DAC value of the high voltage to n. \item[vapower n] CHIPTEST BOARD ONLY - Sets the DAC value of the analog voltage to n. \item[vddpower n] CHIPTEST BOARD ONLY - Sets the DAC value of the analog voltage to n. \item[vshpower n] CHIPTEST BOARD ONLY - Sets the comparator power supply in dac units (0-1024). @@ -594,7 +594,7 @@ Advanced settings changing the analog or digital performance of the acquisition. \item[vpreamp] Returns the DAC value of the preamp feedback to n. \item[vshaper1] Returns the DAC value of the shaper1 feedback to n. \item[vshaper2] Returns the DAC value of the shaper2 feedback to n. -\item[vhighvoltage] CHIPTEST BOARD ONLY - Returns the DAC value of the high voltage to n. +\item[highvoltage] CHIPTEST BOARD ONLY - Returns the DAC value of the high voltage to n. \item[vapower] CHIPTEST BOARD ONLY - Returns the DAC value of the analog voltage to n. \item[vddpower] CHIPTEST BOARD ONLY - Returns the DAC value of the analog voltage to n. \item[vshpower] CHIPTEST BOARD ONLY - Returns the comparator power supply in dac units (0-1024). diff --git a/slsDetectorGui/forms/form_tab_developer.ui b/slsDetectorGui/forms/form_tab_developer.ui index d93fd43c6..8cf71fea6 100755 --- a/slsDetectorGui/forms/form_tab_developer.ui +++ b/slsDetectorGui/forms/form_tab_developer.ui @@ -86,7 +86,7 @@ - <html><head/><body><p>High Voltage</p><p> #vhighvoltage#</p></body></html> + <html><head/><body><p>High Voltage</p><p> #highvoltage#</p></body></html> High Voltage: @@ -108,7 +108,7 @@ - <html><head/><body><p>High Voltage</p><p> #vhighvoltage#</p></body></html> + <html><head/><body><p>High Voltage</p><p> #highvoltage#</p></body></html> @@ -156,7 +156,7 @@ - <html><head/><body><p>High Voltage. Range: 60 - 200V. Swich off high voltage by setting to 0.</p><p>-1 corresponds to different values from detectors.</p><p>#vhighvoltage#</p></body></html> + <html><head/><body><p>High Voltage. Range: 60 - 200V. Swich off high voltage by setting to 0.</p><p>-1 corresponds to different values from detectors.</p><p>#highvoltage#</p></body></html> High Voltage: @@ -178,7 +178,7 @@ - <html><head/><body><p>High Voltage. Range: 60 - 200V. Swich off high voltage by setting to 0.</p><p>-1 corresponds to different values from detectors.</p><p>#vhighvoltage#</p></body></html> + <html><head/><body><p>High Voltage. Range: 60 - 200V. Swich off high voltage by setting to 0.</p><p>-1 corresponds to different values from detectors.</p><p>#highvoltage#</p></body></html> -1 diff --git a/slsDetectorSoftware/src/CmdProxy.h b/slsDetectorSoftware/src/CmdProxy.h index f3e85893c..28c7cbe58 100644 --- a/slsDetectorSoftware/src/CmdProxy.h +++ b/slsDetectorSoftware/src/CmdProxy.h @@ -528,6 +528,7 @@ class CmdProxy { {"cycles", "triggers"}, {"cyclesl", "triggersl"}, {"clkdivider", "speed"}, + {"vhighvoltage", "highvoltage"}, {"digitest", "imagetest"}, /** temperature */ @@ -654,7 +655,7 @@ class CmdProxy { {"clkphase", &CmdProxy::ClockPhase}, {"maxclkphaseshift", &CmdProxy::MaxClockPhaseShift}, {"clkdiv", &CmdProxy::ClockDivider}, - {"vhighvoltage", &CmdProxy::vhighvoltage}, + {"highvoltage", &CmdProxy::highvoltage}, {"powerchip", &CmdProxy::powerchip}, {"imagetest", &CmdProxy::imagetest}, {"extsig", &CmdProxy::ExternalSignal}, @@ -1185,7 +1186,7 @@ class CmdProxy { "\n\t[CTB][Jungfrau] Absolute maximum Phase shift of of the " "clock to latch digital bits."); - INTEGER_COMMAND(vhighvoltage, getHighVoltage, setHighVoltage, StringTo, + INTEGER_COMMAND(highvoltage, getHighVoltage, setHighVoltage, StringTo, "[n_value]\n\tHigh voltage to the sensor in Voltage." "\n\t[Gotthard] [0|90|110|120|150|180|200]" "\n\t[Eiger][Mythen3][Gotthard2] 0-200" diff --git a/slsDetectorSoftware/tests/test-CmdProxy.cpp b/slsDetectorSoftware/tests/test-CmdProxy.cpp index 66c8af0a2..401d266e7 100644 --- a/slsDetectorSoftware/tests/test-CmdProxy.cpp +++ b/slsDetectorSoftware/tests/test-CmdProxy.cpp @@ -793,97 +793,97 @@ TEST_CASE("maxclkphaseshift", "[.cmd][.new]") { } } -TEST_CASE("vhighvoltage", "[.cmd][.new]") { +TEST_CASE("highvoltage", "[.cmd][.new]") { Detector det; CmdProxy proxy(&det); auto det_type = det.getDetectorType().squash(); auto prev_val = det.getHighVoltage(); // selected values if (det_type == defs::GOTTHARD) { - REQUIRE_THROWS(proxy.Call("vhighvoltage", {"50"}, -1, PUT)); + REQUIRE_THROWS(proxy.Call("highvoltage", {"50"}, -1, PUT)); { std::ostringstream oss1, oss2; - proxy.Call("vhighvoltage", {"90"}, -1, PUT, oss1); - REQUIRE(oss1.str() == "vhighvoltage 90\n"); - proxy.Call("vhighvoltage", {}, -1, GET, oss2); - REQUIRE(oss2.str() == "vhighvoltage 90\n"); + proxy.Call("highvoltage", {"90"}, -1, PUT, oss1); + REQUIRE(oss1.str() == "highvoltage 90\n"); + proxy.Call("highvoltage", {}, -1, GET, oss2); + REQUIRE(oss2.str() == "highvoltage 90\n"); } { std::ostringstream oss1, oss2; - proxy.Call("vhighvoltage", {"0"}, -1, PUT, oss1); - REQUIRE(oss1.str() == "vhighvoltage 0\n"); - proxy.Call("vhighvoltage", {}, -1, GET, oss2); - REQUIRE(oss2.str() == "vhighvoltage 0\n"); + proxy.Call("highvoltage", {"0"}, -1, PUT, oss1); + REQUIRE(oss1.str() == "highvoltage 0\n"); + proxy.Call("highvoltage", {}, -1, GET, oss2); + REQUIRE(oss2.str() == "highvoltage 0\n"); } } // range 0, 60 - 200 else if (det_type == defs::JUNGFRAU || det_type == defs::CHIPTESTBOARD || det_type == defs::MOENCH) { - REQUIRE_THROWS(proxy.Call("vhighvoltage", {"50"}, -1, PUT)); + REQUIRE_THROWS(proxy.Call("highvoltage", {"50"}, -1, PUT)); { std::ostringstream oss1, oss2; - proxy.Call("vhighvoltage", {"90"}, -1, PUT, oss1); - REQUIRE(oss1.str() == "vhighvoltage 90\n"); - proxy.Call("vhighvoltage", {}, -1, GET, oss2); - REQUIRE(oss2.str() == "vhighvoltage 90\n"); + proxy.Call("highvoltage", {"90"}, -1, PUT, oss1); + REQUIRE(oss1.str() == "highvoltage 90\n"); + proxy.Call("highvoltage", {}, -1, GET, oss2); + REQUIRE(oss2.str() == "highvoltage 90\n"); } { std::ostringstream oss1, oss2; - proxy.Call("vhighvoltage", {"0"}, -1, PUT, oss1); - REQUIRE(oss1.str() == "vhighvoltage 0\n"); - proxy.Call("vhighvoltage", {}, -1, GET, oss2); - REQUIRE(oss2.str() == "vhighvoltage 0\n"); + proxy.Call("highvoltage", {"0"}, -1, PUT, oss1); + REQUIRE(oss1.str() == "highvoltage 0\n"); + proxy.Call("highvoltage", {}, -1, GET, oss2); + REQUIRE(oss2.str() == "highvoltage 0\n"); } } // full range 0 - 200 (get needs to wait) else if (det_type == defs::EIGER) { { std::ostringstream oss1, oss2; - proxy.Call("vhighvoltage", {"50"}, 0, PUT, oss1); - REQUIRE(oss1.str() == "vhighvoltage 50\n"); + proxy.Call("highvoltage", {"50"}, 0, PUT, oss1); + REQUIRE(oss1.str() == "highvoltage 50\n"); std::this_thread::sleep_for(std::chrono::seconds(2)); - proxy.Call("vhighvoltage", {}, 0, GET, oss2); - REQUIRE(oss2.str() == "vhighvoltage 50\n"); + proxy.Call("highvoltage", {}, 0, GET, oss2); + REQUIRE(oss2.str() == "highvoltage 50\n"); } { std::ostringstream oss1, oss2; - proxy.Call("vhighvoltage", {"120"}, 0, PUT, oss1); - REQUIRE(oss1.str() == "vhighvoltage 120\n"); + proxy.Call("highvoltage", {"120"}, 0, PUT, oss1); + REQUIRE(oss1.str() == "highvoltage 120\n"); std::this_thread::sleep_for(std::chrono::seconds(2)); - proxy.Call("vhighvoltage", {}, 0, GET, oss2); - REQUIRE(oss2.str() == "vhighvoltage 120\n"); + proxy.Call("highvoltage", {}, 0, GET, oss2); + REQUIRE(oss2.str() == "highvoltage 120\n"); } { std::ostringstream oss1, oss2; - proxy.Call("vhighvoltage", {"0"}, 0, PUT, oss1); - REQUIRE(oss1.str() == "vhighvoltage 0\n"); + proxy.Call("highvoltage", {"0"}, 0, PUT, oss1); + REQUIRE(oss1.str() == "highvoltage 0\n"); std::this_thread::sleep_for(std::chrono::seconds(2)); - proxy.Call("vhighvoltage", {}, 0, GET, oss2); - REQUIRE(oss2.str() == "vhighvoltage 0\n"); + proxy.Call("highvoltage", {}, 0, GET, oss2); + REQUIRE(oss2.str() == "highvoltage 0\n"); } } // full range 0 - 200 else { { std::ostringstream oss1, oss2; - proxy.Call("vhighvoltage", {"50"}, -1, PUT, oss1); - REQUIRE(oss1.str() == "vhighvoltage 50\n"); - proxy.Call("vhighvoltage", {}, -1, GET, oss2); - REQUIRE(oss2.str() == "vhighvoltage 50\n"); + proxy.Call("highvoltage", {"50"}, -1, PUT, oss1); + REQUIRE(oss1.str() == "highvoltage 50\n"); + proxy.Call("highvoltage", {}, -1, GET, oss2); + REQUIRE(oss2.str() == "highvoltage 50\n"); } { std::ostringstream oss1, oss2; - proxy.Call("vhighvoltage", {"120"}, -1, PUT, oss1); - REQUIRE(oss1.str() == "vhighvoltage 120\n"); - proxy.Call("vhighvoltage", {}, -1, GET, oss2); - REQUIRE(oss2.str() == "vhighvoltage 120\n"); + proxy.Call("highvoltage", {"120"}, -1, PUT, oss1); + REQUIRE(oss1.str() == "highvoltage 120\n"); + proxy.Call("highvoltage", {}, -1, GET, oss2); + REQUIRE(oss2.str() == "highvoltage 120\n"); } { std::ostringstream oss1, oss2; - proxy.Call("vhighvoltage", {"0"}, -1, PUT, oss1); - REQUIRE(oss1.str() == "vhighvoltage 0\n"); - proxy.Call("vhighvoltage", {}, -1, GET, oss2); - REQUIRE(oss2.str() == "vhighvoltage 0\n"); + proxy.Call("highvoltage", {"0"}, -1, PUT, oss1); + REQUIRE(oss1.str() == "highvoltage 0\n"); + proxy.Call("highvoltage", {}, -1, GET, oss2); + REQUIRE(oss2.str() == "highvoltage 0\n"); } } for (int i = 0; i != det.size(); ++i) { diff --git a/slsSupportLib/src/ToString.cpp b/slsSupportLib/src/ToString.cpp index 3397aee0c..18a55af0d 100644 --- a/slsSupportLib/src/ToString.cpp +++ b/slsSupportLib/src/ToString.cpp @@ -492,7 +492,7 @@ std::string ToString(const defs::dacIndex s) { case defs::TRIMBIT_SCAN: return std::string("trimbit_scan"); case defs::HIGH_VOLTAGE: - return std::string("vhighvoltage"); + return std::string("highvoltage"); case defs::IO_DELAY: return std::string("iodelay"); default: @@ -850,7 +850,7 @@ template <> defs::dacIndex StringTo(const std::string &s) { return defs::IBIAS_SFP; if (s == "trimbit_scan") return defs::TRIMBIT_SCAN; - if (s == "vhighvoltage") + if (s == "highvoltage") return defs::HIGH_VOLTAGE; if (s == "iodelay") return defs::IO_DELAY; From 98ffe350f3da7ef7737ead33c2ef31ca2b56d31c Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Thu, 30 Jul 2020 11:50:56 +0200 Subject: [PATCH 05/26] changing command from vhighvoltage to highvoltage --- slsDetectorCalibration/gotthardExecutables/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slsDetectorCalibration/gotthardExecutables/Makefile b/slsDetectorCalibration/gotthardExecutables/Makefile index edd3e257d..5d11522b1 100644 --- a/slsDetectorCalibration/gotthardExecutables/Makefile +++ b/slsDetectorCalibration/gotthardExecutables/Makefile @@ -10,5 +10,5 @@ sls_detector_put exptime 0.000005 sls_detector_put period 0.01 -sls_detector_put vhighvoltage 90 +sls_detector_put highvoltage 90 From 5b9c7c41052cb72e9f0444bc045e95e117befce7 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Thu, 30 Jul 2020 11:52:22 +0200 Subject: [PATCH 06/26] python vhighvoltage to highvoltage --- python/simple-integration-tests/eiger/test.config | 2 +- python/simple-integration-tests/jungfrau_0_6/tests/test.par | 2 +- python/slsdet/detector.py | 6 +++--- python/unit-tests/detector_eiger.py | 6 +++--- python/unit-tests/detector_test.py | 6 +++--- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/python/simple-integration-tests/eiger/test.config b/python/simple-integration-tests/eiger/test.config index 75fc82b40..79ab1f6be 100755 --- a/python/simple-integration-tests/eiger/test.config +++ b/python/simple-integration-tests/eiger/test.config @@ -27,7 +27,7 @@ dr 32 threaded 1 tengiga 0 -vhighvoltage 150 +highvoltage 150 iodelay 660 #gappixels 1 diff --git a/python/simple-integration-tests/jungfrau_0_6/tests/test.par b/python/simple-integration-tests/jungfrau_0_6/tests/test.par index b04533952..78fb87f03 100755 --- a/python/simple-integration-tests/jungfrau_0_6/tests/test.par +++ b/python/simple-integration-tests/jungfrau_0_6/tests/test.par @@ -1 +1 @@ -vhighvoltage 200 \ No newline at end of file +highvoltage 200 \ No newline at end of file diff --git a/python/slsdet/detector.py b/python/slsdet/detector.py index e7e197d17..76ad24578 100755 --- a/python/slsdet/detector.py +++ b/python/slsdet/detector.py @@ -508,11 +508,11 @@ class Detector(CppDetectorApi): self.setSourceUDPMAC2(MacAddr(mac)) @property - def vhighvoltage(self): + def highvoltage(self): return element_if_equal(self.getHighVoltage()) - @vhighvoltage.setter - def vhighvoltage(self, v): + @highvoltage.setter + def highvoltage(self, v): self.setHighVoltage(v) @property diff --git a/python/unit-tests/detector_eiger.py b/python/unit-tests/detector_eiger.py index be5d56c61..889e97f07 100755 --- a/python/unit-tests/detector_eiger.py +++ b/python/unit-tests/detector_eiger.py @@ -164,18 +164,18 @@ def test_cannot_set_fw_version(d): def test_get_high_voltage_call_signature(d, mocker): m = mocker.patch('_slsdet.DetectorApi.getDac') d.high_voltage - m.assert_called_once_with('vhighvoltage', -1) + m.assert_called_once_with('highvoltage', -1) def test_get_high_voltage(d, mocker): m = mocker.patch('_slsdet.DetectorApi.getDac') m.return_value = 80 assert d.high_voltage == 80 -#self._api.setDac('vhighvoltage', -1, voltage) +#self._api.setDac('highvoltage', -1, voltage) def test_set_high_voltage(d, mocker): m = mocker.patch('_slsdet.DetectorApi.setDac') d.high_voltage = 80 - m.assert_called_once_with('vhighvoltage', -1, 80) + m.assert_called_once_with('highvoltage', -1, 80) def test_decode_hostname_two_names(d, mocker): m = mocker.patch('_slsdet.DetectorApi.getHostname') diff --git a/python/unit-tests/detector_test.py b/python/unit-tests/detector_test.py index c20bd6f65..08185ca53 100755 --- a/python/unit-tests/detector_test.py +++ b/python/unit-tests/detector_test.py @@ -170,18 +170,18 @@ def test_set_counters_single(d, mocker): # def test_get_high_voltage_call_signature(d, mocker): # m = mocker.patch('_slsdet.DetectorApi.getDac') # d.high_voltage -# m.assert_called_once_with('vhighvoltage', -1) +# m.assert_called_once_with('highvoltage', -1) # def test_get_high_voltage(d, mocker): # m = mocker.patch('_slsdet.DetectorApi.getDac') # m.return_value = 80 # assert d.high_voltage == 80 -# #self._api.setDac('vhighvoltage', -1, voltage) +# #self._api.setDac('highvoltage', -1, voltage) # def test_set_high_voltage(d, mocker): # m = mocker.patch('_slsdet.DetectorApi.setDac') # d.high_voltage = 80 -# m.assert_called_once_with('vhighvoltage', -1, 80) +# m.assert_called_once_with('highvoltage', -1, 80) # def test_decode_hostname_two_names(d, mocker): # m = mocker.patch('_slsdet.DetectorApi.getHostname') From d31839e80e08fb1d0df1579f46e07ff7a846b391 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Thu, 30 Jul 2020 14:04:50 +0200 Subject: [PATCH 07/26] roi constructor added --- slsDetectorGui/src/qTabAdvanced.cpp | 4 +--- slsDetectorSoftware/src/CmdProxy.cpp | 4 +--- slsSupportLib/include/sls_detector_defs.h | 2 ++ slsSupportLib/tests/test-ToString.cpp | 4 ++-- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/slsDetectorGui/src/qTabAdvanced.cpp b/slsDetectorGui/src/qTabAdvanced.cpp index 5974e6141..e5ad30cab 100644 --- a/slsDetectorGui/src/qTabAdvanced.cpp +++ b/slsDetectorGui/src/qTabAdvanced.cpp @@ -560,9 +560,7 @@ void qTabAdvanced::ClearROI() { void qTabAdvanced::SetROI() { - slsDetectorDefs::ROI roi; - roi.xmin = spinXmin->value(); - roi.xmax = spinXmax->value(); + slsDetectorDefs::ROI roi(spinXmin->value(), spinXmax->value()); // set roi LOG(logINFO) << "Setting ROI: [" << roi.xmin << ", " << roi.xmax << "]"; diff --git a/slsDetectorSoftware/src/CmdProxy.cpp b/slsDetectorSoftware/src/CmdProxy.cpp index 984f240a0..a4d2d266c 100644 --- a/slsDetectorSoftware/src/CmdProxy.cpp +++ b/slsDetectorSoftware/src/CmdProxy.cpp @@ -1559,9 +1559,7 @@ std::string CmdProxy::ROI(int action) { if (args.size() != 2) { WrongNumberOfParameters(2); } - defs::ROI t; - t.xmin = StringTo(args[0]); - t.xmax = StringTo(args[1]); + defs::ROI t(StringTo(args[0]), StringTo(args[1])); det->setROI(t, det_id); os << '[' << t.xmin << ", " << t.xmax << "]\n"; } else { diff --git a/slsSupportLib/include/sls_detector_defs.h b/slsSupportLib/include/sls_detector_defs.h index 733d4afb2..f0d9b6ca5 100644 --- a/slsSupportLib/include/sls_detector_defs.h +++ b/slsSupportLib/include/sls_detector_defs.h @@ -160,6 +160,8 @@ class slsDetectorDefs { struct ROI { int xmin{-1}; int xmax{-1}; + ROI() = default; + ROI(int xmin, int xmax) : xmin(xmin), xmax(xmax){}; } __attribute__((packed)); #else typedef struct { diff --git a/slsSupportLib/tests/test-ToString.cpp b/slsSupportLib/tests/test-ToString.cpp index 06f9253ae..6eabadc4b 100644 --- a/slsSupportLib/tests/test-ToString.cpp +++ b/slsSupportLib/tests/test-ToString.cpp @@ -221,13 +221,13 @@ TEST_CASE("Detector type") { } TEST_CASE("Formatting slsDetectorDefs::ROI") { - slsDetectorDefs::ROI roi{5, 159}; + slsDetectorDefs::ROI roi(5, 159); REQUIRE(ToString(roi) == "[5, 159]"); } TEST_CASE("Streaming of slsDetectorDefs::ROI") { using namespace sls; - slsDetectorDefs::ROI roi{-10, 1}; + slsDetectorDefs::ROI roi(-10, 1); std::ostringstream oss; oss << roi; REQUIRE(oss.str() == "[-10, 1]"); From c2b586a3335a6d4a2ca5c1142815ba959fa8ae16 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Thu, 30 Jul 2020 14:07:02 +0200 Subject: [PATCH 08/26] eiger: virtual server more print minor --- .../eigerDetectorServer/slsDetectorFunctionList.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c index a673a4081..8121f28c7 100644 --- a/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c @@ -2048,7 +2048,7 @@ void *start_timer(void *arg) { int colRight = top ? eiger_virtual_detPos[1] + 1 : eiger_virtual_detPos[1]; int ntotpixels = 256 * 256 * 4; - LOG(logINFO, (" dr:%d\n bytesperpixel:%f\n tgenable:%d\n datasize:%d\n " + LOG(logDEBUG1, (" dr:%d\n bytesperpixel:%f\n tgenable:%d\n datasize:%d\n " "packetsize:%d\n numpackes:%d\n npixelsx:%d\n databytes:%d\n " "ntotpixels:%d\n", dr, bytesPerPixel, tgEnable, datasize, packetsize, @@ -2181,7 +2181,7 @@ void *start_timer(void *arg) { usleep(eiger_virtual_transmission_delay_right); sendUDPPacket(1, packetData2, packetsize); } - LOG(logINFO, ("Sent frame: %d\n", iframes)); + LOG(logINFO, ("Sent frame: %d[%lld]\n", iframes, (long long unsigned int)(frameNr + iframes))); clock_gettime(CLOCK_REALTIME, &end); int64_t timeNs = ((end.tv_sec - begin.tv_sec) * 1E9 + (end.tv_nsec - begin.tv_nsec)); From 85c958facf27c242fcd19b42084e09bfe397e734 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Thu, 30 Jul 2020 18:05:47 +0200 Subject: [PATCH 09/26] WIP det dependant master file attribtes --- slsReceiverSoftware/src/Implementation.cpp | 1 + .../src/masterFileAttributes.h | 116 ++++++++++++++++++ slsReceiverSoftware/src/receiver_defs.h | 7 +- slsSupportLib/include/ToString.h | 2 + slsSupportLib/src/ToString.cpp | 10 ++ 5 files changed, 132 insertions(+), 4 deletions(-) create mode 100644 slsReceiverSoftware/src/masterFileAttributes.h diff --git a/slsReceiverSoftware/src/Implementation.cpp b/slsReceiverSoftware/src/Implementation.cpp index 0bb059f82..0e56c1163 100644 --- a/slsReceiverSoftware/src/Implementation.cpp +++ b/slsReceiverSoftware/src/Implementation.cpp @@ -7,6 +7,7 @@ #include "ToString.h" #include "ZmqSocket.h" //just for the zmq port define #include "file_utils.h" +#include "masterFileAttributes.h" #include //eperm #include diff --git a/slsReceiverSoftware/src/masterFileAttributes.h b/slsReceiverSoftware/src/masterFileAttributes.h new file mode 100644 index 000000000..5b0a4a702 --- /dev/null +++ b/slsReceiverSoftware/src/masterFileAttributes.h @@ -0,0 +1,116 @@ +#pragma once + +#include "sls_detector_defs.h" +#include "logger.h" +#include "ToString.h" + +// versions +#define HDF5_WRITER_VERSION (6.1) // 1 decimal places +#define BINARY_WRITER_VERSION (6.1) // 1 decimal places + +class masterFileAttributes { + + public: + double version{0.0}; + slsDetectorDefs::detectorType detType{slsDetectorDefs::GENERIC}; + uint32_t imageSize{0}; + slsDetectorDefs::xy nPixels{}; + uint32_t maxFramesPerFile{0}; + uint64_t totalFrames{0}; + uint64_t exptimeNs{0}; + uint64_t periodNs{0}; + uint32_t dynamicRange{0}; + uint32_t tenGiga{0}; + uint64_t subExptimeNs{0}; + uint64_t subPeriodNs{0}; + uint32_t quadEnable{0}; + uint32_t adcmask{0}; + uint32_t analogFlag{0}; + uint32_t digitalFlag{0}; + uint32_t dbitoffset{0}; + uint64_t dbitlist{0}; + slsDetectorDefs::ROI roi{}; + uint64_t exptime1Ns{0}; + uint64_t exptime2Ns{0}; + uint64_t exptime3Ns{0}; + uint64_t gateDelay1Ns{0}; + uint64_t gateDelay2Ns{0}; + uint64_t gateDelay3Ns{0}; + uint32_t gates; + /* + double version{0.0}; + slsDetectorDefs::detectorType myDetectorType{slsDetectorDefs::GENERIC}; + uint32_t imageSize{0}; + uint32_t nPixelsX{0}; + uint32_t nPixelsY{0}; + uint32_t maxFramesPerFile{0}; + uint64_t totalFrames{0}; + uint64_t exptimeNs{0}; + uint64_t periodNs{0}; +*/ + /* eiger + uint32_t dynamicRange{0}; + uint32_t tenGiga{0}; + uint64_t subExptimeNs{0}; + uint64_t subPeriodNs{0}; + uint32_t quadEnable{0}; + */ + /** moench + uint32_t tenGiga{0}; + uint32_t adcmask{0}; + */ + /* ctb + uint32_t tenGiga{0}; + uint32_t adcmask{0}; + uint32_t analogFlag{0}; + uint32_t digitalFlag{0}; + uint32_t dbitoffset{0}; + uint64_t dbitlist{0}; + */ + /* gotthard + uint32_t roiXmin{0}; + uint32_t roiXmax{0}; + */ + /* mythen3 + uint32_t dynamicRange{0}; + uint32_t tenGiga{0}; + uint64_t exptime1Ns{0}; + uint64_t exptime2Ns{0}; + uint64_t exptime3Ns{0}; + uint64_t gateDelay1Ns{0}; + uint64_t gateDelay2Ns{0}; + uint64_t gateDelay3Ns{0}; + uint32_t gates; +*/ + masterFileAttributes(){}; + virtual ~masterFileAttributes(){}; + + std::string GetBinaryMasterFileAttributes() { + std::ostringstream oss; + oss << "Version : " << std::setprecision(2) << version << '\n' + << "Detector Type : " << sls::ToString(detType) << '\n' + << "Image Size : " << imageSize << " bytes" << '\n' + << "nPixels : " << sls::ToString(nPixels) << " pixels" << '\n' + << "Max Frames Per File : " << maxFramesPerFile << '\n' + << "Total Frames : " << totalFrames << '\n' + << "Exptime (ns) : " << exptimeNs << '\n' + << "Period (ns) : " << periodNs << '\n'; + return oss.str(); + }; + + // hdf5 +}; + +class GotthardMasterFileAttributes : public masterFileAttributes { + + public: + GotthardMasterFileAttributes() {}; + + std::string GetBinaryMasterFileAttributes() { + std::ostringstream oss; + oss << masterFileAttributes::GetBinaryMasterFileAttributes() + << "Roi (xmin, xmax) : " << sls::ToString(roi) << '\n'; + return oss.str(); + }; +}; + diff --git a/slsReceiverSoftware/src/receiver_defs.h b/slsReceiverSoftware/src/receiver_defs.h index 7a5e91c1e..e2397e97a 100755 --- a/slsReceiverSoftware/src/receiver_defs.h +++ b/slsReceiverSoftware/src/receiver_defs.h @@ -39,10 +39,6 @@ // hdf5 #define MAX_CHUNKED_IMAGES (1) -// versions -#define HDF5_WRITER_VERSION (6.0) // 1 decimal places -#define BINARY_WRITER_VERSION (6.0) // 1 decimal places - // parameters to calculate fifo depth #define SAMPLE_TIME_IN_NS (100000000) // 100ms #define MAX_EIGER_ROWS_PER_READOUT (256) @@ -57,6 +53,9 @@ #define STREAMER_PRIORITY (10) #define TCP_PRIORITY (10) + +#define HDF5_WRITER_VERSION (6.1) // 1 decimal places +#define BINARY_WRITER_VERSION (6.1) // 1 decimal places struct masterAttributes { double version; uint32_t detectorType; diff --git a/slsSupportLib/include/ToString.h b/slsSupportLib/include/ToString.h index 5654ef7ed..fb2c2747f 100644 --- a/slsSupportLib/include/ToString.h +++ b/slsSupportLib/include/ToString.h @@ -39,6 +39,8 @@ std::string ToString(const std::vector &vec); std::string ToString(const defs::burstMode s); std::string ToString(const defs::timingSourceType s); +std::string ToString(const slsDetectorDefs::xy &coord); +std::ostream &operator<<(std::ostream &os, const slsDetectorDefs::xy &coord); std::string ToString(const slsDetectorDefs::ROI &roi); std::ostream &operator<<(std::ostream &os, const slsDetectorDefs::ROI &roi); std::string ToString(const slsDetectorDefs::rxParameters &r); diff --git a/slsSupportLib/src/ToString.cpp b/slsSupportLib/src/ToString.cpp index 18a55af0d..334192deb 100644 --- a/slsSupportLib/src/ToString.cpp +++ b/slsSupportLib/src/ToString.cpp @@ -3,6 +3,16 @@ namespace sls { +std::string ToString(const slsDetectorDefs::xy &coord) { + std::ostringstream oss; + oss << '[' << coord.x << ", " << coord.y << ']'; + return oss.str(); +} + +std::ostream &operator<<(std::ostream &os, const slsDetectorDefs::xy &coord) { + return os << ToString(coord); +} + std::string ToString(const slsDetectorDefs::ROI &roi) { std::ostringstream oss; oss << '[' << roi.xmin << ", " << roi.xmax << ']'; From 4eaa9588baff0bdd079f336f2f8bbfa514cc0fc7 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Fri, 31 Jul 2020 12:15:28 +0200 Subject: [PATCH 10/26] created detector dependant master file attributes --- slsReceiverSoftware/src/BinaryFile.cpp | 84 +------------ slsReceiverSoftware/src/BinaryFile.h | 9 +- slsReceiverSoftware/src/DataProcessor.cpp | 5 +- slsReceiverSoftware/src/DataProcessor.h | 3 +- slsReceiverSoftware/src/File.h | 4 +- slsReceiverSoftware/src/Implementation.cpp | 88 ++++++++----- .../src/masterFileAttributes.h | 116 ------------------ slsReceiverSoftware/src/receiver_defs.h | 3 +- 8 files changed, 76 insertions(+), 236 deletions(-) delete mode 100644 slsReceiverSoftware/src/masterFileAttributes.h diff --git a/slsReceiverSoftware/src/BinaryFile.cpp b/slsReceiverSoftware/src/BinaryFile.cpp index cccaafa7c..8740db18f 100644 --- a/slsReceiverSoftware/src/BinaryFile.cpp +++ b/slsReceiverSoftware/src/BinaryFile.cpp @@ -6,6 +6,7 @@ #include "BinaryFile.h" #include "Fifo.h" +#include "MasterAttributes.h" #include "receiver_defs.h" #include @@ -133,7 +134,7 @@ void BinaryFile::WriteToFile(char *buffer, int buffersize, } void BinaryFile::CreateMasterFile(bool masterFileWriteEnable, - masterAttributes &masterFileAttributes) { + MasterAttributes *attr) { // beginning of every acquisition numFramesInFile = 0; numActualPacketsInFile = 0; @@ -147,7 +148,6 @@ void BinaryFile::CreateMasterFile(bool masterFileWriteEnable, if (!(*silentMode)) { LOG(logINFO) << "Master File: " << masterFileName; } - masterFileAttributes.version = BINARY_WRITER_VERSION; // create master file if (!(*overWriteEnable)) { @@ -167,84 +167,10 @@ void BinaryFile::CreateMasterFile(bool masterFileWriteEnable, masterFileName); } // create master file data - time_t t = time(nullptr); + std::string strAttributes = attr->GetBinaryMasterAttributes(); char message[maxMasterFileSize]; - sprintf(message, - "Version : %.1f\n" - "Detector Type : %d\n" - "Dynamic Range : %d\n" - "Ten Giga : %d\n" - "Image Size : %d bytes\n" - "nPixelsX : %d pixels\n" - "nPixelsY : %d pixels\n" - "Max Frames Per File : %u\n" - "Total Frames : %lld\n" - "Exptime (ns) : %lld\n" - "SubExptime (ns) : %lld\n" - "SubPeriod (ns) : %lld\n" - "Period (ns) : %lld\n" - "Quad Enable : %d\n" - "Analog Flag : %d\n" - "Digital Flag : %d\n" - "ADC Mask : %d\n" - "Dbit Offset : %d\n" - "Dbit Bitset : %lld\n" - "Roi (xmin, xmax) : %d %d\n" - "Exptime1 (ns) : %lld\n" - "Exptime2 (ns) : %lld\n" - "Exptime3 (ns) : %lld\n" - "GateDelay1 (ns) : %lld\n" - "GateDelay2 (ns) : %lld\n" - "GateDelay3 (ns) : %lld\n" - "Gates : %d\n" - "Timestamp : %s\n\n" - - "#Frame Header\n" - "Frame Number : 8 bytes\n" - "SubFrame Number/ExpLength : 4 bytes\n" - "Packet Number : 4 bytes\n" - "Bunch ID : 8 bytes\n" - "Timestamp : 8 bytes\n" - "Module Id : 2 bytes\n" - "Row : 2 bytes\n" - "Column : 2 bytes\n" - "Reserved : 2 bytes\n" - "Debug : 4 bytes\n" - "Round Robin Number : 2 bytes\n" - "Detector Type : 1 byte\n" - "Header Version : 1 byte\n" - "Packets Caught Mask : 64 bytes\n", - masterFileAttributes.version, masterFileAttributes.detectorType, - masterFileAttributes.dynamicRange, masterFileAttributes.tenGiga, - masterFileAttributes.imageSize, masterFileAttributes.nPixelsX, - masterFileAttributes.nPixelsY, - masterFileAttributes.maxFramesPerFile, - (long long int)masterFileAttributes.totalFrames, - (long long int)masterFileAttributes.exptimeNs, - (long long int)masterFileAttributes.subExptimeNs, - (long long int)masterFileAttributes.subPeriodNs, - (long long int)masterFileAttributes.periodNs, - masterFileAttributes.quadEnable, - masterFileAttributes.analogFlag, - masterFileAttributes.digitalFlag, masterFileAttributes.adcmask, - masterFileAttributes.dbitoffset, - (long long int)masterFileAttributes.dbitlist, - masterFileAttributes.roiXmin, masterFileAttributes.roiXmax, - (long long int)masterFileAttributes.exptime1Ns, - (long long int)masterFileAttributes.exptime2Ns, - (long long int)masterFileAttributes.exptime3Ns, - (long long int)masterFileAttributes.gateDelay1Ns, - (long long int)masterFileAttributes.gateDelay2Ns, - (long long int)masterFileAttributes.gateDelay3Ns, - masterFileAttributes.gates, ctime(&t)); - - //TODO! snprintf? This would already have been a buffer overflow - if (strlen(message) > maxMasterFileSize) { - throw sls::RuntimeError("Master File Size " + - std::to_string(strlen(message)) + - " is greater than max str size " + - std::to_string(maxMasterFileSize)); - } + memset(message, 0, maxMasterFileSize); + sls::strcpy_safe(message, strAttributes.c_str()); // write and close file if (fwrite((void *)message, 1, strlen(message), masterfd) != strlen(message)) { diff --git a/slsReceiverSoftware/src/BinaryFile.h b/slsReceiverSoftware/src/BinaryFile.h index 9206cedfa..8f0087fa5 100644 --- a/slsReceiverSoftware/src/BinaryFile.h +++ b/slsReceiverSoftware/src/BinaryFile.h @@ -42,7 +42,7 @@ class BinaryFile : private virtual slsDetectorDefs, public File { void PrintMembers(TLogLevel level = logDEBUG1) override; void CreateFile() override; void CreateMasterFile(bool masterFileWriteEnable, - masterAttributes &masterFileAttributes) override; + MasterAttributes *attr) override; void CloseCurrentFile() override; void CloseAllFiles() override; void WriteToFile(char *buffer, int buffersize, uint64_t currentFrameNumber, @@ -55,8 +55,7 @@ class BinaryFile : private virtual slsDetectorDefs, public File { static FILE *masterfd; uint32_t numFramesInFile = 0; uint64_t numActualPacketsInFile = 0; - //Make sure this is known at compile time - //TODO! Later away from stack allocation of message - static constexpr size_t maxMasterFileSize = 2000; - + // Make sure this is known at compile time + // TODO! Later away from stack allocation of message + static constexpr size_t maxMasterFileSize = 2000; }; \ No newline at end of file diff --git a/slsReceiverSoftware/src/DataProcessor.cpp b/slsReceiverSoftware/src/DataProcessor.cpp index 7a0df2951..ebfdd744b 100644 --- a/slsReceiverSoftware/src/DataProcessor.cpp +++ b/slsReceiverSoftware/src/DataProcessor.cpp @@ -9,6 +9,7 @@ #include "BinaryFile.h" #include "Fifo.h" #include "GeneralData.h" +#include "MasterAttributes.h" #ifdef HDF5C #include "HDF5File.h" #endif @@ -143,7 +144,7 @@ void DataProcessor::SetupFileWriter(bool fwe, int *nd, uint32_t *maxf, } // only the first file -void DataProcessor::CreateNewFile(masterAttributes &attr) { +void DataProcessor::CreateNewFile(MasterAttributes *attr) { if (file == nullptr) { throw sls::RuntimeError("file object not contstructed"); } @@ -411,7 +412,7 @@ void DataProcessor::PadMissingPackets(char *buf) { /** ctb specific */ void DataProcessor::RearrangeDbitData(char *buf) { - //TODO! (Erik) Refactor and add tests + // TODO! (Erik) Refactor and add tests int totalSize = (int)(*((uint32_t *)buf)); int ctbDigitalDataBytes = totalSize - (*ctbAnalogDataBytes) - (*ctbDbitOffset); diff --git a/slsReceiverSoftware/src/DataProcessor.h b/slsReceiverSoftware/src/DataProcessor.h index 26917a947..71e719369 100644 --- a/slsReceiverSoftware/src/DataProcessor.h +++ b/slsReceiverSoftware/src/DataProcessor.h @@ -16,6 +16,7 @@ class GeneralData; class Fifo; class File; class DataStreamer; +class MasterAttributes; #include #include @@ -134,7 +135,7 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject { * Create New File * @param attr master file attributes */ - void CreateNewFile(masterAttributes &attr); + void CreateNewFile(MasterAttributes *attr); /** * Closes files diff --git a/slsReceiverSoftware/src/File.h b/slsReceiverSoftware/src/File.h index b8a53c454..651691df5 100644 --- a/slsReceiverSoftware/src/File.h +++ b/slsReceiverSoftware/src/File.h @@ -15,6 +15,8 @@ #include +class MasterAttributes; + class File : private virtual slsDetectorDefs { public: @@ -86,7 +88,7 @@ class File : private virtual slsDetectorDefs { * @param mfwenable master file write enable * @param attr master file attributes */ - virtual void CreateMasterFile(bool mfwenable, masterAttributes &attr) = 0; + virtual void CreateMasterFile(bool mfwenable, MasterAttributes *attr) = 0; // HDf5 specific /** diff --git a/slsReceiverSoftware/src/Implementation.cpp b/slsReceiverSoftware/src/Implementation.cpp index 0e56c1163..0ba8e2528 100644 --- a/slsReceiverSoftware/src/Implementation.cpp +++ b/slsReceiverSoftware/src/Implementation.cpp @@ -4,10 +4,10 @@ #include "Fifo.h" #include "GeneralData.h" #include "Listener.h" +#include "MasterAttributes.h" #include "ToString.h" #include "ZmqSocket.h" //just for the zmq port define #include "file_utils.h" -#include "masterFileAttributes.h" #include //eperm #include @@ -906,45 +906,71 @@ void Implementation::CreateUDPSockets() { void Implementation::SetupWriter() { LOG(logDEBUG3) << __SHORT_AT__ << " called"; - masterAttributes attr; - attr.detectorType = myDetectorType; - attr.dynamicRange = dynamicRange; - attr.tenGiga = tengigaEnable; - attr.imageSize = generalData->imageSize; - attr.nPixelsX = generalData->nPixelsX; - attr.nPixelsY = generalData->nPixelsY; - attr.maxFramesPerFile = framesPerFile; - attr.totalFrames = numberOfTotalFrames; - attr.exptimeNs = acquisitionTime; - attr.subExptimeNs = subExpTime; - attr.subPeriodNs = subPeriod; - attr.periodNs = acquisitionPeriod; - attr.quadEnable = quadEnable; - attr.analogFlag = + std::unique_ptr masterAttributes; + switch (myDetectorType) { + 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 = myDetectorType; + masterAttributes->imageSize = generalData->imageSize; + masterAttributes->nPixels = + xy(generalData->nPixelsX, generalData->nPixelsY); + masterAttributes->maxFramesPerFile = framesPerFile; + masterAttributes->totalFrames = numberOfTotalFrames; + masterAttributes->exptime = std::chrono::nanoseconds(acquisitionTime); + masterAttributes->period = std::chrono::nanoseconds(acquisitionPeriod); + masterAttributes->dynamicRange = dynamicRange; + masterAttributes->tenGiga = tengigaEnable; + masterAttributes->subExptime = std::chrono::nanoseconds(subExpTime); + masterAttributes->subPeriod = std::chrono::nanoseconds(subPeriod); + masterAttributes->quad = quadEnable; + masterAttributes->adcmask = + tengigaEnable ? adcEnableMaskTenGiga : adcEnableMaskOneGiga; + masterAttributes->analog = (readoutType == ANALOG_ONLY || readoutType == ANALOG_AND_DIGITAL) ? 1 : 0; - attr.digitalFlag = + masterAttributes->digital = (readoutType == DIGITAL_ONLY || readoutType == ANALOG_AND_DIGITAL) ? 1 : 0; - attr.adcmask = tengigaEnable ? adcEnableMaskTenGiga : adcEnableMaskOneGiga; - attr.dbitoffset = ctbDbitOffset; - attr.dbitlist = 0; - attr.roiXmin = roi.xmin; - attr.roiXmax = roi.xmax; + masterAttributes->dbitoffset = ctbDbitOffset; + masterAttributes->dbitlist = 0; for (auto &i : ctbDbitList) { - attr.dbitlist |= (1 << i); + masterAttributes->dbitlist |= (1 << i); } - attr.exptime1Ns = acquisitionTime1; - attr.exptime2Ns = acquisitionTime2; - attr.exptime3Ns = acquisitionTime3; - attr.gateDelay1Ns = gateDelay1; - attr.gateDelay2Ns = gateDelay2; - attr.gateDelay3Ns = gateDelay3; - attr.gates = numberOfGates; + masterAttributes->roi = roi; + masterAttributes->exptime1 = std::chrono::nanoseconds(acquisitionTime1); + masterAttributes->exptime2 = std::chrono::nanoseconds(acquisitionTime2); + masterAttributes->exptime3 = std::chrono::nanoseconds(acquisitionTime3); + masterAttributes->gateDelay1 = std::chrono::nanoseconds(gateDelay1); + masterAttributes->gateDelay2 = std::chrono::nanoseconds(gateDelay2); + masterAttributes->gateDelay3 = std::chrono::nanoseconds(gateDelay3); + masterAttributes->gates = numberOfGates; try { for (unsigned int i = 0; i < dataProcessor.size(); ++i) { - dataProcessor[i]->CreateNewFile(attr); + dataProcessor[i]->CreateNewFile(masterAttributes.get()); } } catch (const sls::RuntimeError &e) { shutDownUDPSockets(); diff --git a/slsReceiverSoftware/src/masterFileAttributes.h b/slsReceiverSoftware/src/masterFileAttributes.h deleted file mode 100644 index 5b0a4a702..000000000 --- a/slsReceiverSoftware/src/masterFileAttributes.h +++ /dev/null @@ -1,116 +0,0 @@ -#pragma once - -#include "sls_detector_defs.h" -#include "logger.h" -#include "ToString.h" - -// versions -#define HDF5_WRITER_VERSION (6.1) // 1 decimal places -#define BINARY_WRITER_VERSION (6.1) // 1 decimal places - -class masterFileAttributes { - - public: - double version{0.0}; - slsDetectorDefs::detectorType detType{slsDetectorDefs::GENERIC}; - uint32_t imageSize{0}; - slsDetectorDefs::xy nPixels{}; - uint32_t maxFramesPerFile{0}; - uint64_t totalFrames{0}; - uint64_t exptimeNs{0}; - uint64_t periodNs{0}; - uint32_t dynamicRange{0}; - uint32_t tenGiga{0}; - uint64_t subExptimeNs{0}; - uint64_t subPeriodNs{0}; - uint32_t quadEnable{0}; - uint32_t adcmask{0}; - uint32_t analogFlag{0}; - uint32_t digitalFlag{0}; - uint32_t dbitoffset{0}; - uint64_t dbitlist{0}; - slsDetectorDefs::ROI roi{}; - uint64_t exptime1Ns{0}; - uint64_t exptime2Ns{0}; - uint64_t exptime3Ns{0}; - uint64_t gateDelay1Ns{0}; - uint64_t gateDelay2Ns{0}; - uint64_t gateDelay3Ns{0}; - uint32_t gates; - /* - double version{0.0}; - slsDetectorDefs::detectorType myDetectorType{slsDetectorDefs::GENERIC}; - uint32_t imageSize{0}; - uint32_t nPixelsX{0}; - uint32_t nPixelsY{0}; - uint32_t maxFramesPerFile{0}; - uint64_t totalFrames{0}; - uint64_t exptimeNs{0}; - uint64_t periodNs{0}; -*/ - /* eiger - uint32_t dynamicRange{0}; - uint32_t tenGiga{0}; - uint64_t subExptimeNs{0}; - uint64_t subPeriodNs{0}; - uint32_t quadEnable{0}; - */ - /** moench - uint32_t tenGiga{0}; - uint32_t adcmask{0}; - */ - /* ctb - uint32_t tenGiga{0}; - uint32_t adcmask{0}; - uint32_t analogFlag{0}; - uint32_t digitalFlag{0}; - uint32_t dbitoffset{0}; - uint64_t dbitlist{0}; - */ - /* gotthard - uint32_t roiXmin{0}; - uint32_t roiXmax{0}; - */ - /* mythen3 - uint32_t dynamicRange{0}; - uint32_t tenGiga{0}; - uint64_t exptime1Ns{0}; - uint64_t exptime2Ns{0}; - uint64_t exptime3Ns{0}; - uint64_t gateDelay1Ns{0}; - uint64_t gateDelay2Ns{0}; - uint64_t gateDelay3Ns{0}; - uint32_t gates; -*/ - masterFileAttributes(){}; - virtual ~masterFileAttributes(){}; - - std::string GetBinaryMasterFileAttributes() { - std::ostringstream oss; - oss << "Version : " << std::setprecision(2) << version << '\n' - << "Detector Type : " << sls::ToString(detType) << '\n' - << "Image Size : " << imageSize << " bytes" << '\n' - << "nPixels : " << sls::ToString(nPixels) << " pixels" << '\n' - << "Max Frames Per File : " << maxFramesPerFile << '\n' - << "Total Frames : " << totalFrames << '\n' - << "Exptime (ns) : " << exptimeNs << '\n' - << "Period (ns) : " << periodNs << '\n'; - return oss.str(); - }; - - // hdf5 -}; - -class GotthardMasterFileAttributes : public masterFileAttributes { - - public: - GotthardMasterFileAttributes() {}; - - std::string GetBinaryMasterFileAttributes() { - std::ostringstream oss; - oss << masterFileAttributes::GetBinaryMasterFileAttributes() - << "Roi (xmin, xmax) : " << sls::ToString(roi) << '\n'; - return oss.str(); - }; -}; - diff --git a/slsReceiverSoftware/src/receiver_defs.h b/slsReceiverSoftware/src/receiver_defs.h index e2397e97a..ba7ca56fb 100755 --- a/slsReceiverSoftware/src/receiver_defs.h +++ b/slsReceiverSoftware/src/receiver_defs.h @@ -53,7 +53,7 @@ #define STREAMER_PRIORITY (10) #define TCP_PRIORITY (10) - +/* #define HDF5_WRITER_VERSION (6.1) // 1 decimal places #define BINARY_WRITER_VERSION (6.1) // 1 decimal places struct masterAttributes { @@ -86,3 +86,4 @@ struct masterAttributes { uint64_t gateDelay3Ns; uint32_t gates; }; +*/ \ No newline at end of file From 68c0f76bd97641a16ba2a763890c6096d1935418 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Fri, 31 Jul 2020 12:15:38 +0200 Subject: [PATCH 11/26] created detector dependant master file attributes --- slsReceiverSoftware/src/MasterAttributes.h | 208 +++++++++++++++++++++ 1 file changed, 208 insertions(+) create mode 100644 slsReceiverSoftware/src/MasterAttributes.h diff --git a/slsReceiverSoftware/src/MasterAttributes.h b/slsReceiverSoftware/src/MasterAttributes.h new file mode 100644 index 000000000..976d2e4f1 --- /dev/null +++ b/slsReceiverSoftware/src/MasterAttributes.h @@ -0,0 +1,208 @@ +#pragma once + +#include "ToString.h" +#include "logger.h" +#include "sls_detector_defs.h" +#include +using ns = std::chrono::nanoseconds; + +// versions +#define HDF5_WRITER_VERSION (6.1) // 1 decimal places +#define BINARY_WRITER_VERSION (6.1) // 1 decimal places + +class MasterAttributes { + + public: + slsDetectorDefs::detectorType detType{slsDetectorDefs::GENERIC}; + uint32_t imageSize{0}; + slsDetectorDefs::xy nPixels{}; + uint32_t maxFramesPerFile{0}; + uint64_t totalFrames{0}; + ns exptime{0}; + ns period{0}; + uint32_t dynamicRange{0}; + uint32_t tenGiga{0}; + ns subExptime{0}; + ns subPeriod{0}; + uint32_t quad{0}; + uint32_t adcmask{0}; + uint32_t analog{0}; + uint32_t digital{0}; + uint32_t dbitoffset{0}; + uint64_t dbitlist{0}; + slsDetectorDefs::ROI roi{}; + ns exptime1{0}; + ns exptime2{0}; + ns exptime3{0}; + ns gateDelay1{0}; + ns gateDelay2{0}; + ns gateDelay3{0}; + uint32_t gates; + + MasterAttributes(){}; + virtual ~MasterAttributes(){}; + + virtual 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' + << "Image Size : " << imageSize << " bytes" << '\n' + << "Pixels : " << sls::ToString(nPixels) << '\n' + << "Max Frames Per File : " << maxFramesPerFile << '\n' + << "Total Frames : " << totalFrames << '\n'; + return oss.str(); + }; + + std::string GetBinaryFrameHeaderFormat() { + return std::string("\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"); + }; + + // hdf5 +}; + +class GotthardMasterAttributes : public MasterAttributes { + public: + GotthardMasterAttributes(){}; + + std::string GetBinaryMasterAttributes() override { + std::ostringstream oss; + oss << MasterAttributes::GetBinaryMasterAttributes() + << "Exptime : " << sls::ToString(exptime) << '\n' + << "Period : " << sls::ToString(period) << '\n' + << "Roi (xmin, xmax) : " << sls::ToString(roi) << '\n' + << GetBinaryFrameHeaderFormat(); + return oss.str(); + }; +}; + +class JungfrauMasterAttributes : public MasterAttributes { + public: + JungfrauMasterAttributes(){}; + + std::string GetBinaryMasterAttributes() override { + std::ostringstream oss; + oss << MasterAttributes::GetBinaryMasterAttributes() + << "Exptime : " << sls::ToString(exptime) << '\n' + << "Period : " << sls::ToString(period) << '\n' + << GetBinaryFrameHeaderFormat(); + return oss.str(); + }; +}; + +class EigerMasterAttributes : public MasterAttributes { + public: + EigerMasterAttributes(){}; + + std::string GetBinaryMasterAttributes() 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' + << "SubExptime : " << sls::ToString(subExptime) + << '\n' + << "SubPeriod : " << sls::ToString(subPeriod) + << '\n' + << "Quad : " << quad << '\n' + << GetBinaryFrameHeaderFormat(); + return oss.str(); + }; +}; + +class Mythen3MasterAttributes : public MasterAttributes { + public: + Mythen3MasterAttributes(){}; + + std::string GetBinaryMasterAttributes() override { + std::ostringstream oss; + oss << MasterAttributes::GetBinaryMasterAttributes() + << "Dynamic Range : " << dynamicRange << '\n' + << "Ten Giga : " << tenGiga << '\n' + << "Period : " << sls::ToString(period) << '\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' + << GetBinaryFrameHeaderFormat(); + return oss.str(); + }; +}; + +class Gotthard2MasterAttributes : public MasterAttributes { + public: + Gotthard2MasterAttributes(){}; + + std::string GetBinaryMasterAttributes() override { + std::ostringstream oss; + oss << MasterAttributes::GetBinaryMasterAttributes() + << "Exptime : " << sls::ToString(exptime) << '\n' + << "Period : " << sls::ToString(period) << '\n' + << GetBinaryFrameHeaderFormat(); + return oss.str(); + }; +}; + +class MoenchMasterAttributes : public MasterAttributes { + public: + MoenchMasterAttributes(){}; + + std::string GetBinaryMasterAttributes() override { + std::ostringstream oss; + oss << MasterAttributes::GetBinaryMasterAttributes() + << "Exptime : " << sls::ToString(exptime) << '\n' + << "Period : " << sls::ToString(period) << '\n' + << "Ten Giga : " << tenGiga << '\n' + << "ADC Mask : " << sls::ToStringHex(adcmask) + << '\n' + << GetBinaryFrameHeaderFormat(); + return oss.str(); + }; +}; + +class CtbMasterAttributes : public MasterAttributes { + public: + CtbMasterAttributes(){}; + + std::string GetBinaryMasterAttributes() 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' + << "Digital Flag : " << digital << '\n' + << "Dbit Offset : " << dbitoffset << '\n' + << "Dbit Bitset : " << dbitlist << '\n' + << GetBinaryFrameHeaderFormat(); + return oss.str(); + }; +}; \ No newline at end of file From ea2e7839d03dd6b0fe97b03c88b56bb7e40256d1 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Fri, 31 Jul 2020 13:59:06 +0200 Subject: [PATCH 12/26] binary master attributes done, hdf5 WIP --- slsReceiverSoftware/src/BinaryFile.cpp | 13 +-- slsReceiverSoftware/src/BinaryFile.h | 3 - slsReceiverSoftware/src/HDF5File.cpp | 7 +- slsReceiverSoftware/src/HDF5File.h | 4 +- slsReceiverSoftware/src/MasterAttributes.h | 114 ++++++++++++--------- 5 files changed, 75 insertions(+), 66 deletions(-) diff --git a/slsReceiverSoftware/src/BinaryFile.cpp b/slsReceiverSoftware/src/BinaryFile.cpp index 8740db18f..6ed3946e9 100644 --- a/slsReceiverSoftware/src/BinaryFile.cpp +++ b/slsReceiverSoftware/src/BinaryFile.cpp @@ -166,17 +166,8 @@ void BinaryFile::CreateMasterFile(bool masterFileWriteEnable, "(with overwrite enable) " + masterFileName); } - // create master file data - std::string strAttributes = attr->GetBinaryMasterAttributes(); - char message[maxMasterFileSize]; - memset(message, 0, maxMasterFileSize); - sls::strcpy_safe(message, strAttributes.c_str()); - // write and close file - if (fwrite((void *)message, 1, strlen(message), masterfd) != - strlen(message)) { - throw sls::RuntimeError( - "Master binary file incorrect number of bytes written to file"); - } + + attr->WriteMasterBinaryAttributes(masterfd); if (masterfd) fclose(masterfd); masterfd = nullptr; diff --git a/slsReceiverSoftware/src/BinaryFile.h b/slsReceiverSoftware/src/BinaryFile.h index 8f0087fa5..d429bd705 100644 --- a/slsReceiverSoftware/src/BinaryFile.h +++ b/slsReceiverSoftware/src/BinaryFile.h @@ -55,7 +55,4 @@ class BinaryFile : private virtual slsDetectorDefs, public File { static FILE *masterfd; uint32_t numFramesInFile = 0; uint64_t numActualPacketsInFile = 0; - // Make sure this is known at compile time - // TODO! Later away from stack allocation of message - static constexpr size_t maxMasterFileSize = 2000; }; \ No newline at end of file diff --git a/slsReceiverSoftware/src/HDF5File.cpp b/slsReceiverSoftware/src/HDF5File.cpp index 436ef4e70..342f74b22 100644 --- a/slsReceiverSoftware/src/HDF5File.cpp +++ b/slsReceiverSoftware/src/HDF5File.cpp @@ -5,6 +5,7 @@ ***********************************************/ #include "HDF5File.h" #include "Fifo.h" +#include "MasterAttributes.h" #include "receiver_defs.h" #include @@ -152,7 +153,7 @@ void HDF5File::WriteToFile(char *buffer, int bufferSize, } void HDF5File::CreateMasterFile(bool masterFileWriteEnable, - masterAttributes &masterFileAttributes) { + MasterAttributes &attr) { // beginning of every acquisition numFramesInFile = 0; @@ -161,7 +162,7 @@ void HDF5File::CreateMasterFile(bool masterFileWriteEnable, if (masterFileWriteEnable && master) { virtualfd = 0; - CreateMasterDataFile(masterFileAttributes); + CreateMasterDataFile(attr); } } @@ -458,7 +459,7 @@ void HDF5File::CreateDataFile() { } } -void HDF5File::CreateMasterDataFile(masterAttributes &masterFileAttributes) { +void HDF5File::CreateMasterDataFile(MasterAttributes &attr) { std::ostringstream os; os << *filePath << "/" << *fileNamePrefix << "_master" diff --git a/slsReceiverSoftware/src/HDF5File.h b/slsReceiverSoftware/src/HDF5File.h index 782c8dea9..dfac6013d 100644 --- a/slsReceiverSoftware/src/HDF5File.h +++ b/slsReceiverSoftware/src/HDF5File.h @@ -51,7 +51,7 @@ class HDF5File : private virtual slsDetectorDefs, public File { void WriteToFile(char *buffer, int bufferSize, uint64_t currentFrameNumber, uint32_t numPacketsCaught); void CreateMasterFile(bool masterFileWriteEnable, - masterAttributes &masterFileAttributes); + MasterAttributes &attr) override; void EndofAcquisition(bool anyPacketsCaught, uint64_t numImagesCaught); private: @@ -61,7 +61,7 @@ class HDF5File : private virtual slsDetectorDefs, public File { sls_receiver_header *rheader); void ExtendDataset(); void CreateDataFile(); - void CreateMasterDataFile(masterAttributes &masterFileAttributes); + void CreateMasterDataFile(MasterAttributes &attr); void CreateVirtualDataFile(uint32_t maxFramesPerFile, uint64_t numf); void LinkVirtualInMaster(std::string fname, std::string dsetname); hid_t GetDataTypeinC(DataType dtype); diff --git a/slsReceiverSoftware/src/MasterAttributes.h b/slsReceiverSoftware/src/MasterAttributes.h index 976d2e4f1..1ab114665 100644 --- a/slsReceiverSoftware/src/MasterAttributes.h +++ b/slsReceiverSoftware/src/MasterAttributes.h @@ -3,6 +3,14 @@ #include "ToString.h" #include "logger.h" #include "sls_detector_defs.h" + +#ifdef HDF5C +#include "H5Cpp.h" +#ifndef H5_NO_NAMESPACE +using namespace H5; +#endif +#endif + #include using ns = std::chrono::nanoseconds; @@ -11,7 +19,6 @@ using ns = std::chrono::nanoseconds; #define BINARY_WRITER_VERSION (6.1) // 1 decimal places class MasterAttributes { - public: slsDetectorDefs::detectorType detType{slsDetectorDefs::GENERIC}; uint32_t imageSize{0}; @@ -42,7 +49,12 @@ class MasterAttributes { MasterAttributes(){}; virtual ~MasterAttributes(){}; - virtual std::string GetBinaryMasterAttributes() { + virtual void WriteMasterBinaryAttributes(FILE *fd) { + LOG(logERROR) << "WriteMasterBinaryAttributes should have been called " + "by a child class"; + } + + std::string GetBinaryMasterAttributes() { time_t t = time(nullptr); std::ostringstream oss; oss << "Version : " << std::setprecision(2) @@ -56,39 +68,47 @@ class MasterAttributes { return oss.str(); }; - std::string GetBinaryFrameHeaderFormat() { - return std::string("\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"); + void WriteBinaryAttributes(FILE *fd, std::string message) { + message += std::string("\n#Frame Header\n" + "Frame Number : 8 bytes\n" + "SubFrame Number/ExpLength : 4 bytes\n" + "Packet Number : 4 bytes\n" + "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"); + + if (fwrite((void *)message.c_str(), 1, message.length(), fd) != + message.length()) { + throw sls::RuntimeError( + "Master binary file incorrect number of bytes written to file"); + } }; - // hdf5 +#ifdef HDF5C + virtual void Write +#endif }; class GotthardMasterAttributes : public MasterAttributes { public: GotthardMasterAttributes(){}; - std::string GetBinaryMasterAttributes() override { + void WriteMasterBinaryAttributes(FILE *fd) override { std::ostringstream oss; oss << MasterAttributes::GetBinaryMasterAttributes() << "Exptime : " << sls::ToString(exptime) << '\n' << "Period : " << sls::ToString(period) << '\n' - << "Roi (xmin, xmax) : " << sls::ToString(roi) << '\n' - << GetBinaryFrameHeaderFormat(); - return oss.str(); + << "Roi (xmin, xmax) : " << sls::ToString(roi) << '\n'; + std::string message = oss.str(); + MasterAttributes::WriteBinaryAttributes(fd, message); }; }; @@ -96,13 +116,13 @@ class JungfrauMasterAttributes : public MasterAttributes { public: JungfrauMasterAttributes(){}; - std::string GetBinaryMasterAttributes() override { + void WriteMasterBinaryAttributes(FILE *fd) override { std::ostringstream oss; oss << MasterAttributes::GetBinaryMasterAttributes() << "Exptime : " << sls::ToString(exptime) << '\n' - << "Period : " << sls::ToString(period) << '\n' - << GetBinaryFrameHeaderFormat(); - return oss.str(); + << "Period : " << sls::ToString(period) << '\n'; + std::string message = oss.str(); + MasterAttributes::WriteBinaryAttributes(fd, message); }; }; @@ -110,7 +130,7 @@ class EigerMasterAttributes : public MasterAttributes { public: EigerMasterAttributes(){}; - std::string GetBinaryMasterAttributes() override { + void WriteMasterBinaryAttributes(FILE *fd) override { std::ostringstream oss; oss << MasterAttributes::GetBinaryMasterAttributes() << "Dynamic Range : " << dynamicRange << '\n' @@ -121,9 +141,9 @@ class EigerMasterAttributes : public MasterAttributes { << '\n' << "SubPeriod : " << sls::ToString(subPeriod) << '\n' - << "Quad : " << quad << '\n' - << GetBinaryFrameHeaderFormat(); - return oss.str(); + << "Quad : " << quad << '\n'; + std::string message = oss.str(); + MasterAttributes::WriteBinaryAttributes(fd, message); }; }; @@ -131,7 +151,7 @@ class Mythen3MasterAttributes : public MasterAttributes { public: Mythen3MasterAttributes(){}; - std::string GetBinaryMasterAttributes() override { + void WriteMasterBinaryAttributes(FILE *fd) override { std::ostringstream oss; oss << MasterAttributes::GetBinaryMasterAttributes() << "Dynamic Range : " << dynamicRange << '\n' @@ -149,9 +169,9 @@ class Mythen3MasterAttributes : public MasterAttributes { << '\n' << "GateDelay3 : " << sls::ToString(gateDelay3) << '\n' - << "Gates : " << gates << '\n' - << GetBinaryFrameHeaderFormat(); - return oss.str(); + << "Gates : " << gates << '\n'; + std::string message = oss.str(); + MasterAttributes::WriteBinaryAttributes(fd, message); }; }; @@ -159,13 +179,13 @@ class Gotthard2MasterAttributes : public MasterAttributes { public: Gotthard2MasterAttributes(){}; - std::string GetBinaryMasterAttributes() override { + void WriteMasterBinaryAttributes(FILE *fd) override { std::ostringstream oss; oss << MasterAttributes::GetBinaryMasterAttributes() << "Exptime : " << sls::ToString(exptime) << '\n' - << "Period : " << sls::ToString(period) << '\n' - << GetBinaryFrameHeaderFormat(); - return oss.str(); + << "Period : " << sls::ToString(period) << '\n'; + std::string message = oss.str(); + MasterAttributes::WriteBinaryAttributes(fd, message); }; }; @@ -173,16 +193,16 @@ class MoenchMasterAttributes : public MasterAttributes { public: MoenchMasterAttributes(){}; - std::string GetBinaryMasterAttributes() override { + void WriteMasterBinaryAttributes(FILE *fd) override { std::ostringstream oss; oss << MasterAttributes::GetBinaryMasterAttributes() << "Exptime : " << sls::ToString(exptime) << '\n' << "Period : " << sls::ToString(period) << '\n' << "Ten Giga : " << tenGiga << '\n' << "ADC Mask : " << sls::ToStringHex(adcmask) - << '\n' - << GetBinaryFrameHeaderFormat(); - return oss.str(); + << '\n'; + std::string message = oss.str(); + MasterAttributes::WriteBinaryAttributes(fd, message); }; }; @@ -190,7 +210,7 @@ class CtbMasterAttributes : public MasterAttributes { public: CtbMasterAttributes(){}; - std::string GetBinaryMasterAttributes() override { + void WriteMasterBinaryAttributes(FILE *fd) override { std::ostringstream oss; oss << MasterAttributes::GetBinaryMasterAttributes() << "Exptime : " << sls::ToString(exptime) << '\n' @@ -201,8 +221,8 @@ class CtbMasterAttributes : public MasterAttributes { << "Analog Flag : " << analog << '\n' << "Digital Flag : " << digital << '\n' << "Dbit Offset : " << dbitoffset << '\n' - << "Dbit Bitset : " << dbitlist << '\n' - << GetBinaryFrameHeaderFormat(); - return oss.str(); + << "Dbit Bitset : " << dbitlist << '\n'; + std::string message = oss.str(); + MasterAttributes::WriteBinaryAttributes(fd, message); }; }; \ No newline at end of file From 1211d024281cbcb15951f17f6476e8c4f63ddb12 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Fri, 31 Jul 2020 16:19:34 +0200 Subject: [PATCH 13/26] hdf5 dependant master attributes --- slsReceiverSoftware/src/HDF5File.cpp | 320 +-------------------- slsReceiverSoftware/src/HDF5File.h | 4 +- slsReceiverSoftware/src/MasterAttributes.h | 306 +++++++++++++++++++- slsReceiverSoftware/src/receiver_defs.h | 2 +- 4 files changed, 312 insertions(+), 320 deletions(-) diff --git a/slsReceiverSoftware/src/HDF5File.cpp b/slsReceiverSoftware/src/HDF5File.cpp index 342f74b22..24157ee8a 100644 --- a/slsReceiverSoftware/src/HDF5File.cpp +++ b/slsReceiverSoftware/src/HDF5File.cpp @@ -153,7 +153,7 @@ void HDF5File::WriteToFile(char *buffer, int bufferSize, } void HDF5File::CreateMasterFile(bool masterFileWriteEnable, - MasterAttributes &attr) { + MasterAttributes *attr) { // beginning of every acquisition numFramesInFile = 0; @@ -459,7 +459,7 @@ void HDF5File::CreateDataFile() { } } -void HDF5File::CreateMasterDataFile(MasterAttributes &attr) { +void HDF5File::CreateMasterDataFile(MasterAttributes *attr) { std::ostringstream os; os << *filePath << "/" << *fileNamePrefix << "_master" @@ -469,7 +469,6 @@ void HDF5File::CreateMasterDataFile(MasterAttributes &attr) { if (!(*silentMode)) { LOG(logINFO) << "Master File: " << masterFileName; } - masterFileAttributes.version = HDF5_WRITER_VERSION; std::lock_guard lock(HDF5File::hdf5Lib); @@ -486,15 +485,6 @@ void HDF5File::CreateMasterDataFile(MasterAttributes &attr) { masterfd = new H5File(masterFileName.c_str(), H5F_ACC_TRUNC, FileCreatPropList::DEFAULT, flist); - // create attributes - // version - { - double dValue = masterFileAttributes.version; - DataSpace dataspace = DataSpace(H5S_SCALAR); - Attribute attribute = masterfd->createAttribute( - "version", PredType::NATIVE_DOUBLE, dataspace); - attribute.write(PredType::NATIVE_DOUBLE, &dValue); - } // Create a group in the file Group group1(masterfd->createGroup("entry")); Group group2(group1.createGroup("data")); @@ -503,309 +493,7 @@ void HDF5File::CreateMasterDataFile(MasterAttributes &attr) { Group group5(group3.createGroup("detector")); Group group6(group1.createGroup("sample")); - // Dynamic Range - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group5.createDataSet( - "dynamic range", PredType::NATIVE_INT, dataspace); - dataset.write(&(masterFileAttributes.dynamicRange), - PredType::NATIVE_INT); - DataSpace dataspaceAttr = DataSpace(H5S_SCALAR); - StrType strdatatype(PredType::C_S1, 256); - Attribute attribute = - dataset.createAttribute("unit", strdatatype, dataspaceAttr); - attribute.write(strdatatype, std::string("bits")); - } - - // Ten Giga - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - int iValue = masterFileAttributes.tenGiga; - DataSet dataset = group5.createDataSet( - "ten giga enable", PredType::NATIVE_INT, dataspace); - dataset.write(&iValue, PredType::NATIVE_INT); - } - - // Image Size - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group5.createDataSet( - "image size", PredType::NATIVE_INT, dataspace); - dataset.write(&(masterFileAttributes.imageSize), - PredType::NATIVE_INT); - DataSpace dataspaceAttr = DataSpace(H5S_SCALAR); - StrType strdatatype(PredType::C_S1, 256); - Attribute attribute = - dataset.createAttribute("unit", strdatatype, dataspaceAttr); - attribute.write(strdatatype, std::string("bytes")); - } - - // x - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group5.createDataSet( - "number of pixels in x axis", PredType::NATIVE_INT, dataspace); - dataset.write(&(masterFileAttributes.nPixelsX), - PredType::NATIVE_INT); - } - - // y - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group5.createDataSet( - "number of pixels in y axis", PredType::NATIVE_INT, dataspace); - dataset.write(&(masterFileAttributes.nPixelsY), - PredType::NATIVE_INT); - } - - // Maximum frames per file - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group5.createDataSet( - "maximum frames per file", PredType::NATIVE_INT, dataspace); - dataset.write(&(masterFileAttributes.maxFramesPerFile), - PredType::NATIVE_INT); - } - - // Total Frames - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group5.createDataSet( - "total frames", PredType::STD_U64LE, dataspace); - dataset.write(&(masterFileAttributes.totalFrames), - PredType::STD_U64LE); - } - - // Exptime - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group5.createDataSet( - "exposure time", PredType::STD_U64LE, dataspace); - dataset.write(&(masterFileAttributes.exptimeNs), - PredType::STD_U64LE); - DataSpace dataspaceAttr = DataSpace(H5S_SCALAR); - StrType strdatatype(PredType::C_S1, 256); - Attribute attribute = - dataset.createAttribute("unit", strdatatype, dataspaceAttr); - attribute.write(strdatatype, std::string("ns")); - } - - // SubExptime - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group5.createDataSet( - "sub exposure time", PredType::STD_U64LE, dataspace); - dataset.write(&(masterFileAttributes.subExptimeNs), - PredType::STD_U64LE); - DataSpace dataspaceAttr = DataSpace(H5S_SCALAR); - StrType strdatatype(PredType::C_S1, 256); - Attribute attribute = - dataset.createAttribute("unit", strdatatype, dataspaceAttr); - attribute.write(strdatatype, std::string("ns")); - } - - // SubPeriod - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group5.createDataSet( - "sub period", PredType::STD_U64LE, dataspace); - dataset.write(&(masterFileAttributes.subPeriodNs), - PredType::STD_U64LE); - DataSpace dataspaceAttr = DataSpace(H5S_SCALAR); - StrType strdatatype(PredType::C_S1, 256); - Attribute attribute = - dataset.createAttribute("unit", strdatatype, dataspaceAttr); - attribute.write(strdatatype, std::string("ns")); - } - - // Period - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group5.createDataSet( - "acquisition period", PredType::STD_U64LE, dataspace); - dataset.write(&(masterFileAttributes.periodNs), - PredType::STD_U64LE); - DataSpace dataspaceAttr = DataSpace(H5S_SCALAR); - StrType strdatatype(PredType::C_S1, 256); - Attribute attribute = - dataset.createAttribute("unit", strdatatype, dataspaceAttr); - attribute.write(strdatatype, std::string("ns")); - } - - // Quad Enable - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group5.createDataSet( - "quad enable", PredType::NATIVE_INT, dataspace); - dataset.write(&(masterFileAttributes.quadEnable), - PredType::NATIVE_INT); - } - - // Analog Flag - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group5.createDataSet( - "analog flag", PredType::NATIVE_INT, dataspace); - dataset.write(&(masterFileAttributes.analogFlag), - PredType::NATIVE_INT); - } - - // Digital Flag - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group5.createDataSet( - "digital flag", PredType::NATIVE_INT, dataspace); - dataset.write(&(masterFileAttributes.digitalFlag), - PredType::NATIVE_INT); - } - - // ADC Mask - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group5.createDataSet( - "adc mask", PredType::NATIVE_INT, dataspace); - dataset.write(&(masterFileAttributes.adcmask), - PredType::NATIVE_INT); - } - - // Dbit Offset - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group5.createDataSet( - "dbit offset", PredType::NATIVE_INT, dataspace); - dataset.write(&(masterFileAttributes.dbitoffset), - PredType::NATIVE_INT); - } - - // Dbit List - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group5.createDataSet( - "dbit bitset list", PredType::STD_U64LE, dataspace); - dataset.write(&(masterFileAttributes.dbitlist), - PredType::STD_U64LE); - } - - // Roi xmin - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group5.createDataSet( - "roi xmin", PredType::NATIVE_INT, dataspace); - dataset.write(&(masterFileAttributes.roiXmin), - PredType::NATIVE_INT); - } - - // Roi xmax - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group5.createDataSet( - "roi xmax", PredType::NATIVE_INT, dataspace); - dataset.write(&(masterFileAttributes.roiXmax), - PredType::NATIVE_INT); - } - - // Exptime1 - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group5.createDataSet( - "exposure time1", PredType::STD_U64LE, dataspace); - dataset.write(&(masterFileAttributes.exptime1Ns), - PredType::STD_U64LE); - DataSpace dataspaceAttr = DataSpace(H5S_SCALAR); - StrType strdatatype(PredType::C_S1, 256); - Attribute attribute = - dataset.createAttribute("unit", strdatatype, dataspaceAttr); - attribute.write(strdatatype, std::string("ns")); - } - - // Exptime2 - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group5.createDataSet( - "exposure time2", PredType::STD_U64LE, dataspace); - dataset.write(&(masterFileAttributes.exptime2Ns), - PredType::STD_U64LE); - DataSpace dataspaceAttr = DataSpace(H5S_SCALAR); - StrType strdatatype(PredType::C_S1, 256); - Attribute attribute = - dataset.createAttribute("unit", strdatatype, dataspaceAttr); - attribute.write(strdatatype, std::string("ns")); - } - - // Exptime3 - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group5.createDataSet( - "exposure time3", PredType::STD_U64LE, dataspace); - dataset.write(&(masterFileAttributes.exptime3Ns), - PredType::STD_U64LE); - DataSpace dataspaceAttr = DataSpace(H5S_SCALAR); - StrType strdatatype(PredType::C_S1, 256); - Attribute attribute = - dataset.createAttribute("unit", strdatatype, dataspaceAttr); - attribute.write(strdatatype, std::string("ns")); - } - - // GateDelay1 - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group5.createDataSet( - "gate delay1", PredType::STD_U64LE, dataspace); - dataset.write(&(masterFileAttributes.gateDelay1Ns), - PredType::STD_U64LE); - DataSpace dataspaceAttr = DataSpace(H5S_SCALAR); - StrType strdatatype(PredType::C_S1, 256); - Attribute attribute = - dataset.createAttribute("unit", strdatatype, dataspaceAttr); - attribute.write(strdatatype, std::string("ns")); - } - - // GateDelay2 - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group5.createDataSet( - "gate delay2", PredType::STD_U64LE, dataspace); - dataset.write(&(masterFileAttributes.gateDelay2Ns), - PredType::STD_U64LE); - DataSpace dataspaceAttr = DataSpace(H5S_SCALAR); - StrType strdatatype(PredType::C_S1, 256); - Attribute attribute = - dataset.createAttribute("unit", strdatatype, dataspaceAttr); - attribute.write(strdatatype, std::string("ns")); - } - - // GateDelay3 - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group5.createDataSet( - "gate delay3", PredType::STD_U64LE, dataspace); - dataset.write(&(masterFileAttributes.gateDelay3Ns), - PredType::STD_U64LE); - DataSpace dataspaceAttr = DataSpace(H5S_SCALAR); - StrType strdatatype(PredType::C_S1, 256); - Attribute attribute = - dataset.createAttribute("unit", strdatatype, dataspaceAttr); - attribute.write(strdatatype, std::string("ns")); - } - - // Dbit Offset - { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = - group5.createDataSet("gates", PredType::NATIVE_INT, dataspace); - dataset.write(&(masterFileAttributes.gates), PredType::NATIVE_INT); - } - - // Timestamp - { - time_t t = time(nullptr); - StrType strdatatype(PredType::C_S1, 256); - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = - group5.createDataSet("timestamp", strdatatype, dataspace); - dataset.write(std::string(ctime(&t)), strdatatype); - } - + attr->WriteMasterHDF5Attributes(masterfd, &group5); masterfd->close(); } catch (const Exception &error) { @@ -893,7 +581,7 @@ void HDF5File::CreateVirtualDataFile(uint32_t maxFramesPerFile, uint64_t numf) { if (H5Pset_fill_value(dcpl, GetDataTypeinC(datatype), &fill_value) < 0) throw sls::RuntimeError( "Could not create fill value in virtual file " + vname); - hid_t dcpl_para[parameterNames.size()]; + std::vector dcpl_para(parameterNames.size()); for (unsigned int i = 0; i < parameterNames.size(); ++i) { dcpl_para[i] = H5Pcreate(H5P_DATASET_CREATE); if (dcpl_para[i] < 0) diff --git a/slsReceiverSoftware/src/HDF5File.h b/slsReceiverSoftware/src/HDF5File.h index dfac6013d..110f50810 100644 --- a/slsReceiverSoftware/src/HDF5File.h +++ b/slsReceiverSoftware/src/HDF5File.h @@ -51,7 +51,7 @@ class HDF5File : private virtual slsDetectorDefs, public File { void WriteToFile(char *buffer, int bufferSize, uint64_t currentFrameNumber, uint32_t numPacketsCaught); void CreateMasterFile(bool masterFileWriteEnable, - MasterAttributes &attr) override; + MasterAttributes *attr) override; void EndofAcquisition(bool anyPacketsCaught, uint64_t numImagesCaught); private: @@ -61,7 +61,7 @@ class HDF5File : private virtual slsDetectorDefs, public File { sls_receiver_header *rheader); void ExtendDataset(); void CreateDataFile(); - void CreateMasterDataFile(MasterAttributes &attr); + void CreateMasterDataFile(MasterAttributes *attr); void CreateVirtualDataFile(uint32_t maxFramesPerFile, uint64_t numf); void LinkVirtualInMaster(std::string fname, std::string dsetname); hid_t GetDataTypeinC(DataType dtype); diff --git a/slsReceiverSoftware/src/MasterAttributes.h b/slsReceiverSoftware/src/MasterAttributes.h index 1ab114665..0fc520e8d 100644 --- a/slsReceiverSoftware/src/MasterAttributes.h +++ b/slsReceiverSoftware/src/MasterAttributes.h @@ -93,9 +93,118 @@ class MasterAttributes { }; #ifdef HDF5C - virtual void Write + virtual void WriteMasterHDF5Attributes(H5File *fd, Group *group) { + LOG(logERROR) << "WriteMasterHdf5Attributes should have been called " + "by a child class"; + }; + + void WriteHDF5Attributes(H5File *fd, Group *group){ + // 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); + dataset.write(std::string(ctime(&t)), strdatatype); + } + // detector type + { + DataSpace dataspace = DataSpace(H5S_SCALAR); + StrType strdatatype(PredType::C_S1, 256); + DataSet dataset = + group->createDataSet("detector type", strdatatype, dataspace); + dataset.write(sls::ToString(detType), 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); + attribute.write(strdatatype, std::string("bytes")); + } + //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); + } + // Total Frames + { + DataSpace dataspace = DataSpace(H5S_SCALAR); + DataSet dataset = group->createDataSet( + "total frames", PredType::STD_U64LE, dataspace); + dataset.write(&totalFrames, PredType::STD_U64LE); + } + }; + + 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); + dataset.write(sls::ToString(exptime), 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); + dataset.write(sls::ToString(period), 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); + attribute.write(strdatatype, std::string("bits")); + }; + + 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); + }; #endif }; +// clang-format on class GotthardMasterAttributes : public MasterAttributes { public: @@ -110,6 +219,28 @@ class GotthardMasterAttributes : public MasterAttributes { std::string message = oss.str(); MasterAttributes::WriteBinaryAttributes(fd, message); }; + +#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); + } + }; +#endif }; class JungfrauMasterAttributes : public MasterAttributes { @@ -124,6 +255,14 @@ class JungfrauMasterAttributes : public MasterAttributes { std::string message = oss.str(); MasterAttributes::WriteBinaryAttributes(fd, message); }; + +#ifdef HDF5C + void WriteMasterHDF5Attributes(H5File *fd, Group *group) override { + MasterAttributes::WriteHDF5Attributes(fd, group); + MasterAttributes::WriteHDF5Exptime(fd, group); + MasterAttributes::WriteHDF5Period(fd, group); + }; +#endif }; class EigerMasterAttributes : public MasterAttributes { @@ -145,6 +284,39 @@ class EigerMasterAttributes : public MasterAttributes { std::string message = oss.str(); MasterAttributes::WriteBinaryAttributes(fd, message); }; + +#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); + // SubExptime + { + DataSpace dataspace = DataSpace(H5S_SCALAR); + StrType strdatatype(PredType::C_S1, 256); + DataSet dataset = group->createDataSet("sub exposure time", + strdatatype, dataspace); + dataset.write(sls::ToString(subExptime), strdatatype); + } + // SubPeriod + { + DataSpace dataspace = DataSpace(H5S_SCALAR); + StrType strdatatype(PredType::C_S1, 256); + DataSet dataset = + group->createDataSet("sub period", strdatatype, dataspace); + dataset.write(sls::ToString(subPeriod), strdatatype); + } + // Quad + { + DataSpace dataspace = DataSpace(H5S_SCALAR); + DataSet dataset = + group->createDataSet("quad", PredType::NATIVE_INT, dataspace); + dataset.write(&quad, PredType::NATIVE_INT); + } + }; +#endif }; class Mythen3MasterAttributes : public MasterAttributes { @@ -173,6 +345,70 @@ class Mythen3MasterAttributes : public MasterAttributes { std::string message = oss.str(); MasterAttributes::WriteBinaryAttributes(fd, message); }; + +#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); + // Exptime1 + { + DataSpace dataspace = DataSpace(H5S_SCALAR); + StrType strdatatype(PredType::C_S1, 256); + DataSet dataset = + group->createDataSet("exposure time1", strdatatype, dataspace); + dataset.write(sls::ToString(exptime1), strdatatype); + } + // Exptime2 + { + DataSpace dataspace = DataSpace(H5S_SCALAR); + StrType strdatatype(PredType::C_S1, 256); + DataSet dataset = + group->createDataSet("exposure time2", strdatatype, dataspace); + dataset.write(sls::ToString(exptime2), strdatatype); + } + // Exptime3 + { + DataSpace dataspace = DataSpace(H5S_SCALAR); + StrType strdatatype(PredType::C_S1, 256); + DataSet dataset = + group->createDataSet("exposure time3", strdatatype, dataspace); + dataset.write(sls::ToString(exptime3), strdatatype); + } + // GateDelay1 + { + DataSpace dataspace = DataSpace(H5S_SCALAR); + StrType strdatatype(PredType::C_S1, 256); + DataSet dataset = + group->createDataSet("gate delay1", strdatatype, dataspace); + dataset.write(sls::ToString(gateDelay1), strdatatype); + } + // GateDelay2 + { + DataSpace dataspace = DataSpace(H5S_SCALAR); + StrType strdatatype(PredType::C_S1, 256); + DataSet dataset = + group->createDataSet("gate delay2", strdatatype, dataspace); + dataset.write(sls::ToString(gateDelay2), strdatatype); + } + // GateDelay3 + { + DataSpace dataspace = DataSpace(H5S_SCALAR); + StrType strdatatype(PredType::C_S1, 256); + DataSet dataset = + group->createDataSet("gate delay3", strdatatype, dataspace); + dataset.write(sls::ToString(gateDelay3), strdatatype); + } + // Gates + { + DataSpace dataspace = DataSpace(H5S_SCALAR); + DataSet dataset = + group->createDataSet("gates", PredType::STD_U32LE, dataspace); + dataset.write(&gates, PredType::STD_U64LE); + } + }; +#endif }; class Gotthard2MasterAttributes : public MasterAttributes { @@ -187,6 +423,14 @@ class Gotthard2MasterAttributes : public MasterAttributes { std::string message = oss.str(); MasterAttributes::WriteBinaryAttributes(fd, message); }; + +#ifdef HDF5C + void WriteMasterHDF5Attributes(H5File *fd, Group *group) override { + MasterAttributes::WriteHDF5Attributes(fd, group); + MasterAttributes::WriteHDF5Exptime(fd, group); + MasterAttributes::WriteHDF5Period(fd, group); + }; +#endif }; class MoenchMasterAttributes : public MasterAttributes { @@ -204,6 +448,22 @@ class MoenchMasterAttributes : public MasterAttributes { std::string message = oss.str(); MasterAttributes::WriteBinaryAttributes(fd, message); }; + +#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); + } + }; +#endif }; class CtbMasterAttributes : public MasterAttributes { @@ -225,4 +485,48 @@ class CtbMasterAttributes : public MasterAttributes { std::string message = oss.str(); MasterAttributes::WriteBinaryAttributes(fd, message); }; + +#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 Flag + { + DataSpace dataspace = DataSpace(H5S_SCALAR); + DataSet dataset = group->createDataSet( + "analog flag", PredType::NATIVE_INT, dataspace); + dataset.write(&analog, 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); + } + // 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 }; \ No newline at end of file diff --git a/slsReceiverSoftware/src/receiver_defs.h b/slsReceiverSoftware/src/receiver_defs.h index ba7ca56fb..e22fb6380 100755 --- a/slsReceiverSoftware/src/receiver_defs.h +++ b/slsReceiverSoftware/src/receiver_defs.h @@ -86,4 +86,4 @@ struct masterAttributes { uint64_t gateDelay3Ns; uint32_t gates; }; -*/ \ No newline at end of file +*/ From 5c4d355d57b7557a927c057ec2d472b9cd97f618 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Fri, 31 Jul 2020 17:18:15 +0200 Subject: [PATCH 14/26] minor --- slsReceiverSoftware/src/receiver_defs.h | 35 ------------------------- 1 file changed, 35 deletions(-) diff --git a/slsReceiverSoftware/src/receiver_defs.h b/slsReceiverSoftware/src/receiver_defs.h index e22fb6380..635bbedcf 100755 --- a/slsReceiverSoftware/src/receiver_defs.h +++ b/slsReceiverSoftware/src/receiver_defs.h @@ -52,38 +52,3 @@ #define PROCESSOR_PRIORITY (70) #define STREAMER_PRIORITY (10) #define TCP_PRIORITY (10) - -/* -#define HDF5_WRITER_VERSION (6.1) // 1 decimal places -#define BINARY_WRITER_VERSION (6.1) // 1 decimal places -struct masterAttributes { - double version; - uint32_t detectorType; - uint32_t dynamicRange; - uint32_t tenGiga; - uint32_t imageSize; - uint32_t nPixelsX; - uint32_t nPixelsY; - uint32_t maxFramesPerFile; - uint64_t totalFrames; - uint64_t exptimeNs; - uint64_t subExptimeNs; - uint64_t subPeriodNs; - uint64_t periodNs; - uint32_t quadEnable; - uint32_t analogFlag; - uint32_t digitalFlag; - uint32_t adcmask; - uint32_t dbitoffset; - uint64_t dbitlist; - uint32_t roiXmin; - uint32_t roiXmax; - uint64_t exptime1Ns; - uint64_t exptime2Ns; - uint64_t exptime3Ns; - uint64_t gateDelay1Ns; - uint64_t gateDelay2Ns; - uint64_t gateDelay3Ns; - uint32_t gates; -}; -*/ From 874092a9d07d9a076b636093f61986c079154c2a Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Fri, 31 Jul 2020 17:26:53 +0200 Subject: [PATCH 15/26] gui sub frame index now shows --- slsDetectorGui/src/qDrawPlot.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slsDetectorGui/src/qDrawPlot.cpp b/slsDetectorGui/src/qDrawPlot.cpp index 68234cc6e..7a553abe6 100644 --- a/slsDetectorGui/src/qDrawPlot.cpp +++ b/slsDetectorGui/src/qDrawPlot.cpp @@ -813,7 +813,7 @@ void qDrawPlot::GetData(detectorData *data, uint64_t frameIndex, plotTitlePrefix + QString(data->fileName.c_str()).section('/', -1); indexTitle = QString("%1").arg(frameIndex); if ((int)subFrameIndex != -1) { - indexTitle = QString("%1 %2").arg(frameIndex, subFrameIndex); + indexTitle = QString("%1 %2").arg(frameIndex).arg(subFrameIndex); } completeImage = data->completeImage; From 09fa8a3ba585ae7e2a34729113c1a5cf53f78c98 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Fri, 31 Jul 2020 17:37:04 +0200 Subject: [PATCH 16/26] timing mode into receiver master file --- slsReceiverSoftware/src/MasterAttributes.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/slsReceiverSoftware/src/MasterAttributes.h b/slsReceiverSoftware/src/MasterAttributes.h index 0fc520e8d..4d5b7cc3f 100644 --- a/slsReceiverSoftware/src/MasterAttributes.h +++ b/slsReceiverSoftware/src/MasterAttributes.h @@ -21,6 +21,7 @@ using ns = std::chrono::nanoseconds; class MasterAttributes { public: slsDetectorDefs::detectorType detType{slsDetectorDefs::GENERIC}; + slsDetectorDefs::timingMode timingMode{slsDetectorDefs::AUTO_TIMING}; uint32_t imageSize{0}; slsDetectorDefs::xy nPixels{}; uint32_t maxFramesPerFile{0}; @@ -61,6 +62,8 @@ class MasterAttributes { << 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' @@ -125,6 +128,14 @@ class MasterAttributes { group->createDataSet("detector type", strdatatype, dataspace); dataset.write(sls::ToString(detType), strdatatype); } + // timing mode + { + DataSpace dataspace = DataSpace(H5S_SCALAR); + StrType strdatatype(PredType::C_S1, 256); + DataSet dataset = + group->createDataSet("timing mode", strdatatype, dataspace); + dataset.write(sls::ToString(timingMode), strdatatype); + } // Image Size { DataSpace dataspace = DataSpace(H5S_SCALAR); From bea4ba131afa13b0c247dbdebdd97924ab8fbd05 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Fri, 31 Jul 2020 17:45:33 +0200 Subject: [PATCH 17/26] eiger rxr added threshold to master file --- slsReceiverSoftware/src/MasterAttributes.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/slsReceiverSoftware/src/MasterAttributes.h b/slsReceiverSoftware/src/MasterAttributes.h index 4d5b7cc3f..3a7f84b89 100644 --- a/slsReceiverSoftware/src/MasterAttributes.h +++ b/slsReceiverSoftware/src/MasterAttributes.h @@ -30,6 +30,7 @@ class MasterAttributes { ns period{0}; uint32_t dynamicRange{0}; uint32_t tenGiga{0}; + int threshold{0}; ns subExptime{0}; ns subPeriod{0}; uint32_t quad{0}; @@ -303,6 +304,18 @@ class EigerMasterAttributes : public MasterAttributes { MasterAttributes::WriteHDF5TenGiga(fd, group); MasterAttributes::WriteHDF5Exptime(fd, group); MasterAttributes::WriteHDF5Period(fd, group); + // threshold + { + DataSpace dataspace = DataSpace(H5S_SCALAR); + DataSet dataset = group->createDataSet( + "threshold", PredType::NATIVE_INT, dataspace); + dataset.write(&threshold, PredType::NATIVE_INT); + DataSpace dataspaceAttr = DataSpace(H5S_SCALAR); + StrType strdatatype(PredType::C_S1, 256); + Attribute attribute = + dataset.createAttribute("unit", strdatatype, dataspaceAttr); + attribute.write(strdatatype, std::string("eV")); + } // SubExptime { DataSpace dataspace = DataSpace(H5S_SCALAR); From 885b22eca8d1ac48bda13b226e335c37a7e4cd84 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Fri, 31 Jul 2020 18:38:27 +0200 Subject: [PATCH 18/26] ratecorrectiosn addded to master file --- slsDetectorSoftware/include/Detector.h | 1 + slsDetectorSoftware/src/Detector.cpp | 16 ++++++++++++++ slsDetectorSoftware/src/Module.cpp | 15 ++++++++++++++ slsDetectorSoftware/src/Module.h | 6 ++++-- slsReceiverSoftware/src/ClientInterface.cpp | 23 ++++++++++++++++++--- slsReceiverSoftware/src/ClientInterface.h | 1 + slsReceiverSoftware/src/Implementation.cpp | 7 +++++++ slsReceiverSoftware/src/Implementation.h | 3 +++ slsReceiverSoftware/src/MasterAttributes.h | 13 +++++++++++- slsSupportLib/include/sls_detector_funcs.h | 3 ++- 10 files changed, 81 insertions(+), 7 deletions(-) diff --git a/slsDetectorSoftware/include/Detector.h b/slsDetectorSoftware/include/Detector.h index 40d116e1d..2152a0135 100644 --- a/slsDetectorSoftware/include/Detector.h +++ b/slsDetectorSoftware/include/Detector.h @@ -1469,6 +1469,7 @@ class Detector { private: std::vector getPortNumbers(int start_port); + void updateRxRateCorrections(); }; } // namespace sls \ No newline at end of file diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index 10d7d7592..46aa5d925 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -771,6 +771,7 @@ Result Detector::getRxHostname(Positions pos) const { void Detector::setRxHostname(const std::string &receiver, Positions pos) { pimpl->Parallel(&Module::setReceiverHostname, pos, receiver); + updateRxRateCorrections(); } void Detector::setRxHostname(const std::vector &name) { @@ -788,6 +789,7 @@ void Detector::setRxHostname(const std::vector &name) { pimpl->Parallel(&Module::setReceiverHostname, {idet}, name[idet]); } } + updateRxRateCorrections(); } Result Detector::getRxPort(Positions pos) const { @@ -1109,6 +1111,20 @@ void Detector::setDefaultRateCorrection(Positions pos) { void Detector::setRateCorrection(ns dead_time, Positions pos) { pimpl->Parallel(&Module::setRateCorrection, pos, dead_time.count()); + updateRxRateCorrections(); +} + +void Detector::updateRxRateCorrections() { + // get tau from all modules and send to Rx index 0 + if (getUseReceiverFlag().squash(false)) { + // convert Result to std::vector + auto retval = getRateCorrection(); + std::vector t(retval.size()); + for (int i = 0; i < (int)retval.size(); ++i) { + t[i] = retval[i].count(); + } + pimpl->Parallel(&Module::sendReceiverRateCorrections, {0}, t); + } } Result Detector::getPartialReadout(Positions pos) const { diff --git a/slsDetectorSoftware/src/Module.cpp b/slsDetectorSoftware/src/Module.cpp index f44e34f48..e613a961d 100644 --- a/slsDetectorSoftware/src/Module.cpp +++ b/slsDetectorSoftware/src/Module.cpp @@ -1163,6 +1163,21 @@ void Module::setRateCorrection(int64_t t) { sendToDetector(F_SET_RATE_CORRECT, t, nullptr); } +void Module::sendReceiverRateCorrections(const std::vector &t) { + LOG(logDEBUG) << "Sending to detector [rate corrections: " << ToString(t) + << ']'; + auto receiver = ReceiverSocket(shm()->rxHostname, shm()->rxTCPPort); + receiver.Send(F_SET_RECEIVER_RATE_CORRECT); + // TODO: use overload for vector + int size = t.size(); + receiver.Send(size); + receiver.Send(t.data(), t.size() * sizeof(t[0])); + if (receiver.Receive() == FAIL) { + throw RuntimeError("Receiver " + std::to_string(moduleId) + + " returned error: " + receiver.readErrorMessage()); + } +} + int Module::getReadNLines() const { return sendToDetector(F_GET_READ_N_LINES); } diff --git a/slsDetectorSoftware/src/Module.h b/slsDetectorSoftware/src/Module.h index fecb590cd..d1c9cc93a 100644 --- a/slsDetectorSoftware/src/Module.h +++ b/slsDetectorSoftware/src/Module.h @@ -312,6 +312,7 @@ class Module : public virtual slsDetectorDefs { int64_t getRateCorrection() const; void setDefaultRateCorrection(); void setRateCorrection(int64_t t = 0); + void sendReceiverRateCorrections(const std::vector &t); int getReadNLines() const; void setReadNLines(const int value); bool getInterruptSubframe() const; @@ -371,8 +372,9 @@ class Module : public virtual slsDetectorDefs { void setBurstPeriod(int64_t value); std::array getInjectChannel() const; void setInjectChannel(const int offsetChannel, const int incrementChannel); - void sendVetoPhoton(const int chipIndex, const std::vector& gainIndices, - const std::vector& values); + void sendVetoPhoton(const int chipIndex, + const std::vector &gainIndices, + const std::vector &values); void getVetoPhoton(const int chipIndex, const std::string &fname) const; void setVetoPhoton(const int chipIndex, const int numPhotons, const int energy, const std::string &fname); diff --git a/slsReceiverSoftware/src/ClientInterface.cpp b/slsReceiverSoftware/src/ClientInterface.cpp index 64857950d..dc20985d1 100644 --- a/slsReceiverSoftware/src/ClientInterface.cpp +++ b/slsReceiverSoftware/src/ClientInterface.cpp @@ -201,6 +201,7 @@ int ClientInterface::functionTable(){ flist[F_GET_RECEIVER_THREAD_IDS] = &ClientInterface::get_thread_ids; flist[F_GET_RECEIVER_STREAMING_START_FNUM] = &ClientInterface::get_streaming_start_fnum; flist[F_SET_RECEIVER_STREAMING_START_FNUM] = &ClientInterface::set_streaming_start_fnum; + flist[F_SET_RECEIVER_RATE_CORRECT] = &ClientInterface::set_rate_correct; for (int i = NUM_DET_FUNCTIONS + 1; i < NUM_REC_FUNCTIONS ; i++) { LOG(logDEBUG1) << "function fnum: " << i << " (" << @@ -906,7 +907,8 @@ int ClientInterface::get_missing_packets(Interface &socket) { auto size = static_cast(missing_packets.size()); socket.Send(OK); socket.Send(size); - socket.Send(missing_packets.data(), sizeof(missing_packets[0])* missing_packets.size()); + socket.Send(missing_packets.data(), + sizeof(missing_packets[0]) * missing_packets.size()); return OK; } @@ -1204,7 +1206,7 @@ int ClientInterface::set_additional_json_header(Interface &socket) { socket.Receive(&buff[0], buff.size()); std::istringstream iss(buff); std::string key, value; - while(iss >> key){ + while (iss >> key) { iss >> value; json[key] = value; } @@ -1219,7 +1221,7 @@ int ClientInterface::get_additional_json_header(Interface &socket) { std::map json = impl()->getAdditionalJsonHeader(); LOG(logDEBUG1) << "additional json header:" << sls::ToString(json); std::ostringstream oss; - for (auto & it : json){ + for (auto &it : json) { oss << it.first << ' ' << it.second << ' '; } auto buff = oss.str(); @@ -1735,3 +1737,18 @@ int ClientInterface::set_streaming_start_fnum(Interface &socket) { validate(index, retval, "set streaming start fnum", DEC); return socket.Send(OK); } + +int ClientInterface::set_rate_correct(Interface &socket) { + auto index = socket.Receive(); + if (index <= 0) { + throw RuntimeError("Invalid number of rate correction values: " + + std::to_string(index)); + } + LOG(logDEBUG) << "Number of detectors for rate correction: " << index; + std::vector t(index); + socket.Receive(t.data(), t.size() * sizeof(t[0])); + verifyIdle(socket); + LOG(logINFOBLUE) << "Setting rate corrections[" << index << ']'; + impl()->setRateCorrections(t); + return socket.Send(OK); +} \ No newline at end of file diff --git a/slsReceiverSoftware/src/ClientInterface.h b/slsReceiverSoftware/src/ClientInterface.h index dc54a86dd..effd11dbb 100644 --- a/slsReceiverSoftware/src/ClientInterface.h +++ b/slsReceiverSoftware/src/ClientInterface.h @@ -157,6 +157,7 @@ class ClientInterface : private virtual slsDetectorDefs { int get_thread_ids(sls::ServerInterface &socket); int get_streaming_start_fnum(sls::ServerInterface &socket); int set_streaming_start_fnum(sls::ServerInterface &socket); + int set_rate_correct(sls::ServerInterface &socket); Implementation *impl() { if (receiver != nullptr) { diff --git a/slsReceiverSoftware/src/Implementation.cpp b/slsReceiverSoftware/src/Implementation.cpp index 0ba8e2528..0e4ea412d 100644 --- a/slsReceiverSoftware/src/Implementation.cpp +++ b/slsReceiverSoftware/src/Implementation.cpp @@ -47,6 +47,7 @@ void Implementation::DeleteMembers() { fifo.clear(); eth.clear(); udpPortNum.clear(); + rateCorrections.clear(); ctbDbitList.clear(); } @@ -946,6 +947,7 @@ void Implementation::SetupWriter() { masterAttributes->subExptime = std::chrono::nanoseconds(subExpTime); masterAttributes->subPeriod = std::chrono::nanoseconds(subPeriod); masterAttributes->quad = quadEnable; + masterAttributes->ratecorr = rateCorrections; masterAttributes->adcmask = tengigaEnable ? adcEnableMaskTenGiga : adcEnableMaskOneGiga; masterAttributes->analog = @@ -1798,6 +1800,11 @@ void Implementation::setReadNLines(const int value) { LOG(logINFO) << "Number of Lines to readout: " << numLinesReadout; } +void Implementation::setRateCorrections(const std::vector &t) { + rateCorrections = t; + LOG(logINFO) << "Rate Corrections: " << sls::ToString(rateCorrections); +} + slsDetectorDefs::readoutMode Implementation::getReadoutMode() const { LOG(logDEBUG3) << __SHORT_AT__ << " called"; return readoutType; diff --git a/slsReceiverSoftware/src/Implementation.h b/slsReceiverSoftware/src/Implementation.h index f2001ac14..a669a0820 100644 --- a/slsReceiverSoftware/src/Implementation.h +++ b/slsReceiverSoftware/src/Implementation.h @@ -211,6 +211,8 @@ class Implementation : private virtual slsDetectorDefs { int getReadNLines() const; /* [Eiger] */ void setReadNLines(const int value); + /* [Eiger] */ + void setRateCorrections(const std::vector &t); readoutMode getReadoutMode() const; /* [Ctb] */ void setReadoutMode(const readoutMode f); @@ -336,6 +338,7 @@ class Implementation : private virtual slsDetectorDefs { bool activated; bool deactivatedPaddingEnable; int numLinesReadout; + std::vector rateCorrections; readoutMode readoutType; uint32_t adcEnableMaskOneGiga; uint32_t adcEnableMaskTenGiga; diff --git a/slsReceiverSoftware/src/MasterAttributes.h b/slsReceiverSoftware/src/MasterAttributes.h index 3a7f84b89..4fe1fef92 100644 --- a/slsReceiverSoftware/src/MasterAttributes.h +++ b/slsReceiverSoftware/src/MasterAttributes.h @@ -34,6 +34,7 @@ class MasterAttributes { ns subExptime{0}; ns subPeriod{0}; uint32_t quad{0}; + std::vector ratecorr; uint32_t adcmask{0}; uint32_t analog{0}; uint32_t digital{0}; @@ -292,7 +293,9 @@ class EigerMasterAttributes : public MasterAttributes { << '\n' << "SubPeriod : " << sls::ToString(subPeriod) << '\n' - << "Quad : " << quad << '\n'; + << "Quad : " << quad << '\n' + << "Rate Corrections : " << sls::ToString(ratecorr) + << '\n'; std::string message = oss.str(); MasterAttributes::WriteBinaryAttributes(fd, message); }; @@ -339,6 +342,14 @@ class EigerMasterAttributes : public MasterAttributes { group->createDataSet("quad", PredType::NATIVE_INT, dataspace); dataset.write(&quad, PredType::NATIVE_INT); } + // Rate corrections + { + DataSpace dataspace = DataSpace(H5S_SCALAR); + StrType strdatatype(PredType::C_S1, 256); + DataSet dataset = group->createDataSet("rate corrections", + strdatatype, dataspace); + dataset.write(sls::ToString(ratecorr), strdatatype); + } }; #endif }; diff --git a/slsSupportLib/include/sls_detector_funcs.h b/slsSupportLib/include/sls_detector_funcs.h index a739b0ac2..8d83fbdc5 100755 --- a/slsSupportLib/include/sls_detector_funcs.h +++ b/slsSupportLib/include/sls_detector_funcs.h @@ -309,6 +309,7 @@ enum detFuncs { F_GET_RECEIVER_THREAD_IDS, F_GET_RECEIVER_STREAMING_START_FNUM, F_SET_RECEIVER_STREAMING_START_FNUM, + F_SET_RECEIVER_RATE_CORRECT, NUM_REC_FUNCTIONS }; @@ -617,9 +618,9 @@ const char* getFunctionNameFromEnum(enum detFuncs func) { case F_SET_RECEIVER_NUM_GATES: return "F_SET_RECEIVER_NUM_GATES"; case F_SET_RECEIVER_GATE_DELAY: return "F_SET_RECEIVER_GATE_DELAY"; case F_GET_RECEIVER_THREAD_IDS: return "F_GET_RECEIVER_THREAD_IDS"; - case F_GET_RECEIVER_STREAMING_START_FNUM: return "F_GET_RECEIVER_STREAMING_START_FNUM"; case F_SET_RECEIVER_STREAMING_START_FNUM: return "F_SET_RECEIVER_STREAMING_START_FNUM"; + case F_SET_RECEIVER_RATE_CORRECT: return "F_SET_RECEIVER_RATE_CORRECT"; case NUM_REC_FUNCTIONS: return "NUM_REC_FUNCTIONS"; default: return "Unknown Function"; From e2f1fd076a79eeff9133bc5c9936c6d00868259d Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Mon, 3 Aug 2020 10:07:00 +0200 Subject: [PATCH 19/26] rate correction updated in rxr also when chanign exptime, subexptime, default rate correction --- slsDetectorSoftware/src/Detector.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index 46aa5d925..11a1fe687 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -281,6 +281,7 @@ Result Detector::getDynamicRange(Positions pos) const { void Detector::setDynamicRange(int value) { pimpl->Parallel(&Module::setDynamicRange, {}, value); + updateRxRateCorrections(); } Result Detector::getTimingMode(Positions pos) const { @@ -1040,6 +1041,7 @@ Result Detector::getSubExptime(Positions pos) const { void Detector::setSubExptime(ns t, Positions pos) { pimpl->Parallel(&Module::setSubExptime, pos, t.count()); + updateRxRateCorrections(); } Result Detector::getSubDeadTime(Positions pos) const { @@ -1107,6 +1109,7 @@ Result Detector::getRateCorrection(Positions pos) const { void Detector::setDefaultRateCorrection(Positions pos) { pimpl->Parallel(&Module::setDefaultRateCorrection, pos); + updateRxRateCorrections(); } void Detector::setRateCorrection(ns dead_time, Positions pos) { @@ -1116,14 +1119,16 @@ void Detector::setRateCorrection(ns dead_time, Positions pos) { void Detector::updateRxRateCorrections() { // get tau from all modules and send to Rx index 0 - if (getUseReceiverFlag().squash(false)) { - // convert Result to std::vector - auto retval = getRateCorrection(); - std::vector t(retval.size()); - for (int i = 0; i < (int)retval.size(); ++i) { - t[i] = retval[i].count(); + if (getDetectorType().squash() == EIGER) { + if (getUseReceiverFlag().squash(false)) { + // convert Result to std::vector + auto retval = getRateCorrection(); + std::vector t(retval.size()); + for (int i = 0; i < (int)retval.size(); ++i) { + t[i] = retval[i].count(); + } + pimpl->Parallel(&Module::sendReceiverRateCorrections, {0}, t); } - pimpl->Parallel(&Module::sendReceiverRateCorrections, {0}, t); } } @@ -1421,6 +1426,7 @@ Result Detector::getExptime(int gateIndex, Positions pos) const { void Detector::setExptime(int gateIndex, ns t, Positions pos) { pimpl->Parallel(&Module::setExptime, pos, gateIndex, t.count()); + updateRxRateCorrections(); } Result> Detector::getExptimeForAllGates(Positions pos) const { From ddd562f8b575511e7a999533ba111aabee6230a9 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Mon, 3 Aug 2020 10:27:06 +0200 Subject: [PATCH 20/26] fix --- slsDetectorSoftware/src/Detector.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index 11a1fe687..2f59c717d 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -1119,7 +1119,7 @@ void Detector::setRateCorrection(ns dead_time, Positions pos) { void Detector::updateRxRateCorrections() { // get tau from all modules and send to Rx index 0 - if (getDetectorType().squash() == EIGER) { + if (getDetectorType().squash() == defs::EIGER) { if (getUseReceiverFlag().squash(false)) { // convert Result to std::vector auto retval = getRateCorrection(); From 6e4b7f5bd7f5edd04bf4c2d0c6611c98a2bf62cf Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Mon, 3 Aug 2020 11:10:01 +0200 Subject: [PATCH 21/26] fixed space in python enums --- python/scripts/generate_enums.py | 1 + python/src/enums.cpp | 37 ++++++++++++++++---------------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/python/scripts/generate_enums.py b/python/scripts/generate_enums.py index e6835e1da..29c73f628 100644 --- a/python/scripts/generate_enums.py +++ b/python/scripts/generate_enums.py @@ -42,6 +42,7 @@ def extract_enums(lines): except: pass + fields = [f.strip() for f in fields] enums[enum_name] = fields return enums diff --git a/python/src/enums.cpp b/python/src/enums.cpp index f2a7637b8..e1bfb622c 100644 --- a/python/src/enums.cpp +++ b/python/src/enums.cpp @@ -49,14 +49,14 @@ void init_enums(py::module &m) { py::enum_(Defs, "fileFormat") .value("BINARY", slsDetectorDefs::fileFormat::BINARY) - .value(" HDF5", slsDetectorDefs::fileFormat::HDF5) - .value(" NUM_FILE_FORMATS", + .value("HDF5", slsDetectorDefs::fileFormat::HDF5) + .value("NUM_FILE_FORMATS", slsDetectorDefs::fileFormat::NUM_FILE_FORMATS) .export_values(); py::enum_(Defs, "dimension") .value("X", slsDetectorDefs::dimension::X) - .value(" Y", slsDetectorDefs::dimension::Y) + .value("Y", slsDetectorDefs::dimension::Y) .export_values(); py::enum_(Defs, "externalSignalFlag") @@ -176,6 +176,7 @@ void init_enums(py::module &m) { slsDetectorDefs::dacIndex::TEMPERATURE_FPGA2) .value("TEMPERATURE_FPGA3", slsDetectorDefs::dacIndex::TEMPERATURE_FPGA3) + .value("TRIMBIT_SCAN", slsDetectorDefs::dacIndex::TRIMBIT_SCAN) .value("V_POWER_A", slsDetectorDefs::dacIndex::V_POWER_A) .value("V_POWER_B", slsDetectorDefs::dacIndex::V_POWER_B) .value("V_POWER_C", slsDetectorDefs::dacIndex::V_POWER_C) @@ -234,42 +235,42 @@ void init_enums(py::module &m) { py::enum_(Defs, "clockIndex") .value("ADC_CLOCK", slsDetectorDefs::clockIndex::ADC_CLOCK) - .value(" DBIT_CLOCK", slsDetectorDefs::clockIndex::DBIT_CLOCK) - .value(" RUN_CLOCK", slsDetectorDefs::clockIndex::RUN_CLOCK) - .value(" SYNC_CLOCK", slsDetectorDefs::clockIndex::SYNC_CLOCK) + .value("DBIT_CLOCK", slsDetectorDefs::clockIndex::DBIT_CLOCK) + .value("RUN_CLOCK", slsDetectorDefs::clockIndex::RUN_CLOCK) + .value("SYNC_CLOCK", slsDetectorDefs::clockIndex::SYNC_CLOCK) .export_values(); py::enum_(Defs, "readoutMode") .value("ANALOG_ONLY", slsDetectorDefs::readoutMode::ANALOG_ONLY) - .value(" DIGITAL_ONLY", slsDetectorDefs::readoutMode::DIGITAL_ONLY) - .value(" ANALOG_AND_DIGITAL", + .value("DIGITAL_ONLY", slsDetectorDefs::readoutMode::DIGITAL_ONLY) + .value("ANALOG_AND_DIGITAL", slsDetectorDefs::readoutMode::ANALOG_AND_DIGITAL) .export_values(); py::enum_(Defs, "speedLevel") .value("FULL_SPEED", slsDetectorDefs::speedLevel::FULL_SPEED) - .value(" HALF_SPEED", slsDetectorDefs::speedLevel::HALF_SPEED) - .value(" QUARTER_SPEED", slsDetectorDefs::speedLevel::QUARTER_SPEED) + .value("HALF_SPEED", slsDetectorDefs::speedLevel::HALF_SPEED) + .value("QUARTER_SPEED", slsDetectorDefs::speedLevel::QUARTER_SPEED) .export_values(); py::enum_(Defs, "masterFlags") .value("NO_MASTER", slsDetectorDefs::masterFlags::NO_MASTER) - .value(" IS_MASTER", slsDetectorDefs::masterFlags::IS_MASTER) - .value(" IS_SLAVE", slsDetectorDefs::masterFlags::IS_SLAVE) + .value("IS_MASTER", slsDetectorDefs::masterFlags::IS_MASTER) + .value("IS_SLAVE", slsDetectorDefs::masterFlags::IS_SLAVE) .export_values(); py::enum_(Defs, "frameModeType") .value("PEDESTAL", slsDetectorDefs::frameModeType::PEDESTAL) - .value(" NEW_PEDESTAL", slsDetectorDefs::frameModeType::NEW_PEDESTAL) - .value(" FLATFIELD", slsDetectorDefs::frameModeType::FLATFIELD) - .value(" NEW_FLATFIELD", slsDetectorDefs::frameModeType::NEW_FLATFIELD) + .value("NEW_PEDESTAL", slsDetectorDefs::frameModeType::NEW_PEDESTAL) + .value("FLATFIELD", slsDetectorDefs::frameModeType::FLATFIELD) + .value("NEW_FLATFIELD", slsDetectorDefs::frameModeType::NEW_FLATFIELD) .export_values(); py::enum_(Defs, "detectorModeType") .value("COUNTING", slsDetectorDefs::detectorModeType::COUNTING) - .value(" INTERPOLATING", + .value("INTERPOLATING", slsDetectorDefs::detectorModeType::INTERPOLATING) - .value(" ANALOG", slsDetectorDefs::detectorModeType::ANALOG) + .value("ANALOG", slsDetectorDefs::detectorModeType::ANALOG) .export_values(); py::enum_(Defs, "burstMode") @@ -282,7 +283,7 @@ void init_enums(py::module &m) { py::enum_(Defs, "timingSourceType") .value("TIMING_INTERNAL", slsDetectorDefs::timingSourceType::TIMING_INTERNAL) - .value(" TIMING_EXTERNAL", + .value("TIMING_EXTERNAL", slsDetectorDefs::timingSourceType::TIMING_EXTERNAL) .export_values(); } From 3083260b2894be780e1e2bcad8b0c2879133df45 Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Mon, 3 Aug 2020 11:13:47 +0200 Subject: [PATCH 22/26] changed clkdiv to speed in python --- python/slsdet/detector.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/python/slsdet/detector.py b/python/slsdet/detector.py index 76ad24578..0989f6e98 100755 --- a/python/slsdet/detector.py +++ b/python/slsdet/detector.py @@ -601,13 +601,12 @@ class Detector(CppDetectorApi): self.setRateCorrection(tau) @property - def clkdivider(self): - res = [int(value) for value in self.getSpeed()] - return element_if_equal(res) + def speed(self): + return element_if_equal(self.getSpeed()) - @clkdivider.setter - def clkdivider(self, value): - self.setSpeed(speedLevel(value)) + @speed.setter + def speed(self, value): + self.setSpeed(value) @property def frameindex(self): From 63a5b4d61f8c4734159af9aaa02b3cc60296a3b6 Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Mon, 3 Aug 2020 13:05:36 +0200 Subject: [PATCH 23/26] send vector for ratecorr --- slsDetectorSoftware/src/Module.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/slsDetectorSoftware/src/Module.cpp b/slsDetectorSoftware/src/Module.cpp index e613a961d..d2dd694c2 100644 --- a/slsDetectorSoftware/src/Module.cpp +++ b/slsDetectorSoftware/src/Module.cpp @@ -1168,10 +1168,8 @@ void Module::sendReceiverRateCorrections(const std::vector &t) { << ']'; auto receiver = ReceiverSocket(shm()->rxHostname, shm()->rxTCPPort); receiver.Send(F_SET_RECEIVER_RATE_CORRECT); - // TODO: use overload for vector - int size = t.size(); - receiver.Send(size); - receiver.Send(t.data(), t.size() * sizeof(t[0])); + receiver.Send(static_cast(t.size())); + receiver.Send(t); if (receiver.Receive() == FAIL) { throw RuntimeError("Receiver " + std::to_string(moduleId) + " returned error: " + receiver.readErrorMessage()); From acc43842eb2eda9f4d602c32c7f5512fc3189832 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Mon, 3 Aug 2020 14:29:16 +0200 Subject: [PATCH 24/26] code reviewe --- slsDetectorSoftware/src/Detector.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index 2f59c717d..5819ce8d8 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -1121,13 +1121,11 @@ void Detector::updateRxRateCorrections() { // get tau from all modules and send to Rx index 0 if (getDetectorType().squash() == defs::EIGER) { if (getUseReceiverFlag().squash(false)) { - // convert Result to std::vector - auto retval = getRateCorrection(); - std::vector t(retval.size()); - for (int i = 0; i < (int)retval.size(); ++i) { - t[i] = retval[i].count(); - } - pimpl->Parallel(&Module::sendReceiverRateCorrections, {0}, t); + std::vector dead_times; + for (auto item : getRateCorrection()) + dead_times.push_back(item.count()); + pimpl->Parallel(&Module::sendReceiverRateCorrections, {0}, + dead_times); } } } From e82bcafb769b9aedf9a5056060d446de20e1d105 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Mon, 3 Aug 2020 14:36:35 +0200 Subject: [PATCH 25/26] moved class to struct masterattributes --- slsReceiverSoftware/src/MasterAttributes.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/slsReceiverSoftware/src/MasterAttributes.h b/slsReceiverSoftware/src/MasterAttributes.h index 4fe1fef92..de837efcd 100644 --- a/slsReceiverSoftware/src/MasterAttributes.h +++ b/slsReceiverSoftware/src/MasterAttributes.h @@ -18,8 +18,7 @@ using ns = std::chrono::nanoseconds; #define HDF5_WRITER_VERSION (6.1) // 1 decimal places #define BINARY_WRITER_VERSION (6.1) // 1 decimal places -class MasterAttributes { - public: +struct MasterAttributes { slsDetectorDefs::detectorType detType{slsDetectorDefs::GENERIC}; slsDetectorDefs::timingMode timingMode{slsDetectorDefs::AUTO_TIMING}; uint32_t imageSize{0}; From 57c3cb084903145c759333ac0d63593e05a82e21 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Mon, 3 Aug 2020 14:48:27 +0200 Subject: [PATCH 26/26] class to struct: review --- slsReceiverSoftware/src/DataProcessor.h | 2 +- slsReceiverSoftware/src/File.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/slsReceiverSoftware/src/DataProcessor.h b/slsReceiverSoftware/src/DataProcessor.h index 71e719369..c9eacbac0 100644 --- a/slsReceiverSoftware/src/DataProcessor.h +++ b/slsReceiverSoftware/src/DataProcessor.h @@ -16,7 +16,7 @@ class GeneralData; class Fifo; class File; class DataStreamer; -class MasterAttributes; +struct MasterAttributes; #include #include diff --git a/slsReceiverSoftware/src/File.h b/slsReceiverSoftware/src/File.h index 651691df5..20a6c4562 100644 --- a/slsReceiverSoftware/src/File.h +++ b/slsReceiverSoftware/src/File.h @@ -15,7 +15,7 @@ #include -class MasterAttributes; +struct MasterAttributes; class File : private virtual slsDetectorDefs {