mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-20 00:37:12 +02:00
Dev/proper free (#1005)
* first draft of fixing the free function available within the class * removed class member function freeSharedmemory for both Detector and Module; made the free function freeSharedmemory accessible to python interface; setHostname if there is already a module in shm will recreate the Detector object while freeing shm completely and keeping detsize and intitialchecks (previous commit), sethostname called from DetectorClass in virtual command to have one point of entry (previous commit), testing Module class frees shared memory using free function * Detector class: added copy and move constructor and assignmentoperators due to explicit destructor (DetectorImpl fwd declared), DetectorImpl class: included ZmqSocket to remove destructor (should not be virtual in any case), Module class: removed explciit destructor to allow compiler generated constructor and operators * formatting * minor fix for readme autocomplete * updated client version date
This commit is contained in:
@ -37,8 +37,6 @@ DetectorImpl::DetectorImpl(int detector_index, bool verify, bool update)
|
||||
setupDetector(verify, update);
|
||||
}
|
||||
|
||||
DetectorImpl::~DetectorImpl() = default;
|
||||
|
||||
void DetectorImpl::setupDetector(bool verify, bool update) {
|
||||
initSharedMemory(verify);
|
||||
initializeMembers(verify);
|
||||
@ -59,51 +57,6 @@ void DetectorImpl::setAcquiringFlag(bool flag) { shm()->acquiringFlag = flag; }
|
||||
|
||||
int DetectorImpl::getDetectorIndex() const { return detectorIndex; }
|
||||
|
||||
void DetectorImpl::freeSharedMemory(int detectorIndex, int detPos) {
|
||||
// single
|
||||
if (detPos >= 0) {
|
||||
SharedMemory<sharedModule> moduleShm(detectorIndex, detPos);
|
||||
if (moduleShm.exists()) {
|
||||
moduleShm.removeSharedMemory();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// multi - get number of modules from shm
|
||||
SharedMemory<sharedDetector> detectorShm(detectorIndex, -1);
|
||||
int numModules = 0;
|
||||
|
||||
if (detectorShm.exists()) {
|
||||
detectorShm.openSharedMemory(false);
|
||||
numModules = detectorShm()->totalNumberOfModules;
|
||||
detectorShm.removeSharedMemory();
|
||||
}
|
||||
|
||||
for (int i = 0; i < numModules; ++i) {
|
||||
SharedMemory<sharedModule> moduleShm(detectorIndex, i);
|
||||
moduleShm.removeSharedMemory();
|
||||
}
|
||||
|
||||
SharedMemory<CtbConfig> ctbShm(detectorIndex, -1, CtbConfig::shm_tag());
|
||||
if (ctbShm.exists())
|
||||
ctbShm.removeSharedMemory();
|
||||
}
|
||||
|
||||
void DetectorImpl::freeSharedMemory() {
|
||||
zmqSocket.clear();
|
||||
for (auto &module : modules) {
|
||||
module->freeSharedMemory();
|
||||
}
|
||||
modules.clear();
|
||||
|
||||
// clear detector shm
|
||||
shm.removeSharedMemory();
|
||||
client_downstream = false;
|
||||
|
||||
if (ctb_shm.exists())
|
||||
ctb_shm.removeSharedMemory();
|
||||
}
|
||||
|
||||
std::string DetectorImpl::getUserDetails() {
|
||||
if (modules.empty()) {
|
||||
return std::string("none");
|
||||
@ -242,24 +195,11 @@ std::string DetectorImpl::exec(const char *cmd) {
|
||||
return result;
|
||||
}
|
||||
|
||||
void DetectorImpl::setVirtualDetectorServers(const int numdet,
|
||||
const uint16_t port) {
|
||||
std::vector<std::string> hostnames;
|
||||
for (int i = 0; i < numdet; ++i) {
|
||||
// * 2 is for control and stop port
|
||||
hostnames.push_back(std::string("localhost:") +
|
||||
std::to_string(port + i * 2));
|
||||
}
|
||||
setHostname(hostnames);
|
||||
bool DetectorImpl::hasModulesInSharedMemory() {
|
||||
return (shm.exists() && shm()->totalNumberOfModules > 0);
|
||||
}
|
||||
|
||||
void DetectorImpl::setHostname(const std::vector<std::string> &name) {
|
||||
// do not free always to allow the previous detsize/ initialchecks command
|
||||
if (shm.exists() && shm()->totalNumberOfModules != 0) {
|
||||
LOG(logWARNING) << "There are already module(s) in shared memory."
|
||||
"Freeing Shared memory now.";
|
||||
freeSharedMemory();
|
||||
}
|
||||
// could be called after freeing shm from API
|
||||
if (!shm.exists()) {
|
||||
setupDetector();
|
||||
@ -292,8 +232,8 @@ void DetectorImpl::addModule(const std::string &name) {
|
||||
|
||||
// gotthard cannot have more than 2 modules (50um=1, 25um=2
|
||||
if ((type == GOTTHARD || type == GOTTHARD2) && modules.size() > 2) {
|
||||
freeSharedMemory();
|
||||
throw RuntimeError("Gotthard cannot have more than 2 modules");
|
||||
throw RuntimeError("Gotthard cannot have more than 2 modules. Please "
|
||||
"free the shared memory and start again.");
|
||||
}
|
||||
|
||||
auto pos = modules.size();
|
||||
|
Reference in New Issue
Block a user