From 31589ce3522f269b94932abcaa13de69cf1ea02c Mon Sep 17 00:00:00 2001 From: Anna Bergamaschi Date: Tue, 19 Dec 2017 13:40:05 +0100 Subject: [PATCH] added and fixed gotthard 25um file and zmq photon finder --- .../gotthardDoubleModuleDataNew.h | 4 +- .../gotthardExecutables/Makefile.onTheFly | 10 +- .../gotthard25umOnTheFlyAnalysis.C | 149 ++++--- .../gotthard25umZmqAnalysis.C | 386 ++++++++++++++++++ .../interpolatingDetector.h | 192 +++++++-- .../interpolations/linearInterpolation.h | 28 +- .../moenchExecutables/Makefile.moench_zmq | 8 +- .../moenchZmqClusterFinder.cpp | 9 +- .../moenchZmqInterpolating.cpp | 217 ++++++++++ slsDetectorCalibration/singlePhotonDetector.h | 7 +- .../jctbDetectorServer/firmware_funcs.c | 4 +- .../jctbDetectorServer/gitInfo.txt | 14 +- .../jctbDetectorServer/gitInfoMoench.h | 10 +- .../jctbDetectorServer/jctbDetectorServer | Bin 118844 -> 118844 bytes .../jctbDetectorServer/registers_m.h | 6 +- 15 files changed, 925 insertions(+), 119 deletions(-) create mode 100644 slsDetectorCalibration/gotthardExecutables/gotthard25umZmqAnalysis.C create mode 100644 slsDetectorCalibration/moenchExecutables/moenchZmqInterpolating.cpp diff --git a/slsDetectorCalibration/dataStructures/gotthardDoubleModuleDataNew.h b/slsDetectorCalibration/dataStructures/gotthardDoubleModuleDataNew.h index e80dbd16e..1daa9db82 100644 --- a/slsDetectorCalibration/dataStructures/gotthardDoubleModuleDataNew.h +++ b/slsDetectorCalibration/dataStructures/gotthardDoubleModuleDataNew.h @@ -50,9 +50,9 @@ public: for(int ix=0; ix @@ -27,9 +27,60 @@ void *gotthardProcessFrame() { + + + + + + if (argc < 3 ) { + cprintf(RED, "Help: ./trial [receive socket ip] [receive starting port number] [send_socket ip] [send starting port number]\n"); + return EXIT_FAILURE; + } + + // receive parameters + bool send = false; + char* socketip=argv[1]; + uint32_t portnum = atoi(argv[2]); + int size = 32*2*5000;//atoi(argv[3]); + + // send parameters if any + char* socketip2 = 0; + uint32_t portnum2 = 0; + if (argc > 3) { + send = true; + socketip2 = argv[3]; + portnum2 = atoi(argv[4]); + } + cout << "\nrx socket ip : " << socketip << + "\nrx port num : " << portnum ; + if (send) { + cout << "\nsd socket ip : " << socketip2 << + "\nsd port num : " << portnum2; + } + cout << endl; + + + + + + + + + + + + + + + + + + + char fname0[10000], fname1[10000]; char fformat[10000]; - strcpy(fformat,"/external_pool/gotthard_data/datadir_gotthardI/bchip074075/20170731/Xray/xray_15kV_200uA_5us_d%d_f000000040000_0.raw"); + int fifosize=1000; + strcpy(fformat,"/external_pool/gotthard_data/datadir_gotthardI/bchip074075/20170731/Xray/xray_15kV_200uA_5us_d%d_f000000000000_0.raw"); sprintf(fname0,fformat,0,0); sprintf(fname1,fformat,1,1); @@ -65,9 +116,20 @@ void *gotthardProcessFrame() { filter->setFrameMode(eFrame); - char buff[2*(48+1280*2)]; - char *buff0=buff; - char *buff1=buff+48+1280*2; + char *buff;//[2*(48+1280*2)]; + + + char *buff0; + char *buff1; + + + multiThreadedAnalogDetector *mt=new multiThreadedAnalogDetector(filter,nthreads,fifosize); + mt->setFrameMode(eFrame); + mt->StartThreads(); + mt->popFree(buff); + buff0=buff; + buff1=buff+48+1280*2; + int photons[1280*2]; @@ -75,33 +137,16 @@ void *gotthardProcessFrame() { int ok=0; ifstream filebin0,filebin1; std::time_t end_time; - + int16_t dout[1280*2]; int iFrame=-1; int np=-1; - // typedef struct { - // uint64_t frameNumber; /**< is the frame number */ - // uint32_t expLength; /**< is the subframe number (32 bit eiger) or real time exposure time in 100ns (others) */ - // uint32_t packetNumber; /**< is the packet number */ - // uint64_t bunchId; /**< is the bunch id from beamline */ - // uint64_t timestamp; /**< is the time stamp with 10 MHz clock */ - // uint16_t modId; /**< is the unique module id (unique even for left, right, top, bottom) */ - // uint16_t xCoord; /**< is the x coordinate in the complete detector system */ - // uint16_t yCoord; /**< is the y coordinate in the complete detector system */ - // uint16_t zCoord; /**< is the z coordinate in the complete detector system */ - // uint32_t debug; /**< is for debugging purposes */ - // uint16_t roundRNumber; /**< is the round robin set number */ - // uint8_t detType; /**< is the detector type see :: detectorType */ - // uint8_t version; /**< is the version number of this structure format */ - // } sls_detector_header; - - // multiThreadedDetector *mt=new multiThreadedDetector(filter,nthreads,100); nph=0; nph1=0; //int np; int iph; int data_ready=1; - + int *image; // filter->setROI(0,512,0,1); @@ -117,39 +162,49 @@ void *gotthardProcessFrame() { nf=0; iFrame=-1; while ((decoder->readNextFrame(filebin0, iFrame, np, buff0)) && (decoder->readNextFrame(filebin1, iFrame, np, buff1))) { - filter->processData(buff, photons); - cout << nf << " " << decoder->getFrameNumber(buff0) << " " << decoder->getFrameNumber(buff1) << " " << filter->getPhFrame() << " " << filter->getPhTot() << endl; + //filter->processData(buff, photons); + // cout << nf << " " << decoder->getFrameNumber(buff0) << " " << decoder->getFrameNumber(buff1) << " " << filter->getPhFrame() << " " << filter->getPhTot() << endl; + // for (int i=0; i<1280*2; i++) { + // filter->addToPedestal(buff,i,0); + // dout[i]=filter->subtractPedestal(buff,i,0); + // if (nf>10 && i<512) + // if (i%2) + // cout << nf << " " << i << " " << filter->getPedestal(i,0) << " " << det->getValue(buff,i,0) << " " << decoder->getValue(buff1,1280-1-i/2,0)<< " " << dout[i] << endl; + // else + // cout << nf << " " << i << " " << filter->getPedestal(i,0) << " " << det->getValue(buff,i,0) << " " << decoder->getValue(buff0,i/2,0)<< " " << dout[i] << endl; + + // } + mt->pushData(buff); + mt->nextThread(); + mt->popFree(buff); + buff0=buff; + buff1=buff+48+1280*2; + nf++; - } // cout << id << " " << nf << endl; - if (nf%1000==0) { - std::time(&end_time); - cout << std::ctime(&end_time) << " " << nf << endl; + if (nf%10000==0) { + while (mt->isBusy()) {;} + image=filter->getImage(); + if (image) { + cout << nf << "*****************" << endl; + for (int i=0; i<512; i++) { + cout << image[i] << "\t"; + } + cout << endl; + } + filter->clearImage(); + std::time(&end_time); + cout << std::ctime(&end_time) << " " << nf << endl; + } + iFrame=-1; } - //delete [] buff; - iFrame=-1; - - filebin0.close(); filebin1.close(); } else cout << "Could not open file " << fname0<< " or " << fname1 << endl; - - - //mt->StopThreads(); - - // char tit[10000]; - //sprintf(tit,"/scratch/int_image_mt%d.tiff",nthreads); - - //mt->writeInterpolatedImage(tit); - // delete [] etah; - - // delete interp; - //delete decoder; - //cout << "Read " << nf << " frames" << endl; return NULL; } diff --git a/slsDetectorCalibration/gotthardExecutables/gotthard25umZmqAnalysis.C b/slsDetectorCalibration/gotthardExecutables/gotthard25umZmqAnalysis.C new file mode 100644 index 000000000..90d84ee18 --- /dev/null +++ b/slsDetectorCalibration/gotthardExecutables/gotthard25umZmqAnalysis.C @@ -0,0 +1,386 @@ +#include "sls_receiver_defs.h" +//#ifdef ZMQ +#include "ZmqSocket.h" +//#endif +#include +#include +#include +#include +#include +#include +//#include +//#include +//#include +#include +#include + +#include "gotthardModuleDataNew.h" +#include "gotthardDoubleModuleDataNew.h" + +#include "singlePhotonDetector.h" +//#include "interpolatingDetector.h" +//#include "linearInterpolation.h" +#include "multiThreadedAnalogDetector.h" + +#include + +#define NC 1280 +#define NR 1 + +#include "tiffIO.h" + + + + + + +#define SLS_DETECTOR_JSON_HEADER_VERSION 0x2 +int main(int argc, char *argv[]){ + //void *gotthardProcessFrame() { + + + + + + + + + + + + + + + + + int fifosize=1000; + int nthreads=3; + int nph, nph1; + int etabins=550; + double etamin=-1, etamax=2; + int nsubpix=1; + float *etah=new float[etabins*etabins]; + int *heta, *himage; + int offset=48; + #ifdef ZMQ + offset=0; + #endif + #ifndef ZMQ + offset=48; + #endif + + + gotthardModuleDataNew *decoder=new gotthardModuleDataNew(); + gotthardDoubleModuleDataNew *det=new gotthardDoubleModuleDataNew(offset); + singlePhotonDetector *filter=new singlePhotonDetector(det,3, 5, 1, 0, 1000, 200); + filter->setROI(0,512,0,1); + char *buff;//[2*(48+1280*2)]; + char *buff0; + char *buff1; + multiThreadedAnalogDetector *mt=new multiThreadedAnalogDetector(filter,nthreads,fifosize); + mt->setFrameMode(eFrame); + mt->StartThreads(); + mt->popFree(buff); + buff0=buff; + buff1=buff+48+1280*2; + int photons[1280*2]; + int nf=0; + int ok=0; + std::time_t end_time; + //int16_t dout[1280*2]; + int iFrame=-1; + int np=-1; + nph=0; + nph1=0; + //int np; + int iph; + int data_ready=1; + int *image; + + + + int length; + int nnx, nny,nns; + int nix, niy,nis; + // infinite loop + int ix, iy, isx, isy; + + filter->getImageSize(nnx, nny,nns); + int16_t *dout=new int16_t [nnx*nny]; + + + +#ifdef ZMQ + if (argc < 3 ) { + cprintf(RED, "Help: %s [receive socket ip] [receive starting port number] [send_socket ip] [send starting port number]\n",argv[0]); + return EXIT_FAILURE; + } + + // receive parameters + bool send = false; + char* socketip=argv[1]; + uint32_t portnum = atoi(argv[2]); + int size = nnx*nny*2; + + // send parameters if any + char* socketip2 = 0; + uint32_t portnum2 = 0; + if (argc > 3) { + send = true; + socketip2 = argv[3]; + portnum2 = atoi(argv[4]); + } + cout << "\nrx socket ip : " << socketip << + "\nrx port num : " << portnum ; + if (send) { + cout << "\nsd socket ip : " << socketip2 << + "\nsd port num : " << portnum2; + } + cout << endl; + + + + // receive socket + ZmqSocket* zmqsocket0 = new ZmqSocket(socketip,portnum); + if (zmqsocket0->IsError()) { + cprintf(RED, "Error: Could not create Zmq socket on port %d with ip %s\n", portnum, socketip); + delete zmqsocket0; + return EXIT_FAILURE; + } + + ZmqSocket* zmqsocket1 = new ZmqSocket(socketip,portnum+1); + if (zmqsocket1->IsError()) { + cprintf(RED, "Error: Could not create Zmq socket on port %d with ip %s\n", portnum+1, socketip); + delete zmqsocket1; + delete zmqsocket0; + return EXIT_FAILURE; + } + + + zmqsocket0->Connect(); + printf("Zmq Client 0 at %s\n", zmqsocket0->GetZmqServerAddress()); + zmqsocket1->Connect(); + printf("Zmq Client 1 at %s\n", zmqsocket1->GetZmqServerAddress()); + + // send socket + ZmqSocket* zmqsocket2 = 0; + ZmqSocket* zmqsocket3 = 0; + if (send) { + zmqsocket2 = new ZmqSocket(portnum2, socketip2); + if (zmqsocket2->IsError()) { + bprintf(RED, "Error: Could not create Zmq socket server on port %d and ip %s\n", portnum2, socketip2); + delete zmqsocket2; + delete zmqsocket1; + delete zmqsocket0; + return EXIT_FAILURE; + } + + zmqsocket3 = new ZmqSocket(portnum2+1, socketip2); + if (zmqsocket3->IsError()) { + bprintf(RED, "Error: Could not create Zmq socket server on port %d and ip %s\n", portnum2+1, socketip2); + delete zmqsocket3; + delete zmqsocket2; + delete zmqsocket1; + delete zmqsocket0; + return EXIT_FAILURE; + } + + zmqsocket2->Connect(); + printf("Zmq Server 0 started at %s\n", zmqsocket2->GetZmqServerAddress()); + zmqsocket3->Connect(); + printf("Zmq Server 1 started at %s\n", zmqsocket3->GetZmqServerAddress()); + } + + + + + + + + uint64_t acqIndex1 = -1; + uint64_t frameIndex1 = -1; + uint32_t subframeIndex1 = -1; + uint64_t fileindex1 = -1; + string filename1 = ""; + + uint64_t acqIndex0 = -1; + uint64_t frameIndex0 = -1; + uint32_t subframeIndex0 = -1; + uint64_t fileindex0 = -1; + string filename0 = ""; + + + + + + + + + #endif + + + + + + + + + + + + + char ofname[10000]; + FILE *fout=NULL; + for (int i=0; ireadNextFrame(filebin0, iFrame, np, buff0)) && (decoder->readNextFrame(filebin1, iFrame, np, buff1))) { +#endif + + + + + +#ifdef ZMQ + + while(1) { + if ((!zmqsocket0->ReceiveHeader(0, acqIndex0, frameIndex0, subframeIndex0, filename0, fileindex0)) && (!zmqsocket1->ReceiveHeader(0, acqIndex1, frameIndex1, subframeIndex1, filename1, fileindex1))){ + + + + while (mt->isBusy()) {;} + image=filter->getImage(); + if (image) { + fout=fopen(ofname,"w"); + //cout << nf << "*****************" << endl; + for (int i=0; i<512; i++) { + fprintf(fout,"%d %d\n",i,image[i]); + dout[i]=image[i]; + } + fclose(fout);; + } + + + if (send) { + strcpy(fname0,filename0.c_str()); + strcpy(fname1,filename1.c_str()); + // zmqsocket2->SendHeaderData(0, false, SLS_DETECTOR_JSON_HEADER_VERSION,16,fileindex,400,400,400*400, acqIndex,frameIndex,fname, acqIndex, 0,0,0,0,0,0,0,0,0,0,0,1); + zmqsocket2->SendHeaderData(0, false, SLS_DETECTOR_JSON_HEADER_VERSION,0,0,0,0,0, 0,0,fname0, 0, 0,0,0,0,0,0,0,0,0,0,0,1); + zmqsocket3->SendHeaderData(0, false, SLS_DETECTOR_JSON_HEADER_VERSION,0,0,0,0,0, 0,0,fname1, 0, 0,0,0,0,0,0,0,0,0,0,0,1); + + zmqsocket2->SendData((char*)dout,size/2); + zmqsocket3->SendData(((char*)dout)+size/2,size/2); + // cprintf(GREEN, "Sent Data\n"); + + + zmqsocket2->SendHeaderData(0, true, SLS_DETECTOR_JSON_HEADER_VERSION); + zmqsocket3->SendHeaderData(0, true, SLS_DETECTOR_JSON_HEADER_VERSION); + + cprintf(RED, "Received %d frames\n", nf); + + } + + + filter->clearImage(); + // std::time(&end_time); + // cout << std::ctime(&end_time) << " " << nf << endl; + + + + + continue; + } + if (acqIndex0!=acqIndex1) + cout << "different acquisition indexes " << acqIndex0 << " and " << acqIndex1 << endl; + if (frameIndex0!=frameIndex1) + cout << "different frame indexes " << frameIndex0 << " and " << frameIndex1 << endl; + + + + length = zmqsocket0->ReceiveData(0, buff0, size/2); + length += zmqsocket0->ReceiveData(0, buff1, size/2); + irun=fileindex0; + sprintf(ofname,"%s_%d.ph",filename0.c_str(),fileindex0); + +#endif + + + + mt->pushData(buff); + mt->nextThread(); + mt->popFree(buff); + buff0=buff; + buff1=buff+48+1280*2; + + nf++; + + + + +#ifndef ZMQ + + + while (mt->isBusy()) {;} + image=filter->getImage(); + if (image) { + fout=fopen(ofname,"w"); + //cout << nf << "*****************" << endl; + for (int i=0; i<512; i++) { + fprintf(fout,"%d %d\n",i,image[i]); + } + fclose(fout);; + } + filter->clearImage(); + + + + iFrame=-1; + } + + filebin0.close(); + filebin1.close(); + } + else + cout << "Could not open file " << fname0<< " or " << fname1 << endl; +#endif + + } + return NULL; + + + +} diff --git a/slsDetectorCalibration/interpolatingDetector.h b/slsDetectorCalibration/interpolatingDetector.h index 4135bb35b..321862b96 100644 --- a/slsDetectorCalibration/interpolatingDetector.h +++ b/slsDetectorCalibration/interpolatingDetector.h @@ -111,13 +111,13 @@ class interpolatingDetector : public singlePhotonDetector { } #ifdef MYROOT1 - virtual TH2F *addToInterpolatedImage(char *data, single_photon_hit *clusters, int &nph) + virtual TH2F *addToInterpolatedImage(char *data, int *val, int &nph) #endif #ifndef MYROOT1 - virtual int *addToInterpolatedImage(char *data, single_photon_hit *clusters, int &nph) + virtual int *addToInterpolatedImage(char *data, int *val, int &nph) #endif { - nph=addFrame(data,clusters,0); + nph=addFrame(data,val,0); if (interp) return interp->getInterpolatedImage(); else @@ -127,13 +127,13 @@ class interpolatingDetector : public singlePhotonDetector { #ifdef MYROOT1 - virtual TH2F *addToFlatField(char *data, single_photon_hit *clusters, int &nph) + virtual TH2F *addToFlatField(char *data, int *val, int &nph) #endif #ifndef MYROOT1 - virtual int *addToFlatField(char *data, single_photon_hit *clusters, int &nph) + virtual int *addToFlatField(char *data, int *val, int &nph) #endif { - nph=addFrame(data,clusters,1); + nph=addFrame(data,val,1); if (interp) return interp->getFlatField(); else @@ -149,8 +149,151 @@ class interpolatingDetector : public singlePhotonDetector { return NULL; } +int addFrame(char *data, int *ph=NULL, int ff=0) { + + + int nph=0; + double val[ny][nx]; + int cy=(clusterSizeY+1)/2; + int cs=(clusterSize+1)/2; + int ir, ic; - int addFrame(char *data, single_photon_hit *clusters=NULL, int ff=0) { + double int_x,int_y, eta_x, eta_y; + double max=0, tl=0, tr=0, bl=0,br=0, *v, vv; + + if (ph==NULL) + ph=image; + + if (iframerms=getPedestalRMS(ix,iy); + + + + for (int ir=-(clusterSizeY/2); ir<(clusterSizeY/2)+1; ir++) { + for (int ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) { + + if ((iy+ir)>=iy && (iy+ir)=ix && (ix+ic)=0) + br+=*v; + if (ir>=0 && ic<=0) + tl+=*v; + if (ir>=0 && ic>=0) + tr+=*v; + if (*v>max) { + max=*v; + } + + + if (ir==0 && ic==0) { + if (*v<-nSigma*cluster->rms) + eventMask[iy][ix]=NEGATIVE_PEDESTAL; + } + + } + } + + if (bl>=br && bl>=tl && bl>=tr) { + (clusters+nph)->quad=BOTTOM_LEFT; + (clusters+nph)->quadTot=bl; + } else if (br>=bl && br>=tl && br>=tr) { + (clusters+nph)->quad=BOTTOM_RIGHT; + (clusters+nph)->quadTot=br; + } else if (tl>=br && tl>=bl && tl>=tr) { + (clusters+nph)->quad=TOP_LEFT; + (clusters+nph)->quadTot=tl; + } else if (tr>=bl && tr>=tl && tr>=br) { + (clusters+nph)->quad=TOP_RIGHT; + (clusters+nph)->quadTot=tr; + } + + if (max>nSigma*cluster->rms || tot>sqrt(clusterSizeY*clusterSize)*nSigma*cluster->rms || ((clusters+nph)->quadTot)>sqrt(cy*cs)*nSigma*cluster->rms) { + if (val[iy][ix]>=max) { + eventMask[iy][ix]=PHOTON_MAX; + (clusters+nph)->tot=tot; + (clusters+nph)->x=ix; + (clusters+nph)->y=iy; + (clusters+nph)->iframe=det->getFrameNumber(data); + (clusters+nph)->ped=getPedestal(ix,iy,0); + for (int ir=-(clusterSizeY/2); ir<(clusterSizeY/2)+1; ir++) { + for (int ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) { + (clusters+nph)->set_data(val[iy+ir][ix+ic],ic,ir); + } + } + + + + + if (interp) { + if (ff) { + interp->addToFlatField((clusters+nph)->quadTot,(clusters+nph)->quad,(clusters+nph)->get_cluster(),eta_x, eta_y); + } else { + interp->getInterpolatedPosition(ix, iy, (clusters+nph)->quadTot,(clusters+nph)->quad,(clusters+nph)->get_cluster(),int_x, int_y); + interp->addToImage(int_x, int_y); + } + } else + image[ix+nx*iy]++; + + + + + + + + + + + nph++; + image[iy*nx+ix]++; + + } else { + eventMask[iy][ix]=PHOTON; + } + } else if (eventMask[iy][ix]==PEDESTAL) { + addToPedestal(data,ix,iy); + } + + + } + } + nphFrame=nph; + nphTot+=nph; + //cout << nphFrame << endl; + // cout <<"**********************************"<< endl; + writeClusters(); + return nphFrame; + +}; + + /********************************************************* + int addFrame(char *data, int ff=0) { double g=1; @@ -262,13 +405,6 @@ class interpolatingDetector : public singlePhotonDetector { } - - /* cout << ix << " " << iy << " " << rest[iy][ix] <<" " << tot << " " << quadTot << endl; */ - /* for (int ir=-(clusterSizeY/2); ir<(clusterSizeY/2)+1; ir++) { */ - /* for (int ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) */ - /* cout << rest[iy+ir][ix+ic] << " " ; */ - /* cout << endl; */ - /* } */ eventMask[iy][ix]=PHOTON_MAX; cl->tot=tot; cl->x=ix; @@ -322,7 +458,7 @@ class interpolatingDetector : public singlePhotonDetector { return nph; } - + ******************************************/ @@ -485,20 +621,20 @@ class interpolatingDetector : public singlePhotonDetector { - virtual void processData(char *data, frameMode i=eFrame, int *val=NULL) { + virtual void processData(char *data, int *val=NULL) { if (interp){ - switch(i) { - case ePedestal: - addToPedestal(data); - break; - case eFlat: - addFrame(data,NULL,1); - break; - default: - addFrame(data,NULL,0); - } - } else - singlePhotonDetector::processData(data,i,val); + switch(fMode) { + case ePedestal: + addToPedestal(data); + break; + case eFlat: + addFrame(data,val,1); + break; + default: + addFrame(data,val,0); + } + } else + singlePhotonDetector::processData(data,val); }; diff --git a/slsDetectorCalibration/interpolations/linearInterpolation.h b/slsDetectorCalibration/interpolations/linearInterpolation.h index 1625e8651..061a1a6e7 100644 --- a/slsDetectorCalibration/interpolations/linearInterpolation.h +++ b/slsDetectorCalibration/interpolations/linearInterpolation.h @@ -32,7 +32,7 @@ class linearInterpolation : public slsInterpolation{ int corner; corner=calcQuad(data, tot, totquad, sDum); - if (ns>2) { + if (nSubPixels>2) { calcEta(totquad, sDum, etax, etay); } getInterpolatedPosition(x, y, etax,etay, corner, int_x, int_y); @@ -41,14 +41,16 @@ class linearInterpolation : public slsInterpolation{ }; - virtual int getInterpolatedPosition(int x, int y, double totquad,int quad,double *cl,double &etax, double &etay) { + virtual void getInterpolatedPosition(int x, int y, double totquad,int quad,double *cl,double &int_x, double &int_y) { - if (ns>2) { + double eta_x, eta_y; + if (nSubPixels>2) { double cc[2][2]; double *cluster[3]; cluster[0]=cl; cluster[1]=cl+3; cluster[2]=cl+6; + int xoff, yoff; switch (quad) { case BOTTOM_LEFT: @@ -74,10 +76,9 @@ class linearInterpolation : public slsInterpolation{ cc[1][0]=cluster[yoff+1][xoff]; cc[0][1]=cluster[yoff][xoff+1]; cc[1][1]=cluster[yoff+1][xoff+1]; - double eta_x, eta_y; - calcEta(quadTot,cc,eta_x,eta_y); + calcEta(totquad,cc,eta_x,eta_y); } - return getInterpolatedPosition(x,y,etax, etay,quad,int_x,int_y); + return getInterpolatedPosition(x,y,eta_x, eta_y,quad,int_x,int_y); @@ -113,20 +114,21 @@ class linearInterpolation : public slsInterpolation{ dY=-1.; break; default: + cout << "bad quadrant" << endl; dX=0.; dY=0.; } - if (ns>2) { - xpos_eta=(etax); - ypos_eta=(etay); + if (nSubPixels>2) { + xpos_eta=(etax)+dX; + ypos_eta=(etay)+dY; } else { - xpos_eta=0; - xpos_eta=0; + xpos_eta=0.5*dX+0.25; + xpos_eta=0.5*dY+0.25; } - int_x=((double)x) + dX + xpos_eta; - int_y=((double)y) + dY + ypos_eta; + int_x=((double)x) + xpos_eta; + int_y=((double)y) + ypos_eta; return; }; diff --git a/slsDetectorCalibration/moenchExecutables/Makefile.moench_zmq b/slsDetectorCalibration/moenchExecutables/Makefile.moench_zmq index 2414bfc9c..46177890f 100644 --- a/slsDetectorCalibration/moenchExecutables/Makefile.moench_zmq +++ b/slsDetectorCalibration/moenchExecutables/Makefile.moench_zmq @@ -6,16 +6,14 @@ INCDIR=-I../../slsReceiverSoftware/include -I$(CBFLIBDIR)/include/ -I. -I../inte LIBHDF5= LDFLAG= -L/usr/lib64/ -lpthread -lm -lstdc++ -L. -lzmq -pthread -lrt -L$(CBFLIBDIR)/lib/ -lhdf5 -ltiff -L$(ZMQLIB) #-L../../bin -MAIN=moench03ZmqOnTheFly.cpp #DESTDIR?=../bin -all: moenchZmqClusterFinder -#moench03ZmqOnTheFly +all: moenchZmqClusterFinder moenchZmqInterpolating -moench03ZmqOnTheFly: $(MAIN) $(INCS) clean - g++ -o moench03ZmqOnTheFly $(MAIN) $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) tiffIO.cpp -DSAVE_ALL +moenchZmqInterpolating: $(MAIN) $(INCS) clean + g++ -o moenchZmqInterpolating moenchZmqInterpolating.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DSAVE_ALL moenchZmqClusterFinder: $(MAIN) $(INCS) clean g++ -o moenchZmqClusterFinder moenchZmqClusterFinder.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DSAVE_ALL diff --git a/slsDetectorCalibration/moenchExecutables/moenchZmqClusterFinder.cpp b/slsDetectorCalibration/moenchExecutables/moenchZmqClusterFinder.cpp index 6564290ee..4fe7c20b9 100644 --- a/slsDetectorCalibration/moenchExecutables/moenchZmqClusterFinder.cpp +++ b/slsDetectorCalibration/moenchExecutables/moenchZmqClusterFinder.cpp @@ -125,7 +125,7 @@ int main(int argc, char *argv[]) { while(1) { - cout << "+++++++++++++++++++++++++++++++LOOP" << endl; + // cout << "+++++++++++++++++++++++++++++++LOOP" << endl; // get header, (if dummy, fail is on parse error or end of acquisition) if (!zmqsocket->ReceiveHeader(0, acqIndex, frameIndex, subframeIndex, filename, fileindex)){ // if (!zmqsocket->ReceiveHeader(0, acqIndex, frameIndex, subframeIndex, filename, fileindex)) { @@ -155,8 +155,11 @@ int main(int argc, char *argv[]) { zmqsocket2->SendHeaderData(0, true, SLS_DETECTOR_JSON_HEADER_VERSION); cprintf(RED, "Sent Dummy\n"); } - fclose(of); - of=NULL; + mt->clearImage(); + if (of) { + fclose(of); + of=NULL; + } continue; //continue to not get out } diff --git a/slsDetectorCalibration/moenchExecutables/moenchZmqInterpolating.cpp b/slsDetectorCalibration/moenchExecutables/moenchZmqInterpolating.cpp new file mode 100644 index 000000000..2b3809b8a --- /dev/null +++ b/slsDetectorCalibration/moenchExecutables/moenchZmqInterpolating.cpp @@ -0,0 +1,217 @@ +#include "sls_receiver_defs.h" +#include "ZmqSocket.h" +#include "moench03T1ZmqDataNew.h" +#include +#include +#include +#include +#include +#include "tiffIO.h" + +#include + +//#include "analogDetector.h" +#include "interpolatingDetector.h" +#include "linearInterpolation.h" +#include "multiThreadedAnalogDetector.h" +#include "ansi.h" +#include +using namespace std; + + +#define SLS_DETECTOR_JSON_HEADER_VERSION 0x2 + + +int main(int argc, char *argv[]) { +/** + * trial.o [socket ip] [starting port number] [send_socket ip] [send port number] + * + */ + FILE *of=NULL; + int fifosize=1000; + int nthreads=20; + int nsubpixels=2; + // help + if (argc < 3 ) { + cprintf(RED, "Help: ./trial [receive socket ip] [receive starting port number] [send_socket ip] [send starting port number]\n"); + return EXIT_FAILURE; + } + + // receive parameters + bool send = false; + char* socketip=argv[1]; + uint32_t portnum = atoi(argv[2]); + int size = 32*2*5000;//atoi(argv[3]); + + // send parameters if any + char* socketip2 = 0; + uint32_t portnum2 = 0; + if (argc > 3) { + send = true; + socketip2 = argv[3]; + portnum2 = atoi(argv[4]); + } + cout << "\nrx socket ip : " << socketip << + "\nrx port num : " << portnum ; + if (send) { + cout << "\nsd socket ip : " << socketip2 << + "\nsd port num : " << portnum2; + } + cout << endl; + //slsDetectorData *det=new moench03T1ZmqDataNew(); + int npx, npy; + moench03T1ZmqDataNew *det=new moench03T1ZmqDataNew(); + det->getDetectorSize(npx, npy); + //analogDetector *filter=new analogDetector(det,1,NULL,1000); + //singlePhotonDetector *filter=new singlePhotonDetector(det,3, 5, 1, 0, 1000, 10); + linearInterpolation *interp=new linearInterpolation(npx,npy,nsubpixels); + interpolatingDetector *filter=new interpolatingDetector(det,interp, 5, 1, 0, 1000, 100,npx,npy); + + + char* buff; + multiThreadedAnalogDetector *mt=new multiThreadedAnalogDetector(filter,nthreads,fifosize); + mt->setFrameMode(eFrame); + mt->StartThreads(); + mt->popFree(buff); + + + + + + // receive socket + ZmqSocket* zmqsocket = new ZmqSocket(socketip,portnum); + + + + if (zmqsocket->IsError()) { + cprintf(RED, "Error: Could not create Zmq socket on port %d with ip %s\n", portnum, socketip); + delete zmqsocket; + return EXIT_FAILURE; + } + zmqsocket->Connect(); + printf("Zmq Client at %s\n", zmqsocket->GetZmqServerAddress()); + + // send socket + ZmqSocket* zmqsocket2 = 0; + cout << "zmq2 " << endl; + if (send) { + zmqsocket2 = new ZmqSocket(portnum2, socketip2); + if (zmqsocket2->IsError()) { + bprintf(RED, "Error: Could not create Zmq socket server on port %d and ip %s\n", portnum2, socketip2); + delete zmqsocket2; + delete zmqsocket; + return EXIT_FAILURE; + } + zmqsocket2->Connect(); + printf("Zmq Server started at %s\n", zmqsocket2->GetZmqServerAddress()); + } + + + // header variables + uint64_t acqIndex = -1; + uint64_t frameIndex = -1; + uint32_t subframeIndex = -1; + uint64_t fileindex = -1; + string filename = ""; + char* image = new char[size]; + //int* image = new int[(size/sizeof(int))](); + + int *nph; + int iframe=0; + char ofname[10000]; + + char fname[10000]; + int length; + int *detimage; + int nnx, nny,nns; + int nix, niy,nis; + filter->getImageSize(nnx, nny,nns); + int16_t *dout=new int16_t [nnx*nny]; + // infinite loop + int ix, iy, isx, isy; + while(1) { + + + // cout << "+++++++++++++++++++++++++++++++LOOP" << endl; + // get header, (if dummy, fail is on parse error or end of acquisition) + if (!zmqsocket->ReceiveHeader(0, acqIndex, frameIndex, subframeIndex, filename, fileindex)){ + // if (!zmqsocket->ReceiveHeader(0, acqIndex, frameIndex, subframeIndex, filename, fileindex)) { + // cprintf(RED, "Got Dummy\n"); + while (mt->isBusy()) {;}//wait until all data are processed from the queues + + + detimage=mt->getImage(nix,niy,nis); + + if (detimage) { + for (ix=0; ixSendHeaderData(0, false, SLS_DETECTOR_JSON_HEADER_VERSION,16,fileindex,400,400,400*400, acqIndex,frameIndex,fname, acqIndex, 0,0,0,0,0,0,0,0,0,0,0,1); + zmqsocket2->SendHeaderData(0, false, SLS_DETECTOR_JSON_HEADER_VERSION,0,0,0,0,0, 0,0,fname, 0, 0,0,0,0,0,0,0,0,0,0,0,1); + + zmqsocket2->SendData((char*)dout,length); + cprintf(GREEN, "Sent Data\n"); + } + + sprintf(ofname,"%s_%d.tiff",filename.c_str(),fileindex); + mt->writeImage(ofname); + + } + // stream dummy to socket2 to signal end of acquisition + if (send) { + zmqsocket2->SendHeaderData(0, true, SLS_DETECTOR_JSON_HEADER_VERSION); + // cprintf(RED, "Sent Dummy\n"); + cprintf(RED, "Received %d frames\n", iframe); + } + mt->clearImage(); + if (of) { + fclose(of); + of=NULL; + } + iframe=0; + continue; //continue to not get out + } + + + if (of==NULL) { + sprintf(ofname,"%s_%d.clust",filename.c_str(),fileindex); + of=fopen(ofname,"w"); + if (of) { + mt->setFilePointer(of); + }else { + cout << "Could not open "<< ofname << " for writing " << endl; + mt->setFilePointer(NULL); + } + } + + // get data + length = zmqsocket->ReceiveData(0, buff, size); + mt->pushData(buff); + mt->nextThread(); + mt->popFree(buff); + + iframe++; + } // exiting infinite loop + + + + delete zmqsocket; + if (send) + delete zmqsocket2; + + + // cout<<"Goodbye"<< endl; + return 0; +} + diff --git a/slsDetectorCalibration/singlePhotonDetector.h b/slsDetectorCalibration/singlePhotonDetector.h index 5121dfc81..38074b581 100644 --- a/slsDetectorCalibration/singlePhotonDetector.h +++ b/slsDetectorCalibration/singlePhotonDetector.h @@ -286,7 +286,7 @@ public analogDetector { } } cout << iframe << " " << nph << endl; - } else return getClusters(data); + } else return getClusters(data, nph); } return NULL; }; @@ -410,7 +410,7 @@ public analogDetector { */ -int *getClusters(char *data) { +int *getClusters(char *data, int *ph=NULL) { int nph=0; @@ -421,6 +421,9 @@ int *getClusters(char *data) { double max=0, tl=0, tr=0, bl=0,br=0, *v, vv; + if (ph==NULL) + ph=image; + if (iframekayVAMixq`+5f&gGg;TIqW z;T5w17t3i4a{yRR@UVEHxuMEoVzb$RVFLwFpaA0>li`CMlU#&E22h{?N~kTn delta 105 zcmV-v0G9u}pa;C52aqWPC^4;kayVAMixq`+5f&gGg;TIqW z;Rdq-7t3i4X#iMH@UVEHxuI%caG_@?> diff --git a/slsDetectorSoftware/jctbDetectorServer/registers_m.h b/slsDetectorSoftware/jctbDetectorServer/registers_m.h index 61932c8db..3351f9a8a 100755 --- a/slsDetectorSoftware/jctbDetectorServer/registers_m.h +++ b/slsDetectorSoftware/jctbDetectorServer/registers_m.h @@ -129,8 +129,10 @@ #define GET_PERIOD_LSB_REG 24<<11//0x76<<11 #define GET_PERIOD_MSB_REG 25<<11//0x77<<11 -#define SET_EXPTIME_LSB_REG 104<<11//0x78<<11 -#define SET_EXPTIME_MSB_REG 105<<11//0x79<<11 +//#define PATTERN_WAIT0_TIME_REG_LSB 114<<11 +//#define PATTERN_WAIT0_TIME_REG_MSB 115<<11 +#define SET_EXPTIME_LSB_REG 114<<11//0x78<<11 +#define SET_EXPTIME_MSB_REG 115<<11//0x79<<11 #define GET_EXPTIME_LSB_REG 26<<11//0x7a<<11 #define GET_EXPTIME_MSB_REG 27<<11//0x7b<<11