From 4a97dd0ebad39fe7452de43c3122d185e33a1d38 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Fri, 9 Aug 2019 16:16:15 +0200 Subject: [PATCH] WIP --- slsDetectorSoftware/include/Detector.h | 84 ++++++++- .../include/multiSlsDetector.h | 19 +- slsDetectorSoftware/include/slsDetector.h | 2 + slsDetectorSoftware/src/Detector.cpp | 173 ++++++++++++++++-- slsDetectorSoftware/src/multiSlsDetector.cpp | 47 +---- slsDetectorSoftware/src/slsDetector.cpp | 4 + 6 files changed, 263 insertions(+), 66 deletions(-) diff --git a/slsDetectorSoftware/include/Detector.h b/slsDetectorSoftware/include/Detector.h index 2bc8a533d..753798e81 100644 --- a/slsDetectorSoftware/include/Detector.h +++ b/slsDetectorSoftware/include/Detector.h @@ -826,6 +826,88 @@ class Detector { */ void setDBITPipeline(int value, Positions pos = {}); + Result getDynamicRange(Positions pos = {}) const; + + /** + * (Eiger: + * Options: 4, 8, 16, 32 + * If i is 32, also sets clkdivider to 2, if 16, sets clkdivider to 1) + */ + void setDynamicRange(int value); + + Result getHighVoltage(Positions pos = {}) const; + + /** + * (Gotthard Options: 0, 90, 110, 120, 150, 180, 200) + * (Jungfrau, CTB Options: 0, 60 - 200) + * (Eiger Options: 0 - 200) + */ + void setHighVoltage(int value, Positions pos = {}); + + /** + * (Eiger) + */ + Result getIODelay(Positions pos = {}) const; + + /** + * (Eiger) + */ + void setIODelay(int value, Positions pos = {}); + + /** + * (Degrees) + * (Gotthard Options: TEMPERATURE_ADC, TEMPERATURE_FPGA) + * (Jungfrau Options: TEMPERATURE_ADC, TEMPERATURE_FPGA) + * (Eiger Options: TEMPERATURE_FPGA, TEMPERATURE_FPGAEXT, TEMPERATURE_10GE, + * TEMPERATURE_DCDC, TEMPERATURE_SODL, TEMPERATURE_SODR, TEMPERATURE_FPGA2, + * TEMPERATURE_FPGA3) (CTB Options: SLOW_ADC_TEMP) + */ + Result getTemp(defs::dacIndex index, Positions pos = {}) const; + + /** + * (CTB mV) + */ + Result getVrefVoltage(bool mV, Positions pos = {}) const; + + /** + * (CTB mV) + */ + void setVrefVoltage(int value, bool mV, Positions pos = {}); + + /** + * (CTB mV Options: V_LIMIT, V_POWER_A, V_POWER_B, V_POWER_C, + * V_POWER_D, V_POWER_IO, V_POWER_CHIP)) + */ + Result getVoltage(defs::dacIndex index, Positions pos = {}) const; + + /** + * (CTB mV Options: V_LIMIT, V_POWER_A, V_POWER_B, V_POWER_C, + * V_POWER_D, V_POWER_IO, V_POWER_CHIP) + */ + void setVoltage(int value, defs::dacIndex index, Positions pos = {}); + + /** + * (CTB mV Options: V_POWER_A, V_POWER_B, V_POWER_C, V_POWER_D, V_POWER_IO, + * V_POWER_CHIP) + */ + Result getMeasuredVoltage(defs::dacIndex index, + Positions pos = {}) const; + + /** + * (CTB mA Options: I_POWER_A, I_POWER_B, I_POWER_C, I_POWER_D, I_POWER_IO) + */ + Result getMeasuredCurrent(defs::dacIndex index, + Positions pos = {}) const; + + /** + * (CTB Options: SLOW_ADC0 - SLOW_ADC7) + */ + Result getSlowADC(defs::dacIndex index, Positions pos = {}) const; + + Result getDAC(defs::dacIndex index, bool mV, Positions pos = {}) const; + + void setDAC(int value, defs::dacIndex index, bool mV, Positions pos = {}); + // Erik Result getFramesCaughtByReceiver(Positions pos = {}) const; @@ -1233,7 +1315,7 @@ class Detector { int setDetectorMinMaxEnergyThreshold(const int index, int value); void setAdditionalJsonHeader(const std::string &jsonheader, - Positions pos = {}); + Positions pos = {}); Result getAdditionalJsonHeader(Positions pos = {}) const; }; diff --git a/slsDetectorSoftware/include/multiSlsDetector.h b/slsDetectorSoftware/include/multiSlsDetector.h index 4c8c85544..f177782f8 100755 --- a/slsDetectorSoftware/include/multiSlsDetector.h +++ b/slsDetectorSoftware/include/multiSlsDetector.h @@ -56,12 +56,6 @@ struct sharedMultiSlsDetector { /** Number of detectors operated at once */ int numberOfDetector[2]; - /** size of the data that are transfered from all detectors */ - int dataBytes; - - /** data bytes including gap pixels transferred from all detectors */ - int dataBytesInclGapPixels; - /** total number of channels for all detectors */ int numberOfChannels; @@ -863,14 +857,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns current dynamic range */ - int setDynamicRange(int dr = -1, int detPos = -1); - - /** - * Recalculated number of data bytes for multi detector - * @param detPos -1 for all detectors in list or specific detector position - * @returns tota number of data bytes for multi detector - */ - int getDataBytes(int detPos = -1); + int setDynamicRange(int dr = -1, int detPos = -1);// /** * Set/get dacs value @@ -880,7 +867,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns current DAC value */ - int setDAC(int val, dacIndex index, int mV, int detPos = -1); + int setDAC(int val, dacIndex index, int mV, int detPos = -1);// /** * Get adc value @@ -889,7 +876,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @returns current adc value (temperature for eiger and jungfrau in * millidegrees) */ - int getADC(dacIndex index, int detPos = -1); + int getADC(dacIndex index, int detPos = -1);// /** * Set/get timing mode diff --git a/slsDetectorSoftware/include/slsDetector.h b/slsDetectorSoftware/include/slsDetector.h index 9a270306a..cd9cc01e8 100755 --- a/slsDetectorSoftware/include/slsDetector.h +++ b/slsDetectorSoftware/include/slsDetector.h @@ -696,6 +696,8 @@ class slsDetector : public virtual slsDetectorDefs { */ int setDynamicRange(int n = -1); + int getDynamicRangeFromShm(); + /** * Recalculated number of data bytes * @returns tota number of data bytes diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index 0cee028d1..7f288e641 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -468,7 +468,8 @@ Result Detector::getMeasuredSubFramePeriod(Positions pos) const { } Result Detector::getSpeed(Positions pos) const { - return pimpl->Parallel(&slsDetector::setSpeed, pos, defs::CLOCK_DIVIDER, -1, 0); + return pimpl->Parallel(&slsDetector::setSpeed, pos, defs::CLOCK_DIVIDER, -1, + 0); } void Detector::setSpeed(int value, Positions pos) { @@ -476,7 +477,8 @@ void Detector::setSpeed(int value, Positions pos) { } Result Detector::getADCPhase(bool inDeg, Positions pos) const { - return pimpl->Parallel(&slsDetector::setSpeed, pos, defs::ADC_PHASE, -1, inDeg); + return pimpl->Parallel(&slsDetector::setSpeed, pos, defs::ADC_PHASE, -1, + inDeg); } void Detector::setADCPhase(int value, bool inDeg, Positions pos) { @@ -484,19 +486,23 @@ void Detector::setADCPhase(int value, bool inDeg, Positions pos) { } Result Detector::getMaxADCPhaseShift(Positions pos) const { - return pimpl->Parallel(&slsDetector::setSpeed, pos, defs::MAX_ADC_PHASE_SHIFT, -1, 0); + return pimpl->Parallel(&slsDetector::setSpeed, pos, + defs::MAX_ADC_PHASE_SHIFT, -1, 0); } Result Detector::getDBITPhase(bool inDeg, Positions pos) const { - return pimpl->Parallel(&slsDetector::setSpeed, pos, defs::DBIT_PHASE, -1, inDeg); + return pimpl->Parallel(&slsDetector::setSpeed, pos, defs::DBIT_PHASE, -1, + inDeg); } void Detector::setDBITPhase(int value, bool inDeg, Positions pos) { - pimpl->Parallel(&slsDetector::setSpeed, pos, defs::DBIT_PHASE, value, inDeg); + pimpl->Parallel(&slsDetector::setSpeed, pos, defs::DBIT_PHASE, value, + inDeg); } Result Detector::getMaxDBITPhaseShift(Positions pos) const { - return pimpl->Parallel(&slsDetector::setSpeed, pos, defs::MAX_DBIT_PHASE_SHIFT, -1, 0); + return pimpl->Parallel(&slsDetector::setSpeed, pos, + defs::MAX_DBIT_PHASE_SHIFT, -1, 0); } Result Detector::getADCClock(Positions pos) const { @@ -508,7 +514,8 @@ void Detector::setADCClock(int value, Positions pos) { } Result Detector::getDBITClock(Positions pos) const { - return pimpl->Parallel(&slsDetector::setSpeed, pos, defs::DBIT_CLOCK, -1, 0); + return pimpl->Parallel(&slsDetector::setSpeed, pos, defs::DBIT_CLOCK, -1, + 0); } void Detector::setDBITClock(int value, Positions pos) { @@ -516,7 +523,8 @@ void Detector::setDBITClock(int value, Positions pos) { } Result Detector::getRUNClock(Positions pos) const { - return pimpl->Parallel(&slsDetector::setSpeed, pos, defs::CLOCK_DIVIDER, -1, 0); + return pimpl->Parallel(&slsDetector::setSpeed, pos, defs::CLOCK_DIVIDER, -1, + 0); } void Detector::setRUNClock(int value, Positions pos) { @@ -524,11 +532,13 @@ void Detector::setRUNClock(int value, Positions pos) { } Result Detector::getSYNCClock(Positions pos) const { - return pimpl->Parallel(&slsDetector::setSpeed, pos, defs::SYNC_CLOCK, -1, 0); + return pimpl->Parallel(&slsDetector::setSpeed, pos, defs::SYNC_CLOCK, -1, + 0); } Result Detector::getADCPipeline(Positions pos) const { - return pimpl->Parallel(&slsDetector::setSpeed, pos, defs::ADC_PIPELINE, -1, 0); + return pimpl->Parallel(&slsDetector::setSpeed, pos, defs::ADC_PIPELINE, -1, + 0); } void Detector::setADCPipeline(int value, Positions pos) { @@ -536,13 +546,154 @@ void Detector::setADCPipeline(int value, Positions pos) { } Result Detector::getDBITPipeline(Positions pos) const { - return pimpl->Parallel(&slsDetector::setSpeed, pos, defs::DBIT_PIPELINE, -1, 0); + return pimpl->Parallel(&slsDetector::setSpeed, pos, defs::DBIT_PIPELINE, -1, + 0); } void Detector::setDBITPipeline(int value, Positions pos) { pimpl->Parallel(&slsDetector::setSpeed, pos, defs::DBIT_PIPELINE, value, 0); } +Result Detector::getDynamicRange(Positions pos) const { + return pimpl->Parallel(&slsDetector::setDynamicRange, pos, -1); +} + +void Detector::setDynamicRange(int value) { pimpl->setDynamicRange(value); } + +Result Detector::getHighVoltage(Positions pos) const { + return pimpl->Parallel(&slsDetector::setDAC, pos, -1, defs::HIGH_VOLTAGE, + 0); +} + +void Detector::setHighVoltage(int value, Positions pos) { + pimpl->Parallel(&slsDetector::setDAC, pos, value, defs::HIGH_VOLTAGE, 0); +} + +Result Detector::getIODelay(Positions pos) const { + return pimpl->Parallel(&slsDetector::setDAC, pos, -1, defs::IO_DELAY, 0); +} + +void Detector::setIODelay(int value, Positions pos) { + pimpl->Parallel(&slsDetector::setDAC, pos, value, defs::IO_DELAY, 0); +} + +Result Detector::getTemp(defs::dacIndex index, Positions pos) const { + switch (index) { + case defs::TEMPERATURE_ADC: + case defs::TEMPERATURE_FPGA: + case defs::TEMPERATURE_FPGAEXT: + case defs::TEMPERATURE_10GE: + case defs::TEMPERATURE_DCDC: + case defs::TEMPERATURE_SODL: + case defs::TEMPERATURE_SODR: + case defs::TEMPERATURE_FPGA2: + case defs::TEMPERATURE_FPGA3: + case defs::SLOW_ADC_TEMP: + break; + default: + throw RuntimeError("Unknown Temperature Index"); + } + auto res = pimpl->Parallel(&slsDetector::getADC, pos, index); + switch (getDetectorType()) { + case defs::EIGER: + case defs::JUNGFRAU: + for (auto it : pos) { + it /= 1000; + } + break; + default: + break; + } + return res; +} + +Result Detector::getVrefVoltage(bool mV, Positions pos) const { + return pimpl->Parallel(&slsDetector::setDAC, pos, -1, defs::ADC_VPP, mV); +} + +void Detector::setVrefVoltage(int value, bool mV, Positions pos) { + pimpl->Parallel(&slsDetector::setDAC, pos, value, defs::ADC_VPP, mV); +} + +Result Detector::getVoltage(defs::dacIndex index, Positions pos) const { + switch (index) { + case defs::V_LIMIT: + case defs::V_POWER_A: + case defs::V_POWER_B: + case defs::V_POWER_C: + case defs::V_POWER_D: + case defs::V_POWER_IO: + case defs::V_POWER_CHIP: + break; + default: + throw RuntimeError("Unknown Voltage Index"); + } + return pimpl->Parallel(&slsDetector::setDAC, pos, -1, index, 1); +} + +void Detector::setVoltage(int value, defs::dacIndex index, Positions pos) { + switch (index) { + case defs::V_LIMIT: + case defs::V_POWER_A: + case defs::V_POWER_B: + case defs::V_POWER_C: + case defs::V_POWER_D: + case defs::V_POWER_IO: + case defs::V_POWER_CHIP: + break; + default: + throw RuntimeError("Unknown Voltage Index"); + } + pimpl->Parallel(&slsDetector::setDAC, pos, value, index, 1); +} + +Result Detector::getMeasuredVoltage(defs::dacIndex index, + Positions pos) const { + switch (index) { + case defs::V_POWER_A: + case defs::V_POWER_B: + case defs::V_POWER_C: + case defs::V_POWER_D: + case defs::V_POWER_IO: + case defs::V_POWER_CHIP: + break; + default: + throw RuntimeError("Unknown Voltage Index"); + } + return pimpl->Parallel(&slsDetector::getADC, pos, index); +} + +Result Detector::getMeasuredCurrent(defs::dacIndex index, + Positions pos) const { + switch (index) { + case defs::I_POWER_A: + case defs::I_POWER_B: + case defs::I_POWER_C: + case defs::I_POWER_D: + case defs::I_POWER_IO: + break; + default: + throw RuntimeError("Unknown Current Index"); + } + return pimpl->Parallel(&slsDetector::getADC, pos, index); +} + +Result Detector::getSlowADC(defs::dacIndex index, Positions pos) const { + if (index < defs::SLOW_ADC0 || index > defs::SLOW_ADC7) { + throw RuntimeError("Unknown Slow ADC Index"); + } + return pimpl->Parallel(&slsDetector::getADC, pos, index); +} + +Result Detector::getDAC(defs::dacIndex index, bool mV, + Positions pos) const { + return pimpl->Parallel(&slsDetector::setDAC, pos, -1, index, mV); +} + +void Detector::setDAC(int value, defs::dacIndex index, bool mV, Positions pos) { + pimpl->Parallel(&slsDetector::setDAC, pos, value, index, mV); +} + // Erik Result Detector::getFramesCaughtByReceiver(Positions pos) const { return pimpl->Parallel(&slsDetector::getFramesCaughtByReceiver, pos); diff --git a/slsDetectorSoftware/src/multiSlsDetector.cpp b/slsDetectorSoftware/src/multiSlsDetector.cpp index 843fb1f41..919159bd6 100755 --- a/slsDetectorSoftware/src/multiSlsDetector.cpp +++ b/slsDetectorSoftware/src/multiSlsDetector.cpp @@ -278,8 +278,6 @@ void multiSlsDetector::initializeDetectorStructure() { multi_shm()->multiDetectorType = GENERIC; multi_shm()->numberOfDetector[X] = 0; multi_shm()->numberOfDetector[Y] = 0; - multi_shm()->dataBytes = 0; - multi_shm()->dataBytesInclGapPixels = 0; multi_shm()->numberOfChannels = 0; multi_shm()->numberOfChannel[X] = 0; multi_shm()->numberOfChannel[Y] = 0; @@ -624,9 +622,6 @@ void multiSlsDetector::addSlsDetector(const std::string &hostname) { detectors.push_back( sls::make_unique(type, multiId, pos, false)); multi_shm()->numberOfDetectors = detectors.size(); - multi_shm()->dataBytes += detectors[pos]->getDataBytes(); - multi_shm()->dataBytesInclGapPixels += - detectors[pos]->getDataBytesInclGapPixels(); multi_shm()->numberOfChannels += detectors[pos]->getTotalNumberOfChannels(); detectors[pos]->setHostname(hostname); @@ -1264,22 +1259,18 @@ int multiSlsDetector::setDynamicRange(int dr, int detPos) { } // multi + int prevValue = -1; + auto temp = Parallel(&slsDetector::getDynamicRangeFromShm, {}); + if (temp.equal()) { + prevValue = temp.squash(); + } + auto r = parallelCall(&slsDetector::setDynamicRange, dr); int ret = sls::minusOneIfDifferent(r); - // update shm - int prevValue = multi_shm()->dataBytes; - int prevGValue = multi_shm()->dataBytesInclGapPixels; - multi_shm()->dataBytes = 0; - multi_shm()->dataBytesInclGapPixels = 0; - for (auto &d : detectors) { - multi_shm()->dataBytes += d->getDataBytes(); - multi_shm()->dataBytesInclGapPixels += d->getDataBytesInclGapPixels(); - } - - // if there was a change FIXME:add dr to sls shm and check that instead - if ((prevValue != multi_shm()->dataBytes) || - (prevGValue != multi_shm()->dataBytesInclGapPixels)) { + + // change in dr + if (dr != -1 && dr != prevValue) { updateOffsets(); @@ -1312,17 +1303,6 @@ int multiSlsDetector::setDynamicRange(int dr, int detPos) { return ret; } -int multiSlsDetector::getDataBytes(int detPos) { - // single - if (detPos >= 0) { - return detectors[detPos]->getDataBytes(); - } - - // multi - auto r = parallelCall(&slsDetector::getDataBytes); - return sls::sum(r); -} - int multiSlsDetector::setDAC(int val, dacIndex index, int mV, int detPos) { // single if (detPos >= 0) { @@ -2699,12 +2679,7 @@ int multiSlsDetector::enableGapPixels(int val, int detPos) { auto r = parallelCall(&slsDetector::enableGapPixels, val); int ret = sls::minusOneIfDifferent(r); - // update data bytes incl gap pixels if (val != -1) { - auto r2 = serialCall(&slsDetector::getDataBytesInclGapPixels); - multi_shm()->dataBytesInclGapPixels = sls::sum(r2); - - // update updateOffsets(); } return ret; @@ -2713,11 +2688,7 @@ int multiSlsDetector::enableGapPixels(int val, int detPos) { void multiSlsDetector::setGapPixelsEnable(bool enable, Positions pos){ Parallel(&slsDetector::enableGapPixels, pos, static_cast(enable)); - // update data bytes incl gap pixels - auto r2 = serialCall(&slsDetector::getDataBytesInclGapPixels); - multi_shm()->dataBytesInclGapPixels = sls::sum(r2); updateOffsets(); - } int multiSlsDetector::setTrimEn(std::vector energies, int detPos) { diff --git a/slsDetectorSoftware/src/slsDetector.cpp b/slsDetectorSoftware/src/slsDetector.cpp index 0f23a319a..37ef4f634 100755 --- a/slsDetectorSoftware/src/slsDetector.cpp +++ b/slsDetectorSoftware/src/slsDetector.cpp @@ -1539,6 +1539,10 @@ int slsDetector::setDynamicRange(int n) { return shm()->dynamicRange; } +int slsDetector::getDynamicRangeFromShm() { + return shm()->dynamicRange; +} + int slsDetector::getDataBytes() { return shm()->dataBytes; } int slsDetector::getDataBytesInclGapPixels() {