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->receiverOnlineFlag = OFFLINE_FLAG;
thisMultiDetector->numberOfDetectors=0;
for (int id=0; id<MAXDET; id++) {
thisMultiDetector->detectorIds[id]=-1;
@ -297,18 +298,18 @@ int multiSlsDetector::createThreadPool(){
if(threadpool){
threadpool->destroy_threadpool();
}
if(thisMultiDetector->numberOfDetectors < 1){
cout << "No detectors attached to create threadpool" << endl;
return OK;
int numthreads = thisMultiDetector->numberOfDetectors;
if(numthreads < 1){
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()){
case 0:
cerr << "Failed to initialize thread pool!" << endl;
return FAIL;
case 1:
#ifdef VERBOSE
cout << "Not initializing threads, only one detector" << endl;
cout << "Not initializing threads, not multi detector" << endl;
#endif
break;
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
cout << endl << "Updating Multi-Detector Offsets" << endl;
#endif
@ -1067,20 +1068,45 @@ slsDetectorDefs::synchronizationMode multiSlsDetector::setSynchronization(synchr
int multiSlsDetector::setOnline(int off) {
// int retdet;
if (off!=GET_ONLINE_FLAG) {
thisMultiDetector->onlineFlag=off;
for (int i=0; i<thisMultiDetector->numberOfDetectors; i++) {
if (detectors[i]){
detectors[i]->setOnline(off);
if(detectors[i]->getErrorMask())
setErrorMask(getErrorMask()|(1<<i));
}
}
int ret=-100;
if(!threadpool){
cout << "Error in creating threadpool. Exiting" << endl;
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;
};
@ -3165,7 +3191,7 @@ dacs_t multiSlsDetector::setDAC(dacs_t val, dacIndex idac, int mV, int imod) {
for(int idet=posmin; idet<posmax; ++idet){
if(detectors[idet]){
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]));
threadpool->add_task(task);
}
@ -3227,7 +3253,7 @@ dacs_t multiSlsDetector::getADC(dacIndex idac, int imod) {
for(int idet=posmin; idet<posmax; ++idet){
if(detectors[idet]){
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]));
threadpool->add_task(task);
}
@ -3625,7 +3651,7 @@ string multiSlsDetector::setNetworkParameter(networkParameter p, string s){
if (p == RECEIVER_STREAMING_PORT)
s.append("multi\0");
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]));
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++){
if(detectors[idet]){
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]));
threadpool->add_task(task);
}
@ -4384,7 +4410,7 @@ int multiSlsDetector::loadSettingsFile(string fname, int imod) {
for(int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++){
if(detectors[idet]){
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]));
threadpool->add_task(task);
}
@ -4458,7 +4484,7 @@ int multiSlsDetector::setAllTrimbits(int val, int imod){
for(int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++){
if(detectors[idet]){
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]));
threadpool->add_task(task);
}
@ -4512,7 +4538,7 @@ int multiSlsDetector::loadCalibrationFile(string fname, int imod) {
for(int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++){
if(detectors[idet]){
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]));
threadpool->add_task(task);
}
@ -5061,18 +5087,42 @@ int multiSlsDetector::readDataFile(string fname, int *data) {
int multiSlsDetector::setReceiverOnline(int off) {
int ret=-100,ret1;
for (int i=0; i<thisMultiDetector->numberOfDetectors; i++)
if (detectors[i]){
ret1=detectors[i]->setReceiverOnline(off);
if(detectors[i]->getErrorMask())
setErrorMask(getErrorMask()|(1<<i));
if(ret==-100)
ret=ret1;
else if (ret!=ret1)
ret=-1;
if (off != GET_ONLINE_FLAG) {
int ret=-100;
if(!threadpool){
cout << "Error in creating threadpool. Exiting" << endl;
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::setReceiverOnline,
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));
}
}
}
return ret;
thisMultiDetector->receiverOnlineFlag=ret;
}
return thisMultiDetector->receiverOnlineFlag;
}
@ -5120,21 +5170,41 @@ string multiSlsDetector::setFilePath(string s) {
string multiSlsDetector::setFileName(string s) {
string ret="error", ret1;
for (int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++) {
if (detectors[idet]) {
ret1=detectors[idet]->setFileName(s);
if(detectors[idet]->getErrorMask())
setErrorMask(getErrorMask()|(1<<idet));
if (ret=="error")
ret=ret1;
else if (ret!=ret1)
ret="";
}
}
return ret;
string ret = "error";
int posmax = thisMultiDetector->numberOfDetectors;
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())
setErrorMask(getErrorMask()|(1<<idet));
}
}
}
return ret;
}
@ -5328,52 +5398,120 @@ slsDetectorDefs::runStatus multiSlsDetector::startReceiverReadout(){
}
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 (detectors[i]) {
ret=detectors[i]->getReceiverStatus();
if(detectors[i]->getErrorMask())
setErrorMask(getErrorMask()|(1<<i));
return ret;
}
}
if (thisMultiDetector->masterPosition>=0)
if (detectors[thisMultiDetector->masterPosition]){
s = detectors[thisMultiDetector->masterPosition]->getReceiverStatus();
if(detectors[thisMultiDetector->masterPosition]->getErrorMask())
setErrorMask(getErrorMask()|(1<<thisMultiDetector->masterPosition));
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));
}
}
}
// if (detectors[0]) s=detectors[0]->getReceiverStatus();
for (int i=0; i<thisMultiDetector->numberOfDetectors; i++) {
s1=detectors[i]->getReceiverStatus();
if(detectors[i]->getErrorMask())
setErrorMask(getErrorMask()|(1<<i));
if (s1==ERROR)
s=ERROR;
//if (s1==IDLE && s!=IDLE)
// s=ERROR;
if (s1!=IDLE)
s = s1;
}
return s;
return ret;
}
int multiSlsDetector::getFramesCaughtByAnyReceiver() {
int ret = 0;
int i = thisMultiDetector->masterPosition;
int multiSlsDetector::getFramesCaughtByReceiver() {
int ret=0,ret1=0;
if (i >=0 ) {
if (detectors[i]){
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++)
if (detectors[i]){
ret1+=detectors[i]->getFramesCaughtByReceiver();
ret=detectors[i]->getFramesCaughtByReceiver();
if(detectors[i]->getErrorMask())
setErrorMask(getErrorMask()|(1<<i));
// return the first one that works
return ret;
}
if(!thisMultiDetector->numberOfDetectors)
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;
}
@ -5397,17 +5535,36 @@ int multiSlsDetector::getReceiverCurrentFrameIndex() {
int multiSlsDetector::resetFramesCaught() {
int ret=-100, ret1;
for (int i=0; i<thisMultiDetector->numberOfDetectors; i++){
if (detectors[i]){
ret1=detectors[i]->resetFramesCaught();
if(detectors[i]->getErrorMask())
setErrorMask(getErrorMask()|(1<<i));
if (ret==-100)
ret=ret1;
else if (ret!=ret1)
ret=-1;
int ret=OK;
int posmax = thisMultiDetector->numberOfDetectors;
if(!threadpool){
cout << "Error in creating threadpool. Exiting" << endl;
return FAIL;
}else{
int* iret[posmax];
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 ret=-100, ret1;
int ret=-100;
int posmax = thisMultiDetector->numberOfDetectors;
fileIO::setFrameIndex(index);
for (int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++) {
if (detectors[idet]) {
ret1=detectors[idet]->setFrameIndex(index);
if(detectors[idet]->getErrorMask())
setErrorMask(getErrorMask()|(1<<idet));
if (ret==-100)
ret=ret1;
else if (ret!=ret1)
ret=-1;
if(!threadpool){
cout << "Error in creating threadpool. Exiting" << endl;
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())
setErrorMask(getErrorMask()|(1<<idet));
}
}
}
return ret;
}
@ -5910,7 +6085,7 @@ int multiSlsDetector::getStreamingSocketsCreatedInClient() {
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
if (!thisMultiDetector->externalgui) {
@ -5944,7 +6119,7 @@ int multiSlsDetector::enableDataStreamingFromReceiver(int enable){
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::enableDataStreamingFromReceiver,
Task* task = new Task(new func1_t<int,int>(&slsDetector::enableDataStreamingFromReceiver,
detectors[idet],enable,iret[idet]));
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++){
if(detectors[idet]){
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]));
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++){
if(detectors[idet]){
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]));
threadpool->add_task(task);
}
@ -6247,7 +6422,7 @@ int multiSlsDetector::pulseChip(int n) {
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::pulseChip,
Task* task = new Task(new func1_t<int,int>(&slsDetector::pulseChip,
detectors[idet],n,iret[idet]));
threadpool->add_task(task);
}

View File

@ -204,6 +204,9 @@ class multiSlsDetector : public slsDetectorUtils {
/** external gui */
bool externalgui;
/** receiver online flag - is set if the receiver is connected, unset if socket connection is not possible */
int receiverOnlineFlag;
} sharedMultiSlsDetector;
@ -1233,6 +1236,11 @@ class multiSlsDetector : public slsDetectorUtils {
*/
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
\returns current frame index of receiver
*/

View File

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

View File

@ -1636,6 +1636,11 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
*/
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
\returns current frame index of receiver
*/

View File

@ -490,6 +490,11 @@ class slsDetectorBase : public virtual slsDetectorDefs, public virtual errorDef
*/
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
*/

View File

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

View File

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

View File

@ -669,6 +669,11 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing {
*/
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
*/

View File

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

View File

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