mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-23 10:07:59 +02:00
gotthard receiver works so far without cpu file write and tcp generic socket lock
git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@337 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
@ -442,7 +442,7 @@ slsDetectorDefs::detectorType slsDetector::getDetectorType(int id) {
|
||||
int slsDetector::initializeDetectorSize(detectorType type) {
|
||||
char *goff;
|
||||
goff=(char*)thisDetector;
|
||||
|
||||
|
||||
// cout << "init detector size" << endl;
|
||||
|
||||
/** if the shared memory has newly be created, initialize the detector variables */
|
||||
@ -674,6 +674,9 @@ int slsDetector::initializeDetectorSize(detectorType type) {
|
||||
filePath=thisDetector->filePath;
|
||||
fileName=parentDet->fileName;
|
||||
fileIndex=parentDet->fileIndex;
|
||||
framesPerFile=parentDet->framesPerFile;
|
||||
if(thisDetector->myDetectorType==GOTTHARD)
|
||||
setFramesPerFile(20000);
|
||||
|
||||
thisReceiver = new receiverInterface(dataSocket);
|
||||
|
||||
@ -3946,7 +3949,7 @@ int slsDetector::executeTrimming(trimMode mode, int par1, int par2, int imod){
|
||||
};
|
||||
|
||||
double* slsDetector::decodeData(int *datain, double *fdata) {
|
||||
|
||||
|
||||
double *dataout;
|
||||
if (fdata)
|
||||
dataout=fdata;
|
||||
@ -5557,12 +5560,6 @@ int slsDetector::stopReceiver(){
|
||||
ret=updateReceiver();
|
||||
}
|
||||
|
||||
//increment file index
|
||||
if(ret==OK){
|
||||
fileIO::setFileIndex(fileIO::getFileIndex()+1);
|
||||
setFileIndex(fileIO::getFileIndex());
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -5665,6 +5662,81 @@ int slsDetector::getCurrentFrameIndex(){
|
||||
|
||||
|
||||
|
||||
|
||||
int slsDetector::resetFramesCaught(int index){
|
||||
int fnum=F_RESET_FRAMES_CAUGHT;
|
||||
int ret = FAIL;
|
||||
int retval=-1;
|
||||
int arg=index;
|
||||
|
||||
if (setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG) {
|
||||
#ifdef VERBOSE
|
||||
std::cout << "Reset Frames Caught by Receiver:" << arg << std::endl;
|
||||
#endif
|
||||
ret=thisReceiver->sendInt(fnum,retval,arg);
|
||||
if(ret==FORCE_UPDATE)
|
||||
ret=updateReceiver();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int* slsDetector::readFrameFromReceiver(){
|
||||
int fnum=F_READ_FRAME;
|
||||
int nel=(thisDetector->dataBytes+HEADERLENGTH)/sizeof(int);//2572/
|
||||
int* retval=new int[nel];
|
||||
int* origVal=new int[nel];
|
||||
int ret=FAIL;
|
||||
int n;
|
||||
char mess[100]="Nothing";
|
||||
|
||||
|
||||
if (setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG) {
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "slsDetector: Reading frame from receiver "<< thisDetector->dataBytes+HEADERLENGTH << " " <<nel <<std::endl;
|
||||
#endif
|
||||
if (dataSocket) {
|
||||
if (dataSocket->Connect()>=0) {
|
||||
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 [] origVal;
|
||||
delete [] retval;
|
||||
return NULL;
|
||||
} else {
|
||||
n=dataSocket->ReceiveDataOnly(origVal,thisDetector->dataBytes+HEADERLENGTH);
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "Received "<< n << " data bytes" << std::endl;
|
||||
#endif
|
||||
if (n!=thisDetector->dataBytes+HEADERLENGTH) {
|
||||
std::cout<<endl<< "wrong data size received: received " << n << " but expected " << thisDetector->dataBytes+HEADERLENGTH << std::endl;
|
||||
ret=FAIL;
|
||||
delete [] origVal;
|
||||
delete [] retval;
|
||||
return NULL;
|
||||
}//worked
|
||||
else{
|
||||
memcpy(retval,((char*) origVal)+2, getDataBytes()/2);
|
||||
memcpy((((char*)retval)+getDataBytes()/2), ((char*) origVal)+8+getDataBytes()/2, getDataBytes()/2);
|
||||
}
|
||||
}
|
||||
dataSocket->Disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
delete [] origVal;
|
||||
return retval;//(retval+HEADERLENGTH/sizeof(int));
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
int slsDetector::lockReceiver(int lock){
|
||||
int fnum=F_LOCK_RECEIVER;
|
||||
int ret = FAIL;
|
||||
|
@ -1459,6 +1459,18 @@ class slsDetector : public slsDetectorUtils, public energyConversion {
|
||||
*/
|
||||
int getCurrentFrameIndex();
|
||||
|
||||
/**
|
||||
* resets framescaught
|
||||
* @param index frames caught by receiver
|
||||
* @param index if frame index is needed
|
||||
*/
|
||||
int resetFramesCaught(int index=-1);
|
||||
|
||||
/**
|
||||
/returns a frame read from recever
|
||||
*/
|
||||
int* readFrameFromReceiver();
|
||||
|
||||
/** Locks/Unlocks the connection to the receiver
|
||||
/param lock sets (1), usets (0), gets (-1) the lock
|
||||
/returns lock status of the receiver
|
||||
|
@ -462,6 +462,11 @@ class slsDetectorBase : public virtual slsDetectorDefs {
|
||||
virtual int lockReceiver(int lock=-1)=0;
|
||||
|
||||
|
||||
/**
|
||||
/returns a frame read from recever
|
||||
*/
|
||||
virtual int* readFrameFromReceiver()=0;
|
||||
|
||||
/** returns detector type string from detector type index
|
||||
\param t string can be Mythen, Pilatus, Eiger, Gotthard, Agipd, Unknown
|
||||
\returns MYTHEN, PILATUS, EIGER, GOTTHARD, AGIPD, GENERIC
|
||||
|
@ -778,19 +778,8 @@ string slsDetectorCommand::cmdAcquire(int narg, char *args[], int action) {
|
||||
|
||||
|
||||
myDet->setOnline(ONLINE_FLAG);
|
||||
bool receiver=(myDet->setReceiverOnline()==ONLINE_FLAG);
|
||||
|
||||
if(receiver)
|
||||
if(myDet->startReceiver()==OK)
|
||||
usleep(2000000);
|
||||
else return string("could not start receiver");
|
||||
|
||||
myDet->acquire();
|
||||
|
||||
if(receiver)
|
||||
myDet->stopReceiver();
|
||||
|
||||
|
||||
return string("");
|
||||
|
||||
}
|
||||
|
@ -41,6 +41,8 @@ slsDetectorUtils::slsDetectorUtils() {
|
||||
|
||||
void slsDetectorUtils::acquire(int delflag){
|
||||
|
||||
bool receiver = (setReceiverOnline()==ONLINE_FLAG);
|
||||
|
||||
// setTotalProgress();
|
||||
//moved these 2 here for measurement change
|
||||
progressIndex=0;
|
||||
@ -109,6 +111,25 @@ void slsDetectorUtils::acquire(int delflag){
|
||||
ns1=1;
|
||||
}
|
||||
|
||||
if(receiver){
|
||||
if(getReceiverStatus()!=IDLE)
|
||||
stopReceiver();
|
||||
if(setReceiverOnline()==OFFLINE_FLAG)
|
||||
*stoppedFlag=1;
|
||||
|
||||
|
||||
//resets frames caught in receiver
|
||||
if ((timerValue[FRAME_NUMBER]*timerValue[CYCLES_NUMBER])>1)
|
||||
resetFramesCaught(1);
|
||||
else
|
||||
resetFramesCaught(0);
|
||||
|
||||
if(setReceiverOnline()==OFFLINE_FLAG)
|
||||
*stoppedFlag=1;
|
||||
else
|
||||
setReceiverAcquiring(1);
|
||||
}
|
||||
|
||||
|
||||
if (*threadedProcessing) {
|
||||
startThread(delflag);
|
||||
@ -178,7 +199,7 @@ void slsDetectorUtils::acquire(int delflag){
|
||||
|
||||
|
||||
pthread_mutex_lock(&mp);
|
||||
createFileName();
|
||||
createFileName();
|
||||
pthread_mutex_unlock(&mp);
|
||||
|
||||
if (*stoppedFlag==0) {
|
||||
@ -192,9 +213,6 @@ void slsDetectorUtils::acquire(int delflag){
|
||||
if (*stoppedFlag==0) {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
executeAction(headerBefore);
|
||||
|
||||
if (*correctionMask&(1<< ANGULAR_CONVERSION) || aclog || eclog) {
|
||||
@ -202,27 +220,43 @@ void slsDetectorUtils::acquire(int delflag){
|
||||
setCurrentPosition(getDetectorPosition());
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (aclog)
|
||||
aclog->addStep(getCurrentPosition(), getCurrentFileName());
|
||||
|
||||
|
||||
aclog->addStep(getCurrentPosition(), getCurrentFileName());
|
||||
|
||||
if (eclog)
|
||||
eclog->addStep(setDAC(-1,THRESHOLD), getCurrentFileName());
|
||||
|
||||
eclog->addStep(setDAC(-1,THRESHOLD), getCurrentFileName());
|
||||
|
||||
|
||||
if (*correctionMask&(1<< I0_NORMALIZATION)) {
|
||||
if (get_i0)
|
||||
get_i0(0, IOarg);
|
||||
}
|
||||
|
||||
|
||||
if ((timerValue[FRAME_NUMBER]*timerValue[CYCLES_NUMBER])>1) {
|
||||
setFrameIndex(0);
|
||||
} else {
|
||||
setFrameIndex(-1);
|
||||
}
|
||||
|
||||
if(receiver){
|
||||
//send receiver file name
|
||||
pthread_mutex_lock(&mp);
|
||||
createFileName();
|
||||
pthread_mutex_unlock(&mp);
|
||||
setFileName(fileIO::getFileName());
|
||||
if(setReceiverOnline()==OFFLINE_FLAG){
|
||||
stopReceiver();
|
||||
break;
|
||||
}
|
||||
//start receiver
|
||||
startReceiver();
|
||||
if(setReceiverOnline()==OFFLINE_FLAG){
|
||||
stopReceiver();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
startAndReadAll();
|
||||
#ifdef VERBOSE
|
||||
cout << "returned! " << endl;
|
||||
@ -244,18 +278,19 @@ void slsDetectorUtils::acquire(int delflag){
|
||||
cout << "done! " << endl;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
if (*threadedProcessing==0){
|
||||
#ifdef VERBOSE
|
||||
cout << "start unthreaded process data " << endl;
|
||||
#endif
|
||||
|
||||
processData(delflag);
|
||||
}
|
||||
|
||||
} else
|
||||
break;
|
||||
|
||||
|
||||
if(setReceiverOnline()==OFFLINE_FLAG){
|
||||
// wait until data processing thread has finished the data
|
||||
|
||||
#ifdef VERBOSE
|
||||
@ -268,19 +303,27 @@ void slsDetectorUtils::acquire(int delflag){
|
||||
usleep(100000);
|
||||
}
|
||||
|
||||
closeDataFile();
|
||||
if((*correctionMask)&(1<<WRITE_FILE))
|
||||
closeDataFile();
|
||||
|
||||
}else{
|
||||
while(stopReceiver()!=OK);
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&mp);
|
||||
if (*stoppedFlag==0) {
|
||||
executeAction(headerAfter);
|
||||
executeAction(headerAfter);
|
||||
|
||||
pthread_mutex_unlock(&mp);
|
||||
// setLastIndex(*fileIndex);
|
||||
} else {
|
||||
// setLastIndex(*fileIndex);
|
||||
|
||||
pthread_mutex_unlock(&mp);
|
||||
break;
|
||||
}
|
||||
pthread_mutex_unlock(&mp);
|
||||
|
||||
|
||||
|
||||
if (*stoppedFlag) {
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "exiting since the detector has been stopped" << std::endl;
|
||||
@ -292,7 +335,7 @@ void slsDetectorUtils::acquire(int delflag){
|
||||
// pthread_mutex_unlock(&mp);
|
||||
}
|
||||
} // loop on position finished
|
||||
|
||||
|
||||
//script after
|
||||
if (*stoppedFlag==0) {
|
||||
executeAction(scriptAfter);
|
||||
@ -311,7 +354,7 @@ void slsDetectorUtils::acquire(int delflag){
|
||||
// pthread_mutex_unlock(&mp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//end scan1 loop is1
|
||||
|
||||
|
||||
@ -345,27 +388,29 @@ void slsDetectorUtils::acquire(int delflag){
|
||||
#endif
|
||||
if(*correctionMask&(1<<WRITE_FILE))
|
||||
IncrementFileIndex();
|
||||
|
||||
setFileIndex(fileIO::getFileIndex());
|
||||
|
||||
|
||||
|
||||
if (measurement_finished)
|
||||
measurement_finished(im,*fileIndex,measFinished_p);
|
||||
|
||||
|
||||
if (*stoppedFlag) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// loop measurements
|
||||
}
|
||||
|
||||
setReceiverAcquiring(0);
|
||||
|
||||
// waiting for the data processing thread to finish!
|
||||
if (*threadedProcessing) {
|
||||
if (*threadedProcessing) {
|
||||
setJoinThread(1);
|
||||
pthread_join(dataProcessingThread, &status);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (connectChannels) {
|
||||
if (disconnect_channels)
|
||||
@ -378,7 +423,6 @@ void slsDetectorUtils::acquire(int delflag){
|
||||
if (eclog)
|
||||
delete eclog;
|
||||
|
||||
|
||||
if (acquisition_finished)
|
||||
acquisition_finished(getCurrentProgress(),getDetectorStatus(),acqFinished_p);
|
||||
|
||||
@ -542,87 +586,6 @@ void slsDetectorUtils::incrementProgress(int i) {
|
||||
|
||||
|
||||
int slsDetectorUtils::testFunction(int times) {
|
||||
int i,count=0;
|
||||
runStatus s;
|
||||
char controlval[1000];
|
||||
char statusval[1000];
|
||||
|
||||
int nchans = getTotalNumberOfChannels();
|
||||
short int dataVals[nchans];
|
||||
|
||||
for(i=0;i<times;i++){
|
||||
sprintf(statusval,"%x",readRegister(0x25));
|
||||
std::cout<<std::endl<<dec<<i+1<<": stat:\t"<<statusval<<"\t";
|
||||
sprintf(controlval,"%x",readRegister(0x24));
|
||||
std::cout<<"cont:"<<controlval<<"\t"<<std::endl;
|
||||
|
||||
startAcquisition();
|
||||
|
||||
sprintf(controlval,"%x",readRegister(0x24));
|
||||
std::cout<<"cont:"<<controlval<<"\t"<<std::endl;
|
||||
//sprintf(statusval,"%x",readRegister(0x25));
|
||||
//std::cout<<statusval<<std::endl;
|
||||
s = getRunStatus();
|
||||
if(s==IDLE){
|
||||
std::cout<<"IDLE\t"<<std::endl;
|
||||
s = getRunStatus();
|
||||
if(s==IDLE){
|
||||
std::cout<<"IDLE"<<std::endl;
|
||||
exit(-1);
|
||||
}
|
||||
;
|
||||
}
|
||||
else {
|
||||
if (s==RUNNING){
|
||||
count=0;
|
||||
while(s==RUNNING){
|
||||
count++;//std::cout<<"count:"<<count<<std::endl;
|
||||
if(count==4){
|
||||
sprintf(statusval,"%x",readRegister(0x25));
|
||||
|
||||
|
||||
std::cout<<"STUCK: stat"<<statusval<<std::endl;
|
||||
exit(-1);
|
||||
}
|
||||
usleep(50000);
|
||||
//val=readRegister(0x25);
|
||||
s = getRunStatus();
|
||||
}
|
||||
}
|
||||
}
|
||||
/* else{
|
||||
std::cout<<"\nWeird Status. "<<runStatusType(s)<<" Exit\n";
|
||||
exit(-1);
|
||||
}*/
|
||||
system("rm ~/wORKSPACE/scratch/run* ");
|
||||
//system("more ~/wORKSPACE/scratch/run* ");
|
||||
usleep(1000000);
|
||||
|
||||
setFileIndex(0);
|
||||
int b;
|
||||
|
||||
b=setThreadedProcessing(-1);
|
||||
setThreadedProcessing(0);
|
||||
readAll();
|
||||
processData(1);
|
||||
setThreadedProcessing(b);
|
||||
|
||||
|
||||
if(!readDataFile("/home/l_maliakal_d/wORKSPACE/scratch/run_1.raw",dataVals)){
|
||||
std::cout<< "Could not open file "<< std::endl;
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
std::cout<<std::endl;
|
||||
for(int j=1277;j< (nchans);j++)
|
||||
std::cout<<"\t"<<j<<":"<<dataVals[j];
|
||||
|
||||
if(dataVals[1278]!=2558){
|
||||
std::cout<< "DATA ERROR!! "<< std::endl;
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
std::cout<<std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -621,6 +621,19 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing {
|
||||
*/
|
||||
virtual int getCurrentFrameIndex()=0;
|
||||
|
||||
/**
|
||||
* resets framescaught
|
||||
* @param index frames caught by receiver
|
||||
* @param index if frame index is needed
|
||||
*/
|
||||
virtual int resetFramesCaught(int index=-1)=0;
|
||||
|
||||
/**
|
||||
/returns a frame read from recever
|
||||
*/
|
||||
virtual int* readFrameFromReceiver()=0;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
static const int64_t thisSoftwareVersion=0x20120124;
|
||||
|
Reference in New Issue
Block a user