merge conflict from 3.0.1 to restream stop from recieveR

This commit is contained in:
Dhanya Maliakal 2017-11-30 19:05:35 +01:00
commit 5b88203bd9
8 changed files with 468 additions and 494 deletions

View File

@ -83,7 +83,7 @@ using namespace std;
#define RECEIVER_SILENT_MODE_NOT_SET 0x0000000100000000ULL #define RECEIVER_SILENT_MODE_NOT_SET 0x0000000100000000ULL
#define RECEIVER_TIMER_NOT_SET 0x0000000200000000ULL #define RECEIVER_TIMER_NOT_SET 0x0000000200000000ULL
#define RECEIVER_ENABLE_GAPPIXELS_NOT_SET 0x0000000400000000ULL #define RECEIVER_ENABLE_GAPPIXELS_NOT_SET 0x0000000400000000ULL
#define RESTREAM_STOP_FROM_RECEIVER 0x0000000800000000ULL
// 0x0000000FFFFFFFFFULL // 0x0000000FFFFFFFFFULL
/** @short class returning all error messages for error mask */ /** @short class returning all error messages for error mask */
@ -271,6 +271,11 @@ public:
if(slsErrorMask&RECEIVER_ENABLE_GAPPIXELS_NOT_SET) if(slsErrorMask&RECEIVER_ENABLE_GAPPIXELS_NOT_SET)
retval.append("Could not enable/disable gap pixels in receiver.\n"); retval.append("Could not enable/disable gap pixels in receiver.\n");
if(slsErrorMask&RESTREAM_STOP_FROM_RECEIVER)
retval.append("Could not restream stop from receiver.\n");
//------------------------------------------------------ length of message //------------------------------------------------------ length of message

View File

@ -214,7 +214,6 @@ multiSlsDetector::multiSlsDetector(int id) : slsDetectorUtils(), shmId(-1)
} }
thisMultiDetector->acquiringFlag = false; thisMultiDetector->acquiringFlag = false;
thisMultiDetector->externalgui = false;
thisMultiDetector->receiver_upstream = false; thisMultiDetector->receiver_upstream = false;
thisMultiDetector->alreadyExisting=1; thisMultiDetector->alreadyExisting=1;
} }
@ -1626,7 +1625,7 @@ int multiSlsDetector::stopAcquisition(){
} }
*stoppedFlag=1; *stoppedFlag=1;
setAcquiringFlag(false);
return ret; return ret;
}; };
@ -6720,11 +6719,6 @@ int multiSlsDetector::pulseChip(int n) {
void multiSlsDetector::setAcquiringFlag(bool b){ void multiSlsDetector::setAcquiringFlag(bool b){
thisMultiDetector->acquiringFlag = b; thisMultiDetector->acquiringFlag = b;
for(int idet=0; idet<thisMultiDetector->numberOfDetectors; ++idet){
if(detectors[idet]){
detectors[idet]->setAcquiringFlag(b);
}
}
} }
bool multiSlsDetector::getAcquiringFlag(){ bool multiSlsDetector::getAcquiringFlag(){
@ -6732,11 +6726,30 @@ bool multiSlsDetector::getAcquiringFlag(){
} }
void multiSlsDetector::setExternalGuiFlag(bool b){ bool multiSlsDetector::isAcquireReady() {
thisMultiDetector->externalgui = b; 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;
}
thisMultiDetector->acquiringFlag = true;
return OK;
} }
bool multiSlsDetector::getExternalGuiFlag(){
return thisMultiDetector->externalgui;
int multiSlsDetector::restreamStopFromReceiver() {
int ret=OK, ret1;
for(int idet=0; idet<thisMultiDetector->numberOfDetectors; ++idet){
if (detectors[idet]) {
ret1=detectors[idet]->restreamStopFromReceiver();
if(detectors[idet]->getErrorMask())
setErrorMask(getErrorMask()|(1<<idet));
if (ret1!=OK)
ret=FAIL;
}
}
return ret;
} }

View File

@ -1494,18 +1494,19 @@ class multiSlsDetector : public slsDetectorUtils {
bool getAcquiringFlag(); bool getAcquiringFlag();
/** /**
Set external gui flag in shared memory * Check if acquiring flag is set, set error if set
\param b set external gui flag * \returns FAIL if not ready, OK if ready
*/ */
void setExternalGuiFlag(bool b=false); bool isAcquireReady();
/** /**
Get external gui flag from shared memory If data streaming in receiver is enabled,
\returns external gui flag restream the stop dummy packet from receiver
Used usually for Moench,
in case it is lost in network due to high data rate
\returns OK if success else FAIL
*/ */
bool getExternalGuiFlag(); int restreamStopFromReceiver();
private: private:

View File

@ -792,7 +792,6 @@ int slsDetector::initializeDetectorSize(detectorType type) {
thisDetector->actionMask=0; thisDetector->actionMask=0;
thisDetector->tenGigaEnable=0; thisDetector->tenGigaEnable=0;
thisDetector->acquiringFlag = false;
thisDetector->flippedData[0] = 0; thisDetector->flippedData[0] = 0;
thisDetector->flippedData[1] = 0; thisDetector->flippedData[1] = 0;
thisDetector->zmqport = 0; thisDetector->zmqport = 0;
@ -9366,21 +9365,38 @@ int slsDetector::pulseChip(int n) {
void slsDetector::setAcquiringFlag(bool b){ void slsDetector::setAcquiringFlag(bool b){
thisDetector->acquiringFlag = b; parentDet->setAcquiringFlag(b);
} }
bool slsDetector::getAcquiringFlag(){ bool slsDetector::getAcquiringFlag(){
return thisDetector->acquiringFlag; return parentDet->getAcquiringFlag();
} }
void slsDetector::setExternalGuiFlag(bool b){ bool slsDetector::isAcquireReady() {
pthread_mutex_lock(&ms); return parentDet->isAcquireReady();
parentDet->setExternalGuiFlag(b);
pthread_mutex_unlock(&ms);
} }
bool slsDetector::getExternalGuiFlag(){
return parentDet->getExternalGuiFlag();
}
int slsDetector::restreamStopFromReceiver(){
int fnum=F_RESTREAM_STOP_FROM_RECEIVER;
int ret = FAIL;
char mess[MAX_STR_LENGTH] = "";
if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) {
#ifdef VERBOSE
std::cout << "To Restream stop dummy from Receiver via zmq" << std::endl;
#endif
if (connectData() == OK){
ret=thisReceiver->executeFunction(fnum,mess);
disconnectData();
}
if(ret==FORCE_UPDATE)
ret=updateReceiver();
else if (ret == FAIL)
setErrorMask((getErrorMask())|(RESTREAM_STOP_FROM_RECEIVER));
}
return ret;
}

View File

@ -265,8 +265,6 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
/** 10 Gbe enable*/ /** 10 Gbe enable*/
int tenGigaEnable; int tenGigaEnable;
/** flag for acquiring */
bool acquiringFlag;
/** flipped data across x or y axis */ /** flipped data across x or y axis */
int flippedData[2]; int flippedData[2];
/** tcp port from gui/different process to receiver (only data) */ /** tcp port from gui/different process to receiver (only data) */
@ -1951,16 +1949,19 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
bool getAcquiringFlag(); bool getAcquiringFlag();
/** /**
Set external gui flag in shared memory * Check if acquiring flag is set, set error if set
\param b set external gui flag * \returns FAIL if not ready, OK if ready
*/ */
void setExternalGuiFlag(bool b=false); bool isAcquireReady();
/** /**
Get external gui flag from shared memory If data streaming in receiver is enabled,
\returns external gui flag restream the stop dummy packet from receiver
Used usually for Moench,
in case it is lost in network due to high data rate
\returns OK if success else FAIL
*/ */
bool getExternalGuiFlag(); int restreamStopFromReceiver();
protected: protected:

View File

@ -184,7 +184,7 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) {
++i; ++i;
/*! \page acquisition /*! \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) - <b> busy i</b> 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_pFuncName="busy"; //
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdStatus; descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdStatus;
@ -2069,6 +2069,12 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) {
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdReceiver; descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdReceiver;
++i; ++i;
/*! \page receiver
- <b>r_restreamstop [i]</b> If data streaming in receiver is enabled, restreams the stop dummy packet via zmq. i can be any value. Only put! \cReturns 1 for success 0 for fail \c (int)
*/
descrToFuncMap[i].m_pFuncName="r_restreamstop"; //
descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdReceiver;
++i;
@ -2460,7 +2466,10 @@ string slsDetectorCommand::cmdStatus(int narg, char *args[], int action) {
} }
else if (cmd=="busy") { else if (cmd=="busy") {
if (action==PUT_ACTION) { 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]; char answer[100];
sprintf(answer,"%d", myDet->getAcquiringFlag()); sprintf(answer,"%d", myDet->getAcquiringFlag());
@ -2479,8 +2488,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("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"); 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("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(); return os.str();
} }
@ -5414,15 +5425,6 @@ string slsDetectorCommand::cmdTimer(int narg, char *args[], int action) {
ret=myDet->setTimer(index,t); ret=myDet->setTimer(index,t);
// cout << "here!"<< endl;
//set frame index
if (index==FRAME_NUMBER || index==CYCLES_NUMBER ){
if ((myDet->setTimer(FRAME_NUMBER,-1)*myDet->setTimer(CYCLES_NUMBER,-1))>1) {
myDet->setFrameIndex(0);
} else
myDet->setFrameIndex(-1);
}
if ((ret!=-1) && (index==ACQUISITION_TIME || index==SUBFRAME_ACQUISITION_TIME || index==FRAME_PERIOD || index==DELAY_AFTER_TRIGGER)) { if ((ret!=-1) && (index==ACQUISITION_TIME || index==SUBFRAME_ACQUISITION_TIME || index==FRAME_PERIOD || index==DELAY_AFTER_TRIGGER)) {
rval=(double)ret*1E-9; rval=(double)ret*1E-9;
sprintf(answer,"%0.9f",rval); sprintf(answer,"%0.9f",rval);
@ -6053,6 +6055,20 @@ string slsDetectorCommand::cmdReceiver(int narg, char *args[], int action) {
} }
else if(cmd=="r_restreamstop"){
if (action==GET_ACTION)
return string("cannot get");
else {
if ((myDet->getRunStatus() != IDLE) || (myDet->getReceiverStatus() != IDLE)) {
std::cout << "Could not restream stop from receiver. Acquisition still in progress" << std::endl;
sprintf(answer,"%d",0);
}
sprintf(answer,"%d",(myDet->restreamStopFromReceiver() == OK) ? 1 : 0);
}
return string(answer);
}
return string("could not decode command"); return string("could not decode command");
} }
@ -6063,12 +6079,13 @@ string slsDetectorCommand::helpReceiver(int narg, char *args[], int action) {
ostringstream os; ostringstream os;
if (action==PUT_ACTION || action==HELP_ACTION) { if (action==PUT_ACTION || action==HELP_ACTION) {
os << "receiver [status] \t starts/stops the receiver to listen to detector packets. - can be start or stop" << std::endl; os << "receiver [status] \t starts/stops the receiver to listen to detector packets. - can be start, stop." << std::endl;
os << "resetframescaught [any value] \t resets frames caught by receiver" << std::endl; os << "resetframescaught [any value] \t resets frames caught by receiver" << std::endl;
os << "r_readfreq \t sets the gui read frequency of the receiver, 0 if gui requests frame, >0 if receiver sends every nth frame to gui" << std::endl; os << "r_readfreq \t sets the gui read frequency of the receiver, 0 if gui requests frame, >0 if receiver sends every nth frame to gui" << std::endl;
os << "tengiga \t sets system to be configure for 10Gbe if set to 1, else 1Gbe if set to 0" << std::endl; os << "tengiga \t sets system to be configure for 10Gbe if set to 1, else 1Gbe if set to 0" << std::endl;
os << "rx_fifodepth [val]\t sets receiver fifo depth to val" << std::endl; os << "rx_fifodepth [val]\t sets receiver fifo depth to val" << std::endl;
os << "r_silent [i]\t sets receiver in silent mode, ie. it will not print anything during real time acquisition. 1 sets, 0 unsets." << std::endl; os << "r_silent [i]\t sets receiver in silent mode, ie. it will not print anything during real time acquisition. 1 sets, 0 unsets." << std::endl;
os << "r_restreamstop [i]\t If data streaming in receiver is enabled and receiver is idle, restreams the stop dummy packet via zmq. i can be any value." << std::endl;
} }
if (action==GET_ACTION || action==HELP_ACTION){ if (action==GET_ACTION || action==HELP_ACTION){
os << "receiver \t returns the status of receiver - can be running or idle" << std::endl; os << "receiver \t returns the status of receiver - can be running or idle" << std::endl;
@ -6078,16 +6095,9 @@ string slsDetectorCommand::helpReceiver(int narg, char *args[], int action) {
os << "tengiga \t returns 1 if the system is configured for 10Gbe else 0 for 1Gbe" << std::endl; os << "tengiga \t returns 1 if the system is configured for 10Gbe else 0 for 1Gbe" << std::endl;
os << "rx_fifodepth \t returns receiver fifo depth" << std::endl; os << "rx_fifodepth \t returns receiver fifo depth" << std::endl;
os << "r_silent \t returns receiver silent mode enable. 1 is silent, 0 not silent." << std::endl; os << "r_silent \t returns receiver silent mode enable. 1 is silent, 0 not silent." << std::endl;
os << "r_restreamstop \t returns if restreaming the stop dummy packet from receiver via zmq was success(1) or fail(0)" << std:: endl;
} }
return os.str(); return os.str();
} }
string slsDetectorCommand::helpPattern(int narg, char *args[], int action) { string slsDetectorCommand::helpPattern(int narg, char *args[], int action) {

View File

@ -42,20 +42,16 @@ slsDetectorUtils::slsDetectorUtils() {
int slsDetectorUtils::acquire(int delflag){ int slsDetectorUtils::acquire(int delflag){
//ensure acquire isnt started multiple times by same client //ensure acquire isnt started multiple times by same client
if(getAcquiringFlag() == false) if (isAcquireReady() == FAIL)
setAcquiringFlag(true);
else{
std::cout << "Error: Acquire has already been started." << std::endl;
return FAIL; return FAIL;
}
#ifdef VERBOSE #ifdef VERBOSE
struct timespec begin,end; struct timespec begin,end;
clock_gettime(CLOCK_REALTIME, &begin); clock_gettime(CLOCK_REALTIME, &begin);
#endif #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 //in the real time acquisition loop, processing thread will wait for a post each time
sem_init(&sem_newRTAcquisition,1,0); sem_init(&sem_newRTAcquisition,1,0);
//in the real time acquistion loop, main thread will wait for processing thread to be done each time (which in turn waits for receiver/ext process) //in the real time acquistion loop, main thread will wait for processing thread to be done each time (which in turn waits for receiver/ext process)
@ -71,17 +67,13 @@ int slsDetectorUtils::acquire(int delflag){
int nf=setTimer(FRAME_NUMBER,-1); int nf=setTimer(FRAME_NUMBER,-1);
if (nc==0) nc=1; if (nc==0) nc=1;
if (nf==0) nf=1; if (nf==0) nf=1;
int multiframe = nc*nf; int multiframe = nc*nf;
// setTotalProgress();
//moved these 2 here for measurement change
progressIndex=0; progressIndex=0;
*stoppedFlag=0; *stoppedFlag=0;
angCalLogClass *aclog=NULL; angCalLogClass *aclog=NULL;
enCalLogClass *eclog=NULL; enCalLogClass *eclog=NULL;
// int lastindex=startindex, nowindex=startindex;
int connectChannels=0; int connectChannels=0;
#ifdef VERBOSE #ifdef VERBOSE
@ -90,8 +82,6 @@ int slsDetectorUtils::acquire(int delflag){
#endif #endif
void *status; void *status;
if ((*correctionMask&(1<< ANGULAR_CONVERSION)) || (*correctionMask&(1<< I0_NORMALIZATION)) || getActionMode(angCalLog) || (getScanMode(0)==positionScan)|| (getScanMode(1)==positionScan)) { if ((*correctionMask&(1<< ANGULAR_CONVERSION)) || (*correctionMask&(1<< I0_NORMALIZATION)) || getActionMode(angCalLog) || (getScanMode(0)==positionScan)|| (getScanMode(1)==positionScan)) {
if (connectChannels==0) if (connectChannels==0)
if (connect_channels) { if (connect_channels) {
@ -99,8 +89,6 @@ int slsDetectorUtils::acquire(int delflag){
connectChannels=1; connectChannels=1;
} }
} }
if (getActionMode(angCalLog)) { if (getActionMode(angCalLog)) {
aclog=new angCalLogClass(this); aclog=new angCalLogClass(this);
} }
@ -110,13 +98,10 @@ int slsDetectorUtils::acquire(int delflag){
} }
setJoinThread(0); setJoinThread(0);
positionFinished(0); positionFinished(0);
int nm=timerValue[MEASUREMENTS_NUMBER]; int nm=timerValue[MEASUREMENTS_NUMBER];
if (nm<1) if (nm<1)
nm=1; nm=1;
@ -141,12 +126,13 @@ int slsDetectorUtils::acquire(int delflag){
ns1=1; ns1=1;
} }
// verify receiver is idle
if(receiver){ if(receiver){
pthread_mutex_lock(&mg); //cout << "lock"<< endl; pthread_mutex_lock(&mg);
if(getReceiverStatus()!=IDLE) if(getReceiverStatus()!=IDLE)
if(stopReceiver() == FAIL) if(stopReceiver() == FAIL)
*stoppedFlag=1; *stoppedFlag=1;
pthread_mutex_unlock(&mg);//cout << "unlock"<< endl; pthread_mutex_unlock(&mg);
} }
@ -158,10 +144,10 @@ int slsDetectorUtils::acquire(int delflag){
//resets frames caught in receiver //resets frames caught in receiver
if(receiver){ if(receiver){
pthread_mutex_lock(&mg); //cout << "lock"<< endl; pthread_mutex_lock(&mg);
if (resetFramesCaught() == FAIL) if (resetFramesCaught() == FAIL)
*stoppedFlag=1; *stoppedFlag=1;
pthread_mutex_unlock(&mg);//cout << "unlock"<< endl; pthread_mutex_unlock(&mg);
} }
@ -171,23 +157,12 @@ int slsDetectorUtils::acquire(int delflag){
cout << " starting measurement "<< im << " of " << nm << endl; cout << " starting measurement "<< im << " of " << nm << endl;
#endif #endif
// start script
//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) { if (*stoppedFlag==0) {
executeAction(startScript); executeAction(startScript);
} }
for (int is0=0; is0<ns0; ++is0) { for (int is0=0; is0<ns0; ++is0) {
// cout << "scan0 loop" << endl;
if (*stoppedFlag==0) { if (*stoppedFlag==0) {
executeScan(0,is0); executeScan(0,is0);
@ -196,7 +171,6 @@ int slsDetectorUtils::acquire(int delflag){
for (int is1=0; is1<ns1; ++is1) { for (int is1=0; is1<ns1; ++is1) {
// cout << "scan1 loop" << endl;
if (*stoppedFlag==0) { if (*stoppedFlag==0) {
executeScan(1,is1); executeScan(1,is1);
@ -212,7 +186,6 @@ int slsDetectorUtils::acquire(int delflag){
for (int ip=0; ip<np; ++ip) { for (int ip=0; ip<np; ++ip) {
// cout << "positions " << endl;
if (*stoppedFlag==0) { if (*stoppedFlag==0) {
if (getNumberOfPositions()>0) { if (getNumberOfPositions()>0) {
moveDetector(detPositions[ip]); moveDetector(detPositions[ip]);
@ -229,25 +202,22 @@ int slsDetectorUtils::acquire(int delflag){
createFileName(); createFileName();
pthread_mutex_unlock(&mp); pthread_mutex_unlock(&mp);
// script before
if (*stoppedFlag==0) { if (*stoppedFlag==0) {
executeAction(scriptBefore); executeAction(scriptBefore);
} else } else
break; break;
// header before
if (*stoppedFlag==0) { if (*stoppedFlag==0) {
executeAction(headerBefore); executeAction(headerBefore);
if (*correctionMask&(1<< ANGULAR_CONVERSION) || aclog){// || eclog) { if (*correctionMask&(1<< ANGULAR_CONVERSION) || aclog){
positionFinished(0); positionFinished(0);
setCurrentPosition(getDetectorPosition()); setCurrentPosition(getDetectorPosition());
} }
if (aclog) if (aclog)
aclog->addStep(getCurrentPosition(), getCurrentFileName()); aclog->addStep(getCurrentPosition(), getCurrentFileName());
@ -262,56 +232,48 @@ int slsDetectorUtils::acquire(int delflag){
setCurrentFrameIndex(0); setCurrentFrameIndex(0);
if(receiver)
pthread_mutex_lock(&mg); //cout << "lock"<< endl;
if (multiframe>1) if (multiframe>1)
setFrameIndex(0); setFrameIndex(0);
else else
setFrameIndex(-1); setFrameIndex(-1);
// file name and start receiver
if(receiver){ if(receiver){
pthread_mutex_unlock(&mg);//cout << "unlock"<< endl;
pthread_mutex_lock(&mp); pthread_mutex_lock(&mp);
createFileName(); createFileName();
pthread_mutex_unlock(&mp); pthread_mutex_unlock(&mp);
//send receiver file name //send receiver file name
pthread_mutex_lock(&mg); //cout << "lock"<< endl; pthread_mutex_lock(&mg);
setFileName(fileIO::getFileName()); setFileName(fileIO::getFileName());
//start receiver
if(startReceiver() == FAIL) { if(startReceiver() == FAIL) {
cout << "Start receiver failed " << endl; cout << "Start receiver failed " << endl;
stopReceiver(); stopReceiver();
*stoppedFlag=1; *stoppedFlag=1;
pthread_mutex_unlock(&mg);//cout << "unlock"<< endl; pthread_mutex_unlock(&mg);
break; break;
} }
#ifdef VERBOSE #ifdef VERBOSE
cout << "Receiver started " << endl; cout << "Receiver started " << endl;
#endif #endif
pthread_mutex_unlock(&mg);//cout << "unlock"<< endl; pthread_mutex_unlock(&mg);
//let processing thread listen to these packets //let processing thread listen to these packets
sem_post(&sem_newRTAcquisition); sem_post(&sem_newRTAcquisition);
} }
#ifdef VERBOSE #ifdef VERBOSE
cout << "Acquiring " << endl; cout << "Acquiring " << endl;
#endif #endif
startAndReadAll(); startAndReadAll();
#ifdef VERBOSE #ifdef VERBOSE
cout << "detector finished " << endl; cout << "detector finished" << endl;
#endif
#ifdef VERBOSE
cout << "returned! " << endl; cout << "returned! " << endl;
#endif #endif
if (*correctionMask&(1<< I0_NORMALIZATION)) { if (*correctionMask&(1<< I0_NORMALIZATION)) {
if (get_i0) if (get_i0)
currentI0=get_i0(1,IOarg); // this is the correct i0!!!!! currentI0=get_i0(1,IOarg);
} }
#ifdef VERBOSE #ifdef VERBOSE
cout << "pos finished? " << endl; cout << "pos finished? " << endl;
@ -328,7 +290,6 @@ int slsDetectorUtils::acquire(int delflag){
#ifdef VERBOSE #ifdef VERBOSE
cout << "start unthreaded process data " << endl; cout << "start unthreaded process data " << endl;
#endif #endif
processData(delflag); processData(delflag);
} }
@ -336,65 +297,59 @@ int slsDetectorUtils::acquire(int delflag){
break; break;
while (dataQueueSize()) usleep(100000); while (dataQueueSize()) usleep(100000);
// cout << "mglock " << endl;;
// close file
pthread_mutex_lock(&mg); //cout << "lock"<< endl;
// cout << "done " << endl;;
//offline
if(!receiver){ if(!receiver){
if ((getDetectorsType()==GOTTHARD) || (getDetectorsType()==MOENCH) || (getDetectorsType()==JUNGFRAU)|| (getDetectorsType()==JUNGFRAUCTB) ){ detectorType type = getDetectorsType();
if ((type==GOTTHARD) || (type==MOENCH) || (type==JUNGFRAUCTB) ){
if((*correctionMask)&(1<<WRITE_FILE)) if((*correctionMask)&(1<<WRITE_FILE))
closeDataFile(); closeDataFile();
} }
} }
//online
// stop receiver
else{ else{
if (stopReceiver() == FAIL) pthread_mutex_lock(&mg);
if (stopReceiver() == FAIL) {
*stoppedFlag = 1; *stoppedFlag = 1;
else { pthread_mutex_unlock(&mg);
if (*threadedProcessing && dataReady) // threaded processing } else {
pthread_mutex_unlock(&mg);
if (*threadedProcessing && dataReady)
sem_wait(&sem_endRTAcquisition); // waits for receiver's external process to be done sending data to gui sem_wait(&sem_endRTAcquisition); // waits for receiver's external process to be done sending data to gui
} }
// cout<<"***********receiver stopped"<<endl;
} }
pthread_mutex_unlock(&mg);//cout << "unlock"<< endl;
// header after
pthread_mutex_lock(&mp);
if (*stoppedFlag==0) { if (*stoppedFlag==0) {
pthread_mutex_lock(&mp);
executeAction(headerAfter); executeAction(headerAfter);
pthread_mutex_unlock(&mp); pthread_mutex_unlock(&mp);
// setLastIndex(*fileIndex);
} else {
// setLastIndex(*fileIndex);
pthread_mutex_unlock(&mp);
break;
} }
if (*stoppedFlag) { if (*stoppedFlag) {
#ifdef VERBOSE #ifdef VERBOSE
std::cout<< "exiting since the detector has been stopped" << std::endl; std::cout<< "exiting since the detector has been stopped" << std::endl;
#endif #endif
break; break;
} else if (ip<(np-1)) {
// pthread_mutex_lock(&mp);
// *fileIndex=setStartIndex();
// pthread_mutex_unlock(&mp);
} }
} // loop on position finished
}//end position loop ip
//script after //script after
if (*stoppedFlag==0) { if (*stoppedFlag==0) {
executeAction(scriptAfter); executeAction(scriptAfter);
} else }
if (*stoppedFlag) {
#ifdef VERBOSE
std::cout<< "exiting since the detector has been stopped" << std::endl;
#endif
break; break;
}
}//end scan1 loop is1
if (*stoppedFlag) { if (*stoppedFlag) {
@ -402,46 +357,28 @@ int slsDetectorUtils::acquire(int delflag){
std::cout<< "exiting since the detector has been stopped" << std::endl; std::cout<< "exiting since the detector has been stopped" << std::endl;
#endif #endif
break; break;
} else if (is1<(ns1-1)) {
// pthread_mutex_lock(&mp);
// *fileIndex=setStartIndex();
// pthread_mutex_unlock(&mp);
}
} }
//end scan1 loop is1 }//end scan0 loop is0
if (*stoppedFlag) {
#ifdef VERBOSE
std::cout<< "exiting since the detector has been stopped" << std::endl;
#endif
break;
} else if (is0<(ns0-1)) {
// pthread_mutex_lock(&mp);
// *fileIndex=setStartIndex();
// pthread_mutex_unlock(&mp);
}
} //end scan0 loop is0
// pthread_mutex_lock(&mp);
// *fileIndex=setLastIndex();
// pthread_mutex_unlock(&mp);
if (*stoppedFlag==0) { if (*stoppedFlag==0) {
executeAction(stopScript); executeAction(stopScript);
} else{ }
if (*stoppedFlag) {
#ifdef VERBOSE #ifdef VERBOSE
cout << "findex incremented " << endl; cout << "findex incremented " << endl;
#endif #endif
if(*correctionMask&(1<<WRITE_FILE)) if(*correctionMask&(1<<WRITE_FILE))
IncrementFileIndex(); IncrementFileIndex();
pthread_mutex_lock(&mg); //cout << "lock"<< endl; pthread_mutex_lock(&mg);
setFileIndex(fileIO::getFileIndex()); setFileIndex(fileIO::getFileIndex());
pthread_mutex_unlock(&mg);//cout << "unlock"<< endl; pthread_mutex_unlock(&mg);
#ifdef VERBOSE
std::cout<< "exiting since the detector has been stopped" << std::endl;
#endif
break; break;
} }
@ -462,12 +399,13 @@ int slsDetectorUtils::acquire(int delflag){
} }
if (*stoppedFlag) { if (*stoppedFlag) {
#ifdef VERBOSE
std::cout<< "exiting since the detector has been stopped" << std::endl;
#endif
break; break;
} }
}//end measurements loop im
// loop measurements
}
@ -518,10 +456,12 @@ int slsDetectorUtils::acquire(int delflag){
clock_gettime(CLOCK_REALTIME, &end); clock_gettime(CLOCK_REALTIME, &end);
cout << "Elapsed time for acquisition:" << (( end.tv_sec - begin.tv_sec ) + ( end.tv_nsec - begin.tv_nsec ) / 1000000000.0) << " seconds" << endl; cout << "Elapsed time for acquisition:" << (( end.tv_sec - begin.tv_sec ) + ( end.tv_nsec - begin.tv_nsec ) / 1000000000.0) << " seconds" << endl;
#endif #endif
setAcquiringFlag(false); setAcquiringFlag(false);
return OK; return OK;
} }

View File

@ -939,33 +939,21 @@ virtual int setReceiverSilentMode(int i = -1)=0;
*/ */
virtual bool getAcquiringFlag() = 0; virtual bool getAcquiringFlag() = 0;
/**
Set external gui flag in shared memory
\param b set external gui flag
*/
virtual void setExternalGuiFlag(bool b=false) = 0;
/** /**
Get external gui flag from shared memory * Check if acquiring flag is set, set error if set
\returns external gui flag * \returns FAIL if not ready, OK if ready
*/ */
virtual bool getExternalGuiFlag() = 0; virtual bool isAcquireReady() = 0;
/**
If data streaming in receiver is enabled,
restream the stop dummy packet from receiver
Used usually for Moench,
in case it is lost in network due to high data rate
\returns OK if success else FAIL
*/
virtual int restreamStopFromReceiver() = 0;