almost compiling on 64bit...

git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@297 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
bergamaschi
2012-10-16 14:50:05 +00:00
parent 0c89b0986f
commit 6fb6f72bc3
18 changed files with 408 additions and 179 deletions

View File

@ -4,6 +4,7 @@
#include <fstream>
#include <sstream>
#include <math.h>
#include <cstring>
using namespace std;

View File

@ -69,31 +69,18 @@ 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 angularConversionStatic::convertAngle(double pos, int ich, angleConversionConstant *p, int mF, double fo, double go, int angdir) {
double enc=0, trans=0;
angleConversionConstant *p=NULL;
int ch0=0;
int chlast=chansPerMod[0]-1;
int nchmod=chansPerMod[0];
double ang;
while (ich>chlast) {
imod++;
ch0=chlast+1;
nchmod=chansPerMod[imod];
chlast=ch0+nchmod-1;
}
p=angOff[imod];
switch (mF[imod]) {
switch (mF) {
case 0:
enc=0;
trans=0;
@ -118,11 +105,9 @@ double angularConversionStatic::convertAngle(double pos, int ich, int *chansPerM
enc=0;
trans=0;
}
if (p)
ang=angle(ich-ch0, \
ang=angle(ich, \
enc, \
fo+go, \
p->r_conversion, \
@ -133,6 +118,47 @@ double angularConversionStatic::convertAngle(double pos, int ich, int *chansPerM
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];
ang=convertAngle(pos, ich-ch0, p, mF[imod], fo, go, angdir);
return ang;
}
@ -162,12 +188,13 @@ int angularConversionStatic::readAngularConversion(string fname, int nmod, angle
int angularConversionStatic::readAngularConversion( ifstream& infile, int nmod, angleConversionConstant *angOff) {
string str;
int mod;
double center, ecenter;
double center, ecenter, pitch, epitch;
double r_conv, er_conv;
double off, eoff;
string ss;
int interrupt=0;
int nm=0;
int newangconv=0;
//" module %i center %E +- %E conversion %E +- %E offset %f +- %f \n"
while (infile.good() and interrupt==0) {
getline(infile,str);
@ -178,18 +205,31 @@ int angularConversionStatic::readAngularConversion( ifstream& infile, int nmod,
istringstream ssstr(str);
ssstr >> ss >> mod;
ssstr >> ss >> center;
if (ss==string("center"))
newangconv=1;
ssstr >> ss >> ecenter;
if (newangconv) {
ssstr >> ss >> pitch;
ssstr >> ss >> epitch;
}
ssstr >> ss >> r_conv;
ssstr >> ss >> er_conv;
ssstr >> ss >> off;
ssstr >> ss >> eoff;
if (nm<nmod && nm>=0 ) {
angOff[nm].center=center;
angOff[nm].r_conversion=r_conv;
angOff[nm].offset=off;
angOff[nm].ecenter=ecenter;
angOff[nm].er_conversion=er_conv;
angOff[nm].eoffset=eoff;
if (newangconv==0) {
angOff[nm].center=center;
angOff[nm].r_conversion=r_conv;
angOff[nm].offset=off;
angOff[nm].ecenter=ecenter;
angOff[nm].er_conversion=er_conv;
angOff[nm].eoffset=eoff;
} else {
angOff[nm].tilt=pitch;
angOff[nm].etilt=epitch;
}
} else
break;
//cout << nm<<" " << angOff[nm].offset << endl;

View File

@ -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;

View File

@ -161,6 +161,9 @@ class angularConversionStatic
double convertAngle(double pos, int ich, int *chansPerMod, angleConversionConstant **angOff, int *mF, double fo, double go, int angdir);
double convertAngle(double pos, int ich, angleConversionConstant *angOff, int mF, double fo, double go, int angdir);
protected:

View File

@ -116,7 +116,26 @@ class angularConversionStatic
\returns OK or FAIL
*/
static int addToMerging(double *p1, double *v1, double *e1, double *mp, double *mv,double *me, int *mm, int nchans, double binsize,int nb, int *badChanMask );
static int addToMerging(double *p1, double *v1, double *e1, double *mp, double *mv,double *me, int *mm, int nchans, double binsize,int nb, int *badChanMask=NULL);
/**
merge dataset
\param p1 angular positions of dataset
\param v1 data
\param e1 errors
\param mp already merged postions
\param mv already merged data
\param me already merged errors (squared sum)
\param mm multiplicity of merged arrays
\param nchans number of channels
\param binsize size of angular bin
\param nb number of angular bins
\param badChanMask badchannelmask (if NULL does not correct for bad channels)
\returns OK or FAIL
*/
static int addPointToMerging(double p1, double v1, double e1, double *mp, double *mv,double *me, int *mm, double binsize, int nb);
/**
@ -139,6 +158,8 @@ class angularConversionStatic
double* convertAngles(double pos, int nch, int *chansPerMod, angleConversionConstant **angOff, int *mF, double fo, double go, int angdir);
double convertAngle(double pos, int ich, int *chansPerMod, angleConversionConstant **angOff, int *mF, double fo, double go, int angdir);
protected:

View File

@ -3,26 +3,30 @@
#include "angleConversionConstant.h"
#ifdef VERBOSE
#include "usersFunctions.h"
#elif EXTPP
#include "usersFunctions.h"
#endif
postProcessing::postProcessing(): expTime(NULL), ang(NULL), val(NULL), err(NULL){
postProcessing::postProcessing(): expTime(NULL), ang(NULL), val(NULL), err(NULL), numberOfChannels(0){
pthread_mutex_t mp1 = PTHREAD_MUTEX_INITIALIZER;
mp=mp1;
pthread_mutex_init(&mp, NULL);
mg=mp1;
pthread_mutex_init(&mg, NULL);
// mg=mp1;
// pthread_mutex_init(&mg, NULL);
//cout << "reg callback "<< endl;
dataReady = 0;
pCallbackArg = 0;
#ifdef VERBOSE
registerDataCallback(&defaultDataReadyFunc, NULL);
#endif
//cout << "done "<< endl;
rawDataReady = 0;
pRawDataArg = 0;
#ifdef VERBOSE
registerDataCallback(&defaultDataReadyFunc, NULL);
#endif
#ifdef EXTPP
registerRawDataCallback(&defaultRawDataReadyFunc, NULL);
#endif
ppFun=new postProcessingFuncs();
}
@ -30,7 +34,9 @@ postProcessing::postProcessing(): expTime(NULL), ang(NULL), val(NULL), err(NULL)
postProcessing::~postProcessing(){delete ppFun;};
postProcessing::~postProcessing(){
delete ppFun;
};
@ -62,50 +68,60 @@ void postProcessing::processFrame(int *myData, int delflag) {
cout << "decode"<< endl;
#endif
if (rawDataReady) {
//#ifdef VERBOSE
cout << "raw data ready..." << endl;
//#endif
rawDataReady(fdata,numberOfChannels, pRawDataArg);
//#ifdef VERBOSE
cout << "done" << endl;
cout << "NO FILE WRITING AND/OR DATA PROCESSING DONE BY SLS DETECTOR SOFTWARE!!!" << endl;
//#endif
} else {
pthread_mutex_lock(&mp);
fname=createFileName();
pthread_mutex_unlock(&mp);
pthread_mutex_lock(&mp);
fname=createFileName();
pthread_mutex_unlock(&mp);
#ifdef VERBOSE
cout << "fname is " << fname << endl;
cout << "fname is " << fname << endl;
#endif
//Checking for write flag
if((*correctionMask)&(1<<WRITE_FILE)) {
//Checking for write flag
if((*correctionMask)&(1<<WRITE_FILE)) {
#ifdef VERBOSE
cout << "writing raw data " << endl;
cout << "writing raw data " << endl;
#endif
//uses static function?!?!?!?
writeDataFile (fname+string(".raw"),fdata, NULL, NULL, 'i');
writeDataFile (fname+string(".raw"),fdata, NULL, NULL, 'i');
#ifdef VERBOSE
cout << "done " << endl;
#endif
}
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);
} else
if (dataReady) {
thisData=new detectorData(fdata,NULL,NULL,getCurrentProgress(),(fname+string(".raw")).c_str(),getTotalNumberOfChannels());
dataReady(thisData, pCallbackArg);
delete thisData;
fdata=NULL;
}
cout << "done " << endl;
#endif
}
if ((*correctionMask) & ~(1<<WRITE_FILE)) {
doProcessing(fdata,delflag, fname);
} else
if (dataReady) {
thisData=new detectorData(fdata,NULL,NULL,getCurrentProgress(),(fname+string(".raw")).c_str(),getTotalNumberOfChannels());
dataReady(thisData, pCallbackArg);
delete thisData;
fdata=NULL;
}
#ifdef VERBOSE
cout << "findex incremented " << endl;
#endif
if(*correctionMask&(1<<WRITE_FILE))
IncrementFileIndex();
}
delete [] myData;
if (fdata)
delete [] fdata;
@ -116,20 +132,15 @@ void postProcessing::processFrame(int *myData, int delflag) {
cout << "Pop data queue " << *fileIndex << endl;
#endif
if(*correctionMask&(1<<WRITE_FILE))
IncrementFileIndex();
#ifdef VERBOSE
cout << "findex incremented " << endl;
#endif
popDataQueue(); //remove the data from the queue
#ifdef VERBOSE
cout << "Pop data queue " << *fileIndex << endl;
cout << "Data queue popped" << endl;
#endif
#ifdef VERBOSE
cout << "processing returning " << *fileIndex << endl;
cout << "process frame returning " << endl;
#endif
@ -144,13 +155,7 @@ void postProcessing::doProcessing(double *lfdata, int delflag, string fname) {
cout << "do processing - data size is " << arraySize << endl;
#endif
if (*correctionMask&(1<< ANGULAR_CONVERSION))
ang=new double[arraySize];
else
ang=NULL;
val=new double[arraySize];
err=new double[arraySize];
int np;
#ifdef VERBOSE
@ -177,36 +182,44 @@ void postProcessing::doProcessing(double *lfdata, int delflag, string fname) {
if (GetCurrentPositionIndex()<=1) {
#ifdef VERBOSE
cout << "init dataset" << endl;
#endif
ppFun->initDataset();
}
#endif
if (*correctionMask&(1<< ANGULAR_CONVERSION))
ang=new double[arraySize];
else
ang=NULL;
val=new double[arraySize];
err=new double[arraySize];
initDataset(0);
}
#ifdef VERBOSE
cout << "add frame" << endl;
#endif
ppFun->addFrame(lfdata, &currentPosition, &currentI0, &t, (fname).c_str(), NULL);
addFrame(lfdata,currentPosition, currentI0, t, fname, 0);
if ((GetCurrentPositionIndex()>=npos && positionFinished() && dataQueueSize()) || npos==0) {
if ((GetCurrentPositionIndex()>=npos && positionFinished() && dataQueueSize()) || npos==0) {
#ifdef VERBOSE
cout << "finalize dataset" << endl;
cout << "finalize dataset" << endl;
#endif
ppFun->finalizeDataset(ang, val, err, &np);
finalizeDataset(ang, val, err, np);
IncrementPositionIndex();
pthread_mutex_lock(&mp);
fname=createFileName();
pthread_mutex_unlock(&mp);
if((*correctionMask)&(1<<WRITE_FILE)) {
//cout << "write to file " << fname+ext << " " << np << " " << ang<< " " << val << " " << err << endl;
writeDataFile (fname+ext,np,val, err,ang,'f');
}
if (dataReady) {
thisData=new detectorData(val,err,ang,getCurrentProgress(),(fname+ext).c_str(),np);
dataReady(thisData, pCallbackArg);
@ -215,6 +228,7 @@ void postProcessing::doProcessing(double *lfdata, int delflag, string fname) {
val=NULL;
err=NULL;
}
if (ang)
delete [] ang;
if (val)
@ -222,7 +236,11 @@ void postProcessing::doProcessing(double *lfdata, int delflag, string fname) {
if (err)
delete [] err;
}
}
}
@ -414,16 +432,16 @@ int* postProcessing::popDataQueue() {
return retval;
}
detectorData* postProcessing::popFinalDataQueue() {
detectorData *retval=NULL;
pthread_mutex_unlock(&mg);
if( !finalDataQueue.empty() ) {
retval=finalDataQueue.front();
finalDataQueue.pop();
}
pthread_mutex_unlock(&mg);
return retval;
}
// detectorData* postProcessing::popFinalDataQueue() {
// detectorData *retval=NULL;
// pthread_mutex_unlock(&mg);
// if( !finalDataQueue.empty() ) {
// retval=finalDataQueue.front();
// finalDataQueue.pop();
// }
// pthread_mutex_unlock(&mg);
// return retval;
// }
void postProcessing::resetDataQueue() {
int *retval=NULL;
@ -437,30 +455,24 @@ void postProcessing::resetDataQueue() {
}
void postProcessing::resetFinalDataQueue() {
detectorData *retval=NULL;
pthread_mutex_lock(&mg);
while( !finalDataQueue.empty() ) {
retval=finalDataQueue.front();
finalDataQueue.pop();
delete retval;
}
pthread_mutex_unlock(&mg);
}
// void postProcessing::resetFinalDataQueue() {
// detectorData *retval=NULL;
// pthread_mutex_lock(&mg);
// while( !finalDataQueue.empty() ) {
// retval=finalDataQueue.front();
// finalDataQueue.pop();
// delete retval;
// }
// pthread_mutex_unlock(&mg);
// }
void postProcessing::initDataset(int r) {
void postProcessing::startThread(int delflag) {
/////////////////////////////////// Initialize dataset
//resetDataQueue();
setTotalProgress();
int nmod=getNMods();
int *chPM=new int[nmod];
int *mM=new int[nmod];
int totch=0;
if (r) {
int nmod=getNMods();
int *chPM=new int[nmod];
int *mM=new int[nmod];
int totch=0;
#ifdef VERBOSE
cout << "init dataset stuff" << endl;
#endif
@ -484,14 +496,14 @@ void postProcessing::startThread(int delflag) {
cout << "total channels is " << totch << endl;
#endif
double *ffcoeff=NULL, *fferr=NULL;
if (*correctionMask&(1<<FLAT_FIELD_CORRECTION)) {
#ifdef VERBOSE
cout << "get ff " << endl;
cout << "get ff " << endl;
#endif
ffcoeff=new double[totch];
fferr=new double[totch];
getFlatFieldCorrection(ffcoeff,fferr);
}
@ -554,16 +566,69 @@ void postProcessing::startThread(int delflag) {
arraySize=totch;
}
numberOfChannels=totch;
queuesize=dataQueueSize();
resetFinalDataQueue();
// resetFinalDataQueue();
resetDataQueue();
} else {
ppFun->initDataset();
}
}
void postProcessing::addFrame(double *data, double pos, double i0, double t, string fname, double var) {
ppFun->addFrame(data, &pos, &i0, &t, fname.c_str(), &var);
}
void postProcessing::finalizeDataset(double *a, double *v, double *e, int &np) {
ppFun->finalizeDataset(a, v, e, &np);
}
void postProcessing::startThread(int delflag) {
/////////////////////////////////// Initialize dataset
//resetDataQueue();
setTotalProgress();
initDataset(1);
/////////////////////////////////// Start thread ////////////////////////////////////////////////////////
#ifdef VERBOSE
cout << "start thread stuff" << endl;
#endif
pthread_attr_t tattr;
int ret;
sched_param param, mparam;

View File

@ -184,12 +184,12 @@ s
int dataQueueSize();
/**
pops the data from thepostprocessed data queue
\returns pointer to the popped data or NULL if the queue is empty.
\sa finalDataQueue
*/
detectorData* popFinalDataQueue();
/* /\** */
/* pops the data from thepostprocessed data queue */
/* \returns pointer to the popped data or NULL if the queue is empty. */
/* \sa finalDataQueue */
/* *\/ */
/* detectorData* popFinalDataQueue(); */
int checkJoinThread();
@ -202,11 +202,11 @@ s
*/
void resetDataQueue();
/**
resets the postprocessed data queue
\sa finalDataQueue
*/
void resetFinalDataQueue();
/* /\** */
/* resets the postprocessed data queue */
/* \sa finalDataQueue */
/* *\/ */
/* void resetFinalDataQueue(); */
@ -238,7 +238,7 @@ s
void registerDataCallback(int( *userCallback)(detectorData*, void*), void *pArg) {dataReady = userCallback; pCallbackArg = pArg;};
void registerRawDataCallback(int( *userCallback)(double*, void*), void *pArg) {rawDataReady = userCallback; pRawDataArg = pArg;};
void registerRawDataCallback(int( *userCallback)(double*, int, void*), void *pArg) {rawDataReady = userCallback; pRawDataArg = pArg;};
@ -251,6 +251,15 @@ s
int setCurrentPosition(double v) { pthread_mutex_lock(&mp); currentPosition=v; pthread_mutex_unlock(&mp); return currentPosition;};
void initDataset(int refresh);
void addFrame(double *data, double pos, double i0, double t, string fname, double var);
void finalizeDataset(double *a, double *v, double *e, int &np);
protected:
int *threadedProcessing;
@ -322,7 +331,7 @@ s
int (*dataReady)(detectorData*,void*);
void *pCallbackArg;
int (*rawDataReady)(double*,void*);
int (*rawDataReady)(double*,int,void*);
void *pRawDataArg;
@ -334,6 +343,7 @@ s
double *val;
double *err;
int numberOfChannels;

View File

@ -70,18 +70,30 @@ int postProcessingFuncs::finalizeDataset(double *ang, double *val, double *err,
}
int postProcessingFuncs::addFrame(double *data, double *pos, double *I0, double *expTime, const char *filename, int *var) {
int postProcessingFuncs::addFrame(double *data, double *pos, double *I0, double *expTime, const char *filename, double *var) {
double p1, vin, ein, vout, eout;
double e=0.;
double i0=*I0;
int imod=0, ch0=0;
int chlast=chansPerMod[0]-1;
int nchmod=chansPerMod[0];
if (i0>0)
totalI0+=i0;
for (int ich=0; ich<totalChans; ich++) {
if (ich>chlast) {
imod++;
ch0=chlast+1;
nchmod=chansPerMod[imod];
chlast=ch0+nchmod-1;
}
vin=data[ich];
ein=0;
vout=data[ich];
@ -138,12 +150,14 @@ int postProcessingFuncs::addFrame(double *data, double *pos, double *I0, double
//check module mask?!?!?!?
p1=convertAngle(*pos,ich,chansPerMod,angConv,moduleMask,totalOffset,0,angDir);
p1=convertAngle(*pos,ich-ch0,angConv[imod],moduleMask[imod],totalOffset,0,angDir);
#ifdef VERBOSE
cout << "ppFuncs merge" << endl;
#endif
addPointToMerging(p1,vout,eout,mp,mv,me,mm, binSize, nBins);
} else {
#ifdef VERBOSE
cout << "ppFuncs merge" << endl;

View File

@ -38,7 +38,7 @@ class postProcessingFuncs : public virtual angularConversionStatic
int finalizeDataset(double ang[], double val[], double err[], int *np);
int addFrame(double data[], double *pos, double *IO, double *expTime, const char *filename, int *var=0);
int addFrame(double data[], double *pos, double *IO, double *expTime, const char *filename, double *var=0);
static int calculateFlatField(int* nModules, int *chPerMod, int moduleMask[], int badChannelMask[], double ffData[], double ffCoeff[], double ffErr[]);