solved segmentation fault on may frames, printing progress during acquisition

git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@144 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
bergamaschi 2012-03-16 12:25:45 +00:00
parent 97a0d06618
commit d8d08d5a9b
4 changed files with 60 additions and 67 deletions

View File

@ -1077,8 +1077,8 @@ int* multiSlsDetector::readAll(){
i++; i++;
#ifdef VERBOSE #ifdef VERBOSE
std::cout<< i << std::endl; std::cout<< i << std::endl;
#else //#else
std::cout << "-" << flush; //std::cout << "-" << flush;
#endif #endif
dataQueue.push(retval); dataQueue.push(retval);
} }
@ -1117,8 +1117,8 @@ int* multiSlsDetector::startAndReadAll(){
i++; i++;
#ifdef VERBOSE #ifdef VERBOSE
std::cout<< i << std::endl; std::cout<< i << std::endl;
#else //#else
std::cout << "-" << flush; //std::cout << "-" << flush;
#endif #endif
dataQueue.push(retval); dataQueue.push(retval);
} }
@ -2887,7 +2887,9 @@ int multiSlsDetector::writeConfigurationFile(string const fname){
ofstream outfile; ofstream outfile;
// int ret; #ifdef VERBOSE
int ret;
#endif
outfile.open(fname.c_str(),ios_base::out); outfile.open(fname.c_str(),ios_base::out);
if (outfile.is_open()) { if (outfile.is_open()) {

View File

@ -3080,8 +3080,8 @@ int* slsDetector::readAll(){
i++; i++;
#ifdef VERBOSE #ifdef VERBOSE
std::cout<< i << std::endl; std::cout<< i << std::endl;
#else //#else
std::cout << "-" << flush ; //std::cout << "-" << flush ;
#endif #endif
dataQueue.push(retval); dataQueue.push(retval);
} }
@ -3141,8 +3141,8 @@ int* slsDetector::startAndReadAll(){
i++; i++;
#ifdef VERBOSE #ifdef VERBOSE
std::cout<< i << std::endl; std::cout<< i << std::endl;
#else //#else
std::cout<< "-" << flush; //std::cout<< "-" << flush;
#endif #endif
dataQueue.push(retval); dataQueue.push(retval);
} }

View File

@ -637,7 +637,7 @@ string slsDetectorCommand::executeLine(int narg, char *args[], int action) {
string slsDetectorCommand::cmdUnknown(int narg, char *args[], int action) { string slsDetectorCommand::cmdUnknown(int narg, char *args[], int action) {
return string("Unknown command ")+string(args[0])+string("\n")+helpLine(narg, args, action); return string("Unknown command ")+string(args[0])+string("\n");//+helpLine(narg, args, action);
} }
string slsDetectorCommand::cmdUnderDevelopment(int narg, char *args[], int action) { string slsDetectorCommand::cmdUnderDevelopment(int narg, char *args[], int action) {
@ -732,7 +732,7 @@ string slsDetectorCommand::cmdAcquire(int narg, char *args[], int action) {
#endif #endif
myDet->setOnline(ONLINE_FLAG); myDet->setOnline(ONLINE_FLAG);
myDet->acquire(1); myDet->acquire(1);
return string("ok"); return string("");
} }
@ -770,7 +770,7 @@ string slsDetectorCommand::cmdData(int narg, char *args[], int action) {
myDet->readAll(); myDet->readAll();
myDet->processData(1); myDet->processData(1);
myDet->setThreadedProcessing(b); myDet->setThreadedProcessing(b);
return string("ok"); return string("");
} }
} }
@ -1763,7 +1763,7 @@ string slsDetectorCommand::helpScripts(int narg, char *args[], int action) {
string slsDetectorCommand::cmdScans(int narg, char *args[], int action) { string slsDetectorCommand::cmdScans(int narg, char *args[], int action) {
int is=-1, ival, ns=0; int is=-1, ival, ns=0;
char answer[MAX_STR_LENGTH*10]; char answer[MAX_SCAN_STEPS*10];
float *values; float *values;
if (action==HELP_ACTION) if (action==HELP_ACTION)
return helpScans(narg,args,action); return helpScans(narg,args,action);

View File

@ -1661,22 +1661,28 @@ void* slsDetectorUtils::processData(int delflag) {
while((queuesize=dataQueue.size())>0) { while((queuesize=dataQueue.size())>0) {
#ifdef VERBOSE #ifdef VERBOSE
std::cout<< " queue size " << queuesize << endl; // std::cout<< " queue size " << queuesize << endl;
#endif #endif
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 */
myData=dataQueue.front(); // get the data from the queue myData=dataQueue.front(); // get the data from the queue
pthread_mutex_unlock(&mp);
if (myData) { if (myData) {
progressIndex++; progressIndex++;
//#ifdef VERBOSE
cout << fixed << setprecision(2) << setw (6) << getCurrentProgress() << " \%";
#ifdef VERBOSE #ifdef VERBOSE
cout << "Progress is " << getCurrentProgress() << " \%" << endl; cout << endl;
#else
cout << "\r" << flush;
#endif #endif
//process data //process data
@ -1714,11 +1720,11 @@ void* slsDetectorUtils::processData(int delflag) {
ffcdata=new float[getTotalNumberOfChannels()]; ffcdata=new float[getTotalNumberOfChannels()];
ffcerr=new float[getTotalNumberOfChannels()]; ffcerr=new float[getTotalNumberOfChannels()];
#ifdef VERBOSE #ifdef VERBOSE
cout << "array size " << getTotalNumberOfChannels() << endl; // cout << "array size " << getTotalNumberOfChannels() << endl;
#endif #endif
flatFieldCorrect(rcdata,rcerr,ffcdata,ffcerr); flatFieldCorrect(rcdata,rcerr,ffcdata,ffcerr);
#ifdef VERBOSE #ifdef VERBOSE
cout << "FF corr done " << endl; // cout << "FF corr done " << endl;
#endif #endif
delete [] rcdata; delete [] rcdata;
rcdata=NULL; rcdata=NULL;
@ -1733,7 +1739,7 @@ void* slsDetectorUtils::processData(int delflag) {
if (*correctionMask&(1<< ANGULAR_CONVERSION)) { if (*correctionMask&(1<< ANGULAR_CONVERSION)) {
#ifdef VERBOSE #ifdef VERBOSE
cout << "**************Current position index is " << currentPositionIndex << endl; // cout << "**************Current position index is " << currentPositionIndex << endl;
#endif #endif
if (currentPositionIndex<=1) { if (currentPositionIndex<=1) {
if (*binSize>0) if (*binSize>0)
@ -1745,7 +1751,7 @@ void* slsDetectorUtils::processData(int delflag) {
nb=(int)(360./bs)+1; nb=(int)(360./bs)+1;
#ifdef VERBOSE #ifdef VERBOSE
cout << "creating merging arrays "<< nb << endl; // cout << "creating merging arrays "<< nb << endl;
#endif #endif
mergingBins=new float[nb]; mergingBins=new float[nb];
mergingCounts=new float[nb]; mergingCounts=new float[nb];
@ -1757,14 +1763,14 @@ void* slsDetectorUtils::processData(int delflag) {
#endif #endif
#ifdef VERBOSE #ifdef VERBOSE
cout << "reset merging " << endl; // cout << "reset merging " << endl;
#endif #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 #ifdef VERBOSE
cout << "convert angles" << endl; // cout << "convert angles" << endl;
#endif #endif
ang=convertAngles(currentPosition); ang=convertAngles(currentPosition);
@ -1773,14 +1779,14 @@ void* slsDetectorUtils::processData(int delflag) {
//uses static function?!?!?!? //uses static function?!?!?!?
//writeDataFile (fname+string(".dat"), getTotalNumberOfChannels(), ffcdata, ffcerr,ang); //writeDataFile (fname+string(".dat"), getTotalNumberOfChannels(), ffcdata, ffcerr,ang);
#ifdef VERBOSE #ifdef VERBOSE
cout << "Write angular converted file for position " << currentPositionIndex << endl; // cout << "Write angular converted file for position " << currentPositionIndex << endl;
#endif #endif
writeDataFile (fname+string(".dat"), ffcdata, ffcerr,ang); writeDataFile (fname+string(".dat"), ffcdata, ffcerr,ang);
} }
} }
#ifdef VERBOSE #ifdef VERBOSE
cout << "add to merging "<< currentPositionIndex << endl; // cout << "add to merging "<< currentPositionIndex << endl;
#endif #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 );
@ -1796,82 +1802,68 @@ void* slsDetectorUtils::processData(int delflag) {
// if ((currentPositionIndex>=(*numberOfPositions)) || (currentPositionIndex==0)) { // if ((currentPositionIndex>=(*numberOfPositions)) || (currentPositionIndex==0)) {
#ifdef VERBOSE #ifdef VERBOSE
cout << "finalize merging " << currentPositionIndex<< endl; // cout << "finalize merging " << currentPositionIndex<< endl;
#endif #endif
np=finalizeMerging(mergingBins, mergingCounts,mergingErrors, mergingMultiplicity, bs); np=finalizeMerging(mergingBins, mergingCounts,mergingErrors, mergingMultiplicity, bs);
/** file writing */ /** file writing */
// pthread_mutex_lock(&mp);
// if (currentPositionIndex==(*numberOfPositions) && posfinished==1 && queuesize==1) {
//cout << "PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP Incrementing positon index " << endl;
currentPositionIndex++; currentPositionIndex++;
// }
pthread_mutex_unlock(&mp); pthread_mutex_unlock(&mp);
fname=createFileName(); fname=createFileName();
//if (*correctionMask!=0) { ///////is this necessary?!?!?!?
//uses static function?!?!?!?
#ifdef VERBOSE #ifdef VERBOSE
cout << "writing merged data file" << endl; // cout << "writing merged data file" << endl;
#endif #endif
writeDataFile (fname+string(".dat"),np,mergingCounts, mergingErrors, mergingBins,'f'); writeDataFile (fname+string(".dat"),np,mergingCounts, mergingErrors, mergingBins,'f');
#ifdef VERBOSE #ifdef VERBOSE
cout << " done" << endl; // cout << " done" << endl;
#endif #endif
//}
// if ((*numberOfPositions)==0)
// currentPositionIndex--;
if (delflag) { if (delflag) {
#ifdef VERBOSE #ifdef VERBOSE
cout << mergingBins<< " " << mergingCounts<< " " << mergingErrors << " " << mergingMultiplicity << " " << endl; // cout << mergingBins<< " " << mergingCounts<< " " << mergingErrors << " " << mergingMultiplicity << " " << endl;
#endif #endif
if (mergingBins) { if (mergingBins) {
#ifdef VERBOSE #ifdef VERBOSE
cout << "deleting merged bins "<< mergingBins << " size " << sizeof(mergingBins) << endl; // cout << "deleting merged bins "<< mergingBins << " size " << sizeof(mergingBins) << endl;
#endif #endif
delete [] mergingBins; delete [] mergingBins;
mergingBins=NULL; mergingBins=NULL;
} }
if (mergingCounts) { if (mergingCounts) {
#ifdef VERBOSE #ifdef VERBOSE
cout << "deleting merged counts "<< mergingCounts << endl; // cout << "deleting merged counts "<< mergingCounts << endl;
#endif #endif
delete [] mergingCounts; delete [] mergingCounts;
mergingCounts=NULL; mergingCounts=NULL;
} }
if (mergingErrors) { if (mergingErrors) {
#ifdef VERBOSE #ifdef VERBOSE
cout << "deleting merged errors "<< mergingErrors << endl; // cout << "deleting merged errors "<< mergingErrors << endl;
#endif #endif
delete [] mergingErrors; delete [] mergingErrors;
mergingErrors=NULL; mergingErrors=NULL;
} }
if (mergingMultiplicity){ if (mergingMultiplicity){
#ifdef VERBOSE #ifdef VERBOSE
cout << "deleting merged multiplicity "<<mergingMultiplicity << endl; // cout << "deleting merged multiplicity "<<mergingMultiplicity << endl;
#endif #endif
delete [] mergingMultiplicity; delete [] mergingMultiplicity;
mergingMultiplicity=NULL; mergingMultiplicity=NULL;
} }
#ifdef VERBOSE #ifdef VERBOSE
cout << "deleting merged data done " << endl; // cout << "deleting merged data done " << endl;
//#ifdef VERBOSE
cout << mergingBins<< " " << mergingCounts<< " " << mergingErrors << " " << mergingMultiplicity << " " << endl; // cout << mergingBins<< " " << mergingCounts<< " " << mergingErrors << " " << mergingMultiplicity << " " << endl;
//#endif
#endif #endif
} else { } else {
@ -1884,7 +1876,7 @@ void* slsDetectorUtils::processData(int delflag) {
#ifdef VERBOSE #ifdef VERBOSE
cout << "delete data" << ffcdata << endl; // cout << "delete data" << ffcdata << endl;
#endif #endif
if (ffcdata) if (ffcdata)
@ -1892,13 +1884,13 @@ void* slsDetectorUtils::processData(int delflag) {
ffcdata=NULL; ffcdata=NULL;
#ifdef VERBOSE #ifdef VERBOSE
cout << "delete err " << ffcerr << endl; // cout << "delete err " << ffcerr << endl;
#endif #endif
if (ffcerr) if (ffcerr)
delete [] ffcerr; delete [] ffcerr;
ffcerr=NULL; ffcerr=NULL;
#ifdef VERBOSE #ifdef VERBOSE
cout << "delete ang " << ang << endl; // cout << "delete ang " << ang << endl;
#endif #endif
if (ang) if (ang)
delete [] ang; delete [] ang;
@ -1907,8 +1899,6 @@ void* slsDetectorUtils::processData(int delflag) {
} else { } else {
if (*correctionMask!=0) { if (*correctionMask!=0) {
//uses static function?!?!?!?
//writeDataFile (fname+string(".dat"), getTotalNumberOfChannels(), ffcdata, ffcerr);
writeDataFile (fname+string(".dat"), ffcdata, ffcerr); writeDataFile (fname+string(".dat"), ffcdata, ffcerr);
} }
if (delflag) { if (delflag) {
@ -1926,21 +1916,21 @@ void* slsDetectorUtils::processData(int delflag) {
} }
(*fileIndex)++; (*fileIndex)++;
#ifdef VERBOSE #ifdef VERBOSE
cout << "Incrementing file index " << *fileIndex << endl; // cout << "Incrementing file index " << *fileIndex << endl;
#endif #endif
#ifdef VERBOSE #ifdef VERBOSE
cout << "delete data " << myData << endl; // cout << "delete data " << myData << endl;
#endif #endif
delete [] myData; delete [] myData;
myData=NULL; myData=NULL;
#ifdef VERBOSE #ifdef VERBOSE
cout << "Pop data queue " << *fileIndex << endl; // cout << "Pop data queue " << *fileIndex << endl;
#endif #endif
dataQueue.pop(); //remove the data from the queue
pthread_mutex_lock(&mp); pthread_mutex_lock(&mp);
dataQueue.pop(); //remove the data from the queue
queuesize=dataQueue.size(); queuesize=dataQueue.size();
pthread_mutex_unlock(&mp); pthread_mutex_unlock(&mp);
usleep(1000); usleep(1000);
@ -1964,7 +1954,7 @@ void* slsDetectorUtils::processData(int delflag) {
} }
#ifdef VERBOSE #ifdef VERBOSE
cout << "data Queue size is " << dataQueue.size() << endl; // cout << "data Queue size is " << dataQueue.size() << endl;
#endif #endif
pthread_mutex_unlock(&mp); pthread_mutex_unlock(&mp);
} else { } else {
@ -1975,6 +1965,7 @@ void* slsDetectorUtils::processData(int delflag) {
} }
dum=0; dum=0;
} // ???????????????????????? } // ????????????????????????
// cout << fixed << setprecision(2) << setw (6) << getCurrentProgress() << " \%"<< endl;
return 0; return 0;
} }