diff --git a/slsDetectorSoftware/commonFiles/sls_detector_funcs.h b/slsDetectorSoftware/commonFiles/sls_detector_funcs.h index 8c4612339..b0c63f366 100644 --- a/slsDetectorSoftware/commonFiles/sls_detector_funcs.h +++ b/slsDetectorSoftware/commonFiles/sls_detector_funcs.h @@ -100,7 +100,8 @@ enum { F_PULSE_PIXEL_AND_MOVE, /** < pulse pixel n number of times and move relatively by x and y */ F_PULSE_CHIP, /** < pulse chip n number of times */ - F_SET_RATE_CORRECT /** < set/reset rate correction tau */ + F_SET_RATE_CORRECT, /** < set/reset rate correction tau */ + F_GET_RATE_CORRECT, /** < get rate correction tau */ /* Always append functions hereafter!!! */ diff --git a/slsDetectorSoftware/eigerDetectorServer/bin/eigerDetectorServerv2.0.3.11.2 b/slsDetectorSoftware/eigerDetectorServer/bin/eigerDetectorServerv2.0.3.11.3 similarity index 55% rename from slsDetectorSoftware/eigerDetectorServer/bin/eigerDetectorServerv2.0.3.11.2 rename to slsDetectorSoftware/eigerDetectorServer/bin/eigerDetectorServerv2.0.3.11.3 index 045995ec4..2ad0e4c98 100755 Binary files a/slsDetectorSoftware/eigerDetectorServer/bin/eigerDetectorServerv2.0.3.11.2 and b/slsDetectorSoftware/eigerDetectorServer/bin/eigerDetectorServerv2.0.3.11.3 differ diff --git a/slsDetectorSoftware/eigerDetectorServer/gitInfo.txt b/slsDetectorSoftware/eigerDetectorServer/gitInfo.txt index 21cc06104..4aede902d 100644 --- a/slsDetectorSoftware/eigerDetectorServer/gitInfo.txt +++ b/slsDetectorSoftware/eigerDetectorServer/gitInfo.txt @@ -1,9 +1,9 @@ Path: slsDetectorsPackage/slsDetectorSoftware/eigerDetectorServer URL: origin git@git.psi.ch:sls_detectors_software/sls_detector_software.git/eigerDetectorServer Repository Root: origin git@git.psi.ch:sls_detectors_software/sls_detector_software.git -Repsitory UUID: 769ba51f2796ac8088f29a6cdb87955befbbdae2 -Revision: 201 +Repsitory UUID: f65bc993ef8b3548b52e677b3f42ae6229611d73 +Revision: 203 Branch: developer Last Changed Author: Dhanya_Maliakal -Last Changed Rev: 326 -Last Changed Date: 2016-07-05 17:24:44 +0200 +Last Changed Rev: 327 +Last Changed Date: 2016-07-12 16:45:00 +0200 diff --git a/slsDetectorSoftware/eigerDetectorServer/gitInfoEiger.h b/slsDetectorSoftware/eigerDetectorServer/gitInfoEiger.h index 4457f1185..a96e67f0c 100644 --- a/slsDetectorSoftware/eigerDetectorServer/gitInfoEiger.h +++ b/slsDetectorSoftware/eigerDetectorServer/gitInfoEiger.h @@ -1,11 +1,11 @@ //#define SVNPATH "" #define SVNURL "git@git.psi.ch:sls_detectors_software/sls_detector_software.git/eigerDetectorServer" //#define SVNREPPATH "" -#define SVNREPUUID "769ba51f2796ac8088f29a6cdb87955befbbdae2" -//#define SVNREV 0x326 +#define SVNREPUUID "f65bc993ef8b3548b52e677b3f42ae6229611d73" +//#define SVNREV 0x327 //#define SVNKIND "" //#define SVNSCHED "" #define SVNAUTH "Dhanya_Maliakal" -#define SVNREV 0x326 -#define SVNDATE 0x20160705 +#define SVNREV 0x327 +#define SVNDATE 0x20160712 // diff --git a/slsDetectorSoftware/eigerDetectorServer/slsDetectorFunctionList.c b/slsDetectorSoftware/eigerDetectorServer/slsDetectorFunctionList.c index 29911ac53..2d568fcd2 100644 --- a/slsDetectorSoftware/eigerDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorSoftware/eigerDetectorServer/slsDetectorFunctionList.c @@ -12,6 +12,8 @@ #include "FebControl.h" #include "Beb.h" +int default_tau_from_file= -1; + #define BEB_NUM 34 enum detectorSettings thisSettings; @@ -535,16 +537,21 @@ int getRateCorrectionEnable(){ } int getDefaultSettingsTau_in_nsec(){ - switch(thisSettings){ - case STANDARD: return STANDARD_TAU; - case HIGHGAIN: return HIGHGAIN_TAU; - case LOWGAIN: return LOWGAIN_TAU; - default: return -1; - } + return default_tau_from_file; } +int64_t getCurrentTau(){ + if(!getRateCorrectionEnable()) + return 0; + else + return Feb_Control_Get_RateTable_Tau_in_nsec(); +} -int setModule(sls_detector_module myMod, int* gain, int* offset,int* delay, int64_t tau_ns){ +void setDefaultSettingsTau_in_nsec(int t){ + default_tau_from_file = t; +} + +int setModule(sls_detector_module myMod, int* gain, int* offset,int* delay){ int retval[2]; int i; @@ -555,32 +562,6 @@ int setModule(sls_detector_module myMod, int* gain, int* offset,int* delay, int6 //set the settings variable setSettings( (enum detectorSettings)myMod.reg,-1); - - //rate correction (ignore -2: from load settings) - if(tau_ns > -2){ - //set settings, with no tau in calib file - if(tau_ns == -1){ - tau_ns = getDefaultSettingsTau_in_nsec(); - //incorrect settings - if(tau_ns < 0) - return -1; - } - //set the tau for all - int64_t rate_retval = setRateCorrection(tau_ns); //tau_ns will not be -1 here - if(tau_ns != rate_retval){ - if(rate_retval == -1) - return -2; - else - return -3; - } - //set settings, with no tau in calib file : - //only setting tau, rate correction should be off - //(in previous "error" returns, its switched off anyway) - if(tau_ns == -1) - setRateCorrection(0); - }else cprintf(RED,"rate not changed\n"); - - //set the gains and offset variables locally for(i=0;i=0){ @@ -629,7 +610,7 @@ int setModule(sls_detector_module myMod, int* gain, int* offset,int* delay, int6 return FAIL; } - return 0; + return thisSettings; } @@ -728,6 +709,9 @@ enum detectorSettings setSettings(enum detectorSettings sett, int imod){ return thisSettings; } +enum detectorSettings getSettings(){ + return thisSettings; +} int startReceiver(int d){ printf("Going to prepare for acquisition with counter_bit:%d\n",Feb_Control_Get_Counter_Bit()); diff --git a/slsDetectorSoftware/eigerDetectorServer/slsDetectorServer_defs.h b/slsDetectorSoftware/eigerDetectorServer/slsDetectorServer_defs.h index c41e5cdbf..aa52415a8 100644 --- a/slsDetectorSoftware/eigerDetectorServer/slsDetectorServer_defs.h +++ b/slsDetectorSoftware/eigerDetectorServer/slsDetectorServer_defs.h @@ -40,12 +40,5 @@ enum detDacIndex{SVP,VTR,VRF,VRS,SVN,VTGSTV,VCMP_LL,VCMP_LR,CAL,VCMP_RL,RXB_RB,RXB_LB,VCMP_RR,VCP,VCN,VIS,VTHRESHOLD}; -enum defaultTauValues{ - HIGHGAIN_TAU=410, - STANDARD_TAU=290, - LOWGAIN_TAU=180}; - - - #endif /* SLSDETECTORSERVER_DEFS_H_ */ diff --git a/slsDetectorSoftware/gitInfo.txt b/slsDetectorSoftware/gitInfo.txt index ff4d07177..21995d17e 100644 --- a/slsDetectorSoftware/gitInfo.txt +++ b/slsDetectorSoftware/gitInfo.txt @@ -1,9 +1,9 @@ Path: slsDetectorsPackage/slsDetectorSoftware URL: origin git@git.psi.ch:sls_detectors_software/sls_detector_software.git Repository Root: origin git@git.psi.ch:sls_detectors_software/sls_detector_software.git -Repsitory UUID: 769ba51f2796ac8088f29a6cdb87955befbbdae2 -Revision: 1103 +Repsitory UUID: f65bc993ef8b3548b52e677b3f42ae6229611d73 +Revision: 1109 Branch: developer Last Changed Author: Dhanya_Maliakal -Last Changed Rev: 1103 -Last Changed Date: 2016-07-05 17:24:44 +0200 +Last Changed Rev: 1109 +Last Changed Date: 2016-07-12 16:45:00 +0200 diff --git a/slsDetectorSoftware/gotthardDetectorServer/gitInfo.txt b/slsDetectorSoftware/gotthardDetectorServer/gitInfo.txt index feecb2fe1..ccc7dba44 100644 --- a/slsDetectorSoftware/gotthardDetectorServer/gitInfo.txt +++ b/slsDetectorSoftware/gotthardDetectorServer/gitInfo.txt @@ -1,9 +1,9 @@ Path: slsDetectorsPackage/slsDetectorSoftware/gotthardDetectorServer URL: origin git@git.psi.ch:sls_detectors_software/sls_detector_software.git/gotthardDetectorServer Repository Root: origin git@git.psi.ch:sls_detectors_software/sls_detector_software.git -Repsitory UUID: 769ba51f2796ac8088f29a6cdb87955befbbdae2 -Revision: 193 +Repsitory UUID: f65bc993ef8b3548b52e677b3f42ae6229611d73 +Revision: 194 Branch: developer Last Changed Author: Dhanya_Maliakal -Last Changed Rev: 326 -Last Changed Date: 2016-07-05 17:24:44 +0200 +Last Changed Rev: 327 +Last Changed Date: 2016-07-12 16:45:00 +0200 diff --git a/slsDetectorSoftware/gotthardDetectorServer/gitInfoGotthard.h b/slsDetectorSoftware/gotthardDetectorServer/gitInfoGotthard.h index 703367eae..fe0441c2c 100644 --- a/slsDetectorSoftware/gotthardDetectorServer/gitInfoGotthard.h +++ b/slsDetectorSoftware/gotthardDetectorServer/gitInfoGotthard.h @@ -1,11 +1,11 @@ //#define SVNPATH "" #define SVNURL "git@git.psi.ch:sls_detectors_software/sls_detector_software.git/gotthardDetectorServer" //#define SVNREPPATH "" -#define SVNREPUUID "769ba51f2796ac8088f29a6cdb87955befbbdae2" -//#define SVNREV 0x326 +#define SVNREPUUID "f65bc993ef8b3548b52e677b3f42ae6229611d73" +//#define SVNREV 0x327 //#define SVNKIND "" //#define SVNSCHED "" #define SVNAUTH "Dhanya_Maliakal" -#define SVNREV 0x326 -#define SVNDATE 0x20160705 +#define SVNREV 0x327 +#define SVNDATE 0x20160712 // diff --git a/slsDetectorSoftware/moenchDetectorServer/gitInfo.txt b/slsDetectorSoftware/moenchDetectorServer/gitInfo.txt index f02addb2f..4124ace98 100644 --- a/slsDetectorSoftware/moenchDetectorServer/gitInfo.txt +++ b/slsDetectorSoftware/moenchDetectorServer/gitInfo.txt @@ -1,9 +1,9 @@ Path: slsDetectorsPackage/slsDetectorSoftware/moenchDetectorServer URL: origin git@git.psi.ch:sls_detectors_software/sls_detector_software.git/moenchDetectorServer Repository Root: origin git@git.psi.ch:sls_detectors_software/sls_detector_software.git -Repsitory UUID: 769ba51f2796ac8088f29a6cdb87955befbbdae2 -Revision: 76 +Repsitory UUID: f65bc993ef8b3548b52e677b3f42ae6229611d73 +Revision: 77 Branch: developer Last Changed Author: Dhanya_Maliakal -Last Changed Rev: 326 -Last Changed Date: 2016-07-05 17:24:44 +0200 +Last Changed Rev: 327 +Last Changed Date: 2016-07-12 16:45:00 +0200 diff --git a/slsDetectorSoftware/moenchDetectorServer/gitInfoMoench.h b/slsDetectorSoftware/moenchDetectorServer/gitInfoMoench.h index 1830efbef..2370e9a5c 100644 --- a/slsDetectorSoftware/moenchDetectorServer/gitInfoMoench.h +++ b/slsDetectorSoftware/moenchDetectorServer/gitInfoMoench.h @@ -1,11 +1,11 @@ //#define SVNPATH "" #define SVNURL "git@git.psi.ch:sls_detectors_software/sls_detector_software.git/moenchDetectorServer" //#define SVNREPPATH "" -#define SVNREPUUID "769ba51f2796ac8088f29a6cdb87955befbbdae2" -//#define SVNREV 0x326 +#define SVNREPUUID "f65bc993ef8b3548b52e677b3f42ae6229611d73" +//#define SVNREV 0x327 //#define SVNKIND "" //#define SVNSCHED "" #define SVNAUTH "Dhanya_Maliakal" -#define SVNREV 0x326 -#define SVNDATE 0x20160705 +#define SVNREV 0x327 +#define SVNDATE 0x20160712 // diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index 16832ce3f..6acd95006 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -421,7 +421,8 @@ void multiSlsDetector::updateOffsets(){ for (int i=0; inumberOfDetectors; i++) { if (detectors[i]) { - cout<<"offsetY:"<getTotalNumberOfChannels(Y) <<" maxChanY:"<getTotalNumberOfChannels(Y) <<" maxChanY:"< 0) && ((offsetX + prevChanX + detectors[i]->getTotalNumberOfChannels(X)) > maxChanX)) cout<<"\nDetector[" << i << "] exceeds maximum channels allowed for complete detector set in X dimension!" << endl; offsetY = 0; - prevChanY = 0; + prevChanY = detectors[i]->getTotalNumberOfChannels(Y);; numY = 0; //assuming symmetry with this statement. whats on 1st column should be on 2nd column maxY = 0; offsetX += prevChanX; @@ -1740,15 +1741,6 @@ int64_t multiSlsDetector::setTimer(timerIndex index, int64_t t){ // check return values!!! thisMultiDetector->timerValue[index]=ret1; - - - if (getDetectorsType() == EIGER) { - //if subexptime set, update rate correction in server and update result in multi client - double r; - if((index == SUBFRAME_ACQUISITION_TIME) && (t>=0) && getRateCorrection(r)){ - setRateCorrection(r); - } - } return ret1; }; @@ -2547,19 +2539,31 @@ int multiSlsDetector::flatFieldCorrect(double* datain, double *errin, double* da int multiSlsDetector::setRateCorrection(double t){ - // double tdead[]=defaultTDead; - if (getDetectorsType() == MYTHEN){ #ifdef VERBOSE - std::cout<< "Setting rate correction with dead time "<< thisMultiDetector->tDead << std::endl; + std::cout<< "Setting rate correction with dead time "<< thisMultiDetector->tDead << std::endl; #endif - if (t==0) { - thisMultiDetector->correctionMask&=~(1<correctionMask&(1<correctionMask|=(1<numberOfDetectors; idet++) { + if (detectors[idet]) { + ret=detectors[idet]->setRateCorrection(t); + if(detectors[idet]->getErrorMask()) + setErrorMask(getErrorMask()|(1<correctionMask&=~(1<correctionMask&(1<correctionMask|=(1<numberOfDetectors; idet++) { @@ -2574,76 +2578,62 @@ int multiSlsDetector::setRateCorrection(double t){ } } - if (getDetectorsType() != MYTHEN){ - if (ret1==0) - thisMultiDetector->correctionMask&=~(1<correctionMask|=(1<correctionMask&(1<correctionMask&(1<correctionMask&(1<tDead << std::endl; + std::cout<< "Rate correction is enabled with dead time "<< thisMultiDetector->tDead << std::endl; #endif - return 1; - } else - t=0; + return 1; + } else + t=0; #ifdef VERBOSE - std::cout<< "Rate correction is disabled " << std::endl; + std::cout<< "Rate correction is disabled " << std::endl; #endif - return 0; + return 0; }; double multiSlsDetector::getRateCorrectionTau(){ - double ret1=-100,ret; - for (int idet=0; idetnumberOfDetectors; idet++) { - if (detectors[idet]) { - ret=detectors[idet]->getRateCorrectionTau(); - if (ret1==-100) - ret1=ret; - else if (ret!=ret1){ - std::cout<< "Rate correction is different for different readouts " << std::endl; - if(getDetectorsType() == EIGER) - ret1=-2; - else - ret1=-1; //same settings also return -1 - } - } - } + double ret1=-100,ret; + for (int idet=0; idetnumberOfDetectors; idet++) { + if (detectors[idet]) { + ret=detectors[idet]->getRateCorrectionTau(); + if (ret1==-100) + ret1=ret; + else if (ret!=ret1){ + std::cout<< "Rate correction is different for different readouts " << std::endl; + ret1=-1; + } + } + } - if (getDetectorsType() != MYTHEN){ - //if set by the slsDetector - if(ret1 == 0) - thisMultiDetector->correctionMask&=~(1<correctionMask|=(1<correctionMask&(1<correctionMask&(1<tDead << std::endl; + std::cout<< "Rate correction is enabled with dead time "<< thisMultiDetector->tDead << std::endl; #endif - } else { + } else { #ifdef VERBOSE - std::cout<< "Rate correction is disabled " << std::endl; + std::cout<< "Rate correction is disabled " << std::endl; #endif - ret1=0; - } - return ret1; + ret1=0; + } + return ret1; }; @@ -2651,6 +2641,10 @@ double multiSlsDetector::getRateCorrectionTau(){ int multiSlsDetector::getRateCorrection(){ + if (getDetectorsType() == EIGER){ + return getRateCorrectionTau(); + } + if (thisMultiDetector->correctionMask&(1<onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK){ - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - sendModule(&module); + if (thisDetector->onlineFlag==ONLINE_FLAG) { + if (connectControl() == OK){ + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + sendModule(&module); - //extra gain and offset - eiger - if((thisDetector->nGain) && (gainval)) - controlSocket->SendDataOnly(gainval,sizeof(int)*thisDetector->nGain); - if((thisDetector->nOffset) && (offsetval)) - controlSocket->SendDataOnly(offsetval,sizeof(int)*thisDetector->nOffset); - if(thisDetector->myDetectorType == EIGER) - controlSocket->SendDataOnly(iodelay,sizeof(int)); - if(thisDetector->myDetectorType == EIGER) - controlSocket->SendDataOnly(&tau,sizeof(tau)); + //extra gain and offset - eiger + if((thisDetector->nGain) && (gainval)) + controlSocket->SendDataOnly(gainval,sizeof(int)*thisDetector->nGain); + if((thisDetector->nOffset) && (offsetval)) + controlSocket->SendDataOnly(offsetval,sizeof(int)*thisDetector->nOffset); + if(thisDetector->myDetectorType == EIGER){ + controlSocket->SendDataOnly(iodelay,sizeof(int)); + controlSocket->SendDataOnly(&tau,sizeof(tau)); + } - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret!=FAIL) { - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - } else { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned error: " << mess << std::endl; - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); - } - } + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret!=FAIL) + controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); + else { + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + } + disconnectControl(); + if (ret==FORCE_UPDATE) + updateDetector(); + } + } - if(ret == FAIL && thisDetector->myDetectorType == EIGER && strcasestr(mess,"Rate")){ - setErrorMask((getErrorMask())|(COULD_NOT_SET_RATE_CORRECTION)); - if(strcasestr(mess,"tau/subexptime")) - setErrorMask((getErrorMask())|(RATE_CORRECTION_TAU_SUBEXPOSURE)); - thisDetector->correctionMask&=~(1<tDead = 0; - } - if (ret!=FAIL) { - if (detectorModules) { - if (imod>=0 && imodnMod[X]*thisDetector->nMod[Y]) { - (detectorModules+imod)->nchan=module.nchan; - (detectorModules+imod)->nchip=module.nchip; - (detectorModules+imod)->ndac=module.ndac; - (detectorModules+imod)->nadc=module.nadc; - thisDetector->nChips=module.nchip; - thisDetector->nChans=module.nchan/module.nchip; - thisDetector->nDacs=module.ndac; - thisDetector->nAdcs=module.nadc; + if (ret!=FAIL) { + if (detectorModules) { + if (imod>=0 && imodnMod[X]*thisDetector->nMod[Y]) { + (detectorModules+imod)->nchan=module.nchan; + (detectorModules+imod)->nchip=module.nchip; + (detectorModules+imod)->ndac=module.ndac; + (detectorModules+imod)->nadc=module.nadc; + thisDetector->nChips=module.nchip; + thisDetector->nChans=module.nchan/module.nchip; + thisDetector->nDacs=module.ndac; + thisDetector->nAdcs=module.nadc; - if(thisDetector->myDetectorType != JUNGFRAU){ - for (int ichip=0; ichipnChips; ichip++) { - if (chipregs) - chipregs[ichip+thisDetector->nChips*imod]=module.chipregs[ichip]; + if(thisDetector->myDetectorType != JUNGFRAU){ + for (int ichip=0; ichipnChips; ichip++) { + if (chipregs) + chipregs[ichip+thisDetector->nChips*imod]=module.chipregs[ichip]; - if (chanregs) { - for (int i=0; inChans; i++) { - chanregs[i+ichip*thisDetector->nChans+thisDetector->nChips*thisDetector->nChans*imod]=module.chanregs[ichip*thisDetector->nChans+i]; + if (chanregs) { + for (int i=0; inChans; i++) { + chanregs[i+ichip*thisDetector->nChans+thisDetector->nChips*thisDetector->nChans*imod]=module.chanregs[ichip*thisDetector->nChans+i]; + } + } + } + if (adcs) { + for (int i=0; inAdcs; i++) + adcs[i+imod*thisDetector->nAdcs]=module.adcs[i]; + } } + + if (dacs) { + for (int i=0; inDacs; i++) + dacs[i+imod*thisDetector->nDacs]=module.dacs[i]; + } + + (detectorModules+imod)->gain=module.gain; + (detectorModules+imod)->offset=module.offset; + (detectorModules+imod)->serialnumber=module.serialnumber; + (detectorModules+imod)->reg=module.reg; } } - if (adcs) { - for (int i=0; inAdcs; i++) - adcs[i+imod*thisDetector->nAdcs]=module.adcs[i]; + + if ((thisDetector->nGain) && (gainval) && (gain)) { + for (int i=0; inGain; i++) + gain[i+imod*thisDetector->nGain]=gainval[i]; } - } - if (dacs) { - for (int i=0; inDacs; i++) - dacs[i+imod*thisDetector->nDacs]=module.dacs[i]; - } + if ((thisDetector->nOffset) && (offsetval) && (offset)) { + for (int i=0; inOffset; i++) + offset[i+imod*thisDetector->nOffset]=offsetval[i]; + } - (detectorModules+imod)->gain=module.gain; - (detectorModules+imod)->offset=module.offset; - (detectorModules+imod)->serialnumber=module.serialnumber; - (detectorModules+imod)->reg=module.reg; - } - } - - if ((thisDetector->nGain) && (gainval) && (gain)) { - for (int i=0; inGain; i++) - gain[i+imod*thisDetector->nGain]=gainval[i]; } - if ((thisDetector->nOffset) && (offsetval) && (offset)) { - for (int i=0; inOffset; i++) - offset[i+imod*thisDetector->nOffset]=offsetval[i]; - } - } - #ifdef VERBOSE - std::cout<< "Module register returned "<< retval << std::endl; + std::cout<< "Module register returned "<< retval << std::endl; #endif - return retval; + return retval; }; @@ -3956,7 +3950,10 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t){ setTotalProgress(); } - + double r; + if((index == SUBFRAME_ACQUISITION_TIME) && (thisDetector->myDetectorType == EIGER) && (t>=0) && getRateCorrection(r)){ + setRateCorrection(r); + } //send acquisiton period/frame number to receiver if((index==FRAME_NUMBER)||(index==FRAME_PERIOD)||(index==CYCLES_NUMBER)){ @@ -5001,110 +4998,126 @@ int slsDetector::flatFieldCorrect(double* datain, double *errin, double* dataout int slsDetector::setRateCorrection(double t){ - if (getDetectorsType() == MYTHEN){ - double tdead[]=defaultTDead; - if (t==0) { + if (getDetectorsType() == EIGER){ + int fnum=F_SET_RATE_CORRECT; + int ret=FAIL; + char mess[1000]=""; + int64_t arg = t; + int64_t retval = -1; #ifdef VERBOSE - std::cout<< "unsetting rate correction" << std::endl; + std::cout<< "Setting Rate Correction to " << arg << endl; #endif - thisDetector->correctionMask&=~(1<correctionMask|=(1<0) - thisDetector->tDead=t; - else { - if (thisDetector->currentSettings<3 && thisDetector->currentSettings>-1) - thisDetector->tDead=tdead[thisDetector->currentSettings]; - else - thisDetector->tDead=0; - } -#ifdef VERBOSE - std::cout<< "Setting rate correction with dead time "<< thisDetector->tDead << std::endl; -#endif - } - return thisDetector->correctionMask&(1<SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(&arg,sizeof(arg)); - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret!=FAIL) { - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - if(retval<0){ - thisDetector->correctionMask&=~(1<tDead = 0; - }else{ - if(retval>0){ - thisDetector->correctionMask|=(1<tDead = -1; - else - thisDetector->tDead = (double)retval; - } - else{ - thisDetector->correctionMask&=~(1<tDead = (double)retval; - } + if (setOnline(ONLINE_FLAG)==ONLINE_FLAG) { + if (connectControl() == OK){ + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->SendDataOnly(&arg,sizeof(arg)); + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret==FAIL) { + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + setErrorMask((getErrorMask())|(COULD_NOT_SET_RATE_CORRECTION)); + if(strcasestr(mess,"tau/subexptime")) + setErrorMask((getErrorMask())|(RATE_CORRECTION_TAU_SUBEXPOSURE)); } - } else { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - std::cout<< "Detector returned error: " << mess << std::endl; - setErrorMask((getErrorMask())|(COULD_NOT_SET_RATE_CORRECTION)); - if(strcasestr(mess,"tau/subexptime")) - setErrorMask((getErrorMask())|(RATE_CORRECTION_TAU_SUBEXPOSURE)); - thisDetector->correctionMask&=~(1<tDead = 0; + disconnectControl(); + if (ret==FORCE_UPDATE) + updateDetector(); } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); } + return ret; //only success/fail } + + //mythen + double tdead[]=defaultTDead; + if (t==0) { +#ifdef VERBOSE + std::cout<< "unsetting rate correction" << std::endl; +#endif + thisDetector->correctionMask&=~(1<correctionMask|=(1<0) + thisDetector->tDead=t; + else { + if (thisDetector->currentSettings<3 && thisDetector->currentSettings>-1) + thisDetector->tDead=tdead[thisDetector->currentSettings]; + else + thisDetector->tDead=0; + } +#ifdef VERBOSE + std::cout<< "Setting rate correction with dead time "<< thisDetector->tDead << std::endl; +#endif + } return thisDetector->correctionMask&(1<correctionMask&(1<myDetectorType == EIGER){ + t = getRateCorrectionTau(); + return t; + } + + if (thisDetector->correctionMask&(1<tDead << std::endl; + std::cout<< "Rate correction is enabled with dead time "<< thisDetector->tDead << std::endl; #endif - t=thisDetector->tDead; - return 1; - } else - t=0; + t=thisDetector->tDead; + return 1; + } else + t=0; #ifdef VERBOSE - std::cout<< "Rate correction is disabled " << std::endl; + std::cout<< "Rate correction is disabled " << std::endl; #endif - return 0; + return 0; }; double slsDetector::getRateCorrectionTau(){ - if (thisDetector->correctionMask&(1<myDetectorType == EIGER){ + int fnum=F_GET_RATE_CORRECT; + int ret=FAIL; + char mess[1000]=""; + int64_t retval = -1; + #ifdef VERBOSE + std::cout<< "Setting Rate Correction to " << arg << endl; + #endif + if (setOnline(ONLINE_FLAG)==ONLINE_FLAG) { + if (connectControl() == OK){ + controlSocket->SendDataOnly(&fnum,sizeof(fnum)); + controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); + if (ret!=FAIL) + controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); + else { + controlSocket->ReceiveDataOnly(mess,sizeof(mess)); + std::cout<< "Detector returned error: " << mess << std::endl; + } + disconnectControl(); + if (ret==FORCE_UPDATE) + updateDetector(); + } + } + + return double(retval); + } + + + //mythen only + if (thisDetector->correctionMask&(1<tDead << std::endl; + std::cout<< "Rate correction is enabled with dead time "<< thisDetector->tDead << std::endl; #endif - return thisDetector->tDead; - //return 1; - } else + return thisDetector->tDead; + //return 1; + } else #ifdef VERBOSE - std::cout<< "Rate correction is disabled " << std::endl; + std::cout<< "Rate correction is disabled " << std::endl; #endif - return 0; + return 0; }; @@ -5113,6 +5126,11 @@ double slsDetector::getRateCorrectionTau(){ int slsDetector::getRateCorrection(){ + if (thisDetector->myDetectorType == EIGER){ + double t = getRateCorrectionTau(); + return (int)t; + } + if (thisDetector->correctionMask&(1< -2){ //ignore -2: from load settings) + + //set default tau value (-1 or a normal value) + setDefaultSettingsTau_in_nsec(myTau); + + //switch off rate correction: no value read from load calib/load settings) + if(myTau == -1){ + ret = FAIL; + if(getRateCorrectionEnable()){ + setRateCorrection(0); + strcat(mess," Cannot set Rate correction. No default tau provided. Deactivating Rate Correction\n"); + }else{ + strcat(mess," Cannot set Rate correction. No default tau provided\n"); + } + cprintf(RED,"%s",mess); + } + + + //normal tau value (only if enabled) + else if (getRateCorrectionEnable()){ + int64_t retvalTau = setRateCorrection(myTau); //myTau will not be -1 here + if(myTau != retvalTau){ + if(retvalTau == -1) + strcat(mess," Rate correction Deactivated, (tau/subexptime) must be < 0.0015\n"); + cprintf(RED,"%s",mess); + ret=FAIL; + } + } } + retval = getSettings(); + #else ret=setModule(myModule); -#endif retval = ret; +#endif } } #endif @@ -3863,10 +3880,9 @@ int pulse_chip(int file_des) { -int rate_correct(int file_des) { +int set_rate_correct(int file_des) { int64_t tau_ns=-1; int n; - int64_t retval=-1; int ret=OK,ret1=OK; sprintf(mess,"can't set/unset rate correction\n"); @@ -3886,30 +3902,39 @@ int rate_correct(int file_des) { #ifdef SLS_DETECTOR_FUNCTION_LIST - //tau = -1, use default tau of settings - if((ret==OK)&&(tau_ns<0)){ - tau_ns = getDefaultSettingsTau_in_nsec(); - if(tau_ns < 0){ - ret = FAIL; - sprintf(mess,"Cannot set rate correction. Settings %d not recognized by detector\n",thisSettings); - cprintf(RED,"%s",mess); - } - } - - if (ret==OK) { printf("Setting rate correction to %lld ns\n",tau_ns); - if (differentClients==1 && lockStatus==1 && tau_ns!=-1) { + if (differentClients==1 && lockStatus==1) { ret=FAIL; sprintf(mess,"Detector locked by %s\n",lastClientIP); } else { - retval = setRateCorrection(tau_ns); //tau_ns will not be -1 here - if(tau_ns != retval){ - if(retval == -1) - strcpy(mess,"Rate correction Deactivated, (tau/subexptime) must be < 0.0015\n"); + + //tau = -1, use default tau of settings + if((ret==OK)&&(tau_ns<0)){ + tau_ns = getDefaultSettingsTau_in_nsec(); + } + //still negative (not set) + if(tau_ns < 0){ + ret = FAIL; + if(getRateCorrectionEnable()){ + setRateCorrection(0); + strcpy(mess,"Cannot set rate correction as default tau not provided. Switching off Rate Correction\n"); + }else{ + strcpy(mess,"Cannot set rate correction as default tau not provided\n"); + } cprintf(RED,"%s",mess); - ret=FAIL; + } + + //set rate + else{ + int64_t retval = setRateCorrection(tau_ns); //tau_ns will not be -1 here + if(tau_ns != retval){ + if(retval == -1) + strcpy(mess,"Rate correction Deactivated, (tau/subexptime) must be < 0.0015\n"); + cprintf(RED,"%s",mess); + ret=FAIL; + } } } } @@ -3923,8 +3948,45 @@ int rate_correct(int file_des) { n = sendData(file_des,&ret1,sizeof(ret),INT32); if (ret==FAIL) { n = sendData(file_des,mess,sizeof(mess),OTHER); - } else { - n = sendData(file_des,&retval,sizeof(retval),INT64); + } + + return ret; +} + + + + +int get_rate_correct(int file_des) { + int64_t retval=-1; + int ret=OK,ret1=OK; + + sprintf(mess,"can't get rate correction\n"); + + +#ifndef EIGERD + sprintf(mess,"Rate Correction not implemented for this detector\n"); + cprintf(RED,"%s",mess); + ret=FAIL; +#endif + +#ifdef SLS_DETECTOR_FUNCTION_LIST + + if (ret==OK) { + retval = getCurrentTau(); + printf("Getting rate correction %lld\n",(long long int)retval); + } +#endif + if ((ret==OK) && (differentClients)) + ret=FORCE_UPDATE; + + + //ret could be swapped during sendData + ret1 = ret; + sendData(file_des,&ret1,sizeof(ret),INT32); + if (ret==FAIL) { + sendData(file_des,mess,sizeof(mess),OTHER); + } else { + sendData(file_des,&retval,sizeof(retval),INT64); } return ret; diff --git a/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.h b/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.h index c2fa38438..a1bd9a16b 100755 --- a/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.h +++ b/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.h @@ -87,7 +87,7 @@ int set_counter_bit(int); int pulse_pixel(int); int pulse_pixel_and_move(int); int pulse_chip(int); -int rate_correct(int); - +int set_rate_correct(int); +int get_rate_correct(int); #endif