From 6a71e61c129cc70bb092085c8d13c74877706e0c Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Wed, 7 Aug 2019 15:23:58 +0200 Subject: [PATCH] WIP --- slsDetectorSoftware/include/Detector.h | 48 +++++++++++++++++-- .../include/multiSlsDetector.h | 29 ++++++++--- slsDetectorSoftware/src/Detector.cpp | 33 +++++++++++-- slsDetectorSoftware/src/multiSlsDetector.cpp | 33 ++++++++++++- 4 files changed, 125 insertions(+), 18 deletions(-) diff --git a/slsDetectorSoftware/include/Detector.h b/slsDetectorSoftware/include/Detector.h index 60a19cc1c..a363aea7e 100644 --- a/slsDetectorSoftware/include/Detector.h +++ b/slsDetectorSoftware/include/Detector.h @@ -124,6 +124,11 @@ class Detector { void setPeriod(ns t, Positions pos = {}); // dhanya + /** + * Get multidetector Id + * @returns multidetector Id + */ + int getMultiId() const; /** * Check version compatibility with detector software @@ -142,34 +147,67 @@ class Detector { * @param pos detector position * @returns detector firmware version */ - int64_t getDetectorFirmwareVersion(Positions pos = {}) const; + Result getDetectorFirmwareVersion(Positions pos = {}) const; /** * Get detector server version * @param pos detector position * @returns detector server version */ - int64_t getDetectorServerVersion(Positions pos = {}) const; + Result getDetectorServerVersion(Positions pos = {}) const; /** * Get detector serial number * @param pos detector position * @returns detector serial number */ - int64_t getDetectorSerialNumber(Positions pos = {}) const; + Result getDetectorSerialNumber(Positions pos = {}) const; /** * Get Client Software version * @returns client software version */ - int64_t getClientSoftwareVersion() const; + Result getClientSoftwareVersion() const; /** * Get Receiver software version * @param pos detector position * @return receiver software version */ - int64_t getReceiverSoftwareVersion(Positions pos = {}) const; + Result getReceiverSoftwareVersion(Positions pos = {}) const; + + /** + * Get user details of shared memory + * @returns string with user details + */ + std::string getUserDetails() const; + + /** + * Frees shared memory and adds detectors to the list + * Also updates local detector cache + * @param name hostnames for the positions given + */ + void setHostname(const std::vector &name); + + /** + * Get Detector type as an enum + * @returns detector type + */ + detectorType Detector::getDetectorTypeAsEnum() const; + + /** + * Get Detector type as an enum + * @param pos detector position + * @returns detector type + */ + Result getDetectorTypeAsEnum(Positions pos = {}) const; + + /** + * Returns detector type as a string + * @param pos detector position + * @returns detector type as string + */ + Result getDetectorTypeAsString(Positions pos = {}); }; } // namespace sls \ No newline at end of file diff --git a/slsDetectorSoftware/include/multiSlsDetector.h b/slsDetectorSoftware/include/multiSlsDetector.h index 433612f9d..43cd153de 100755 --- a/slsDetectorSoftware/include/multiSlsDetector.h +++ b/slsDetectorSoftware/include/multiSlsDetector.h @@ -304,7 +304,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { */ int64_t getId(idMode mode, int detPos = -1);//not needed anymore (later remove this_software_version from enum) - int getMultiId()const{return multiId;} //public but part of multi + int getMultiId()const{return multiId;} //part of multi also /** * Get Client Software version @@ -329,7 +329,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param multiId multi detector Id * @param detPos -1 for all detectors in list or specific detector position */ - static void freeSharedMemory(int multiId, int detPos = -1);// + static void freeSharedMemory(int multiId, int detPos = -1);// private or not needed /** * Free shared memory and delete shared memory structure @@ -338,21 +338,27 @@ class multiSlsDetector : public virtual slsDetectorDefs { * object back to state before object creation amap * @param detPos -1 for all detectors in list or specific detector position */ - void freeSharedMemory(int detPos = -1); + void freeSharedMemory(int detPos = -1);// /** * Get user details of shared memory * @returns string with user details */ - std::string getUserDetails(); + std::string getUserDetails();// part of multi + /** + * Sets the hostname of all sls detectors in shared memory and updates local cache + * @param name hostname of all the sls detectors + */ + void setHostname(const std::vector &name);//cannot set individually + /** * Sets the hostname of all sls detectors in shared memory * Connects to them * @param name concatenated hostname of all the sls detectors * @param detPos -1 for all detectors in list or specific detector position */ - void setHostname(const char *name, int detPos = -1); + void setHostname(const char *name, int detPos = -1);// not needed /** * Gets the hostname of detector at particular position @@ -369,7 +375,13 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param name concatenated hostname of the sls detectors to be appended to * the list */ - void addMultipleDetectors(const char *name); + void addMultipleDetectors(const char *name);// ???? + + /** + * Get Detector type as an enum + * @returns detector type + */ + detectorType getDetectorTypeAsEnum() const; /** * Get Detector type for a particular sls detector or get the first one @@ -377,7 +389,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @returns detector type of sls detector in position pos, if -1, returns * the first det type */ - detectorType getDetectorTypeAsEnum(int detPos = -1); + detectorType getDetectorTypeAsEnum(int detPos);//?? /** * Concatenates string types of all sls detectors or @@ -2335,6 +2347,9 @@ class multiSlsDetector : public virtual slsDetectorDefs { /** Multi detector Id */ const int multiId{0}; + /** multi detector type */ + detectorType multiDetType; + /** Shared Memory object */ sls::SharedMemory multi_shm{0, -1}; diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index 5206f2368..b4407d646 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -121,11 +121,15 @@ Result Detector::getFileOverWrite(Positions pos) const { } // dhanya -Result Detector::checkDetectorVersionCompatibility(Positions pos) const { +int Detector::getMultiId() const { + pimpl->getMultiId()); +} + +void Detector::checkDetectorVersionCompatibility(Positions pos) const { pimpl->Parallel(&slsDetector::checkDetectorVersionCompatibility, pos); } -Result Detector::checkReceiverVersionCompatibility(Positions pos) const { +void Detector::checkReceiverVersionCompatibility(Positions pos) const { pimpl->Parallel(&slsDetector::checkReceiverVersionCompatibility, pos); } @@ -141,12 +145,31 @@ Result Detector::getDetectorSerialNumber(Positions pos) const { return pimpl->Parallel(&slsDetector::getId, DETECTOR_SERIAL_NUMBER, pos); } -Result Detector::getClientSoftwareVersion() const { - return APILIB; -} +Result Detector::getClientSoftwareVersion() const { return APILIB; } Result Detector::getReceiverSoftwareVersion(Positions pos) const { return pimpl->Parallel(&slsDetector::getReceiverSoftwareVersion, pos); } +std::string Detector::getUserDetails() const { + return pimpl->getUserDetails(); +} + +void Detector::setHostname(const std::vector &name, + Positions pos) { + pimpl->setHostname(name); +} + +detectorType Detector::getDetectorTypeAsEnum() const { + return pimpl->getDetectorTypeAsEnum(); +} + +Result Detector::getDetectorTypeAsEnum(Positions pos) const { + return pimpl->Parallel(&slsDetector::getDetectorTypeAsEnum, pos); +} + +Result Detector::getDetectorTypeAsString(Positions pos) const { + return pimpl->Parallel(&slsDetector::getDetectorTypeAsString, pos); +} + } // namespace sls \ No newline at end of file diff --git a/slsDetectorSoftware/src/multiSlsDetector.cpp b/slsDetectorSoftware/src/multiSlsDetector.cpp index 0c7b14feb..9f94d3b76 100755 --- a/slsDetectorSoftware/src/multiSlsDetector.cpp +++ b/slsDetectorSoftware/src/multiSlsDetector.cpp @@ -30,7 +30,7 @@ using namespace sls; multiSlsDetector::multiSlsDetector(int multi_id, bool verify, bool update) - : multiId(multi_id), multi_shm(multi_id, -1) { + : multiId(multi_id), multiDetType(GENERIC), multi_shm(multi_id, -1) { setupMultiDetector(verify, update); } @@ -332,6 +332,11 @@ void multiSlsDetector::initializeDetectorStructure() { void multiSlsDetector::initializeMembers(bool verify) { // multiSlsDetector + if (multi_shm()->numberOfDetectors == 0) { + multiDetType = GENERIC; + } else { + multiDetType = getDetectorTypeAsEnum(); + } zmqSocket.clear(); // get objects from single det shared memory (open) @@ -385,6 +390,22 @@ std::string multiSlsDetector::exec(const char *cmd) { return result; } +void multiSlsDetector::setHostname(const std::vector &name) { + // this check is there only to allow the previous detsizechan command + if (multi_shm()->numberOfDetectors != 0) { + FILE_LOG(logWARNING) + << "There are already detector(s) in shared memory." + "Freeing Shared memory now."; + freeSharedMemory(); + setupMultiDetector(); + } + for (const auto &hostname : name) { + addSlsDetector(hostname); + } + + updateOffsets(); +} + void multiSlsDetector::setHostname(const char *name, int detPos) { // single if (detPos >= 0) { @@ -461,6 +482,10 @@ void multiSlsDetector::addSlsDetector(std::unique_ptr det) { detectors.back()->getTotalNumberOfChannels(); } +slsDetectorDefs::detectorType multiSlsDetector::getDetectorTypeAsEnum() const { + return multiDetType; +} + slsDetectorDefs::detectorType multiSlsDetector::getDetectorTypeAsEnum(int detPos) { // single @@ -842,6 +867,12 @@ void multiSlsDetector::readConfigurationFile(const std::string &fname) { } } input_file.close(); + + if (multi_shm()->numberOfDetectors == 0) { + multiDetType = GENERIC; + } else { + multiDetType = getDetectorTypeAsEnum(); + } } int multiSlsDetector::writeConfigurationFile(const std::string &fname) {