diff --git a/RELEASE.txt b/RELEASE.txt index abf35629d..0cd4c5f26 100755 --- a/RELEASE.txt +++ b/RELEASE.txt @@ -75,8 +75,14 @@ This document describes the differences between v7.0.0 and v6.x.x - rxr src files and classes (detectordata, ZmqSocket, helpDacs) added to sls namespace, and macros (namely from logger (logINFO etc)), slsDetectorGui (make_unique in implemtnation requires sls nemspace (points to std otherwise) but not deectorImpl.cpp) - blackfin programing made seamless (nCE fixed which helps) -save settings file for m3 and eiger +- m3 threshold changes - g2 and m3 clkdiv 2 (system clock) change should affect time settings (g2: exptime, period, delayaftertrigger, burstperiod, m3: exptime, gatedelay, gateperiod, period, delayaftertrigger) - g2 system frequency is the same irrespective of timing source +- (apparently) rxr doesnt get stuck anymore from 6.1.1 +- rxr mem size changed (fifo header size from 8 to 16) due to sls rxr header = 112.. 112+ 16=128 (reduces packet losss especially for g2) +-udp_srcip and udp_Srcip2: can set to auto (for virtual or 1g data networks) +- set dataset name for all hdf5 files to "data" only +- number of storage cells is not updated in teh receiver. done. and also allowing it to be modified in running status 2. Resolved Issues ================== diff --git a/python/slsdet/detector.py b/python/slsdet/detector.py index 6de5bb9af..4f0c51423 100755 --- a/python/slsdet/detector.py +++ b/python/slsdet/detector.py @@ -1834,13 +1834,13 @@ class Detector(CppDetectorApi): @property @element def threshold(self): - """[Eiger] Threshold in eV + """[Eiger][Mythen3] Threshold in eV Note ---- To change settings as well or set threshold without trimbits, use setThresholdEnergy. - :setter: It loads trim files from settingspath. + :setter: It loads trim files from settingspath.\n [Mythen3] An energy of -1 will pick up values from detector. """ if self.type == detectorType.MYTHEN3: return self.getAllThresholdEnergy() @@ -3516,7 +3516,7 @@ class Detector(CppDetectorApi): @property @element def interpolation(self): - """[Mythen3] Enable or disable interpolation. Enabling also enables all counters """ + """[Mythen3] Enable or disable interpolation. interpolation mode enables all counters and disables vth3. Disabling sets back counter mask and vth3. """ return self.getInterpolation() @interpolation.setter @@ -3526,7 +3526,7 @@ class Detector(CppDetectorApi): @property @element def pumpprobe(self): - """[Mythen3] Enable or disable pump probe mode. """ + """[Mythen3] Enable or disable pump probe mode. Pump probe mode only enables vth2. Disabling sets back to previous value """ return self.getPumpProbe() @pumpprobe.setter diff --git a/slsDetectorGui/forms/form_tab_developer.ui b/slsDetectorGui/forms/form_tab_developer.ui index e16e86287..7a0140d97 100755 --- a/slsDetectorGui/forms/form_tab_developer.ui +++ b/slsDetectorGui/forms/form_tab_developer.ui @@ -32,17 +32,29 @@ Form - - + + - - 0 + + 5 0 - - Readout: + + 1 + + + DACs + + + + + + ADCs + + + @@ -77,145 +89,19 @@ - - + + 0 0 - - <html><head/><body><p>High Voltage</p><p> #highvoltage#</p></body></html> - - High Voltage: + Readout: - - - - - 0 - 0 - - - - - 0 - 28 - - - - <html><head/><body><p>High Voltage</p><p> #highvoltage#</p></body></html> - - - - 0 - - - - - 90 - - - - - 110 - - - - - 120 - - - - - 150 - - - - - 180 - - - - - 200 - - - - - - - - - 0 - 0 - - - - <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: - - - - - - - - 0 - 0 - - - - - 0 - 28 - - - - <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> - - - false - - - -1 - - - 200 - - - - - - - - 5 - 0 - - - - 1 - - - - DACs - - - - - - ADCs - - - - - diff --git a/slsDetectorGui/forms/form_tab_settings.ui b/slsDetectorGui/forms/form_tab_settings.ui index 884f9e14e..526e31c72 100755 --- a/slsDetectorGui/forms/form_tab_settings.ui +++ b/slsDetectorGui/forms/form_tab_settings.ui @@ -7,7 +7,7 @@ 0 0 775 - 385 + 400 @@ -32,7 +32,77 @@ Form - + + + + + 0 + 0 + + + + + 140 + 28 + + + + <html><head/><body><p>High Voltage</p><p> #highvoltage#</p></body></html> + + + + 0 + + + + + 90 + + + + + 110 + + + + + 120 + + + + + 150 + + + + + 180 + + + + + 200 + + + + + + + + + 0 + 0 + + + + <html><head/><body><p>High Voltage</p><p> #highvoltage#</p></body></html> + + + High Voltage: + + + + false @@ -54,7 +124,7 @@ - + false @@ -73,7 +143,7 @@ - + Qt::Horizontal @@ -89,7 +159,7 @@ - + true @@ -111,7 +181,7 @@ - + false @@ -130,7 +200,7 @@ - + true @@ -144,7 +214,7 @@ 140 - 25 + 28 @@ -269,7 +339,7 @@ - + false @@ -306,7 +376,7 @@ - + true @@ -381,7 +451,7 @@ - + Qt::Horizontal @@ -397,7 +467,7 @@ - + false @@ -434,7 +504,23 @@ - + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 190 + + + + + false @@ -471,7 +557,7 @@ - + false @@ -493,7 +579,7 @@ - + false @@ -515,23 +601,7 @@ - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 20 - 190 - - - - - + false @@ -553,7 +623,7 @@ - + false @@ -561,7 +631,7 @@ 140 - 25 + 28 @@ -597,7 +667,7 @@ - + false @@ -616,7 +686,7 @@ - + false @@ -630,7 +700,7 @@ 140 - 25 + 28 @@ -674,6 +744,50 @@ + + + + + 0 + 0 + + + + <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: + + + + + + + + 0 + 0 + + + + + 140 + 28 + + + + <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> + + + false + + + -1 + + + 200 + + + diff --git a/slsDetectorGui/include/qTabDeveloper.h b/slsDetectorGui/include/qTabDeveloper.h index 90b3da3cd..c672bc69f 100644 --- a/slsDetectorGui/include/qTabDeveloper.h +++ b/slsDetectorGui/include/qTabDeveloper.h @@ -20,25 +20,16 @@ class qTabDeveloper : public QWidget, private Ui::TabDeveloperObject { public slots: void Refresh(); - private slots: - void SetHighVoltage(); - private: void SetupWidgetWindow(); void Initialization(); void PopulateDetectors(); - void GetHighVoltage(); slsDetectorDefs::dacIndex getSLSIndex(slsDetectorDefs::detectorType detType, int index); Detector *det; std::vector dacWidgets; std::vector adcWidgets; - - enum hvVals { HV_0, HV_90, HV_110, HV_120, HV_150, HV_180, HV_200 }; - int hvmin; - static const int HV_MIN = 60; - static const int HV_MAX = 200; }; } // namespace sls diff --git a/slsDetectorGui/include/qTabSettings.h b/slsDetectorGui/include/qTabSettings.h index ef0997c91..6e70b9377 100644 --- a/slsDetectorGui/include/qTabSettings.h +++ b/slsDetectorGui/include/qTabSettings.h @@ -18,6 +18,7 @@ class qTabSettings : public QWidget, private Ui::TabSettingsObject { void SetExportMode(bool exportMode); private slots: + void SetHighVoltage(); void SetSettings(int index); void SetGainMode(int index); void SetDynamicRange(int index); @@ -32,6 +33,7 @@ class qTabSettings : public QWidget, private Ui::TabSettingsObject { void ShowFixG0(bool expertMode); void Initialization(); + void GetHighVoltage(); void GetSettings(); void GetGainMode(); void GetDynamicRange(); @@ -42,6 +44,12 @@ class qTabSettings : public QWidget, private Ui::TabSettingsObject { Detector *det; std::vector counters; + enum hvVals { HV_0, HV_90, HV_110, HV_120, HV_150, HV_180, HV_200 }; + + int hvmin; + static const int HV_MIN = 60; + static const int HV_MAX = 200; + enum { STANDARD, FAST, diff --git a/slsDetectorGui/src/qTabDeveloper.cpp b/slsDetectorGui/src/qTabDeveloper.cpp index c8ee4be6e..7fb6cfdfc 100644 --- a/slsDetectorGui/src/qTabDeveloper.cpp +++ b/slsDetectorGui/src/qTabDeveloper.cpp @@ -18,12 +18,6 @@ qTabDeveloper::~qTabDeveloper() {} void qTabDeveloper::SetupWidgetWindow() { int tempid = 0; - comboHV->hide(); - lblComboHV->hide(); - lblSpinHV->hide(); - spinHV->hide(); - hvmin = HV_MIN; - try { slsDetectorDefs::detectorType detType = det->getDetectorType().squash(); switch (detType) { @@ -84,8 +78,6 @@ void qTabDeveloper::SetupWidgetWindow() { break; case slsDetectorDefs::GOTTHARD: - comboHV->show(); - lblComboHV->show(); dacWidgets.push_back(new qDacWidget( this, det, true, "v Reference: ", getSLSIndex(detType, tempid++))); @@ -119,8 +111,6 @@ void qTabDeveloper::SetupWidgetWindow() { break; case slsDetectorDefs::JUNGFRAU: - lblSpinHV->show(); - spinHV->show(); dacWidgets.push_back( new qDacWidget(this, det, true, "v vb comp: ", getSLSIndex(detType, tempid++))); @@ -150,8 +140,6 @@ void qTabDeveloper::SetupWidgetWindow() { break; case slsDetectorDefs::MOENCH: - lblSpinHV->show(); - spinHV->show(); dacWidgets.push_back( new qDacWidget(this, det, true, "vbp_colbuf: ", getSLSIndex(detType, tempid++))); @@ -175,9 +163,6 @@ void qTabDeveloper::SetupWidgetWindow() { break; case slsDetectorDefs::MYTHEN3: - lblSpinHV->show(); - spinHV->show(); - hvmin = 0; dacWidgets.push_back(new qDacWidget( this, det, true, "vcassh: ", getSLSIndex(detType, tempid++))); dacWidgets.push_back(new qDacWidget( @@ -218,9 +203,6 @@ void qTabDeveloper::SetupWidgetWindow() { break; case slsDetectorDefs::GOTTHARD2: - lblSpinHV->show(); - spinHV->show(); - hvmin = 0; dacWidgets.push_back( new qDacWidget(this, det, true, "vref_h_adc: ", getSLSIndex(detType, tempid++))); @@ -292,9 +274,6 @@ void qTabDeveloper::SetupWidgetWindow() { void qTabDeveloper::Initialization() { connect(comboDetector, SIGNAL(currentIndexChanged(int)), this, SLOT(Refresh())); - connect(comboHV, SIGNAL(currentIndexChanged(int)), this, - SLOT(SetHighVoltage())); - connect(spinHV, SIGNAL(valueChanged(int)), this, SLOT(SetHighVoltage())); } void qTabDeveloper::PopulateDetectors() { @@ -311,75 +290,6 @@ void qTabDeveloper::PopulateDetectors() { comboDetector->setCurrentIndex(0); } -void qTabDeveloper::GetHighVoltage() { - // not enabled for eiger - if (!comboHV->isVisible() && !spinHV->isVisible()) - return; - LOG(logDEBUG) << "Getting High Voltage"; - disconnect(spinHV, SIGNAL(valueChanged(int)), this, SLOT(SetHighVoltage())); - disconnect(comboHV, SIGNAL(currentIndexChanged(int)), this, - SLOT(SetHighVoltage())); - try { - // dac units - auto retval = det->getHighVoltage({comboDetector->currentIndex() - 1}) - .tsquash("Inconsistent values for high voltage."); - // spinHV - if (spinHV->isVisible()) { - if (retval != 0 && retval < hvmin && retval > HV_MAX) { - throw RuntimeError(std::string("Unknown High Voltage: ") + - std::to_string(retval)); - } - spinHV->setValue(retval); - } - // combo HV - else { - switch (retval) { - case 0: - comboHV->setCurrentIndex(HV_0); - break; - case 90: - comboHV->setCurrentIndex(HV_90); - break; - case 110: - comboHV->setCurrentIndex(HV_110); - break; - case 120: - comboHV->setCurrentIndex(HV_120); - break; - case 150: - comboHV->setCurrentIndex(HV_150); - break; - case 180: - comboHV->setCurrentIndex(HV_180); - break; - case 200: - comboHV->setCurrentIndex(HV_200); - break; - default: - throw RuntimeError(std::string("Unknown High Voltage: ") + - std::to_string(retval)); - } - } - } - CATCH_DISPLAY("Could not get high voltage.", - "qTabDeveloper::GetHighVoltage") - connect(spinHV, SIGNAL(valueChanged(int)), this, SLOT(SetHighVoltage())); - connect(comboHV, SIGNAL(currentIndexChanged(int)), this, - SLOT(SetHighVoltage())); -} - -void qTabDeveloper::SetHighVoltage() { - int val = (comboHV->isVisible() ? comboHV->currentText().toInt() - : spinHV->value()); - LOG(logINFO) << "Setting high voltage:" << val; - - try { - det->setHighVoltage({comboDetector->currentIndex() - 1}); - } - CATCH_HANDLE("Could not set high voltage.", "qTabDeveloper::SetHighVoltage", - this, &qTabDeveloper::GetHighVoltage) -} - slsDetectorDefs::dacIndex qTabDeveloper::getSLSIndex(slsDetectorDefs::detectorType detType, int index) { switch (detType) { @@ -606,7 +516,6 @@ void qTabDeveloper::Refresh() { for (const auto &it : adcWidgets) { it->SetDetectorIndex(comboDetector->currentIndex() - 1); } - GetHighVoltage(); LOG(logDEBUG) << "**Updated Developer Tab"; } diff --git a/slsDetectorGui/src/qTabSettings.cpp b/slsDetectorGui/src/qTabSettings.cpp index 23a9f28d6..91f758f28 100644 --- a/slsDetectorGui/src/qTabSettings.cpp +++ b/slsDetectorGui/src/qTabSettings.cpp @@ -19,6 +19,12 @@ qTabSettings::~qTabSettings() {} void qTabSettings::SetupWidgetWindow() { + comboHV->hide(); + lblComboHV->hide(); + lblSpinHV->hide(); + spinHV->hide(); + hvmin = HV_MIN; + counters = std::vector{chkCounter1, chkCounter2, chkCounter3}; spinThreshold2->hide(); @@ -37,6 +43,9 @@ void qTabSettings::SetupWidgetWindow() { // enabling according to det type slsDetectorDefs::detectorType detType = det->getDetectorType().squash(); if (detType == slsDetectorDefs::MYTHEN3) { + lblSpinHV->show(); + spinHV->show(); + hvmin = 0; lblDynamicRange->setEnabled(true); comboDynamicRange->setEnabled(true); @@ -77,13 +86,28 @@ void qTabSettings::SetupWidgetWindow() { } } } else if (detType == slsDetectorDefs::EIGER) { + lblSpinHV->show(); + spinHV->show(); + hvmin = 0; lblDynamicRange->setEnabled(true); comboDynamicRange->setEnabled(true); lblThreshold->setEnabled(true); spinThreshold->setEnabled(true); } else if (detType == slsDetectorDefs::JUNGFRAU) { + lblSpinHV->show(); + spinHV->show(); lblGainMode->setEnabled(true); comboGainMode->setEnabled(true); + } else if (detType == slsDetectorDefs::GOTTHARD) { + comboHV->show(); + lblComboHV->show(); + } else if (detType == slsDetectorDefs::MOENCH) { + lblSpinHV->show(); + spinHV->show(); + } else if (detType == slsDetectorDefs::GOTTHARD2) { + lblSpinHV->show(); + spinHV->show(); + hvmin = 0; } // default settings for the disabled @@ -165,6 +189,11 @@ void qTabSettings::ShowFixG0(bool expertMode) { } void qTabSettings::Initialization() { + // High voltage + connect(comboHV, SIGNAL(currentIndexChanged(int)), this, + SLOT(SetHighVoltage())); + connect(spinHV, SIGNAL(valueChanged(int)), this, SLOT(SetHighVoltage())); + // Settings if (comboSettings->isEnabled()) connect(comboSettings, SIGNAL(currentIndexChanged(int)), this, @@ -201,6 +230,91 @@ void qTabSettings::Initialization() { } } +void qTabSettings::GetHighVoltage() { + // not enabled for eiger + if (!comboHV->isVisible() && !spinHV->isVisible()) + return; + LOG(logDEBUG) << "Getting High Voltage"; + disconnect(spinHV, SIGNAL(valueChanged(int)), this, SLOT(SetHighVoltage())); + disconnect(comboHV, SIGNAL(currentIndexChanged(int)), this, + SLOT(SetHighVoltage())); + try { + Result retvals = det->getHighVoltage(); + + int retval = 0; + if (det->getDetectorType().squash() != slsDetectorDefs::EIGER) { + retval = retvals.tsquash("Inconsistent values for high voltage."); + } + // eiger slaves return -999 + else { + + auto is_master = det->getMaster(); + Result master_retvals; + for (size_t i = 0; i != retvals.size(); ++i) { + if (is_master[i]) { + master_retvals.push_back(retvals[i]); + } + } + retval = master_retvals.tsquash("Inconsistent values for high voltage."); + } + + // spinHV + if (spinHV->isVisible()) { + if (retval != 0 && retval < hvmin && retval > HV_MAX) { + throw RuntimeError(std::string("Unknown High Voltage: ") + + std::to_string(retval)); + } + spinHV->setValue(retval); + } + // combo HV + else { + switch (retval) { + case 0: + comboHV->setCurrentIndex(HV_0); + break; + case 90: + comboHV->setCurrentIndex(HV_90); + break; + case 110: + comboHV->setCurrentIndex(HV_110); + break; + case 120: + comboHV->setCurrentIndex(HV_120); + break; + case 150: + comboHV->setCurrentIndex(HV_150); + break; + case 180: + comboHV->setCurrentIndex(HV_180); + break; + case 200: + comboHV->setCurrentIndex(HV_200); + break; + default: + throw RuntimeError(std::string("Unknown High Voltage: ") + + std::to_string(retval)); + } + } + } + CATCH_DISPLAY("Could not get high voltage.", + "qTabSettings::GetHighVoltage") + connect(spinHV, SIGNAL(valueChanged(int)), this, SLOT(SetHighVoltage())); + connect(comboHV, SIGNAL(currentIndexChanged(int)), this, + SLOT(SetHighVoltage())); +} + +void qTabSettings::SetHighVoltage() { + int val = (comboHV->isVisible() ? comboHV->currentText().toInt() + : spinHV->value()); + LOG(logINFO) << "Setting high voltage:" << val; + + try { + det->setHighVoltage(val); + } + CATCH_HANDLE("Could not set high voltage.", "qTabSettings::SetHighVoltage", + this, &qTabSettings::GetHighVoltage) +} + void qTabSettings::GetSettings() { LOG(logDEBUG) << "Getting settings"; disconnect(comboSettings, SIGNAL(currentIndexChanged(int)), this, @@ -472,6 +586,8 @@ void qTabSettings::SetCounterMask() { void qTabSettings::Refresh() { LOG(logDEBUG) << "**Updating Settings Tab"; + GetHighVoltage(); + if (comboSettings->isEnabled()) { GetSettings(); } diff --git a/slsDetectorServers/mythen3DetectorServer/bin/mythen3DetectorServer_developer b/slsDetectorServers/mythen3DetectorServer/bin/mythen3DetectorServer_developer index 59ce094cc..fe31b3408 100755 Binary files a/slsDetectorServers/mythen3DetectorServer/bin/mythen3DetectorServer_developer and b/slsDetectorServers/mythen3DetectorServer/bin/mythen3DetectorServer_developer differ diff --git a/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c index ce96f5f78..776787a81 100644 --- a/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c @@ -68,6 +68,7 @@ int64_t exptimeReg[NCOUNTERS] = {0, 0, 0}; int64_t gateDelayReg[NCOUNTERS] = {0, 0, 0}; int vthEnabledVals[NCOUNTERS] = {0, 0, 0}; int detID = 0; +int counterMask = 0x0; int isInitCheckDone() { return initCheckDone; } @@ -474,17 +475,19 @@ void setupDetector() { // defaults setHighVoltage(DEFAULT_HIGH_VOLTAGE); - resetToDefaultDacs(0); setASICDefaults(); setADIFDefaults(); + // enable all counters before setting dacs (vthx) + setCounterMask(MAX_COUNTER_MSK); + resetToDefaultDacs(0); + // set trigger flow for m3 (for all timing modes) bus_w(FLOW_TRIGGER_REG, bus_r(FLOW_TRIGGER_REG) | FLOW_TRIGGER_MSK); // dynamic range setDynamicRange(DEFAULT_DYNAMIC_RANGE); - // enable all counters - setCounterMask(MAX_COUNTER_MSK); + // Initialization of acquistion parameters setNumFrames(DEFAULT_NUM_FRAMES); @@ -596,8 +599,8 @@ int resetToDefaultDacs(int hardReset) { } } - // set to defualt - setDAC((enum DACINDEX)i, value, 0); + // set to default (last arg to ensure counter check) + setDAC((enum DACINDEX)i, value, 0, 1); if (detectorDacs[i] != value) { LOG(logERROR, ("Setting dac %d failed, wrote %d, read %d\n", i, value, detectorDacs[i])); @@ -1087,12 +1090,44 @@ int64_t getGateDelay(int gateIndex) { return retval / (1E-9 * getFrequency(SYSTEM_C0)); } +void updateVthAndCounterMask() { + LOG(logINFO, ("\tUpdating Vth and countermask\n")); + int interpolation = getInterpolation(); + int pumpProbe = getPumpProbe(); + + if (interpolation) { + // enable all counters + setCounterMaskWithUpdateFlag(MAX_COUNTER_MSK, 0); + // disable vth3 + setVthDac(2, 0); + } else { + // previous counter values + setCounterMaskWithUpdateFlag(counterMask, 0); + } + if (pumpProbe) { + // enable only vth2 + setVthDac(0, 0); + setVthDac(1, 1); + setVthDac(2, 0); + } else { + setVthDac(0, (counterMask & (1 << 0))); + setVthDac(1, (counterMask & (1 << 1))); + } + if (!interpolation && !pumpProbe) { + setVthDac(2, (counterMask & (1 << 2))); + } +} + void setCounterMask(uint32_t arg) { + setCounterMaskWithUpdateFlag(arg, 1); + updateVthAndCounterMask(); +} + +void setCounterMaskWithUpdateFlag(uint32_t arg, int updateMaskFlag) { if (arg == 0 || arg > MAX_COUNTER_MSK) { return; } - uint32_t oldmask = getCounterMask(); - LOG(logINFO, ("Setting counter mask to 0x%x\n", arg)); + LOG(logINFO, ("\tSetting counter mask to 0x%x\n", arg)); uint32_t addr = CONFIG_REG; bus_w(addr, bus_r(addr) & ~CONFIG_COUNTERS_ENA_MSK); bus_w(addr, bus_r(addr) | ((arg << CONFIG_COUNTERS_ENA_OFST) & @@ -1108,19 +1143,8 @@ void setCounterMask(uint32_t arg) { setGateDelay(i, ns); } - LOG(logINFO, ("\tUpdating Vth dacs\n")); - enum DACINDEX vthdacs[] = {M_VTH1, M_VTH2, M_VTH3}; - for (int i = 0; i < NCOUNTERS; ++i) { - // if change in enable - if ((arg & (1 << i)) ^ (oldmask & (1 << i))) { - // disable, disable value - int value = DEFAULT_COUNTER_DISABLED_VTH_VAL; - // enable, set saved values - if (arg & (1 << i)) { - value = vthEnabledVals[i]; - } - setGeneralDAC(vthdacs[i], value, 0); - } + if (updateMaskFlag) { + counterMask = arg; } } @@ -1241,7 +1265,8 @@ int64_t getMeasurementTime() { int setDACS(int *dacs) { for (int i = 0; i < NDAC; ++i) { if (dacs[i] != -1) { - setDAC((enum DACINDEX)i, dacs[i], 0); + // set to default (last arg to ensure counter check) + setDAC((enum DACINDEX)i, dacs[i], 0, 1); if (dacs[i] != detectorDacs[i]) { // dont complain if that counter was disabled if ((i == M_VTH1 || i == M_VTH2 || i == M_VTH3) && @@ -1300,6 +1325,9 @@ int setModule(sls_detector_module myMod, char *mess) { return FAIL; } + // update vth and countermask + updateVthAndCounterMask(); + // threshold energy for (int i = 0; i < NCOUNTERS; ++i) { if (myMod.eV[i] >= 0) { @@ -1440,7 +1468,8 @@ enum detectorSettings setSettings(enum detectorSettings sett) { // set special dacs const int specialDacs[] = SPECIALDACINDEX; for (int i = 0; i < NSPECIALDACS; ++i) { - setDAC(specialDacs[i], dacVals[i], 0); + // set to default (last arg to ensure counter check) + setDAC(specialDacs[i], dacVals[i], 0, 1); } LOG(logINFO, ("Settings: %d\n", thisSettings)); @@ -1500,7 +1529,8 @@ void setThresholdEnergy(int counterIndex, int eV) { } /* parameters - dac, hv */ -void setDAC(enum DACINDEX ind, int val, int mV) { +// counterEnableCheck false only if setDAC called directly +void setDAC(enum DACINDEX ind, int val, int mV, int counterEnableCheck) { // invalid value if (val < 0) { return; @@ -1511,7 +1541,10 @@ void setDAC(enum DACINDEX ind, int val, int mV) { return; } - // threshold dacs (remember value, vthreshold: skip disabled) + // threshold dacs + // remember value, vthreshold: skip disabled, + // others: disable or enable dac if counter mask + // setDAC called directly: will set independent of counter enable if (ind == M_VTHRESHOLD || ind == M_VTH1 || ind == M_VTH2 || ind == M_VTH3) { char *dac_names[] = {DAC_NAMES}; @@ -1522,7 +1555,6 @@ void setDAC(enum DACINDEX ind, int val, int mV) { int dacval = val; // if not disabled value, remember value if (dacval != DEFAULT_COUNTER_DISABLED_VTH_VAL) { - // convert mv to dac if (mV) { if (LTC2620_D_VoltageToDac(val, &dacval) == FAIL) { return; @@ -1532,9 +1564,16 @@ void setDAC(enum DACINDEX ind, int val, int mV) { LOG(logINFO, ("Remembering %s [%d]\n", dac_names[ind], dacval)); } - // if vthreshold,skip for disabled counters - if ((ind == M_VTHRESHOLD) && (!(counters & (1 << i)))) { - continue; + // disabled counter + if (!(counters & (1 << i))) { + // skip setting vthx dac (value remembered anyway) + if (ind == M_VTHRESHOLD) { + continue; + } + // disable dac (except when setting dac directly) + if (counterEnableCheck) { + val = DEFAULT_COUNTER_DISABLED_VTH_VAL; + } } setGeneralDAC(vthdacs[i], val, mV); } @@ -1575,6 +1614,19 @@ void setGeneralDAC(enum DACINDEX ind, int val, int mV) { } } +void setVthDac(int index, int enable) { + LOG(logINFO, ("\t%s vth%d\n", (enable ? "Enabling" : "Disabing"), index)); + // enables (from remembered values) or disables vthx + enum DACINDEX vthdacs[] = {M_VTH1, M_VTH2, M_VTH3}; + // disable value + int value = DEFAULT_COUNTER_DISABLED_VTH_VAL; + // enable, set saved values + if (enable) { + value = vthEnabledVals[index]; + } + setGeneralDAC(vthdacs[index], value, 0); +} + int getDAC(enum DACINDEX ind, int mV) { if (ind == M_VTHRESHOLD) { int ret = -1, ret1 = -1; @@ -1738,23 +1790,24 @@ int setGainCaps(int caps) { int setInterpolation(int enable) { LOG(logINFO, ("%s Interpolation\n", enable == 0 ? "Disabling" : "Enabling")); - if (enable) { - setCounterMask(MAX_COUNTER_MSK); - if (getCounterMask() != MAX_COUNTER_MSK) { - LOG(logERROR, - ("Could not set interpolation. Could not enable all counters")); - return FAIL; - } - LOG(logINFO, ("\tEnabled all counters\n")); - } + int csr = M3SetInterpolation(enable); - return setChipStatusRegister(csr); + int ret = setChipStatusRegister(csr); + if (ret == OK) { + updateVthAndCounterMask(); + } + return ret; } int setPumpProbe(int enable) { LOG(logINFO, ("%s Pump Probe\n", enable == 0 ? "Disabling" : "Enabling")); + int csr = M3SetPumpProbe(enable); - return setChipStatusRegister(csr); + int ret = setChipStatusRegister(csr); + if (ret == OK) { + updateVthAndCounterMask(); + } + return ret; } int setDigitalPulsing(int enable) { diff --git a/slsDetectorServers/mythen3DetectorServer/slsDetectorServer_defs.h b/slsDetectorServers/mythen3DetectorServer/slsDetectorServer_defs.h index 5faaf20bf..4956dd52f 100644 --- a/slsDetectorServers/mythen3DetectorServer/slsDetectorServer_defs.h +++ b/slsDetectorServers/mythen3DetectorServer/slsDetectorServer_defs.h @@ -105,7 +105,7 @@ enum DACINDEX { 1220, /* vIpreOut */ \ 2800, /* Vth3 */ \ 2800, /* Vth1 */ \ - 1708, /* vIcin */ \ + 800, /* vIcin */ \ 1800, /* cas */ \ 1100, /* Vrpreamp */ \ 1100, /* Vcal_n */ \ diff --git a/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h b/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h index 3ae08b95d..d33cec62b 100644 --- a/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h +++ b/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h @@ -281,6 +281,7 @@ int getNumDigitalSamples(); #endif #ifdef MYTHEN3D void setCounterMask(uint32_t arg); +void setCounterMaskWithUpdateFlag(uint32_t arg, int updateMaskFlag); uint32_t getCounterMask(); void updatePacketizing(); #endif @@ -347,9 +348,12 @@ void setThresholdEnergy(int counterIndex, int eV); int setOnChipDAC(enum ONCHIP_DACINDEX ind, int chipIndex, int val); int getOnChipDAC(enum ONCHIP_DACINDEX ind, int chipIndex); #endif -void setDAC(enum DACINDEX ind, int val, int mV); #ifdef MYTHEN3D +void setDAC(enum DACINDEX ind, int val, int mV, int counterEnableCheck); void setGeneralDAC(enum DACINDEX ind, int val, int mV); +void setVthDac(int index, int enable); +#else +void setDAC(enum DACINDEX ind, int val, int mV); #endif int getDAC(enum DACINDEX ind, int mV); int getMaxDacSteps(); diff --git a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c index 988051528..235e8f427 100644 --- a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c +++ b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c @@ -1288,7 +1288,12 @@ int validateAndSetDac(enum dacIndex ind, int val, int mV) { LOG(logERROR, (mess)); } else #endif +#ifdef MYTHEN3D + // ignore counter enable to force vth dac values + setDAC(serverDacIndex, val, mV, 0); +#else setDAC(serverDacIndex, val, mV); +#endif retval = getDAC(serverDacIndex, mV); } #ifdef EIGERD @@ -9944,19 +9949,25 @@ int set_interpolation(int file_des) { #else // only set if (Server_VerifyLock() == OK) { - ret = setInterpolation(arg); - if (ret == FAIL) { - if (arg) - sprintf(mess, "Could not set interpolation or enable all " - "counters for it.\n"); - else - sprintf(mess, "Could not set interpolation\n"); + if (getPumpProbe() && arg) { + ret = FAIL; + sprintf(mess, "Could not set interpolation. Disable pump probe mode first.\n"); LOG(logERROR, (mess)); - } else { - int retval = getInterpolation(); - validate(&ret, mess, (int)arg, (int)retval, "set interpolation", - DEC); - LOG(logDEBUG1, ("interpolation retval: %u\n", retval)); + } else { + ret = setInterpolation(arg); + if (ret == FAIL) { + if (arg) + sprintf(mess, "Could not set interpolation or enable all " + "counters for it.\n"); + else + sprintf(mess, "Could not set interpolation\n"); + LOG(logERROR, (mess)); + } else { + int retval = getInterpolation(); + validate(&ret, mess, (int)arg, (int)retval, "set interpolation", + DEC); + LOG(logDEBUG1, ("interpolation retval: %u\n", retval)); + } } } #endif @@ -9994,14 +10005,20 @@ int set_pump_probe(int file_des) { #else // only set if (Server_VerifyLock() == OK) { - ret = setPumpProbe(arg); - if (ret == FAIL) { - sprintf(mess, "Could not set pump probe\n"); + if (getInterpolation() && arg) { + ret = FAIL; + sprintf(mess, "Could not set pump probe mode. Disable interpolation mode first.\n"); LOG(logERROR, (mess)); - } else { - int retval = getPumpProbe(); - validate(&ret, mess, (int)arg, (int)retval, "set pump probe", DEC); - LOG(logDEBUG1, ("pump probe retval: %u\n", retval)); + } else { + ret = setPumpProbe(arg); + if (ret == FAIL) { + sprintf(mess, "Could not set pump probe\n"); + LOG(logERROR, (mess)); + } else { + int retval = getPumpProbe(); + validate(&ret, mess, (int)arg, (int)retval, "set pump probe", DEC); + LOG(logDEBUG1, ("pump probe retval: %u\n", retval)); + } } } #endif diff --git a/slsDetectorSoftware/include/sls/Detector.h b/slsDetectorSoftware/include/sls/Detector.h index 8d428be6a..9afe3ec4a 100644 --- a/slsDetectorSoftware/include/sls/Detector.h +++ b/slsDetectorSoftware/include/sls/Detector.h @@ -144,7 +144,7 @@ class Detector { defs::detectorSettings settings = defs::STANDARD, bool trimbits = true, Positions pos = {}); - /** [Mythen3] It loads trim files from settingspath */ + /** [Mythen3] It loads trim files from settingspath. An energy of -1 will pick up values from detector */ void setThresholdEnergy(std::array threshold_ev, defs::detectorSettings settings = defs::STANDARD, bool trimbits = true, Positions pos = {}); @@ -1495,13 +1495,13 @@ class Detector { /** [Mythen3] */ Result getInterpolation(Positions pos = {}) const; - /** [Mythen3] Also enables all counters */ + /** [Mythen3] interpolation mode enables all counters and disables vth3. Disabling sets back counter mask and vth3. */ void setInterpolation(bool value, Positions pos = {}); /** [Mythen3] */ Result getPumpProbe(Positions pos = {}) const; - /** [Mythen3] */ + /** [Mythen3] pump probe mode only enables vth2. Disabling sets back to previous value */ void setPumpProbe(bool value, Positions pos = {}); /** [Mythen3] */ diff --git a/slsDetectorSoftware/src/CmdProxy.cpp b/slsDetectorSoftware/src/CmdProxy.cpp index 330fad9ae..d8fbd42ce 100644 --- a/slsDetectorSoftware/src/CmdProxy.cpp +++ b/slsDetectorSoftware/src/CmdProxy.cpp @@ -382,8 +382,8 @@ std::string CmdProxy::Threshold(int action) { } os << "\n\nthreshold [eV1] [eV2] [eV3] [(optional settings)]" "\n\t[Mythen3] Threshold in eV for each counter. It loads trim " - "files from " - "settingspath."; + "files from settingspath. An energy of -1 will pick up values " + " from detector."; if (cmd == "thresholdnotb") { os << "Trimbits are not loaded."; } @@ -1539,6 +1539,72 @@ std::string CmdProxy::UDPDestinationList(int action) { return os.str(); } +std::string CmdProxy::UDPSourceIP(int action) { + std::ostringstream os; + os << cmd << ' '; + if (action == defs::HELP_ACTION) { + os << "[x.x.x.x] or auto\n\tIp address of the detector (source) udp interface. Must be same subnet as destination udp ip.\n\t[Eiger] Set only for 10G. For 1G, detector will replace with its own DHCP IP address. If 'auto' used, then ip is set to ip of rx_hostname." + << '\n'; + } else if (action == defs::GET_ACTION) { + auto t = det->getSourceUDPIP(std::vector{det_id}); + if (!args.empty()) { + WrongNumberOfParameters(0); + } + os << OutString(t) << '\n'; + } else if (action == defs::PUT_ACTION) { + if (args.size() != 1) { + WrongNumberOfParameters(1); + } + IpAddr val; + if (args[0] == "auto") { + val = getIpFromAuto(); + LOG(logINFO) << "Setting udp_srcip of detector " << det_id << " to " + << val; + } else { + val = IpAddr(args[0]); + } + det->setSourceUDPIP(val, std::vector{det_id}); + os << val << '\n'; + + } else { + throw RuntimeError("Unknown action"); + } + return os.str(); +} + +std::string CmdProxy::UDPSourceIP2(int action) { + std::ostringstream os; + os << cmd << ' '; + if (action == defs::HELP_ACTION) { + os << "[x.x.x.x] or auto\n\t[Jungfrau][Gotthard2] Ip address of the detector (source) udp interface 2. Must be same subnet as destination udp ip2.\n\t [Jungfrau] top half or inner interface\n\t [Gotthard2] veto debugging. If 'auto' used, then ip is set to ip of rx_hostname." + << '\n'; + } else if (action == defs::GET_ACTION) { + auto t = det->getSourceUDPIP2(std::vector{det_id}); + if (!args.empty()) { + WrongNumberOfParameters(0); + } + os << OutString(t) << '\n'; + } else if (action == defs::PUT_ACTION) { + if (args.size() != 1) { + WrongNumberOfParameters(1); + } + IpAddr val; + if (args[0] == "auto") { + val = getIpFromAuto(); + LOG(logINFO) << "Setting udp_srcip2 of detector " << det_id << " to " + << val; + } else { + val = IpAddr(args[0]); + } + det->setSourceUDPIP2(val, std::vector{det_id}); + os << val << '\n'; + + } else { + throw RuntimeError("Unknown action"); + } + return os.str(); +} + std::string CmdProxy::UDPDestinationIP(int action) { std::ostringstream os; os << cmd << ' '; @@ -2302,6 +2368,9 @@ std::string CmdProxy::Counters(int action) { if (args.empty()) { WrongNumberOfParameters(1); } + if (std::any_of(args.cbegin(), args.cend(), [](std::string s){ return (StringTo(s) < 0 || StringTo(s) > 2); })) { + throw RuntimeError("Invalid counter indices list. Example: 0 1 2"); + } // convert vector to counter enable mask uint32_t mask = 0; for (size_t i = 0; i < args.size(); ++i) { diff --git a/slsDetectorSoftware/src/CmdProxy.h b/slsDetectorSoftware/src/CmdProxy.h index 3b7aa4886..5a9f99553 100644 --- a/slsDetectorSoftware/src/CmdProxy.h +++ b/slsDetectorSoftware/src/CmdProxy.h @@ -877,8 +877,8 @@ class CmdProxy { {"udp_numdst", &CmdProxy::udp_numdst}, {"udp_cleardst", &CmdProxy::udp_cleardst}, {"udp_firstdst", &CmdProxy::udp_firstdst}, - {"udp_srcip", &CmdProxy::udp_srcip}, - {"udp_srcip2", &CmdProxy::udp_srcip2}, + {"udp_srcip", &CmdProxy::UDPSourceIP}, + {"udp_srcip2", &CmdProxy::UDPSourceIP2}, {"udp_dstip", &CmdProxy::UDPDestinationIP}, {"udp_dstip2", &CmdProxy::UDPDestinationIP2}, {"udp_srcmac", &CmdProxy::udp_srcmac}, @@ -1148,6 +1148,8 @@ class CmdProxy { IpAddr getIpFromAuto(); UdpDestination getUdpEntry(); std::string UDPDestinationList(int action); + std::string UDPSourceIP(int action); + std::string UDPSourceIP2(int action); std::string UDPDestinationIP(int action); std::string UDPDestinationIP2(int action); /* Receiver Config */ @@ -1597,19 +1599,6 @@ class CmdProxy { "out from in a round robin fashion. The entry must not have been " "empty. Default: 0"); - INTEGER_COMMAND_VEC_ID( - udp_srcip, getSourceUDPIP, setSourceUDPIP, IpAddr, - "[x.x.x.x]\n\tIp address of the detector (source) udp " - "interface. Must be same subnet as destination udp " - "ip.\n\t[Eiger] Set only for 10G. For 1G, detector will " - "replace with its own DHCP IP address."); - - INTEGER_COMMAND_VEC_ID( - udp_srcip2, getSourceUDPIP2, setSourceUDPIP2, IpAddr, - "[x.x.x.x]\n\t[Jungfrau][Gotthard2] Ip address of the detector " - "(source) udp interface 2. Must be same subnet as destination udp " - "ip2.\n\t [Jungfrau] top half or inner interface\n\t [Gotthard2] veto " - "debugging."); INTEGER_COMMAND_VEC_ID( udp_srcmac, getSourceUDPMAC, setSourceUDPMAC, MacAddr, @@ -2053,12 +2042,11 @@ class CmdProxy { INTEGER_COMMAND_VEC_ID(interpolation, getInterpolation, setInterpolation, StringTo, "[0, 1]\n\t[Mythen3] Enables or disables " - "interpolation. Default is disabled. Enabling also " - "enables all counters. "); + "interpolation. Default is disabled. Interpolation mode enables all counters and disables vth3. Disabling sets back counter mask and vth3."); INTEGER_COMMAND_VEC_ID(pumpprobe, getPumpProbe, setPumpProbe, StringTo, "[0, 1]\n\t[Mythen3] Enables or disables pump probe " - "mode. Default is disabled"); + "mode. Default is disabled. Pump probe mode only enables vth2. Disabling sets back to previous value."); INTEGER_COMMAND_VEC_ID(apulse, getAnalogPulsing, setAnalogPulsing, StringTo, diff --git a/slsDetectorSoftware/src/Module.cpp b/slsDetectorSoftware/src/Module.cpp index d8898b709..05e59c420 100644 --- a/slsDetectorSoftware/src/Module.cpp +++ b/slsDetectorSoftware/src/Module.cpp @@ -173,7 +173,9 @@ std::array Module::getAllThresholdEnergy() const { void Module::setThresholdEnergy(int e_eV, detectorSettings isettings, bool trimbits) { - + if (shm()->detType == MYTHEN3) { + throw RuntimeError("Mythen3 should have called with 3 energies"); + } // verify e_eV exists in trimEneregies[] if (shm()->trimEnergies.empty() || (e_eV < shm()->trimEnergies.front()) || (e_eV > shm()->trimEnergies.back())) { @@ -214,21 +216,9 @@ void Module::setThresholdEnergy(int e_eV, detectorSettings isettings, myMod.iodelay = myMod1.iodelay; myMod.tau = linearInterpolation(e_eV, trim1, trim2, myMod1.tau, myMod2.tau); - // m3, reg is used for gaincaps - if (shm()->detType == MYTHEN3) { - if (myMod1.reg != myMod2.reg) { - throw RuntimeError( - "setThresholdEnergyAndSettings: gaincaps do not " - "match between files"); - } - myMod.reg = myMod1.reg; - } - } - // m3, reg is used for gaincaps - if (shm()->detType != MYTHEN3) { - myMod.reg = isettings; } + myMod.reg = isettings; myMod.eV[0] = e_eV; setModule(myMod, trimbits); if (getSettings() != isettings) { @@ -243,42 +233,35 @@ void Module::setThresholdEnergy(int e_eV, detectorSettings isettings, void Module::setAllThresholdEnergy(std::array e_eV, detectorSettings isettings, bool trimbits) { - // only mythen3 + if (shm()->detType != MYTHEN3) { + throw RuntimeError("This detector should have called with 3 energies"); + } if (shm()->trimEnergies.empty()) { throw RuntimeError( - "Trim energies have not been defined for this module yet!"); + "Trim energies have not been defined for this module yet! Use trimen."); } - auto counters = getSetBits(getCounterMask()); - enum mythen3_DacIndex { - M_VCASSH, - M_VTH2, - M_VRSHAPER, - M_VRSHAPER_N, - M_VIPRE_OUT, - M_VTH3, - M_VTH1, - M_VICIN, - M_VCAS, - M_VRPREAMP, - M_VCAL_N, - M_VIPRE, - M_VISHAPER, - M_VCAL_P, - M_VTRIM, - M_VDCSH - }; - - std::vector myMods{shm()->detType}; std::vector energy(e_eV.begin(), e_eV.end()); // if all energies are same if (allEqualTo(energy, energy[0])) { + if (energy[0] == -1) { + throw RuntimeError("Every energy provided to set threshold energy is -1. Typo?"); + } energy.resize(1); } - myMods.resize(energy.size()); // for each threshold + std::vector myMods; for (size_t i = 0; i < energy.size(); ++i) { + if (energy[i] == -1) { + sls_detector_module mod = getModule(); + myMods.push_back(mod); + continue; + } + + sls_detector_module mod{shm()->detType}; + myMods.push_back(mod); + // don't interpolate if (shm()->trimEnergies.anyEqualTo(energy[i])) { std::string settingsfname = @@ -324,10 +307,9 @@ void Module::setAllThresholdEnergy(std::array e_eV, myMods[i] = interpolateTrim(&myMod1, &myMod2, energy[i], trim1, trim2, trimbits); - // gaincaps + // csr if (myMod1.reg != myMod2.reg) { - throw RuntimeError("setAllThresholdEnergy: gaincaps do not " - "match between files for energy (eV) " + + throw RuntimeError("setAllThresholdEnergy: chip shift register values do not match between files for energy (eV) " + std::to_string(energy[i])); } myMods[i].reg = myMod1.reg; @@ -337,8 +319,11 @@ void Module::setAllThresholdEnergy(std::array e_eV, sls_detector_module myMod{shm()->detType}; myMod = myMods[0]; + // if multiple thresholds, combine if (myMods.size() > 1) { + auto counters = getSetBits(getCounterMask()); + // average vtrim of enabled counters int sum = 0; @@ -377,56 +362,15 @@ void Module::setAllThresholdEnergy(std::array e_eV, for (int i = 0; i < myMod.nchan; ++i) { myMod.chanregs[i] = myMods[i % 3].chanregs[i]; } - // gain caps + // csr if (myMods[0].reg != myMods[1].reg || myMods[1].reg != myMods[2].reg) { - throw RuntimeError("setAllThresholdEnergy: gaincaps do not " - "match between files for all energies"); + throw RuntimeError("setAllThresholdEnergy: chip shift register values do not match between files for all energies"); } } - myMod.reg = isettings; std::copy(e_eV.begin(), e_eV.end(), myMod.eV); LOG(logDEBUG) << "ev:" << ToString(myMod.eV); - // check for trimbits that are out of range - bool out_of_range = false; - for (int i = 0; i != myMod.nchan; ++i) { - if (myMod.chanregs[i] < 0) { - myMod.chanregs[i] = 0; - out_of_range = true; - } else if (myMod.chanregs[i] > 63) { - myMod.chanregs[i] = 63; - out_of_range = true; - } - } - if (out_of_range) { - LOG(logWARNING) - << "Some trimbits were out of range after interpolation, these " - "have been replaced with 0 or 63."; - } - - // check dacs - out_of_range = false; - for (int i = 0; i != myMod.ndac; ++i) { - int dacMin = 0; - int dacMax = 2800; - if (i == M_VTH1 || i == M_VTH2 || i == M_VTH3) { - dacMin = 200; - dacMax = 2400; - } - if (myMod.dacs[i] < dacMin) { - myMod.dacs[i] = dacMin; - out_of_range = true; - } else if (myMod.dacs[i] > dacMax) { - myMod.dacs[i] = dacMax; - out_of_range = true; - } - } - if (out_of_range) { - LOG(logWARNING) << "Some dacs were out of range after interpolation, " - "these have been replaced with 600 or 2400."; - } - setModule(myMod, trimbits); if (getSettings() != isettings) { throw RuntimeError("setThresholdEnergyAndSettings: Could not set " @@ -1824,6 +1768,9 @@ int Module::getNumberOfAdditionalStorageCells() const { void Module::setNumberOfAdditionalStorageCells(int value) { sendToDetector(F_SET_NUM_ADDITIONAL_STORAGE_CELLS, value, nullptr); + if (shm()->useReceiverFlag) { + sendToReceiver(F_SET_RECEIVER_NUM_ADD_STORAGE_CELLS, value, nullptr); + } } int Module::getStorageCellStart() const { @@ -2252,10 +2199,8 @@ uint32_t Module::getCounterMask() const { } void Module::setCounterMask(uint32_t countermask) { - LOG(logDEBUG1) << "Setting Counter mask to " << countermask; sendToDetector(F_SET_COUNTER_MASK, countermask, nullptr); if (shm()->useReceiverFlag) { - LOG(logDEBUG1) << "Sending Reciver counter mask: " << countermask; sendToReceiver(F_RECEIVER_SET_COUNTER_MASK, countermask, nullptr); } } @@ -2315,7 +2260,10 @@ bool Module::getInterpolation() const { void Module::setInterpolation(const bool enable) { sendToDetector(F_SET_INTERPOLATION, static_cast(enable), nullptr); - setCounterMask(getCounterMask()); + int mask = getCounterMask(); + if (shm()->useReceiverFlag) { + sendToReceiver(F_RECEIVER_SET_COUNTER_MASK, mask, nullptr); + } } bool Module::getPumpProbe() const { @@ -2398,12 +2346,9 @@ int Module::getNumberOfDigitalSamples() const { } void Module::setNumberOfDigitalSamples(int value) { - LOG(logDEBUG1) << "Setting number of digital samples to " << value; sendToDetector(F_SET_NUM_DIGITAL_SAMPLES, value, nullptr); updateNumberOfChannels(); // depends on samples and adcmask if (shm()->useReceiverFlag) { - LOG(logDEBUG1) << "Sending number of digital samples to Receiver: " - << value; sendToReceiver(F_RECEIVER_SET_NUM_DIGITAL_SAMPLES, value, nullptr); } } @@ -3338,6 +3283,45 @@ void Module::setModule(sls_detector_module &module, bool trimbits) { module.nchan = 0; module.nchip = 0; } + // validate dacs and trimbits + if (shm()->detType == MYTHEN3) { + // check for trimbits that are out of range + bool out_of_range = false; + for (int i = 0; i != module.nchan; ++i) { + if (module.chanregs[i] < 0) { + module.chanregs[i] = 0; + out_of_range = true; + } else if (module.chanregs[i] > 63) { + module.chanregs[i] = 63; + out_of_range = true; + } + } + if (out_of_range) { + LOG(logWARNING) + << "Some trimbits were out of range, these have been replaced with 0 or 63."; + } + // check dacs + out_of_range = false; + for (int i = 0; i != module.ndac; ++i) { + int dacMin = 0; + int dacMax = 2800; + if (i == M_VTH1 || i == M_VTH2 || i == M_VTH3) { + dacMin = 200; + dacMax = 2400; + } + if (module.dacs[i] < dacMin) { + module.dacs[i] = dacMin; + out_of_range = true; + } else if (module.dacs[i] > dacMax) { + module.dacs[i] = dacMax; + out_of_range = true; + } + } + if (out_of_range) { + LOG(logWARNING) << "Some dacs were out of range, " + "these have been replaced with 0/200 or 2800/2400."; + } + } auto client = DetectorSocket(shm()->hostname, shm()->controlPort); client.Send(F_SET_MODULE); sendModule(&module, client); @@ -3469,42 +3453,6 @@ sls_detector_module Module::interpolateTrim(sls_detector_module *a, } sls_detector_module myMod{shm()->detType}; - enum eiger_DacIndex { - E_SVP, - E_VTR, - E_VRF, - E_VRS, - E_SVN, - E_VTGSTV, - E_VCMP_LL, - E_VCMP_LR, - E_CAL, - E_VCMP_RL, - E_RXB_RB, - E_RXB_LB, - E_VCMP_RR, - E_VCP, - E_VCN, - E_VIS - }; - enum mythen3_DacIndex { - M_VCASSH, - M_VTH2, - M_VRSHAPER, - M_VRSHAPER_N, - M_VIPRE_OUT, - M_VTH3, - M_VTH1, - M_VICIN, - M_VCAS, - M_VRPREAMP, - M_VCAL_N, - M_VIPRE, - M_VISHAPER, - M_VCAL_P, - M_VTRIM, - M_VDCSH - }; // create copy and interpolate dac lists std::vector dacs_to_copy, dacs_to_interpolate; diff --git a/slsDetectorSoftware/src/Module.h b/slsDetectorSoftware/src/Module.h index 28fd08db5..2ab2f0217 100644 --- a/slsDetectorSoftware/src/Module.h +++ b/slsDetectorSoftware/src/Module.h @@ -789,6 +789,44 @@ class Module : public virtual slsDetectorDefs { static const int NIOS_WRITE_TO_FLASH_TIME_FPGA = 45; static const int NIOS_ERASE_FLASH_TIME_KERNEL = 9; static const int NIOS_WRITE_TO_FLASH_TIME_KERNEL = 40; + + enum mythen3_DacIndex { + M_VCASSH, + M_VTH2, + M_VRSHAPER, + M_VRSHAPER_N, + M_VIPRE_OUT, + M_VTH3, + M_VTH1, + M_VICIN, + M_VCAS, + M_VRPREAMP, + M_VCAL_N, + M_VIPRE, + M_VISHAPER, + M_VCAL_P, + M_VTRIM, + M_VDCSH + }; + + enum eiger_DacIndex { + E_SVP, + E_VTR, + E_VRF, + E_VRS, + E_SVN, + E_VTGSTV, + E_VCMP_LL, + E_VCMP_LR, + E_CAL, + E_VCMP_RL, + E_RXB_RB, + E_RXB_LB, + E_VCMP_RR, + E_VCP, + E_VCN, + E_VIS + }; }; } // namespace sls \ No newline at end of file diff --git a/slsDetectorSoftware/tests/test-CmdProxy-mythen3.cpp b/slsDetectorSoftware/tests/test-CmdProxy-mythen3.cpp index 3eedd9ea4..be6d9877f 100644 --- a/slsDetectorSoftware/tests/test-CmdProxy-mythen3.cpp +++ b/slsDetectorSoftware/tests/test-CmdProxy-mythen3.cpp @@ -496,32 +496,46 @@ TEST_CASE("interpolation", "[.cmd]") { Detector det; CmdProxy proxy(&det); if (det.getDetectorType().squash() == defs::MYTHEN3) { - auto prev_val = det.getInterpolation(); - auto mask = det.getCounterMask(); - { - proxy.Call("counters", {"0", "1"}, -1, PUT); - std::ostringstream oss; - proxy.Call("interpolation", {"1"}, -1, PUT, oss); - REQUIRE(oss.str() == "interpolation 1\n"); - REQUIRE(det.getCounterMask().tsquash("inconsistent counter mask") == - 7); - } - { - proxy.Call("counters", {"0", "1"}, -1, PUT); - std::ostringstream oss; - proxy.Call("interpolation", {"0"}, -1, PUT, oss); - REQUIRE(oss.str() == "interpolation 0\n"); - REQUIRE(det.getCounterMask().tsquash("inconsistent counter mask") == - 3); + auto prev_interpolation = det.getInterpolation(); + auto prev_mask = det.getCounterMask(); + auto prev_vth3DacVal = det.getDAC(defs::VTH3, 0, {}); + + int disabledDacValue = 2800; + auto fixedVth3DacVal = 1000; + det.setDAC(defs::VTH3, fixedVth3DacVal, 0, {}); + // mask with counter 3 disabled and enabled(to test vth3) + uint32_t fixedMask[2] = {0x2, 0x4}; + for (int i = 0; i != 2; ++i) { + det.setCounterMask(fixedMask[i]); + { + std::ostringstream oss; + proxy.Call("interpolation", {"1"}, -1, PUT, oss); + REQUIRE(oss.str() == "interpolation 1\n"); + REQUIRE(det.getCounterMask().tsquash("inconsistent counter mask") == + 7); + REQUIRE(det.getDAC(defs::VTH3, 0, {0}).tsquash("inconsistent vth3 dac value") == disabledDacValue); + } + { + std::ostringstream oss; + proxy.Call("interpolation", {"0"}, -1, PUT, oss); + REQUIRE(oss.str() == "interpolation 0\n"); + REQUIRE(det.getCounterMask().tsquash("inconsistent counter mask") == + fixedMask[i]); + uint32_t expectedVth3DacVal = (fixedMask[i] & 0x4 ? fixedVth3DacVal : disabledDacValue); + REQUIRE(det.getDAC(defs::VTH3, 0, {0}).tsquash("inconsistent vth3 dac value") == expectedVth3DacVal); + } } + { std::ostringstream oss; proxy.Call("interpolation", {}, -1, GET, oss); REQUIRE(oss.str() == "interpolation 0\n"); } for (int i = 0; i != det.size(); ++i) { - det.setCounterMask(mask[i], {i}); - det.setInterpolation(prev_val[i], {i}); + det.setCounterMask(prev_mask[i], {i}); + det.setInterpolation(prev_interpolation[i], {i}); + det.setDAC(defs::VTH3, prev_vth3DacVal[i], 0, {i}); + } } else { REQUIRE_THROWS(proxy.Call("interpolation", {}, -1, GET)); @@ -533,15 +547,43 @@ TEST_CASE("pumpprobe", "[.cmd]") { CmdProxy proxy(&det); if (det.getDetectorType().squash() == defs::MYTHEN3) { auto prev_val = det.getPumpProbe(); - { - std::ostringstream oss; - proxy.Call("pumpprobe", {"1"}, -1, PUT, oss); - REQUIRE(oss.str() == "pumpprobe 1\n"); - } - { - std::ostringstream oss; - proxy.Call("pumpprobe", {"0"}, -1, PUT, oss); - REQUIRE(oss.str() == "pumpprobe 0\n"); + auto prev_interpolation = det.getInterpolation(); + auto prev_mask = det.getCounterMask(); + auto prev_vth1DacVal = det.getDAC(defs::VTH1, 0, {}); + auto prev_vth2DacVal = det.getDAC(defs::VTH2, 0, {}); + auto prev_vth3DacVal = det.getDAC(defs::VTH3, 0, {}); + + int disabledDacValue = 2800; + auto fixedVthDacVal = 1000; + det.setDAC(defs::VTH1, fixedVthDacVal, 0, {}); + det.setDAC(defs::VTH2, fixedVthDacVal, 0, {}); + det.setDAC(defs::VTH3, fixedVthDacVal, 0, {}); + // mask with counter 2 disabled and enabled(to test vth2) + uint32_t fixedMask[2] = {0x4, 0x3}; + for (int i = 0; i != 2; ++i) { + det.setCounterMask(fixedMask[i]); + { + // pump probe + std::ostringstream oss; + proxy.Call("pumpprobe", {"1"}, -1, PUT, oss); + REQUIRE(oss.str() == "pumpprobe 1\n"); + REQUIRE(det.getDAC(defs::VTH1, 0, {0}).tsquash("inconsistent vth2 dac value") == disabledDacValue); + REQUIRE(det.getDAC(defs::VTH2, 0, {0}).tsquash("inconsistent vth2 dac value") == fixedVthDacVal); + REQUIRE(det.getDAC(defs::VTH3, 0, {0}).tsquash("inconsistent vth2 dac value") == disabledDacValue); + } + // interpolation and pump probe + REQUIRE_THROWS(proxy.Call("interpolation", {"1"}, -1, PUT)); + { + // none + std::ostringstream oss; + proxy.Call("pumpprobe", {"0"}, -1, PUT, oss); + REQUIRE(oss.str() == "pumpprobe 0\n"); + REQUIRE(det.getCounterMask().tsquash("inconsistent counter mask") == 7); + REQUIRE(det.getDAC(defs::VTH1, 0, {0}).tsquash("inconsistent vth1 dac value") == (fixedMask[i] & 0x1 ? fixedVthDacVal : disabledDacValue)); + REQUIRE(det.getDAC(defs::VTH2, 0, {0}).tsquash("inconsistent vth2 dac value") == (fixedMask[i] & 0x2 ? fixedVthDacVal : disabledDacValue)); + REQUIRE(det.getDAC(defs::VTH3, 0, {0}).tsquash("inconsistent vth3 dac value") == (fixedMask[i] & 0x4 ? fixedVthDacVal : disabledDacValue)); + } + } { std::ostringstream oss; @@ -549,7 +591,12 @@ TEST_CASE("pumpprobe", "[.cmd]") { REQUIRE(oss.str() == "pumpprobe 0\n"); } for (int i = 0; i != det.size(); ++i) { + det.setCounterMask(prev_mask[i], {i}); det.setPumpProbe(prev_val[i], {i}); + det.setInterpolation(prev_interpolation[i], {i}); + det.setDAC(defs::VTH1, prev_vth1DacVal[i], 0, {i}); + det.setDAC(defs::VTH2, prev_vth2DacVal[i], 0, {i}); + det.setDAC(defs::VTH3, prev_vth3DacVal[i], 0, {i}); } } else { REQUIRE_THROWS(proxy.Call("pumpprobe", {}, -1, GET)); diff --git a/slsReceiverSoftware/src/ClientInterface.cpp b/slsReceiverSoftware/src/ClientInterface.cpp index 280ed77a9..c17accb2a 100644 --- a/slsReceiverSoftware/src/ClientInterface.cpp +++ b/slsReceiverSoftware/src/ClientInterface.cpp @@ -581,7 +581,7 @@ int ClientInterface::set_num_add_storage_cells(Interface &socket) { throw RuntimeError("Invalid number of additional storage cells " + std::to_string(value)); } - verifyIdle(socket); + // allowing this to be done even when receiver not idle LOG(logDEBUG1) << "Setting num additional storage cells to " << value; impl()->setNumberOfAdditionalStorageCells(value); return socket.Send(OK); diff --git a/slsReceiverSoftware/src/DataProcessor.cpp b/slsReceiverSoftware/src/DataProcessor.cpp index 517f062e5..f36850572 100644 --- a/slsReceiverSoftware/src/DataProcessor.cpp +++ b/slsReceiverSoftware/src/DataProcessor.cpp @@ -169,7 +169,7 @@ uint32_t DataProcessor::GetFilesInAcquisition() const { return dataFile_->GetFilesInAcquisition(); } -std::array DataProcessor::CreateVirtualFile( +std::string DataProcessor::CreateVirtualFile( const std::string &filePath, const std::string &fileNamePrefix, const uint64_t fileIndex, const bool overWriteEnable, const bool silentMode, const int modulePos, const int numUnitsPerReadout, @@ -195,7 +195,7 @@ std::array DataProcessor::CreateVirtualFile( // stop acquisition) return masterFileUtility::CreateVirtualHDF5File( filePath, fileNamePrefix, fileIndex, overWriteEnable, silentMode, - modulePos, numUnitsPerReadout, framesPerFile, numImages, + modulePos, numUnitsPerReadout, framesPerFile, generalData_->nPixelsX, generalData_->nPixelsY, dynamicRange, numFramesCaught_, numModX, numModY, dataFile_->GetPDataType(), dataFile_->GetParameterNames(), dataFile_->GetParameterDataTypes(), @@ -204,21 +204,18 @@ std::array DataProcessor::CreateVirtualFile( void DataProcessor::LinkFileInMaster(const std::string &masterFileName, const std::string &virtualFileName, - const std::string &virtualDatasetName, const bool silentMode, std::mutex *hdf5LibMutex) { if (receiverRoiEnabled_) { throw std::runtime_error("Should not be here, roi with hdf5 virtual should throw."); } - std::string fname{virtualFileName}, datasetName{virtualDatasetName}; + std::string fname{virtualFileName}, masterfname{masterFileName}; // if no virtual file, link data file if (virtualFileName.empty()) { - auto res = dataFile_->GetFileAndDatasetName(); - fname = res[0]; - datasetName = res[1]; + fname = dataFile_->GetFileName(); } - masterFileUtility::LinkHDF5FileInMaster(masterFileName, fname, datasetName, + masterFileUtility::LinkHDF5FileInMaster(masterfname, fname, dataFile_->GetParameterNames(), silentMode, hdf5LibMutex); } diff --git a/slsReceiverSoftware/src/DataProcessor.h b/slsReceiverSoftware/src/DataProcessor.h index 2e89ec198..78bcc58d0 100644 --- a/slsReceiverSoftware/src/DataProcessor.h +++ b/slsReceiverSoftware/src/DataProcessor.h @@ -62,7 +62,7 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject { const bool detectorDataStream); #ifdef HDF5C uint32_t GetFilesInAcquisition() const; - std::array CreateVirtualFile( + std::string CreateVirtualFile( const std::string &filePath, const std::string &fileNamePrefix, const uint64_t fileIndex, const bool overWriteEnable, const bool silentMode, const int modulePos, @@ -71,7 +71,6 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject { const uint32_t dynamicRange, std::mutex *hdf5LibMutex); void LinkFileInMaster(const std::string &masterFileName, const std::string &virtualFileName, - const std::string &virtualDatasetName, const bool silentMode, std::mutex *hdf5LibMutex); #endif diff --git a/slsReceiverSoftware/src/File.h b/slsReceiverSoftware/src/File.h index c9cebb276..957d414cd 100644 --- a/slsReceiverSoftware/src/File.h +++ b/slsReceiverSoftware/src/File.h @@ -7,15 +7,12 @@ #include -namespace sls { - #ifdef HDF5C #include "H5Cpp.h" -#ifndef H5_NO_NAMESPACE -using namespace H5; -#endif #endif +namespace sls { + struct MasterAttributes; class File : private virtual slsDetectorDefs { @@ -28,11 +25,11 @@ class File : private virtual slsDetectorDefs { virtual void CloseFile() = 0; #ifdef HDF5C - virtual std::array GetFileAndDatasetName() const { + virtual std::string GetFileName() const { LOG(logERROR) - << "This is a generic function GetFilesInAcquisition that " + << "This is a generic function GetFileName that " "should be overloaded by a derived class"; - return std::array{}; + return std::string{}; } virtual uint32_t GetFilesInAcquisition() const { @@ -42,24 +39,24 @@ class File : private virtual slsDetectorDefs { return 0; }; - virtual DataType GetPDataType() const { + virtual H5::DataType GetPDataType() const { LOG(logERROR) << "This is a generic function GetPDataType that " "should be overloaded by a derived class"; - return PredType::STD_U16LE; + return H5::PredType::STD_U16LE; } virtual std::vector GetParameterNames() const { LOG(logERROR) - << "This is a generic function GetFilesInAcquisition that " + << "This is a generic function GetParameterNames that " "should be overloaded by a derived class"; return std::vector{}; }; - virtual std::vector GetParameterDataTypes() const { + virtual std::vector GetParameterDataTypes() const { LOG(logERROR) - << "This is a generic function GetFilesInAcquisition that " + << "This is a generic function GetParameterDataTypes that " "should be overloaded by a derived class"; - return std::vector{}; + return std::vector{}; }; virtual void CreateFirstHDF5DataFile( @@ -70,7 +67,7 @@ class File : private virtual slsDetectorDefs { const uint32_t maxFramesPerFile, const uint64_t numImages, const uint32_t nPixelsX, const uint32_t nPixelsY, const uint32_t dynamicRange) { - LOG(logERROR) << "This is a generic function CreateFirstDataFile that " + LOG(logERROR) << "This is a generic function CreateFirstHDF5DataFile that " "should be overloaded by a derived class"; }; #endif @@ -80,7 +77,7 @@ class File : private virtual slsDetectorDefs { const bool silentMode, const int modulePos, const int numUnitsPerReadout, const uint32_t udpPortNumber, const uint32_t maxFramesPerFile) { - LOG(logERROR) << "This is a generic function CreateFirstDataFile that " + LOG(logERROR) << "This is a generic function CreateFirstBinaryDataFile that " "should be overloaded by a derived class"; }; diff --git a/slsReceiverSoftware/src/HDF5DataFile.cpp b/slsReceiverSoftware/src/HDF5DataFile.cpp index 2d30b90c3..3af531145 100644 --- a/slsReceiverSoftware/src/HDF5DataFile.cpp +++ b/slsReceiverSoftware/src/HDF5DataFile.cpp @@ -26,44 +26,44 @@ HDF5DataFile::HDF5DataFile(int index, std::mutex *hdf5Lib) "detector header version", "packets caught bit mask", }; - StrType strdatatype(PredType::C_S1, sizeof(bitset_storage)); - parameterDataTypes_ = std::vector{ - PredType::STD_U64LE, PredType::STD_U32LE, PredType::STD_U32LE, - PredType::STD_U64LE, PredType::STD_U64LE, PredType::STD_U16LE, - PredType::STD_U16LE, PredType::STD_U16LE, PredType::STD_U16LE, - PredType::STD_U32LE, PredType::STD_U16LE, PredType::STD_U8LE, - PredType::STD_U8LE, strdatatype}; + H5::StrType strdatatype(H5::PredType::C_S1, sizeof(bitset_storage)); + parameterDataTypes_ = std::vector{ + H5::PredType::STD_U64LE, H5::PredType::STD_U32LE, H5::PredType::STD_U32LE, + H5::PredType::STD_U64LE, H5::PredType::STD_U64LE, H5::PredType::STD_U16LE, + H5::PredType::STD_U16LE, H5::PredType::STD_U16LE, H5::PredType::STD_U16LE, + H5::PredType::STD_U32LE, H5::PredType::STD_U16LE, H5::PredType::STD_U8LE, + H5::PredType::STD_U8LE, strdatatype}; } HDF5DataFile::~HDF5DataFile() { CloseFile(); } -std::array HDF5DataFile::GetFileAndDatasetName() const { - return std::array{fileName_, dataSetName_}; +std::string HDF5DataFile::GetFileName() const { + return fileName_; } uint32_t HDF5DataFile::GetFilesInAcquisition() const { return numFilesInAcquisition_; } -DataType HDF5DataFile::GetPDataType() const { return dataType_; } +H5::DataType HDF5DataFile::GetPDataType() const { return dataType_; } std::vector HDF5DataFile::GetParameterNames() const { return parameterNames_; } -std::vector HDF5DataFile::GetParameterDataTypes() const { +std::vector HDF5DataFile::GetParameterDataTypes() const { return parameterDataTypes_; } void HDF5DataFile::CloseFile() { std::lock_guard lock(*hdf5Lib_); try { - Exception::dontPrint(); // to handle errors + H5::Exception::dontPrint(); // to handle errors if (fd_) { fd_->close(); delete fd_; fd_ = nullptr; } - } catch (const Exception &error) { + } catch (const H5::Exception &error) { LOG(logERROR) << "Could not close data HDF5 handles of index " << index_; error.printErrorStack(); @@ -116,13 +116,13 @@ void HDF5DataFile::CreateFirstHDF5DataFile( switch (dynamicRange_) { case 12: case 16: - dataType_ = PredType::STD_U16LE; + dataType_ = H5::PredType::STD_U16LE; break; case 32: - dataType_ = PredType::STD_U32LE; + dataType_ = H5::PredType::STD_U32LE; break; default: - dataType_ = PredType::STD_U8LE; + dataType_ = H5::PredType::STD_U8LE; break; } @@ -153,42 +153,35 @@ void HDF5DataFile::CreateFile() { uint32_t nDimz = ((dynamicRange_ == 4) ? (nPixelsX_ / 2) : nPixelsX_); try { - Exception::dontPrint(); // to handle errors + H5::Exception::dontPrint(); // to handle errors // file - FileAccPropList fapl; + H5::FileAccPropList fapl; fapl.setFcloseDegree(H5F_CLOSE_STRONG); fd_ = nullptr; if (!overWriteEnable_) - fd_ = new H5File(fileName_.c_str(), H5F_ACC_EXCL, - FileCreatPropList::DEFAULT, fapl); + fd_ = new H5::H5File(fileName_.c_str(), H5F_ACC_EXCL, + H5::FileCreatPropList::DEFAULT, fapl); else - fd_ = new H5File(fileName_.c_str(), H5F_ACC_TRUNC, - FileCreatPropList::DEFAULT, fapl); + fd_ = new H5::H5File(fileName_.c_str(), H5F_ACC_TRUNC, + H5::FileCreatPropList::DEFAULT, fapl); // attributes - version double dValue = HDF5_WRITER_VERSION; - DataSpace dataspace_attr = DataSpace(H5S_SCALAR); - Attribute attribute = fd_->createAttribute( - "version", PredType::NATIVE_DOUBLE, dataspace_attr); - attribute.write(PredType::NATIVE_DOUBLE, &dValue); + H5::DataSpace dataspace_attr = H5::DataSpace(H5S_SCALAR); + H5::Attribute attribute = fd_->createAttribute( + "version", H5::PredType::NATIVE_DOUBLE, dataspace_attr); + attribute.write(H5::PredType::NATIVE_DOUBLE, &dValue); // dataspace hsize_t srcdims[3] = {nDimx, nDimy, nDimz}; hsize_t srcdimsmax[3] = {H5S_UNLIMITED, nDimy, nDimz}; dataSpace_ = nullptr; - dataSpace_ = new DataSpace(3, srcdims, srcdimsmax); - - // dataset name - std::ostringstream osfn; - osfn << "/data"; - if (numImages_ > 1) - osfn << "_f" << std::setfill('0') << std::setw(12) << subFileIndex_; - dataSetName_ = osfn.str(); + dataSpace_ = new H5::DataSpace(3, srcdims, srcdimsmax); // dataset // fill value - DSetCreatPropList plist; + H5::DSetCreatPropList plist; int fill_value = -1; plist.setFillValue(dataType_, &fill_value); // always create chunked dataset as unlimited is only @@ -196,28 +189,28 @@ void HDF5DataFile::CreateFile() { hsize_t chunk_dims[3] = {MAX_CHUNKED_IMAGES, nDimy, nDimz}; plist.setChunk(3, chunk_dims); dataSet_ = nullptr; - dataSet_ = new DataSet(fd_->createDataSet( - dataSetName_.c_str(), dataType_, *dataSpace_, plist)); + dataSet_ = new H5::DataSet(fd_->createDataSet( + DATASET_NAME, dataType_, *dataSpace_, plist)); // create parameter datasets hsize_t dims[1] = {nDimx}; hsize_t dimsmax[1] = {H5S_UNLIMITED}; dataSpacePara_ = nullptr; - dataSpacePara_ = new DataSpace(1, dims, dimsmax); + dataSpacePara_ = new H5::DataSpace(1, dims, dimsmax); // always create chunked dataset as unlimited is only // supported with chunked layout - DSetCreatPropList paralist; + H5::DSetCreatPropList paralist; hsize_t chunkpara_dims[3] = {MAX_CHUNKED_IMAGES}; paralist.setChunk(1, chunkpara_dims); for (unsigned int i = 0; i < parameterNames_.size(); ++i) { - DataSet *ds = new DataSet(fd_->createDataSet( + H5::DataSet *ds = new H5::DataSet(fd_->createDataSet( parameterNames_[i].c_str(), parameterDataTypes_[i], *dataSpacePara_, paralist)); dataSetPara_.push_back(ds); } - } catch (const Exception &error) { + } catch (const H5::Exception &error) { error.printErrorStack(); CloseFile(); throw RuntimeError("Could not create HDF5 handles in object " + @@ -287,16 +280,16 @@ void HDF5DataFile::WriteDataFile(const uint64_t currentFrameNumber, hsize_t start[3] = {nDimx, 0, 0}; hsize_t dims2[2] = {nDimy, nDimz}; try { - Exception::dontPrint(); // to handle errors + H5::Exception::dontPrint(); // to handle errors dataSpace_->selectHyperslab(H5S_SELECT_SET, count, start); - DataSpace memspace(2, dims2); + H5::DataSpace memspace(2, dims2); dataSet_->write(revBuffer, dataType_, memspace, *dataSpace_); memspace.close(); if (dynamicRange_ == 12) { free(revBuffer); } - } catch (const Exception &error) { + } catch (const H5::Exception &error) { if (dynamicRange_ == 12) { free(revBuffer); } @@ -320,9 +313,9 @@ void HDF5DataFile::WriteParameterDatasets(const uint64_t currentFrameNumber, hsize_t start[1] = {fnum}; int i = 0; try { - Exception::dontPrint(); // to handle errors + H5::Exception::dontPrint(); // to handle errors dataSpacePara_->selectHyperslab(H5S_SELECT_SET, count, start); - DataSpace memspace(H5S_SCALAR); + H5::DataSpace memspace(H5S_SCALAR); dataSetPara_[0]->write(&header.frameNumber, parameterDataTypes_[0], memspace, *dataSpacePara_); i = 1; @@ -383,7 +376,7 @@ void HDF5DataFile::WriteParameterDatasets(const uint64_t currentFrameNumber, memspace, *dataSpacePara_); } i = 14; - } catch (const Exception &error) { + } catch (const H5::Exception &error) { error.printErrorStack(); throw RuntimeError( "Could not write parameters (index:" + std::to_string(i) + @@ -395,7 +388,7 @@ void HDF5DataFile::ExtendDataset() { std::lock_guard lock(*hdf5Lib_); try { - Exception::dontPrint(); // to handle errors + H5::Exception::dontPrint(); // to handle errors hsize_t dims[3]; dataSpace_->getSimpleExtentDims(dims); @@ -404,16 +397,16 @@ void HDF5DataFile::ExtendDataset() { dataSet_->extend(dims); delete dataSpace_; dataSpace_ = nullptr; - dataSpace_ = new DataSpace(dataSet_->getSpace()); + dataSpace_ = new H5::DataSpace(dataSet_->getSpace()); hsize_t dims_para[1] = {dims[0]}; for (unsigned int i = 0; i < dataSetPara_.size(); ++i) dataSetPara_[i]->extend(dims_para); delete dataSpacePara_; dataSpacePara_ = nullptr; - dataSpacePara_ = new DataSpace(dataSetPara_[0]->getSpace()); + dataSpacePara_ = new H5::DataSpace(dataSetPara_[0]->getSpace()); - } catch (const Exception &error) { + } catch (const H5::Exception &error) { error.printErrorStack(); throw RuntimeError("Could not extend dataset in object " + std::to_string(index_)); diff --git a/slsReceiverSoftware/src/HDF5DataFile.h b/slsReceiverSoftware/src/HDF5DataFile.h index 7c0805ea7..a6d32ae15 100644 --- a/slsReceiverSoftware/src/HDF5DataFile.h +++ b/slsReceiverSoftware/src/HDF5DataFile.h @@ -14,11 +14,11 @@ class HDF5DataFile : private virtual slsDetectorDefs, public File { HDF5DataFile(const int index, std::mutex *hdf5Lib); ~HDF5DataFile(); - std::array GetFileAndDatasetName() const override; + std::string GetFileName() const override; uint32_t GetFilesInAcquisition() const override; - DataType GetPDataType() const override; + H5::DataType GetPDataType() const override; std::vector GetParameterNames() const override; - std::vector GetParameterDataTypes() const override; + std::vector GetParameterDataTypes() const override; void CloseFile() override; @@ -45,17 +45,17 @@ class HDF5DataFile : private virtual slsDetectorDefs, public File { int index_; std::mutex *hdf5Lib_; - H5File *fd_{nullptr}; + H5::H5File *fd_{nullptr}; std::string fileName_; std::string dataSetName_; - DataSpace *dataSpace_{nullptr}; - DataSet *dataSet_{nullptr}; - DataType dataType_{PredType::STD_U16LE}; + H5::DataSpace *dataSpace_{nullptr}; + H5::DataSet *dataSet_{nullptr}; + H5::DataType dataType_{H5::PredType::STD_U16LE}; - DataSpace *dataSpacePara_{nullptr}; - std::vector dataSetPara_{nullptr}; + H5::DataSpace *dataSpacePara_{nullptr}; + std::vector dataSetPara_{nullptr}; std::vector parameterNames_; - std::vector parameterDataTypes_; + std::vector parameterDataTypes_; uint32_t subFileIndex_{0}; uint32_t numFramesInFile_{0}; diff --git a/slsReceiverSoftware/src/Implementation.cpp b/slsReceiverSoftware/src/Implementation.cpp index 97c3719e2..d65c4c75c 100644 --- a/slsReceiverSoftware/src/Implementation.cpp +++ b/slsReceiverSoftware/src/Implementation.cpp @@ -915,11 +915,11 @@ void Implementation::StartMasterWriter() { } #ifdef HDF5C if (fileFormatType == HDF5) { - std::array virtualFileAndDatasetNames; + std::string virtualFileName; // create virtual hdf5 file (if multiple files) if (dataProcessor[0]->GetFilesInAcquisition() > 1 || (numPorts.x * numPorts.y) > 1) { - virtualFileAndDatasetNames = + virtualFileName = dataProcessor[0]->CreateVirtualFile( filePath, fileName, fileIndex, overwriteEnable, silentMode, modulePos, numUDPInterfaces, framesPerFile, @@ -929,8 +929,7 @@ void Implementation::StartMasterWriter() { // link file in master if (masterFileWriteEnable) { dataProcessor[0]->LinkFileInMaster( - masterFileName, virtualFileAndDatasetNames[0], - virtualFileAndDatasetNames[1], silentMode, &hdf5LibMutex); + masterFileName, virtualFileName, silentMode, &hdf5LibMutex); } } #endif diff --git a/slsReceiverSoftware/src/MasterAttributes.cpp b/slsReceiverSoftware/src/MasterAttributes.cpp index 8de7e2f9c..9047e86e8 100644 --- a/slsReceiverSoftware/src/MasterAttributes.cpp +++ b/slsReceiverSoftware/src/MasterAttributes.cpp @@ -1,6 +1,8 @@ // SPDX-License-Identifier: LGPL-3.0-or-other // Copyright (C) 2021 Contributors to the SLS Detector Package #include "MasterAttributes.h" +#include + namespace sls { @@ -39,7 +41,7 @@ void MasterAttributes::GetBinaryAttributes( } #ifdef HDF5C -void MasterAttributes::WriteHDF5Attributes(H5File *fd, Group *group) { +void MasterAttributes::WriteHDF5Attributes(H5::H5File *fd, H5::Group *group) { WriteCommonHDF5Attributes(fd, group); switch (detType) { case slsDetectorDefs::GOTTHARD: @@ -167,40 +169,40 @@ void MasterAttributes::GetFinalBinaryAttributes( } #ifdef HDF5C -void MasterAttributes::WriteCommonHDF5Attributes(H5File *fd, Group *group) { +void MasterAttributes::WriteCommonHDF5Attributes(H5::H5File *fd, H5::Group *group) { char c[1024]{}; // 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); + H5::DataSpace dataspace = H5::DataSpace(H5S_SCALAR); + H5::Attribute attribute = + fd->createAttribute("Version", H5::PredType::NATIVE_DOUBLE, dataspace); + attribute.write(H5::PredType::NATIVE_DOUBLE, &version); } // timestamp { - time_t t = time(nullptr); - StrType strdatatype(PredType::C_S1, 256); - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = + time_t t = std::time(nullptr); + H5::StrType strdatatype(H5::PredType::C_S1, 256); + H5::DataSpace dataspace = H5::DataSpace(H5S_SCALAR); + H5::DataSet dataset = group->createDataSet("Timestamp", strdatatype, dataspace); strcpy_safe(c, std::string(ctime(&t))); dataset.write(c, strdatatype); } // detector type { - DataSpace dataspace = DataSpace(H5S_SCALAR); - StrType strdatatype(PredType::C_S1, 256); - DataSet dataset = + H5::DataSpace dataspace = H5::DataSpace(H5S_SCALAR); + H5::StrType strdatatype(H5::PredType::C_S1, 256); + H5::DataSet dataset = group->createDataSet("Detector Type", strdatatype, dataspace); strcpy_safe(c, ToString(detType)); dataset.write(c, strdatatype); } // timing mode { - DataSpace dataspace = DataSpace(H5S_SCALAR); - StrType strdatatype(PredType::C_S1, 256); - DataSet dataset = + H5::DataSpace dataspace = H5::DataSpace(H5S_SCALAR); + H5::StrType strdatatype(H5::PredType::C_S1, 256); + H5::DataSet dataset = group->createDataSet("Timing Mode", strdatatype, dataspace); strcpy_safe(c, ToString(timingMode)); dataset.write(c, strdatatype); @@ -208,27 +210,27 @@ void MasterAttributes::WriteCommonHDF5Attributes(H5File *fd, Group *group) { // TODO: make this into an array? // geometry x { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group->createDataSet("Geometry in x axis", - PredType::NATIVE_INT, dataspace); - dataset.write(&geometry.x, PredType::NATIVE_INT); + H5::DataSpace dataspace = H5::DataSpace(H5S_SCALAR); + H5::DataSet dataset = group->createDataSet("Geometry in x axis", + H5::PredType::NATIVE_INT, dataspace); + dataset.write(&geometry.x, H5::PredType::NATIVE_INT); } // geometry y { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group->createDataSet("Geometry in y axis", - PredType::NATIVE_INT, dataspace); - dataset.write(&geometry.y, PredType::NATIVE_INT); + H5::DataSpace dataspace = H5::DataSpace(H5S_SCALAR); + H5::DataSet dataset = group->createDataSet("Geometry in y axis", + H5::PredType::NATIVE_INT, dataspace); + dataset.write(&geometry.y, H5::PredType::NATIVE_INT); } // Image Size { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = - group->createDataSet("Image Size", PredType::NATIVE_INT, dataspace); - dataset.write(&imageSize, PredType::NATIVE_INT); - DataSpace dataspaceAttr = DataSpace(H5S_SCALAR); - StrType strdatatype(PredType::C_S1, 256); - Attribute attribute = + H5::DataSpace dataspace = H5::DataSpace(H5S_SCALAR); + H5::DataSet dataset = + group->createDataSet("Image Size", H5::PredType::NATIVE_INT, dataspace); + dataset.write(&imageSize, H5::PredType::NATIVE_INT); + H5::DataSpace dataspaceAttr = H5::DataSpace(H5S_SCALAR); + H5::StrType strdatatype(H5::PredType::C_S1, 256); + H5::Attribute attribute = dataset.createAttribute("Unit", strdatatype, dataspaceAttr); strcpy_safe(c, "bytes"); attribute.write(strdatatype, c); @@ -236,335 +238,335 @@ void MasterAttributes::WriteCommonHDF5Attributes(H5File *fd, Group *group) { // TODO: make this into an array? // npixels x { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group->createDataSet("Number of pixels in x axis", - PredType::NATIVE_INT, dataspace); - dataset.write(&nPixels.x, PredType::NATIVE_INT); + H5::DataSpace dataspace = H5::DataSpace(H5S_SCALAR); + H5::DataSet dataset = group->createDataSet("Number of pixels in x axis", + H5::PredType::NATIVE_INT, dataspace); + dataset.write(&nPixels.x, H5::PredType::NATIVE_INT); } // npixels y { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group->createDataSet("Number of pixels in y axis", - PredType::NATIVE_INT, dataspace); - dataset.write(&nPixels.y, PredType::NATIVE_INT); + H5::DataSpace dataspace = H5::DataSpace(H5S_SCALAR); + H5::DataSet dataset = group->createDataSet("Number of pixels in y axis", + H5::PredType::NATIVE_INT, dataspace); + dataset.write(&nPixels.y, H5::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); + H5::DataSpace dataspace = H5::DataSpace(H5S_SCALAR); + H5::DataSet dataset = group->createDataSet("Maximum frames per file", + H5::PredType::NATIVE_INT, dataspace); + dataset.write(&maxFramesPerFile, H5::PredType::NATIVE_INT); } // Frame Discard Policy { - DataSpace dataspace = DataSpace(H5S_SCALAR); - StrType strdatatype(PredType::C_S1, 256); - DataSet dataset = group->createDataSet("Frame Discard Policy", + H5::DataSpace dataspace = H5::DataSpace(H5S_SCALAR); + H5::StrType strdatatype(H5::PredType::C_S1, 256); + H5::DataSet dataset = group->createDataSet("Frame Discard Policy", strdatatype, dataspace); strcpy_safe(c, ToString(frameDiscardMode)); dataset.write(c, strdatatype); } // Frame Padding { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group->createDataSet("Frame Padding", - PredType::NATIVE_INT, dataspace); - dataset.write(&framePadding, PredType::NATIVE_INT); + H5::DataSpace dataspace = H5::DataSpace(H5S_SCALAR); + H5::DataSet dataset = group->createDataSet("Frame Padding", + H5::PredType::NATIVE_INT, dataspace); + dataset.write(&framePadding, H5::PredType::NATIVE_INT); } // Scan Parameters { - DataSpace dataspace = DataSpace(H5S_SCALAR); - StrType strdatatype(PredType::C_S1, 256); - DataSet dataset = + H5::DataSpace dataspace = H5::DataSpace(H5S_SCALAR); + H5::StrType strdatatype(H5::PredType::C_S1, 256); + H5::DataSet dataset = group->createDataSet("Scan Parameters", strdatatype, dataspace); strcpy_safe(c, ToString(scanParams)); dataset.write(c, strdatatype); } // Total Frames { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group->createDataSet("Total Frames", - PredType::STD_U64LE, dataspace); - dataset.write(&totalFrames, PredType::STD_U64LE); + H5::DataSpace dataspace = H5::DataSpace(H5S_SCALAR); + H5::DataSet dataset = group->createDataSet("Total Frames", + H5::PredType::STD_U64LE, dataspace); + dataset.write(&totalFrames, H5::PredType::STD_U64LE); } // Receiver Roi xmin { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group->createDataSet("receiver roi xmin", - PredType::NATIVE_INT, dataspace); - dataset.write(&receiverRoi.xmin, PredType::NATIVE_INT); + H5::DataSpace dataspace = H5::DataSpace(H5S_SCALAR); + H5::DataSet dataset = group->createDataSet("receiver roi xmin", + H5::PredType::NATIVE_INT, dataspace); + dataset.write(&receiverRoi.xmin, H5::PredType::NATIVE_INT); } // Receiver Roi xmax { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group->createDataSet("receiver roi xmax", - PredType::NATIVE_INT, dataspace); - dataset.write(&receiverRoi.xmax, PredType::NATIVE_INT); + H5::DataSpace dataspace = H5::DataSpace(H5S_SCALAR); + H5::DataSet dataset = group->createDataSet("receiver roi xmax", + H5::PredType::NATIVE_INT, dataspace); + dataset.write(&receiverRoi.xmax, H5::PredType::NATIVE_INT); } // Receiver Roi ymin { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group->createDataSet("receiver roi ymin", - PredType::NATIVE_INT, dataspace); - dataset.write(&receiverRoi.ymin, PredType::NATIVE_INT); + H5::DataSpace dataspace = H5::DataSpace(H5S_SCALAR); + H5::DataSet dataset = group->createDataSet("receiver roi ymin", + H5::PredType::NATIVE_INT, dataspace); + dataset.write(&receiverRoi.ymin, H5::PredType::NATIVE_INT); } // Receiver Roi ymax { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group->createDataSet("receiver roi ymax", - PredType::NATIVE_INT, dataspace); - dataset.write(&receiverRoi.ymax, PredType::NATIVE_INT); + H5::DataSpace dataspace = H5::DataSpace(H5S_SCALAR); + H5::DataSet dataset = group->createDataSet("receiver roi ymax", + H5::PredType::NATIVE_INT, dataspace); + dataset.write(&receiverRoi.ymax, H5::PredType::NATIVE_INT); } } -void MasterAttributes::WriteFinalHDF5Attributes(H5File *fd, Group *group) { +void MasterAttributes::WriteFinalHDF5Attributes(H5::H5File *fd, H5::Group *group) { char c[1024]{}; // Total Frames in file { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group->createDataSet("Frames in File", - PredType::STD_U64LE, dataspace); - dataset.write(&framesInFile, PredType::STD_U64LE); + H5::DataSpace dataspace = H5::DataSpace(H5S_SCALAR); + H5::DataSet dataset = group->createDataSet("Frames in File", + H5::PredType::STD_U64LE, dataspace); + dataset.write(&framesInFile, H5::PredType::STD_U64LE); } // additional json header if (!additionalJsonHeader.empty()) { std::string json = ToString(additionalJsonHeader); - StrType strdatatype(PredType::C_S1, json.length()); - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group->createDataSet("Additional JSON Header", + H5::StrType strdatatype(H5::PredType::C_S1, json.length()); + H5::DataSpace dataspace = H5::DataSpace(H5S_SCALAR); + H5::DataSet dataset = group->createDataSet("Additional JSON Header", strdatatype, dataspace); strcpy_safe(c, ToString(additionalJsonHeader)); dataset.write(c, strdatatype); } } -void MasterAttributes::WriteHDF5Exptime(H5File *fd, Group *group) { - DataSpace dataspace = DataSpace(H5S_SCALAR); - StrType strdatatype(PredType::C_S1, 256); - DataSet dataset = +void MasterAttributes::WriteHDF5Exptime(H5::H5File *fd, H5::Group *group) { + H5::DataSpace dataspace = H5::DataSpace(H5S_SCALAR); + H5::StrType strdatatype(H5::PredType::C_S1, 256); + H5::DataSet dataset = group->createDataSet("Exposure Time", strdatatype, dataspace); char c[1024]{}; strcpy_safe(c, ToString(exptime)); dataset.write(c, strdatatype); } -void MasterAttributes::WriteHDF5Period(H5File *fd, Group *group) { - DataSpace dataspace = DataSpace(H5S_SCALAR); - StrType strdatatype(PredType::C_S1, 256); - DataSet dataset = +void MasterAttributes::WriteHDF5Period(H5::H5File *fd, H5::Group *group) { + H5::DataSpace dataspace = H5::DataSpace(H5S_SCALAR); + H5::StrType strdatatype(H5::PredType::C_S1, 256); + H5::DataSet dataset = group->createDataSet("Acquisition Period", strdatatype, dataspace); char c[1024]{}; strcpy_safe(c, ToString(period)); dataset.write(c, strdatatype); } -void MasterAttributes::WriteHDF5DynamicRange(H5File *fd, Group *group) { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = - group->createDataSet("Dynamic Range", PredType::NATIVE_INT, dataspace); - dataset.write(&dynamicRange, PredType::NATIVE_INT); - DataSpace dataspaceAttr = DataSpace(H5S_SCALAR); - StrType strdatatype(PredType::C_S1, 256); - Attribute attribute = +void MasterAttributes::WriteHDF5DynamicRange(H5::H5File *fd, H5::Group *group) { + H5::DataSpace dataspace = H5::DataSpace(H5S_SCALAR); + H5::DataSet dataset = + group->createDataSet("Dynamic Range", H5::PredType::NATIVE_INT, dataspace); + dataset.write(&dynamicRange, H5::PredType::NATIVE_INT); + H5::DataSpace dataspaceAttr = H5::DataSpace(H5S_SCALAR); + H5::StrType strdatatype(H5::PredType::C_S1, 256); + H5::Attribute attribute = dataset.createAttribute("Unit", strdatatype, dataspaceAttr); char c[1024] = "bits"; attribute.write(strdatatype, c); } -void MasterAttributes::WriteHDF5TenGiga(H5File *fd, Group *group) { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group->createDataSet("Ten Giga Enable", - PredType::NATIVE_INT, dataspace); - dataset.write(&tenGiga, PredType::NATIVE_INT); +void MasterAttributes::WriteHDF5TenGiga(H5::H5File *fd, H5::Group *group) { + H5::DataSpace dataspace = H5::DataSpace(H5S_SCALAR); + H5::DataSet dataset = group->createDataSet("Ten Giga Enable", + H5::PredType::NATIVE_INT, dataspace); + dataset.write(&tenGiga, H5::PredType::NATIVE_INT); } -void MasterAttributes::WriteHDF5ROI(H5File *fd, Group *group) { +void MasterAttributes::WriteHDF5ROI(H5::H5File *fd, H5::Group *group) { // Roi xmin { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = - group->createDataSet("roi xmin", PredType::NATIVE_INT, dataspace); - dataset.write(&detectorRoi.xmin, PredType::NATIVE_INT); + H5::DataSpace dataspace = H5::DataSpace(H5S_SCALAR); + H5::DataSet dataset = + group->createDataSet("roi xmin", H5::PredType::NATIVE_INT, dataspace); + dataset.write(&detectorRoi.xmin, H5::PredType::NATIVE_INT); } // Roi xmax { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = - group->createDataSet("roi xmax", PredType::NATIVE_INT, dataspace); - dataset.write(&detectorRoi.xmax, PredType::NATIVE_INT); + H5::DataSpace dataspace = H5::DataSpace(H5S_SCALAR); + H5::DataSet dataset = + group->createDataSet("roi xmax", H5::PredType::NATIVE_INT, dataspace); + dataset.write(&detectorRoi.xmax, H5::PredType::NATIVE_INT); } } -void MasterAttributes::WriteHDF5NumUDPInterfaces(H5File *fd, Group *group) { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group->createDataSet("Number of UDP Interfaces", - PredType::NATIVE_INT, dataspace); - dataset.write(&numUDPInterfaces, PredType::NATIVE_INT); +void MasterAttributes::WriteHDF5NumUDPInterfaces(H5::H5File *fd, H5::Group *group) { + H5::DataSpace dataspace = H5::DataSpace(H5S_SCALAR); + H5::DataSet dataset = group->createDataSet("Number of UDP Interfaces", + H5::PredType::NATIVE_INT, dataspace); + dataset.write(&numUDPInterfaces, H5::PredType::NATIVE_INT); } -void MasterAttributes::WriteHDF5ReadNRows(H5File *fd, Group *group) { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = - group->createDataSet("Number of rows", PredType::NATIVE_INT, dataspace); - dataset.write(&readNRows, PredType::NATIVE_INT); +void MasterAttributes::WriteHDF5ReadNRows(H5::H5File *fd, H5::Group *group) { + H5::DataSpace dataspace = H5::DataSpace(H5S_SCALAR); + H5::DataSet dataset = + group->createDataSet("Number of rows", H5::PredType::NATIVE_INT, dataspace); + dataset.write(&readNRows, H5::PredType::NATIVE_INT); } -void MasterAttributes::WriteHDF5ThresholdEnergy(H5File *fd, Group *group) { +void MasterAttributes::WriteHDF5ThresholdEnergy(H5::H5File *fd, H5::Group *group) { char c[1024]{}; - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group->createDataSet("Threshold Energy", - PredType::NATIVE_INT, dataspace); - dataset.write(&thresholdEnergyeV, PredType::NATIVE_INT); - DataSpace dataspaceAttr = DataSpace(H5S_SCALAR); - StrType strdatatype(PredType::C_S1, 256); - Attribute attribute = + H5::DataSpace dataspace = H5::DataSpace(H5S_SCALAR); + H5::DataSet dataset = group->createDataSet("Threshold Energy", + H5::PredType::NATIVE_INT, dataspace); + dataset.write(&thresholdEnergyeV, H5::PredType::NATIVE_INT); + H5::DataSpace dataspaceAttr = H5::DataSpace(H5S_SCALAR); + H5::StrType strdatatype(H5::PredType::C_S1, 256); + H5::Attribute attribute = dataset.createAttribute("Unit", strdatatype, dataspaceAttr); strcpy_safe(c, "eV"); attribute.write(strdatatype, c); } -void MasterAttributes::WriteHDF5ThresholdEnergies(H5File *fd, Group *group) { +void MasterAttributes::WriteHDF5ThresholdEnergies(H5::H5File *fd, H5::Group *group) { char c[1024]{}; - DataSpace dataspace = DataSpace(H5S_SCALAR); - StrType strdatatype(PredType::C_S1, 1024); - DataSet dataset = + H5::DataSpace dataspace = H5::DataSpace(H5S_SCALAR); + H5::StrType strdatatype(H5::PredType::C_S1, 1024); + H5::DataSet dataset = group->createDataSet("Threshold Energies", strdatatype, dataspace); strcpy_safe(c, ToString(thresholdAllEnergyeV)); dataset.write(c, strdatatype); } -void MasterAttributes::WriteHDF5SubExpTime(H5File *fd, Group *group) { +void MasterAttributes::WriteHDF5SubExpTime(H5::H5File *fd, H5::Group *group) { char c[1024]{}; - DataSpace dataspace = DataSpace(H5S_SCALAR); - StrType strdatatype(PredType::C_S1, 256); - DataSet dataset = + H5::DataSpace dataspace = H5::DataSpace(H5S_SCALAR); + H5::StrType strdatatype(H5::PredType::C_S1, 256); + H5::DataSet dataset = group->createDataSet("Sub Exposure Time", strdatatype, dataspace); strcpy_safe(c, ToString(subExptime)); dataset.write(c, strdatatype); } -void MasterAttributes::WriteHDF5SubPeriod(H5File *fd, Group *group) { +void MasterAttributes::WriteHDF5SubPeriod(H5::H5File *fd, H5::Group *group) { char c[1024]{}; - DataSpace dataspace = DataSpace(H5S_SCALAR); - StrType strdatatype(PredType::C_S1, 256); - DataSet dataset = + H5::DataSpace dataspace = H5::DataSpace(H5S_SCALAR); + H5::StrType strdatatype(H5::PredType::C_S1, 256); + H5::DataSet dataset = group->createDataSet("Sub Period", strdatatype, dataspace); strcpy_safe(c, ToString(subPeriod)); dataset.write(c, strdatatype); } -void MasterAttributes::WriteHDF5SubQuad(H5File *fd, Group *group) { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = - group->createDataSet("Quad", PredType::NATIVE_INT, dataspace); - dataset.write(&quad, PredType::NATIVE_INT); +void MasterAttributes::WriteHDF5SubQuad(H5::H5File *fd, H5::Group *group) { + H5::DataSpace dataspace = H5::DataSpace(H5S_SCALAR); + H5::DataSet dataset = + group->createDataSet("Quad", H5::PredType::NATIVE_INT, dataspace); + dataset.write(&quad, H5::PredType::NATIVE_INT); } -void MasterAttributes::WriteHDF5RateCorrections(H5File *fd, Group *group) { +void MasterAttributes::WriteHDF5RateCorrections(H5::H5File *fd, H5::Group *group) { char c[1024]{}; - DataSpace dataspace = DataSpace(H5S_SCALAR); - StrType strdatatype(PredType::C_S1, 1024); - DataSet dataset = + H5::DataSpace dataspace = H5::DataSpace(H5S_SCALAR); + H5::StrType strdatatype(H5::PredType::C_S1, 1024); + H5::DataSet dataset = group->createDataSet("Rate Corrections", strdatatype, dataspace); strcpy_safe(c, ToString(ratecorr)); dataset.write(c, strdatatype); } -void MasterAttributes::WriteHDF5CounterMask(H5File *fd, Group *group) { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = - group->createDataSet("Counter Mask", PredType::STD_U32LE, dataspace); - dataset.write(&counterMask, PredType::STD_U32LE); +void MasterAttributes::WriteHDF5CounterMask(H5::H5File *fd, H5::Group *group) { + H5::DataSpace dataspace = H5::DataSpace(H5S_SCALAR); + H5::DataSet dataset = + group->createDataSet("Counter Mask", H5::PredType::STD_U32LE, dataspace); + dataset.write(&counterMask, H5::PredType::STD_U32LE); } -void MasterAttributes::WriteHDF5ExptimeArray(H5File *fd, Group *group) { +void MasterAttributes::WriteHDF5ExptimeArray(H5::H5File *fd, H5::Group *group) { for (int i = 0; i != 3; ++i) { char c[1024]{}; - DataSpace dataspace = DataSpace(H5S_SCALAR); - StrType strdatatype(PredType::C_S1, 256); - DataSet dataset = + H5::DataSpace dataspace = H5::DataSpace(H5S_SCALAR); + H5::StrType strdatatype(H5::PredType::C_S1, 256); + H5::DataSet dataset = group->createDataSet("Exposure Time1", strdatatype, dataspace); strcpy_safe(c, ToString(exptimeArray[i])); dataset.write(c, strdatatype); } } -void MasterAttributes::WriteHDF5GateDelayArray(H5File *fd, Group *group) { +void MasterAttributes::WriteHDF5GateDelayArray(H5::H5File *fd, H5::Group *group) { for (int i = 0; i != 3; ++i) { char c[1024]{}; - DataSpace dataspace = DataSpace(H5S_SCALAR); - StrType strdatatype(PredType::C_S1, 256); - DataSet dataset = + H5::DataSpace dataspace = H5::DataSpace(H5S_SCALAR); + H5::StrType strdatatype(H5::PredType::C_S1, 256); + H5::DataSet dataset = group->createDataSet("Gate Delay1", strdatatype, dataspace); strcpy_safe(c, ToString(gateDelayArray[i])); dataset.write(c, strdatatype); } } -void MasterAttributes::WriteHDF5Gates(H5File *fd, Group *group) { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = - group->createDataSet("Gates", PredType::STD_U32LE, dataspace); - dataset.write(&gates, PredType::STD_U32LE); +void MasterAttributes::WriteHDF5Gates(H5::H5File *fd, H5::Group *group) { + H5::DataSpace dataspace = H5::DataSpace(H5S_SCALAR); + H5::DataSet dataset = + group->createDataSet("Gates", H5::PredType::STD_U32LE, dataspace); + dataset.write(&gates, H5::PredType::STD_U32LE); } -void MasterAttributes::WriteHDF5BurstMode(H5File *fd, Group *group) { - DataSpace dataspace = DataSpace(H5S_SCALAR); - StrType strdatatype(PredType::C_S1, 256); - DataSet dataset = +void MasterAttributes::WriteHDF5BurstMode(H5::H5File *fd, H5::Group *group) { + H5::DataSpace dataspace = H5::DataSpace(H5S_SCALAR); + H5::StrType strdatatype(H5::PredType::C_S1, 256); + H5::DataSet dataset = group->createDataSet("Burst Mode", strdatatype, dataspace); char c[1024]{}; strcpy_safe(c, ToString(burstMode)); dataset.write(c, strdatatype); } -void MasterAttributes::WriteHDF5AdcMask(H5File *fd, Group *group) { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = - group->createDataSet("ADC Mask", PredType::NATIVE_INT, dataspace); - dataset.write(&adcmask, PredType::NATIVE_INT); +void MasterAttributes::WriteHDF5AdcMask(H5::H5File *fd, H5::Group *group) { + H5::DataSpace dataspace = H5::DataSpace(H5S_SCALAR); + H5::DataSet dataset = + group->createDataSet("ADC Mask", H5::PredType::NATIVE_INT, dataspace); + dataset.write(&adcmask, H5::PredType::NATIVE_INT); } -void MasterAttributes::WriteHDF5AnalogFlag(H5File *fd, Group *group) { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = - group->createDataSet("Analog Flag", PredType::NATIVE_INT, dataspace); - dataset.write(&analog, PredType::NATIVE_INT); +void MasterAttributes::WriteHDF5AnalogFlag(H5::H5File *fd, H5::Group *group) { + H5::DataSpace dataspace = H5::DataSpace(H5S_SCALAR); + H5::DataSet dataset = + group->createDataSet("Analog Flag", H5::PredType::NATIVE_INT, dataspace); + dataset.write(&analog, H5::PredType::NATIVE_INT); } -void MasterAttributes::WriteHDF5AnalogSamples(H5File *fd, Group *group) { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = - group->createDataSet("Analog Samples", PredType::NATIVE_INT, dataspace); - dataset.write(&analogSamples, PredType::NATIVE_INT); +void MasterAttributes::WriteHDF5AnalogSamples(H5::H5File *fd, H5::Group *group) { + H5::DataSpace dataspace = H5::DataSpace(H5S_SCALAR); + H5::DataSet dataset = + group->createDataSet("Analog Samples", H5::PredType::NATIVE_INT, dataspace); + dataset.write(&analogSamples, H5::PredType::NATIVE_INT); } -void MasterAttributes::WriteHDF5DigitalFlag(H5File *fd, Group *group) { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = - group->createDataSet("Digital Flag", PredType::NATIVE_INT, dataspace); - dataset.write(&digital, PredType::NATIVE_INT); +void MasterAttributes::WriteHDF5DigitalFlag(H5::H5File *fd, H5::Group *group) { + H5::DataSpace dataspace = H5::DataSpace(H5S_SCALAR); + H5::DataSet dataset = + group->createDataSet("Digital Flag", H5::PredType::NATIVE_INT, dataspace); + dataset.write(&digital, H5::PredType::NATIVE_INT); } -void MasterAttributes::WriteHDF5DigitalSamples(H5File *fd, Group *group) { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group->createDataSet("Digital Samples", - PredType::NATIVE_INT, dataspace); - dataset.write(&digitalSamples, PredType::NATIVE_INT); +void MasterAttributes::WriteHDF5DigitalSamples(H5::H5File *fd, H5::Group *group) { + H5::DataSpace dataspace = H5::DataSpace(H5S_SCALAR); + H5::DataSet dataset = group->createDataSet("Digital Samples", + H5::PredType::NATIVE_INT, dataspace); + dataset.write(&digitalSamples, H5::PredType::NATIVE_INT); } -void MasterAttributes::WriteHDF5DbitOffset(H5File *fd, Group *group) { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = - group->createDataSet("Dbit Offset", PredType::NATIVE_INT, dataspace); - dataset.write(&dbitoffset, PredType::NATIVE_INT); +void MasterAttributes::WriteHDF5DbitOffset(H5::H5File *fd, H5::Group *group) { + H5::DataSpace dataspace = H5::DataSpace(H5S_SCALAR); + H5::DataSet dataset = + group->createDataSet("Dbit Offset", H5::PredType::NATIVE_INT, dataspace); + dataset.write(&dbitoffset, H5::PredType::NATIVE_INT); } -void MasterAttributes::WriteHDF5DbitList(H5File *fd, Group *group) { - DataSpace dataspace = DataSpace(H5S_SCALAR); - DataSet dataset = group->createDataSet("Dbit Bitset List", - PredType::STD_U64LE, dataspace); - dataset.write(&dbitlist, PredType::STD_U64LE); +void MasterAttributes::WriteHDF5DbitList(H5::H5File *fd, H5::Group *group) { + H5::DataSpace dataspace = H5::DataSpace(H5S_SCALAR); + H5::DataSet dataset = group->createDataSet("Dbit Bitset List", + H5::PredType::STD_U64LE, dataspace); + dataset.write(&dbitlist, H5::PredType::STD_U64LE); } #endif @@ -584,7 +586,7 @@ void MasterAttributes::GetGotthardBinaryAttributes( }; #ifdef HDF5C -void MasterAttributes::WriteGotthardHDF5Attributes(H5File *fd, Group *group) { +void MasterAttributes::WriteGotthardHDF5Attributes(H5::H5File *fd, H5::Group *group) { MasterAttributes::WriteHDF5Exptime(fd, group); MasterAttributes::WriteHDF5Period(fd, group); MasterAttributes::WriteHDF5ROI(fd, group); @@ -604,7 +606,7 @@ void MasterAttributes::GetJungfrauBinaryAttributes( } #ifdef HDF5C -void MasterAttributes::WriteJungfrauHDF5Attributes(H5File *fd, Group *group) { +void MasterAttributes::WriteJungfrauHDF5Attributes(H5::H5File *fd, H5::Group *group) { MasterAttributes::WriteHDF5Exptime(fd, group); MasterAttributes::WriteHDF5Period(fd, group); MasterAttributes::WriteHDF5NumUDPInterfaces(fd, group); @@ -637,7 +639,7 @@ void MasterAttributes::GetEigerBinaryAttributes( } #ifdef HDF5C -void MasterAttributes::WriteEigerHDF5Attributes(H5File *fd, Group *group) { +void MasterAttributes::WriteEigerHDF5Attributes(H5::H5File *fd, H5::Group *group) { MasterAttributes::WriteHDF5DynamicRange(fd, group); MasterAttributes::WriteHDF5TenGiga(fd, group); MasterAttributes::WriteHDF5Exptime(fd, group); @@ -676,7 +678,7 @@ void MasterAttributes::GetMythen3BinaryAttributes( } #ifdef HDF5C -void MasterAttributes::WriteMythen3HDF5Attributes(H5File *fd, Group *group) { +void MasterAttributes::WriteMythen3HDF5Attributes(H5::H5File *fd, H5::Group *group) { MasterAttributes::WriteHDF5DynamicRange(fd, group); MasterAttributes::WriteHDF5TenGiga(fd, group); MasterAttributes::WriteHDF5Period(fd, group); @@ -699,7 +701,7 @@ void MasterAttributes::GetGotthard2BinaryAttributes( } #ifdef HDF5C -void MasterAttributes::WriteGotthard2HDF5Attributes(H5File *fd, Group *group) { +void MasterAttributes::WriteGotthard2HDF5Attributes(H5::H5File *fd, H5::Group *group) { MasterAttributes::WriteHDF5Exptime(fd, group); MasterAttributes::WriteHDF5Period(fd, group); MasterAttributes::WriteHDF5BurstMode(fd, group); @@ -721,7 +723,7 @@ void MasterAttributes::GetMoenchBinaryAttributes( } #ifdef HDF5C -void MasterAttributes::WriteMoenchHDF5Attributes(H5File *fd, Group *group) { +void MasterAttributes::WriteMoenchHDF5Attributes(H5::H5File *fd, H5::Group *group) { MasterAttributes::WriteHDF5Exptime(fd, group); MasterAttributes::WriteHDF5Period(fd, group); MasterAttributes::WriteHDF5TenGiga(fd, group); @@ -755,7 +757,7 @@ void MasterAttributes::GetCtbBinaryAttributes( } #ifdef HDF5C -void MasterAttributes::WriteCtbHDF5Attributes(H5File *fd, Group *group) { +void MasterAttributes::WriteCtbHDF5Attributes(H5::H5File *fd, H5::Group *group) { MasterAttributes::WriteHDF5Exptime(fd, group); MasterAttributes::WriteHDF5Period(fd, group); MasterAttributes::WriteHDF5TenGiga(fd, group); diff --git a/slsReceiverSoftware/src/MasterAttributes.h b/slsReceiverSoftware/src/MasterAttributes.h index 5fbb0a41a..89dd4d1b1 100644 --- a/slsReceiverSoftware/src/MasterAttributes.h +++ b/slsReceiverSoftware/src/MasterAttributes.h @@ -11,16 +11,16 @@ #include #include +#ifdef HDF5C +#include "H5Cpp.h" +#endif + + namespace sls { using ns = std::chrono::nanoseconds; -#ifdef HDF5C -#include "H5Cpp.h" -#ifndef H5_NO_NAMESPACE -using namespace H5; -#endif -#endif + class MasterAttributes { public: @@ -71,7 +71,7 @@ class MasterAttributes { void GetBinaryAttributes(rapidjson::PrettyWriter *w); #ifdef HDF5C - void WriteHDF5Attributes(H5File *fd, Group *group); + void WriteHDF5Attributes(H5::H5File *fd, H5::Group *group); #endif void GetCommonBinaryAttributes( @@ -79,75 +79,75 @@ class MasterAttributes { void GetFinalBinaryAttributes( rapidjson::PrettyWriter *w); #ifdef HDF5C - void WriteCommonHDF5Attributes(H5File *fd, Group *group); - void WriteFinalHDF5Attributes(H5File *fd, Group *group); - void WriteHDF5Exptime(H5File *fd, Group *group); - void WriteHDF5Period(H5File *fd, Group *group); - void WriteHDF5DynamicRange(H5File *fd, Group *group); - void WriteHDF5TenGiga(H5File *fd, Group *group); - void WriteHDF5ROI(H5File *fd, Group *group); - void WriteHDF5NumUDPInterfaces(H5File *fd, Group *group); - void WriteHDF5ReadNRows(H5File *fd, Group *group); - void WriteHDF5ThresholdEnergy(H5File *fd, Group *group); - void WriteHDF5ThresholdEnergies(H5File *fd, Group *group); - void WriteHDF5SubExpTime(H5File *fd, Group *group); - void WriteHDF5SubPeriod(H5File *fd, Group *group); - void WriteHDF5SubQuad(H5File *fd, Group *group); - void WriteHDF5RateCorrections(H5File *fd, Group *group); - void WriteHDF5CounterMask(H5File *fd, Group *group); - void WriteHDF5ExptimeArray(H5File *fd, Group *group); - void WriteHDF5GateDelayArray(H5File *fd, Group *group); - void WriteHDF5Gates(H5File *fd, Group *group); - void WriteHDF5BurstMode(H5File *fd, Group *group); - void WriteHDF5AdcMask(H5File *fd, Group *group); - void WriteHDF5AnalogFlag(H5File *fd, Group *group); - void WriteHDF5AnalogSamples(H5File *fd, Group *group); - void WriteHDF5DigitalFlag(H5File *fd, Group *group); - void WriteHDF5DigitalSamples(H5File *fd, Group *group); - void WriteHDF5DbitOffset(H5File *fd, Group *group); - void WriteHDF5DbitList(H5File *fd, Group *group); + void WriteCommonHDF5Attributes(H5::H5File *fd, H5::Group *group); + void WriteFinalHDF5Attributes(H5::H5File *fd, H5::Group *group); + void WriteHDF5Exptime(H5::H5File *fd, H5::Group *group); + void WriteHDF5Period(H5::H5File *fd, H5::Group *group); + void WriteHDF5DynamicRange(H5::H5File *fd, H5::Group *group); + void WriteHDF5TenGiga(H5::H5File *fd, H5::Group *group); + void WriteHDF5ROI(H5::H5File *fd, H5::Group *group); + void WriteHDF5NumUDPInterfaces(H5::H5File *fd, H5::Group *group); + void WriteHDF5ReadNRows(H5::H5File *fd, H5::Group *group); + void WriteHDF5ThresholdEnergy(H5::H5File *fd, H5::Group *group); + void WriteHDF5ThresholdEnergies(H5::H5File *fd, H5::Group *group); + void WriteHDF5SubExpTime(H5::H5File *fd, H5::Group *group); + void WriteHDF5SubPeriod(H5::H5File *fd, H5::Group *group); + void WriteHDF5SubQuad(H5::H5File *fd, H5::Group *group); + void WriteHDF5RateCorrections(H5::H5File *fd, H5::Group *group); + void WriteHDF5CounterMask(H5::H5File *fd, H5::Group *group); + void WriteHDF5ExptimeArray(H5::H5File *fd, H5::Group *group); + void WriteHDF5GateDelayArray(H5::H5File *fd, H5::Group *group); + void WriteHDF5Gates(H5::H5File *fd, H5::Group *group); + void WriteHDF5BurstMode(H5::H5File *fd, H5::Group *group); + void WriteHDF5AdcMask(H5::H5File *fd, H5::Group *group); + void WriteHDF5AnalogFlag(H5::H5File *fd, H5::Group *group); + void WriteHDF5AnalogSamples(H5::H5File *fd, H5::Group *group); + void WriteHDF5DigitalFlag(H5::H5File *fd, H5::Group *group); + void WriteHDF5DigitalSamples(H5::H5File *fd, H5::Group *group); + void WriteHDF5DbitOffset(H5::H5File *fd, H5::Group *group); + void WriteHDF5DbitList(H5::H5File *fd, H5::Group *group); #endif void GetGotthardBinaryAttributes( rapidjson::PrettyWriter *w); #ifdef HDF5C - void WriteGotthardHDF5Attributes(H5File *fd, Group *group); + void WriteGotthardHDF5Attributes(H5::H5File *fd, H5::Group *group); #endif void GetJungfrauBinaryAttributes( rapidjson::PrettyWriter *w); #ifdef HDF5C - void WriteJungfrauHDF5Attributes(H5File *fd, Group *group); + void WriteJungfrauHDF5Attributes(H5::H5File *fd, H5::Group *group); #endif void GetEigerBinaryAttributes( rapidjson::PrettyWriter *w); #ifdef HDF5C - void WriteEigerHDF5Attributes(H5File *fd, Group *group); + void WriteEigerHDF5Attributes(H5::H5File *fd, H5::Group *group); #endif void GetMythen3BinaryAttributes( rapidjson::PrettyWriter *w); #ifdef HDF5C - void WriteMythen3HDF5Attributes(H5File *fd, Group *group); + void WriteMythen3HDF5Attributes(H5::H5File *fd, H5::Group *group); #endif void GetGotthard2BinaryAttributes( rapidjson::PrettyWriter *w); #ifdef HDF5C - void WriteGotthard2HDF5Attributes(H5File *fd, Group *group); + void WriteGotthard2HDF5Attributes(H5::H5File *fd, H5::Group *group); #endif void GetMoenchBinaryAttributes( rapidjson::PrettyWriter *w); #ifdef HDF5C - void WriteMoenchHDF5Attributes(H5File *fd, Group *group); + void WriteMoenchHDF5Attributes(H5::H5File *fd, H5::Group *group); #endif void GetCtbBinaryAttributes(rapidjson::PrettyWriter *w); #ifdef HDF5C - void WriteCtbHDF5Attributes(H5File *fd, Group *group); + void WriteCtbHDF5Attributes(H5::H5File *fd, H5::Group *group); #endif }; diff --git a/slsReceiverSoftware/src/MasterFileUtility.cpp b/slsReceiverSoftware/src/MasterFileUtility.cpp index 22ba0400d..2cf48c319 100644 --- a/slsReceiverSoftware/src/MasterFileUtility.cpp +++ b/slsReceiverSoftware/src/MasterFileUtility.cpp @@ -47,32 +47,31 @@ std::string CreateMasterBinaryFile(const std::string &filePath, } #ifdef HDF5C -void LinkHDF5FileInMaster(const std::string &masterFileName, - const std::string &dataFilename, - const std::string &dataSetname, - const std::vector parameterNames, +void LinkHDF5FileInMaster(std::string &masterFileName, + std::string &dataFilename, + std::vector parameterNames, const bool silentMode, std::mutex *hdf5LibMutex) { std::lock_guard lock(*hdf5LibMutex); - std::unique_ptr fd{nullptr}; + std::unique_ptr fd{nullptr}; try { - Exception::dontPrint(); // to handle errors + H5::Exception::dontPrint(); // to handle errors - FileAccPropList flist; + H5::FileAccPropList flist; flist.setFcloseDegree(H5F_CLOSE_STRONG); // open master file - H5File masterfd(masterFileName.c_str(), H5F_ACC_RDWR, - FileCreatPropList::DEFAULT, flist); + H5::H5File masterfd(masterFileName.c_str(), H5F_ACC_RDWR, + H5::FileCreatPropList::DEFAULT, flist); // open data file - fd = make_unique(dataFilename.c_str(), H5F_ACC_RDONLY, - FileCreatPropList::DEFAULT, flist); + fd = make_unique(dataFilename.c_str(), H5F_ACC_RDONLY, + H5::FileCreatPropList::DEFAULT, flist); // create link for data dataset - DataSet dset = fd->openDataSet(dataSetname.c_str()); - std::string linkname = std::string("/entry/data/") + dataSetname; - if (H5Lcreate_external(dataFilename.c_str(), dataSetname.c_str(), + H5::DataSet dset = fd->openDataSet(DATASET_NAME); + std::string linkname = std::string("/entry/data/") + std::string(DATASET_NAME); + if (H5Lcreate_external(dataFilename.c_str(), DATASET_NAME, masterfd.getLocId(), linkname.c_str(), H5P_DEFAULT, H5P_DEFAULT) < 0) { throw RuntimeError( @@ -81,7 +80,7 @@ void LinkHDF5FileInMaster(const std::string &masterFileName, // create link for parameter datasets for (unsigned int i = 0; i < parameterNames.size(); ++i) { - DataSet pDset = fd->openDataSet(parameterNames[i].c_str()); + H5::DataSet pDset = fd->openDataSet(parameterNames[i].c_str()); linkname = std::string("/entry/data/") + parameterNames[i]; if (H5Lcreate_external(dataFilename.c_str(), parameterNames[i].c_str(), @@ -93,7 +92,7 @@ void LinkHDF5FileInMaster(const std::string &masterFileName, } fd->close(); masterfd.close(); - } catch (const Exception &error) { + } catch (const H5::Exception &error) { error.printErrorStack(); if (fd != nullptr) fd->close(); @@ -118,38 +117,38 @@ std::string CreateMasterHDF5File(const std::string &filePath, std::lock_guard lock(*hdf5LibMutex); - std::unique_ptr fd{nullptr}; + std::unique_ptr fd{nullptr}; try { - Exception::dontPrint(); // to handle errors + H5::Exception::dontPrint(); // to handle errors - FileAccPropList flist; + H5::FileAccPropList flist; flist.setFcloseDegree(H5F_CLOSE_STRONG); unsigned int createFlags = H5F_ACC_EXCL; if (overWriteEnable) { createFlags = H5F_ACC_TRUNC; } - fd = make_unique(fileName.c_str(), createFlags, - FileCreatPropList::DEFAULT, flist); + fd = make_unique(fileName.c_str(), createFlags, + H5::FileCreatPropList::DEFAULT, flist); // attributes - version double dValue = HDF5_WRITER_VERSION; - DataSpace dataspace_attr = DataSpace(H5S_SCALAR); - Attribute attribute = fd->createAttribute( - "version", PredType::NATIVE_DOUBLE, dataspace_attr); - attribute.write(PredType::NATIVE_DOUBLE, &dValue); + H5::DataSpace dataspace_attr = H5::DataSpace(H5S_SCALAR); + H5::Attribute attribute = fd->createAttribute( + "version", H5::PredType::NATIVE_DOUBLE, dataspace_attr); + attribute.write(H5::PredType::NATIVE_DOUBLE, &dValue); // Create a group in the file - Group group1(fd->createGroup("entry")); - Group group2(group1.createGroup("data")); - Group group3(group1.createGroup("instrument")); - Group group4(group3.createGroup("beam")); - Group group5(group3.createGroup("detector")); - Group group6(group1.createGroup("sample")); + H5::Group group1(fd->createGroup("entry")); + H5::Group group2(group1.createGroup("data")); + H5::Group group3(group1.createGroup("instrument")); + H5::Group group4(group3.createGroup("beam")); + H5::Group group5(group3.createGroup("detector")); + H5::Group group6(group1.createGroup("sample")); attr->WriteHDF5Attributes(fd.get(), &group5); fd->close(); - } catch (const Exception &error) { + } catch (const H5::Exception &error) { error.printErrorStack(); if (fd != nullptr) fd->close(); @@ -162,16 +161,16 @@ std::string CreateMasterHDF5File(const std::string &filePath, return fileName; } -std::array CreateVirtualHDF5File( +std::string CreateVirtualHDF5File( const std::string &filePath, const std::string &fileNamePrefix, const uint64_t fileIndex, const bool overWriteEnable, const bool silentMode, const int modulePos, const int numUnitsPerReadout, - const uint32_t maxFramesPerFile, const uint64_t numImages, + const uint32_t maxFramesPerFile, const uint32_t nPixelsX, const uint32_t nPixelsY, const uint32_t dynamicRange, const uint64_t numImagesCaught, - const int numModX, const int numModY, const DataType dataType, + const int numModX, const int numModY, const H5::DataType dataType, const std::vector parameterNames, - const std::vector parameterDataTypes, std::mutex *hdf5LibMutex, + const std::vector parameterDataTypes, std::mutex *hdf5LibMutex, bool gotthard25um) { // virtual file name @@ -180,8 +179,6 @@ std::array CreateVirtualHDF5File( << "_" << fileIndex << ".h5"; std::string fileName = osfn.str(); - std::string dataSetName = "data"; - unsigned int paraSize = parameterNames.size(); uint64_t numModZ = numModX; uint32_t nDimy = nPixelsY; @@ -189,42 +186,42 @@ std::array CreateVirtualHDF5File( std::lock_guard lock(*hdf5LibMutex); - std::unique_ptr fd{nullptr}; + std::unique_ptr fd{nullptr}; try { - Exception::dontPrint(); // to handle errors + H5::Exception::dontPrint(); // to handle errors // file - FileAccPropList fapl; + H5::FileAccPropList fapl; fapl.setFcloseDegree(H5F_CLOSE_STRONG); if (!overWriteEnable) - fd = make_unique(fileName.c_str(), H5F_ACC_EXCL, - FileCreatPropList::DEFAULT, fapl); + fd = make_unique(fileName.c_str(), H5F_ACC_EXCL, + H5::FileCreatPropList::DEFAULT, fapl); else - fd = make_unique(fileName.c_str(), H5F_ACC_TRUNC, - FileCreatPropList::DEFAULT, fapl); + fd = make_unique(fileName.c_str(), H5F_ACC_TRUNC, + H5::FileCreatPropList::DEFAULT, fapl); // attributes - version double dValue = HDF5_WRITER_VERSION; - DataSpace dataspace_attr = DataSpace(H5S_SCALAR); - Attribute attribute = fd->createAttribute( - "version", PredType::NATIVE_DOUBLE, dataspace_attr); - attribute.write(PredType::NATIVE_DOUBLE, &dValue); + H5::DataSpace dataspace_attr = H5::DataSpace(H5S_SCALAR); + H5::Attribute attribute = fd->createAttribute( + "version", H5::PredType::NATIVE_DOUBLE, dataspace_attr); + attribute.write(H5::PredType::NATIVE_DOUBLE, &dValue); // virtual dataspace hsize_t vdsDims[3] = {numImagesCaught, numModY * nDimy, numModZ * nDimz}; - DataSpace vdsDataSpace(3, vdsDims, nullptr); + H5::DataSpace vdsDataSpace(3, vdsDims, nullptr); hsize_t vdsDimsPara[2] = {numImagesCaught, (unsigned int)numModY * numModZ}; - DataSpace vdsDataSpacePara(2, vdsDimsPara, nullptr); + H5::DataSpace vdsDataSpacePara(2, vdsDimsPara, nullptr); // property list (fill value and datatype) int fill_value = -1; - DSetCreatPropList plist; + H5::DSetCreatPropList plist; plist.setFillValue(dataType, &fill_value); // property list for parameters (datatype) - std::vector plistPara(paraSize); + std::vector plistPara(paraSize); // hyperslab (files) int numFiles = numImagesCaught / maxFramesPerFile; @@ -286,24 +283,17 @@ std::array CreateVirtualHDF5File( p + 1, srcFileName.length() - p)); } - // source dataset name - std::ostringstream osfn; - osfn << "/data"; - if (numImages > 1) - osfn << "_f" << std::setfill('0') << std::setw(12) << iFile; - std::string srcDatasetName = osfn.str(); - // source dataspace hsize_t srcDims[3] = {nDimx, nDimy, nDimz}; hsize_t srcDimsMax[3] = {H5S_UNLIMITED, nDimy, nDimz}; - DataSpace srcDataSpace(3, srcDims, srcDimsMax); + H5::DataSpace srcDataSpace(3, srcDims, srcDimsMax); hsize_t srcDimsPara[1] = {nDimx}; hsize_t srcDimsMaxPara[1] = {H5S_UNLIMITED}; - DataSpace srcDataSpacePara(1, srcDimsPara, srcDimsMaxPara); + H5::DataSpace srcDataSpacePara(1, srcDimsPara, srcDimsMaxPara); // mapping of property list plist.setVirtual(vdsDataSpace, relative_srcFileName.c_str(), - srcDatasetName.c_str(), srcDataSpace); + DATASET_NAME, srcDataSpace); for (unsigned int p = 0; p < paraSize; ++p) { plistPara[p].setVirtual( vdsDataSpacePara, relative_srcFileName.c_str(), @@ -325,17 +315,17 @@ std::array CreateVirtualHDF5File( framesSaved += nDimx; } // datasets - DataSet vdsDataSet(fd->createDataSet(dataSetName.c_str(), dataType, + H5::DataSet vdsDataSet(fd->createDataSet(DATASET_NAME, dataType, vdsDataSpace, plist)); for (unsigned int p = 0; p < paraSize; ++p) { - DataSet vdsDataSetPara(fd->createDataSet( + H5::DataSet vdsDataSetPara(fd->createDataSet( parameterNames[p].c_str(), parameterDataTypes[p], vdsDataSpacePara, plistPara[p])); } fd->close(); - } catch (const Exception &error) { + } catch (const H5::Exception &error) { error.printErrorStack(); if (fd) { fd->close(); @@ -346,7 +336,7 @@ std::array CreateVirtualHDF5File( if (!silentMode) { LOG(logINFO) << "Virtual File: " << fileName; } - return std::array{fileName, dataSetName}; + return fileName; } #endif diff --git a/slsReceiverSoftware/src/MasterFileUtility.h b/slsReceiverSoftware/src/MasterFileUtility.h index 4a4b0e136..bbce2f4e5 100644 --- a/slsReceiverSoftware/src/MasterFileUtility.h +++ b/slsReceiverSoftware/src/MasterFileUtility.h @@ -4,17 +4,13 @@ #include "MasterAttributes.h" +#include + namespace sls { namespace masterFileUtility { -#ifdef HDF5C -#include "H5Cpp.h" -#include -#ifndef H5_NO_NAMESPACE -using namespace H5; -#endif -#endif + std::string CreateMasterBinaryFile(const std::string &filePath, @@ -25,10 +21,9 @@ std::string CreateMasterBinaryFile(const std::string &filePath, MasterAttributes *attr); #ifdef HDF5C -void LinkHDF5FileInMaster(const std::string &masterFileName, - const std::string &dataFilename, - const std::string &dataSetname, - const std::vector parameterNames, +void LinkHDF5FileInMaster(std::string &masterFileName, + std::string &dataFilename, + std::vector parameterNames, const bool silentMode, std::mutex *hdf5LibMutex); std::string CreateMasterHDF5File(const std::string &filePath, @@ -38,16 +33,16 @@ std::string CreateMasterHDF5File(const std::string &filePath, const bool silentMode, MasterAttributes *attr, std::mutex *hdf5LibMutex); -std::array CreateVirtualHDF5File( +std::string CreateVirtualHDF5File( const std::string &filePath, const std::string &fileNamePrefix, const uint64_t fileIndex, const bool overWriteEnable, const bool silentMode, const int modulePos, const int numUnitsPerReadout, - const uint32_t maxFramesPerFile, const uint64_t numImages, + const uint32_t maxFramesPerFile, const uint32_t nPixelsX, const uint32_t nPixelsY, const uint32_t dynamicRange, const uint64_t numImagesCaught, - const int numModX, const int numModY, const DataType dataType, + const int numModX, const int numModY, const H5::DataType dataType, const std::vector parameterNames, - const std::vector parameterDataTypes, std::mutex *hdf5LibMutex, + const std::vector parameterDataTypes, std::mutex *hdf5LibMutex, bool gotthard25um); #endif } // namespace masterFileUtility diff --git a/slsReceiverSoftware/src/receiver_defs.h b/slsReceiverSoftware/src/receiver_defs.h index e65623e90..21dfeaa1a 100644 --- a/slsReceiverSoftware/src/receiver_defs.h +++ b/slsReceiverSoftware/src/receiver_defs.h @@ -37,7 +37,7 @@ namespace sls { #define FILE_BUFFER_SIZE (16 * 1024 * 1024) // 16mb // fifo -#define FIFO_HEADER_NUMBYTES (8) +#define FIFO_HEADER_NUMBYTES (16) #define FIFO_DATASIZE_NUMBYTES (4) #define FIFO_PADDING_NUMBYTES \ (4) // for 8 byte alignment due to sls_receiver_header structure @@ -59,4 +59,7 @@ namespace sls { #define TCP_PRIORITY (10) +#ifdef HDF5C +#define DATASET_NAME "/data" +#endif } // namespace sls diff --git a/slsSupportLib/include/sls/versionAPI.h b/slsSupportLib/include/sls/versionAPI.h index 97ff2a907..fb0049e27 100644 --- a/slsSupportLib/include/sls/versionAPI.h +++ b/slsSupportLib/include/sls/versionAPI.h @@ -2,13 +2,13 @@ // Copyright (C) 2021 Contributors to the SLS Detector Package /** API versions */ #define GITBRANCH "developer" -#define APILIB 0x220408 -#define APIRECEIVER 0x220408 -#define APIGUI 0x220328 #define APICTB 0x220524 #define APIGOTTHARD 0x220524 #define APIJUNGFRAU 0x220524 #define APIMOENCH 0x220519 #define APIEIGER 0x220524 -#define APIMYTHEN3 0x220602 #define APIGOTTHARD2 0x220602 +#define APIMYTHEN3 0x220607 +#define APILIB 0x220609 +#define APIRECEIVER 0x220609 +#define APIGUI 0x220609