From 5403656e79772f44c9bcc680e708c6734cf6deed Mon Sep 17 00:00:00 2001 From: Anna Bergamaschi Date: Wed, 19 Jan 2022 14:56:44 +0100 Subject: [PATCH 1/3] Fixed some stuff for the Zmq process --- slsDetectorCalibration/analogDetector.h | 37 ++- .../dataStructures/moench03T1ZmqDataNew.h | 2 +- slsDetectorCalibration/ghostSummation.h | 2 +- .../interpolations/etaInterpolationBase.h | 10 +- .../interpolations/etaInterpolationPosXY.h | 15 +- .../interpolations/slsInterpolation.h | 3 +- .../moenchExecutables/Makefile.zmq | 7 +- .../moenchExecutables/moenchZmqProcess.cpp | 283 ++++++++---------- .../multiThreadedAnalogDetector.h | 25 +- .../multiThreadedCountingDetector.h | 2 +- .../multiThreadedInterpolatingDetector.h | 2 +- slsDetectorCalibration/singlePhotonDetector.h | 37 +-- 12 files changed, 221 insertions(+), 204 deletions(-) diff --git a/slsDetectorCalibration/analogDetector.h b/slsDetectorCalibration/analogDetector.h index bda071176..098160bd0 100644 --- a/slsDetectorCalibration/analogDetector.h +++ b/slsDetectorCalibration/analogDetector.h @@ -32,11 +32,11 @@ using namespace std; /** enum to define the flags of the data set, which are needed to seect the type of processing it should undergo: frame, pedestal, flat */ - enum frameMode { eFrame, ePedestal, eFlat }; +enum frameMode { eFrame, ePedestal, eFlat, eRaw }; /** enum to define the detector mode */ - enum detectorMode { eAnalog, ePhotonCounting, eInterpolating }; +enum detectorMode { eAnalog, ePhotonCounting, eInterpolating }; #endif @@ -1034,7 +1034,7 @@ template class analogDetector { \returns converted number of photons. If no threshold is set, returns gain converted pedestal subtracted data. */ - virtual int getNPhotons(char *data, int ix, int iy=0) { + int convertToPhotons(char *data, int ix, int iy=0) { int nph=0; double v; if (ix>=0 && ix=0 && iy class analogDetector { \param nph pointer where the photons should added. If NULL,the internal image is used \returns pointer to array containing the number of photons */ - int *getNPhotons(char *data, int *nph=NULL) { + virtual int *getNPhotons(char *data, int *nph=NULL) { //double val; if (nph==NULL) nph=image; newFrame(data); - + /* cout << fMode << endl; */ + + /* switch(fMode) { */ + /* case eRaw: */ + /* cout << "raw" << endl; */ + /* break; */ + /* default: */ + /* cout << "analog" << endl; */ + /* } */ //calcGhost(data); addToCommonMode(data); for (iy=ymin; iyisGood(ix,iy)) - nph[iy*nx+ix]+=getNPhotons(data, ix, iy); + for (ix=xmin; ixgetChannel(data,ix,iy); + break; + default: + if (det->isGood(ix,iy)) + nph[iy*nx+ix]+=convertToPhotons(data, ix, iy); + } } } return nph; @@ -1164,7 +1179,7 @@ template class analogDetector { for (ix=xmi; ixisGood(ix,iy)) { if (ix>=0 && ix=0 && iy class analogDetector { addToPedestal(data,1); break; default: - // cout << "analog " << endl; + //cout << "analog frame" << endl; //subtractPedestal(data); - getNPhotons(data); + analogDetector::getNPhotons(data); } }; diff --git a/slsDetectorCalibration/dataStructures/moench03T1ZmqDataNew.h b/slsDetectorCalibration/dataStructures/moench03T1ZmqDataNew.h index 2a5fbecba..376769066 100644 --- a/slsDetectorCalibration/dataStructures/moench03T1ZmqDataNew.h +++ b/slsDetectorCalibration/dataStructures/moench03T1ZmqDataNew.h @@ -55,7 +55,7 @@ class moench03T1ZmqDataNew : public slsDetectorData { int iadc; int ix, iy; - int npackets=40; + //int npackets=40; int i; int adc4(0); diff --git a/slsDetectorCalibration/ghostSummation.h b/slsDetectorCalibration/ghostSummation.h index 82721059d..e6986ecfe 100644 --- a/slsDetectorCalibration/ghostSummation.h +++ b/slsDetectorCalibration/ghostSummation.h @@ -30,7 +30,7 @@ template class ghostSummation { ghost=new double[nx*ny]; } - ~ghostSummation() {delete [] ghost;}; + virtual ~ghostSummation() {delete [] ghost;}; virtual ghostSummation *Clone() { return new ghostSummation(this); diff --git a/slsDetectorCalibration/interpolations/etaInterpolationBase.h b/slsDetectorCalibration/interpolations/etaInterpolationBase.h index d04e125db..c87449051 100644 --- a/slsDetectorCalibration/interpolations/etaInterpolationBase.h +++ b/slsDetectorCalibration/interpolations/etaInterpolationBase.h @@ -302,7 +302,11 @@ float *gethhx() double diff=0, d; //double bsize=1./nSubPixels; int nbad=0; - double p_tot_x[nSubPixelsX], p_tot_y[nSubPixelsY], p_tot[nSubPixelsX*nSubPixelsY]; + double *p_tot_x=new double[nSubPixelsX]; + double *p_tot_y=new double[nSubPixelsY]; + double *p_tot= new double[nSubPixelsX*nSubPixelsY]; + + double maxdiff=0, mindiff=avg*nSubPixelsX*nSubPixelsY; int ipx, ipy; @@ -362,6 +366,10 @@ float *gethhx() // cout << "Bad pixels: " << 100.*(float)nbad/((float)(nSubPixels*nSubPixels)) << " %" << endl; + delete [] p_tot_x; + delete [] p_tot_y; + delete [] p_tot; + return sqrt(diff); } diff --git a/slsDetectorCalibration/interpolations/etaInterpolationPosXY.h b/slsDetectorCalibration/interpolations/etaInterpolationPosXY.h index 5d28bfffb..2596a3792 100644 --- a/slsDetectorCalibration/interpolations/etaInterpolationPosXY.h +++ b/slsDetectorCalibration/interpolations/etaInterpolationPosXY.h @@ -40,10 +40,10 @@ class etaInterpolationPosXY : public virtual etaInterpolationBase{ if (tot_eta<=0) {ok=0; return;}; - double hx[nbetaX]; //profile x - double hy[nbetaY]; //profile y - double hix[nbetaX]; //integral of projection x - double hiy[nbetaY]; //integral of projection y + double *hx=new double[nbetaX]; //profile x + double *hy=new double[nbetaY]; //profile y + double *hix=new double[nbetaX]; //integral of projection x + double *hiy=new double[nbetaY]; //integral of projection y // int ii=0; double etax, etay; for (int ib=0; ibnPixelsX; nPixelsY=orig->nPixelsY; diff --git a/slsDetectorCalibration/moenchExecutables/Makefile.zmq b/slsDetectorCalibration/moenchExecutables/Makefile.zmq index af60de798..d2ada9fb0 100644 --- a/slsDetectorCalibration/moenchExecutables/Makefile.zmq +++ b/slsDetectorCalibration/moenchExecutables/Makefile.zmq @@ -7,14 +7,15 @@ LDFLAG= -L/usr/lib64/ -lpthread -lm -lstdc++ -lzmq -pthread -lrt -ltiff -O3 #DESTDIR?=../bin -all: moenchZmqProcess moenchZmq04Process +all: moenchZmqProcess +#moenchZmq04Process #moenchZmqProcessCtbGui moenchZmqProcess: moenchZmqProcess.cpp clean g++ -o moenchZmqProcess moenchZmqProcess.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DNEWZMQ -DINTERP -moenchZmq04Process: moenchZmqProcess.cpp clean - g++ -o moench04ZmqProcess moenchZmqProcess.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DNEWZMQ -DINTERP -DMOENCH04 +#moenchZmq04Process: moenchZmqProcess.cpp clean# +# g++ -o moench04ZmqProcess moenchZmqProcess.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DNEWZMQ -DINTERP -DMOENCH04 #moenchZmqProcessCtbGui: moenchZmqProcess.cpp clean # g++ -o moenchZmqProcessCtbGui moenchZmqProcess.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DNEWZMQ -DINTERP -DCTBGUI diff --git a/slsDetectorCalibration/moenchExecutables/moenchZmqProcess.cpp b/slsDetectorCalibration/moenchExecutables/moenchZmqProcess.cpp index 70237919b..49f7668b5 100644 --- a/slsDetectorCalibration/moenchExecutables/moenchZmqProcess.cpp +++ b/slsDetectorCalibration/moenchExecutables/moenchZmqProcess.cpp @@ -68,8 +68,9 @@ int main(int argc, char *argv[]) { int etabins=1000, etabinsy=1000;//nsubpix*2*100; double etamin=-1, etamax=2; int nSubPixelsX=2; - // int emin, emax; + int emin, emax; int nSubPixelsY=2; + // help if (argc < 3 ) { cprintf(RED, "Help: ./trial [receive socket ip] [receive starting port number] [send_socket ip] [send starting port number] [nthreads] [nsubpix] [gainmap] [etafile]\n"); @@ -159,7 +160,7 @@ int main(int argc, char *argv[]) { //int multisize=size; //int dataSize=size; - char dummybuff[size]; + char *dummybuff=new char[size]; moench03CommonMode *cm=NULL; @@ -355,7 +356,7 @@ int main(int argc, char *argv[]) { // int resetFlat=0; //int resetPed=0; - // int nsubPixels=1; + //int nsubPixels=1; //int isPedestal=0; //int isFlat=0; int newFrame=1; @@ -393,7 +394,7 @@ int main(int argc, char *argv[]) { cout << "Measurement lasted " << (end-begin).count()*0.000001 << " ms" << endl; while (mt->isBusy()) {;}//wait until all data are processed from the queues - + usleep(100); if (of) { mt->setFilePointer(NULL); fclose(of); @@ -626,40 +627,8 @@ int main(int argc, char *argv[]) { //strcpy(fname,filename.c_str()); fname=filename; - // cprintf(BLUE, "Header Info:\n" - // "size: %u\n" - // "multisize: %u\n" - // "dynamicRange: %u\n" - // "nPixelsX: %u\n" - // "nPixelsY: %u\n" - // "currentFileName: %s\n" - // "currentAcquisitionIndex: %lu\n" - // "currentFrameIndex: %lu\n" - // "currentFileIndex: %lu\n" - // "currentSubFrameIndex: %u\n" - // "xCoordX: %u\n" - // "yCoordY: %u\n" - // "zCoordZ: %u\n" - // "flippedDataX: %u\n" - // "packetNumber: %u\n" - // "bunchId: %u\n" - // "timestamp: %u\n" - // "modId: %u\n" - // "debug: %u\n" - // "roundRNumber: %u\n" - // "detType: %u\n" - // "version: %u\n", - // size, multisize, dynamicRange, nPixelsX, nPixelsY, - // filename.c_str(), acqIndex, - // frameIndex, fileindex, subFrameIndex, - // xCoord, yCoord,zCoord, - // flippedDataX, packetNumber, bunchId, timestamp, modId, debug, roundRNumber, detType, version); - addJsonHeader=zHeader.addJsonHeader; - /* Analog detector commands */ - //isPedestal=0; - //isFlat=0; rms=0; fMode=eFrame; frameMode_s="frame"; @@ -682,6 +651,11 @@ int main(int argc, char *argv[]) { fMode=ePedestal; //isPedestal=1; rms=1; + } else if (frameMode_s == "raw"){ + //mt->newDataSet(); //resets pedestal + // cprintf(MAGENTA, "Resetting pedestal\n"); + fMode=eRaw; + //isPedestal=1; } #ifdef INTERP else if (frameMode_s == "flatfield") { @@ -695,7 +669,6 @@ int main(int argc, char *argv[]) { } //#endif else { - fMode=eFrame; //isPedestal=0; //isFlat=0; fMode=eFrame; @@ -710,14 +683,8 @@ int main(int argc, char *argv[]) { cprintf(MAGENTA, "Threshold: "); if (addJsonHeader.find("threshold")!= addJsonHeader.end()) { istringstream(addJsonHeader.at("threshold")) >>threshold; - // threshold=atoi(addJsonHeader.at("threshold").c_str());//doc["frameMode"].GetString(); } - //if (doc.HasMember("threshold")) { - //if (doc["threshold"].IsInt()) { - // threshold=doc["threshold"].GetInt(); mt->setThreshold(threshold); - // } - // } cprintf(MAGENTA, "%d\n", threshold); xmin=0; @@ -728,24 +695,6 @@ int main(int argc, char *argv[]) { if (addJsonHeader.find("roi")!= addJsonHeader.end()) { istringstream(addJsonHeader.at("roi")) >> xmin >> xmax >> ymin >> ymax ; - // if (doc.HasMember("roi")) { - //if (doc["roi"].IsArray()) { - // if (doc["roi"].Size() > 0 ) - // if (doc["roi"][0].IsInt()) - // xmin=doc["roi"][0].GetInt(); - - // if (doc["roi"].Size() > 1 ) - // if (doc["roi"][1].IsInt()) - // xmax=doc["roi"][1].GetInt(); - - // if (doc["roi"].Size() > 2 ) - // if (doc["roi"][2].IsInt()) - // ymin=doc["roi"][2].GetInt(); - - // if (doc["roi"].Size() > 3 ) - // if (doc["roi"][3].IsInt()) - // ymax=doc["roi"][3].GetInt(); - // } } cprintf(MAGENTA, "%d %d %d %d\n", xmin, xmax, ymin, ymax); @@ -754,17 +703,10 @@ int main(int argc, char *argv[]) { istringstream(addJsonHeader.at("dynamicRange")) >> dr ; dr=32; } - // if (doc.HasMember("dynamicRange")) { - // dr=doc["dynamicRange"].GetUint(); - // dr=32; - // } - dMode=eAnalog; detectorMode_s="analog"; cprintf(MAGENTA, "Detector mode: "); if (addJsonHeader.find("detectorMode")!= addJsonHeader.end()) {; - //if (doc.HasMember("detectorMode")) { - //if (doc["detectorMode"].IsString()) { detectorMode_s=addJsonHeader.at("detectorMode");//=doc["detectorMode"].GetString(); #ifdef INTERP if (detectorMode_s == "interpolating"){ @@ -783,98 +725,69 @@ int main(int argc, char *argv[]) { mt->setInterpolation(NULL); #endif } - // } + // } + if (fMode==eRaw) { + detectorMode_s = "analog"; + dMode=eAnalog; + } } mt->setDetectorMode(dMode); cprintf(MAGENTA, "%s\n" , detectorMode_s.c_str()); - // cout << "done " << endl; + cout << "done " << endl; - // /* Single Photon Detector commands */ - // nSigma=5; - // if (doc.HasMember("nSigma")) { - // if (doc["nSigma"].IsInt()) - // nSigma=doc["nSigma"].GetInt(); - // mt->setNSigma(nSigma); - // } + /* Single Photon Detector commands */ + nSigma=5; - // emin=-1; - // emax=-1; - // if (doc.HasMember("energyRange")) { - // if (doc["energyRange"].IsArray()) { - // if (doc["energyRange"].Size() > 0 ) - // if (doc["energyRange"][0].IsInt()) - // emin=doc["energyRange"][0].GetInt(); - - // if (doc["energyRange"].Size() > 1 ) - // if (doc["energyRange"][1].IsInt()) - // emax=doc["energyRange"][1].GetUint(); - // } - // } - // if (doc.HasMember("eMin")) { - // if (doc["eMin"][1].IsInt()) - // emin=doc["eMin"].GetInt(); - // } - // if (doc.HasMember("eMax")) { - // if (doc["eMax"][1].IsInt()) - // emin=doc["eMax"].GetInt(); - // } - // mt->setEnergyRange(emin,emax); + if (addJsonHeader.find("nSigma")!= addJsonHeader.end()) {; + istringstream(addJsonHeader.at("nSigma")) >> nSigma ; + mt->setNSigma(nSigma); + } - // /* interpolating detector commands */ - - // if (doc.HasMember("nSubPixels")) { - // if (doc["nSubPixels"].IsUint()) - // nSubPixels=doc["nSubPixels"].GetUint(); + emin=-1; + emax=-1; + if (addJsonHeader.find("energyRange")!= addJsonHeader.end()) { + istringstream(addJsonHeader.at("energyRange")) >> emin >> emax ; + } + if (addJsonHeader.find("eMin")!= addJsonHeader.end()) { + istringstream(addJsonHeader.at("eMin")) >> emin ; + } + + if (addJsonHeader.find("eMax")!= addJsonHeader.end()) { + istringstream(addJsonHeader.at("eMax")) >> emax ; + } + + mt->setEnergyRange(emin,emax); + + /* interpolating detector commands */ + //must set subpixels X and Y separately + // if (addJsonHeader.find("nSubPixels")!= addJsonHeader.end()) { + // istringstream(addJsonHeader.at("nSubPixels")) >> nSubPixels ; // mt->setNSubPixels(nSubPixels); // } - - // threshold=0; - // cprintf(MAGENTA, "Subframes: "); - // subframes=0; - // //isubframe=0; - // insubframe=0; - // subnorm=1; - // f0=0; - // nnsubframe=0; - // if (doc.HasMember("subframes")) { - // if (doc["subframes"].IsInt()) { - // subframes=doc["subframes"].GetInt(); - // } - // } - // cprintf(MAGENTA, "%ld\n", subframes); + + threshold=0; + cprintf(MAGENTA, "Subframes: "); + subframes=0; + //isubframe=0; + insubframe=0; + subnorm=1; + f0=0; + nnsubframe=0; + if (addJsonHeader.find("subframes")!= addJsonHeader.end()) { + istringstream(addJsonHeader.at("subframes")) >> subframes ; + } + + cprintf(MAGENTA, "%ld\n", subframes); newFrame=0; - /* zmqsocket->CloseHeaderMessage();*/ } #endif - // cout << "file" << endl; - // cout << "data " << endl; - if (of==NULL) { -#ifdef WRITE_QUAD - sprintf(ofname,"%s_%ld.clust2",filename.c_str(),fileindex); -#endif -#ifndef WRITE_QUAD - sprintf(ofname,"%s_%ld.clust",filename.c_str(),fileindex); -#endif - of=fopen(ofname,"w"); - if (of) { - mt->setFilePointer(of); - }else { - cout << "Could not open "<< ofname << " for writing " << endl; - mt->setFilePointer(NULL); - } - } - - - // cout << "data" << endl; - // get data - // acqIndex = doc["acqIndex"].GetUint64(); frameIndex = zHeader.frameIndex;////doc["fIndex"].GetUint64(); @@ -891,11 +804,45 @@ int main(int argc, char *argv[]) { memcpy(buff,&frameIndex,sizeof(int)); //length = zmqsocket->ReceiveData(0, buff+sizeof(int), size); + + + + + + if (fMode!=ePedestal || dMode!=eAnalog) { + if (of==NULL) { +#ifdef WRITE_QUAD + sprintf(ofname,"%s_%ld.clust2",filename.c_str(),fileindex); +#endif +#ifndef WRITE_QUAD + sprintf(ofname,"%s_%ld.clust",filename.c_str(),fileindex); +#endif + of=fopen(ofname,"w"); + if (of) { + mt->setFilePointer(of); + }else { + cout << "Could not open "<< ofname << " for writing " << endl; + mt->setFilePointer(NULL); + } + } + } + + + + + + + mt->pushData(buff); mt->nextThread(); mt->popFree(buff); insubframe++; nsubframes=frameIndex+1-f0; + // cout << "insubframe " << insubframe << endl; + // cout << "nsubframes " << nsubframes << endl; + // cout << "f0 " << f0 << endl; + // cout << "frameIndex " << frameIndex << endl; + } else { cprintf(RED, "Incomplete frame: received only %d packet\n", packetNumber); //length = @@ -905,9 +852,13 @@ int main(int argc, char *argv[]) { - if (subframes>0 && insubframe>=subframes && fMode==eFrame) { + if (subframes>0 && insubframe>=subframes && (fMode==eFrame ||fMode==eRaw) ) { while (mt->isBusy()) {;}//wait until all data are processed from the queues + usleep(100); + detimage=mt->getImage(nnx,nny,nnsx, nnsy); + + cprintf(MAGENTA,"Get image!\n"); dout= new int32_t[nnx*nny]; doutf= new float[nnx*nny]; @@ -932,9 +883,37 @@ int main(int argc, char *argv[]) { // zmqsocket2->SendHeaderData (0, false,SLS_DETECTOR_JSON_HEADER_VERSION , dr, fileindex, 1,1,nnx,nny,nnx*nny*dr/8,acqIndex, frameIndex, fname,acqIndex,0 , packetNumber,bunchId, timestamp, modId,xCoord, yCoord, zCoord,debug, roundRNumber, detType, version, 0,0, 0,&additionalJsonHeader); - zHeader.data = true; - zmqsocket2->SendHeader(0,zHeader); - zmqsocket2->SendData((char*)dout,nnx*nny*dr/8); + + + + // zmqsocket2->SendHeaderData (0, false,SLS_DETECTOR_JSON_HEADER_VERSION , dr, fileindex, 1,1,nnx,nny,nnx*nny*dr/8,acqIndex, frameIndex, fname,acqIndex,0 , packetNumber,bunchId, timestamp, modId,xCoord, yCoord, zCoord,debug, roundRNumber, detType, version, 0,0, 0,&additionalJsonHeader); + + outHeader.data=true; + outHeader.dynamicRange=dr; + outHeader.fileIndex=fileindex; + outHeader.ndetx=1; + outHeader.ndety=1; + outHeader.npixelsx=nnx; + outHeader.npixelsy=nny; + outHeader.imageSize=nnx*nny*dr/8; + outHeader.acqIndex=acqIndex; + outHeader.frameIndex=frameIndex; + outHeader.fname=fname; + outHeader.frameNumber=acqIndex; + outHeader.expLength=expLength; + outHeader.packetNumber=packetNumber; + outHeader.bunchId=bunchId; + outHeader.timestamp=timestamp; + outHeader.modId=modId; + outHeader.row=xCoord; + outHeader.column=yCoord; + outHeader.debug=debug; + outHeader.roundRNumber=roundRNumber; + outHeader.detType=detType; + outHeader.version=version; + + zmqsocket2->SendHeader(0,outHeader); + zmqsocket2->SendData((char*)dout,nnx*nny*dr/8); cprintf(GREEN, "Sent subdata\n"); @@ -950,18 +929,6 @@ int main(int argc, char *argv[]) { } - - - - - - - - - - - - iframe++; diff --git a/slsDetectorCalibration/multiThreadedAnalogDetector.h b/slsDetectorCalibration/multiThreadedAnalogDetector.h index d5a2ebdca..e1cc9d6bc 100644 --- a/slsDetectorCalibration/multiThreadedAnalogDetector.h +++ b/slsDetectorCalibration/multiThreadedAnalogDetector.h @@ -125,8 +125,20 @@ public: return fifoFree->pop(ptr); } - virtual int isBusy() {if (fifoData->isEmpty() && busy==0) return 0; return 1;} + // virtual int isBusy() {if (fifoData->isEmpty() && busy==0) return 0; return 1;} + virtual int isBusy() { + if (busy==0) { + usleep(100); + if (busy==0) { + if (fifoData->isEmpty()) { + usleep(100); + return 0; + } + } + } + return 1; + } //protected: /** Implement this method in your subclass with the code you want your thread to run. */ //virtual void InternalThreadEntry() = 0; @@ -254,10 +266,15 @@ protected: // busy=1; while (!stop) { if (fifoData->isEmpty()) { - busy=0; usleep(100); - } else { + if (fifoData->isEmpty()) { + busy=0; + } else + busy=1; + } else busy=1; + + if (busy==1) { fifoData->pop(data); //blocking! det->processData(data); fifoFree->push(data); @@ -298,7 +315,7 @@ public: cout << "Ithread is " << ithread << endl; } - ~multiThreadedAnalogDetector() { + virtual ~multiThreadedAnalogDetector() { StopThreads(); for (int i=0; isetNSigma(n); for (int i=1; isetNSigma(n); return ret;}; virtual void setEnergyRange(double emi, double ema) {for (int i=0; isetEnergyRange(emi,ema);}; diff --git a/slsDetectorCalibration/multiThreadedInterpolatingDetector.h b/slsDetectorCalibration/multiThreadedInterpolatingDetector.h index 1362cfdf2..344ac9e7f 100644 --- a/slsDetectorCalibration/multiThreadedInterpolatingDetector.h +++ b/slsDetectorCalibration/multiThreadedInterpolatingDetector.h @@ -17,7 +17,7 @@ class multiThreadedInterpolatingDetector : public multiThreadedCountingDetector { public: multiThreadedInterpolatingDetector(interpolatingDetector *d, int n, int fs=1000) : multiThreadedCountingDetector(d,n,fs) { }; - + //virtual ~multiThreadedInterpolatingDetector() {multiThreadedCountingDetector::~multiThreadedCountingDetector();}; virtual void prepareInterpolation(int &ok){ /* getFlatField(); //sum up all etas */ /* setFlatField(); //set etas to all detectors */ diff --git a/slsDetectorCalibration/singlePhotonDetector.h b/slsDetectorCalibration/singlePhotonDetector.h index 720f3517d..b63d8df85 100644 --- a/slsDetectorCalibration/singlePhotonDetector.h +++ b/slsDetectorCalibration/singlePhotonDetector.h @@ -189,14 +189,13 @@ public analogDetector { */ virtual int *getNPhotons(char *data, int *nph=NULL) { - + // cout << "spc frame" << endl; nphFrame=0; double val; if (nph==NULL) nph=image; //nph=new int[nx*ny]; - double rest[ny][nx]; //int cy=(clusterSizeY+1)/2; //quad size //int cs=(clusterSize+1)/2; //quad size @@ -226,6 +225,7 @@ public analogDetector { return nph; } else { if (thr>0) { + double *rest=new double[ny*nx]; newFrame(data); if (cmSub) { cout << "add to common mode?"<< endl; @@ -236,14 +236,14 @@ public analogDetector { if (det->isGood(ix,iy)) { val=subtractPedestal(data,ix,iy, cm); - nn=analogDetector::getNPhotons(data,ix,iy);//val/thr;// + nn=analogDetector::convertToPhotons(data,ix,iy);//val/thr;// if (nn>0) { nph[ix+nx*iy]+=nn; - rest[iy][ix]=(val-nn*thr);//?+0.5*thr + rest[iy*nx+ix]=(val-nn*thr);//?+0.5*thr nphFrame+=nn; nphTot+=nn; } else - rest[iy][ix]=val; + rest[iy*nx+ix]=val; } } @@ -262,7 +262,7 @@ public analogDetector { tot=0; quadTot=0; - if (rest[iy][ix]>0.25*thr) { + if (rest[iy*nx+ix]>0.25*thr) { eventMask[iy][ix]=NEIGHBOUR; for (int ir=-(clusterSizeY/2); ir<(clusterSizeY/2)+1; ir++) { for (int ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) { @@ -270,7 +270,7 @@ public analogDetector { //clusters->set_data(rest[iy+ir][ix+ic], ic, ir); - v=rest[iy+ir][ix+ic];//clusters->get_data(ic,ir); + v=rest[(iy+ir)*nx+ix+ic];//clusters->get_data(ic,ir); tot+=v; if (ir<=0 && ic<=0) @@ -290,7 +290,7 @@ public analogDetector { } } - if (rest[iy][ix]>=max) { + if (rest[iy*nx+ix]>=max) { if (bl>=br && bl>=tl && bl>=tr) { quad=BOTTOM_LEFT; quadTot=bl; @@ -327,7 +327,7 @@ public analogDetector { if (tot>tthr1 || quadTot>tthr2 || max>tthr) { eventMask[iy][ix]=PHOTON; nph[ix+nx*iy]++; - rest[iy][ix]-=thr; + rest[iy*nx+ix]-=thr; nphFrame++; nphTot++; @@ -338,6 +338,7 @@ public analogDetector { } } } + delete [] rest; } else return getClusters(data, nph); } return NULL; @@ -372,7 +373,6 @@ int *getClusters(char *data, int *ph=NULL) { //quadrant quad; double rms; //if (cmSub) cm=1; - double val[ny][nx]; if (ph==NULL) ph=image; @@ -389,6 +389,8 @@ int *getClusters(char *data, int *ph=NULL) { cm=1; } + double *val=new double[ny*nx]; + for (iy=ymin; iyisGood(ix,iy)==0) continue; @@ -416,8 +418,8 @@ int *getClusters(char *data, int *ph=NULL) { for (ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) { if ((iy+ir)>=iy && (iy+ir)=ix && (ix+ic)getValue(data,ix,iy)<< " " << val[iy][ix] << " " << getPedestal(ix,iy) << " " << rms << endl; */ - if (val[iy][ix]<-nSigma*rms){ + if (val[iy*nx+ix]<-nSigma*rms){ ee=NEGATIVE_PEDESTAL; continue; } if (max>nSigma*rms){ // cout << "ph1 " << max << " " << nSigma*rms << endl; ee=PHOTON; - if (val[iy][ix]c3*nSigma*rms) { @@ -478,7 +480,7 @@ int *getClusters(char *data, int *ph=NULL) { #ifndef WRITE_QUAD } #endif - if (ee==PHOTON && val[iy][ix]==max) { + if (ee==PHOTON && val[iy*nx+ix]==max) { ee=PHOTON_MAX; // cout << "**" <tot=tot; @@ -493,7 +495,7 @@ int *getClusters(char *data, int *ph=NULL) { for (ir=-(clusterSizeY/2); ir<(clusterSizeY/2)+1; ir++) { for (ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) { if ((iy+ir)>=0 && (iy+ir)=0 && (ix+ic)set_data(val[iy+ir][ix+ic],ic,ir); + (clusters+nph)->set_data(val[(iy+ir)*nx+ix+ic],ic,ir); } } good=1; @@ -519,6 +521,7 @@ int *getClusters(char *data, int *ph=NULL) { //cout << nphFrame << endl; //cout <getFrameNumber(data) << " " << nphFrame << endl; writeClusters(det->getFrameNumber(data)); + delete [] val; return image; }; @@ -652,7 +655,7 @@ int *getClusters(char *data, int *ph=NULL) { analogDetector::processData(data,val); break; default: - // cout <<"spc " << endl; + //cout <<"spc " << endl; getNPhotons(data,val); } } From 14d10d2f8fd0fc8544d24dcaa612ec5105822991 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Thu, 20 Jan 2022 17:21:37 +0100 Subject: [PATCH 2/3] fix for slow adcs and any other adcs that went to stop server, but needed control server for configuration of the adc --- slsDetectorSoftware/src/Module.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/slsDetectorSoftware/src/Module.cpp b/slsDetectorSoftware/src/Module.cpp index 1f357e5de..0b17f7f96 100644 --- a/slsDetectorSoftware/src/Module.cpp +++ b/slsDetectorSoftware/src/Module.cpp @@ -690,7 +690,22 @@ void Module::setImageTestMode(const int value) { } int Module::getADC(dacIndex index) const { - return sendToDetectorStop(F_GET_ADC, index); + switch (index) { + case TEMPERATURE_ADC: + case TEMPERATURE_FPGA: + case TEMPERATURE_FPGAEXT: + case TEMPERATURE_10GE: + case TEMPERATURE_DCDC: + case TEMPERATURE_SODL: + case TEMPERATURE_SODR: + case TEMPERATURE_FPGA2: + case TEMPERATURE_FPGA3: + // only the temperatures go to the control server + return sendToDetectorStop(F_GET_ADC, index); + + default: + return sendToDetector(F_GET_ADC, index); + } } int Module::getOnChipDAC(slsDetectorDefs::dacIndex index, int chipIndex) const { From 50c1056eb2abf5485c43fe149e5cba35eb263f97 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Thu, 20 Jan 2022 17:23:41 +0100 Subject: [PATCH 3/3] minor --- slsDetectorSoftware/src/Module.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/slsDetectorSoftware/src/Module.cpp b/slsDetectorSoftware/src/Module.cpp index 0b17f7f96..29c02de91 100644 --- a/slsDetectorSoftware/src/Module.cpp +++ b/slsDetectorSoftware/src/Module.cpp @@ -700,7 +700,8 @@ int Module::getADC(dacIndex index) const { case TEMPERATURE_SODR: case TEMPERATURE_FPGA2: case TEMPERATURE_FPGA3: - // only the temperatures go to the control server + // only the temperatures go to the control server, others need + // configuration of adc in control server return sendToDetectorStop(F_GET_ADC, index); default: