mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-12 04:47:14 +02:00
few bugs fixed
git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@286 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
@ -248,11 +248,18 @@ void slsDetectorUtils::acquire(int delflag){
|
||||
|
||||
// wait until data processing thread has finished the data
|
||||
|
||||
#ifdef VERBOSE
|
||||
cout << "check data queue size " << endl;
|
||||
#endif
|
||||
while (dataQueueSize()){
|
||||
#ifdef VERBOSE
|
||||
cout << "AAAAAAAAA check data queue size " << endl;
|
||||
#endif
|
||||
usleep(100000);
|
||||
}
|
||||
pthread_mutex_lock(&mp);
|
||||
|
||||
|
||||
pthread_mutex_lock(&mp);
|
||||
if (*stoppedFlag==0) {
|
||||
executeAction(headerAfter);
|
||||
setLastIndex(*fileIndex);
|
||||
@ -489,8 +496,10 @@ double slsDetectorUtils::getCurrentProgress() {
|
||||
#ifdef VERBOSE
|
||||
cout << progressIndex << " / " << totalProgress << endl;
|
||||
#endif
|
||||
return 100.*((double)progressIndex)/((double)totalProgress);
|
||||
|
||||
double p=100.*((double)progressIndex)/((double)totalProgress);
|
||||
pthread_mutex_unlock(&mp);
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
|
@ -258,9 +258,9 @@ int angularConversionStatic::finalizeMerging(double *mp, double *mv, double *me,
|
||||
for (int ibin=0; ibin<nb; ibin++) {
|
||||
if (mm[ibin]>0) {
|
||||
|
||||
#ifdef VERBOSE
|
||||
cout << "finalize " << ibin << " "<< mm[ibin] << " " << mp[ibin]<< mv[ibin] << me[ibin] << endl;
|
||||
#endif
|
||||
// #ifdef VERBOSE
|
||||
// cout << "finalize " << ibin << " "<< mm[ibin] << " " << mp[ibin]<< mv[ibin] << me[ibin] << endl;
|
||||
// #endif
|
||||
mp[np]=mp[ibin]/mm[ibin];
|
||||
mv[np]=mv[ibin]/mm[ibin];
|
||||
me[np]=me[ibin]/mm[ibin];
|
||||
@ -323,9 +323,9 @@ int angularConversionStatic::addToMerging(double *p1, double *v1, double *e1, d
|
||||
me[ibin]+=v1[ip];
|
||||
mm[ibin]++;
|
||||
|
||||
#ifdef VERBOSE
|
||||
cout << "add " << ibin << " "<< mm[ibin] << " " << mp[ibin]<< mv[ibin] << me[ibin] << endl;
|
||||
#endif
|
||||
// #ifdef VERBOSE
|
||||
// cout << "add " << ibin << " "<< mm[ibin] << " " << mp[ibin]<< mv[ibin] << me[ibin] << endl;
|
||||
// #endif
|
||||
} else
|
||||
return slsDetectorDefs::FAIL;
|
||||
}
|
||||
@ -371,9 +371,9 @@ int angularConversionStatic::addPointToMerging(double p1, double v1, double e1,
|
||||
me[ibin]+=v1;
|
||||
mm[ibin]++;
|
||||
|
||||
#ifdef VERBOSE
|
||||
cout << "add " << ibin << " "<< mm[ibin] << " " << mp[ibin]<< mv[ibin] << me[ibin] << endl;
|
||||
#endif
|
||||
// #ifdef VERBOSE
|
||||
// cout << "add " << ibin << " "<< mm[ibin] << " " << mp[ibin]<< mv[ibin] << me[ibin] << endl;
|
||||
// #endif
|
||||
} else
|
||||
return slsDetectorDefs::FAIL;
|
||||
|
||||
|
@ -30,7 +30,7 @@ double* angularConversionStatic::convertAngles(double pos, int nch, int *chansPe
|
||||
angleConversionConstant *p=NULL;
|
||||
|
||||
int ch0=0;
|
||||
int chlast=chansPerMod[0];
|
||||
int chlast=chansPerMod[0]-1;
|
||||
int nchmod=chansPerMod[0];
|
||||
p=angOff[imod];
|
||||
if (mF[imod]==0)
|
||||
@ -42,7 +42,7 @@ double* angularConversionStatic::convertAngles(double pos, int nch, int *chansPe
|
||||
#ifdef VERBOSE
|
||||
// cout << "ip " << ip << " ch0 " << ch0 << " chlast " << chlast << " imod " << imod << endl;
|
||||
#endif
|
||||
if (ip>=chlast) {
|
||||
if (ip>chlast) {
|
||||
imod++;
|
||||
p=angOff[imod];
|
||||
if (mF[imod]==0)
|
||||
@ -50,10 +50,10 @@ double* angularConversionStatic::convertAngles(double pos, int nch, int *chansPe
|
||||
else
|
||||
enc=pos;
|
||||
|
||||
ch0=chlast;
|
||||
ch0=chlast+1;
|
||||
nchmod=chansPerMod[imod];
|
||||
if (nchmod>0)
|
||||
chlast+=nchmod;
|
||||
chlast=ch0+nchmod-1;
|
||||
}
|
||||
|
||||
if (p)
|
||||
@ -69,6 +69,72 @@ double* angularConversionStatic::convertAngles(double pos, int nch, int *chansPe
|
||||
return ang;
|
||||
}
|
||||
|
||||
double angularConversionStatic::convertAngle(double pos, int ich, int *chansPerMod, angleConversionConstant **angOff, int *mF, double fo, double go, int angdir) {
|
||||
|
||||
int imod=0;
|
||||
double ang;
|
||||
double enc=0, trans=0;
|
||||
angleConversionConstant *p=NULL;
|
||||
|
||||
int ch0=0;
|
||||
int chlast=chansPerMod[0]-1;
|
||||
int nchmod=chansPerMod[0];
|
||||
|
||||
|
||||
|
||||
while (ich>chlast) {
|
||||
imod++;
|
||||
ch0=chlast+1;
|
||||
nchmod=chansPerMod[imod];
|
||||
chlast=ch0+nchmod-1;
|
||||
}
|
||||
|
||||
p=angOff[imod];
|
||||
|
||||
|
||||
|
||||
switch (mF[imod]) {
|
||||
case 0:
|
||||
enc=0;
|
||||
trans=0;
|
||||
break;
|
||||
case 1:
|
||||
enc=pos;
|
||||
trans=0;
|
||||
break;
|
||||
case -1:
|
||||
enc=-pos;
|
||||
trans=0;
|
||||
break;
|
||||
case 2:
|
||||
enc=0;
|
||||
trans=pos;
|
||||
break;
|
||||
case -2:
|
||||
enc=0;
|
||||
trans=-pos;
|
||||
break;
|
||||
default:
|
||||
enc=0;
|
||||
trans=0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (p)
|
||||
ang=angle(ich-ch0, \
|
||||
enc, \
|
||||
fo+go, \
|
||||
p->r_conversion, \
|
||||
p->center, \
|
||||
p->offset, \
|
||||
trans, \
|
||||
angdir );
|
||||
|
||||
return ang;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//static!
|
||||
@ -265,6 +331,53 @@ int angularConversionStatic::addToMerging(double *p1, double *v1, double *e1, d
|
||||
}
|
||||
|
||||
|
||||
return slsDetectorDefs::OK;
|
||||
|
||||
}
|
||||
|
||||
int angularConversionStatic::addPointToMerging(double p1, double v1, double e1, double *mp, double *mv,double *me, int *mm, double binsize,int nbins) {
|
||||
|
||||
|
||||
double binmi=-180.;
|
||||
int ibin=0;
|
||||
|
||||
|
||||
if (mp==NULL) //can be changed if we want to use a fixed bin algorithm!
|
||||
return slsDetectorDefs::FAIL;
|
||||
|
||||
if (mv==NULL)
|
||||
return slsDetectorDefs::FAIL;
|
||||
if (me==NULL)
|
||||
return slsDetectorDefs::FAIL;
|
||||
if (mm==NULL)
|
||||
return slsDetectorDefs::FAIL;
|
||||
|
||||
if (binsize<=0)
|
||||
return slsDetectorDefs::FAIL;
|
||||
|
||||
if (nbins<=0)
|
||||
return slsDetectorDefs::FAIL;
|
||||
|
||||
|
||||
ibin=(int)((p1-binmi)/binsize);
|
||||
|
||||
|
||||
if (ibin<nbins && ibin>=0) {
|
||||
mp[ibin]+=p1;
|
||||
mv[ibin]+=v1;
|
||||
if (e1)
|
||||
me[ibin]+=(e1*e1);
|
||||
else
|
||||
me[ibin]+=v1;
|
||||
mm[ibin]++;
|
||||
|
||||
#ifdef VERBOSE
|
||||
cout << "add " << ibin << " "<< mm[ibin] << " " << mp[ibin]<< mv[ibin] << me[ibin] << endl;
|
||||
#endif
|
||||
} else
|
||||
return slsDetectorDefs::FAIL;
|
||||
|
||||
|
||||
return slsDetectorDefs::OK;
|
||||
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
|
||||
|
||||
postProcessing::postProcessing(){
|
||||
postProcessing::postProcessing(): expTime(NULL){
|
||||
pthread_mutex_t mp1 = PTHREAD_MUTEX_INITIALIZER;
|
||||
mp=mp1;
|
||||
pthread_mutex_init(&mp, NULL);
|
||||
@ -64,6 +64,9 @@ void postProcessing::processFrame(int *myData, int delflag) {
|
||||
|
||||
|
||||
fname=createFileName();
|
||||
#ifdef VERBOSE
|
||||
cout << "fname is " << fname << endl;
|
||||
#endif
|
||||
|
||||
//Checking for write flag
|
||||
if(*correctionMask&(1<<WRITE_FILE)) {
|
||||
@ -80,9 +83,16 @@ void postProcessing::processFrame(int *myData, int delflag) {
|
||||
|
||||
#endif
|
||||
}
|
||||
if (rawDataReady)
|
||||
if (rawDataReady) {
|
||||
#ifdef VERBOSE
|
||||
cout << "raw data ready..." << endl;
|
||||
#endif
|
||||
rawDataReady(fdata,pRawDataArg);
|
||||
|
||||
#ifdef VERBOSE
|
||||
cout << "done" << endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (*correctionMask & ~(1<<WRITE_FILE))
|
||||
doProcessing(fdata,delflag, fname);
|
||||
|
||||
@ -98,8 +108,18 @@ void postProcessing::processFrame(int *myData, int delflag) {
|
||||
if(*correctionMask&(1<<WRITE_FILE))
|
||||
IncrementFileIndex();
|
||||
|
||||
#ifdef VERBOSE
|
||||
cout << "findex incremented " << endl;
|
||||
#endif
|
||||
popDataQueue(); //remove the data from the queue
|
||||
queuesize=dataQueueSize();
|
||||
#ifdef VERBOSE
|
||||
cout << "Pop data queue " << *fileIndex << endl;
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef VERBOSE
|
||||
cout << "processing returning " << *fileIndex << endl;
|
||||
#endif
|
||||
|
||||
|
||||
}
|
||||
@ -108,6 +128,11 @@ void postProcessing::processFrame(int *myData, int delflag) {
|
||||
|
||||
|
||||
void postProcessing::doProcessing(double *lfdata, int delflag, string fname) {
|
||||
|
||||
#ifdef VERBOSE
|
||||
cout << "do processing - data size is " << arraySize << endl;
|
||||
#endif
|
||||
|
||||
|
||||
double *ang=new double[arraySize];
|
||||
double *val=new double[arraySize];
|
||||
@ -115,12 +140,28 @@ void postProcessing::doProcessing(double *lfdata, int delflag, string fname) {
|
||||
int np;
|
||||
detectorData *thisData;
|
||||
|
||||
#ifdef VERBOSE
|
||||
cout << "arrays allocated " << endl;
|
||||
#endif
|
||||
int npos=getNumberOfPositions();
|
||||
|
||||
string ext=".dat";
|
||||
|
||||
double t=(*expTime)*1E-9;
|
||||
if (GetCurrentPositionIndex()<=1) {
|
||||
#ifdef VERBOSE
|
||||
cout << "npos is "<< npos << endl;
|
||||
#endif
|
||||
|
||||
double t=0;
|
||||
|
||||
// if (expTime)
|
||||
// t=(*expTime)*1E-9;
|
||||
//else
|
||||
// cout << "no pointer to exptime" << endl;
|
||||
#ifdef VERBOSE
|
||||
cout << "exptime is "<< t << endl;
|
||||
#endif
|
||||
|
||||
if (GetCurrentPositionIndex()<=1) {
|
||||
#ifdef VERBOSE
|
||||
cout << "init dataset" << endl;
|
||||
#endif
|
||||
@ -145,10 +186,12 @@ void postProcessing::doProcessing(double *lfdata, int delflag, string fname) {
|
||||
pthread_mutex_lock(&mp);
|
||||
fname=createFileName();
|
||||
pthread_mutex_unlock(&mp);
|
||||
|
||||
if(*correctionMask&(1<<WRITE_FILE))
|
||||
writeDataFile (fname+ext,np,ang, val, err,'f');
|
||||
|
||||
|
||||
if(*correctionMask&(1<<WRITE_FILE)) {
|
||||
cout << "writing to file?!?!?" << endl;
|
||||
writeDataFile (fname+ext,np,ang, val, err,'f');
|
||||
}
|
||||
thisData=new detectorData(ang,val,err,getCurrentProgress(),(fname+ext).c_str(),np);
|
||||
|
||||
if (dataReady) {
|
||||
@ -310,21 +353,39 @@ int* postProcessing::dataQueueFront() {
|
||||
}
|
||||
int postProcessing::dataQueueSize() {
|
||||
int retval;
|
||||
|
||||
#ifdef VERBOSE
|
||||
cout << "data queue size lock" << endl;
|
||||
#endif
|
||||
|
||||
|
||||
pthread_mutex_lock(&mp);
|
||||
retval=dataQueue.size();
|
||||
pthread_mutex_unlock(&mp);
|
||||
#ifdef VERBOSE
|
||||
cout << "data queue size unlock" << endl;
|
||||
#endif
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
int* postProcessing::popDataQueue() {
|
||||
int *retval=NULL;
|
||||
#ifdef VERBOSE
|
||||
cout << "Pop data queue lock" << endl;
|
||||
#endif
|
||||
|
||||
pthread_mutex_lock(&mp);
|
||||
if( !dataQueue.empty() ) {
|
||||
retval=dataQueue.front();
|
||||
dataQueue.pop();
|
||||
}
|
||||
queuesize=dataQueue.size();
|
||||
pthread_mutex_unlock(&mp);
|
||||
#ifdef VERBOSE
|
||||
cout << "Pop data queue lock" << endl;
|
||||
#endif
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
@ -226,7 +226,8 @@ s
|
||||
|
||||
int GetCurrentPositionIndex(){ pthread_mutex_lock(&mp); int retval=getCurrentPositionIndex(); pthread_mutex_unlock(&mp); return retval;};
|
||||
void IncrementPositionIndex(){ pthread_mutex_lock(&mp); incrementPositionIndex(); pthread_mutex_unlock(&mp);};
|
||||
void IncrementFileIndex(){ pthread_mutex_lock(&mp); incrementFileIndex(); pthread_mutex_unlock(&mp);};
|
||||
|
||||
void IncrementFileIndex(){ pthread_mutex_lock(&mp); incrementFileIndex(); pthread_mutex_unlock(&mp); cout << "findex unlock" << endl;};
|
||||
|
||||
void ResetPositionIndex(){pthread_mutex_lock(&mp); resetPositionIndex(); pthread_mutex_unlock(&mp);};
|
||||
|
||||
@ -243,8 +244,8 @@ s
|
||||
|
||||
int positionFinished(int v=-1){pthread_mutex_lock(&mp); if (v>=0) posfinished=v; int retval=posfinished; pthread_mutex_unlock(&mp); return retval;};
|
||||
|
||||
double getCurrentPosition() {double p; pthread_mutex_lock(&mp); p=currentPosition; pthread_mutex_unlock(&mp); return p;}
|
||||
int setCurrentPosition(double v) { pthread_mutex_lock(&mp); currentPosition=v; pthread_mutex_unlock(&mp); }
|
||||
double getCurrentPosition() {double p; pthread_mutex_lock(&mp); p=currentPosition; pthread_mutex_unlock(&mp); return p;};
|
||||
int setCurrentPosition(double v) { pthread_mutex_lock(&mp); currentPosition=v; pthread_mutex_unlock(&mp); return currentPosition;};
|
||||
|
||||
|
||||
protected:
|
||||
|
@ -309,12 +309,12 @@ int defaultDataReadyFunc(detectorData* d, void* p) {
|
||||
printf("UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU Data received \n");
|
||||
printf("Filename %s\n",d->fileName);
|
||||
printf("Number of points %d (%d)\n",d->npoints,d->npy);
|
||||
for(int i=0;i<d->npoints;i++){
|
||||
/* for(int i=0;i<d->npoints;i++){
|
||||
if ((d->angles))
|
||||
printf("%d-[%f]:%f\n",i,(d->angles)[i],(d->values)[i]);
|
||||
else
|
||||
printf("%d-%f\n",i,(d->values)[i]);
|
||||
}
|
||||
}*/
|
||||
printf("UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU Finished \n");
|
||||
#endif
|
||||
return 0;
|
||||
|
Reference in New Issue
Block a user