slsDetector -> Module

This commit is contained in:
Erik Frojdh 2020-03-11 16:16:15 +01:00
parent 012c66bbbf
commit 5784ce8231
7 changed files with 734 additions and 725 deletions

View File

@ -4,7 +4,7 @@
#include "ClientSocket.h" #include "ClientSocket.h"
#include "logger.h" #include "logger.h"
#include "DetectorImpl.h" #include "DetectorImpl.h"
#include "slsDetector.h" #include "Module.h"
#include "sls_detector_defs.h" #include "sls_detector_defs.h"
#include "Timer.h" #include "Timer.h"
@ -23,10 +23,10 @@
// extern dt type; // extern dt type;
TEST_CASE("Single detector no receiver", "[.integration][.single]") { TEST_CASE("Single detector no receiver", "[.integration][.single]") {
auto t = slsDetector::getTypeFromDetector(test::hostname); auto t = Module::getTypeFromDetector(test::hostname);
CHECK(t == test::type); CHECK(t == test::type);
slsDetector d(t); Module d(t);
CHECK(d.getDetectorTypeAsEnum() == t); CHECK(d.getDetectorTypeAsEnum() == t);
CHECK(d.getDetectorTypeAsString() == test::detector_type); CHECK(d.getDetectorTypeAsString() == test::detector_type);
@ -51,7 +51,7 @@ TEST_CASE("Set control port then create a new object with this control port",
int new_cport = 1993; int new_cport = 1993;
int new_sport = 2000; int new_sport = 2000;
{ {
slsDetector d(test::type); Module d(test::type);
d.setHostname(test::hostname); d.setHostname(test::hostname);
CHECK(d.getControlPort() == old_cport); CHECK(d.getControlPort() == old_cport);
d.setControlPort(new_cport); d.setControlPort(new_cport);
@ -60,7 +60,7 @@ TEST_CASE("Set control port then create a new object with this control port",
d.freeSharedMemory(); d.freeSharedMemory();
} }
{ {
slsDetector d(test::type); Module d(test::type);
d.setHostname(test::hostname); d.setHostname(test::hostname);
d.setControlPort(new_cport); d.setControlPort(new_cport);
d.setStopPort(new_sport); d.setStopPort(new_sport);
@ -73,7 +73,7 @@ TEST_CASE("Set control port then create a new object with this control port",
d.freeSharedMemory(); d.freeSharedMemory();
} }
slsDetector d(test::type); Module d(test::type);
d.setHostname(test::hostname); d.setHostname(test::hostname);
CHECK(d.getStopPort() == DEFAULT_PORTNO + 1); CHECK(d.getStopPort() == DEFAULT_PORTNO + 1);
d.freeSharedMemory(); d.freeSharedMemory();
@ -86,11 +86,11 @@ TEST_CASE("single EIGER detector no receiver basic set and get",
SingleDetectorConfig c; SingleDetectorConfig c;
// Read type by connecting to the detector // Read type by connecting to the detector
auto type = slsDetector::getTypeFromDetector(c.hostname); auto type = Module::getTypeFromDetector(c.hostname);
CHECK(type == c.type_enum); CHECK(type == c.type_enum);
// Create slsDetector of said type and set hostname and detector online // Create Module of said type and set hostname and detector online
slsDetector d(type); Module d(type);
CHECK(d.getDetectorTypeAsEnum() == type); CHECK(d.getDetectorTypeAsEnum() == type);
CHECK(d.getDetectorTypeAsString() == c.type_string); CHECK(d.getDetectorTypeAsString() == c.type_string);
@ -133,7 +133,7 @@ TEST_CASE("single EIGER detector no receiver basic set and get",
TEST_CASE("Locking mechanism and last ip", "[.integration][.single]") { TEST_CASE("Locking mechanism and last ip", "[.integration][.single]") {
slsDetector d(test::type); Module d(test::type);
d.setHostname(test::hostname); d.setHostname(test::hostname);
// Check that detector server is unlocked then lock // Check that detector server is unlocked then lock
@ -155,7 +155,7 @@ TEST_CASE("Locking mechanism and last ip", "[.integration][.single]") {
} }
TEST_CASE("Set settings", "[.integration][.single]"){ TEST_CASE("Set settings", "[.integration][.single]"){
slsDetector d(test::type); Module d(test::type);
d.setHostname(test::hostname); d.setHostname(test::hostname);
CHECK(d.setSettings(defs::STANDARD) == defs::STANDARD); CHECK(d.setSettings(defs::STANDARD) == defs::STANDARD);
} }
@ -185,7 +185,7 @@ TEST_CASE("Timer functions", "[.integration][cli]") {
// MEASURED_SUBPERIOD, /**< measured subperiod */ // MEASURED_SUBPERIOD, /**< measured subperiod */
// MAX_TIMERS // MAX_TIMERS
slsDetector d(test::type); Module d(test::type);
d.setHostname(test::hostname); d.setHostname(test::hostname);
// Number of frames // Number of frames
@ -226,8 +226,8 @@ TEST_CASE("Timer functions", "[.integration][cli]") {
// TEST_CASE("Aquire", "[.integration][eiger]"){ // TEST_CASE("Aquire", "[.integration][eiger]"){
// SingleDetectorConfig c; // SingleDetectorConfig c;
// auto type = slsDetector::getTypeFromDetector(c.hostname); // auto type = Module::getTypeFromDetector(c.hostname);
// slsDetector d(type); // Module d(type);
// d.setHostname(c.hostname); // d.setHostname(c.hostname);
// auto period = 1000000000; // auto period = 1000000000;

View File

@ -1,7 +1,7 @@
set(SOURCES set(SOURCES
src/DetectorImpl.cpp src/DetectorImpl.cpp
src/slsDetectorUsers.cpp src/slsDetectorUsers.cpp
src/slsDetector.cpp src/Module.cpp
src/Detector.cpp src/Detector.cpp
src/CmdProxy.cpp src/CmdProxy.cpp
src/CmdParser.cpp src/CmdParser.cpp

File diff suppressed because it is too large Load Diff

View File

@ -4,7 +4,7 @@
#include "detectorData.h" #include "detectorData.h"
#include "file_utils.h" #include "file_utils.h"
#include "logger.h" #include "logger.h"
#include "slsDetector.h" #include "Module.h"
#include "sls_detector_exceptions.h" #include "sls_detector_exceptions.h"
#include "versionAPI.h" #include "versionAPI.h"
@ -172,7 +172,7 @@ void DetectorImpl::initializeMembers(bool verify) {
for (int i = 0; i < multi_shm()->numberOfDetectors; i++) { for (int i = 0; i < multi_shm()->numberOfDetectors; i++) {
try { try {
detectors.push_back( detectors.push_back(
sls::make_unique<slsDetector>(multiId, i, verify)); sls::make_unique<Module>(multiId, i, verify));
} catch (...) { } catch (...) {
detectors.clear(); detectors.clear();
throw; throw;
@ -275,17 +275,17 @@ void DetectorImpl::addSlsDetector(const std::string &hostname) {
} }
// get type by connecting // get type by connecting
detectorType type = slsDetector::getTypeFromDetector(host, port); detectorType type = Module::getTypeFromDetector(host, port);
auto pos = detectors.size(); auto pos = detectors.size();
detectors.emplace_back( detectors.emplace_back(
sls::make_unique<slsDetector>(type, multiId, pos, false)); sls::make_unique<Module>(type, multiId, pos, false));
multi_shm()->numberOfDetectors = detectors.size(); multi_shm()->numberOfDetectors = detectors.size();
detectors[pos]->setControlPort(port); detectors[pos]->setControlPort(port);
detectors[pos]->setStopPort(port + 1); detectors[pos]->setStopPort(port + 1);
detectors[pos]->setHostname(host, multi_shm()->initialChecks); detectors[pos]->setHostname(host, multi_shm()->initialChecks);
// detector type updated by now // detector type updated by now
multi_shm()->multiDetectorType = multi_shm()->multiDetectorType =
Parallel(&slsDetector::getDetectorType, {}) Parallel(&Module::getDetectorType, {})
.tsquash("Inconsistent detector types."); .tsquash("Inconsistent detector types.");
// for moench and ctb // for moench and ctb
detectors[pos]->updateNumberOfChannels(); detectors[pos]->updateNumberOfChannels();
@ -345,10 +345,10 @@ void DetectorImpl::setNumberOfChannels(const slsDetectorDefs::xy c) {
} }
void DetectorImpl::setGapPixelsinReceiver(bool enable) { void DetectorImpl::setGapPixelsinReceiver(bool enable) {
Parallel(&slsDetector::enableGapPixels, {}, static_cast<int>(enable)); Parallel(&Module::enableGapPixels, {}, static_cast<int>(enable));
// update number of channels // update number of channels
Result<slsDetectorDefs::xy> res = Result<slsDetectorDefs::xy> res =
Parallel(&slsDetector::getNumberOfChannels, {}); Parallel(&Module::getNumberOfChannels, {});
multi_shm()->numberOfChannels.x = 0; multi_shm()->numberOfChannels.x = 0;
multi_shm()->numberOfChannels.y = 0; multi_shm()->numberOfChannels.y = 0;
for (auto &it : res) { for (auto &it : res) {
@ -377,7 +377,7 @@ int DetectorImpl::createReceivingDataSockets(const bool destroy) {
if (multi_shm()->multiDetectorType == EIGER) { if (multi_shm()->multiDetectorType == EIGER) {
numSocketsPerDetector = 2; numSocketsPerDetector = 2;
} }
if (Parallel(&slsDetector::getNumberofUDPInterfacesFromShm, {}).squash() == if (Parallel(&Module::getNumberofUDPInterfacesFromShm, {}).squash() ==
2) { 2) {
numSocketsPerDetector = 2; numSocketsPerDetector = 2;
} }
@ -419,7 +419,7 @@ void DetectorImpl::readFrameFromReceiver() {
bool quadEnable = false; bool quadEnable = false;
bool eiger = false; bool eiger = false;
bool numInterfaces = bool numInterfaces =
Parallel(&slsDetector::getNumberofUDPInterfacesFromShm, {}) Parallel(&Module::getNumberofUDPInterfacesFromShm, {})
.squash(); // cannot pick up from zmq .squash(); // cannot pick up from zmq
bool runningList[zmqSocket.size()], connectList[zmqSocket.size()]; bool runningList[zmqSocket.size()], connectList[zmqSocket.size()];
@ -829,7 +829,7 @@ void DetectorImpl::savePattern(const std::string &fname) {
// throw RuntimeError("Could not create file to save pattern"); // throw RuntimeError("Could not create file to save pattern");
// } // }
// // get pattern limits // // get pattern limits
// auto r = Parallel(&slsDetector::setPatternLoopAddresses, {}, -1, -1, -1) // auto r = Parallel(&Module::setPatternLoopAddresses, {}, -1, -1, -1)
// .tsquash("Inconsistent pattern limits"); // .tsquash("Inconsistent pattern limits");
// // pattern words // // pattern words
// for (int i = r[0]; i <= r[1]; ++i) { // for (int i = r[0]; i <= r[1]; ++i) {
@ -879,7 +879,7 @@ void DetectorImpl::registerDataCallback(void (*userCallback)(detectorData *,
} }
double DetectorImpl::setTotalProgress() { double DetectorImpl::setTotalProgress() {
int64_t tot = Parallel(&slsDetector::getTotalNumFramesToReceive, {}) int64_t tot = Parallel(&Module::getTotalNumFramesToReceive, {})
.tsquash("Inconsistent number of total frames (#frames x #triggers(or bursts) x #storage cells)"); .tsquash("Inconsistent number of total frames (#frames x #triggers(or bursts) x #storage cells)");
if (tot == 0) { if (tot == 0) {
throw RuntimeError("Invalid Total Number of frames (0)"); throw RuntimeError("Invalid Total Number of frames (0)");
@ -929,15 +929,15 @@ int DetectorImpl::acquire() {
sem_init(&sem_endRTAcquisition, 1, 0); sem_init(&sem_endRTAcquisition, 1, 0);
bool receiver = bool receiver =
Parallel(&slsDetector::getUseReceiverFlag, {}).squash(false); Parallel(&Module::getUseReceiverFlag, {}).squash(false);
progressIndex = 0; progressIndex = 0;
setJoinThreadFlag(false); setJoinThreadFlag(false);
// verify receiver is idle // verify receiver is idle
if (receiver) { if (receiver) {
if (Parallel(&slsDetector::getReceiverStatus, {}).squash(ERROR) != if (Parallel(&Module::getReceiverStatus, {}).squash(ERROR) !=
IDLE) { IDLE) {
Parallel(&slsDetector::stopReceiver, {}); Parallel(&Module::stopReceiver, {});
} }
} }
setTotalProgress(); setTotalProgress();
@ -946,7 +946,7 @@ int DetectorImpl::acquire() {
// start receiver // start receiver
if (receiver) { if (receiver) {
Parallel(&slsDetector::startReceiver, {}); Parallel(&Module::startReceiver, {});
// let processing thread listen to these packets // let processing thread listen to these packets
sem_post(&sem_newRTAcquisition); sem_post(&sem_newRTAcquisition);
} }
@ -954,24 +954,24 @@ int DetectorImpl::acquire() {
// start and read all // start and read all
try { try {
if (multi_shm()->multiDetectorType == EIGER) { if (multi_shm()->multiDetectorType == EIGER) {
Parallel(&slsDetector::prepareAcquisition, {}); Parallel(&Module::prepareAcquisition, {});
} }
Parallel(&slsDetector::startAndReadAll, {}); Parallel(&Module::startAndReadAll, {});
} catch (...) { } catch (...) {
Parallel(&slsDetector::stopReceiver, {}); Parallel(&Module::stopReceiver, {});
throw; throw;
} }
// stop receiver // stop receiver
if (receiver) { if (receiver) {
Parallel(&slsDetector::stopReceiver, {}); Parallel(&Module::stopReceiver, {});
if (dataReady != nullptr) { if (dataReady != nullptr) {
sem_wait(&sem_endRTAcquisition); // waits for receiver's sem_wait(&sem_endRTAcquisition); // waits for receiver's
} }
// external process to be // external process to be
// done sending data to gui // done sending data to gui
Parallel(&slsDetector::incrementFileIndex, {}); Parallel(&Module::incrementFileIndex, {});
} }
// waiting for the data processing thread to finish! // waiting for the data processing thread to finish!
@ -982,7 +982,7 @@ int DetectorImpl::acquire() {
if (acquisition_finished != nullptr) { if (acquisition_finished != nullptr) {
// same status for all, else error // same status for all, else error
int status = static_cast<int>(ERROR); int status = static_cast<int>(ERROR);
auto t = Parallel(&slsDetector::getRunStatus, {}); auto t = Parallel(&Module::getRunStatus, {});
if (t.equal()) if (t.equal())
status = t.front(); status = t.front();
acquisition_finished(getCurrentProgress(), status, acqFinished_p); acquisition_finished(getCurrentProgress(), status, acqFinished_p);
@ -1010,7 +1010,7 @@ void DetectorImpl::startProcessingThread() {
} }
void DetectorImpl::processData() { void DetectorImpl::processData() {
if (Parallel(&slsDetector::getUseReceiverFlag, {}).squash(false)) { if (Parallel(&Module::getUseReceiverFlag, {}).squash(false)) {
if (dataReady != nullptr) { if (dataReady != nullptr) {
readFrameFromReceiver(); readFrameFromReceiver();
} }
@ -1023,11 +1023,11 @@ void DetectorImpl::processData() {
if (fgetc(stdin) == 'q') { if (fgetc(stdin) == 'q') {
LOG(logINFO) LOG(logINFO)
<< "Caught the command to stop acquisition"; << "Caught the command to stop acquisition";
Parallel(&slsDetector::stopAcquisition, {}); Parallel(&Module::stopAcquisition, {});
} }
} }
// get progress // get progress
caught = Parallel(&slsDetector::getFramesCaughtByReceiver, {0}) caught = Parallel(&Module::getFramesCaughtByReceiver, {0})
.squash(); .squash();
// updating progress // updating progress

View File

@ -5,7 +5,10 @@
#include "logger.h" #include "logger.h"
#include "sls_detector_defs.h" #include "sls_detector_defs.h"
class slsDetector; namespace sls{
class Module;
}
class ZmqSocket; class ZmqSocket;
class detectorData; class detectorData;
@ -87,7 +90,7 @@ class DetectorImpl : public virtual slsDetectorDefs {
template <class CT> struct NonDeduced { using type = CT; }; template <class CT> struct NonDeduced { using type = CT; };
template <typename RT, typename... CT> template <typename RT, typename... CT>
sls::Result<RT> Parallel(RT (slsDetector::*somefunc)(CT...), sls::Result<RT> Parallel(RT (sls::Module::*somefunc)(CT...),
std::vector<int> positions, std::vector<int> positions,
typename NonDeduced<CT>::type... Args) { typename NonDeduced<CT>::type... Args) {
@ -115,7 +118,7 @@ class DetectorImpl : public virtual slsDetectorDefs {
} }
template <typename RT, typename... CT> template <typename RT, typename... CT>
sls::Result<RT> Parallel(RT (slsDetector::*somefunc)(CT...) const, sls::Result<RT> Parallel(RT (sls::Module::*somefunc)(CT...) const,
std::vector<int> positions, std::vector<int> positions,
typename NonDeduced<CT>::type... Args) const { typename NonDeduced<CT>::type... Args) const {
@ -143,7 +146,7 @@ class DetectorImpl : public virtual slsDetectorDefs {
} }
template <typename... CT> template <typename... CT>
void Parallel(void (slsDetector::*somefunc)(CT...), void Parallel(void (sls::Module::*somefunc)(CT...),
std::vector<int> positions, std::vector<int> positions,
typename NonDeduced<CT>::type... Args) { typename NonDeduced<CT>::type... Args) {
@ -168,7 +171,7 @@ class DetectorImpl : public virtual slsDetectorDefs {
} }
template <typename... CT> template <typename... CT>
void Parallel(void (slsDetector::*somefunc)(CT...) const, void Parallel(void (sls::Module::*somefunc)(CT...) const,
std::vector<int> positions, std::vector<int> positions,
typename NonDeduced<CT>::type... Args) const { typename NonDeduced<CT>::type... Args) const {
@ -404,8 +407,8 @@ class DetectorImpl : public virtual slsDetectorDefs {
/** Shared Memory object */ /** Shared Memory object */
sls::SharedMemory<sharedMultiSlsDetector> multi_shm{0, -1}; sls::SharedMemory<sharedMultiSlsDetector> multi_shm{0, -1};
/** pointers to the slsDetector structures */ /** pointers to the Module structures */
std::vector<std::unique_ptr<slsDetector>> detectors; std::vector<std::unique_ptr<sls::Module>> detectors;
/** data streaming (down stream) enabled in client (zmq sckets created) */ /** data streaming (down stream) enabled in client (zmq sckets created) */
bool client_downstream{false}; bool client_downstream{false};

View File

@ -15,6 +15,8 @@ class ServerInterface;
#define SLS_SHMAPIVERSION 0x190726 #define SLS_SHMAPIVERSION 0x190726
#define SLS_SHMVERSION 0x200309 #define SLS_SHMVERSION 0x200309
namespace sls{
/** /**
* @short structure allocated in shared memory to store detector settings for * @short structure allocated in shared memory to store detector settings for
* IPC and cache * IPC and cache
@ -178,7 +180,7 @@ struct sharedSlsDetector {
bool stoppedFlag; bool stoppedFlag;
}; };
class slsDetector : public virtual slsDetectorDefs { class Module : public virtual slsDetectorDefs {
public: public:
/** /**
* Constructor called when creating new shared memory * Constructor called when creating new shared memory
@ -188,7 +190,7 @@ class slsDetector : public virtual slsDetectorDefs {
* @param verify true to verify if shared memory version matches existing * @param verify true to verify if shared memory version matches existing
* one * one
*/ */
explicit slsDetector(detectorType type, int multi_id = 0, int det_id = 0, explicit Module(detectorType type, int multi_id = 0, int det_id = 0,
bool verify = true); bool verify = true);
/** /**
@ -198,12 +200,12 @@ class slsDetector : public virtual slsDetectorDefs {
* @param verify true to verify if shared memory version matches existing * @param verify true to verify if shared memory version matches existing
* one * one
*/ */
explicit slsDetector(int multi_id = 0, int det_id = 0, bool verify = true); explicit Module(int multi_id = 0, int det_id = 0, bool verify = true);
/** /**
* Destructor * Destructor
*/ */
virtual ~slsDetector(); virtual ~Module();
/** /**
* Returns false if it cannot get fixed pattern from an old version of shm * Returns false if it cannot get fixed pattern from an old version of shm
@ -235,7 +237,7 @@ class slsDetector : public virtual slsDetectorDefs {
/** /**
* Free shared memory and delete shared memory structure * Free shared memory and delete shared memory structure
* occupied by the sharedSlsDetector structure * occupied by the sharedSlsDetector structure
* Is only safe to call if one deletes the slsDetector object afterward * Is only safe to call if one deletes the Module object afterward
* and frees multi shared memory/updates * and frees multi shared memory/updates
* thisMultiDetector->numberOfDetectors * thisMultiDetector->numberOfDetectors
*/ */
@ -2083,9 +2085,11 @@ class slsDetector : public virtual slsDetectorDefs {
*/ */
std::vector<std::string> getSettingsFileDacNames(); std::vector<std::string> getSettingsFileDacNames();
/** slsDetector Id or position in the detectors list */ /** Module Id or position in the detectors list */
const int detId; const int detId;
/** Shared Memory object */ /** Shared Memory object */
mutable sls::SharedMemory<sharedSlsDetector> shm{0, 0}; mutable sls::SharedMemory<sharedSlsDetector> shm{0, 0};
}; };
}// sls