Should now work also for multiple frames and positions

git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@140 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
bergamaschi 2012-03-15 09:59:40 +00:00
parent 14bc483310
commit 4b296b6b7d
3 changed files with 204 additions and 31 deletions

View File

@ -1457,8 +1457,10 @@ int multiSlsDetector::setFlatFieldCorrection(string fname){
xmed[im]=data[ichan]; xmed[im]=data[ichan];
nmed++; nmed++;
} else { } else {
badlist[nbad]=ichdet; if (nbad<MAX_BADCHANS) {
nbad++; badlist[nbad]=ichdet;
nbad++;
}
} }
} }
if (detectors[idet]) if (detectors[idet])

View File

@ -1223,6 +1223,9 @@ void slsDetectorUtils::acquire(int delflag){
#endif #endif
posfinished=0;
void *status; void *status;
int trimbit; int trimbit;
@ -1453,18 +1456,39 @@ void slsDetectorUtils::acquire(int delflag){
if (*stoppedFlag==0) { if (*stoppedFlag==0) {
if (*correctionMask&(1<< ANGULAR_CONVERSION)) {
pthread_mutex_lock(&mp);
currentPosition=get_position();
posfinished=0;
pthread_mutex_unlock(&mp);
}
// cout << "starting???? " << endl; // cout << "starting???? " << endl;
startAndReadAll(); startAndReadAll();
if (*correctionMask&(1<< ANGULAR_CONVERSION)) pthread_mutex_lock(&mp);
currentPosition=get_position(); posfinished=1;
pthread_mutex_unlock(&mp);
#ifdef VERBOSE
cout << "returned " << endl;
pthread_mutex_lock(&mp);
cout << "AAAA queue size " << dataQueue.size()<< endl;
pthread_mutex_unlock(&mp);
#endif
if (*correctionMask&(1<< I0_NORMALIZATION)) if (*correctionMask&(1<< I0_NORMALIZATION))
currentI0=get_i0()-currentI0; currentI0=get_i0()-currentI0;
////////////////// Reput in in case of unthreaded processing ////////////////// Reput in in case of unthreaded processing
// if (*threadedProcessing==0) if (*threadedProcessing==0){
// processData(delflag); #ifdef VERBOSE
cout << "start unthreaded process data " << endl;
#endif
processData(delflag);
}
} else } else
@ -1524,7 +1548,7 @@ void slsDetectorUtils::acquire(int delflag){
*fileIndex=startindex; *fileIndex=startindex;
} }
} // loop on position finished } // loop on position finished
//script after //script after
if (*stoppedFlag==0) { if (*stoppedFlag==0) {
if (*actionMask & (1 << scriptAfter)) { if (*actionMask & (1 << scriptAfter)) {
@ -1599,6 +1623,10 @@ void slsDetectorUtils::acquire(int delflag){
void* slsDetectorUtils::processData(int delflag) { void* slsDetectorUtils::processData(int delflag) {
#ifdef VERBOSE
std::cout<< " processing data - threaded mode " << *threadedProcessing << endl;
#endif
//cout << "thread mutex lock line 6505" << endl; //cout << "thread mutex lock line 6505" << endl;
pthread_mutex_lock(&mp); pthread_mutex_lock(&mp);
queuesize=dataQueue.size(); queuesize=dataQueue.size();
@ -1606,7 +1634,7 @@ void* slsDetectorUtils::processData(int delflag) {
//cout << "thread mutex unlock line 6505" << endl; //cout << "thread mutex unlock line 6505" << endl;
int *myData; int *myData;
float *fdata; float *fdata=NULL;
float *rcdata=NULL, *rcerr=NULL; float *rcdata=NULL, *rcerr=NULL;
float *ffcdata=NULL, *ffcerr=NULL; float *ffcdata=NULL, *ffcerr=NULL;
float *ang=NULL; float *ang=NULL;
@ -1620,9 +1648,6 @@ void* slsDetectorUtils::processData(int delflag) {
string fname; string fname;
#ifdef ACQVERBOSE
std::cout<< " processing data - threaded mode " << *threadedProcessing;
#endif
if (*correctionMask!=0) { if (*correctionMask!=0) {
ext=".dat"; ext=".dat";
@ -1633,11 +1658,16 @@ void* slsDetectorUtils::processData(int delflag) {
// while( !dataQueue.empty() ) { // while( !dataQueue.empty() ) {
//cout << "thread mutex lock line 6539" << endl; // cout << "thread mutex lock line 6539" << endl;
pthread_mutex_lock(&mp); pthread_mutex_lock(&mp);
while((queuesize=dataQueue.size())>0) { while((queuesize=dataQueue.size())>0) {
#ifdef VERBOSE
std::cout<< " queue size " << queuesize << endl;
#endif
pthread_mutex_unlock(&mp); pthread_mutex_unlock(&mp);
//cout << "thread mutex unlock line 6543" << endl; // cout << "thread mutex unlock line 6543" << endl;
//queuesize=dataQueue.size(); //queuesize=dataQueue.size();
/** Pop data queue */ /** Pop data queue */
@ -1674,6 +1704,7 @@ void* slsDetectorUtils::processData(int delflag) {
rcerr=new float[getTotalNumberOfChannels()]; rcerr=new float[getTotalNumberOfChannels()];
rateCorrect(fdata,NULL,rcdata,rcerr); rateCorrect(fdata,NULL,rcdata,rcerr);
delete [] fdata; delete [] fdata;
fdata=NULL;
} else { } else {
rcdata=fdata; rcdata=fdata;
fdata=NULL; fdata=NULL;
@ -1692,7 +1723,9 @@ void* slsDetectorUtils::processData(int delflag) {
cout << "FF corr done " << endl; cout << "FF corr done " << endl;
#endif #endif
delete [] rcdata; delete [] rcdata;
rcdata=NULL;
if (rcerr) delete [] rcerr; if (rcerr) delete [] rcerr;
rcerr=NULL;
} else { } else {
ffcdata=rcdata; ffcdata=rcdata;
ffcerr=rcerr; ffcerr=rcerr;
@ -1701,62 +1734,179 @@ void* slsDetectorUtils::processData(int delflag) {
} }
if (*correctionMask&(1<< ANGULAR_CONVERSION)) { if (*correctionMask&(1<< ANGULAR_CONVERSION)) {
#ifdef VERBOSE
cout << "**************Current position index is " << currentPositionIndex << endl;
#endif
if (currentPositionIndex<=1) { if (currentPositionIndex<=1) {
if (*binSize>0) if (*binSize>0)
bs=*binSize; bs=*binSize;
else else
*binSize=bs; *binSize=bs;
nb=(int)(360./bs); nb=(int)(360./bs)+1;
#ifdef VERBOSE
cout << "creating merging arrays "<< nb << endl;
#endif
mergingBins=new float[nb]; mergingBins=new float[nb];
mergingCounts=new float[nb]; mergingCounts=new float[nb];
mergingErrors=new float[nb]; mergingErrors=new float[nb];
mergingMultiplicity=new int[nb]; mergingMultiplicity=new int[nb];
#ifdef VERBOSE
cout << mergingBins<< " "<< mergingCounts<< " "<< mergingErrors<< " "<< mergingMultiplicity<< " " << endl;
#endif
#ifdef VERBOSE
cout << "reset merging " << endl;
#endif
resetMerging(mergingBins, mergingCounts,mergingErrors, mergingMultiplicity, bs); resetMerging(mergingBins, mergingCounts,mergingErrors, mergingMultiplicity, bs);
} }
/* it would be better to create an ang0 with 0 encoder position and add to merging/write to file simply specifying that offset so that when it cycles writing the data or adding to merging it also calculates the angular position */ /* it would be better to create an ang0 with 0 encoder position and add to merging/write to file simply specifying that offset so that when it cycles writing the data or adding to merging it also calculates the angular position */
#ifdef VERBOSE
cout << "convert angles" << endl;
#endif
ang=convertAngles(currentPosition); ang=convertAngles(currentPosition);
if (*correctionMask!=0) { if (*correctionMask!=0) {
if (*numberOfPositions>1) { if (*numberOfPositions>1) {
//uses static function?!?!?!? //uses static function?!?!?!?
//writeDataFile (fname+string(".dat"), getTotalNumberOfChannels(), ffcdata, ffcerr,ang); //writeDataFile (fname+string(".dat"), getTotalNumberOfChannels(), ffcdata, ffcerr,ang);
#ifdef VERBOSE
cout << "Write angular converted file for position " << currentPositionIndex << endl;
#endif
writeDataFile (fname+string(".dat"), ffcdata, ffcerr,ang); writeDataFile (fname+string(".dat"), ffcdata, ffcerr,ang);
} }
} }
#ifdef VERBOSE
cout << "add to merging "<< currentPositionIndex << endl;
#endif
addToMerging(ang, ffcdata, ffcerr, mergingBins, mergingCounts,mergingErrors, mergingMultiplicity, getTotalNumberOfChannels(), bs, *angDirection, *correctionMask, badChannelMask ); addToMerging(ang, ffcdata, ffcerr, mergingBins, mergingCounts,mergingErrors, mergingMultiplicity, getTotalNumberOfChannels(), bs, *angDirection, *correctionMask, badChannelMask );
if ((currentPositionIndex==*numberOfPositions) || (currentPositionIndex==0)) { #ifdef VERBOSE
cout << currentPositionIndex << " " << (*numberOfPositions) << endl;
#endif
pthread_mutex_lock(&mp);
if (currentPositionIndex==(*numberOfPositions) && posfinished==1 && queuesize==1) {
// if ((currentPositionIndex>=(*numberOfPositions)) || (currentPositionIndex==0)) {
#ifdef VERBOSE
cout << "finalize merging " << currentPositionIndex<< endl;
#endif
np=finalizeMerging(mergingBins, mergingCounts,mergingErrors, mergingMultiplicity, bs); np=finalizeMerging(mergingBins, mergingCounts,mergingErrors, mergingMultiplicity, bs);
/** file writing */ /** file writing */
currentPositionIndex++;
// pthread_mutex_lock(&mp);
// if (currentPositionIndex==(*numberOfPositions) && posfinished==1 && queuesize==1) {
cout << "PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP Incrementing positon index " << endl;
currentPositionIndex++;
// }
pthread_mutex_unlock(&mp);
fname=createFileName(); fname=createFileName();
if (*correctionMask!=0) {
//if (*correctionMask!=0) { ///////is this necessary?!?!?!?
//uses static function?!?!?!? //uses static function?!?!?!?
#ifdef VERBOSE
cout << "writing merged data file" << endl;
#endif
writeDataFile (fname+string(".dat"),np,mergingCounts, mergingErrors, mergingBins,'f'); writeDataFile (fname+string(".dat"),np,mergingCounts, mergingErrors, mergingBins,'f');
} #ifdef VERBOSE
cout << " done" << endl;
#endif
//}
// if ((*numberOfPositions)==0)
// currentPositionIndex--;
if (delflag) { if (delflag) {
#ifdef VERBOSE
cout << mergingBins<< " " << mergingCounts<< " " << mergingErrors << " " << mergingMultiplicity << " " << endl;
#endif
if (mergingBins) {
#ifdef VERBOSE
cout << "deleting merged bins "<< mergingBins << " size " << sizeof(mergingBins) << endl;
#endif
delete [] mergingBins; delete [] mergingBins;
mergingBins=NULL;
}
if (mergingCounts) {
#ifdef VERBOSE
cout << "deleting merged counts "<< mergingCounts << endl;
#endif
delete [] mergingCounts; delete [] mergingCounts;
mergingCounts=NULL;
}
if (mergingErrors) {
#ifdef VERBOSE
cout << "deleting merged errors "<< mergingErrors << endl;
#endif
delete [] mergingErrors; delete [] mergingErrors;
mergingErrors=NULL;
}
if (mergingMultiplicity){
#ifdef VERBOSE
cout << "deleting merged multiplicity "<<mergingMultiplicity << endl;
#endif
delete [] mergingMultiplicity; delete [] mergingMultiplicity;
} else { mergingMultiplicity=NULL;
}
#ifdef VERBOSE
cout << "deleting merged data done " << endl;
//#ifdef VERBOSE
cout << mergingBins<< " " << mergingCounts<< " " << mergingErrors << " " << mergingMultiplicity << " " << endl;
//#endif
#endif
} else {
thisData=new detectorData(mergingCounts,mergingErrors,mergingBins,getCurrentProgress(),(fname+string(ext)).c_str(),np); thisData=new detectorData(mergingCounts,mergingErrors,mergingBins,getCurrentProgress(),(fname+string(ext)).c_str(),np);
finalDataQueue.push(thisData); finalDataQueue.push(thisData);
} }
} pthread_mutex_lock(&mp);
}
pthread_mutex_unlock(&mp);
#ifdef VERBOSE
cout << "delete data" << ffcdata << endl;
#endif
if (ffcdata) if (ffcdata)
delete [] ffcdata; delete [] ffcdata;
if (ffcerr) ffcdata=NULL;
delete [] ffcerr;
#ifdef VERBOSE
cout << "delete err " << ffcerr << endl;
#endif
if (ffcerr)
delete [] ffcerr;
ffcerr=NULL;
#ifdef VERBOSE
cout << "delete ang " << ang << endl;
#endif
if (ang) if (ang)
delete [] ang; delete [] ang;
ang=NULL;
} else { } else {
if (*correctionMask!=0) { if (*correctionMask!=0) {
//uses static function?!?!?!? //uses static function?!?!?!?
@ -1768,7 +1918,7 @@ void* slsDetectorUtils::processData(int delflag) {
delete [] ffcdata; delete [] ffcdata;
if (ffcerr) if (ffcerr)
delete [] ffcerr; delete [] ffcerr;
if (ang) if ( ang)
delete [] ang; delete [] ang;
} else { } else {
thisData=new detectorData(ffcdata,ffcerr,NULL,getCurrentProgress(),(fname+string(ext)).c_str(),getTotalNumberOfChannels()); thisData=new detectorData(ffcdata,ffcerr,NULL,getCurrentProgress(),(fname+string(ext)).c_str(),getTotalNumberOfChannels());
@ -1781,9 +1931,16 @@ void* slsDetectorUtils::processData(int delflag) {
cout << "Incrementing file index " << *fileIndex << endl; cout << "Incrementing file index " << *fileIndex << endl;
#endif #endif
#ifdef VERBOSE
cout << "delete data " << myData << endl;
#endif
delete [] myData; delete [] myData;
myData=NULL; myData=NULL;
#ifdef VERBOSE
cout << "Pop data queue " << *fileIndex << endl;
#endif
dataQueue.pop(); //remove the data from the queue dataQueue.pop(); //remove the data from the queue
pthread_mutex_lock(&mp); pthread_mutex_lock(&mp);
queuesize=dataQueue.size(); queuesize=dataQueue.size();
@ -1796,12 +1953,22 @@ void* slsDetectorUtils::processData(int delflag) {
// cout << "looping on dataque size" << endl; // cout << "looping on dataque size" << endl;
#endif #endif
} }
//pthread_mutex_unlock(&mp);
//pthread_mutex_lock(&mp); #ifdef VERBOSE
// cout << "queue empty -mutex unlock line 1883" << endl;
#endif
pthread_mutex_unlock(&mp);
pthread_mutex_lock(&mp);
if (jointhread) { if (jointhread) {
pthread_mutex_unlock(&mp); if (dataQueue.size()==0) {
if (dataQueue.size()==0) pthread_mutex_unlock(&mp);
break; break;
}
#ifdef VERBOSE
cout << "data Queue size is " << dataQueue.size() << endl;
#endif
pthread_mutex_unlock(&mp);
} else { } else {
#ifdef VERBOSE #ifdef VERBOSE
// cout << "waiting on jointhread "<< jointhread << " " << (*threadedProcessing) << endl; // cout << "waiting on jointhread "<< jointhread << " " << (*threadedProcessing) << endl;

View File

@ -884,6 +884,10 @@ s
/** sets when the acquisition is finished */ /** sets when the acquisition is finished */
int jointhread; int jointhread;
/** sets when the position is finished */
int posfinished;
/** data queue size */ /** data queue size */
int queuesize; int queuesize;