compiles after merging

This commit is contained in:
bergamaschi 2016-12-19 13:50:25 +01:00
parent 68b13a0ecd
commit 3eea80a121
4 changed files with 86 additions and 240 deletions

View File

@ -5319,7 +5319,7 @@ void multiSlsDetector::readFrameFromReceiver(){
return;
}
int* multiframe=new int[nel]();
int nch;
volatile uint64_t dataThreadMask = 0x0;
@ -5395,7 +5395,7 @@ void multiSlsDetector::readFrameFromReceiver(){
//send data to callback
if(running){
fdata = decodeData(multiframe);
fdata = decodeData(multiframe,nch);
if ((fdata) && (dataReady)){
thisData = new detectorData(fdata,NULL,NULL,getCurrentProgress(),currentFileName.c_str(),nx,ny);
dataReady(thisData, currentFrameIndex, currentSubFrameIndex, pCallbackArg);

View File

@ -7663,54 +7663,54 @@ int slsDetector::resetFramesCaught(){
}
int* slsDetector::readFrameFromReceiver(char* fName, int &acquisitionIndex, int &frameIndex, int &subFrameIndex){
int fnum=F_READ_RECEIVER_FRAME;
int nel=thisDetector->dataBytes/sizeof(int);
int* retval=new int[nel];
int ret=FAIL;
int n;
char mess[MAX_STR_LENGTH]="Nothing";
if (setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG) {
#ifdef VERBOSE
std::cout<< "slsDetector: Reading frame from receiver "<< thisDetector->dataBytes << " " <<nel <<std::endl;
#endif
if (connectData() == OK){
dataSocket->SendDataOnly(&fnum,sizeof(fnum));
dataSocket->ReceiveDataOnly(&ret,sizeof(ret));
if (ret==FAIL) {
n= dataSocket->ReceiveDataOnly(mess,sizeof(mess));
std::cout<< "Detector returned: " << mess << " " << n << std::endl;
delete [] retval;
disconnectData();
return NULL;
} else {
n=dataSocket->ReceiveDataOnly(fName,MAX_STR_LENGTH);
n=dataSocket->ReceiveDataOnly(&acquisitionIndex,sizeof(acquisitionIndex));
n=dataSocket->ReceiveDataOnly(&frameIndex,sizeof(frameIndex));
if(thisDetector->myDetectorType == EIGER)
n=dataSocket->ReceiveDataOnly(&subFrameIndex,sizeof(subFrameIndex));
n=dataSocket->ReceiveDataOnly(retval,thisDetector->dataBytes);
#ifdef VERBOSE
std::cout<< "Received "<< n << " data bytes" << std::endl;
#endif
if (n!=thisDetector->dataBytes) {
std::cout<<endl<< "wrong data size received: received " << n << " but expected from receiver " << thisDetector->dataBytes << std::endl;
ret=FAIL;
delete [] retval;
disconnectData();
return NULL; }
//jungfrau masking adcval
if(thisDetector->myDetectorType == JUNGFRAU){
for(unsigned int i=0;i<nel;i++){
retval[i] = (retval[i] & 0x3FFF3FFF);
}
}
}
disconnectData();
}
}
return retval;
};
// int* slsDetector::readFrameFromReceiver(char* fName, int &acquisitionIndex, int &frameIndex, int &subFrameIndex){
// int fnum=F_READ_RECEIVER_FRAME;
// int nel=thisDetector->dataBytes/sizeof(int);
// int* retval=new int[nel];
// int ret=FAIL;
// int n;
// char mess[MAX_STR_LENGTH]="Nothing";
// if (setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG) {
// #ifdef VERBOSE
// std::cout<< "slsDetector: Reading frame from receiver "<< thisDetector->dataBytes << " " <<nel <<std::endl;
// #endif
// if (connectData() == OK){
// dataSocket->SendDataOnly(&fnum,sizeof(fnum));
// dataSocket->ReceiveDataOnly(&ret,sizeof(ret));
// if (ret==FAIL) {
// n= dataSocket->ReceiveDataOnly(mess,sizeof(mess));
// std::cout<< "Detector returned: " << mess << " " << n << std::endl;
// delete [] retval;
// disconnectData();
// return NULL;
// } else {
// n=dataSocket->ReceiveDataOnly(fName,MAX_STR_LENGTH);
// n=dataSocket->ReceiveDataOnly(&acquisitionIndex,sizeof(acquisitionIndex));
// n=dataSocket->ReceiveDataOnly(&frameIndex,sizeof(frameIndex));
// if(thisDetector->myDetectorType == EIGER)
// n=dataSocket->ReceiveDataOnly(&subFrameIndex,sizeof(subFrameIndex));
// n=dataSocket->ReceiveDataOnly(retval,thisDetector->dataBytes);
// #ifdef VERBOSE
// std::cout<< "Received "<< n << " data bytes" << std::endl;
// #endif
// if (n!=thisDetector->dataBytes) {
// std::cout<<endl<< "wrong data size received: received " << n << " but expected from receiver " << thisDetector->dataBytes << std::endl;
// ret=FAIL;
// delete [] retval;
// disconnectData();
// return NULL; }
// //jungfrau masking adcval
// if(thisDetector->myDetectorType == JUNGFRAU){
// for(unsigned int i=0;i<nel;i++){
// retval[i] = (retval[i] & 0x3FFF3FFF);
// }
// }
// }
// disconnectData();
// }
// }
// return retval;
// };

View File

@ -508,8 +508,8 @@ class slsDetectorBase : public virtual slsDetectorDefs, public virtual errorDef
/** Reads frames from receiver through a constant socket
*/
virtual int* readFrameFromReceiver(char* fName, int &acquisitionIndex, int &frameIndex, int &subFrameIndex)=0;
// virtual int* readFrameFromReceiver(char* fName, int &acquisitionIndex, int &frameIndex, int &subFrameIndex)=0;
virtual void readFrameFromReceiver()=0;
/** Sets the read receiver frequency
if data required from receiver randomly readRxrFrequency=0,

View File

@ -501,27 +501,27 @@ void* postProcessing::processData(int delflag) {
else{
pthread_mutex_unlock(&mg);
// //cprintf(RED,"In post processing threads\n");
//cprintf(RED,"In post processing threads\n");
// if(dataReady){
// readFrameFromReceiver();
// }
if(dataReady){
readFrameFromReceiver();
}
// //only update progress
// else{
// int caught = -1;
// char c;
// int ifp;
// while(true){
//only update progress
else{
int caught = -1;
char c;
int ifp;
while(true){
// //cout.flush();
// //cout<<flush;
// usleep(100 * 1000); //20ms need this else connecting error to receiver (too fast)
//cout.flush();
//cout<<flush;
usleep(100 * 1000); //20ms need this else connecting error to receiver (too fast)
// if (checkJoinThread()){
// break;
// }
if (checkJoinThread()){
break;
}
@ -536,184 +536,30 @@ void* postProcessing::processData(int delflag) {
// //get progress
// pthread_mutex_lock(&mg);
// if(setReceiverOnline() == ONLINE_FLAG){
// caught = getFramesCaughtByReceiver();
// }
// pthread_mutex_unlock(&mg);
//get progress
pthread_mutex_lock(&mg);
if(setReceiverOnline() == ONLINE_FLAG){
caught = getFramesCaughtByReceiver();
}
pthread_mutex_unlock(&mg);
// //updating progress
// if(caught!= -1){
// setCurrentProgress(caught);
// #ifdef VERY_VERY_DEBUG
// cout << "caught:" << caught << endl;
// #endif
// }
// if (checkJoinThread()){
// break;
// }
//updating progress
if(caught!= -1){
setCurrentProgress(caught);
#ifdef VERY_VERY_DEBUG
cout << "caught:" << caught << endl;
#endif
}
if (checkJoinThread()){
break;
}
// }
// }
}
}
//cout<<"exiting from proccessing thread"<<endl;
int progress = 0;
char currentfName[MAX_STR_LENGTH]="";
int caught = -1;
int currentAcquisitionIndex = -1;
int currentFrameIndex = -1;
int currentSubFrameIndex = -1;
bool newData = false;
int nthframe = setReadReceiverFrequency(0);
int nx =getTotalNumberOfChannels(slsDetectorDefs::X);
int ny =getTotalNumberOfChannels(slsDetectorDefs::Y);
int nn;
#ifdef VERBOSE
std::cout << "receiver read freq:" << nthframe << std::endl;
#endif
//repeat forever until joined by the calling thread
while(1){
cout.flush();
//cout<<flush;
usleep(20000); //20ms need this else connecting error to receiver (too fast)
//get progress
if(setReceiverOnline() == ONLINE_FLAG){
pthread_mutex_lock(&mg);
caught = getFramesCaughtByReceiver();
pthread_mutex_unlock(&mg); }
//updating progress
if(caught!= -1){
setCurrentProgress(caught);
#ifdef VERY_VERY_DEBUG
cout << "caught:" << caught << endl;
#endif
}
//detector acquistion done, wait for all frames received
if(acquiringDone > 0){
#ifdef VERY_VERY_DEBUG
if(acquiringDone == 1)
cout << "acquiring seems to be done" << endl;
#endif
//IF GUI, check for last frames (counter upto 5)
if(dataReady){
pthread_mutex_lock(&mg);
acquiringDone++;
pthread_mutex_unlock(&mg);
#ifdef VERY_VERY_DEBUG
cout << "acquiringDone :" << acquiringDone << endl;
#endif
}
//post to stopReceiver in acquire(), but continue reading frames
if (!dataReady || (acquiringDone >= 5)){
if(!dataReady || (!nthframe) ||(!newData)){
#ifdef VERY_VERY_DEBUG
cout << "gonna post for it to end" << endl;
#endif
sem_post(&sem_queue);
#ifdef VERY_VERY_DEBUG
cout << "Sem posted" << endl;
#endif
}
}
}
//random reads and for nthframe, checks if there is no new data
else if((!nthframe) ||(!newData)){
//cout <<"cecking now" << endl;
if (checkJoinThread()){
break;
}
}
//for random reads, ask only if it has new data
if(!newData){
if(caught > progress){
newData = true; // If new data and acquiringDone>0 (= det acq over), reset to get more frames
if(dataReady && (acquiringDone > 0)){
pthread_mutex_lock(&mg);
acquiringDone = 1;
#ifdef VERY_VERY_DEBUG
cout << "Keeping acquiringDone at 1 " << endl;
#endif
pthread_mutex_unlock(&mg);
}
} }
if(newData){
#ifdef VERY_VERY_DEBUG
cout << "new data" << endl;
#endif
//no gui
if (!dataReady){
progress = caught;
#ifdef VERY_VERY_DEBUG
cout << "progress:" << progress << endl;
#endif
newData = false;
#ifdef VERY_VERY_DEBUG
cout << "newData set to false" << endl;
#endif
}
//gui
else{
if(setReceiverOnline()==ONLINE_FLAG){
//get data
strcpy(currentfName,"");
pthread_mutex_lock(&mg);
//int* receiverData = new int [getTotalNumberOfChannels()];
int* receiverData = readFrameFromReceiver(currentfName,currentAcquisitionIndex,currentFrameIndex,currentSubFrameIndex);
pthread_mutex_unlock(&mg);
//if detector returned null
if(setReceiverOnline()==OFFLINE_FLAG)
receiverData = NULL;
//no data or wrong data for print out
if(receiverData == NULL){
currentAcquisitionIndex = -1;
cout<<"****Detector Data returned is NULL***"<<endl;
}
// garbage frame
if(currentAcquisitionIndex < 0){
#ifdef VERY_VERY_DEBUG
cout<<"****Detector returned mismatched indices/garbage or acquisition is over. Trying again.***"<<endl;
#endif
if(receiverData)
delete [] receiverData;
}
//not garbage frame
else{// if (currentAcquisitionIndex > progress){
#ifdef VERY_VERY_DEBUG
cout << "GOT data" << endl;
#endif
fdata = decodeData(receiverData, nn);
delete [] receiverData;
if ((fdata) && (dataReady)){
// cout << "DATAREADY 3" << endl;
thisData = new detectorData(fdata,NULL,NULL,getCurrentProgress(),currentfName,nx,ny);
dataReady(thisData, currentFrameIndex, currentSubFrameIndex, pCallbackArg);
delete thisData;
fdata = NULL;
progress = caught;
#ifdef VERY_VERY_DEBUG
cout << "progress:" << progress << endl;
#endif
newData = false;
#ifdef VERY_VERY_DEBUG
cout << "newData set to false" << endl;
#endif
}
}
}
}
}
}
//cprintf(RED,"Exiting post processing thread\n");
}