From e8d83a085fa4657aa360c8248aaef6dedae76db8 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Thu, 10 Aug 2017 18:46:10 +0200 Subject: [PATCH] moved receiver start to status start and to startandreadall (acquire), parallelized status start, moved prepare and clean up to multi level and called by start and stop receiver for gotthard, moench and propix --- slsDetectorSoftware/commonFiles/error_defs.h | 9 +- .../multiSlsDetector/multiSlsDetector.cpp | 254 ++++++++++++++---- .../multiSlsDetector/multiSlsDetector.h | 10 + .../slsDetector/slsDetector.cpp | 104 ++++--- slsDetectorSoftware/slsDetector/slsDetector.h | 15 +- 5 files changed, 295 insertions(+), 97 deletions(-) diff --git a/slsDetectorSoftware/commonFiles/error_defs.h b/slsDetectorSoftware/commonFiles/error_defs.h index 9044911ac..ac4787cff 100644 --- a/slsDetectorSoftware/commonFiles/error_defs.h +++ b/slsDetectorSoftware/commonFiles/error_defs.h @@ -43,7 +43,8 @@ using namespace std; #define COULDNOT_STOP_RECEIVER 0x0000800000000000ULL #define RECEIVER_DET_POSID_NOT_SET 0x0000400000000000ULL #define RECEIVER_MULTI_DET_SIZE_NOT_SET 0x0000200000000000ULL - +#define PREPARE_ACQUISITION 0x0000100000000000ULL +#define CLEANUP_ACQUISITION 0x0000080000000000ULL // 0xFFFFFFF000000000ULL // 0x0000000FFFFFFFFFULL @@ -146,6 +147,12 @@ public: if(slsErrorMask&RECEIVER_MULTI_DET_SIZE_NOT_SET) retval.append("Could not set multi detector size\n"); + if(slsErrorMask&PREPARE_ACQUISITION) + retval.append("Could not prepare acquisition in detector\n"); + + if(slsErrorMask&CLEANUP_ACQUISITION) + retval.append("Could not clean up after acquisition in detector\n"); + diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index f4a4cc5ec..d86ecc319 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -1359,75 +1359,219 @@ int multiSlsDetector::getChanRegs(double* retval,bool fromDetector){ /* Communication to server */ +int multiSlsDetector::prepareAcquisition(){ + + int i=0; + int ret=OK; + int posmin=0, posmax=thisMultiDetector->numberOfDetectors; + + if(!threadpool){ + cout << "Error in creating threadpool. Exiting" << endl; + return FAIL; + }else{ + int* iret[posmax-posmin]; + for(int idet=posmin; idetmasterPosition) && (detectors[idet])){ + iret[idet]= new int(OK); + Task* task = new Task(new func0_t(&slsDetector::prepareAcquisition, + detectors[idet],iret[idet])); + threadpool->add_task(task); + } + } + threadpool->startExecuting(); + threadpool->wait_for_tasks_to_complete(); + for(int idet=posmin; idetmasterPosition) && (detectors[idet])){ + if(iret[idet] != NULL){ + if(*iret[idet] != OK) + ret = FAIL; + delete iret[idet]; + }else ret = FAIL; + if(detectors[idet]->getErrorMask()) + setErrorMask(getErrorMask()|(1<masterPosition; + if (thisMultiDetector->masterPosition>=0) { + if (detectors[i]) { + ret1=detectors[i]->prepareAcquisition(); + if(detectors[i]->getErrorMask()) + setErrorMask(getErrorMask()|(1<numberOfDetectors; + + i=thisMultiDetector->masterPosition; + if (thisMultiDetector->masterPosition>=0) { + if (detectors[i]) { + ret1=detectors[i]->cleanupAcquisition(); + if(detectors[i]->getErrorMask()) + setErrorMask(getErrorMask()|(1<masterPosition) && (detectors[idet])){ + iret[idet]= new int(OK); + Task* task = new Task(new func0_t(&slsDetector::cleanupAcquisition, + detectors[idet],iret[idet])); + threadpool->add_task(task); + } + } + threadpool->startExecuting(); + threadpool->wait_for_tasks_to_complete(); + for(int idet=posmin; idetmasterPosition) && (detectors[idet])){ + if(iret[idet] != NULL){ + if(*iret[idet] != OK) + ret = FAIL; + delete iret[idet]; + }else ret = FAIL; + if(detectors[idet]->getErrorMask()) + setErrorMask(getErrorMask()|(1<numberOfDetectors; i++) { - if (i!=thisMultiDetector->masterPosition) - if (detectors[i]) { - ret=detectors[i]->startAcquisition(); - if(detectors[i]->getErrorMask()) - setErrorMask(getErrorMask()|(1<masterPosition; - if (thisMultiDetector->masterPosition>=0) { - if (detectors[i]) { - ret=detectors[i]->startAcquisition(); - if(detectors[i]->getErrorMask()) - setErrorMask(getErrorMask()|(1<numberOfDetectors; + + if(!threadpool){ + cout << "Error in creating threadpool. Exiting" << endl; + return FAIL; + }else{ + int* iret[posmax-posmin]; + for(int idet=posmin; idetmasterPosition) && (detectors[idet])){ + iret[idet]= new int(OK); + Task* task = new Task(new func0_t(&slsDetector::startAcquisition, + detectors[idet],iret[idet])); + threadpool->add_task(task); + } + } + threadpool->startExecuting(); + threadpool->wait_for_tasks_to_complete(); + for(int idet=posmin; idetmasterPosition) && (detectors[idet])){ + if(iret[idet] != NULL){ + if(*iret[idet] != OK) + ret = FAIL; + delete iret[idet]; + }else ret = FAIL; + if(detectors[idet]->getErrorMask()) + setErrorMask(getErrorMask()|(1<masterPosition; + if (thisMultiDetector->masterPosition>=0) { + if (detectors[i]) { + ret1=detectors[i]->startAcquisition(); + if(detectors[i]->getErrorMask()) + setErrorMask(getErrorMask()|(1<numberOfDetectors; + i=thisMultiDetector->masterPosition; + if (thisMultiDetector->masterPosition>=0) { + if (detectors[i]) { + ret1=detectors[i]->stopAcquisition(); + if(detectors[i]->getErrorMask()) + setErrorMask(getErrorMask()|(1<masterPosition; - if (thisMultiDetector->masterPosition>=0) { - if (detectors[i]) { - ret=detectors[i]->stopAcquisition(); - if(detectors[i]->getErrorMask()) - setErrorMask(getErrorMask()|(1<numberOfDetectors; i++) { - if (detectors[i]) { - ret=detectors[i]->stopAcquisition(); - if(detectors[i]->getErrorMask()) - setErrorMask(getErrorMask()|(1<masterPosition) && (detectors[idet])){ + iret[idet]= new int(OK); + Task* task = new Task(new func0_t(&slsDetector::stopAcquisition, + detectors[idet],iret[idet])); + threadpool->add_task(task); + } + } + threadpool->startExecuting(); + threadpool->wait_for_tasks_to_complete(); + for(int idet=posmin; idetmasterPosition) && (detectors[idet])){ + if(iret[idet] != NULL){ + if(*iret[idet] != OK) + ret = FAIL; + delete iret[idet]; + }else ret = FAIL; + if(detectors[idet]->getErrorMask()) + setErrorMask(getErrorMask()|(1<onlineFlag==ONLINE_FLAG) { - - startAndReadAllNoWait(); + + if(getDetectorsType() == EIGER) { + if (prepareAcquisition() == FAIL) + return NULL; + } + startAndReadAllNoWait(); while ((retval=getDataFromDetector())){ i++; diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h index 2f9b0439e..3a095a20d 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h @@ -561,7 +561,17 @@ class multiSlsDetector : public slsDetectorUtils { // Acquisition functions + /** + prepares detector for acquisition + \returns OK if all detectors are properly started, FAIL otherwise + */ + int prepareAcquisition(); + /** + prepares detector for acquisition + \returns OK if all detectors are properly started, FAIL otherwise + */ + int cleanupAcquisition(); /** start detector acquisition (master is started as last) diff --git a/slsDetectorSoftware/slsDetector/slsDetector.cpp b/slsDetectorSoftware/slsDetector/slsDetector.cpp index e15b3a878..927339e57 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetector.cpp @@ -3976,6 +3976,62 @@ int slsDetector::updateDetector() { // Acquisition functions /* change these funcs accepting also ok/fail */ + +int slsDetector::prepareAcquisition() { + int fnum = F_PREPARE_ACQUISITION; + int ret=FAIL; + char mess[MAX_STR_LENGTH]=""; + + if (thisDetector->onlineFlag==ONLINE_FLAG) { +#ifdef VERBOSE + std::cout << "Preparing Detector for Acquisition" << std::endl; +#endif + if (connectControl() == OK){ + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret==FAIL){ + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + setErrorMask((getErrorMask())|(PREPARE_ACQUISITION)); + } + disconnectControl(); + if (ret==FORCE_UPDATE) + updateDetector(); + } + }else + std::cout << "cannot connect to detector" << endl; + + return ret; +} + +int slsDetector::cleanupAcquisition() { + int fnum = F_CLEANUP_ACQUISITION; + int ret=FAIL; + char mess[MAX_STR_LENGTH]=""; + + if (thisDetector->onlineFlag==ONLINE_FLAG) { +#ifdef VERBOSE + std::cout << "Cleaning up Detector after Acquisition " << std::endl; +#endif + if (connectControl() == OK){ + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret==FAIL){ + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + setErrorMask((getErrorMask())|(CLEANUP_ACQUISITION)); + } + disconnectControl(); + if (ret==FORCE_UPDATE) + updateDetector(); + } + }else + std::cout << "cannot connect to detector" << endl; + + return ret; + +} + int slsDetector::startAcquisition(){ @@ -4258,6 +4314,10 @@ int* slsDetector::startAndReadAll(){ int i=0; #endif //#endif + if(thisDetector->myDetectorType == EIGER) { + if (prepareAcquisition() == FAIL) + return NULL; + } startAndReadAllNoWait(); //#ifdef VERBOSE // std::cout<< "started" << std::endl; @@ -4485,7 +4545,7 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t){ ret = FAIL; cout << "ERROR: " << timername << " in receiver set incorrectly to " << retval << " instead of " << args[1] << endl; - if(strstr(mess,"receiver not idle")==NULL) { + if(strstr(mess,"receiver is not idle")==NULL) { switch(index) { case ACQUISITION_TIME: setErrorMask((getErrorMask())|(RECEIVER_ACQ_TIME_NOT_SET)); @@ -7859,12 +7919,9 @@ int slsDetector::startReceiver(){ } } - //let detector prepare anyway even if receiver didnt work (for those not using the receiver) - if((thisDetector->myDetectorType != JUNGFRAU)) { - int ret1 = detectorSendToReceiver(true); - if (ret != FAIL) - ret = ret1; - } + // tell detector to send to receiver (if start receiver failed, this is not executed) + if((thisDetector->myDetectorType != JUNGFRAU && thisDetector->myDetectorType != EIGER && ret!= FAIL)) + return prepareAcquisition(); // send data to receiver for these detectors return ret; } @@ -7878,7 +7935,7 @@ int slsDetector::stopReceiver(){ char mess[MAX_STR_LENGTH] = ""; if(thisDetector->myDetectorType != EIGER && thisDetector->myDetectorType != JUNGFRAU) - detectorSendToReceiver(false); + cleanupAcquisition(); // reset (send data to receiver) for these detectors, so back to CPU (dont care about ok/fail at this point) if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { #ifdef VERBOSE @@ -7924,37 +7981,6 @@ slsDetectorDefs::runStatus slsDetector::startReceiverReadout(){ } -int slsDetector::detectorSendToReceiver(bool set){ - int fnum; - if(set) fnum=F_PREPARE_ACQUISITION; - else fnum=F_CLEANUP_ACQUISITION; - int ret = FAIL; - char mess[MAX_STR_LENGTH]=""; - - if (thisDetector->onlineFlag==ONLINE_FLAG) { -#ifdef VERBOSE - std::cout << "Setting detector to send packets via client to: " << set << std::endl; -#endif - if (connectControl() == OK){ - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret==FAIL){ - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned error: " << mess << std::endl; - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); - } - }else - std::cout << "cannot connect to detector" << endl; - - return ret; -} - - - - diff --git a/slsDetectorSoftware/slsDetector/slsDetector.h b/slsDetectorSoftware/slsDetector/slsDetector.h index bcb8f6d0a..d6005448b 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.h +++ b/slsDetectorSoftware/slsDetector/slsDetector.h @@ -1063,6 +1063,17 @@ class slsDetector : public slsDetectorUtils, public energyConversion { // Acquisition functions + /** + prepares detector for acquisition + \returns OK/FAIL + */ + int prepareAcquisition(); + + /** + prepares detector for acquisition + \returns OK/FAIL + */ + int cleanupAcquisition(); /** start detector acquisition @@ -1614,10 +1625,6 @@ class slsDetector : public slsDetectorUtils, public energyConversion { */ runStatus startReceiverReadout(); - /** Sets(false) or Resets(true) the CPU bit in detector - \returns OK or FAIL - */ - int detectorSendToReceiver(bool set); /** gets the status of the listening mode of receiver \returns status