diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index 2d8b3a2a8..e65840899 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -781,24 +781,7 @@ void Detector::startReceiver() { pimpl->Parallel(&Module::startReceiver, {}); } void Detector::stopReceiver() { pimpl->Parallel(&Module::stopReceiver, {}); } void Detector::startDetector(Positions pos) { - auto detector_type = getDetectorType(pos).squash(); - if (detector_type == defs::MYTHEN3 && size() > 1) { - std::vector slaves(pos); - auto is_master = getMaster(pos); - int masterPosition = -1; - for (unsigned int i = 0; i < is_master.size(); ++i) { - if (is_master[i]) { - masterPosition = i; - slaves.erase(slaves.begin() + i); - } - } - pimpl->Parallel(&Module::startAcquisition, pos); - if (masterPosition != -1) { - pimpl->Parallel(&Module::startAcquisition, {masterPosition}); - } - } else { - pimpl->Parallel(&Module::startAcquisition, pos); - } + pimpl->startAcquisition(false, pos); } void Detector::startDetectorReadout() { diff --git a/slsDetectorSoftware/src/DetectorImpl.cpp b/slsDetectorSoftware/src/DetectorImpl.cpp index 0edf633a9..3522c5e21 100644 --- a/slsDetectorSoftware/src/DetectorImpl.cpp +++ b/slsDetectorSoftware/src/DetectorImpl.cpp @@ -1124,25 +1124,7 @@ int DetectorImpl::acquire() { // start and read all try { - if (detector_type == defs::MYTHEN3 && modules.size() > 1) { - // Multi module mythen - std::vector master; - std::vector slaves; - auto is_master = Parallel(&Module::isMaster, {}); - slaves.reserve(modules.size() - 1); // check this one!! - for (size_t i = 0; i < modules.size(); ++i) { - if (is_master[i]) - master.push_back(i); - else - slaves.push_back(i); - } - Parallel(&Module::startAcquisition, slaves); - Parallel(&Module::startAndReadAll, master); - } else { - // Normal acquire - Parallel(&Module::startAndReadAll, {}); - } - + startAcquisition(true, {}); } catch (...) { if (receiver) Parallel(&Module::stopReceiver, {}); @@ -1191,6 +1173,35 @@ int DetectorImpl::acquire() { return OK; } +void DetectorImpl::startAcquisition(bool blocking, Positions pos) { + if (shm()->detType == defs::MYTHEN3 && size() > 1) { + std::vector master; + std::vector slaves; + auto is_master = Parallel(&Module::isMaster, pos); + // could be all slaves in pos + slaves.reserve(pos.size()); + for (size_t i = 0; i != pos.size(); ++i) { + if (is_master[i]) + master.push_back(i); + else + slaves.push_back(i); + } + + Parallel(&Module::startAcquisition, slaves); + if (blocking) { + Parallel(&Module::startAndReadAll, master); + } else { + Parallel(&Module::startAcquisition, master); + } + } else { + if (blocking) { + Parallel(&Module::startAndReadAll, pos); + } else { + Parallel(&Module::startAcquisition, pos); + } + } +} + void DetectorImpl::printProgress(double progress) { // spaces for python printout std::cout << " " << std::fixed << std::setprecision(2) << std::setw(6) diff --git a/slsDetectorSoftware/src/DetectorImpl.h b/slsDetectorSoftware/src/DetectorImpl.h index af1ec71ac..1ef51fd75 100644 --- a/slsDetectorSoftware/src/DetectorImpl.h +++ b/slsDetectorSoftware/src/DetectorImpl.h @@ -278,6 +278,9 @@ class DetectorImpl : public virtual slsDetectorDefs { */ int acquire(); + /** also takes care of master and slave for multi module mythen */ + void startAcquisition(bool blocking, Positions pos); + /** * Combines data from all readouts and gives it to the gui * or just gives progress of acquisition by polling receivers