From fe86145881ffd3ae9cbc41f0f41bd29a1ab3cc3b Mon Sep 17 00:00:00 2001 From: bergamaschi Date: Tue, 5 Jun 2012 13:57:00 +0000 Subject: [PATCH] slsDetectorUsers inherited by all classes i.e. API ready for EPICS driver git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@187 951219d9-93cf-4727-9268-0efd64621fa3 --- .../multiSlsDetector/multiSlsDetector.cpp | 6 +- .../multiSlsDetector/multiSlsDetector.h | 2 + .../slsDetector/slsDetector.cpp | 13 +- slsDetectorSoftware/slsDetector/slsDetector.h | 2 +- .../slsDetector/slsDetectorBase.h | 52 +++++--- .../slsDetector/slsDetectorUtils.cpp | 113 ++++++++++++++++++ .../slsDetector/slsDetectorUtils.h | 3 + .../slsDetectorAnalysis/postProcessing.cpp | 4 + 8 files changed, 173 insertions(+), 22 deletions(-) diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index 28871881b..02d8545fb 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -1608,13 +1608,15 @@ int multiSlsDetector::setFlatFieldCorrection(string fname){ int badlist[MAX_BADCHANS]; int im=0; - + if (fname=="default") { + fname=string(thisMultiDetector->flatFieldFile); + } if (fname=="") { #ifdef VERBOSE std::cout<< "disabling flat field correction" << std::endl; #endif thisMultiDetector->correctionMask&=~(1<flatFieldFile,"none"); + // strcpy(thisMultiDetector->flatFieldFile,"none"); for (int i=0; inumberOfDetectors; i++) { if (detectors[i]) detectors[i]->setFlatFieldCorrection(NULL, NULL); diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h index 88cdb1714..a3c7830dc 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h @@ -265,7 +265,9 @@ class multiSlsDetector : public slsDetectorUtils { string getHostname(int pos=-1); + using slsDetectorBase::getDetectorType; + string getDetectorType(){return sgetDetectorsType();}; detectorType getDetectorsType(int pos=-1); detectorType setDetectorsType(detectorType type=GET_DETECTOR_TYPE, int pos=-1){addSlsDetector(type, pos); return getDetectorsType(pos);}; diff --git a/slsDetectorSoftware/slsDetector/slsDetector.cpp b/slsDetectorSoftware/slsDetector/slsDetector.cpp index 0cd9af63e..f7870b482 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetector.cpp @@ -3985,14 +3985,17 @@ int slsDetector::setFlatFieldCorrection(string fname){ thisDetector->nBadFF=0; char ffffname[MAX_STR_LENGTH*2]; + if (fname=="default") { + fname=string("thisDetector->flatFieldFile"); + } - if (fname=="") { + if (fname=="") { #ifdef VERBOSE - std::cout<< "disabling flat field correction" << std::endl; + std::cout<< "disabling flat field correction" << std::endl; #endif - thisDetector->correctionMask&=~(1<flatFieldFile,"none"); - } else { + thisDetector->correctionMask&=~(1<flatFieldFile,"none"); + } else { #ifdef VERBOSE std::cout<< "Setting flat field correction from file " << fname << std::endl; #endif diff --git a/slsDetectorSoftware/slsDetector/slsDetector.h b/slsDetectorSoftware/slsDetector/slsDetector.h index 427d330b7..daf948789 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.h +++ b/slsDetectorSoftware/slsDetector/slsDetector.h @@ -258,7 +258,7 @@ typedef struct sharedSlsDetector { using slsDetectorUtils::getAngularConversion; - + string getDetectorType(){return sgetDetectorsType();}; diff --git a/slsDetectorSoftware/slsDetector/slsDetectorBase.h b/slsDetectorSoftware/slsDetector/slsDetectorBase.h index 51eb2987a..e80174fac 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorBase.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorBase.h @@ -47,7 +47,7 @@ Most methods of interest for the user are implemented in the ::slsDetectorBase i */ -//#include "slsDetectorUsers.h" +#include "slsDetectorUsers.h" #include "sls_detector_defs.h" #include @@ -64,8 +64,7 @@ using namespace std; */ //public virtual slsDetectorUsers, -class slsDetectorBase : public virtual slsDetectorDefs - { +class slsDetectorBase : public virtual slsDetectorDefs, public slsDetectorUsers { public: @@ -76,7 +75,7 @@ class slsDetectorBase : public virtual slsDetectorDefs /** virtual destructor */ virtual ~slsDetectorBase(){}; - + string getDetectorDeveloper(){return string("PSI");}; // protected: /** @@ -275,15 +274,15 @@ class slsDetectorBase : public virtual slsDetectorDefs virtual int setFlatFieldCorrection(string fname="")=0; - - + int setFlatFieldCorrectionFile(string fname=""){return setFlatFieldCorrection(fname);}; + /** set/get dynamic range \param i dynamic range (-1 get) \returns current dynamic range */ virtual int setDynamicRange(int i=-1)=0; - + int setBitDepth(int i=-1){return setDynamicRange(i);}; /** set/get the size of the detector @@ -293,6 +292,12 @@ class slsDetectorBase : public virtual slsDetectorDefs */ virtual int setNumberOfModules(int i=-1, dimension d=X)=0; + int setDetectorSize(int x0=-1, int y0=-1, int nx=-1, int ny=-1){return setNumberOfModules(nx,X);}; + + int getDetectorSize(int &x0, int &y0, int &nx, int &ny){x0=0; nx=setNumberOfModules(-1,X); return nx;}; + + virtual int getMaxNumberOfModules(dimension d=X)=0; // + int getMaximumDetectorSize(int &nx, int &ny){nx=getMaxNumberOfModules(X); ny=1; return nx;}; /** Locks/Unlocks the connection to the server @@ -314,6 +319,7 @@ class slsDetectorBase : public virtual slsDetectorDefs */ virtual void acquire(int delflag=1)=0; + int startMeasurement(){acquire(0); return OK;}; /** asks and receives a data frame from the detector, writes it to disk and processes the data @@ -332,7 +338,7 @@ class slsDetectorBase : public virtual slsDetectorDefs \returns OK/FAIL */ virtual int stopAcquisition()=0; - + int stopMeasurement(){return stopAcquisition();}; /** @@ -342,6 +348,12 @@ class slsDetectorBase : public virtual slsDetectorDefs \returns timer set value in ns or number of...(e.g. frames, gates, probes) */ virtual int64_t setTimer(timerIndex index, int64_t t=-1)=0; + int64_t setExposureTime(int64_t t=-1){return setTimer(ACQUISITION_TIME,t);}; +int64_t setExposurePeriod(int64_t t=-1){return setTimer(FRAME_PERIOD,t);}; +int64_t setDelayAfterTrigger(int64_t t=-1){return setTimer(DELAY_AFTER_TRIGGER,t);}; +int64_t setNumberOfGates(int64_t t=-1){return setTimer(GATES_NUMBER,t);}; +int64_t setNumberOfFrames(int64_t t=-1){return setTimer(FRAME_NUMBER,t);}; +int64_t setNumberOfCycles(int64_t t=-1){return setTimer(CYCLES_NUMBER,t);}; /////////////////////////////////////////////////////////////////////////////////////////// /** @@ -349,7 +361,7 @@ class slsDetectorBase : public virtual slsDetectorDefs \returns status mask */ virtual runStatus getRunStatus()=0; - + int getDetectorStatus() {return (int)getRunStatus();}; /** @short sets the onlineFlag @@ -363,15 +375,15 @@ class slsDetectorBase : public virtual slsDetectorDefs \returns current settings */ virtual detectorSettings setSettings(detectorSettings isettings, int imod=-1)=0; - + int setSettings(int isettings){return (int)setSettings((detectorSettings)isettings,-1);}; virtual detectorSettings getSettings(int imod=-1)=0; /** get threshold energy \param imod module number (-1 all) \returns current threshold value for imod in ev (-1 failed) */ - virtual int getThresholdEnergy(int imod=-1)=0; - + virtual int getThresholdEnergy(int imod)=0; + int getThresholdEnergy(){return getThresholdEnergy(-1);}; /** set/get the external communication mode @@ -381,6 +393,16 @@ class slsDetectorBase : public virtual slsDetectorDefs \returns current external communication mode */ virtual externalCommunicationMode setExternalCommunicationMode(externalCommunicationMode pol=GET_EXTERNAL_COMMUNICATION_MODE)=0; + int setTimingMode(int i=-1){return (int)setExternalCommunicationMode((externalCommunicationMode)i);}; + + + virtual int setThresholdEnergy(int e_eV, int imod, detectorSettings isettings=GET_SETTINGS)=0; + int setThresholdEnergy(int e_eV){return setThresholdEnergy(e_eV,-1);}; + + + int getBeamEnergy(){return 2*getThresholdEnergy();}; + int setBeamEnergy(int e){return 2*setThresholdEnergy(e/2);}; + /** @@ -389,8 +411,10 @@ class slsDetectorBase : public virtual slsDetectorDefs \returns OK or FAIL */ virtual int readConfigurationFile(string const fname)=0; - virtual int dumpDetectorSetup(string const fname, int level=0)=0; - virtual int retrieveDetectorSetup(string const fname, int level=0)=0; + virtual int dumpDetectorSetup(string const fname, int level)=0; + int dumpDetectorSetup(string const fname){return dumpDetectorSetup(fname,0);}; + virtual int retrieveDetectorSetup(string const fname, int level)=0; + int retrieveDetectorSetup(string const fname){return retrieveDetectorSetup(fname,0);}; /** @short \returns the default output file index diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp index f43752729..ab224eb59 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp @@ -735,3 +735,116 @@ int slsDetectorUtils::dumpDetectorSetup(string const fname, int level){ } + +// int slsDetectorUtils::setFlatFieldCorrectionFile(string fname){ +// int tch=getTotalNumberOfChannels(); + + + +// float data[tch], xmed[tch]; +// float ffcoefficients[tch], fferrors[tch]; +// int nmed=0; +// int idet=0, ichdet=-1; +// char ffffname[MAX_STR_LENGTH*2]; +// int nbad=0, nch; +// int badlist[MAX_BADCHANS]; +// int im=0; + +// if (fname=="default") { +// fname=string(flatFieldFile); +// } +// if (fname=="") { +// #ifdef VERBOSE +// std::cout<< "disabling flat field correction" << std::endl; +// #endif +// (*correctionMask)&=~(1<flatFieldFile,"none"); + +// setFlatFieldCorrection(NULL, NULL); +// } else { + +// #ifdef VERBOSE +// std::cout<< "Setting flat field correction from file " << fname << std::endl; +// #endif +// sprintf(ffffname,"%s/%s",flatFieldDir,fname.c_str()); +// nch=readDataFile(string(ffffname),data); + +// if (nch>tch) +// nch=tch; + +// if (nch>0) { +// strcpy(flatFieldFile,fname.c_str()); + + +// nbad=0; +// for (int ichan=0; ichan0) { +// /* add to median */ +// im=0; +// while ((imim; i--) +// xmed[i]=xmed[i-1]; +// xmed[im]=data[ichan]; +// nmed++; +// } else { +// if (nbad1 && xmed[nmed/2]>0) { +// #ifdef VERBOSE +// std::cout<< "Flat field median is " << xmed[nmed/2] << " calculated using "<< nmed << " points" << std::endl; +// #endif + +// thisMultiDetector->correctionMask|=(1<0) { +// ffcoefficients[ichan]=xmed[nmed/2]/data[ichan]; +// fferrors[ichan]=ffcoefficients[ichan]*sqrt(data[ichan])/data[ichan]; +// } else { +// ffcoefficients[ichan]=0.; +// fferrors[ichan]=1.; +// } + +// } + +// setFlatFieldCorrection(ffcoefficients, fferrors); + + +// } else { +// std::cout<< "Flat field data from file " << fname << " are not valid (" << nmed << "///" << xmed[nmed/2] << std::endl; +// thisMultiDetector->correctionMask&=~(1<numberOfDetectors; i++) { +// if (detectors[i]) +// detectors[i]->setFlatFieldCorrection(NULL, NULL); +// } +// return -1; +// } +// } else { +// std::cout<< "Flat field from file " << fname << " is not valid " << nch << std::endl; +// thisMultiDetector->correctionMask&=~(1<numberOfDetectors; i++) { +// if (detectors[i]) +// detectors[i]->setFlatFieldCorrection(NULL, NULL); +// } +// return -1; +// } +// } +// return thisMultiDetector->correctionMask&(1<0) setFlatFieldCorrectionFile("default"); else if (i==0) setFlatFieldCorrectionFile(""); return getFlatFieldCorrection();} + int enablePixelMaskCorrection(int i=-1) {if (i>0) setBadChannelCorrection("default"); else if (i==0) setBadChannelCorrection(""); return getBadChannelCorrection();} + int enableCountRateCorrection(int i=-1){if (i>0) setRateCorrection(-1); else if (i==0) setRateCorrection(0); return getRateCorrection();} // string getFilePath(){return fileIO::getFilePath();}; // string setFilePath(string s){return fileIO::setFilePath(s);}; diff --git a/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp b/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp index 7847e575e..c28dd0ab0 100644 --- a/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp +++ b/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp @@ -15,6 +15,10 @@ postProcessing::postProcessing(){ } + + + + int postProcessing::flatFieldCorrect(float datain, float errin, float &dataout, float &errout, float ffcoefficient, float fferr){ float e;