Last workin version

git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@31 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
bergamaschi 2011-03-10 13:39:38 +00:00
parent d4e73141dd
commit a271d7a9e9
5 changed files with 467 additions and 52 deletions

View File

@ -193,7 +193,7 @@ int acceptConnection() {
socketDescriptor=-1;
}
#ifdef VERY_VERBOSE
#ifdef VERBOSE
printf("client connected %d\n", file_des);
#endif
}
@ -291,8 +291,16 @@ int sendDataOnly(void* buf,int length) {
while(length>0){
nreceiving = (length>send_rec_max_size) ? send_rec_max_size:length;
#ifdef VERY_VERBOSE
printf("want to receive %d Bytes\n", nreceiving);
#endif
nreceived = read(file_des,(char*)buf+total_received,nreceiving);
if(!nreceived) break;
#ifdef VERY_VERBOSE
printf("read %d \n", nreceived);
#endif
if(!nreceived) break;
// if(nreceived<0) break;
length-=nreceived;
total_received+=nreceived;
// cout<<"nrec: "<<nreceived<<" waiting for ("<<length<<")"<<endl;

View File

@ -832,28 +832,30 @@ string mythenDetector::executeLine(int narg, char *args[], int action) {
return string(answer);
} else if (var=="progress") {
if (action==PUT_ACTION) {
setTotalProgress();
sprintf(answer,"Cannot set\n");
} else
sprintf(answer,"%f",(float)getTimeLeft(PROGRESS));
sprintf(answer,"%f",getCurrentProgress());
return string(answer);
}
else if (var=="dr") {
if (action==PUT_ACTION) {
sscanf(args[1],"%d",&ival);
setDynamicRange(ival);
}
sprintf(answer,"%d",setDynamicRange());
return string(answer);
} else if (var=="flags") {
if (action==PUT_ACTION) {
sval=string(args[1]);
readOutFlags flag=GET_READOUT_FLAGS;
if (sval=="none")
flag=NORMAL_READOUT;
//else if (sval=="pumpprobe")
// flag=PUMP_PROBE_MODE;
else if (sval=="storeinram")
if (action==PUT_ACTION) {
sscanf(args[1],"%d",&ival);
setDynamicRange(ival);
}
sprintf(answer,"%d",setDynamicRange());
return string(answer);
} else if (var=="flags") {
if (action==PUT_ACTION) {
sval=string(args[1]);
readOutFlags flag=GET_READOUT_FLAGS;
if (sval=="none")
flag=NORMAL_READOUT;
//else if (sval=="pumpprobe")
// flag=PUMP_PROBE_MODE;
else if (sval=="storeinram")
flag=STORE_IN_RAM;
else if (sval=="tot")
flag=TOT_MODE;
@ -1526,6 +1528,10 @@ int mythenDetector::writeConfigurationFile(string const fname){
"trimen",\
"outdir",\
"ffdir",\
"headerbefore",\
"headerafter",\
"headerbeforepar",\
"headerafterpar",\
"nmod",\
"badchannels",\
"angconv",\
@ -1535,7 +1541,7 @@ int mythenDetector::writeConfigurationFile(string const fname){
"waitstates",\
"setlength",\
"clkdivider"};
int nvar=15;
int nvar=19;
ofstream outfile;
int iv=0;
char *args[100];
@ -1582,13 +1588,33 @@ int mythenDetector::dumpDetectorSetup(string fname, int level){
"probes",\
"fineoff",\
"ratecorr",\
"startscript",\
"startscriptpar",\
"stopscript",\
"stopscriptpar",\
"scriptbefore",\
"scriptbeforepar",\
"scriptafter",\
"scriptafterpar",\
"headerbefore",\
"headerbeforepar",\
"headerafter",\
"headerafterpar",\
"scan0script",\
"scan0par",\
"scan0prec",\
"scan0steps",\
"scan1script",\
"scan1par",\
"scan1prec",\
"scan1steps",\
"flatfield",\
"badchannels",\
"angconv",\
"trimbits",\
"extsig"
};
int nvar=20;
int nvar=40;
int iv=0;
string fname1;
ofstream outfile;
@ -2532,7 +2558,6 @@ void mythenDetector::acquire(int delflag){
//action at start
if (thisDetector->stoppedFlag==0) {
if (thisDetector->actionMask & (1 << startScript)) {
@ -2550,6 +2575,7 @@ void mythenDetector::acquire(int delflag){
if (thisDetector->stoppedFlag==0) {
currentScanVariable[0]=thisDetector->scanSteps[0][is0];
currentScanIndex[0]=is0;
switch(thisDetector->scanMode[0]) {
case 1:
@ -2579,11 +2605,12 @@ void mythenDetector::acquire(int delflag){
break;
for (int is1=0; is1<ns0; is1++) {//scan0 loop
for (int is1=0; is1<ns1; is1++) {//scan0 loop
if (thisDetector->stoppedFlag==0) {
currentScanVariable[1]=thisDetector->scanSteps[1][is1];
currentScanIndex[1]=is1;
switch(thisDetector->scanMode[1]) {
case 1:
@ -2676,7 +2703,7 @@ void mythenDetector::acquire(int delflag){
//while (!dataQueue.empty()){
while (queuesize){
usleep(100);
usleep(1000);
}
@ -2775,6 +2802,9 @@ void mythenDetector::acquire(int delflag){
if (thisDetector->threadedProcessing) {
#ifdef VERBOSE
std::cout<< " ***********************waiting for data processing thread to finish " << queuesize << std::endl ;
#endif
jointhread=1;
pthread_join(dataProcessingThread, &status);
}
@ -2796,12 +2826,18 @@ void* mythenDetector::processData(int delflag) {
int np;
detectorData *thisData;
int dum=1;
string ext;
#ifdef ACQVERBOSE
std::cout<< " processing data - threaded mode " << thisDetector->threadedProcessing;
#endif
if (thisDetector->correctionMask!=0) {
ext=".dat";
} else {
ext=".raw";
}
while(dum | thisDetector->threadedProcessing) { // ????????????????????????
@ -2811,6 +2847,14 @@ void* mythenDetector::processData(int delflag) {
/** Pop data queue */
myData=dataQueue.front(); // get the data from the queue
if (myData) {
thisDetector->progressIndex++;
#ifdef VERBOSE
cout << "Progress is " << getCurrentProgress() << " \%" << endl;
#endif
//process data
/** decode data */
fdata=decodeData(myData);
@ -2880,7 +2924,7 @@ void* mythenDetector::processData(int delflag) {
}
if (thisDetector->correctionMask!=0)
writeDataFile (createFileName().append(".dat"), ffcdata, ffcerr,ang);
writeDataFile (createFileName().append(".dat"), ffcdata, ffcerr,ang);
addToMerging(ang, ffcdata, ffcerr, mergingBins, mergingCounts,mergingErrors, mergingMultiplicity);
if ((currentPositionIndex==thisDetector->numberOfPositions) || (currentPositionIndex==0)) {
np=finalizeMerging(mergingBins, mergingCounts,mergingErrors, mergingMultiplicity);
@ -2894,11 +2938,14 @@ void* mythenDetector::processData(int delflag) {
delete [] mergingErrors;
delete [] mergingMultiplicity;
} else {
if (thisDetector->correctionMask!=0)
thisData=new detectorData(mergingCounts,mergingErrors,mergingBins,thisDetector->progressIndex+1,(createFileName().append(".dat")).c_str(),np);
else
thisData=new detectorData(mergingCounts,mergingErrors,mergingBins,thisDetector->progressIndex+1,(createFileName().append(".raw")).c_str(),np);
thisData=new detectorData(mergingCounts,mergingErrors,mergingBins,getCurrentProgress(),(createFileName().append(ext)).c_str(),np);/*
if (thisDetector->correctionMask!=0) {
//thisData=new detectorData(mergingCounts,mergingErrors,mergingBins,thisDetector->progressIndex+1,(createFileName().append(".dat")).c_str(),np);
thisData=new detectorData(mergingCounts,mergingErrors,mergingBins,getCurrentProgress(),(createFileName().append(".dat")).c_str(),np);
} else {
thisData=new detectorData(mergingCounts,mergingErrors,mergingBins,getCurrentProgress(),(createFileName().append(".raw")).c_str(),np);
//thisData=new detectorData(mergingCounts,mergingErrors,mergingBins,thisDetector->progressIndex+1,(createFileName().append(".raw")).c_str(),np);
}*/
finalDataQueue.push(thisData);
}
}
@ -2921,17 +2968,27 @@ void* mythenDetector::processData(int delflag) {
if (ang)
delete [] ang;
} else {
thisData=new detectorData(ffcdata,ffcerr,NULL,getCurrentProgress(),(createFileName().append(ext)).c_str(),thisDetector->nChans*thisDetector->nChips*thisDetector->nMods);/*
if (thisDetector->correctionMask!=0) {
thisData=new detectorData(ffcdata,ffcerr,NULL,thisDetector->progressIndex+1,(createFileName().append(".dat")).c_str(),thisDetector->nChans*thisDetector->nChips*thisDetector->nMods);
thisData=new detectorData(ffcdata,ffcerr,NULL,getCurrentProgress(),(createFileName().append(".dat")).c_str(),thisDetector->nChans*thisDetector->nChips*thisDetector->nMods);
//thisData=new detectorData(ffcdata,ffcerr,NULL,thisDetector->progressIndex+1,(createFileName().append(".dat")).c_str(),thisDetector->nChans*thisDetector->nChips*thisDetector->nMods);
} else {
thisData=new detectorData(ffcdata,ffcerr,NULL,thisDetector->progressIndex+1,(createFileName().append(".raw")).c_str(),thisDetector->nChans*thisDetector->nChips*thisDetector->nMods);
}
thisData=new detectorData(ffcdata,ffcerr,NULL,getCurrentProgress(),(createFileName().append(".raw")).c_str(),thisDetector->nChans*thisDetector->nChips*thisDetector->nMods);
//thisData=new detectorData(ffcdata,ffcerr,NULL,thisDetector->progressIndex+1,(createFileName().append(".raw")).c_str(),thisDetector->nChans*thisDetector->nChips*thisDetector->nMods);
}*/
finalDataQueue.push(thisData);
}
}
}
thisDetector->fileIndex++;
/*
thisDetector->progressIndex++;
#ifdef VERBOSE
cout << "Progress is " << getCurrentProgress() << " \%" << endl;
#endif
*/
delete [] myData;
myData=NULL;
dataQueue.pop(); //remove the data from the queue
@ -3063,3 +3120,46 @@ int64_t mythenDetector::getTimeLeft(timerIndex index){
#endif
return retval;
};
/*
set positions for the acquisition
\param nPos number of positions
\param pos array with the encoder positions
\returns number of positions
*/
int mythenDetector::setPositions(int nPos, float *pos){
if (nPos>=0)
thisDetector->numberOfPositions=nPos;
for (int ip=0; ip<nPos; ip++)
thisDetector->detPositions[ip]=pos[ip];
setTotalProgress();
return thisDetector->numberOfPositions;
}
/*
get positions for the acquisition
\param pos array which will contain the encoder positions
\returns number of positions
*/
int mythenDetector::getPositions(float *pos){
if (pos ) {
for (int ip=0; ip<thisDetector->numberOfPositions; ip++)
pos[ip]=thisDetector->detPositions[ip];
}
setTotalProgress();
return thisDetector->numberOfPositions;
};

View File

@ -239,13 +239,13 @@ enum {GET_ACTION, PUT_ACTION, READOUT_ACTION};
\param pos array with the encoder positions
\returns number of positions
*/
int setPositions(int nPos, float *pos){thisDetector->numberOfPositions=nPos; for (int ip=0; ip<nPos; ip++) thisDetector->detPositions[ip]=pos[ip]; return thisDetector->numberOfPositions;};
int setPositions(int nPos, float *pos);
/**
get positions for the acquisition
\param pos array which will contain the encoder positions
\returns number of positions
*/
int getPositions(float *pos=NULL){ if (pos ) {for (int ip=0; ip<thisDetector->numberOfPositions; ip++) pos[ip]=thisDetector->detPositions[ip];} return thisDetector->numberOfPositions;};
int getPositions(float *pos=NULL);
/** set detector bin size used for merging (approx angular resolution)*/

View File

@ -186,6 +186,11 @@ int slsDetector::initializeDetectorSize(detectorType type) {
thisDetector->nMod[Y]=thisDetector->nModMax[Y];
thisDetector->nMods=thisDetector->nModsMax;
/** calculates the expected data size */
thisDetector->timerValue[PROBES_NUMBER]=0;
thisDetector->timerValue[FRAME_NUMBER]=1;
thisDetector->timerValue[CYCLES_NUMBER]=1;
if (thisDetector->dynamicRange==24 || thisDetector->timerValue[PROBES_NUMBER]>0)
thisDetector->dataBytes=thisDetector->nMod[X]*thisDetector->nMod[Y]*thisDetector->nChips*thisDetector->nChans*4;
else
@ -200,6 +205,10 @@ int slsDetector::initializeDetectorSize(detectorType type) {
strcpy(thisDetector->fileName,"run");
/** set fileIndex to default to 0*/
thisDetector->fileIndex=0;
/** set progress Index to default to 0*/
thisDetector->progressIndex=0;
/** set total number of frames to be acquired to default to 1*/
thisDetector->totalProgress=1;
/** set number of trim energies to 0*/
thisDetector->nTrimEn=0;
@ -262,11 +271,6 @@ int slsDetector::initializeDetectorSize(detectorType type) {
/** calculates the memory offsets for flat field coefficients and errors, module structures, dacs, adcs, chips and channels */
thisDetector->ffoff=sizeof(sharedSlsDetector);
thisDetector->fferroff=thisDetector->ffoff+sizeof(float)*thisDetector->nChans*thisDetector->nChips*thisDetector->nModsMax;
@ -675,6 +679,157 @@ string slsDetector::createFileName() {
return osfn.str();
}
int slsDetector::getFileIndexFromFileName(string fname) {
int i;
size_t dot=fname.rfind(".");
if (dot==string::npos)
return -1;
size_t uscore=fname.rfind("_");
if (uscore==string::npos)
return -1;
if (sscanf( fname.substr(uscore+1,dot-uscore-1).c_str(),"%d",&i)) {
return i;
}
//#ifdef VERBOSE
cout << "******************************** cannot parse file index" << endl;
//#endif
return 0;
}
int slsDetector::getVariablesFromFileName(string fname, int &index, int &p_index, float &sv0, float &sv1) {
int i;
float f;
string s;
index=-1;
p_index=-1;
sv0=-1;
sv1=-1;
// size_t dot=fname.rfind(".");
//if (dot==string::npos)
// return -1;
size_t uscore=fname.rfind("_");
if (uscore==string::npos)
return -1;
s=fname;
//if (sscanf(s.substr(uscore+1,dot-uscore-1).c_str(),"%d",&i)) {
if (sscanf(s.substr(uscore+1,s.size()-uscore-1).c_str(),"%d",&i)) {
index=i;
#ifdef VERBOSE
cout << "******************************** file index is " << index << endl;
#endif
//return i;
s=fname.substr(0,uscore);
}
#ifdef VERBOSE
else
cout << "******************************** cannot parse file index" << endl;
cout << s << endl;
#endif
uscore=s.rfind("_");
if (sscanf( s.substr(uscore+1,s.size()-uscore-1).c_str(),"p%d",&i)) {
p_index=i;
#ifdef VERBOSE
cout << "******************************** position index is " << p_index << endl;
#endif
s=fname.substr(0,uscore);
}
#ifdef VERBOSE
else
cout << "******************************** cannot parse position index" << endl;
cout << s << endl;
#endif
uscore=s.rfind("_");
if (sscanf( s.substr(uscore+1,s.size()-uscore-1).c_str(),"s%f",&f)) {
sv1=f;
#ifdef VERBOSE
cout << "******************************** scan variable 1 is " << sv1 << endl;
#endif
s=fname.substr(0,uscore);
}
#ifdef VERBOSE
else
cout << "******************************** cannot parse scan varable 1" << endl;
cout << s << endl;
#endif
uscore=s.rfind("_");
if (sscanf( s.substr(uscore+1,s.size()-uscore-1).c_str(),"S%f",&f)) {
sv0=f;
#ifdef VERBOSE
cout << "******************************** scan variable 0 is " << sv0 << endl;
#endif
}
#ifdef VERBOSE
else
cout << "******************************** cannot parse scan varable 0" << endl;
#endif
return index;
}
/* Communication to server */
@ -2635,6 +2790,9 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t){
char mess[100];
int ret=OK;
int n=0;
#ifdef VERBOSE
std::cout<< "Setting timer "<< index << " to " << t << "ns" << std::endl;
#endif
@ -2660,19 +2818,86 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t){
//std::cout<< "offline " << std::endl;
if (t>=0)
thisDetector->timerValue[index]=t;
}
}
#ifdef VERBOSE
std::cout<< "Timer set to "<< thisDetector->timerValue[index] << "ns" << std::endl;
std::cout<< "Timer " << index << " set to "<< thisDetector->timerValue[index] << "ns" << std::endl;
#endif
if (index==PROBES_NUMBER) {
setDynamicRange();
//cout << "Changing probes: data size = " << thisDetector->dataBytes <<endl;
}
/* set progress */
if ((index==FRAME_NUMBER) || (index==CYCLES_NUMBER)) {
setTotalProgress();
}
return thisDetector->timerValue[index];
};
int slsDetector::setTotalProgress() {
int nf=1, npos=1, nscan[MAX_SCAN_LEVELS]={1,1}, nc=1;
if (thisDetector->timerValue[FRAME_NUMBER])
nf=thisDetector->timerValue[FRAME_NUMBER];
if (thisDetector->timerValue[CYCLES_NUMBER]>0)
nc=thisDetector->timerValue[CYCLES_NUMBER];
if (thisDetector->numberOfPositions>0)
npos=thisDetector->numberOfPositions;
if ((thisDetector->nScanSteps[0]>0) && (thisDetector->actionMask & (1 << MAX_ACTIONS)))
nscan[0]=thisDetector->nScanSteps[0];
if ((thisDetector->nScanSteps[1]>0) && (thisDetector->actionMask & (1 << (MAX_ACTIONS+1))))
nscan[1]=thisDetector->nScanSteps[1];
thisDetector->totalProgress=nf*nc*npos*nscan[0]*nscan[1];
#ifdef VERBOSE
cout << "nc " << nc << endl;
cout << "nf " << nf << endl;
cout << "npos " << npos << endl;
cout << "nscan[0] " << nscan[0] << endl;
cout << "nscan[1] " << nscan[1] << endl;
cout << "Set total progress " << thisDetector->totalProgress << endl;
#endif
return thisDetector->totalProgress;
}
float slsDetector::getCurrentProgress() {
return 100.*((float)thisDetector->progressIndex)/((float)thisDetector->totalProgress);
}
/*
important speed parameters
@ -3669,21 +3894,34 @@ int slsDetector::setScan(int iscan, string script, int nvalues, float *values, s
}
}
if (values) {
if (values && thisDetector->scanMode[iscan]>0 ) {
for (int iv=0; iv<thisDetector->nScanSteps[iscan]; iv++) {
thisDetector->scanSteps[iscan][iv]=values[iv];
}
}
if (precision>=0)
thisDetector->scanPrecision[iscan]=precision;
if (thisDetector->scanMode[iscan]>0){
thisDetector->actionMask |= 1 >> (iscan+MAX_ACTIONS);
thisDetector->actionMask |= 1<< (iscan+MAX_ACTIONS);
} else {
thisDetector->actionMask &= ~(1 >> (iscan+MAX_ACTIONS));
thisDetector->actionMask &= ~(1 << (iscan+MAX_ACTIONS));
}
setTotalProgress();
return thisDetector->scanMode[iscan];
} else
return -1;
@ -3715,7 +3953,28 @@ int slsDetector::setScanScript(int iscan, string script) {
thisDetector->actionMask &= ~(1 << (iscan+MAX_ACTIONS));
}
setTotalProgress();
#ifdef VERBOSE
cout << "Action mask is " << hex << thisDetector->actionMask << dec << endl;
#endif
return thisDetector->scanMode[iscan];
@ -3775,6 +4034,13 @@ int slsDetector::setScanSteps(int iscan, int nvalues, float *values) {
thisDetector->actionMask &= ~(1 << (iscan+MAX_ACTIONS));
}
#ifdef VERBOSE
cout << "Action mask is " << hex << thisDetector->actionMask << dec << endl;
#endif
setTotalProgress();
return thisDetector->scanMode[iscan];
@ -3795,9 +4061,12 @@ int slsDetector::setScanSteps(int iscan, int nvalues, float *values) {
\returns scan script
*/
string slsDetector::getScanScript(int iscan){
if (iscan>=0 && iscan<MAX_SCAN_LEVELS)
return string(thisDetector->scanScript[iscan]);
else
if (iscan>=0 && iscan<MAX_SCAN_LEVELS) {
if (thisDetector->scanMode[iscan])
return string(thisDetector->scanScript[iscan]);
else
return string("none");
} else
return string("wrong index");
};
@ -3808,9 +4077,12 @@ string slsDetector::getScanScript(int iscan){
\returns scan parameter
*/
string slsDetector::getScanParameter(int iscan){
if (iscan>=0 && iscan<MAX_SCAN_LEVELS)
if (iscan>=0 && iscan<MAX_SCAN_LEVELS) {
if (thisDetector->scanMode[iscan])
return string(thisDetector->scanParameter[iscan]);
else
return string("none");
} else
return string("wrong index");
}
@ -3843,7 +4115,27 @@ int slsDetector::getScanSteps(int iscan, float *v) {
}
}
return thisDetector->nScanSteps[iscan];
setTotalProgress();
if (thisDetector->scanMode[iscan])
return thisDetector->nScanSteps[iscan];
else
return 0;
} else
return -1;
}

View File

@ -172,6 +172,8 @@ typedef struct sharedSlsDetector {
/** indicator for the acquisition progress - set to 0 at the beginning of the acquisition and incremented every time that the data are written to file */
int progressIndex;
/** total number of frames to be acquired */
int totalProgress;
/** current index of the output file */
int fileIndex;
/** path of the output files */
@ -1472,8 +1474,21 @@ s
virtual void acquire(int delflag=1)=0;
/** calcualtes the total number of steps of the acquisition.
called when number of frames, number of cycles, number of positions and scan steps change
*/
int setTotalProgress();
/** returns the current progress in % */
float getCurrentProgress();
protected:
int getFileIndexFromFileName(string fname);
int getVariablesFromFileName(string fname, int &index, int &p_index, float &sv0, float &sv1);
static const int64_t thisSoftwareVersion=0x20110113;
/**