diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index 83facff91..4d02fa0c3 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -207,7 +207,6 @@ multiSlsDetector::multiSlsDetector(int id) : slsDetectorUtils(), shmId(-1) } thisMultiDetector->acquiringFlag = false; - thisMultiDetector->externalgui = false; thisMultiDetector->receiver_upstream = false; thisMultiDetector->alreadyExisting=1; } @@ -1592,7 +1591,7 @@ int multiSlsDetector::stopAcquisition(){ } *stoppedFlag=1; - setAcquiringFlag(false); + return ret; }; @@ -6520,11 +6519,6 @@ int multiSlsDetector::pulseChip(int n) { void multiSlsDetector::setAcquiringFlag(bool b){ thisMultiDetector->acquiringFlag = b; - for(int idet=0; idetnumberOfDetectors; ++idet){ - if(detectors[idet]){ - detectors[idet]->setAcquiringFlag(b); - } - } } bool multiSlsDetector::getAcquiringFlag(){ @@ -6532,10 +6526,12 @@ bool multiSlsDetector::getAcquiringFlag(){ } -void multiSlsDetector::setExternalGuiFlag(bool b){ - thisMultiDetector->externalgui = b; -} +bool multiSlsDetector::isAcquireReady() { + if (thisMultiDetector->acquiringFlag) { + std::cout << "Acquire has already started. If previous acquisition terminated unexpectedly, reset busy flag to restart.(sls_detector_put busy 0)" << std::endl; + return FAIL; + } -bool multiSlsDetector::getExternalGuiFlag(){ - return thisMultiDetector->externalgui; + thisMultiDetector->acquiringFlag = true; + return OK; } diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h index ff37f29ae..4619fa8d3 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h @@ -1469,18 +1469,10 @@ class multiSlsDetector : public slsDetectorUtils { bool getAcquiringFlag(); /** - Set external gui flag in shared memory - \param b set external gui flag + * Check if acquiring flag is set, set error if set + * \returns FAIL if not ready, OK if ready */ - void setExternalGuiFlag(bool b=false); - - /** - Get external gui flag from shared memory - \returns external gui flag - */ - bool getExternalGuiFlag(); - - + bool isAcquireReady(); private: diff --git a/slsDetectorSoftware/slsDetector/slsDetector.cpp b/slsDetectorSoftware/slsDetector/slsDetector.cpp index 8e368142b..8e23dc9f9 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetector.cpp @@ -774,7 +774,6 @@ int slsDetector::initializeDetectorSize(detectorType type) { thisDetector->actionMask=0; thisDetector->tenGigaEnable=0; - thisDetector->acquiringFlag = false; thisDetector->flippedData[0] = 0; thisDetector->flippedData[1] = 0; thisDetector->zmqport = 0; @@ -9154,21 +9153,15 @@ int slsDetector::pulseChip(int n) { void slsDetector::setAcquiringFlag(bool b){ - thisDetector->acquiringFlag = b; + parentDet->setAcquiringFlag(b); } bool slsDetector::getAcquiringFlag(){ - return thisDetector->acquiringFlag; + return parentDet->getAcquiringFlag(); } -void slsDetector::setExternalGuiFlag(bool b){ - pthread_mutex_lock(&ms); - parentDet->setExternalGuiFlag(b); - pthread_mutex_unlock(&ms); -} - -bool slsDetector::getExternalGuiFlag(){ - return parentDet->getExternalGuiFlag(); +bool slsDetector::isAcquireReady() { + return parentDet->isAcquireReady(); } diff --git a/slsDetectorSoftware/slsDetector/slsDetector.h b/slsDetectorSoftware/slsDetector/slsDetector.h index 5464bdfa7..c4f70f909 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.h +++ b/slsDetectorSoftware/slsDetector/slsDetector.h @@ -265,8 +265,6 @@ class slsDetector : public slsDetectorUtils, public energyConversion { /** 10 Gbe enable*/ int tenGigaEnable; - /** flag for acquiring */ - bool acquiringFlag; /** flipped data across x or y axis */ int flippedData[2]; /** tcp port from gui/different process to receiver (only data) */ @@ -1915,18 +1913,12 @@ class slsDetector : public slsDetectorUtils, public energyConversion { bool getAcquiringFlag(); /** - Set external gui flag in shared memory - \param b set external gui flag + * Check if acquiring flag is set, set error if set + * \returns FAIL if not ready, OK if ready */ - void setExternalGuiFlag(bool b=false); + bool isAcquireReady(); - /** - Get external gui flag from shared memory - \returns external gui flag - */ - bool getExternalGuiFlag(); - protected: diff --git a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp index e773dbd10..c2212857a 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp @@ -184,7 +184,7 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) { ++i; /*! \page acquisition - - \b busy returns \c 1 if the acquisition is active, \c 0 otherwise. Works when the acquisition is started in blocking mode. Only get! \c Returns \c (int) + - busy i sets/gets acquiring flag. \c 1 the acquisition is active, \c 0 otherwise. Acquire command will set this flag to 1 at the beginning and to 0 at the end. Use this to clear flag if acquisition terminated unexpectedly. \c Returns \c (int) */ descrToFuncMap[i].m_pFuncName="busy"; // descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdStatus; @@ -2438,7 +2438,10 @@ string slsDetectorCommand::cmdStatus(int narg, char *args[], int action) { } else if (cmd=="busy") { if (action==PUT_ACTION) { - return string ("cannot put"); + int i; + if(!sscanf(args[1],"%d",&i)) + return string("cannot parse busy mode"); + myDet->setAcquiringFlag(i); } char answer[100]; sprintf(answer,"%d", myDet->getAcquiringFlag()); @@ -2457,8 +2460,10 @@ string slsDetectorCommand::helpStatus(int narg, char *args[], int action) { os << string("status \t gets the detector status - can be: running, error, transmitting, finished, waiting or idle\n"); os << string("busy \t gets the status of acquire- can be: 0 or 1. 0 for idle, 1 for running\n"); } - if (action==PUT_ACTION || action==HELP_ACTION) + if (action==PUT_ACTION || action==HELP_ACTION) { os << string("status \t controls the detector acquisition - can be start or stop \n"); + os << string("busy i\t sets the status of acquire- can be: 0(idle) or 1(running).Command Acquire sets it to 1 at beignning of acquire and back to 0 at the end. Clear Flag for unexpected acquire terminations. \n"); + } return os.str(); } diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp index e2b8e6838..540aede78 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp @@ -42,475 +42,419 @@ slsDetectorUtils::slsDetectorUtils() { int slsDetectorUtils::acquire(int delflag){ - //ensure acquire isnt started multiple times by same client - if(getAcquiringFlag() == false) - setAcquiringFlag(true); - else{ - std::cout << "Error: Acquire has already been started." << std::endl; - return FAIL; - } + + //ensure acquire isnt started multiple times by same client + if (isAcquireReady() == FAIL) + return FAIL; #ifdef VERBOSE struct timespec begin,end; clock_gettime(CLOCK_REALTIME, &begin); #endif - //not in the loop for real time acqusition yet, //in the real time acquisition loop, processing thread will wait for a post each time sem_init(&sem_newRTAcquisition,1,0); - bool receiver = (setReceiverOnline()==ONLINE_FLAG); - if(!receiver){ - setDetectorIndex(-1); - } + bool receiver = (setReceiverOnline()==ONLINE_FLAG); + if(!receiver){ + setDetectorIndex(-1); + } - int nc=setTimer(CYCLES_NUMBER,-1); - int nf=setTimer(FRAME_NUMBER,-1); - if (nc==0) nc=1; - if (nf==0) nf=1; + int nc=setTimer(CYCLES_NUMBER,-1); + int nf=setTimer(FRAME_NUMBER,-1); + if (nc==0) nc=1; + if (nf==0) nf=1; + int multiframe = nc*nf; - int multiframe = nc*nf; + progressIndex=0; + *stoppedFlag=0; - // setTotalProgress(); - //moved these 2 here for measurement change - progressIndex=0; - *stoppedFlag=0; - - angCalLogClass *aclog=NULL; - enCalLogClass *eclog=NULL; - // int lastindex=startindex, nowindex=startindex; - int connectChannels=0; + angCalLogClass *aclog=NULL; + enCalLogClass *eclog=NULL; + int connectChannels=0; #ifdef VERBOSE - cout << "Acquire function "<< delflag << endl; - cout << "Stopped flag is "<< stoppedFlag << delflag << endl; + cout << "Acquire function "<< delflag << endl; + cout << "Stopped flag is "<< stoppedFlag << delflag << endl; #endif - void *status; + void *status; + if ((*correctionMask&(1<< ANGULAR_CONVERSION)) || (*correctionMask&(1<< I0_NORMALIZATION)) || getActionMode(angCalLog) || (getScanMode(0)==positionScan)|| (getScanMode(1)==positionScan)) { + if (connectChannels==0) + if (connect_channels) { + connect_channels(CCarg); + connectChannels=1; + } + } + if (getActionMode(angCalLog)) { + aclog=new angCalLogClass(this); + } + if (getActionMode(enCalLog)) { + eclog=new enCalLogClass(this); + + } - if ((*correctionMask&(1<< ANGULAR_CONVERSION)) || (*correctionMask&(1<< I0_NORMALIZATION)) || getActionMode(angCalLog) || (getScanMode(0)==positionScan)|| (getScanMode(1)==positionScan)) { - if (connectChannels==0) - if (connect_channels) { - connect_channels(CCarg); - connectChannels=1; - } - } - - - if (getActionMode(angCalLog)) { - aclog=new angCalLogClass(this); - } - if (getActionMode(enCalLog)) { - eclog=new enCalLogClass(this); - - } - + setJoinThread(0); + positionFinished(0); - setJoinThread(0); - positionFinished(0); + int nm=timerValue[MEASUREMENTS_NUMBER]; + if (nm<1) + nm=1; + int np=getNumberOfPositions(); + if (np<1) + np=1; - int nm=timerValue[MEASUREMENTS_NUMBER]; - if (nm<1) - nm=1; + int ns0=1; + if (*actionMask & (1 << MAX_ACTIONS)) { + ns0=getScanSteps(0); + if (ns0<1) + ns0=1; + } - - int np=getNumberOfPositions(); - if (np<1) - np=1; - - - int ns0=1; - if (*actionMask & (1 << MAX_ACTIONS)) { - ns0=getScanSteps(0); - if (ns0<1) - ns0=1; - } + int ns1=1; + if (*actionMask & (1 << (MAX_ACTIONS+1))) { + ns1=getScanSteps(1); + if (ns1<1) + ns1=1; + } - int ns1=1; - if (*actionMask & (1 << (MAX_ACTIONS+1))) { - ns1=getScanSteps(1); - if (ns1<1) - ns1=1; - } - - if(receiver){ - pthread_mutex_lock(&mg); //cout << "lock"<< endl; - if(getReceiverStatus()!=IDLE) - if(stopReceiver() == FAIL) - *stoppedFlag=1; - pthread_mutex_unlock(&mg);//cout << "unlock"<< endl; - } + // verify receiver is idle + if(receiver){ + pthread_mutex_lock(&mg); + if(getReceiverStatus()!=IDLE) + if(stopReceiver() == FAIL) + *stoppedFlag=1; + pthread_mutex_unlock(&mg); + } - if (*threadedProcessing) - startThread(delflag); + if (*threadedProcessing) + startThread(delflag); #ifdef VERBOSE - cout << " starting thread " << endl; + cout << " starting thread " << endl; #endif - //resets frames caught in receiver - if(receiver){ - pthread_mutex_lock(&mg); //cout << "lock"<< endl; - if (resetFramesCaught() == FAIL) - *stoppedFlag=1; - pthread_mutex_unlock(&mg);//cout << "unlock"<< endl; - } + //resets frames caught in receiver + if(receiver){ + pthread_mutex_lock(&mg); + if (resetFramesCaught() == FAIL) + *stoppedFlag=1; + pthread_mutex_unlock(&mg); + } - for(int im=0;im0) { + moveDetector(detPositions[ip]); + IncrementPositionIndex(); +#ifdef VERBOSE + std::cout<< "moving to position" << std::endl; +#endif + } + } else + break; + + + pthread_mutex_lock(&mp); + createFileName(); + pthread_mutex_unlock(&mp); + + // script before + if (*stoppedFlag==0) { + executeAction(scriptBefore); + } else + break; + + + // header before + if (*stoppedFlag==0) { + executeAction(headerBefore); + + if (*correctionMask&(1<< ANGULAR_CONVERSION) || aclog){ + positionFinished(0); + setCurrentPosition(getDetectorPosition()); + } + + if (aclog) + aclog->addStep(getCurrentPosition(), getCurrentFileName()); + + if (eclog) + eclog->addStep(setDAC(-1,THRESHOLD,0), getCurrentFileName()); + + + if (*correctionMask&(1<< I0_NORMALIZATION)) { + if (get_i0) + get_i0(0, IOarg); + } + + setCurrentFrameIndex(0); + + if(receiver) + pthread_mutex_lock(&mg); + if (multiframe>1) + setFrameIndex(0); + else + setFrameIndex(-1); + + // file name and start receiver + if(receiver){ + pthread_mutex_unlock(&mg); + pthread_mutex_lock(&mp); + createFileName(); + pthread_mutex_unlock(&mp); + //send receiver file name + pthread_mutex_lock(&mg); + setFileName(fileIO::getFileName()); + + if(startReceiver() == FAIL) { + cout << "Start receiver failed " << endl; + stopReceiver(); + *stoppedFlag=1; + pthread_mutex_unlock(&mg); + break; + } +#ifdef VERBOSE + cout << "Receiver started " << endl; +#endif + pthread_mutex_unlock(&mg); + + //let processing thread listen to these packets + sem_post(&sem_newRTAcquisition); + } +#ifdef VERBOSE + cout << "Acquiring " << endl; +#endif + startAndReadAll(); +#ifdef VERBOSE + cout << "detector finished" << endl; + cout << "returned! " << endl; #endif - //cout << "data thread started " << endl; - - - //loop measurements - -// pthread_mutex_lock(&mp); -// setStartIndex(*fileIndex); -// pthread_mutex_unlock(&mp); - - //cout << "action at start" << endl; - if (*stoppedFlag==0) { - executeAction(startScript); - } - - for (int is0=0; is00) { - moveDetector(detPositions[ip]); - IncrementPositionIndex(); + if (*correctionMask&(1<< I0_NORMALIZATION)) { + if (get_i0) + currentI0=get_i0(1,IOarg); + } #ifdef VERBOSE - std::cout<< "moving to position" << std::endl; -#endif - } - } else - break; - - - pthread_mutex_lock(&mp); - createFileName(); - pthread_mutex_unlock(&mp); - - if (*stoppedFlag==0) { - executeAction(scriptBefore); - } else - break; - - - - - if (*stoppedFlag==0) { - - - executeAction(headerBefore); - - if (*correctionMask&(1<< ANGULAR_CONVERSION) || aclog){// || eclog) { - positionFinished(0); - setCurrentPosition(getDetectorPosition()); - } - - - if (aclog) - aclog->addStep(getCurrentPosition(), getCurrentFileName()); - - if (eclog) - eclog->addStep(setDAC(-1,THRESHOLD,0), getCurrentFileName()); - - - if (*correctionMask&(1<< I0_NORMALIZATION)) { - if (get_i0) - get_i0(0, IOarg); - } - - setCurrentFrameIndex(0); - - if(receiver) - pthread_mutex_lock(&mg); //cout << "lock"<< endl; - if (multiframe>1) - setFrameIndex(0); - else - setFrameIndex(-1); - - - if(receiver){ - pthread_mutex_unlock(&mg);//cout << "unlock"<< endl; - pthread_mutex_lock(&mp); - createFileName(); - pthread_mutex_unlock(&mp); - //send receiver file name - pthread_mutex_lock(&mg); //cout << "lock"<< endl; - setFileName(fileIO::getFileName()); - - //start receiver - if(startReceiver() == FAIL) { - cout << "Start receiver failed " << endl; - stopReceiver(); - *stoppedFlag=1; - pthread_mutex_unlock(&mg);//cout << "unlock"<< endl; - break; - } -#ifdef VERBOSE - cout << "Receiver started " << endl; -#endif - pthread_mutex_unlock(&mg);//cout << "unlock"<< endl; - - //let processing thread listen to these packets - sem_post(&sem_newRTAcquisition); - } - #ifdef VERBOSE - cout << "Acquiring " << endl; - #endif - startAndReadAll(); -#ifdef VERBOSE - cout << "detector finished " << endl; -#endif - #ifdef VERBOSE - cout << "returned! " << endl; - #endif - - - - if (*correctionMask&(1<< I0_NORMALIZATION)) { - if (get_i0) - currentI0=get_i0(1,IOarg); // this is the correct i0!!!!! - } -#ifdef VERBOSE - cout << "pos finished? " << endl; + cout << "pos finished? " << endl; #endif - positionFinished(1); - -#ifdef VERBOSE - cout << "done! " << endl; -#endif - + positionFinished(1); - if (*threadedProcessing==0){ #ifdef VERBOSE - cout << "start unthreaded process data " << endl; + cout << "done! " << endl; #endif - processData(delflag); - } - } else - break; - - while (dataQueueSize()) usleep(100000); - // cout << "mglock " << endl;; - - - - pthread_mutex_lock(&mg); //cout << "lock"<< endl; - // cout << "done " << endl;; - //offline - if(!receiver){ - if ((getDetectorsType()==GOTTHARD) || (getDetectorsType()==MOENCH) || (getDetectorsType()==JUNGFRAU)|| (getDetectorsType()==JUNGFRAUCTB) ){ - if((*correctionMask)&(1<