mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-23 06:50:02 +02:00
dataReady called
git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@288 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
parent
7f8f89f89d
commit
b75b09cc7b
@ -238,6 +238,9 @@ multiSlsDetector::multiSlsDetector(int id) : slsDetectorUtils(), shmId(-1)
|
||||
flatFieldFile=thisMultiDetector->flatFieldFile;
|
||||
badChanFile=thisMultiDetector->badChanFile;
|
||||
timerValue=thisMultiDetector->timerValue;
|
||||
|
||||
expTime=&timerValue[ACQUISITION_TIME];
|
||||
|
||||
currentSettings=&thisMultiDetector->currentSettings;
|
||||
currentThresholdEV=&thisMultiDetector->currentThresholdEV;
|
||||
filePath=thisMultiDetector->filePath;
|
||||
@ -1675,8 +1678,9 @@ int multiSlsDetector::setFlatFieldCorrection(string fname){
|
||||
chpm[im]=getChansPerMod(im);
|
||||
mMask[im]=im;
|
||||
}
|
||||
|
||||
if ((postProcessingFuncs::calculateFlatField(&nm, chpm, mMask, badChannelMask, data, ffcoefficients, fferrors))) {
|
||||
fillModuleMask(mMask);
|
||||
|
||||
if ((postProcessingFuncs::calculateFlatField(&nm, chpm, mMask, badChannelMask, data, ffcoefficients, fferrors))>=0) {
|
||||
strcpy(thisMultiDetector->flatFieldFile,fname.c_str());
|
||||
|
||||
|
||||
@ -1684,7 +1688,8 @@ int multiSlsDetector::setFlatFieldCorrection(string fname){
|
||||
|
||||
setFlatFieldCorrection(ffcoefficients, fferrors);
|
||||
|
||||
}
|
||||
} else
|
||||
std::cout<< "Calculated flat field from file " << fname << " is not valid " << nch << std::endl;
|
||||
} else {
|
||||
std::cout<< "Flat field from file " << fname << " is not valid " << nch << std::endl;
|
||||
}
|
||||
@ -1693,6 +1698,25 @@ int multiSlsDetector::setFlatFieldCorrection(string fname){
|
||||
return thisMultiDetector->correctionMask&(1<<FLAT_FIELD_CORRECTION);
|
||||
}
|
||||
|
||||
int multiSlsDetector::fillModuleMask(int *mM) {
|
||||
int imod=0, off=0;
|
||||
if (mM) {
|
||||
for (int i=0; i<thisMultiDetector->numberOfDetectors; i++) {
|
||||
if (detectors[i]) {
|
||||
for (int im=0; im<detectors[i]->getNMods(); im++) {
|
||||
mM[imod]=im+off;
|
||||
imod++;
|
||||
}
|
||||
off+=detectors[i]->getMaxMods();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
return getNMods();
|
||||
}
|
||||
|
||||
|
||||
|
||||
int multiSlsDetector::setFlatFieldCorrection(double *corr, double *ecorr) {
|
||||
int ichdet=0;
|
||||
|
@ -1079,7 +1079,7 @@ class multiSlsDetector : public slsDetectorUtils {
|
||||
string getReceiverLastClientIP();
|
||||
|
||||
|
||||
|
||||
int fillModuleMask(int *mM);
|
||||
protected:
|
||||
|
||||
|
||||
|
@ -657,6 +657,8 @@ int slsDetector::initializeDetectorSize(detectorType type) {
|
||||
flatFieldFile=thisDetector->flatFieldFile;
|
||||
badChanFile=thisDetector->badChanFile;
|
||||
timerValue=thisDetector->timerValue;
|
||||
expTime=&timerValue[ACQUISITION_TIME];
|
||||
|
||||
currentSettings=&thisDetector->currentSettings;
|
||||
currentThresholdEV=&thisDetector->currentThresholdEV;
|
||||
filePath=thisDetector->filePath;
|
||||
@ -4087,8 +4089,9 @@ int slsDetector::setFlatFieldCorrection(string fname)
|
||||
chpm[im]=getChansPerMod(im);
|
||||
mMask[im]=im;
|
||||
}
|
||||
fillModuleMask(mMask);
|
||||
|
||||
if ((postProcessingFuncs::calculateFlatField(&nm, chpm, mMask, badChannelMask, data, ffcoefficients, fferrors))) {
|
||||
if ((postProcessingFuncs::calculateFlatField(&nm, chpm, mMask, badChannelMask, data, ffcoefficients, fferrors))>=0) {
|
||||
strcpy(thisDetector->flatFieldFile,fname.c_str());
|
||||
|
||||
|
||||
@ -4107,7 +4110,13 @@ int slsDetector::setFlatFieldCorrection(string fname)
|
||||
|
||||
}
|
||||
|
||||
|
||||
int slsDetector::fillModuleMask(int *mM){
|
||||
if (mM)
|
||||
for (int i=0; i<getNMods(); i++)
|
||||
mM[i]=i;
|
||||
|
||||
return getNMods();
|
||||
}
|
||||
|
||||
|
||||
int slsDetector::setFlatFieldCorrection(double *corr, double *ecorr) {
|
||||
|
@ -1452,8 +1452,7 @@ typedef struct sharedSlsDetector {
|
||||
/returns OK
|
||||
*/
|
||||
int updateReceiver();
|
||||
|
||||
|
||||
int fillModuleMask(int *mM);
|
||||
protected:
|
||||
|
||||
|
||||
|
@ -33,7 +33,6 @@ slsDetectorUtils::slsDetectorUtils() {
|
||||
cout << "done " << endl;
|
||||
#endif
|
||||
|
||||
expTime=timerValue+ACQUISITION_TIME;
|
||||
};
|
||||
|
||||
|
||||
@ -62,7 +61,7 @@ void slsDetectorUtils::acquire(int delflag){
|
||||
|
||||
|
||||
|
||||
if ((*correctionMask&(1<< ANGULAR_CONVERSION)) || (*correctionMask&(1<< I0_NORMALIZATION)) || getActionMode(angCalLog) || (getScanMode(0)==positionScan)|| (getScanMode(0)==positionScan)) {
|
||||
if ((*correctionMask&(1<< ANGULAR_CONVERSION)) || (*correctionMask&(1<< I0_NORMALIZATION)) || getActionMode(angCalLog) || (getScanMode(0)==positionScan)|| (getScanMode(1)==positionScan)) {
|
||||
if (connectChannels==0)
|
||||
if (connect_channels) {
|
||||
connect_channels(CCarg);
|
||||
@ -176,8 +175,10 @@ void slsDetectorUtils::acquire(int delflag){
|
||||
} else
|
||||
break;
|
||||
|
||||
|
||||
|
||||
pthread_mutex_lock(&mp);
|
||||
createFileName();
|
||||
pthread_mutex_unlock(&mp);
|
||||
|
||||
if (*stoppedFlag==0) {
|
||||
executeAction(scriptBefore);
|
||||
|
@ -108,7 +108,7 @@ class fileIO : public fileIOStatic, public virtual slsDetectorBase {
|
||||
\returns OK or FAIL if it could not write the file or data=NULL
|
||||
|
||||
*/
|
||||
int writeDataFile(ofstream &outfile, double *data, double *err=NULL, double *ang=NULL, char dataformat='f', int nch=-1, int offset=0);
|
||||
virtual int writeDataFile(ofstream &outfile, double *data, double *err=NULL, double *ang=NULL, char dataformat='f', int nch=-1, int offset=0);
|
||||
|
||||
|
||||
/**
|
||||
@ -126,7 +126,7 @@ class fileIO : public fileIOStatic, public virtual slsDetectorBase {
|
||||
\param offset start channel number
|
||||
\returns OK or FAIL if it could not write the file or data=NULL
|
||||
*/
|
||||
int writeDataFile(ofstream &outfile, int *data, int offset=0);
|
||||
virtual int writeDataFile(ofstream &outfile, int *data, int offset=0);
|
||||
|
||||
|
||||
|
||||
@ -145,7 +145,7 @@ class fileIO : public fileIOStatic, public virtual slsDetectorBase {
|
||||
\param offset start channel number
|
||||
\returns OK or FAIL if it could not write the file or data=NULL
|
||||
*/
|
||||
int writeDataFile(ofstream &outfile, short int *data, int offset=0);
|
||||
virtual int writeDataFile(ofstream &outfile, short int *data, int offset=0);
|
||||
|
||||
|
||||
/**
|
||||
@ -208,7 +208,7 @@ class fileIO : public fileIOStatic, public virtual slsDetectorBase {
|
||||
protected:
|
||||
|
||||
|
||||
void incrementFileIndex() { (*fileIndex)++;};
|
||||
void incrementFileIndex() { (*fileIndex)++; };
|
||||
|
||||
string getCurrentFileName(){return currentFileName;};
|
||||
|
||||
|
@ -142,7 +142,10 @@ class fileIOStatic {
|
||||
|
||||
static int writeDataFile(string fname, int nch, double *data, double *err=NULL, double *ang=NULL, char dataformat='f'){ \
|
||||
ofstream outfile; \
|
||||
if (data==NULL) return slsDetectorDefs::FAIL; \
|
||||
if (data==NULL) { \
|
||||
cout << "No data to write!" << endl; \
|
||||
return slsDetectorDefs::FAIL; \
|
||||
} \
|
||||
outfile.open (fname.c_str(),ios_base::out); \
|
||||
if (outfile.is_open()) { \
|
||||
writeDataFile(outfile, nch, data, err, ang, dataformat, 0); \
|
||||
@ -167,8 +170,10 @@ class fileIOStatic {
|
||||
*/
|
||||
static int writeDataFile(ofstream &outfile, int nch, double *data, double *err=NULL, double *ang=NULL, char dataformat='f', int offset=0){ \
|
||||
int idata; \
|
||||
if (data==NULL) \
|
||||
if (data==NULL) { \
|
||||
cout << "No data to write!" << endl; \
|
||||
return slsDetectorDefs::FAIL; \
|
||||
} \
|
||||
for (int ichan=0; ichan<nch; ichan++) { \
|
||||
if (ang==NULL) { \
|
||||
outfile << ichan+offset << " "; \
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
|
||||
|
||||
postProcessing::postProcessing(): expTime(NULL){
|
||||
postProcessing::postProcessing(): expTime(NULL), ang(NULL), val(NULL), err(NULL){
|
||||
pthread_mutex_t mp1 = PTHREAD_MUTEX_INITIALIZER;
|
||||
mp=mp1;
|
||||
pthread_mutex_init(&mp, NULL);
|
||||
@ -45,37 +45,39 @@ void postProcessing::processFrame(int *myData, int delflag) {
|
||||
// double *fdata=NULL;
|
||||
|
||||
#ifdef VERBOSE
|
||||
cout << "start processing"<< endl;
|
||||
cout << "start processing"<< endl;
|
||||
#endif
|
||||
|
||||
|
||||
incrementProgress();
|
||||
|
||||
|
||||
#ifdef VERBOSE
|
||||
cout << "prog incremented"<< endl;
|
||||
cout << "prog incremented"<< endl;
|
||||
#endif
|
||||
|
||||
/** decode data */
|
||||
|
||||
fdata=decodeData(myData, fdata);
|
||||
|
||||
fdata=decodeData(myData, fdata);
|
||||
|
||||
#ifdef VERBOSE
|
||||
cout << "decode"<< endl;
|
||||
cout << "decode"<< endl;
|
||||
#endif
|
||||
|
||||
|
||||
fname=createFileName();
|
||||
#ifdef VERBOSE
|
||||
|
||||
pthread_mutex_lock(&mp);
|
||||
fname=createFileName();
|
||||
pthread_mutex_unlock(&mp);
|
||||
#ifdef VERBOSE
|
||||
cout << "fname is " << fname << endl;
|
||||
#endif
|
||||
|
||||
//Checking for write flag
|
||||
if(*correctionMask&(1<<WRITE_FILE)) {
|
||||
if((*correctionMask)&(1<<WRITE_FILE)) {
|
||||
|
||||
#ifdef VERBOSE
|
||||
cout << "writing raw data " << endl;
|
||||
|
||||
#endif
|
||||
//uses static function?!?!?!?
|
||||
//uses static function?!?!?!?
|
||||
writeDataFile (fname+string(".raw"),fdata, NULL, NULL, 'i');
|
||||
|
||||
#ifdef VERBOSE
|
||||
@ -92,15 +94,24 @@ void postProcessing::processFrame(int *myData, int delflag) {
|
||||
cout << "done" << endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (*correctionMask & ~(1<<WRITE_FILE))
|
||||
|
||||
if ((*correctionMask) & ~(1<<WRITE_FILE)) {
|
||||
doProcessing(fdata,delflag, fname);
|
||||
} else
|
||||
if (dataReady) {
|
||||
thisData=new detectorData(NULL,fdata,NULL,getCurrentProgress(),(fname+string(".raw")).c_str(),getTotalNumberOfChannels());
|
||||
dataReady(thisData, pCallbackArg);
|
||||
delete thisData;
|
||||
fdata=NULL;
|
||||
}
|
||||
|
||||
|
||||
delete [] myData;
|
||||
delete [] fdata;
|
||||
if (fdata)
|
||||
delete [] fdata;
|
||||
myData=NULL;
|
||||
fdata=NULL;
|
||||
|
||||
|
||||
#ifdef VERBOSE
|
||||
cout << "Pop data queue " << *fileIndex << endl;
|
||||
#endif
|
||||
@ -113,7 +124,7 @@ void postProcessing::processFrame(int *myData, int delflag) {
|
||||
#endif
|
||||
popDataQueue(); //remove the data from the queue
|
||||
#ifdef VERBOSE
|
||||
cout << "Pop data queue " << *fileIndex << endl;
|
||||
cout << "Pop data queue " << *fileIndex << endl;
|
||||
#endif
|
||||
|
||||
|
||||
@ -133,12 +144,14 @@ 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;
|
||||
|
||||
double *ang=new double[arraySize];
|
||||
double *val=new double[arraySize];
|
||||
double *err=new double[arraySize];
|
||||
val=new double[arraySize];
|
||||
err=new double[arraySize];
|
||||
int np;
|
||||
detectorData *thisData;
|
||||
|
||||
#ifdef VERBOSE
|
||||
cout << "arrays allocated " << endl;
|
||||
@ -153,10 +166,10 @@ void postProcessing::doProcessing(double *lfdata, int delflag, string fname) {
|
||||
|
||||
double t=0;
|
||||
|
||||
// if (expTime)
|
||||
// t=(*expTime)*1E-9;
|
||||
//else
|
||||
// cout << "no pointer to exptime" << endl;
|
||||
if (expTime)
|
||||
t=(*expTime)*1E-9;
|
||||
else
|
||||
cout << "no pointer to exptime" << endl;
|
||||
#ifdef VERBOSE
|
||||
cout << "exptime is "<< t << endl;
|
||||
#endif
|
||||
@ -172,7 +185,7 @@ void postProcessing::doProcessing(double *lfdata, int delflag, string fname) {
|
||||
cout << "add frame" << endl;
|
||||
#endif
|
||||
|
||||
ppFun->addFrame(lfdata, ¤tPosition, ¤tI0, &t, (fname+ext).c_str(), NULL);
|
||||
ppFun->addFrame(lfdata, ¤tPosition, ¤tI0, &t, (fname).c_str(), NULL);
|
||||
|
||||
if ((GetCurrentPositionIndex()>=npos && positionFinished() && dataQueueSize()) || npos==0) {
|
||||
|
||||
@ -188,16 +201,27 @@ void postProcessing::doProcessing(double *lfdata, int delflag, string fname) {
|
||||
pthread_mutex_unlock(&mp);
|
||||
|
||||
|
||||
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((*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(ang,val,err,getCurrentProgress(),(fname+ext).c_str(),np);
|
||||
dataReady(thisData, pCallbackArg);
|
||||
delete thisData;
|
||||
ang=NULL;
|
||||
val=NULL;
|
||||
err=NULL;
|
||||
}
|
||||
delete thisData;
|
||||
if (ang)
|
||||
delete [] ang;
|
||||
if (val)
|
||||
delete [] val;
|
||||
if (err)
|
||||
delete [] err;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -370,6 +394,7 @@ int postProcessing::dataQueueSize() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
int* postProcessing::popDataQueue() {
|
||||
int *retval=NULL;
|
||||
#ifdef VERBOSE
|
||||
@ -448,13 +473,13 @@ void postProcessing::startThread(int delflag) {
|
||||
#ifdef VERBOSE
|
||||
cout << "chanspermod" << endl;
|
||||
#endif
|
||||
mM[im]=getMoveFlag(im);
|
||||
// mM[im]=getMoveFlag(im);
|
||||
#ifdef VERBOSE
|
||||
cout << "moveflag" << endl;
|
||||
#endif
|
||||
totch+=chPM[im];
|
||||
}
|
||||
|
||||
fillModuleMask(mM);
|
||||
#ifdef VERBOSE
|
||||
cout << "total channels is " << totch << endl;
|
||||
#endif
|
||||
|
@ -221,13 +221,16 @@ s
|
||||
virtual int flatFieldCorrect(double*, double*, double*, double*)=0;
|
||||
|
||||
|
||||
virtual int fillModuleMask(int *mM)=0;
|
||||
|
||||
virtual int getNMods()=0;
|
||||
|
||||
|
||||
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); cout << "findex unlock" << endl;};
|
||||
void IncrementFileIndex(){ pthread_mutex_lock(&mp); incrementFileIndex(); pthread_mutex_unlock(&mp); };
|
||||
int GetFileIndex(){ pthread_mutex_lock(&mp); int i=*fileIndex; pthread_mutex_unlock(&mp); return i;};
|
||||
|
||||
void ResetPositionIndex(){pthread_mutex_lock(&mp); resetPositionIndex(); pthread_mutex_unlock(&mp);};
|
||||
|
||||
@ -324,6 +327,19 @@ s
|
||||
|
||||
|
||||
postProcessingFuncs *ppFun;
|
||||
detectorData *thisData;
|
||||
|
||||
|
||||
double *ang;
|
||||
double *val;
|
||||
double *err;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
@ -42,8 +42,9 @@ int postProcessingFuncs::finalizeDataset(double *ang, double *val, double *err,
|
||||
|
||||
for (int ip=0; ip<(*np); ip++) {
|
||||
|
||||
if (mp)
|
||||
ang[ip]=mp[ip];
|
||||
if (ang)
|
||||
if (mp)
|
||||
ang[ip]=mp[ip];
|
||||
|
||||
if (mv)
|
||||
val[ip]=mv[ip]*totalI0;
|
||||
@ -89,9 +90,11 @@ int postProcessingFuncs::addFrame(double *data, double *pos, double *I0, double
|
||||
else
|
||||
eout=0;
|
||||
|
||||
//ratecorrect
|
||||
|
||||
|
||||
if (tDead) {
|
||||
#ifdef VERBOSE
|
||||
cout << "ppFuncs ratecorrect" << endl;
|
||||
#endif
|
||||
rateCorrect(vin, ein, vout, eout, tDead, *expTime);
|
||||
vin=vout;
|
||||
ein=eout;
|
||||
@ -99,6 +102,9 @@ int postProcessingFuncs::addFrame(double *data, double *pos, double *I0, double
|
||||
//ffcorrect
|
||||
|
||||
if (ffCoeff) {
|
||||
#ifdef VERBOSE
|
||||
cout << "ppFuncs ffcorrect" << endl;
|
||||
#endif
|
||||
if (ffErr)
|
||||
e=ffErr[ich];
|
||||
else
|
||||
@ -109,23 +115,40 @@ int postProcessingFuncs::addFrame(double *data, double *pos, double *I0, double
|
||||
|
||||
//i0correct
|
||||
if (i0>0) {
|
||||
#ifdef VERBOSE
|
||||
cout << "ppFuncs i0 norm" << endl;
|
||||
#endif
|
||||
vout/=i0;
|
||||
eout/=i0;
|
||||
}
|
||||
|
||||
if (badChannelMask)
|
||||
if (badChannelMask) {
|
||||
#ifdef VERBOSE
|
||||
cout << "ppFuncs badchans" << endl;
|
||||
#endif
|
||||
if (badChannelMask[ich])
|
||||
continue;
|
||||
}
|
||||
if (nBins) {
|
||||
//angconv
|
||||
|
||||
#ifdef VERBOSE
|
||||
cout << "ppFuncs angconv" << endl;
|
||||
#endif
|
||||
//check module mask?!?!?!?
|
||||
|
||||
|
||||
p1=convertAngle(*pos,ich,chansPerMod,angConv,moduleMask,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;
|
||||
#endif
|
||||
//mp[ich]=ich;
|
||||
mv[ich]+=vout;
|
||||
me[ich]+=eout*eout;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user