mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-12 21:07:13 +02:00
functions splitted in many sub-files
git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@167 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
379
slsDetectorSoftware/slsDetectorAnalysis/postProcessing.h
Normal file
379
slsDetectorSoftware/slsDetectorAnalysis/postProcessing.h
Normal file
@ -0,0 +1,379 @@
|
||||
#ifndef POSTPROCESSING_H
|
||||
#define POSTPROCESSING_H
|
||||
|
||||
|
||||
#include "sls_detector_defs.h"
|
||||
#include "detectorData.h"
|
||||
#include "angularConversion.h"
|
||||
#include "fileIO.h"
|
||||
#include <string>
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <queue>
|
||||
#include <math.h>
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define MAX_BADCHANS 2000
|
||||
|
||||
|
||||
#define defaultTDead {170,90,750} /**< should be changed in order to have it separate for the different detector types */
|
||||
|
||||
class postProcessing : public angularConversion, public fileIO {
|
||||
|
||||
|
||||
|
||||
public:
|
||||
postProcessing();
|
||||
virtual ~postProcessing(){};
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
get bad channels correction
|
||||
\param bad pointer to array that if bad!=NULL will be filled with the bad channel list
|
||||
\returns 0 if bad channel disabled or no bad channels, >0 otherwise
|
||||
*/
|
||||
virtual int getBadChannelCorrection(int *bad=NULL)=0;
|
||||
|
||||
|
||||
/**
|
||||
get flat field corrections
|
||||
\param corr if !=NULL will be filled with the correction coefficients
|
||||
\param ecorr if !=NULL will be filled with the correction coefficients errors
|
||||
\returns 0 if ff correction disabled, >0 otherwise
|
||||
*/
|
||||
virtual int getFlatFieldCorrection(float *corr=NULL, float *ecorr=NULL)=0;
|
||||
|
||||
/**
|
||||
set flat field corrections
|
||||
\param corr if !=NULL the flat field corrections will be filled with corr (NULL usets ff corrections)
|
||||
\param ecorr if !=NULL the flat field correction errors will be filled with ecorr (1 otherwise)
|
||||
\returns 0 if ff correction disabled, >0 otherwise
|
||||
*/
|
||||
virtual int setFlatFieldCorrection(float *corr, float *ecorr=NULL)=0;
|
||||
|
||||
/**
|
||||
set bad channels correction
|
||||
\param fname file with bad channel list ("" disable)
|
||||
\returns 0 if bad channel disabled, >0 otherwise
|
||||
*/
|
||||
virtual int setBadChannelCorrection(string fname="")=0;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
set bad channels correction
|
||||
\param fname file with bad channel list ("" disable)
|
||||
\param nbad reference to number of bad channels
|
||||
\param badlist array of badchannels
|
||||
\returns 0 if bad channel disabled, >0 otherwise
|
||||
*/
|
||||
static int setBadChannelCorrection(string fname, int &nbad, int *badlist);
|
||||
|
||||
|
||||
/**
|
||||
set bad channels correction
|
||||
\param nch number of bad channels
|
||||
\param chs array of channels
|
||||
\param ff 0 if normal bad channels, 1 if ff bad channels
|
||||
\returns 0 if bad channel disabled, >0 otherwise
|
||||
*/
|
||||
virtual int setBadChannelCorrection(int nch, int *chs, int ff=0)=0;
|
||||
|
||||
/**
|
||||
flat field correct data
|
||||
\param datain data
|
||||
\param errin error on data (if<=0 will default to sqrt(datain)
|
||||
\param dataout corrected data
|
||||
\param errout error on corrected data
|
||||
\param ffcoefficient flat field correction coefficient
|
||||
\param fferr erro on ffcoefficient
|
||||
\returns 0
|
||||
*/
|
||||
static int flatFieldCorrect(float datain, float errin, float &dataout, float &errout, float ffcoefficient, float fferr);
|
||||
|
||||
/**
|
||||
rate correct data
|
||||
\param datain data
|
||||
\param errin error on data (if<=0 will default to sqrt(datain)
|
||||
\param dataout corrected data
|
||||
\param errout error on corrected data
|
||||
\param tau dead time 9in ns)
|
||||
\param t acquisition time (in ns)
|
||||
\returns 0
|
||||
*/
|
||||
static int rateCorrect(float datain, float errin, float &dataout, float &errout, float tau, float t);
|
||||
|
||||
|
||||
|
||||
|
||||
int setAngularCorrectionMask(int i=-1){if (i==0) (*correctionMask)&=~(1<< ANGULAR_CONVERSION); if (i>0) (*correctionMask)|=(1<< ANGULAR_CONVERSION); return ((*correctionMask)&(1<< ANGULAR_CONVERSION));};
|
||||
|
||||
|
||||
|
||||
int enableAngularConversion(int i=-1) {if (i>0) return setAngularConversionFile("default"); if (i==0) return setAngularConversionFile(""); return setAngularCorrectionMask();}
|
||||
|
||||
|
||||
int enableBadChannelCorrection(int i=-1) {if (i>0) return setBadChannelCorrection("default"); if (i==0) return setBadChannelCorrection(""); return ((*correctionMask)&(1<< DISCARD_BAD_CHANNELS));}
|
||||
|
||||
|
||||
|
||||
|
||||
/** returns the bad channel list file */
|
||||
string getBadChannelCorrectionFile() {if ((*correctionMask)&(1<< DISCARD_BAD_CHANNELS)) return string(badChanFile); else return string("none");};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
get flat field corrections file directory
|
||||
\returns flat field correction file directory
|
||||
*/
|
||||
string getFlatFieldCorrectionDir(){return string(flatFieldDir);};
|
||||
/**
|
||||
set flat field corrections file directory
|
||||
\param flat field correction file directory
|
||||
\returns flat field correction file directory
|
||||
*/
|
||||
string setFlatFieldCorrectionDir(string dir){strcpy(flatFieldDir,dir.c_str()); return string(flatFieldDir);};
|
||||
|
||||
/**
|
||||
get flat field corrections file name
|
||||
\returns flat field correction file name
|
||||
*/
|
||||
string getFlatFieldCorrectionFile(){ if ((*correctionMask)&(1<<FLAT_FIELD_CORRECTION)) return string(flatFieldFile); else return string("none");};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
set/get if the data processing and file writing should be done by a separate thread
|
||||
s
|
||||
\param b 0 sequencial data acquisition and file writing, 1 separate thread, -1 get
|
||||
\returns thread flag
|
||||
*/
|
||||
|
||||
int setThreadedProcessing(int b=-1) {if (b>=0) *threadedProcessing=b; return *threadedProcessing;}
|
||||
|
||||
|
||||
|
||||
|
||||
/** processes the data
|
||||
\param delflag 0 leaves the data in the final data queue
|
||||
\returns nothing
|
||||
|
||||
*/
|
||||
void *processData(int delflag);
|
||||
|
||||
/** processes the data
|
||||
\param delflag 0 leaves the data in the final data queue
|
||||
\returns nothing
|
||||
|
||||
*/
|
||||
void processFrame(int* myData, int delflag);
|
||||
|
||||
/** processes the data
|
||||
\param delflag 0 leaves the data in the final data queue
|
||||
\returns nothing
|
||||
|
||||
*/
|
||||
void doProcessing(float* myData, int delflag);
|
||||
|
||||
|
||||
/**
|
||||
pops the data from the data queue
|
||||
\returns pointer to the popped data or NULL if the queue is empty.
|
||||
\sa dataQueue
|
||||
*/
|
||||
int* popDataQueue();
|
||||
|
||||
/**
|
||||
pops the data from thepostprocessed data queue
|
||||
\returns pointer to the popped data or NULL if the queue is empty.
|
||||
\sa finalDataQueue
|
||||
*/
|
||||
detectorData* popFinalDataQueue();
|
||||
|
||||
|
||||
/**
|
||||
resets the raw data queue
|
||||
\sa dataQueue
|
||||
*/
|
||||
void resetDataQueue();
|
||||
|
||||
/**
|
||||
resets the postprocessed data queue
|
||||
\sa finalDataQueue
|
||||
*/
|
||||
void resetFinalDataQueue();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int fillBadChannelMask();
|
||||
|
||||
|
||||
|
||||
|
||||
virtual void incrementProgress()=0;
|
||||
virtual float getCurrentProgress()=0;
|
||||
virtual void incrementFileIndex()=0;
|
||||
virtual int setTotalProgress()=0;
|
||||
|
||||
|
||||
virtual float* decodeData(int *datain)=0;
|
||||
virtual int getTotalNumberOfChannels()=0;
|
||||
|
||||
|
||||
|
||||
|
||||
virtual int rateCorrect(float*, float*, float*, float*)=0;
|
||||
virtual int flatFieldCorrect(float*, float*, float*, float*)=0;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
int *threadedProcessing;
|
||||
|
||||
int *correctionMask;
|
||||
|
||||
char *flatFieldDir;
|
||||
char *flatFieldFile;
|
||||
|
||||
char *badChanFile;
|
||||
int *nBadChans;
|
||||
int *badChansList;
|
||||
int *nBadFF;
|
||||
int *badFFList;
|
||||
|
||||
|
||||
/** mutex to synchronize main and data processing threads */
|
||||
pthread_mutex_t mp;
|
||||
|
||||
|
||||
/** mutex to synchronizedata processing and plotting threads */
|
||||
pthread_mutex_t mg;
|
||||
|
||||
/** sets when the acquisition is finished */
|
||||
int jointhread;
|
||||
|
||||
/** sets when the position is finished */
|
||||
int posfinished;
|
||||
|
||||
/**
|
||||
data queue
|
||||
*/
|
||||
queue<int*> dataQueue;
|
||||
/**
|
||||
queue containing the postprocessed data
|
||||
*/
|
||||
queue<detectorData*> finalDataQueue;
|
||||
|
||||
|
||||
/** data queue size */
|
||||
int queuesize;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
start data processing thread
|
||||
*/
|
||||
void startThread(int delflag=1); //
|
||||
/** the data processing thread */
|
||||
|
||||
pthread_t dataProcessingThread;
|
||||
|
||||
|
||||
|
||||
/** pointer to bad channel mask 0 is channel is good 1 if it is bad \sa fillBadChannelMask() */
|
||||
int *badChannelMask;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
I0 measured
|
||||
*/
|
||||
float currentI0;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
static void* startProcessData(void *n){\
|
||||
postProcessing *myDet=(postProcessing*)n;\
|
||||
myDet->processData(1);\
|
||||
pthread_exit(NULL);\
|
||||
|
||||
};
|
||||
|
||||
static void* startProcessDataNoDelete(void *n){\
|
||||
postProcessing *myDet=(postProcessing*)n;\
|
||||
myDet->processData(0);\
|
||||
pthread_exit(NULL);\
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user