diff --git a/serverBin/gotthardDetectorServerv4.0.0.2 b/serverBin/gotthardDetectorServerv4.0.0.2 deleted file mode 120000 index 0ffed19a9..000000000 --- a/serverBin/gotthardDetectorServerv4.0.0.2 +++ /dev/null @@ -1 +0,0 @@ -../slsDetectorSoftware/gotthardDetectorServer/gotthardDetectorServerv4.0.0.2 \ No newline at end of file diff --git a/serverBin/gotthardDetectorServerv4.0.0.3 b/serverBin/gotthardDetectorServerv4.0.0.3 new file mode 120000 index 000000000..d98581ea5 --- /dev/null +++ b/serverBin/gotthardDetectorServerv4.0.0.3 @@ -0,0 +1 @@ +../slsDetectorSoftware/gotthardDetectorServer/gotthardDetectorServerv4.0.0.3 \ No newline at end of file diff --git a/slsDetectorSoftware/commonFiles/versionAPI.h b/slsDetectorSoftware/commonFiles/versionAPI.h index 14643dbd6..b2706ecca 100644 --- a/slsDetectorSoftware/commonFiles/versionAPI.h +++ b/slsDetectorSoftware/commonFiles/versionAPI.h @@ -2,4 +2,4 @@ #define APIRECEIVER 0x180823 #define APIEIGER 0x180820 #define APIJUNGFRAU 0x180823 -#define APIGOTTHARD 0x180925 +#define APIGOTTHARD 0x180927 diff --git a/slsDetectorSoftware/gotthardDetectorServer/Makefile b/slsDetectorSoftware/gotthardDetectorServer/Makefile index b43f65031..f6eacbd00 100755 --- a/slsDetectorSoftware/gotthardDetectorServer/Makefile +++ b/slsDetectorSoftware/gotthardDetectorServer/Makefile @@ -16,7 +16,7 @@ INSTMODE= 0777 BINS = testlib_sharedlibc -SRCS = server.c firmware_funcs.c server_funcs.c communication_funcs.c mcb_funcs.c trimming_funcs.c sharedmemory.c +SRCS = server.c firmware_funcs.c server_funcs.c communication_funcs.c mcb_funcs.c OBJS = $(SRCS:%.c=%.o) diff --git a/slsDetectorSoftware/gotthardDetectorServer/Makefile.propix b/slsDetectorSoftware/gotthardDetectorServer/Makefile.propix index c0a4bcc55..7f40e78a3 100755 --- a/slsDetectorSoftware/gotthardDetectorServer/Makefile.propix +++ b/slsDetectorSoftware/gotthardDetectorServer/Makefile.propix @@ -16,7 +16,7 @@ INSTMODE= 0777 BINS = testlib_sharedlibc -SRCS = server.c server_funcs.c communication_funcs.c firmware_funcs.c mcb_funcs.c trimming_funcs.c sharedmemory.c +SRCS = server.c server_funcs.c communication_funcs.c firmware_funcs.c mcb_funcs.c OBJS = $(SRCS:%.c=%.o) diff --git a/slsDetectorSoftware/gotthardDetectorServer/Makefile.virtual b/slsDetectorSoftware/gotthardDetectorServer/Makefile.virtual index d36e90b8e..ca9bff23c 100755 --- a/slsDetectorSoftware/gotthardDetectorServer/Makefile.virtual +++ b/slsDetectorSoftware/gotthardDetectorServer/Makefile.virtual @@ -8,7 +8,7 @@ CFLAGS += -Wall -DGOTTHARDD -DMCB_FUNCS -DDACS_INT -DDEBUG -DVIRTUAL PROGS= $(DESTDIR)/gotthardDetectorServer_virtual -SRCS = server.c server_funcs.c communication_funcs.c firmware_funcs.c mcb_funcs.c trimming_funcs.c sharedmemory.c +SRCS = server.c server_funcs.c communication_funcs.c firmware_funcs.c mcb_funcs.c OBJS = $(SRCS:%.c=%.o) gotthardVirtualServer = $(PROGS) diff --git a/slsDetectorSoftware/gotthardDetectorServer/firmware_funcs.c b/slsDetectorSoftware/gotthardDetectorServer/firmware_funcs.c index ab12ef2af..3238da0a4 100755 --- a/slsDetectorSoftware/gotthardDetectorServer/firmware_funcs.c +++ b/slsDetectorSoftware/gotthardDetectorServer/firmware_funcs.c @@ -4,10 +4,6 @@ #include "mcb_funcs.h" #include "registers_g.h" -#ifdef SHAREDMEMORY -#include "sharedmemory.h" -#endif - #include #include #include @@ -34,9 +30,7 @@ int dataBytes=NMAXMOD*NCHIP*NCHAN*2; int storeInRAM=0; int ROI_flag=0; int adcConfigured=-1; -u_int32_t *ram_values=NULL; -volatile char *now_ptr=NULL; -volatile u_int16_t *values; + int ram_size=0; int64_t totalTime=1; @@ -189,9 +183,6 @@ int mapCSP0(void) { printf("CSPObase is 0x%llx \n",CSP0BASE); printf("CSPOBASE=from %llx to %llx\n",CSP0BASE,CSP0BASE+MEM_SIZE); - u_int32_t address; - address = FIFO_DATA_REG_OFF; - values=(u_int16_t*)(CSP0BASE+address*2); printf("statusreg=%08x\n",bus_r(STATUS_REG)); printf("\n\n"); return OK; @@ -851,18 +842,6 @@ u_int32_t testFpga(void) { } -// for fpga test -u_int32_t testRAM(void) { - int result=OK; - int i=0; - allocateRAM(); - // while(i<100000) { - memcpy((char*)ram_values, (char*)values, dataBytes); - printf ("Testing RAM:\t%d: copied fifo %x to memory %x size %d\n",i++, (unsigned int)(values), (unsigned int)(ram_values), dataBytes); - // } - return result; -} - int getNModBoard() { return nModX; } @@ -1503,11 +1482,7 @@ int startStateMachine(){ //#endif cleanFifo(); // fifoReset(); - now_ptr=(char*)ram_values; -#ifdef SHAREDMEMORY - write_stop_sm(0); - write_status_sm("Started"); -#endif + bus_w16(CONTROL_REG, START_ACQ_BIT | START_EXPOSURE_BIT); bus_w16(CONTROL_REG, 0x0); printf("statusreg=%08x\n",bus_r(STATUS_REG)); @@ -1583,31 +1558,12 @@ u_int32_t fifo_full(void) } -u_int32_t* fifo_read_event() -{ -#ifdef VIRTUAL - return NULL; -#endif - -#ifdef VERBOSE - printf("before looping\n"); -#endif - volatile u_int32_t t = bus_r(LOOK_AT_ME_REG); - +void waitForAcquisitionFinish(){ + volatile u_int32_t t = bus_r(LOOK_AT_ME_REG); #ifdef VERBOSE printf("lookatmereg=x%x\n",t); #endif -/* - while ((t&0x1)==0) - { - t = bus_r(LOOK_AT_ME_REG); - if (!runBusy()){ - return NULL; - } - } -*/ - - while((t&0x1)==0) { + while((t&0x1)==0) { if (runBusy()==0) { t = bus_r(LOOK_AT_ME_REG); if ((t&0x1)==0) { @@ -1615,7 +1571,7 @@ u_int32_t* fifo_read_event() printf("no frame found - exiting "); printf("%08x %08x\n", runState(), bus_r(LOOK_AT_ME_REG)); #endif - return NULL; + return; } else { #ifdef VERBOSE printf("no frame found %x status %x\n", bus_r(LOOK_AT_ME_REG),runState()); @@ -1624,38 +1580,12 @@ u_int32_t* fifo_read_event() } } t = bus_r(LOOK_AT_ME_REG); - } - - -#ifdef VERBOSE - printf("before readout %08x %08x\n", runState(), bus_r(LOOK_AT_ME_REG)); -#endif - - dma_memcpy(now_ptr,values ,dataBytes); - - -#ifdef VERYVERBOSE - int a; - for (a=0;a<8; a=a+2) - printf("\n%d %d: x%04x x%04x ",a+1,a,*(now_ptr+a+1),*(now_ptr+a) ); - for (a=2554;a<2560; a=a+2) - printf("\n%d %d: x%04x x%04x ",a+1,a,*(now_ptr+a+1),*(now_ptr+a) ); - printf("********\n"); - //memcpy(now_ptr, values, dataBytes); -#endif -#ifdef VERBOSE - printf("Copying to ptr %08x %d\n",(unsigned int)(now_ptr), dataBytes); - printf("after readout %08x %08x\n", runState(), bus_r(LOOK_AT_ME_REG)); -#endif - - if (storeInRAM>0) { - now_ptr+=dataBytes; } - return ram_values; } + u_int32_t* decode_data(int *datain) { u_int32_t *dataout; @@ -1770,83 +1700,10 @@ int testBus() { int setStoreInRAM(int b) { - if (b>0) - storeInRAM=1; - else - storeInRAM=0; - return allocateRAM(); + return 0; } -int allocateRAM() { - size_t size; - u_int32_t nt, nf; - nt=setTrains(-1); - nf=setFrames(-1); - if (nt==0) nt=1; - if (nf==0) nf=1; - // ret=clearRAM(); - if (storeInRAM) { - size=dataBytes*nf*nt; - if (size>(23-i))&0x1)<>(23-i))&0x1)<>(23-i))&0x1)<> 8); - // printf("%i: %i %i\n",a, frame[a],v); - avg[a] += ((double)frame[a])/(double)frames; - //if(frame[a] == 8191) - // printf("ch %i: %u\n",a,frame[a]); - } - // printf("********\n"); - numberFrames++; - } - - //no more data or no data - else { - if(getFrames()>-2) { - dataret=FAIL; - printf("no data and run stopped: %d frames left\n",(int)(getFrames()+2)); - - } else { - dataret=FINISHED; - printf("acquisition successfully finished\n"); - - } - printf("dataret %d\n",dataret); - } - } - - - - //double nf = (double)numberFrames; - for(i =0; i < 1280; i++){ - adc = i / 256; - adcCh = (i - adc * 256) / 32; - Ch = i - adc * 256 - adcCh * 32; - adc--; - double v2 = avg[i]; - avg[i] = avg[i]/ ((double)numberFrames/(double)frames); - unsigned short v = (unsigned short)avg[i]; - printf("setting avg for channel %i(%i,%i,%i): %i (double= %f (%f))\t", i,adc,adcCh,Ch, v,avg[i],v2); - v=i*100; - ram_w16(DARK_IMAGE_REG,adc,adcCh,Ch,v-4096); - if(ram_r16(DARK_IMAGE_REG,adc,adcCh,Ch) != v-4096){ - printf("value is wrong (%i,%i,%i): %i \n",adc,adcCh,Ch, ram_r16(DARK_IMAGE_REG,adc,adcCh,Ch)); - } - } - - /*for(adc = 1; adc < 5; adc++){ - for(adcCh = 0; adcCh < 8; adcCh++){ - for(Ch=0 ; Ch < 32; Ch++){ - int channel = (adc+1) * 32 * 8 + adcCh * 32 + Ch; - double v2 = avg[channel]; - avg[channel] = avg[channel]/ ((double)numberFrames/(double)frames); - unsigned short v = (unsigned short)avg[channel]; - printf("setting avg for channel %i: %i (double= %f (%f))\t", channel, v,avg[channel],v2); - ram_w16(DARK_IMAGE_REG,adc,adcCh,Ch,v-4096); - if(ram_r16(DARK_IMAGE_REG,adc,adcCh,Ch) != v-4096){ - printf("value is wrong (%i,%i,%i): %i \n",adc,adcCh,Ch, ram_r16(DARK_IMAGE_REG,adc,adcCh,Ch)); - } - } - } - }*/ - - - - printf("frames: %i\n",numberFrames); - printf("corrected avg by: %f\n",(double)numberFrames/(double)frames); - - printf("restoring previous condition\n"); - setFrames(framesBefore); - setPeriod(periodBefore); - + // removed this functionlity as it requires reading via cpu printf("---------------------------\n"); return 0; } diff --git a/slsDetectorSoftware/gotthardDetectorServer/firmware_funcs.h b/slsDetectorSoftware/gotthardDetectorServer/firmware_funcs.h index 50b143c70..9d2491c0e 100755 --- a/slsDetectorSoftware/gotthardDetectorServer/firmware_funcs.h +++ b/slsDetectorSoftware/gotthardDetectorServer/firmware_funcs.h @@ -77,7 +77,6 @@ u_int32_t getFirmwareVersion(); u_int32_t getFirmwareSVNVersion(); int testFifos(void); u_int32_t testFpga(void); -u_int32_t testRAM(void); int testBus(void); int setDigitalTestBit(int ival); @@ -128,8 +127,8 @@ u_int32_t fifoReadStatus(); u_int32_t fifo_full(void); +void waitForAcquisitionFinish(); -u_int32_t* fifo_read_event(); u_int32_t* decode_data(int* datain); //u_int32_t move_data(u_int64_t* datain, u_int64_t* dataout); int setDynamicRange(int dr); @@ -137,8 +136,7 @@ int getDynamicRange(); int getNModBoard(); int setNMod(int n); int setStoreInRAM(int b); -int allocateRAM(); -int clearRAM(); + diff --git a/slsDetectorSoftware/gotthardDetectorServer/gitInfo.txt b/slsDetectorSoftware/gotthardDetectorServer/gitInfo.txt index c2939552b..e73046edd 100644 --- a/slsDetectorSoftware/gotthardDetectorServer/gitInfo.txt +++ b/slsDetectorSoftware/gotthardDetectorServer/gitInfo.txt @@ -1,9 +1,9 @@ Path: slsDetectorsPackage/slsDetectorSoftware/gotthardDetectorServer URL: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git Repository Root: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git -Repsitory UUID: 4aa0d26f26a16d48ddd265128f02b39e7140127f -Revision: 239 +Repsitory UUID: c2db073d5e936d64733ba9bdfdce311a556ae212 +Revision: 241 Branch: 4.0.0 Last Changed Author: Dhanya_Thattil -Last Changed Rev: 4005 -Last Changed Date: 2018-09-25 12:19:12.000000002 +0200 ./server_funcs.h +Last Changed Rev: 4018 +Last Changed Date: 2018-09-27 16:32:41.000000002 +0200 ./firmware_funcs.c diff --git a/slsDetectorSoftware/gotthardDetectorServer/gitInfoGotthard.h b/slsDetectorSoftware/gotthardDetectorServer/gitInfoGotthard.h index 59109a35d..4ca82b03c 100644 --- a/slsDetectorSoftware/gotthardDetectorServer/gitInfoGotthard.h +++ b/slsDetectorSoftware/gotthardDetectorServer/gitInfoGotthard.h @@ -1,6 +1,6 @@ #define GITURL "git@github.com:slsdetectorgroup/slsDetectorPackage.git" -#define GITREPUUID "4aa0d26f26a16d48ddd265128f02b39e7140127f" +#define GITREPUUID "c2db073d5e936d64733ba9bdfdce311a556ae212" #define GITAUTH "Dhanya_Thattil" -#define GITREV 0x4005 -#define GITDATE 0x20180925 +#define GITREV 0x4018 +#define GITDATE 0x20180927 #define GITBRANCH "4.0.0" diff --git a/slsDetectorSoftware/gotthardDetectorServer/gotthardDetectorServer_virtual b/slsDetectorSoftware/gotthardDetectorServer/gotthardDetectorServer_virtual index 8bb3b7eef..87332b4e1 100755 Binary files a/slsDetectorSoftware/gotthardDetectorServer/gotthardDetectorServer_virtual and b/slsDetectorSoftware/gotthardDetectorServer/gotthardDetectorServer_virtual differ diff --git a/slsDetectorSoftware/gotthardDetectorServer/gotthardDetectorServerv4.0.0.2 b/slsDetectorSoftware/gotthardDetectorServer/gotthardDetectorServerv4.0.0.2 deleted file mode 100755 index a590d003e..000000000 Binary files a/slsDetectorSoftware/gotthardDetectorServer/gotthardDetectorServerv4.0.0.2 and /dev/null differ diff --git a/slsDetectorSoftware/gotthardDetectorServer/gotthardDetectorServerv4.0.0.3 b/slsDetectorSoftware/gotthardDetectorServer/gotthardDetectorServerv4.0.0.3 new file mode 100755 index 000000000..7d609b90d Binary files /dev/null and b/slsDetectorSoftware/gotthardDetectorServer/gotthardDetectorServerv4.0.0.3 differ diff --git a/slsDetectorSoftware/gotthardDetectorServer/mcb_funcs.c b/slsDetectorSoftware/gotthardDetectorServer/mcb_funcs.c index 79879e4d1..8d73b536f 100755 --- a/slsDetectorSoftware/gotthardDetectorServer/mcb_funcs.c +++ b/slsDetectorSoftware/gotthardDetectorServer/mcb_funcs.c @@ -107,7 +107,6 @@ int initDetector() { // initChip(0, 0,ALLMOD); //nModX=n; // - allocateRAM(); return OK; @@ -1831,205 +1830,19 @@ int testDataInOut(int num, int imod) { int testExtPulse(int imod) { - int i, ichan, ichip, result=OK; - int *val1; - - printf("Testing counter for module %d\n", imod); - - setCSregister(ALLMOD); - setSSregister(ALLMOD); - counterClear(ALLMOD); - putout("0000000000000000",ALLMOD); - putout("0000100000000000",ALLMOD); - putout("0000000000000000",ALLMOD); - for (i=0; i-2) { + dataret = FAIL; + sprintf(mess,"no data and run stopped: %d frames left\n",(int)(getFrames()+2)); + cprintf(RED,"%s\n",mess); + } else { + dataret = FINISHED; + sprintf(mess,"acquisition successfully finished\n"); + cprintf(GREEN,"%s",mess); + + } #endif - sendDataOnly(file_des,&dataret,sizeof(dataret)); - sendDataOnly(file_des,dataretval,dataBytes); -#ifdef VERBOSE - printf("sent %d bytes \n",dataBytes); - printf("dataret OK\n"); -#endif - return OK; - } else { - //might add delay???? - if(getFrames()>-2) { - dataret=FAIL; - sprintf(mess,"no data and run stopped: %d frames left\n",(int)(getFrames()+2)); - printf("%s\n",mess); - } else { - dataret=FINISHED; - sprintf(mess,"acquisition successfully finished\n"); - printf("%s\n",mess); - } -#ifdef VERYVERBOSE - printf("%d %d %x %s\n",(int)(sizeof(mess)),(int)(strlen(mess)),(unsigned int)( mess),mess); -#endif - sendDataOnly(file_des,&dataret,sizeof(dataret)); - sendDataOnly(file_des,mess,sizeof(mess)); -#ifdef VERYVERBOSE - printf("message sent %s\n",mess); -#endif - printf("dataret %d\n",dataret); - return dataret; - } - } else { - nframes=0; - while(fifo_read_event()) { - nframes++; - } - dataretval=(char*)ram_values; - dataret=OK; -#ifdef VERBOSE - printf("sending data of %d frames\n",nframes); -#endif - for (iframes=0; iframes-2) { - dataret=FAIL; - sprintf(mess,"no data and run stopped: %d frames left\n",(int)(getFrames()+2)); - printf("%s\n",mess); - } else { - dataret=FINISHED; - sprintf(mess,"acquisition successfully finished\n"); - printf("%s\n",mess); - if (differentClients) - dataret=FORCE_UPDATE; - } -#ifdef VERBOSE - printf("Frames left %d\n",(int)(getFrames())); -#endif - sendDataOnly(file_des,&dataret,sizeof(dataret)); - sendDataOnly(file_des,mess,sizeof(mess)); - printf("dataret %d\n",dataret); - return dataret; - } - printf("dataret %d\n",dataret); - return dataret; + + if (differentClients) + dataret=FORCE_UPDATE; + + sendDataOnly(file_des,&dataret,sizeof(dataret)); + sendDataOnly(file_des,mess,sizeof(mess)); + return dataret; } @@ -2097,9 +2046,9 @@ int set_timer(int file_des) { printf(mess); } -#ifdef VERBOSE +//#ifdef VERBOSE printf("setting timer %d to %lld ns\n",ind,tns); -#endif +//#endif if (ret==OK) { if (differentClients==1 && lockStatus==1 && tns!=-1) { @@ -2150,10 +2099,6 @@ int set_timer(int file_des) { if (ret!=OK) { printf(mess); printf("set timer failed\n"); - } else if (ind==FRAME_NUMBER) { - ret=allocateRAM(); - if (ret!=OK) - sprintf(mess, "could not allocate RAM for %lld frames\n", tns); } n = sendDataOnly(file_des,&ret,sizeof(ret)); @@ -2294,12 +2239,6 @@ int set_dynamic_range(int file_des) { //if (dr>=0 && retval!=dr) ret=FAIL; if (ret!=OK) { sprintf(mess,"set dynamic range failed\n"); - } else { - ret=allocateRAM(); - if (ret!=OK) - sprintf(mess,"Could not allocate RAM for the dynamic range selected\n"); - else if (differentClients) - ret=FORCE_UPDATE; } n = sendDataOnly(file_des,&ret,sizeof(ret)); diff --git a/slsDetectorSoftware/gotthardDetectorServer/sharedmemory.c b/slsDetectorSoftware/gotthardDetectorServer/sharedmemory.c deleted file mode 100755 index 4504cfe05..000000000 --- a/slsDetectorSoftware/gotthardDetectorServer/sharedmemory.c +++ /dev/null @@ -1,39 +0,0 @@ -#include "sharedmemory.h" - -struct statusdata *stdata; - -int inism(int clsv) { - -static int scansmid; - - if (clsv==SMSV) { - if ( (scansmid=shmget(SMKEY,1024,IPC_CREAT | 0666 ))==-1 ) { - return -1; - } - if ( (stdata=shmat(scansmid,NULL,0))==(void*)-1) { - return -2; - } - } - - if (clsv==SMCL) { - if ( (scansmid=shmget(SMKEY,0,0) )==-1 ) { - return -3; - } - if ( (stdata=shmat(scansmid,NULL,0))==(void*)-1) { - return -4; - } - } - return 1; -} - -void write_status_sm(char *status) { - strcpy(stdata->status,status); -} - -void write_stop_sm(int v) { - stdata->stop=v; -} - -void write_runnumber_sm(int v) { - stdata->runnumber=v; -} diff --git a/slsDetectorSoftware/gotthardDetectorServer/sharedmemory.h b/slsDetectorSoftware/gotthardDetectorServer/sharedmemory.h deleted file mode 100755 index bdbddf719..000000000 --- a/slsDetectorSoftware/gotthardDetectorServer/sharedmemory.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef SM -#define SM - -#include "sls_detector_defs.h" - -#include -#include -#include -#include -#include -#include -#include -//#include -#include -#include -#include -#include -#include -#include - - -#include - -#include -#include - -/* key for shared memory */ -#define SMKEY 10001 - -#define SMSV 1 -#define SMCL 2 - - -struct statusdata { - int runnumber; - int stop; - char status[20]; -} ; - - -/* for shared memory */ - -int inism(int clsv); -void write_status_sm(char *status); -void write_stop_sm(int v); -void write_runnumber_sm(int v); - -#endif diff --git a/slsDetectorSoftware/gotthardDetectorServer/trimming_funcs.c b/slsDetectorSoftware/gotthardDetectorServer/trimming_funcs.c deleted file mode 100755 index 6f0d726e8..000000000 --- a/slsDetectorSoftware/gotthardDetectorServer/trimming_funcs.c +++ /dev/null @@ -1,749 +0,0 @@ -#ifndef PICASSOD -#include "server_defs.h" -#else -#include "picasso_defs.h" -#endif -#include "trimming_funcs.h" -#include "mcb_funcs.h" -#include "firmware_funcs.h" -#include - - - -extern int nModX; -//extern int *values; - -extern const int nChans; -extern const int nChips; -extern const int nDacs; -extern const int nAdcs; - - -int trim_fixed_settings(int countlim, int par2, int im) -{ - - int retval=OK; -#ifdef VERBOSE - printf("Trimming with fixed settings\n"); -#endif -#ifdef VIRTUAL - return OK; -#endif - - if (par2<=0) - retval=trim_with_level(countlim, im); - else - retval=trim_with_median(countlim,im); - - - return retval; -} - - -int trim_with_noise(int countlim, int nsigma, int im) -{ - - - int retval=OK, retval1=OK, retval2=OK; -#ifdef VERBOSE - printf("Trimming using noise\n"); -#endif -#ifdef VIRTUAL - return OK; -#endif - - /* threshold scan */ - -#ifdef VERBOSE - printf("chosing vthresh and vtrim....."); -#endif - retval1=choose_vthresh_and_vtrim(countlim,nsigma, im); - -#ifdef VERBOSE - printf("trimming with noise.....\n"); -#endif - retval2=trim_with_level(countlim, im); - -#ifdef DEBUGOUT - printf("done\n"); -#endif - if (retval1==OK && retval2==OK) - retval=OK; - else - retval=FAIL; - - return retval; - -} - -int trim_with_beam(int countlim, int nsigma, int im) //rpc -{ - - - int retval=OK, retval1=OK, retval2=OK; - - printf("Trimming using beam\n"); - //return OK; -#ifdef VIRTUAL - printf("Trimming using beam\n"); - return OK; -#endif - /* threshold scan */ -#ifdef DEBUGOUT - printf("chosing vthresh and vtrim....."); -#endif - - retval1=choose_vthresh_and_vtrim(countlim,nsigma,im); - retval2=trim_with_median(TRIM_DR, im); - -#ifdef DEBUGOUT - printf("done\n"); -#endif - - if (retval1==OK && retval2==OK) - retval=OK; - else - retval=FAIL; - - return retval; - -} - - -int trim_improve(int maxit, int par2, int im) //rpc -{ - - int retval=OK, retval1=OK, retval2=OK; - - -#ifdef VERBOSE - printf("Improve the trimming\n"); -#endif -#ifdef VIRTUAL - return OK; -#endif - - - if (par2!=0 && im==ALLMOD) - retval1=choose_vthresh(); - - retval2=trim_with_median(2*maxit+1, im); -#ifdef DEBUGOUT - printf("done\n"); -#endif - if (retval1==OK && retval2==OK) - retval=OK; - else - retval=FAIL; - - return retval; - -} - -int calcthr_from_vcal(int vcal) { - int thrmin; - //thrmin=140+3*vcal/5; - thrmin=180+3*vcal/5; - return thrmin; -} - -int calccal_from_vthr(int vthr) { - int vcal; - vcal=5*(vthr-140)/3; - return vcal; -} - -int choose_vthresh_and_vtrim(int countlim, int nsigma, int im) { - int retval=OK; -#ifdef MCB_FUNCS - int modma, modmi, nm; - int thr, thrstep=5, nthr=31; - - int *fifodata; - - double vthreshmean, vthreshSTDev; - int *thrmi, *thrma; - double c; - //double b=BVTRIM; - //double a=AVTRIM; - int *trim; - int ich, imod, ichan; - int nvalid=0; - u_int32_t *scan; - int ithr; - sls_detector_channel myChan; - - - - setFrames(1); - // setNMod(getNModBoard()); - - if (im==ALLMOD){ - modmi=0; - modma=nModX; - } else { - modmi=im; - modma=im+1; - } - nm=modma-modmi; - - trim=malloc(sizeof(int)*nChans*nChips*nModX); - thrmi=malloc(sizeof(int)*nModX); - thrma=malloc(sizeof(int)*nModX); - - - for (ich=0; ichcountlim && trim[ich]==-1) { -//commented out by dhanya trim[ich]=getDACbyIndexDACU(VTHRESH,imod); -#ifdef VERBOSE - // printf("yes: %d %d %d\n",ich,ithr,scan[ich]); -#endif - } -#ifdef VERBOSE - /* else { - printf("no: %d %d %d\n",ich,ithr,scan[ich]); - }*/ -#endif - } - } - free(scan); - } - - for (imod=modmi; imodthrmi[imod] && trim[ich]0) { - vthreshmean=vthreshmean/nvalid; - //commented out by dhanya vthreshSTDev=sqrt((vthreshSTDev/nvalid)-vthreshmean*vthreshmean); - } else { - vthreshmean=thrmi[imod]; - vthreshSTDev=nthr*thrstep; - printf("No valid channel for module %d\n",imod); - retval=FAIL; - } - -#ifdef DEBUGOUT - printf("module= %d nvalid = %d mean=%f RMS=%f\n",imod, nvalid, vthreshmean,vthreshSTDev); -#endif - // *vthresh=round(vthreshmean-nsigma*vthreshSTDev); - thr=(int)(vthreshmean-nsigma*vthreshSTDev); - if (thr<0 || thr>(DAC_DR-1)) { - thr=thrmi[imod]/2; - printf("Can't find correct threshold for module %d\n",imod); - retval=FAIL; - } -//commented out by dhanya initDACbyIndexDACU(VTHRESH,thr,imod); -#ifdef VERBOSE - printf("vthresh=%d \n",thr); -#endif - c=CVTRIM-2.*nsigma*vthreshSTDev/63.; - //commented out by dhanya thr=(int)((-b-sqrt(b*b-4*a*c))/(2*a)); - if (thr<500 || thr>(DAC_DR-1)) { - thr=750; - printf("Can't find correct trimbit size for module %d\n",imod); - retval=FAIL; - } - - //commented out by dhanya initDACbyIndexDACU(VTRIM,thr,imod); - -#ifdef VERBOSE - printf("vtrim=%d \n",thr); -#endif - - } - free(trim); - free(thrmi); - free(thrma); - -#endif - return retval; -} - - - - - -int trim_with_level(int countlim, int im) { - int ich, itrim, ichan, ichip, imod; - u_int32_t *scan; - int *inttrim; - int modma, modmi, nm; - int retval=OK; - int *fifodata; - sls_detector_channel myChan; - printf("trimming module number %d", im); - - -#ifdef MCB_FUNCS - setFrames(1); - // setNMod(getNModBoard()); - - if (im==ALLMOD){ - modmi=0; - modma=nModX; - } else { - modmi=im; - modma=im+1; - } - nm=modma-modmi; - - inttrim=malloc(sizeof(int)*nChips*nChans*nModX); - printf("countlim=%d\n",countlim); - for (ich=0; ichcountlim){ - inttrim[ich]=itrim; - if (scan[ich]>2*countlim && itrim>0) { - //if (scan[ich]>2*countlim || itrim==0) { - inttrim[ich]=itrim-1; - } -#ifdef VERBOSE - printf("Channel %d trimbit %d counted %d (%08x) countlim %d\n",ich,itrim,scan[ich],fifodata[ich],countlim); -#endif - } - } -#ifdef VERBOSE - /* else - printf("Channel %d trimbit %d counted %d countlim %d\n",ich,itrim,scan[ich],countlim);*/ -#endif - } - } - free(scan); - } - - for (imod=modmi; imod0) - direction[ichan]=1; - else - direction[ichan]=-1; - } - //commented out by dhanya vthresh=getDACbyIndexDACU(VTHRESH,imod); - if ( direction[ichan]!=-3) { - if (abs(diff)>abs(olddiff[ichan])) { - vthresh=vthresh-direction[ichan]; - if (vthresh>(DAC_DR-1)) { - vthresh=(DAC_DR-1); - printf("can't equalize threshold for module %d\n", ichan); - retval=FAIL; - } - if (vthresh<0) { - vthresh=0; - printf("can't equalize threshold for module %d\n", ichan); - retval=FAIL; - } - direction[ichan]=-3; - } else { - vthresh=vthresh+direction[ichan]; - olddiff[ichan]=diff; - change_flag=1; - } -//commented out by dhanya initDACbyIndex(VTHRESH,vthresh, ichan); - } - } - iteration++; - free(scan); - free(scan1); - } -#endif - return retval; -} - - - - - -int trim_with_median(int stop, int im) { - - - int retval=OK; - -#ifdef MCB_FUNCS - int ichan, imod, ichip, ich; - u_int32_t *scan, *scan1; - int *olddiff, *direction; - int med, diff; - int change_flag=1; - int iteration=0; - int me[nModX], me1[nModX]; - int modma, modmi, nm; - int trim; - int *fifodata; - - setFrames(1); - // setNMod(getNModBoard()); - - if (im==ALLMOD){ - modmi=0; - modma=nModX; - } else { - modmi=im; - modma=im+1; - } - nm=modma-modmi; - - olddiff=malloc(4*nModX*nChips*nChans); - direction=malloc(4*nModX*nChips*nChans); - for (imod=modmi; imod0) { - direction[ichan]=1; - } else { - direction[ichan]=-1; - } - } - if ( direction[ichan]!=-3) { - if (abs(diff)>abs(olddiff[ichan])) { - trim=getTrimbit(imod,ichip,ich)+direction[ichan]; - printf("%d old diff %d < new diff %d %d - trimbit %d\n",ichan, olddiff[ichan], diff, direction[ichan], trim); - direction[ichan]=-3; - } else { - trim=getTrimbit(imod,ichip,ich)-direction[ichan]; - olddiff[ichan]=diff; - change_flag=1; - } - if (trim>TRIM_DR) { - trim=63; - printf("can't trim channel %d chip %d module %d to trim %d\n",ich, ichip, imod, trim); - retval=FAIL; - } - if (trim<0) { - printf("can't trim channel %d chip %d module %d to trim %d\n",ich, ichip, imod, trim); - trim=0; - retval=FAIL; - } - initChannel(trim,0,0,1,0,0,imod); - } - } - } - } - iteration++; - free(scan); - free(scan1); - } - free(olddiff); - free(direction); -#endif - return retval; -} diff --git a/slsDetectorSoftware/gotthardDetectorServer/trimming_funcs.h b/slsDetectorSoftware/gotthardDetectorServer/trimming_funcs.h deleted file mode 100755 index 42ecea24a..000000000 --- a/slsDetectorSoftware/gotthardDetectorServer/trimming_funcs.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef TRIMMING_FUNCS_H -#define TRIMMING_FUNCS_H - -#include "sls_detector_defs.h" - -int trim_fixed_settings(int countlim, int par2, int imod); -int trim_with_noise(int countlim, int nsigma, int imod); -int trim_with_beam(int countlim, int nsigma, int imod); -int trim_improve(int maxit, int par2, int imod); -int calcthr_from_vcal(int vcal); -int calccal_from_vthr(int vthr); -int choose_vthresh_and_vtrim(int countlim, int nsigma, int imod); - -int choose_vthresh(); -int trim_with_level(int countlim, int imod); -int trim_with_median(int stop, int imod); -int calcthr_from_vcal(int vcal); -int calccal_from_vthr(int vthr); - -#endif diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index 97f011eb6..8d0e67711 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -2458,7 +2458,7 @@ int* multiSlsDetector::getDataFromDetector() { int nodatadet = -1; int nodatadetectortype = false; detectorType types = getDetectorsType(); - if (types == EIGER || types == JUNGFRAU) { + if (types == EIGER || types == JUNGFRAU || GOTTHARD || PROPIX) { nodatadetectortype = true; } @@ -5082,7 +5082,7 @@ void multiSlsDetector::readFrameFromReceiver() { coordX = doc["column"].GetUint(); if (eiger) coordY = (nY - 1) - coordY; - //cout << "X:" << doc["row"].GetUint() <<" Y:"<SetHardCodedPosition(row, col); } }