parallelized settimer, setfileindex, setonline, setreceiveronline, getreceiverstatus, resetframescaught, setFrameIndex, setFileName, getFramesCaughtByReceiver; added getFramesCaughtbyAnyreceiver to avoid threadpool and to use in post processing

This commit is contained in:
Dhanya Maliakal
2017-09-18 16:47:22 +02:00
parent 54d231d3c6
commit a95e2efdb0
10 changed files with 369 additions and 165 deletions

View File

@ -114,6 +114,7 @@ multiSlsDetector::multiSlsDetector(int id) : slsDetectorUtils(), shmId(-1)
thisMultiDetector->onlineFlag = ONLINE_FLAG; thisMultiDetector->onlineFlag = ONLINE_FLAG;
thisMultiDetector->receiverOnlineFlag = OFFLINE_FLAG;
thisMultiDetector->numberOfDetectors=0; thisMultiDetector->numberOfDetectors=0;
for (int id=0; id<MAXDET; id++) { for (int id=0; id<MAXDET; id++) {
thisMultiDetector->detectorIds[id]=-1; thisMultiDetector->detectorIds[id]=-1;
@ -297,18 +298,18 @@ int multiSlsDetector::createThreadPool(){
if(threadpool){ if(threadpool){
threadpool->destroy_threadpool(); threadpool->destroy_threadpool();
} }
if(thisMultiDetector->numberOfDetectors < 1){ int numthreads = thisMultiDetector->numberOfDetectors;
cout << "No detectors attached to create threadpool" << endl; if(numthreads < 1){
return OK; numthreads = 1; //create threadpool anyway, threads initialized only when >1 detector added
} }
threadpool = new ThreadPool(thisMultiDetector->numberOfDetectors); threadpool = new ThreadPool(numthreads);
switch(threadpool->initialize_threadpool()){ switch(threadpool->initialize_threadpool()){
case 0: case 0:
cerr << "Failed to initialize thread pool!" << endl; cerr << "Failed to initialize thread pool!" << endl;
return FAIL; return FAIL;
case 1: case 1:
#ifdef VERBOSE #ifdef VERBOSE
cout << "Not initializing threads, only one detector" << endl; cout << "Not initializing threads, not multi detector" << endl;
#endif #endif
break; break;
default: default:
@ -416,7 +417,7 @@ int multiSlsDetector::addSlsDetector(int id, int pos) {
} }
void multiSlsDetector::updateOffsets(){ void multiSlsDetector::updateOffsets(){//cannot paralllize due to slsdetector calling this via parentdet->
#ifdef VERBOSE #ifdef VERBOSE
cout << endl << "Updating Multi-Detector Offsets" << endl; cout << endl << "Updating Multi-Detector Offsets" << endl;
#endif #endif
@ -1067,20 +1068,45 @@ slsDetectorDefs::synchronizationMode multiSlsDetector::setSynchronization(synchr
int multiSlsDetector::setOnline(int off) { int multiSlsDetector::setOnline(int off) {
// int retdet;
if (off!=GET_ONLINE_FLAG) { if (off!=GET_ONLINE_FLAG) {
thisMultiDetector->onlineFlag=off; thisMultiDetector->onlineFlag=off;
for (int i=0; i<thisMultiDetector->numberOfDetectors; i++) {
if (detectors[i]){ int ret=-100;
detectors[i]->setOnline(off); if(!threadpool){
if(detectors[i]->getErrorMask()) cout << "Error in creating threadpool. Exiting" << endl;
setErrorMask(getErrorMask()|(1<<i)); return -1;
}else{
//return storage values
int* iret[thisMultiDetector->numberOfDetectors];
for(int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++){
if(detectors[idet]){
iret[idet]= new int(-1);
Task* task = new Task(new func1_t<int,int>(&slsDetector::setOnline,
detectors[idet],off,iret[idet]));
threadpool->add_task(task);
} }
} }
threadpool->startExecuting();
threadpool->wait_for_tasks_to_complete();
for(int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++){
if(detectors[idet]){
if(iret[idet] != NULL){
if (ret==-100)
ret=*iret[idet];
else if (ret!=*iret[idet])
ret=-1;
delete iret[idet];
}else ret=-1;
if(detectors[idet]->getErrorMask())
setErrorMask(getErrorMask()|(1<<idet));
}
}
}
thisMultiDetector->onlineFlag=ret;
} }
return thisMultiDetector->onlineFlag; return thisMultiDetector->onlineFlag;
}; };
@ -3165,7 +3191,7 @@ dacs_t multiSlsDetector::setDAC(dacs_t val, dacIndex idac, int mV, int imod) {
for(int idet=posmin; idet<posmax; ++idet){ for(int idet=posmin; idet<posmax; ++idet){
if(detectors[idet]){ if(detectors[idet]){
iret[idet]= new dacs_t(-1); iret[idet]= new dacs_t(-1);
Task* task = new Task(new func4_t <dacs_t,dacs_t,dacIndex,int,int>(&slsDetector::setDAC, Task* task = new Task(new func4_t<dacs_t,dacs_t,dacIndex,int,int>(&slsDetector::setDAC,
detectors[idet],val, idac, mV, imod, iret[idet])); detectors[idet],val, idac, mV, imod, iret[idet]));
threadpool->add_task(task); threadpool->add_task(task);
} }
@ -3227,7 +3253,7 @@ dacs_t multiSlsDetector::getADC(dacIndex idac, int imod) {
for(int idet=posmin; idet<posmax; ++idet){ for(int idet=posmin; idet<posmax; ++idet){
if(detectors[idet]){ if(detectors[idet]){
iret[idet]= new dacs_t(-1); iret[idet]= new dacs_t(-1);
Task* task = new Task(new func2_t <dacs_t,dacIndex,int>(&slsDetector::getADC, Task* task = new Task(new func2_t<dacs_t,dacIndex,int>(&slsDetector::getADC,
detectors[idet],idac, imod, iret[idet])); detectors[idet],idac, imod, iret[idet]));
threadpool->add_task(task); threadpool->add_task(task);
} }
@ -3625,7 +3651,7 @@ string multiSlsDetector::setNetworkParameter(networkParameter p, string s){
if (p == RECEIVER_STREAMING_PORT) if (p == RECEIVER_STREAMING_PORT)
s.append("multi\0"); s.append("multi\0");
sret[idet]=new string("error"); sret[idet]=new string("error");
Task* task = new Task(new func2_t <string,networkParameter,string>(&slsDetector::setNetworkParameter, Task* task = new Task(new func2_t<string,networkParameter,string>(&slsDetector::setNetworkParameter,
detectors[idet],p,s,sret[idet])); detectors[idet],p,s,sret[idet]));
threadpool->add_task(task); threadpool->add_task(task);
} }
@ -4281,7 +4307,7 @@ int multiSlsDetector::executeTrimming(trimMode mode, int par1, int par2, int imo
for(int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++){ for(int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++){
if(detectors[idet]){ if(detectors[idet]){
iret[idet]= new int(-1); iret[idet]= new int(-1);
Task* task = new Task(new func4_t <int,trimMode,int,int,int>(&slsDetector::executeTrimming, Task* task = new Task(new func4_t<int,trimMode,int,int,int>(&slsDetector::executeTrimming,
detectors[idet],mode,par1,par2,imod,iret[idet])); detectors[idet],mode,par1,par2,imod,iret[idet]));
threadpool->add_task(task); threadpool->add_task(task);
} }
@ -4384,7 +4410,7 @@ int multiSlsDetector::loadSettingsFile(string fname, int imod) {
for(int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++){ for(int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++){
if(detectors[idet]){ if(detectors[idet]){
iret[idet]= new int(OK); iret[idet]= new int(OK);
Task* task = new Task(new func2_t <int,string,int>(&slsDetector::loadSettingsFile, Task* task = new Task(new func2_t<int,string,int>(&slsDetector::loadSettingsFile,
detectors[idet],fname,imod,iret[idet])); detectors[idet],fname,imod,iret[idet]));
threadpool->add_task(task); threadpool->add_task(task);
} }
@ -4458,7 +4484,7 @@ int multiSlsDetector::setAllTrimbits(int val, int imod){
for(int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++){ for(int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++){
if(detectors[idet]){ if(detectors[idet]){
iret[idet]= new int(-1); iret[idet]= new int(-1);
Task* task = new Task(new func2_t <int,int,int>(&slsDetector::setAllTrimbits, Task* task = new Task(new func2_t<int,int,int>(&slsDetector::setAllTrimbits,
detectors[idet],val,imod,iret[idet])); detectors[idet],val,imod,iret[idet]));
threadpool->add_task(task); threadpool->add_task(task);
} }
@ -4512,7 +4538,7 @@ int multiSlsDetector::loadCalibrationFile(string fname, int imod) {
for(int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++){ for(int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++){
if(detectors[idet]){ if(detectors[idet]){
iret[idet]= new int(OK); iret[idet]= new int(OK);
Task* task = new Task(new func2_t <int,string,int>(&slsDetector::loadCalibrationFile, Task* task = new Task(new func2_t<int,string,int>(&slsDetector::loadCalibrationFile,
detectors[idet],fname,imod,iret[idet])); detectors[idet],fname,imod,iret[idet]));
threadpool->add_task(task); threadpool->add_task(task);
} }
@ -5061,18 +5087,42 @@ int multiSlsDetector::readDataFile(string fname, int *data) {
int multiSlsDetector::setReceiverOnline(int off) { int multiSlsDetector::setReceiverOnline(int off) {
int ret=-100,ret1;
for (int i=0; i<thisMultiDetector->numberOfDetectors; i++) if (off != GET_ONLINE_FLAG) {
if (detectors[i]){ int ret=-100;
ret1=detectors[i]->setReceiverOnline(off); if(!threadpool){
if(detectors[i]->getErrorMask()) cout << "Error in creating threadpool. Exiting" << endl;
setErrorMask(getErrorMask()|(1<<i)); return -1;
if(ret==-100) }else{
ret=ret1; //return storage values
else if (ret!=ret1) int* iret[thisMultiDetector->numberOfDetectors];
ret=-1; for(int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++){
if(detectors[idet]){
iret[idet]= new int(-1);
Task* task = new Task(new func1_t<int,int>(&slsDetector::setReceiverOnline,
detectors[idet],off,iret[idet]));
threadpool->add_task(task);
} }
return ret; }
threadpool->startExecuting();
threadpool->wait_for_tasks_to_complete();
for(int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++){
if(detectors[idet]){
if(iret[idet] != NULL){
if (ret==-100)
ret=*iret[idet];
else if (ret!=*iret[idet])
ret=-1;
delete iret[idet];
}else ret=-1;
if(detectors[idet]->getErrorMask())
setErrorMask(getErrorMask()|(1<<idet));
}
}
}
thisMultiDetector->receiverOnlineFlag=ret;
}
return thisMultiDetector->receiverOnlineFlag;
} }
@ -5120,20 +5170,40 @@ string multiSlsDetector::setFilePath(string s) {
string multiSlsDetector::setFileName(string s) { string multiSlsDetector::setFileName(string s) {
string ret="error", ret1;
for (int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++) { string ret = "error";
if (detectors[idet]) { int posmax = thisMultiDetector->numberOfDetectors;
ret1=detectors[idet]->setFileName(s);
if(!threadpool){
cout << "Error in creating threadpool. Exiting" << endl;
return string("");
} else {
string* sret[thisMultiDetector->numberOfDetectors];
for(int idet=0; idet<posmax; ++idet){
if(detectors[idet]){
sret[idet]=new string("error");
Task* task = new Task(new func1_t<string,string>(&slsDetector::setFileName,
detectors[idet],s,sret[idet]));
threadpool->add_task(task);
}
}
threadpool->startExecuting();
threadpool->wait_for_tasks_to_complete();
for(int idet=0; idet<posmax; idet++){
if(detectors[idet]){
if(sret[idet]!= NULL) {
if(ret == "error")
ret = *sret[idet];
else if (ret != *sret[idet])
ret="";
delete sret[idet];
}else ret = "";
//doing nothing with the return values
if(detectors[idet]->getErrorMask()) if(detectors[idet]->getErrorMask())
setErrorMask(getErrorMask()|(1<<idet)); setErrorMask(getErrorMask()|(1<<idet));
if (ret=="error")
ret=ret1;
else if (ret!=ret1)
ret="";
} }
} }
}
return ret; return ret;
} }
@ -5328,52 +5398,120 @@ slsDetectorDefs::runStatus multiSlsDetector::startReceiverReadout(){
} }
slsDetectorDefs::runStatus multiSlsDetector::getReceiverStatus(){ slsDetectorDefs::runStatus multiSlsDetector::getReceiverStatus(){
int i=0;
runStatus ret=IDLE;
int posmin=0, posmax=thisMultiDetector->numberOfDetectors;
runStatus s = IDLE,s1 = IDLE; i=thisMultiDetector->masterPosition;
if (thisMultiDetector->masterPosition>=0) {
if (thisMultiDetector->masterPosition>=0) if (detectors[i]) {
if (detectors[thisMultiDetector->masterPosition]){ ret=detectors[i]->getReceiverStatus();
s = detectors[thisMultiDetector->masterPosition]->getReceiverStatus();
if(detectors[thisMultiDetector->masterPosition]->getErrorMask())
setErrorMask(getErrorMask()|(1<<thisMultiDetector->masterPosition));
return s;
}
// if (detectors[0]) s=detectors[0]->getReceiverStatus();
for (int i=0; i<thisMultiDetector->numberOfDetectors; i++) {
s1=detectors[i]->getReceiverStatus();
if(detectors[i]->getErrorMask()) if(detectors[i]->getErrorMask())
setErrorMask(getErrorMask()|(1<<i)); setErrorMask(getErrorMask()|(1<<i));
if (s1==ERROR) return ret;
s=ERROR;
//if (s1==IDLE && s!=IDLE)
// s=ERROR;
if (s1!=IDLE)
s = s1;
} }
return s; }
if(!threadpool){
cout << "Error in creating threadpool. Exiting" << endl;
return ERROR;
}else{
runStatus* iret[posmax-posmin];
for(int idet=posmin; idet<posmax; idet++){
if((idet!=thisMultiDetector->masterPosition) && (detectors[idet])){
iret[idet]= new runStatus(ERROR);
Task* task = new Task(new func0_t<runStatus>(&slsDetector::getReceiverStatus,
detectors[idet],iret[idet]));
threadpool->add_task(task);
}
}
threadpool->startExecuting();
threadpool->wait_for_tasks_to_complete();
for(int idet=posmin; idet<posmax; idet++){
if((idet!=thisMultiDetector->masterPosition) && (detectors[idet])){
if(iret[idet] != NULL){
if(*iret[idet] == (int)ERROR)
ret = ERROR;
if(*iret[idet] != IDLE)
ret = *iret[idet];
delete iret[idet];
}else ret = ERROR;
if(detectors[idet]->getErrorMask())
setErrorMask(getErrorMask()|(1<<idet));
}
}
}
return ret;
} }
int multiSlsDetector::getFramesCaughtByAnyReceiver() {
int ret = 0;
int i = thisMultiDetector->masterPosition;
if (i >=0 ) {
int multiSlsDetector::getFramesCaughtByReceiver() { if (detectors[i]){
int ret=0,ret1=0; ret=detectors[i]->getFramesCaughtByReceiver();
if(detectors[i]->getErrorMask())
setErrorMask(getErrorMask()|(1<<i));
// return master receivers frames caught
return ret;
}
}
for (int i=0; i<thisMultiDetector->numberOfDetectors; i++) for (int i=0; i<thisMultiDetector->numberOfDetectors; i++)
if (detectors[i]){ if (detectors[i]){
ret1+=detectors[i]->getFramesCaughtByReceiver(); ret=detectors[i]->getFramesCaughtByReceiver();
if(detectors[i]->getErrorMask()) if(detectors[i]->getErrorMask())
setErrorMask(getErrorMask()|(1<<i)); setErrorMask(getErrorMask()|(1<<i));
// return the first one that works
}
if(!thisMultiDetector->numberOfDetectors)
return ret; return ret;
ret=(int)(ret1/thisMultiDetector->numberOfDetectors); }
return -1;
}
int multiSlsDetector::getFramesCaughtByReceiver() {
int ret=0,ret1=0;
int posmax = thisMultiDetector->numberOfDetectors;
if(!threadpool){
cout << "Error in creating threadpool. Exiting" << endl;
return -1;
}else{
int* iret[posmax];
for(int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++){
if(detectors[idet]){
iret[idet]= new int(0);
Task* task = new Task(new func0_t<int>(&slsDetector::getFramesCaughtByReceiver,
detectors[idet],iret[idet]));
threadpool->add_task(task);
}
}
threadpool->startExecuting();
threadpool->wait_for_tasks_to_complete();
for(int idet=0; idet<posmax; idet++){
if(detectors[idet]){
if(iret[idet] != NULL){
if(*iret[idet] == -1) // could not connect
ret = -1;
else
ret1+=(*iret[idet]);
delete iret[idet];
}else ret = -1;
if(detectors[idet]->getErrorMask())
setErrorMask(getErrorMask()|(1<<idet));
}
}
}
if ((!thisMultiDetector->numberOfDetectors) || (ret == -1))
return ret;
ret=(int)(ret1/thisMultiDetector->numberOfDetectors);
return ret; return ret;
} }
@ -5397,17 +5535,36 @@ int multiSlsDetector::getReceiverCurrentFrameIndex() {
int multiSlsDetector::resetFramesCaught() { int multiSlsDetector::resetFramesCaught() {
int ret=-100, ret1;
for (int i=0; i<thisMultiDetector->numberOfDetectors; i++){ int ret=OK;
if (detectors[i]){ int posmax = thisMultiDetector->numberOfDetectors;
ret1=detectors[i]->resetFramesCaught();
if(detectors[i]->getErrorMask()) if(!threadpool){
setErrorMask(getErrorMask()|(1<<i)); cout << "Error in creating threadpool. Exiting" << endl;
if (ret==-100) return FAIL;
ret=ret1; }else{
else if (ret!=ret1) int* iret[posmax];
ret=-1; for(int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++){
if(detectors[idet]){
iret[idet]= new int(OK);
Task* task = new Task(new func0_t<int>(&slsDetector::resetFramesCaught,
detectors[idet],iret[idet]));
threadpool->add_task(task);
}
}
threadpool->startExecuting();
threadpool->wait_for_tasks_to_complete();
for(int idet=0; idet<posmax; idet++){
if(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<<idet));
}
} }
} }
@ -5772,21 +5929,39 @@ int multiSlsDetector::overwriteFile(int enable){
int multiSlsDetector::setFrameIndex(int index){ int multiSlsDetector::setFrameIndex(int index){
int ret=-100, ret1; int ret=-100;
int posmax = thisMultiDetector->numberOfDetectors;
fileIO::setFrameIndex(index); fileIO::setFrameIndex(index);
for (int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++) { if(!threadpool){
if (detectors[idet]) { cout << "Error in creating threadpool. Exiting" << endl;
ret1=detectors[idet]->setFrameIndex(index); return -1;
}else{
//return storage values
int* iret[thisMultiDetector->numberOfDetectors];
for(int idet=0; idet<posmax; idet++){
if(detectors[idet]){
iret[idet]= new int(-1);
Task* task = new Task(new func1_t<int,int>(&slsDetector::setFrameIndex,
detectors[idet],index,iret[idet]));
threadpool->add_task(task);
}
}
threadpool->startExecuting();
threadpool->wait_for_tasks_to_complete();
for(int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++){
if(detectors[idet]){
if(iret[idet] != NULL){
if (ret==-100)
ret=*iret[idet];
else if (ret!=*iret[idet])
ret=-1;
delete iret[idet];
}else ret=-1;
if(detectors[idet]->getErrorMask()) if(detectors[idet]->getErrorMask())
setErrorMask(getErrorMask()|(1<<idet)); setErrorMask(getErrorMask()|(1<<idet));
if (ret==-100)
ret=ret1;
else if (ret!=ret1)
ret=-1;
} }
} }
}
return ret; return ret;
} }
@ -5910,7 +6085,7 @@ int multiSlsDetector::getStreamingSocketsCreatedInClient() {
return dataSocketsStarted; return dataSocketsStarted;
} }
int multiSlsDetector::enableDataStreamingFromReceiver(int enable){ int multiSlsDetector::enableDataStreamingFromReceiver(int enable){//cannot parrallize due to serReceiver calling parentdet->enabledatastremain
//create client sockets only if no external gui //create client sockets only if no external gui
if (!thisMultiDetector->externalgui) { if (!thisMultiDetector->externalgui) {
@ -5944,7 +6119,7 @@ int multiSlsDetector::enableDataStreamingFromReceiver(int enable){
for(int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++){ for(int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++){
if(detectors[idet]){ if(detectors[idet]){
iret[idet]= new int(-1); iret[idet]= new int(-1);
Task* task = new Task(new func1_t <int,int>(&slsDetector::enableDataStreamingFromReceiver, Task* task = new Task(new func1_t<int,int>(&slsDetector::enableDataStreamingFromReceiver,
detectors[idet],enable,iret[idet])); detectors[idet],enable,iret[idet]));
threadpool->add_task(task); threadpool->add_task(task);
} }
@ -6173,7 +6348,7 @@ int multiSlsDetector::pulsePixel(int n,int x,int y) {
for(int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++){ for(int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++){
if(detectors[idet]){ if(detectors[idet]){
iret[idet]= new int(-1); iret[idet]= new int(-1);
Task* task = new Task(new func3_t <int,int,int,int>(&slsDetector::pulsePixel, Task* task = new Task(new func3_t<int,int,int,int>(&slsDetector::pulsePixel,
detectors[idet],n,x,y,iret[idet])); detectors[idet],n,x,y,iret[idet]));
threadpool->add_task(task); threadpool->add_task(task);
} }
@ -6210,7 +6385,7 @@ int multiSlsDetector::pulsePixelNMove(int n,int x,int y) {
for(int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++){ for(int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++){
if(detectors[idet]){ if(detectors[idet]){
iret[idet]= new int(-1); iret[idet]= new int(-1);
Task* task = new Task(new func3_t <int,int,int,int>(&slsDetector::pulsePixelNMove, Task* task = new Task(new func3_t<int,int,int,int>(&slsDetector::pulsePixelNMove,
detectors[idet],n,x,y,iret[idet])); detectors[idet],n,x,y,iret[idet]));
threadpool->add_task(task); threadpool->add_task(task);
} }
@ -6247,7 +6422,7 @@ int multiSlsDetector::pulseChip(int n) {
for(int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++){ for(int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++){
if(detectors[idet]){ if(detectors[idet]){
iret[idet]= new int(-1); iret[idet]= new int(-1);
Task* task = new Task(new func1_t <int,int>(&slsDetector::pulseChip, Task* task = new Task(new func1_t<int,int>(&slsDetector::pulseChip,
detectors[idet],n,iret[idet])); detectors[idet],n,iret[idet]));
threadpool->add_task(task); threadpool->add_task(task);
} }

View File

@ -204,6 +204,9 @@ class multiSlsDetector : public slsDetectorUtils {
/** external gui */ /** external gui */
bool externalgui; bool externalgui;
/** receiver online flag - is set if the receiver is connected, unset if socket connection is not possible */
int receiverOnlineFlag;
} sharedMultiSlsDetector; } sharedMultiSlsDetector;
@ -1233,6 +1236,11 @@ class multiSlsDetector : public slsDetectorUtils {
*/ */
int getFramesCaughtByReceiver(); int getFramesCaughtByReceiver();
/** gets the number of frames caught by any one receiver (to avoid using threadpool)
\returns number of frames caught by any one receiver (master receiver if exists)
*/
int getFramesCaughtByAnyReceiver();
/** gets the current frame index of receiver /** gets the current frame index of receiver
\returns current frame index of receiver \returns current frame index of receiver
*/ */

View File

@ -6111,7 +6111,8 @@ string slsDetector::setReceiver(string receiverIP){
else else
printf("Disabling Data Streaming\n"); printf("Disabling Data Streaming\n");
// push client state to receiver // push client state to receiver
parentDet->enableDataStreamingFromReceiver(clientSockets); /*parentDet->enableDataStreamingFromReceiver(clientSockets);*/
enableDataStreamingFromReceiver(clientSockets);
pthread_mutex_unlock(&ms); pthread_mutex_unlock(&ms);
} }
} }
@ -7587,19 +7588,23 @@ slsDetectorDefs::synchronizationMode slsDetector::setSynchronization(synchroniza
/*receiver*/ /*receiver*/
int slsDetector::setReceiverOnline(int off) { int slsDetector::setReceiverOnline(int off) {
// int prev = thisDetector->receiverOnlineFlag;
if (off!=GET_ONLINE_FLAG) { if (off!=GET_ONLINE_FLAG) {
if(strcmp(thisDetector->receiver_hostname,"none")){ // setting flag to offline
if (off == OFFLINE_FLAG)
thisDetector->receiverOnlineFlag = off;
// set flag to online only if hostname not none
else if(strcmp(thisDetector->receiver_hostname,"none")){
thisDetector->receiverOnlineFlag=off; thisDetector->receiverOnlineFlag=off;
}
if (thisDetector->receiverOnlineFlag==ONLINE_FLAG){ if (thisDetector->receiverOnlineFlag==ONLINE_FLAG){
setReceiverTCPSocket(); setReceiverTCPSocket();
// error in connecting
if(thisDetector->receiverOnlineFlag==OFFLINE_FLAG){ if(thisDetector->receiverOnlineFlag==OFFLINE_FLAG){
std::cout << "cannot connect to receiver" << endl; std::cout << "cannot connect to receiver" << endl;
setErrorMask((getErrorMask())|(CANNOT_CONNECT_TO_RECEIVER)); setErrorMask((getErrorMask())|(CANNOT_CONNECT_TO_RECEIVER));
} }
} }
} }
}
return thisDetector->receiverOnlineFlag; return thisDetector->receiverOnlineFlag;
} }

View File

@ -1636,6 +1636,11 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
*/ */
int getFramesCaughtByReceiver(); int getFramesCaughtByReceiver();
/** gets the number of frames caught by any one receiver (to avoid using threadpool)
\returns number of frames caught by any one receiver (master receiver if exists)
*/
int getFramesCaughtByAnyReceiver() {getFramesCaughtByReceiver();};
/** gets the current frame index of receiver /** gets the current frame index of receiver
\returns current frame index of receiver \returns current frame index of receiver
*/ */

View File

@ -490,6 +490,11 @@ class slsDetectorBase : public virtual slsDetectorDefs, public virtual errorDef
*/ */
virtual int getFramesCaughtByReceiver()=0; virtual int getFramesCaughtByReceiver()=0;
/** gets the number of frames caught by any one receiver (to avoid using threadpool)
\returns number of frames caught by any one receiver (master receiver if exists)
*/
virtual int getFramesCaughtByAnyReceiver()=0;
/** /**
\returns current frame index of receiver \returns current frame index of receiver
*/ */

View File

@ -2295,10 +2295,9 @@ string slsDetectorCommand::cmdAcquire(int narg, char *args[], int action) {
myDet->setOnline(ONLINE_FLAG); myDet->setOnline(ONLINE_FLAG);
int r_online = myDet->setReceiverOnline(ONLINE_FLAG);
if (myDet->getExternalGuiFlag()) if ((!myDet->getExternalGuiFlag()) && (r_online == ONLINE_FLAG)) {
myDet->setReceiverOnline(ONLINE_FLAG);
else if (myDet->setReceiverOnline(ONLINE_FLAG) == ONLINE_FLAG) {
// command line: must be off, if receiver on or there was -1, then // command line: must be off, if receiver on or there was -1, then
if (myDet->enableDataStreamingFromReceiver(-1) != 0){ if (myDet->enableDataStreamingFromReceiver(-1) != 0){
//switch it off, if error //switch it off, if error
@ -2310,7 +2309,7 @@ string slsDetectorCommand::cmdAcquire(int narg, char *args[], int action) {
if(myDet->acquire() == FAIL) if(myDet->acquire() == FAIL)
return string("acquire unsuccessful"); return string("acquire unsuccessful");
if(myDet->setReceiverOnline()==ONLINE_FLAG){ if(r_online){
char answer[100]; char answer[100];
sprintf(answer,"\nAcquired %d",myDet->getFramesCaughtByReceiver()); sprintf(answer,"\nAcquired %d",myDet->getFramesCaughtByReceiver());
return string(answer); return string(answer);

View File

@ -50,8 +50,10 @@ int slsDetectorUtils::acquire(int delflag){
return FAIL; return FAIL;
} }
#ifdef VERBOSE
struct timespec begin,end; struct timespec begin,end;
clock_gettime(CLOCK_REALTIME, &begin); clock_gettime(CLOCK_REALTIME, &begin);
#endif
//not in the loop for real time acqusition yet, //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
@ -140,8 +142,7 @@ int slsDetectorUtils::acquire(int delflag){
if(receiver){ if(receiver){
pthread_mutex_lock(&mg); //cout << "lock"<< endl; pthread_mutex_lock(&mg); //cout << "lock"<< endl;
if(getReceiverStatus()!=IDLE) if(getReceiverStatus()!=IDLE)
stopReceiver(); if(stopReceiver() == FAIL)
if(setReceiverOnline()==OFFLINE_FLAG)
*stoppedFlag=1; *stoppedFlag=1;
pthread_mutex_unlock(&mg);//cout << "unlock"<< endl; pthread_mutex_unlock(&mg);//cout << "unlock"<< endl;
} }
@ -156,7 +157,8 @@ 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); //cout << "lock"<< endl;
resetFramesCaught(); if (resetFramesCaught() == FAIL)
*stoppedFlag=1;
pthread_mutex_unlock(&mg);//cout << "unlock"<< endl; pthread_mutex_unlock(&mg);//cout << "unlock"<< endl;
} }
@ -332,10 +334,13 @@ int slsDetectorUtils::acquire(int delflag){
while (dataQueueSize()) usleep(100000); while (dataQueueSize()) usleep(100000);
// cout << "mglock " << endl;; // cout << "mglock " << endl;;
pthread_mutex_lock(&mg); //cout << "lock"<< endl; pthread_mutex_lock(&mg); //cout << "lock"<< endl;
// cout << "done " << endl;; // cout << "done " << endl;;
//offline //offline
if(setReceiverOnline()==OFFLINE_FLAG){ if(!receiver){
if ((getDetectorsType()==GOTTHARD) || (getDetectorsType()==MOENCH) || (getDetectorsType()==JUNGFRAU)|| (getDetectorsType()==JUNGFRAUCTB) ){ if ((getDetectorsType()==GOTTHARD) || (getDetectorsType()==MOENCH) || (getDetectorsType()==JUNGFRAU)|| (getDetectorsType()==JUNGFRAUCTB) ){
if((*correctionMask)&(1<<WRITE_FILE)) if((*correctionMask)&(1<<WRITE_FILE))
closeDataFile(); closeDataFile();
@ -343,14 +348,8 @@ int slsDetectorUtils::acquire(int delflag){
} }
//online //online
else{ else{
if (stopReceiver() == FAIL)
if(setReceiverOnline(ONLINE_FLAG)!=ONLINE_FLAG){ *stoppedFlag = 1;
stopAcquisition();
stopReceiver();
pthread_mutex_unlock(&mg);
break;
}
stopReceiver();
// cout<<"***********receiver stopped"<<endl; // cout<<"***********receiver stopped"<<endl;
} }
pthread_mutex_unlock(&mg);//cout << "unlock"<< endl; pthread_mutex_unlock(&mg);//cout << "unlock"<< endl;
@ -507,8 +506,8 @@ int slsDetectorUtils::acquire(int delflag){
setAcquiringFlag(false); setAcquiringFlag(false);
sem_destroy(&sem_newRTAcquisition); sem_destroy(&sem_newRTAcquisition);
clock_gettime(CLOCK_REALTIME, &end);
#ifdef VERBOSE #ifdef VERBOSE
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
return OK; return OK;

View File

@ -669,6 +669,11 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing {
*/ */
virtual int getFramesCaughtByReceiver()=0; virtual int getFramesCaughtByReceiver()=0;
/** gets the number of frames caught by any one receiver (to avoid using threadpool)
\returns number of frames caught by any one receiver (master receiver if exists)
*/
virtual int getFramesCaughtByAnyReceiver()=0;
/** /**
\returns current frame index of receiver \returns current frame index of receiver
*/ */

View File

@ -545,7 +545,7 @@ void* postProcessing::processData(int delflag) {
//get progress //get progress
pthread_mutex_lock(&mg); pthread_mutex_lock(&mg);
if(setReceiverOnline() == ONLINE_FLAG){ if(setReceiverOnline() == ONLINE_FLAG){
caught = getFramesCaughtByReceiver(); caught = getFramesCaughtByAnyReceiver();
} }
pthread_mutex_unlock(&mg); pthread_mutex_unlock(&mg);

View File

@ -109,7 +109,7 @@ private:
class SuperTask: public virtual slsDetectorDefs { class SuperTask: public virtual slsDetectorDefs {
public: public:
SuperTask(): SuperTask():
m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0),m12(0),m13(0),m14(0),m15(0){}; m1(0),m2(0),m3(0),m4(0),m5(0),m6(0),m7(0),m8(0),m9(0),m10(0),m11(0),m12(0),m13(0),m14(0),m15(0),m16(0){};
~SuperTask(){}; ~SuperTask(){};
protected: protected:
/** Function signature defined /** Function signature defined
@ -117,19 +117,20 @@ protected:
*/ */
func00_t <void >* m1; func00_t <void >* m1;
func0_t <int >* m2; func0_t <int >* m2;
func1_t <int, int>* m3; func0_t <runStatus >* m3;
func1_t <string, string>* m4; func1_t <int, int>* m4;
func1_t <detectorSettings, int>* m5; func1_t <string, string>* m5;
func2_t <int, int,int>* m6; func1_t <detectorSettings, int>* m6;
func2_t <int, string,int>* m7; func2_t <int, int,int>* m7;
func2_t <dacs_t, dacIndex,int>* m8; func2_t <int, string,int>* m8;
func2_t <detectorSettings, detectorSettings,int>* m9; func2_t <dacs_t, dacIndex,int>* m9;
func2_t <int64_t, timerIndex,int64_t>* m10; func2_t <detectorSettings, detectorSettings,int>* m10;
func2_t <string, networkParameter,string>* m11; func2_t <int64_t, timerIndex,int64_t>* m11;
func3_t <int, int,int,int>* m12; func2_t <string, networkParameter,string>* m12;
func4_t <int, trimMode,int,int,int>* m13; func3_t <int, int,int,int>* m13;
func4_t <int, int,int,detectorSettings,int>* m14; func4_t <int, trimMode,int,int,int>* m14;
func4_t <dacs_t, dacs_t,dacIndex,int,int>* m15; func4_t <int, int,int,detectorSettings,int>* m15;
func4_t <dacs_t, dacs_t,dacIndex,int,int>* m16;
}; };
class Task: public virtual SuperTask { class Task: public virtual SuperTask {
@ -139,19 +140,20 @@ public:
*/ */
Task(func00_t <void >* t): SuperTask(),fnum(1){m1 = t;}; Task(func00_t <void >* t): SuperTask(),fnum(1){m1 = t;};
Task(func0_t <int >* t): SuperTask(),fnum(2){m2 = t;}; Task(func0_t <int >* t): SuperTask(),fnum(2){m2 = t;};
Task(func1_t <int, int>* t): SuperTask(),fnum(3){m3 = t;}; Task(func0_t <runStatus >* t): SuperTask(),fnum(3){m3 = t;};
Task(func1_t <string, string>* t): SuperTask(),fnum(4){m4 = t;}; Task(func1_t <int, int>* t): SuperTask(),fnum(4){m4 = t;};
Task(func1_t <detectorSettings, int>* t): SuperTask(),fnum(5){m5 = t;}; Task(func1_t <string, string>* t): SuperTask(),fnum(5){m5 = t;};
Task(func2_t <int, int,int>* t): SuperTask(),fnum(6){m6 = t;}; Task(func1_t <detectorSettings, int>* t): SuperTask(),fnum(6){m6 = t;};
Task(func2_t <int, string,int>* t): SuperTask(),fnum(7){m7 = t;}; Task(func2_t <int, int,int>* t): SuperTask(),fnum(7){m7 = t;};
Task(func2_t <dacs_t, dacIndex,int>* t): SuperTask(),fnum(8){m8 = t;}; Task(func2_t <int, string,int>* t): SuperTask(),fnum(8){m8 = t;};
Task(func2_t <detectorSettings, detectorSettings,int>* t): SuperTask(),fnum(9){m9 = t;}; Task(func2_t <dacs_t, dacIndex,int>* t): SuperTask(),fnum(9){m9 = t;};
Task(func2_t <int64_t, timerIndex,int64_t>* t): SuperTask(),fnum(10){m10 = t;}; Task(func2_t <detectorSettings, detectorSettings,int>* t): SuperTask(),fnum(10){m10 = t;};
Task(func2_t <string, networkParameter,string>* t): SuperTask(),fnum(11){m11 = t;}; Task(func2_t <int64_t, timerIndex,int64_t>* t): SuperTask(),fnum(11){m11 = t;};
Task(func3_t <int, int,int,int>* t): SuperTask(),fnum(12){m12 = t;}; Task(func2_t <string, networkParameter,string>* t): SuperTask(),fnum(12){m12 = t;};
Task(func4_t <int, trimMode,int,int,int>* t): SuperTask(),fnum(13){m13 = t;}; Task(func3_t <int, int,int,int>* t): SuperTask(),fnum(13){m13 = t;};
Task(func4_t <int, int,int,detectorSettings,int>* t): SuperTask(),fnum(14){m14 = t;}; Task(func4_t <int, trimMode,int,int,int>* t): SuperTask(),fnum(14){m14 = t;};
Task(func4_t <dacs_t, dacs_t,dacIndex,int,int>* t): SuperTask(),fnum(15){m15 = t;}; Task(func4_t <int, int,int,detectorSettings,int>* t): SuperTask(),fnum(15){m15 = t;};
Task(func4_t <dacs_t, dacs_t,dacIndex,int,int>* t): SuperTask(),fnum(16){m16 = t;};
~Task(){} ~Task(){}
@ -172,6 +174,7 @@ public:
case 13: (*m13)(); break; case 13: (*m13)(); break;
case 14: (*m14)(); break; case 14: (*m14)(); break;
case 15: (*m15)(); break; case 15: (*m15)(); break;
case 16: (*m16)(); break;
default: default:
cprintf(RED, "Error: Task not defined. Abort!\n"); cprintf(RED, "Error: Task not defined. Abort!\n");
break; break;