From 1982b25d89e4c16be4c00d37126482418c7e0d1b Mon Sep 17 00:00:00 2001 From: ramani_n Date: Thu, 2 Aug 2012 14:37:37 +0000 Subject: [PATCH] File_IO added git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@207 951219d9-93cf-4727-9268-0efd64621fa3 --- slsDetectorSoftware/Makefile.Standalone | 4 +- .../commonFiles/sls_detector_defs.h | 14 +- .../multiSlsDetector/multiSlsDetector.cpp | 2 +- .../multiSlsDetector/multiSlsDetector.h | 4 +- .../slsDetector/slsDetector.cpp | 28 +- .../slsDetector/slsDetectorActions.cpp | 5 +- .../slsDetector/slsDetectorBase.h | 6 +- .../slsDetector/slsDetectorCommand.cpp | 4 +- .../slsDetector/slsDetectorUtils.cpp | 56 +- .../slsDetector/slsDetectorUtils.h | 42 +- .../AngularConversion_Standalone.cpp | 30 +- .../AngularConversion_Standalone.h | 45 +- .../slsDetectorAnalysis/FileIO_Standalone.cpp | 648 ++++++++++++++++++ .../slsDetectorAnalysis/FileIO_Standalone.h | 410 +++++++++++ .../slsDetectorAnalysis/postProcessing.cpp | 4 +- .../postProcessingFileIO_Standalone.cpp | 602 ++++++++++++++++ .../postProcessingFileIO_Standalone.h | 391 +++++++++++ .../postProcessing_Standalone.cpp | 4 +- .../postProcessing_Standalone.h | 28 +- .../usersFunctions/usersFunctions.cpp | 2 + .../usersFunctions/usersFunctions.h | 2 +- 21 files changed, 2223 insertions(+), 108 deletions(-) create mode 100644 slsDetectorSoftware/slsDetectorAnalysis/FileIO_Standalone.cpp create mode 100644 slsDetectorSoftware/slsDetectorAnalysis/FileIO_Standalone.h create mode 100644 slsDetectorSoftware/slsDetectorAnalysis/postProcessingFileIO_Standalone.cpp create mode 100644 slsDetectorSoftware/slsDetectorAnalysis/postProcessingFileIO_Standalone.h diff --git a/slsDetectorSoftware/Makefile.Standalone b/slsDetectorSoftware/Makefile.Standalone index 3a6cd15f8..d9a7c0868 100644 --- a/slsDetectorSoftware/Makefile.Standalone +++ b/slsDetectorSoftware/Makefile.Standalone @@ -1,12 +1,12 @@ CFLAGS= -DC_ONLY #FLAGS= -DVERBOSE -DVERYVERBOSE -INCLUDES= -IcommonFiles -IslsDetector -IMySocketTCP -IusersFunctions -ImultiSlsDetector -IslsDetectorUtils -IslsDetectorCommand -IslsDetectorAnalysis +INCLUDES= -IcommonFiles -IslsDetector -IMySocketTCP -IusersFunctions -ImultiSlsDetector -IslsDetectorUtils -IslsDetectorCommand -IslsDetectorAnalysis #EPICSFLAGS=-D EPICS -I/usr/local/epics/base/include/ -I /usr/local/epics/base/include/os/Linux/ -L /usr/local/epics/base/lib/SL5-x86/ -Wl,-R/usr/local/epics/base/lib/SL5-x86 -lca -lCom CC=gcc CXX=g++ -SRC_CLNT= slsDetectorAnalysis/fileIO.cpp MySocketTCP/MySocketTCP.cpp usersFunctions/usersFunctions.cpp slsDetector/slsDetectorUtils.cpp slsDetector/slsDetectorCommand.cpp slsDetectorAnalysis/AngularConversion_Standalone.cpp slsDetectorAnalysis/energyConversion.cpp slsDetector/slsDetectorActions.cpp slsDetectorAnalysis/postProcessing_Standalone.cpp slsDetector/slsDetector.cpp multiSlsDetector/multiSlsDetector.cpp +SRC_CLNT= slsDetectorAnalysis/FileIO_Standalone.cpp MySocketTCP/MySocketTCP.cpp usersFunctions/usersFunctions.cpp slsDetector/slsDetectorUtils.cpp slsDetector/slsDetectorCommand.cpp slsDetectorAnalysis/AngularConversion_Standalone.cpp slsDetectorAnalysis/energyConversion.cpp slsDetector/slsDetectorActions.cpp slsDetectorAnalysis/postProcessingFileIO_Standalone.cpp slsDetector/slsDetector.cpp multiSlsDetector/multiSlsDetector.cpp OBJS = $(SRC_CLNT:.cpp=.o) diff --git a/slsDetectorSoftware/commonFiles/sls_detector_defs.h b/slsDetectorSoftware/commonFiles/sls_detector_defs.h index ac8babb21..8ba45744b 100755 --- a/slsDetectorSoftware/commonFiles/sls_detector_defs.h +++ b/slsDetectorSoftware/commonFiles/sls_detector_defs.h @@ -367,7 +367,8 @@ enum timerIndex { ACTUAL_TIME, /**< Actual time of the detector's internal timer */ MEASUREMENT_TIME, /**< Time of the measurement from the detector (fifo) */ - PROGRESS /**< fraction of measurement elapsed - only get! */ + PROGRESS, /**< fraction of measurement elapsed - only get! */ + MEASUREMENTS_NUMBER }; /** @@ -483,7 +484,16 @@ enum angleConversionParameter { MOVE_FLAG /**< wether the detector moves with the motor or not in a multi detector system */ }; - +//typedef struct { + //float center; /**< center of the module (channel at which the radius is perpendicular to the module surface) */ + //float ecenter; /**< error in the center determination */ + //float r_conversion; /**< detector pixel size (or strip pitch) divided by the diffractometer radius */ + //float er_conversion; /**< error in the r_conversion determination */ + //float offset; /**< the module offset i.e. the position of channel 0 with respect to the diffractometer 0 */ + //float eoffset; /**< error in the offset determination */ + //float tilt; /**< ossible tilt in the orthogonal direction (unused)*/ + //float etilt; /**< error in the tilt determination *// +//} angleConversionConstant; #ifdef __cplusplus diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index 1efeea6b2..adc2a6cd2 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -133,7 +133,7 @@ multiSlsDetector::multiSlsDetector(int id) : slsDetectorUtils(), shmId(-1) /** set correction mask to 0*/ - thisMultiDetector->correctionMask=0; + thisMultiDetector->correctionMask=1<tDead=0; /** sets bad channel list file to none */ diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h index 7c6034d54..456df9ab9 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h @@ -17,7 +17,7 @@ ID: $Id$ class slsDetector; -//#include "sls_detector_defs.h" +#include "sls_detector_defs.h" @@ -36,7 +36,7 @@ class slsDetector; */ -class multiSlsDetector : public slsDetectorUtils { +class multiSlsDetector : public virtual slsDetectorUtils { diff --git a/slsDetectorSoftware/slsDetector/slsDetector.cpp b/slsDetectorSoftware/slsDetector/slsDetector.cpp index 124301ec0..9e59d236c 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetector.cpp @@ -510,6 +510,7 @@ int slsDetector::initializeDetectorSize(detectorType type) { /** calculates the expected data size */ thisDetector->timerValue[PROBES_NUMBER]=0; thisDetector->timerValue[FRAME_NUMBER]=1; + thisDetector->timerValue[MEASUREMENTS_NUMBER]=1; thisDetector->timerValue[CYCLES_NUMBER]=1; @@ -3275,6 +3276,7 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t){ int ret=OK; int n=0; + if (index!=MEASUREMENTS_NUMBER) { #ifdef VERBOSE @@ -3304,8 +3306,11 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t){ //std::cout<< "offline " << std::endl; if (t>=0) thisDetector->timerValue[index]=t; - -} + } +} else { + if (t>=0) + thisDetector->timerValue[index]=t; +} #ifdef VERBOSE std::cout<< "Timer " << index << " set to "<< thisDetector->timerValue[index] << "ns" << std::endl; #endif @@ -3541,20 +3546,11 @@ int slsDetector::setPort(portType index, int num){ - - - - - - - - - - +//Naveen change int slsDetector::setTotalProgress() { - int nf=1, npos=1, nscan[MAX_SCAN_LEVELS]={1,1}, nc=1; + int nf=1, npos=1, nscan[MAX_SCAN_LEVELS]={1,1}, nc=1, nm=1; if (thisDetector->timerValue[FRAME_NUMBER]) nf=thisDetector->timerValue[FRAME_NUMBER]; @@ -3565,6 +3561,10 @@ int slsDetector::setTotalProgress() { if (thisDetector->numberOfPositions>0) npos=thisDetector->numberOfPositions; + if (timerValue[MEASUREMENTS_NUMBER]>0) + nc=timerValue[MEASUREMENTS_NUMBER]; + + if ((thisDetector->nScanSteps[0]>0) && (thisDetector->actionMask & (1 << MAX_ACTIONS))) nscan[0]=thisDetector->nScanSteps[0]; @@ -3575,6 +3575,7 @@ int slsDetector::setTotalProgress() { #ifdef VERBOSE cout << "nc " << nc << endl; + cout << "nm " << nm << endl; cout << "nf " << nf << endl; cout << "npos " << npos << endl; cout << "nscan[0] " << nscan[0] << endl; @@ -4571,7 +4572,6 @@ int slsDetector::getAngularConversion(int &direction, angleConversionConstant * } else { return 0; } - } diff --git a/slsDetectorSoftware/slsDetector/slsDetectorActions.cpp b/slsDetectorSoftware/slsDetector/slsDetectorActions.cpp index d56870a46..18b822702 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorActions.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorActions.cpp @@ -405,7 +405,8 @@ int slsDetectorActions::getScanPrecision(int iscan){ int slsDetectorActions::executeScan(int level, int istep) { - int trimbit; + int trimbit,aMask,prec0,prec1,pindex,npos; + float sv0,sv1; char cmd[MAX_STR_LENGTH]; if (level<0 || level>MAX_SCAN_LEVELS) @@ -430,7 +431,7 @@ int slsDetectorActions::executeScan(int level, int istep) { break; default: //Custom scan script level 1. The arguments are passed as nrun=n fn=filename var=v par=p" - sprintf(cmd,"%s nrun=%d fn=%s var=%f par=%s",getScanScript(level).c_str(),getFileIndex(),createFileName().c_str(),currentScanVariable[level],getScanParameter(level).c_str()); + sprintf(cmd,"%s nrun=%d fn=%s var=%f par=%s",getScanScript(level).c_str(),getFileIndex(),createFileName(aMask,sv0,prec0,sv1,prec1,pindex,npos).c_str(),currentScanVariable[level],getScanParameter(level).c_str()); #ifdef VERBOSE cout << "Executing scan script "<< level << " " << cmd << endl; #endif diff --git a/slsDetectorSoftware/slsDetector/slsDetectorBase.h b/slsDetectorSoftware/slsDetector/slsDetectorBase.h index 6c0455991..e4dbf46d0 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorBase.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorBase.h @@ -229,7 +229,7 @@ class slsDetectorBase : public virtual slsDetectorUsers , public virtual slsDet /** generates file name without extension */ - virtual string createFileName()=0; + string createFileName(int aMask, float sv0, int prec0, float sv1, int prec1, int pindex, int npos); @@ -292,9 +292,9 @@ class slsDetectorBase : public virtual slsDetectorUsers , public virtual slsDet */ virtual int setNumberOfModules(int i=-1, dimension d=X)=0; - int setDetectorSize(int x0=-1, int y0=-1, int nx=-1, int ny=-1){int nm=-1; if (nx>=0) nm=nx/getChansPerMod(0); return setNumberOfModules(nm,X);}; + int setDetectorSize(int x0=-1, int y0=-1, int nx=-1, int ny=-1){return setNumberOfModules(nx/getChansPerMod(0),X);}; - int getDetectorSize(int &x0, int &y0, int &nx, int &ny){x0=0; nx=setNumberOfModules(-1,X)*getChansPerMod(0); y0=0; ny=1; return nx;}; + int getDetectorSize(int &x0, int &y0, int &nx, int &ny){x0=0; nx=setNumberOfModules(-1,X)*getChansPerMod(0); return nx;}; virtual int getMaxNumberOfModules(dimension d=X)=0; // int getMaximumDetectorSize(int &nx, int &ny){nx=getMaxNumberOfModules(X)*getChansPerMod(0); ny=1; return nx;}; diff --git a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp index 26105a2ae..568857964 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp @@ -1312,9 +1312,9 @@ string slsDetectorCommand::cmdEnablefwrite(int narg, char *args[], int action){ if (action==PUT_ACTION) { if (sscanf(args[1],"%d",&i)) myDet->enableWriteToFile(i); - ; + return string("Write to File Enabled"); } - return string(myDet->getFileName()); + else return string("Write to File 'Not' Enabled"); } diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp index df37852a8..342e55ea1 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp @@ -1,13 +1,17 @@ #include "slsDetectorUtils.h" #include "usersFunctions.h" #include "slsDetectorCommand.h" +#include "postProcessing.h" #include #include #include +using namespace std; slsDetectorUtils::slsDetectorUtils() { + + #ifdef VERBOSE cout << "setting callbacks" << endl; #endif @@ -21,6 +25,8 @@ slsDetectorUtils::slsDetectorUtils() { cout << "done " << endl; #endif + + }; @@ -38,8 +44,6 @@ void slsDetectorUtils::acquire(int delflag){ #endif void *status; - - setStartIndex(*fileIndex); // int lastindex=startindex, nowindex=startindex; @@ -74,8 +78,7 @@ void slsDetectorUtils::acquire(int delflag){ if (*threadedProcessing) { startThread(delflag); } - - //cout << "data thread started " << endl; + //cout << "data thread started " << endl; int np=1; if (*numberOfPositions>0) np=*numberOfPositions; @@ -97,6 +100,11 @@ void slsDetectorUtils::acquire(int delflag){ ns1=1; +//loop measurements + + setStartIndex(*fileIndex); + + //cout << "action at start" << endl; if (*stoppedFlag==0) { executeAction(startScript); @@ -259,6 +267,9 @@ void slsDetectorUtils::acquire(int delflag){ executeAction(stopScript); } +// loop measurements + + // waiting for the data processing thread to finish! if (*threadedProcessing) { pthread_mutex_lock(&mp); @@ -278,11 +289,11 @@ void slsDetectorUtils::acquire(int delflag){ - +//Naveen change int slsDetectorUtils::setTotalProgress() { - int nf=1, npos=1, nscan[MAX_SCAN_LEVELS]={1,1}, nc=1; + int nf=1, npos=1, nscan[MAX_SCAN_LEVELS]={1,1}, nc=1, nm=1; if (timerValue[FRAME_NUMBER]) nf=timerValue[FRAME_NUMBER]; @@ -290,19 +301,23 @@ int slsDetectorUtils::setTotalProgress() { if (timerValue[CYCLES_NUMBER]>0) nc=timerValue[CYCLES_NUMBER]; - if (*numberOfPositions>0) + if (timerValue[MEASUREMENTS_NUMBER]>0) + nc=timerValue[MEASUREMENTS_NUMBER]; + + if (*numberOfPositions>0) npos=*numberOfPositions; - if ((nScanSteps[0]>0) && (*actionMask & (1 << MAX_ACTIONS))) - nscan[0]=nScanSteps[0]; + if ((nScanSteps[0]>0) && (*actionMask & (1 << MAX_ACTIONS))) + nscan[0]=nScanSteps[0]; if ((nScanSteps[1]>0) && (*actionMask & (1 << (MAX_ACTIONS+1)))) nscan[1]=nScanSteps[1]; - totalProgress=nf*nc*npos*nscan[0]*nscan[1]; + totalProgress=nm*nf*nc*npos*nscan[0]*nscan[1]; #ifdef VERBOSE cout << "nc " << nc << endl; + cout << "nm " << nm << endl; cout << "nf " << nf << endl; cout << "npos " << npos << endl; cout << "nscan[0] " << nscan[0] << endl; @@ -658,12 +673,9 @@ int slsDetectorUtils::dumpDetectorSetup(string const fname, int level){ ofstream outfile; char *args[2]; - char myargs[2][1000]; - args[0]=myargs[0]; - args[1]=myargs[1]; - // for (int ia=0; ia<2; ia++) { - // args[ia]=new char[1000]; - //} + for (int ia=0; ia<2; ia++) { + args[ia]=new char[1000]; + } @@ -694,18 +706,18 @@ int slsDetectorUtils::dumpDetectorSetup(string const fname, int level){ } - strcpy(myargs[0],names[iv].c_str()); + strcpy(args[0],names[iv].c_str()); if (level==2) { fname1=fname+string(".ff"); - strcpy(myargs[1],fname1.c_str()); + strcpy(args[1],fname1.c_str()); } outfile << names[iv] << " " << cmd->executeLine(nargs,args,GET_ACTION) << std::endl; iv++; - strcpy(myargs[0],names[iv].c_str()); + strcpy(args[0],names[iv].c_str()); if (level==2) { fname1=fname+string(".bad"); - strcpy(myargs[1],fname1.c_str()); + strcpy(args[1],fname1.c_str()); } outfile << names[iv] << " " << cmd->executeLine(nargs,args,GET_ACTION) << std::endl; iv++; @@ -713,14 +725,14 @@ int slsDetectorUtils::dumpDetectorSetup(string const fname, int level){ if (level==2) { - strcpy(myargs[0],names[iv].c_str()); + strcpy(args[0],names[iv].c_str()); size_t c=fname.rfind('/'); if (c } @@ -35,7 +36,7 @@ using namespace std; #include "slsDetectorActions.h" #include "postProcessing.h" -#define MAX_TIMERS 10 +#define MAX_TIMERS 11 #define MAX_ROIS 100 #define MAXPOS 50 @@ -47,19 +48,20 @@ using namespace std; (used in the PSi command line interface) */ + +//class postProcessing; + class slsDetectorUtils : public slsDetectorActions, public postProcessing { - +//public postProcessing public: - slsDetectorUtils(); + slsDetectorUtils(); virtual ~slsDetectorUtils(){}; - - virtual int getNumberOfDetectors(){return 1;}; @@ -71,10 +73,10 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing { using slsDetectorBase::setFlatFieldCorrection; using postProcessing::setBadChannelCorrection; - int enableFlatFieldCorrection(int i=-1) {if (i>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();}; + int enableFlatFieldCorrection(int i=-1) {if (i>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);}; // string getFileName(){return fileIO::getFileName();}; @@ -83,8 +85,14 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing { // int getFileIndex(){return fileIO::getFileIndex();}; // int setFileIndex(int s){return fileIO::setFileIndex(s);}; +/* + int getScanPrecision(int i){return slsDetectorActions::getScanPrecision(i);}; - // int getScanPrecision(int i){return slsDetectorActions::getScanPrecision(i);}; + int getActionMask() {return slsDetectorActions::getActionMask();}; + float getCurrentScanVariable(int i) {return slsDetectorActions::getCurrentScanVariable(i);}; + int getCurrentPositionIndex(){return angularConversion::getCurrentPositionIndex();}; + int getNumberOfPositions(){return angularConversion::getNumberOfPositions();}; +*/ // int getActionMask() {return slsDetectorActions::getActionMask();}; // double getCurrentScanVariable(int i) {return slsDetectorActions::getCurrentScanVariable(i);}; @@ -140,7 +148,7 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing { \param i position in the multiSlsDetector structure \return id or -1 if FAIL */ - virtual int getDetectorId(int i=-1) =0; + virtual int getDetectorId(int i=-1)=0; /** Sets the detector id (shared memory id) of an slsDetector in a multiSlsDetector structure \param ival id to be set @@ -177,7 +185,7 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing { virtual int setPort(portType t, int i=-1)=0; /** - get detector ids/versions for module + get detector ids/versions for module=0 \param mode which id/version has to be read \param imod module number for module serial number \returns id @@ -299,7 +307,7 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing { virtual char* getSettingsDir()=0; /** sets the detector trimbit/settings directory */ - virtual char* setSettingsDir(string s)=0; + virtual char* setSettingsDir(string s); /** returns the location of the calibration files @@ -517,7 +525,7 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing { */ virtual int writeConfigurationFile(string const fname)=0; - + virtual int getAngularConversion(int &direction, angleConversionConstant *angconv=NULL)=0; void registerGetPositionCallback( double (*func)(void*),void *arg){get_position=func; POarg=arg;}; @@ -548,11 +556,13 @@ class slsDetectorUtils : public slsDetectorActions, public postProcessing { int retrieveDetectorSetup(string const fname, int level=0); + protected: + static const int64_t thisSoftwareVersion=0x20120124; - - + + //protected: int *stoppedFlag; diff --git a/slsDetectorSoftware/slsDetectorAnalysis/AngularConversion_Standalone.cpp b/slsDetectorSoftware/slsDetectorAnalysis/AngularConversion_Standalone.cpp index e84d38ed9..36f40e2bd 100644 --- a/slsDetectorSoftware/slsDetectorAnalysis/AngularConversion_Standalone.cpp +++ b/slsDetectorSoftware/slsDetectorAnalysis/AngularConversion_Standalone.cpp @@ -1,4 +1,4 @@ -#include "angularConversion.h" +#include "AngularConversion_Standalone.h" #include #include @@ -18,8 +18,9 @@ angularConversion::angularConversion( int *np, double *pos, double *bs, double { //angleFunctionPointer=0; - registerAngleFunctionCallback(&defaultAngleFunction); - + registerAngleFunctionCallback(&defaultAngleFunction,NULL); + registerCallBackGetChansPerMod(&defaultGetChansPerMod,this); + registerCallBackGetNumberofChannel(&defaultGetNumberofChannel,this); } angularConversion::~angularConversion(){ @@ -49,28 +50,28 @@ double* angularConversion::convertAngles(double pos) { angleConversionConstant *p=NULL; int ch0=0; - int chlast=chansPerMod[imod]; - int nchmod=chansPerMod[imod]; - p=angConvs[imod]; + int chlast=getChansPerMods(imod); + int nchmod=getChansPerMods(imod); + p=angConvs+imod; if (moveFlag[imod]==0) enc=0; else enc=pos; - for (int ip=0; ip=chlast) { imod++; - p=angConvs[imod]; + p=angConvs+imod; if (moveFlag[imod]==0) enc=0; else enc=pos; ch0=chlast; - nchmod=chansPerMod[imod]; + nchmod=getChansPerMods(imod); if (nchmod>0) chlast+=nchmod; } @@ -150,10 +151,7 @@ int angularConversion::readAngularConversion( ifstream& infile, int nmod, angleC if (nm>=nmod) break; - - - - } + } return nm; } @@ -379,7 +377,7 @@ int angularConversion::addToMerging(double *p1, double *v1, double *e1, double } - int ret=addToMerging(p1, v1, e1, mp, mv,me, mm,totalNumberOfChannels, *binSize,nBins, badChanMask ); + int ret=addToMerging(p1, v1, e1, mp, mv,me, mm,getTotalNumberofChannels(), *binSize,nBins, badChanMask ); if (del) { @@ -468,7 +466,7 @@ double angularConversion::getAngularConversionParameter(angleConversionParameter - +/** int angularConversion::setAngularConversionFile(string fname) { if (fname=="") { setAngularCorrectionMask(0); @@ -492,7 +490,7 @@ int angularConversion::setAngularConversionFile(string fname) { } - +*/ /* diff --git a/slsDetectorSoftware/slsDetectorAnalysis/AngularConversion_Standalone.h b/slsDetectorSoftware/slsDetectorAnalysis/AngularConversion_Standalone.h index 1ed024bfe..9fa889a0b 100644 --- a/slsDetectorSoftware/slsDetectorAnalysis/AngularConversion_Standalone.h +++ b/slsDetectorSoftware/slsDetectorAnalysis/AngularConversion_Standalone.h @@ -1,6 +1,6 @@ -#ifndef ANGULARCONVERSION_H -#define ANGULARCONVERSION_H +#ifndef ANGULARCONVERSIONSTD_H +#define ANGULARCONVERSIONSTD_H //#include "slsDetectorBase.h" @@ -319,7 +319,7 @@ class angularConversion : public virtual slsDetectorDefs { //: public virtual sl /* \param angconv array that will be filled with the angular conversion constants */ /* \returns 0 if angular conversion disabled, >0 otherwise */ /* *\/ */ -/* virtual int getAngularConversion(int &direction, angleConversionConstant *angconv=NULL)=0; */ + virtual int getAngularConversion(int &direction, angleConversionConstant *angoff=NULL); /* /\** */ /* pure virtual function */ @@ -340,7 +340,15 @@ class angularConversion : public virtual slsDetectorDefs { //: public virtual sl /* \param imod module number */ /* \returns number of channels in the module */ /* *\/ */ -/* virtual int getChansPerMod(int imod=0)=0; */ + + + static int defaultGetNumberofChannel(int nch, void *p=NULL ) { ((angularConversion*)p)->setTotalNumberOfChannels(nch); return 0;}; + static int defaultGetChansPerMod(int imod=0, void *p=NULL){ ((angularConversion*)p)->setChansPerMod(0,imod); return 0;}; + + int setChansPerMod(int nch, int imod=0){if (nch<0) return -1; if (imod>=0 && imod=0){ totalNumberOfChannels=i; return totalNumberOfChannels;} else return -1;}; + /* /\** */ /* get the angular conversion contant of one modules */ @@ -381,15 +389,28 @@ class angularConversion : public virtual slsDetectorDefs { //: public virtual sl */ int getNumberOfPositions() {return *numberOfPositions;}; + int getChansPerMods(int imod) { return chansPerMod[imod];}; + int getTotalNumberofChannels(){ return totalNumberOfChannels;}; - int setTotalNumberOfChannels(int i){if (i>=0) totalNumberOfChannels=i; return totalNumberOfChannels;}; - void incrementPositionIndex() {currentPositionIndex++;}; + + void registerCallBackGetChansPerMod(int (*func)(int, void *),void *arg){ getChansPerModule=func;pChpermod=arg;}; + void registerCallBackGetNumberofChannel(int (*func)(int, void *),void *arg){ getNumberofChannel=func;pNumberofChannel=arg;}; + protected: + private: + + + int (*getChansPerModule)(int, void*); + int (*getNumberofChannel)(int, void*); + + void *pChpermod,*angPtr,*pNumberofChannel; + + /** merging bins */ double *mergingBins; @@ -403,6 +424,7 @@ class angularConversion : public virtual slsDetectorDefs { //: public virtual sl int *mergingMultiplicity; double (*angle)(double, double, double, double, double, double, double, int); + int totalNumberOfChannels; @@ -420,17 +442,17 @@ class angularConversion : public virtual slsDetectorDefs { //: public virtual sl double *binSize; int *correctionMask; - int chansPerMod; + int chansPerMod[MAXMODS*MAXDET]; int nMod; angleConversionConstant angConvs[MAXMODS*MAXDET]; int directions[MAXMODS*MAXDET]; - /** pointer to beamlien fine offset*/ + /** pointer to beamline fine offset*/ double *fineOffset; - /** pointer to beamlien global offset*/ + /** pointer to beamline global offset*/ double *globalOffset; - /** pointer to beamlien angular direction*/ + /** pointer to beamline angular direction*/ int *angDirection; /** pointer to detector move flag (1 moves with encoder, 0 not)*/ @@ -457,9 +479,10 @@ class angularConversion : public virtual slsDetectorDefs { //: public virtual sl int getCurrentPositionIndex() {return currentPositionIndex;}; + - void registerAngleFunctionCallback(double( *fun)(double, double, double, double, double, double, double, int)) {angle = fun;}; + void registerAngleFunctionCallback(double( *fun)(double, double, double, double, double, double, double, int),void* arg) {angle = fun; angPtr=arg;}; }; diff --git a/slsDetectorSoftware/slsDetectorAnalysis/FileIO_Standalone.cpp b/slsDetectorSoftware/slsDetectorAnalysis/FileIO_Standalone.cpp new file mode 100644 index 000000000..406059cbe --- /dev/null +++ b/slsDetectorSoftware/slsDetectorAnalysis/FileIO_Standalone.cpp @@ -0,0 +1,648 @@ +#include "FileIO_Standalone.h" + + + + + +string fileIO::createFileName(char *filepath, char *filename, int aMask, double sv0, int prec0, double sv1, int prec1, int pindex, int npos, int findex) { + ostringstream osfn; + // string fn; + /*directory name +root file name */ + osfn << filepath << "/" << filename; + + // cout << osfn.str() << endl; + + // scan level 0 + if ( aMask& (1 << (MAX_ACTIONS))) + osfn << "_S" << fixed << setprecision(prec0) << sv0; + + //cout << osfn.str() << endl; + + //scan level 1 + if (aMask & (1 << (MAX_ACTIONS+1))) + osfn << "_s" << fixed << setprecision(prec1) << sv1; + + //cout << osfn.str() << endl; + + + //position + if (pindex>0 && pindex<=npos) + osfn << "_p" << pindex; + + //cout << osfn.str() << endl; + + // file index + osfn << "_" << findex; + + //cout << osfn.str() << endl; + + +#ifdef VERBOSE + cout << "created file name " << osfn.str() << endl; +#endif + + //cout << osfn.str() << endl; + //fn=oosfn.str()sfn.str(); + return osfn.str(); + +} + + + /* I/O */ + +/* generates file name without extension*/ + +string fileIO::createFileName(int aMask, double sv0, int prec0, double sv1, int prec1, int pindex, int npos) { + currentFileName=createFileName(filePath, \ + fileName, \ + aMask, \ + sv0, \ + prec0, \ + sv1, \ + prec1, \ + pindex, \ + npos, \ + *fileIndex \ + ); + return currentFileName; + +} + + +int fileIO::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 fileIO::getVariablesFromFileName(string fname, int &index, int &p_index, double &sv0, double &sv1) { + + int i; + double 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); + } + else + cout << "******************************** cannot parse file index" << endl; + +#ifdef VERBOSE + 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); + } + else + cout << "******************************** cannot parse position index" << endl; + +#ifdef VERBOSE + 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); + } + else + cout << "******************************** cannot parse scan varable 1" << endl; + +#ifdef VERBOSE + 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 + } + else + cout << "******************************** cannot parse scan varable 0" << endl; + +#ifdef VERBOSE +#endif + + + + return index; +} + + + + + +int fileIO::writeDataFile(string fname, int nch, double *data, double *err, double *ang, char dataformat){ + + + ofstream outfile; + // int idata; + if (data==NULL) + return FAIL; + + // args|=0x10; // one line per channel! + + outfile.open (fname.c_str(),ios_base::out); + if (outfile.is_open()) + { + writeDataFile(outfile, nch, data, err, ang, dataformat, 0); + outfile.close(); + return OK; + } else { + std::cout<< "Could not open file " << fname << "for writing"<< std::endl; + return FAIL; + } +}; + + +int fileIO::writeDataFile(ofstream &outfile, int nch, double *data, double *err, double *ang, char dataformat, int offset){ + + + int idata; + if (data==NULL) + return FAIL; + + // args|=0x10; // one line per channel! + + + for (int ichan=0; ichan> ichan >> fdata; + //ich=ichan; + if (ssstr.fail() || ssstr.bad()) { + interrupt=1; + break; + } + // if (ich!=iline) + // std::cout<< "Channel number " << ichan << " does not match with line number " << iline << " " << dataformat << std::endl; + ich=iline; + if (ichan> fang >> fdata; + ich=iline; + } + if (ssstr.fail() || ssstr.bad()) { + interrupt=1; + break; + } + if (err) + ssstr >> ferr; + if (ssstr.fail() || ssstr.bad()) { + interrupt=1; + break; + } + if (ich=nch) { + interrupt=1; + break; + } + } + return iline; +}; + + + +int fileIO::readDataFile(string fname, int *data, int nch){ + + ifstream infile; + int iline=0;//ichan, idata, + //int interrupt=0; + string str; + +#ifdef VERBOSE + std::cout<< "Opening file "<< fname << std::endl; +#endif + infile.open(fname.c_str(), ios_base::in); + if (infile.is_open()) { + iline=readDataFile(infile, data, nch, 0); + infile.close(); + } else { + std::cout<< "Could not read file " << fname << std::endl; + return -1; + } + return iline; +}; + +int fileIO::readDataFile(ifstream &infile, int *data, int nch, int offset){ + + int ichan, idata, iline=0; + int interrupt=0; + string str; + + + while (infile.good() and interrupt==0) { + getline(infile,str); +#ifdef VERBOSE + std::cout<< str << std::endl; +#endif + istringstream ssstr(str); + ssstr >> ichan >> idata; + if (ssstr.fail() || ssstr.bad()) { + interrupt=1; + break; + } + // if (ichan!=iline) { +// std::cout<< " Expected channel "<< iline <<" but read channel "<< ichan << std::endl; +// interrupt=1; +// break; +// } else { + if (iline=offset) { + data[iline]=idata; + iline++; + } + } else { + interrupt=1; + break; + } + // } + } + return iline; +}; + + +int fileIO::readDataFile(string fname, short int *data, int nch){ + + ifstream infile; + int iline=0;//ichan, + //int interrupt=0; + string str; + +#ifdef VERBOSE + std::cout<< "Opening file "<< fname << std::endl; +#endif + infile.open(fname.c_str(), ios_base::in); + if (infile.is_open()) { + iline=readDataFile(infile, data, nch, 0); + infile.close(); + } else { + std::cout<< "Could not read file " << fname << std::endl; + return -1; + } + return iline; +}; + +int fileIO::readDataFile(ifstream &infile, short int *data, int nch, int offset){ + + int ichan, iline=0; + short int idata; + int interrupt=0; + string str; + while (infile.good() and interrupt==0) { + getline(infile,str); +#ifdef VERBOSE + ;//std::cout<< str << std::endl; +#endif + istringstream ssstr(str); + ssstr >> ichan >> idata; + if (ssstr.fail() || ssstr.bad()) { + interrupt=1; + break; + } + // if (ichan!=iline) { +// std::cout<< " Expected channel "<< iline <<" but read channel "<< ichan << std::endl; +// interrupt=1; +// break; +// } else { + if (iline=offset) { + data[iline]=idata; + iline++; + } + } else { + interrupt=1; + break; + } + // } +#ifdef VERBOSE + ;//std::cout<< "read " << iline <<" channels " << std::endl; +#endif + } + return iline; +} + + + +/*writes raw data file */ + +int fileIO::writeDataFile(string fname, double *data, double *err, double *ang, char dataformat, int nch){ + if (nch==-1) + nch=getTotalNumberofChannels();//getTotalNumberOfChannels(); + + return writeDataFile(fname, nch, data, err, ang, dataformat); + +} +int fileIO::writeDataFile(ofstream &outfile, double *data, double *err, double *ang, char dataformat, int nch, int offset){ + if (nch==-1) + nch=getTotalNumberofChannels(); + + return writeDataFile(outfile, nch, data, err, ang, dataformat, offset); + +} + + + + +int fileIO::writeDataFile(string fname, int *data){ + + return writeDataFile(fname, getTotalNumberofChannels(), data); +} + +int fileIO::writeDataFile(ofstream &outfile, int *data, int offset){ + + return writeDataFile(outfile, getTotalNumberofChannels(), data, offset); +} + + + + + +int fileIO::writeDataFile(string fname, short int *data){ + + return writeDataFile(fname, getTotalNumberofChannels(), data); +} + +int fileIO::writeDataFile(ofstream &outfile, short int *data, int offset){ + + return writeDataFile(outfile,getTotalNumberofChannels() , data, offset); +} + + + + +int fileIO::readDataFile(string fname, double *data, double *err, double *ang, char dataformat) { + return readDataFile(getTotalNumberofChannels(), fname, data, err, ang, dataformat); + +} + +int fileIO::readDataFile(ifstream &infile, double *data, double *err, double *ang, char dataformat, int offset) { + return readDataFile(getTotalNumberofChannels(), infile, data, err, ang, dataformat, offset); + +} + + + +int fileIO::readDataFile(string fname, int *data){ + + return readDataFile(fname, data, getTotalNumberofChannels()); +}; + + +int fileIO::readDataFile(ifstream &infile, int *data, int offset){ + + return readDataFile(infile, data, getTotalNumberofChannels(), offset); +}; + + + + + +int fileIO::readDataFile(string fname, short int *data){ + + return readDataFile(fname, data, getTotalNumberofChannels()); +}; + + +int fileIO::readDataFile(ifstream &infile, short int *data, int offset){ + + return readDataFile(infile, data, getTotalNumberofChannels(),offset); +}; + diff --git a/slsDetectorSoftware/slsDetectorAnalysis/FileIO_Standalone.h b/slsDetectorSoftware/slsDetectorAnalysis/FileIO_Standalone.h new file mode 100644 index 000000000..1056c9879 --- /dev/null +++ b/slsDetectorSoftware/slsDetectorAnalysis/FileIO_Standalone.h @@ -0,0 +1,410 @@ +#ifndef FILEIOSTD_H +#define FILEIOSTD_H + +//#include "slsDetectorBase.h" +#include "sls_detector_defs.h" +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; +/** + @short class handling the data file I/O flags +*/ + +class fileIO : public virtual slsDetectorDefs {//public virtual slsDetectorBase { + + + + public: + /** default constructor */ + fileIO(){}; + /** virtual destructor */ + virtual ~fileIO(){}; + + int setTotalNumberofChannels(int i){ if (i>=0) {totalNumberofChannels=i; return totalNumberofChannels;} else return -1;}; + int getTotalNumberofChannels(){ return totalNumberofChannels; }; + /** + sets the default output files path + \param s file path + \return actual file path + */ + string setFilePath(string s) {sprintf(filePath, s.c_str()); return string(filePath);}; + + /** + sets the default output files root name + \param s file name to be set + \returns actual file name + */ + string setFileName(string s) {sprintf(fileName, s.c_str()); return string(fileName);}; + + /** + sets the default output file index + \param i start file index to be set + \returns actual file index + */ + int setFileIndex(int i) {*fileIndex=i; return *fileIndex;}; + + + + /** + \returns the output files path + + */ + string getFilePath() {return string(filePath);}; + + /** + \returns the output files root name + */ + string getFileName() {return string(fileName);}; + + /** + \returns the output file index + */ + int getFileIndex() {return *fileIndex;}; + + + + + + + /** generates file name without extension + + always appends to file path and file name the run index. + + in case also appends the position index and the two level of scan varaibles with the specified precision + + Filenames will be of the form: filepath/filename(_Sy_sw_px)_i + where y is the scan0 variable, W is the scan 1 variable, x is the position index and i is the run index + \param filepath outdir + \param filename file root name + \param aMask action mask (scans, positions) + \param sv0 scan variable 0 + \param prec0 scan precision 0 + \param sv1 scan variable 1 + \param prec1 scan precision 1 + \param pindex position index + \param number of positions + \param findex file index + \returns file name without extension + */ + static string createFileName(char *filepath, char *filename, int aMask, double sv0, int prec0, double sv1, int prec1, int pindex, int npos, int findex); + + + string createFileName(int aMask, double sv0, int prec0, double sv1, int prec1, int pindex, int npos); + + + /** static function that returns the file index from the file name + \param fname file name + \returns file index + */ + int getFileIndexFromFileName(string fname); + + /** static function that returns the variables from the file name + \param fname file name + \param index reference to index + \param p_index reference to position index + \param sv0 reference to scan variable 0 + \param sv1 reference to scan variable 1 + \returns file index + */ + static int getVariablesFromFileName(string fname, int &index, int &p_index, double &sv0, double &sv1); + + + + + /** + + writes a data file + \param fname of the file to be written + \param data array of data values + \param err array of arrors on the data. If NULL no errors will be written + + \param ang array of angular values. If NULL data will be in the form chan-val(-err) otherwise ang-val(-err) + \param dataformat format of the data: can be 'i' integer or 'f' double (default) + \param nch number of channels to be written to file. if -1 defaults to the number of installed channels of the detector + \returns OK or FAIL if it could not write the file or data=NULL + + */ + virtual int writeDataFile(string fname, double *data, double *err=NULL, double *ang=NULL, char dataformat='f', int nch=-1); + + + /** + + writes a data file + \paramoutfile output file stream + \param data array of data values + \param err array of arrors on the data. If NULL no errors will be written + + \param ang array of angular values. If NULL data will be in the form chan-val(-err) otherwise ang-val(-err) + \param dataformat format of the data: can be 'i' integer or 'f' double (default) + \param nch number of channels to be written to file. if -1 defaults to the number of installed channels of the detector + \param offset start channel number + \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); + + + /** + writes a data file + \param fname of the file to be written + \param data array of data values + \returns OK or FAIL if it could not write the file or data=NULL + */ + virtual int writeDataFile(string fname, int *data); + + /** + writes a data file + \param outfile output file stream + \param data array of data values + \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); + + + + /** + writes a data file of short ints + \param fname of the file to be written + \param data array of data values + \returns OK or FAIL if it could not write the file or data=NULL + */ + virtual int writeDataFile(string fname, short int *data); + + /** + writes a data file of short ints + \param outfile output file stream + \param data array of data values + \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); + + + /** + reads a data file + \param fname of the file to be read + \param data array of data values to be filled + \param err array of arrors on the data. If NULL no errors are expected on the file + + \param ang array of angular values. If NULL data are expected in the form chan-val(-err) otherwise ang-val(-err) + \param dataformat format of the data: can be 'i' integer or 'f' double (default) + \returns OK or FAIL if it could not read the file or data=NULL + */ + virtual int readDataFile(string fname, double *data, double *err=NULL, double *ang=NULL, char dataformat='f'); + + /** + reads a data file + \param ifstream input file stream + \param data array of data values to be filled + \param err array of arrors on the data. If NULL no errors are expected on the file + + \param ang array of angular values. If NULL data are expected in the form chan-val(-err) otherwise ang-val(-err) + \param offset start channel number to be expected + \returns OK or FAIL if it could not read the file or data=NULL + */ + int readDataFile(ifstream& infile, double *data, double *err=NULL, double *ang=NULL, char dataformat='f', int offset=0); + + /** + reads a raw data file + \param fname of the file to be read + \param data array of data values + \returns OK or FAIL if it could not read the file or data=NULL + */ + virtual int readDataFile(string fname, int *data); /** + reads a raw data file + \param infile input file stream + \param data array of data values + \param offset first channel number to be expected + \returns OK or FAIL if it could not read the file or data=NULL + */ + int readDataFile(ifstream &infile, int *data, int offset=0); + + /** + + reads a short int raw data file + \param fname of the file to be read + \param data array of data values + \returns OK or FAIL if it could not read the file or data=NULL + */ + virtual int readDataFile(string fname, short int *data); + /** + reads a short int raw data file + \param infile input file stream + \param data array of data values + \param offset first channel number to be expected + \returns OK or FAIL if it could not read the file or data=NULL + */ + int readDataFile(ifstream &infile, short int *data, int offset=0); + + /** + + writes a data file + \param fname of the file to be written + \param nch number of channels to be written + \param data array of data values + \param err array of arrors on the data. If NULL no errors will be written + \param ang array of angular values. If NULL data will be in the form chan-val(-err) otherwise ang-val(-err) + \param dataformat format of the data: can be 'i' integer or 'f' double (default) + \returns OK or FAIL if it could not write the file or data=NULL + + */ + + static int writeDataFile(string fname, int nch, double *data, double *err=NULL, double *ang=NULL, char dataformat='f'); + /** + writes a data file + \param outfile output file stream + \param nch number of channels to be written + \param data array of data values + \param err array of arrors on the data. If NULL no errors will be written + \param ang array of angular values. If NULL data will be in the form chan-val(-err) otherwise ang-val(-err) + \param dataformat format of the data: can be 'i' integer or 'f' double (default) + \param offset start channel number + \returns OK or FAIL if it could not write the file or data=NULL + */ + static int writeDataFile(ofstream &outfile, int nch, double *data, double *err=NULL, double *ang=NULL, char dataformat='f', int offset=0); + + /** + writes a raw data file + \param fname of the file to be written + \param nch number of channels + \param data array of data values + \returns OK or FAIL if it could not write the file or data=NULL + */ + static int writeDataFile(string fname,int nch, int *data); + + /** + writes a raw data file + \param outfile output file stream + \param nch number of channels + \param data array of data values + \param offset start channel number + \returns OK or FAIL if it could not write the file or data=NULL + */ + static int writeDataFile(ofstream &outfile,int nch, int *data, int offset=0); + + + /** + + writes a short int raw data file + \param fname of the file to be written + \param nch number of channels + \param data array of data values + \returns OK or FAIL if it could not write the file or data=NULL + */ + static int writeDataFile(string fname,int nch, short int *data); + + /** + writes a short int raw data file + \param outfile output file stream + \param nch number of channels + \param data array of data values + \param offset start channel number + \returns OK or FAIL if it could not write the file or data=NULL + */ + static int writeDataFile(ofstream &outfile,int nch, short int *data, int offset=0); + + + /** + reads a data file + \param nch number of channels + \param fname of the file to be read + \param data array of data values to be filled + \param err array of arrors on the data. If NULL no errors are expected on the file + \param ang array of angular values. If NULL data are expected in the form chan-val(-err) otherwise ang-val(-err) + \param dataformat format of the data: can be 'i' integer or 'f' double (default) + \returns number of channels read or -1 if it could not read the file or data=NULL + + */ + static int readDataFile(int nch, string fname, double *data, double *err=NULL, double *ang=NULL, char dataformat='f'); + /** + reads a data file + \param nch number of channels + \param infile input file stream + \param data array of data values to be filled + \param err array of arrors on the data. If NULL no errors are expected on the file + \param ang array of angular values. If NULL data are expected in the form chan-val(-err) otherwise ang-val(-err) + \param dataformat format of the data: can be 'i' integer or 'f' double (default) + \param offset start channel number + \returns number of channels read or -1 if it could not read the file or data=NULL + + */ + static int readDataFile(int nch, ifstream &infile, double *data, double *err=NULL, double *ang=NULL, char dataformat='f', int offset=0); + + /** + reads a raw data file + \param fname of the file to be read + \param data array of data values + \param nch number of channels + \returns OK or FAIL if it could not read the file or data=NULL + */ + static int readDataFile(string fname, int *data, int nch); + + /** + reads a raw data file + \param infile input file stream + \param data array of data values + \param nch number of channels + \param offset start channel value + \returns OK or FAIL if it could not read the file or data=NULL + */ + static int readDataFile(ifstream &infile, int *data, int nch, int offset); + + /** + reads a short int rawdata file + \param name of the file to be read + \param data array of data values + \param nch number of channels + \returns OK or FAIL if it could not read the file or data=NULL + */ + static int readDataFile(string fname, short int *data, int nch); + /** + reads a short int raw data file + \param infile input file stream + \param data array of data values + \param nch number of channels + \param offset start channel value + \returns OK or FAIL if it could not read the file or data=NULL + */ + static int readDataFile(ifstream &infile, short int *data, int nch, int offset); + + + + + + void incrementFileIndex() { (*fileIndex)++;}; + + string getCurrentFileName(){return currentFileName;}; + + protected: + string currentFileName; + + + int mask_action; + double currentscan_variable[1]; + int scan_precision[1]; + int currentpostion_i; + int noposition; + + /** output directory */ + char *filePath; + /** file root name */ + char *fileName; + /** file index */ + int *fileIndex; + + private: + + int totalNumberofChannels; + + +}; + +#endif diff --git a/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp b/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp index 86a9aa3f9..d7d6b1867 100644 --- a/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp +++ b/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp @@ -14,6 +14,8 @@ postProcessing::postProcessing(){ pCallbackArg = 0; registerDataCallback(&defaultDataReadyFunc, NULL); //cout << "done "<< endl; + + } @@ -429,7 +431,7 @@ int postProcessing::fillBadChannelMask() { //badChannelMask=NULL; } } - + #ifdef VERBOSE cout << "number of bad channels is " << nbad << endl; #endif diff --git a/slsDetectorSoftware/slsDetectorAnalysis/postProcessingFileIO_Standalone.cpp b/slsDetectorSoftware/slsDetectorAnalysis/postProcessingFileIO_Standalone.cpp new file mode 100644 index 000000000..275003a6c --- /dev/null +++ b/slsDetectorSoftware/slsDetectorAnalysis/postProcessingFileIO_Standalone.cpp @@ -0,0 +1,602 @@ +#include "postProcessingFileIO_Standalone.h" +#include "usersFunctions.h" +//#include "externPostProcessing.h" + +postProcessing::postProcessing(){ + + pthread_mutex_t mp1 = PTHREAD_MUTEX_INITIALIZER; + mp=mp1; + pthread_mutex_init(&mp, NULL); + mg=mp1; + pthread_mutex_init(&mg, NULL); + //cout << "reg callback "<< endl; + dataReady = 0; + pCallbackArg = 0; + registerDataCallback(&defaultDataReadyFunc, NULL); + //cout << "done "<< endl; + angConv=new angularConversion(numberOfPositions,detPositions,binSize, fineOffset, globalOffset); + IOfile= new fileIO(); + + //registerCallBackGetChansPerMod(&getChannelPerMod,this); + registerCallBackGetNumberofChannel(&defaultGetTotalNumberofChannels,this); + //registerAngularConversionCallback(&defaultAngularConversion,this); +} + + + + + + +int postProcessing::flatFieldCorrect(double datain, double errin, double &dataout, double &errout, double ffcoefficient, double fferr){ + double e; + + dataout=datain*ffcoefficient; + + if (errin==0 && datain>=0) + e=sqrt(datain); + else + e=errin; + + if (dataout>0) + errout=sqrt(e*ffcoefficient*e*ffcoefficient+datain*fferr*datain*fferr); + else + errout=1.0; + + return 0; +}; + + + int postProcessing::rateCorrect(double datain, double errin, double &dataout, double &errout, double tau, double t){ + + // double data; + double e; + + dataout=(datain*exp(tau*datain/t)); + + if (errin==0 && datain>=0) + e=sqrt(datain); + else + e=errin; + + if (dataout>0) + errout=e*dataout*sqrt((1/(datain*datain)+tau*tau/(t*t))); + else + errout=1.; + return 0; + +}; + + + + + +int postProcessing::setBadChannelCorrection(ifstream &infile, int &nbad, int *badlist, int moff){ + + int interrupt=0; + int ich; + int chmin,chmax; + string str; + + + + nbad=0; + while (infile.good() and interrupt==0) { + getline(infile,str); +#ifdef VERBOSE + std::cout << str << std::endl; +#endif + istringstream ssstr; + ssstr.str(str); + if (ssstr.bad() || ssstr.fail() || infile.eof()) { + interrupt=1; + break; + } + if (str.find('-')!=string::npos) { + ssstr >> chmin ; + ssstr.str(str.substr(str.find('-')+1,str.size())); + ssstr >> chmax; +#ifdef VERBOSE + std::cout << "channels between"<< chmin << " and " << chmax << std::endl; +#endif + for (ich=chmin; ich<=chmax; ich++) { + if (nbad> ich; +#ifdef VERBOSE + std::cout << "channel "<< ich << std::endl; +#endif + if (nbadcreateFileName(getActionMask(),getCurrentScanVariable(0),getScanPrecision(0),getCurrentScanVariable(1),getScanPrecision(1),getCurrentPositionIndex(),getNumberOfPositions()); + +//Checking for write flag + if(*correctionMask&(1<writeDataFile (fname+string(".raw"),fdata, NULL, NULL, 'i'); + + } + + doProcessing(fdata,delflag, fname); + + delete [] myData; + myData=NULL; + fdata=NULL; + +#ifdef VERBOSE + cout << "Pop data queue " << *fileIndex << endl; +#endif + + pthread_mutex_lock(&mp); + dataQueue.pop(); //remove the data from the queue + queuesize=dataQueue.size(); + pthread_mutex_unlock(&mp); + + +} + + + + +void postProcessing::doProcessing(double *lfdata, int delflag, string fname) { + + +// /** write raw data file */ +// if (*correctionMask==0 && delflag==1) { +// // delete [] fdata; +// ; +// } else { + + + + double *rcdata=NULL, *rcerr=NULL; + double *ffcdata=NULL, *ffcerr=NULL; + double *ang=NULL; + // int imod; + int np; + //string fname; + detectorData *thisData; + + + string ext=".dat"; + // fname=createFileName(); + + /** rate correction */ + if (*correctionMask&(1<writeDataFile (fname+ext, ffcdata, ffcerr,ang);} + } + + if (*correctionMask&(1<< ANGULAR_CONVERSION) && getNumberOfPositions()>0) { +#ifdef VERBOSE + cout << "**************Current position index is " << getCurrentPositionIndex() << endl; +#endif + // if (*numberOfPositions>0) {setTotalNumberOfChannels + if (getCurrentPositionIndex()<=1) { + +#ifdef VERBOSE + cout << "reset merging " << endl; +#endif + angConv->resetMerging(); + } + +#ifdef VERBOSE + cout << "add to merging "<< getCurrentPositionIndex() << endl; +#endif + + angConv->addToMerging(ang, ffcdata, ffcerr, badChannelMask ); + +#ifdef VERBOSE + cout << getCurrentPositionIndex() << " " << getNumberOfPositions() << endl; + +#endif + + + // cout << "lock 1" << endl; + pthread_mutex_lock(&mp); + if ((getCurrentPositionIndex()>=getNumberOfPositions() && posfinished==1 && queuesize==1)) { + +#ifdef VERBOSE + cout << "finalize merging " << getCurrentPositionIndex()<< endl; +#endif + np=angConv->finalizeMerging(); + /** file writing */ + angConv->incrementPositionIndex(); + // cout << "unlock 1" << endl; + pthread_mutex_unlock(&mp); + + + fname=IOfile->createFileName(getActionMask(),getCurrentScanVariable(0),getScanPrecision(0),getCurrentScanVariable(1),getScanPrecision(1),getCurrentPositionIndex(),getNumberOfPositions()); + +#ifdef VERBOSE + cout << "writing merged data file" << endl; +#endif + if(*correctionMask&(1<writeDataFile (fname+ext,np,angConv->getMergedCounts(), angConv->getMergedErrors(), angConv->getMergedPositions(),'f');} +#ifdef VERBOSE + cout << " done" << endl; +#endif + + + +// if (delflag) { +// deleteMerging(); +// } else { + thisData=new detectorData(angConv->getMergedCounts(),angConv->getMergedErrors(),angConv->getMergedPositions(),getCurrentProgress(),(fname+ext).c_str(),np); + + // // cout << "lock 2" << endl; +// pthread_mutex_lock(&mg); +// finalDataQueue.push(thisData); +// // cout << "unlock 2" << endl; + +// pthread_mutex_unlock(&mg); + + if (dataReady) { + + dataReady(thisData, pCallbackArg); + delete thisData; + } + +// } + // cout << "lock 3" << endl; + pthread_mutex_lock(&mp); + } + // cout << "unlock 3" << endl; + pthread_mutex_unlock(&mp); + + if (ffcdata) + delete [] ffcdata; + + ffcdata=NULL; + + if (ffcerr) + delete [] ffcerr; + ffcerr=NULL; + + if (ang) + delete [] ang; + ang=NULL; + + } else { +// if (delflag) { +// if (ffcdata) +// delete [] ffcdata; +// if (ffcerr) +// delete [] ffcerr; +// if ( ang) +// delete [] ang; +// } else { + thisData=new detectorData(ffcdata,ffcerr,NULL,getCurrentProgress(),(fname+ext).c_str(),getTotalNumberOfChannels()); + + + if (dataReady) { + dataReady(thisData, pCallbackArg); + delete thisData; + } +// pthread_mutex_lock(&mg); +// finalDataQueue.push(thisData); + + +// pthread_mutex_unlock(&mg); +// } + } + //} + + if(*correctionMask&(1<incrementFileIndex();} +#ifdef VERBOSE + cout << "fdata is " << fdata << endl; +#endif + +} + + + + + +int postProcessing::fillBadChannelMask() { + + int nbad=0; + + if (*correctionMask&(1<< DISCARD_BAD_CHANNELS)) { + nbad=getBadChannelCorrection(); +#ifdef VERBOSE + cout << "number of bad channels is " << nbad << endl; +#endif + if (nbad>0) { + + int *badChansList=new int[nbad]; + getBadChannelCorrection(badChansList); + + if (badChannelMask) + delete [] badChannelMask; + badChannelMask=new int[getTotalNumberOfChannels()]; + +#ifdef VERBOSE + cout << " pointer to bad channel mask is " << badChannelMask << endl; +#endif + for (int ichan=0; ichan=0 ) { + if (badChannelMask[badChansList[ichan]]==0) + nbad++; + badChannelMask[badChansList[ichan]]=1; + + } + } + delete [] badChansList; + + } else { + if (badChannelMask) { +#ifdef VERBOSE + cout << "deleting bad channel mask beacuse number of bad channels is 0" << endl; +#endif + + delete [] badChannelMask; + badChannelMask=NULL; + } + } + + } else { +#ifdef VERBOSE + cout << "bad channel correction is disabled " << nbad << endl; +#endif + if (badChannelMask) { +#ifdef VERBOSE + cout << "deleting bad channel mask beacuse no bad channel correction is selected" << endl; +#endif + delete [] badChannelMask; + badChannelMask=NULL; + } + } + +#ifdef VERBOSE + cout << "number of bad channels is " << nbad << endl; +#endif + return nbad; + +} + + + + + + +void* postProcessing::processData(int delflag) { + + +#ifdef VERBOSE + std::cout<< " processing data - threaded mode " << *threadedProcessing << endl; +#endif + + + angConv->setTotalNumberOfChannels(getTotalNumberOfChannels()); + IOfile->setTotalNumberofChannels(getTotalNumberOfChannels()); + setTotalProgress(); + pthread_mutex_lock(&mp); + queuesize=dataQueue.size(); + pthread_mutex_unlock(&mp); + + int *myData; + int dum=1; + + fdata=NULL; + + + while(dum | *threadedProcessing) { // ???????????????????????? + + + /* IF THERE ARE DATA PROCESS THEM*/ + pthread_mutex_lock(&mp); + while((queuesize=dataQueue.size())>0) { + /** Pop data queue */ + myData=dataQueue.front(); // get the data from the queue + pthread_mutex_unlock(&mp); + + if (myData) { + processFrame(myData,delflag); + //usleep(1000); + } + pthread_mutex_lock(&mp); + + } + pthread_mutex_unlock(&mp); + + /* IF THERE ARE NO DATA look if acquisition is finished */ + pthread_mutex_lock(&mp); + if (jointhread) { + if (dataQueue.size()==0) { + pthread_mutex_unlock(&mp); + break; + } + pthread_mutex_unlock(&mp); + } else { + pthread_mutex_unlock(&mp); + } + dum=0; + } + + if (fdata) { +#ifdef VERBOSE + cout << "delete fdata" << endl; +#endif + delete [] fdata; +#ifdef VERBOSE + cout << "done " << endl; +#endif + } + return 0; +} + + +int* postProcessing::popDataQueue() { + int *retval=NULL; + if( !dataQueue.empty() ) { + retval=dataQueue.front(); + dataQueue.pop(); + } + 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; + while( !dataQueue.empty() ) { + retval=dataQueue.front(); + dataQueue.pop(); + delete [] retval; + } + +} + +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::startThread(int delflag) { + pthread_attr_t tattr; + int ret; + sched_param param, mparam; + int policy= SCHED_OTHER; + + + // set the priority; others are unchanged + //newprio = 30; + mparam.sched_priority =1; + param.sched_priority =1; + + + /* Initialize and set thread detached attribute */ + pthread_attr_init(&tattr); + pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_JOINABLE); + + + + // param.sched_priority = 5; + // scheduling parameters of main thread + ret = pthread_setschedparam(pthread_self(), policy, &mparam); + //#ifdef VERBOSE + // printf("current priority is %d\n",param.sched_priority); + //#endif + if (delflag) + ret = pthread_create(&dataProcessingThread, &tattr,startProcessData, (void*)this); + else + ret = pthread_create(&dataProcessingThread, &tattr,startProcessDataNoDelete, (void*)this); + + pthread_attr_destroy(&tattr); + // scheduling parameters of target thread + ret = pthread_setschedparam(dataProcessingThread, policy, ¶m); + +} + + + diff --git a/slsDetectorSoftware/slsDetectorAnalysis/postProcessingFileIO_Standalone.h b/slsDetectorSoftware/slsDetectorAnalysis/postProcessingFileIO_Standalone.h new file mode 100644 index 000000000..451b5ccbc --- /dev/null +++ b/slsDetectorSoftware/slsDetectorAnalysis/postProcessingFileIO_Standalone.h @@ -0,0 +1,391 @@ +#ifndef POSTPROCESSING_H +#define POSTPROCESSING_H + + +#include "detectorData.h" +#include "sls_detector_defs.h" +#include "slsDetectorBase.h" +#include "slsDetectorUsers.h" +#include "FileIO_Standalone.h" +#include "AngularConversion_Standalone.h" +//#include "externPostProcessing.h" + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + + +class angularConversion; +class fileIO; + +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 */ + + +/** + @short methods for data postprocessing + + (including thread for writing data files and plotting in parallel with the acquisition) +*/ + +class postProcessing : public virtual slsDetectorBase { + + +//: 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(double *corr=NULL, double *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(double *corr, double *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; + + static int setBadChannelCorrection(ifstream &infile, int &nbad, int *badlist, int moff=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 + */ + virtual int setBadChannelCorrection(string fname, int &nbad, int *badlist, int off=0)=0; + + + /** + 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(double datain, double errin, double &dataout, double &errout, double ffcoefficient, double 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(double datain, double errin, double &dataout, double &errout, double tau, double t); + + + int enableWriteToFile(int i=-1) {if (i>0) ((*correctionMask)|=(1<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<=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(double* myData, int delflag, string fname); + + + /** + 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 int rateCorrect(double*, double*, double*, double*)=0; + virtual int flatFieldCorrect(double*, double*, double*, double*)=0; + + + + + + //void registerAngularConversionCallback(int (*sAngularConversion)(int & ,angleConversionConstant* ,void *), void *arg){seAngularConversion=sAngularConversion; pAngular= arg; }; + + void registerDataCallback(int( *userCallback)(detectorData*, void*), void *pArg) {dataReady = userCallback; pCallbackArg = pArg;}; + + void registerCallBackGetNumberofChannel(int (*func)(int, void *),void *arg){ getNoChannel=func;pNumberofChannel=arg;}; + + + + /** + sets the angular conversion file + \param fname file to read + \returns angular conversion flag + */ + + int setAngularConversionFile(string fname); + + //static int defaultAngularConversion(int &direc, angleConversionConstant *angoff,void *p=NULL){ return ((postProcessing *)p)->getAngularConversion( direc,angleConversionConstant *angoff=NULL);}; + /** + returns the angular conversion file + */ + string getAngularConversionFile(){if (setAngularCorrectionMask()) return string(angConvFile); else return string("none");}; + + //static int setAngularConversion(); + + static int defaultGetTotalNumberofChannels (int nChannel, void *p=NULL){ if(nChannel>=0){ return ((postProcessing*)p)->getTotalNumberOfChannels();} else return -1;}; + + protected: + + int *threadedProcessing; + + int *correctionMask; + + char *flatFieldDir; + char *flatFieldFile; + + char *badChanFile; + int *nBadChans; + int *badChansList; + int *nBadFF; + int *badFFList; + int *direction; + + /** pointer to angular conversion file name*/ + char *angConvFile; + + + /** 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 dataQueue; + /** + queue containing the postprocessed data + */ + queue 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 + */ + double currentI0; + + double *fdata; + + int (*seAngularConversion)(int & ,angleConversionConstant* ,void*); + int (*getNoChannel)(int ,void*); + int (*dataReady)(detectorData*,void*); + void *pCallbackArg, *pChpermod,*pNumberofChannel,*pAngular; + + + + private: + + angularConversion *angConv; + fileIO *IOfile; + + /** pointer to beamlien fine offset*/ + double *fineOffset; + /** pointer to beamlien global offset*/ + double *globalOffset; + /** pointer to number of positions for the acquisition*/ + int *numberOfPositions; + + /** pointer to the detector positions for the acquisition*/ + double *detPositions; + + angleConversionConstant angcc[MAXMODS*MAXDET]; + + + /** pointer to angular bin size*/ + double *binSize; + + +}; + + +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 diff --git a/slsDetectorSoftware/slsDetectorAnalysis/postProcessing_Standalone.cpp b/slsDetectorSoftware/slsDetectorAnalysis/postProcessing_Standalone.cpp index 46b9744f5..185d811ad 100644 --- a/slsDetectorSoftware/slsDetectorAnalysis/postProcessing_Standalone.cpp +++ b/slsDetectorSoftware/slsDetectorAnalysis/postProcessing_Standalone.cpp @@ -1,7 +1,8 @@ #include "postProcessing.h" #include "usersFunctions.h" -#include "angularConversion.h" +//#include "angularConversion.h" +//#include "AngularConversion_Standalone.h" postProcessing::postProcessing(){ pthread_mutex_t mp1 = PTHREAD_MUTEX_INITIALIZER; @@ -13,6 +14,7 @@ postProcessing::postProcessing(){ dataReady = 0; pCallbackArg = 0; registerDataCallback(&defaultDataReadyFunc, NULL); + //tregisterCallBackGetChansPerMod(&defaultGetChansPerMod,NULL); //cout << "done "<< endl; angConv=new angularConversion(numberOfPositions,detPositions,binSize, fineOffset, globalOffset); } diff --git a/slsDetectorSoftware/slsDetectorAnalysis/postProcessing_Standalone.h b/slsDetectorSoftware/slsDetectorAnalysis/postProcessing_Standalone.h index 661ad7b80..2006553d4 100644 --- a/slsDetectorSoftware/slsDetectorAnalysis/postProcessing_Standalone.h +++ b/slsDetectorSoftware/slsDetectorAnalysis/postProcessing_Standalone.h @@ -58,7 +58,7 @@ class postProcessing : public virtual fileIO { \param ecorr if !=NULL will be filled with the correction coefficients errors \returns 0 if ff correction disabled, >0 otherwise */ - virtual int getFlatFieldCorrection(double *corr=NULL, double *ecorr=NULL)=0; + virtual int getFlatFieldCorrection(float *corr=NULL, float *ecorr=NULL)=0; /** set flat field corrections @@ -66,7 +66,7 @@ class postProcessing : public virtual fileIO { \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(double *corr, double *ecorr=NULL)=0; + virtual int setFlatFieldCorrection(float *corr, float *ecorr=NULL)=0; /** set bad channels correction @@ -79,6 +79,8 @@ class postProcessing : public virtual fileIO { /** set bad channels correction \param fname file with bad channel list ("" disable) + +ff \param nbad reference to number of bad channels \param badlist array of badchannels \returns 0 if bad channel disabled, >0 otherwise @@ -105,7 +107,7 @@ class postProcessing : public virtual fileIO { \param fferr erro on ffcoefficient \returns 0 */ - static int flatFieldCorrect(double datain, double errin, double &dataout, double &errout, double ffcoefficient, double fferr); + static int flatFieldCorrect(float datain, float errin, float &dataout, float &errout, float ffcoefficient, float fferr); /** rate correct data @@ -117,7 +119,7 @@ class postProcessing : public virtual fileIO { \param t acquisition time (in ns) \returns 0 */ - static int rateCorrect(double datain, double errin, double &dataout, double &errout, double tau, double t); + static int rateCorrect(float datain, float errin, float &dataout, float &errout, float tau, float t); int enableWriteToFile(int i=-1) {if (i>0) ((*correctionMask)|=(1<