Merge branch 'developer' into eiger2udp

This commit is contained in:
maliakal_d 2022-01-20 18:02:19 +01:00
commit 193ab75ebe
13 changed files with 238 additions and 205 deletions

View File

@ -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 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 to define the detector mode
*/ */
enum detectorMode { eAnalog, ePhotonCounting, eInterpolating }; enum detectorMode { eAnalog, ePhotonCounting, eInterpolating };
#endif #endif
@ -1034,7 +1034,7 @@ template <class dataType> class analogDetector {
\returns converted number of photons. If no threshold is set, returns gain converted pedestal subtracted data. \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; int nph=0;
double v; double v;
if (ix>=0 && ix<nx && iy>=0 && iy<ny) { if (ix>=0 && ix<nx && iy>=0 && iy<ny) {
@ -1068,20 +1068,35 @@ template <class dataType> class analogDetector {
\param nph pointer where the photons should added. If NULL,the internal image is used \param nph pointer where the photons should added. If NULL,the internal image is used
\returns pointer to array containing the number of photons \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; //double val;
if (nph==NULL) if (nph==NULL)
nph=image; nph=image;
newFrame(data); newFrame(data);
/* cout << fMode << endl; */
/* switch(fMode) { */
/* case eRaw: */
/* cout << "raw" << endl; */
/* break; */
/* default: */
/* cout << "analog" << endl; */
/* } */
//calcGhost(data); //calcGhost(data);
addToCommonMode(data); addToCommonMode(data);
for (iy=ymin; iy<ymax; ++iy) { for (iy=ymin; iy<ymax; ++iy) {
for (ix=xmin; ix<xmax; ++ix) { for (ix=xmin; ix<xmax; ++ix) {
if (det->isGood(ix,iy)) switch(fMode) {
nph[iy*nx+ix]+=getNPhotons(data, ix, iy); case eRaw:
//cout << "raw" << endl;
nph[iy*nx+ix]=det->getChannel(data,ix,iy);
break;
default:
if (det->isGood(ix,iy))
nph[iy*nx+ix]+=convertToPhotons(data, ix, iy);
}
} }
} }
return nph; return nph;
@ -1164,7 +1179,7 @@ template <class dataType> class analogDetector {
for (ix=xmi; ix<xma; ++ix) for (ix=xmi; ix<xma; ++ix)
if (det->isGood(ix,iy)) { if (det->isGood(ix,iy)) {
if (ix>=0 && ix<nx && iy>=0 && iy<ny) if (ix>=0 && ix<nx && iy>=0 && iy<ny)
val+=getNPhotons(data, ix, iy); val+=convertToPhotons(data, ix, iy);
} }
return val; return val;
@ -1187,9 +1202,9 @@ template <class dataType> class analogDetector {
addToPedestal(data,1); addToPedestal(data,1);
break; break;
default: default:
// cout << "analog " << endl; //cout << "analog frame" << endl;
//subtractPedestal(data); //subtractPedestal(data);
getNPhotons(data); analogDetector<dataType>::getNPhotons(data);
} }
}; };

View File

@ -55,7 +55,7 @@ class moench03T1ZmqDataNew : public slsDetectorData<uint16_t> {
int iadc; int iadc;
int ix, iy; int ix, iy;
int npackets=40; //int npackets=40;
int i; int i;
int adc4(0); int adc4(0);

View File

@ -30,7 +30,7 @@ template <class dataType> class ghostSummation {
ghost=new double[nx*ny]; ghost=new double[nx*ny];
} }
~ghostSummation() {delete [] ghost;}; virtual ~ghostSummation() {delete [] ghost;};
virtual ghostSummation *Clone() { virtual ghostSummation *Clone() {
return new ghostSummation(this); return new ghostSummation(this);

View File

@ -302,7 +302,11 @@ float *gethhx()
double diff=0, d; double diff=0, d;
//double bsize=1./nSubPixels; //double bsize=1./nSubPixels;
int nbad=0; 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; double maxdiff=0, mindiff=avg*nSubPixelsX*nSubPixelsY;
int ipx, ipy; int ipx, ipy;
@ -362,6 +366,10 @@ float *gethhx()
// cout << "Bad pixels: " << 100.*(float)nbad/((float)(nSubPixels*nSubPixels)) << " %" << endl; // cout << "Bad pixels: " << 100.*(float)nbad/((float)(nSubPixels*nSubPixels)) << " %" << endl;
delete [] p_tot_x;
delete [] p_tot_y;
delete [] p_tot;
return sqrt(diff); return sqrt(diff);
} }

View File

@ -40,10 +40,10 @@ class etaInterpolationPosXY : public virtual etaInterpolationBase{
if (tot_eta<=0) {ok=0; return;}; if (tot_eta<=0) {ok=0; return;};
double hx[nbetaX]; //profile x double *hx=new double[nbetaX]; //profile x
double hy[nbetaY]; //profile y double *hy=new double[nbetaY]; //profile y
double hix[nbetaX]; //integral of projection x double *hix=new double[nbetaX]; //integral of projection x
double hiy[nbetaY]; //integral of projection y double *hiy=new double[nbetaY]; //integral of projection y
// int ii=0; // int ii=0;
double etax, etay; double etax, etay;
for (int ib=0; ib<nbetaX; ib++) { for (int ib=0; ib<nbetaX; ib++) {
@ -166,7 +166,12 @@ class etaInterpolationPosXY : public virtual etaInterpolationBase{
#ifdef SAVE_ALL #ifdef SAVE_ALL
debugSaveAll(); debugSaveAll();
#endif #endif
delete [] hx;
delete [] hy;
delete [] hix;
delete [] hiy;
return ; return ;
} }

View File

@ -37,7 +37,8 @@ class slsInterpolation
hint=new int[nSubPixelsX*nx*nSubPixelsY*ny]; hint=new int[nSubPixelsX*nx*nSubPixelsY*ny];
}; };
virtual ~slsInterpolation(){ delete [] hint;}
slsInterpolation(slsInterpolation *orig){ slsInterpolation(slsInterpolation *orig){
nPixelsX=orig->nPixelsX; nPixelsX=orig->nPixelsX;
nPixelsY=orig->nPixelsY; nPixelsY=orig->nPixelsY;

View File

@ -7,14 +7,15 @@ LDFLAG= -L/usr/lib64/ -lpthread -lm -lstdc++ -lzmq -pthread -lrt -ltiff -O3
#DESTDIR?=../bin #DESTDIR?=../bin
all: moenchZmqProcess moenchZmq04Process all: moenchZmqProcess
#moenchZmq04Process
#moenchZmqProcessCtbGui #moenchZmqProcessCtbGui
moenchZmqProcess: moenchZmqProcess.cpp clean moenchZmqProcess: moenchZmqProcess.cpp clean
g++ -o moenchZmqProcess moenchZmqProcess.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DNEWZMQ -DINTERP g++ -o moenchZmqProcess moenchZmqProcess.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DNEWZMQ -DINTERP
moenchZmq04Process: moenchZmqProcess.cpp clean #moenchZmq04Process: moenchZmqProcess.cpp clean#
g++ -o moench04ZmqProcess moenchZmqProcess.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DNEWZMQ -DINTERP -DMOENCH04 # g++ -o moench04ZmqProcess moenchZmqProcess.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DNEWZMQ -DINTERP -DMOENCH04
#moenchZmqProcessCtbGui: moenchZmqProcess.cpp clean #moenchZmqProcessCtbGui: moenchZmqProcess.cpp clean
# g++ -o moenchZmqProcessCtbGui moenchZmqProcess.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DNEWZMQ -DINTERP -DCTBGUI # g++ -o moenchZmqProcessCtbGui moenchZmqProcess.cpp $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DNEWZMQ -DINTERP -DCTBGUI

View File

@ -68,8 +68,9 @@ int main(int argc, char *argv[]) {
int etabins=1000, etabinsy=1000;//nsubpix*2*100; int etabins=1000, etabinsy=1000;//nsubpix*2*100;
double etamin=-1, etamax=2; double etamin=-1, etamax=2;
int nSubPixelsX=2; int nSubPixelsX=2;
// int emin, emax; int emin, emax;
int nSubPixelsY=2; int nSubPixelsY=2;
// help // help
if (argc < 3 ) { 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"); 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 multisize=size;
//int dataSize=size; //int dataSize=size;
char dummybuff[size]; char *dummybuff=new char[size];
moench03CommonMode *cm=NULL; moench03CommonMode *cm=NULL;
@ -355,7 +356,7 @@ int main(int argc, char *argv[]) {
// int resetFlat=0; // int resetFlat=0;
//int resetPed=0; //int resetPed=0;
// int nsubPixels=1; //int nsubPixels=1;
//int isPedestal=0; //int isPedestal=0;
//int isFlat=0; //int isFlat=0;
int newFrame=1; int newFrame=1;
@ -393,7 +394,7 @@ int main(int argc, char *argv[]) {
cout << "Measurement lasted " << (end-begin).count()*0.000001 << " ms" << endl; cout << "Measurement lasted " << (end-begin).count()*0.000001 << " ms" << endl;
while (mt->isBusy()) {;}//wait until all data are processed from the queues while (mt->isBusy()) {;}//wait until all data are processed from the queues
usleep(100);
if (of) { if (of) {
mt->setFilePointer(NULL); mt->setFilePointer(NULL);
fclose(of); fclose(of);
@ -626,40 +627,8 @@ int main(int argc, char *argv[]) {
//strcpy(fname,filename.c_str()); //strcpy(fname,filename.c_str());
fname=filename; 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; addJsonHeader=zHeader.addJsonHeader;
/* Analog detector commands */
//isPedestal=0;
//isFlat=0;
rms=0; rms=0;
fMode=eFrame; fMode=eFrame;
frameMode_s="frame"; frameMode_s="frame";
@ -682,6 +651,11 @@ int main(int argc, char *argv[]) {
fMode=ePedestal; fMode=ePedestal;
//isPedestal=1; //isPedestal=1;
rms=1; rms=1;
} else if (frameMode_s == "raw"){
//mt->newDataSet(); //resets pedestal
// cprintf(MAGENTA, "Resetting pedestal\n");
fMode=eRaw;
//isPedestal=1;
} }
#ifdef INTERP #ifdef INTERP
else if (frameMode_s == "flatfield") { else if (frameMode_s == "flatfield") {
@ -695,7 +669,6 @@ int main(int argc, char *argv[]) {
} }
//#endif //#endif
else { else {
fMode=eFrame;
//isPedestal=0; //isPedestal=0;
//isFlat=0; //isFlat=0;
fMode=eFrame; fMode=eFrame;
@ -710,14 +683,8 @@ int main(int argc, char *argv[]) {
cprintf(MAGENTA, "Threshold: "); cprintf(MAGENTA, "Threshold: ");
if (addJsonHeader.find("threshold")!= addJsonHeader.end()) { if (addJsonHeader.find("threshold")!= addJsonHeader.end()) {
istringstream(addJsonHeader.at("threshold")) >>threshold; 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); mt->setThreshold(threshold);
// }
// }
cprintf(MAGENTA, "%d\n", threshold); cprintf(MAGENTA, "%d\n", threshold);
xmin=0; xmin=0;
@ -728,24 +695,6 @@ int main(int argc, char *argv[]) {
if (addJsonHeader.find("roi")!= addJsonHeader.end()) { if (addJsonHeader.find("roi")!= addJsonHeader.end()) {
istringstream(addJsonHeader.at("roi")) >> xmin >> xmax >> ymin >> ymax ; 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); 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 ; istringstream(addJsonHeader.at("dynamicRange")) >> dr ;
dr=32; dr=32;
} }
// if (doc.HasMember("dynamicRange")) {
// dr=doc["dynamicRange"].GetUint();
// dr=32;
// }
dMode=eAnalog; dMode=eAnalog;
detectorMode_s="analog"; detectorMode_s="analog";
cprintf(MAGENTA, "Detector mode: "); cprintf(MAGENTA, "Detector mode: ");
if (addJsonHeader.find("detectorMode")!= addJsonHeader.end()) {; if (addJsonHeader.find("detectorMode")!= addJsonHeader.end()) {;
//if (doc.HasMember("detectorMode")) {
//if (doc["detectorMode"].IsString()) {
detectorMode_s=addJsonHeader.at("detectorMode");//=doc["detectorMode"].GetString(); detectorMode_s=addJsonHeader.at("detectorMode");//=doc["detectorMode"].GetString();
#ifdef INTERP #ifdef INTERP
if (detectorMode_s == "interpolating"){ if (detectorMode_s == "interpolating"){
@ -783,98 +725,69 @@ int main(int argc, char *argv[]) {
mt->setInterpolation(NULL); mt->setInterpolation(NULL);
#endif #endif
} }
// } // }
if (fMode==eRaw) {
detectorMode_s = "analog";
dMode=eAnalog;
}
} }
mt->setDetectorMode(dMode); mt->setDetectorMode(dMode);
cprintf(MAGENTA, "%s\n" , detectorMode_s.c_str()); cprintf(MAGENTA, "%s\n" , detectorMode_s.c_str());
// cout << "done " << endl; cout << "done " << endl;
// /* Single Photon Detector commands */ /* Single Photon Detector commands */
// nSigma=5; nSigma=5;
// if (doc.HasMember("nSigma")) {
// if (doc["nSigma"].IsInt())
// nSigma=doc["nSigma"].GetInt();
// mt->setNSigma(nSigma);
// }
// emin=-1; if (addJsonHeader.find("nSigma")!= addJsonHeader.end()) {;
// emax=-1; istringstream(addJsonHeader.at("nSigma")) >> nSigma ;
// if (doc.HasMember("energyRange")) { mt->setNSigma(nSigma);
// 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);
// /* interpolating detector commands */ emin=-1;
emax=-1;
// if (doc.HasMember("nSubPixels")) { if (addJsonHeader.find("energyRange")!= addJsonHeader.end()) {
// if (doc["nSubPixels"].IsUint()) istringstream(addJsonHeader.at("energyRange")) >> emin >> emax ;
// nSubPixels=doc["nSubPixels"].GetUint(); }
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); // mt->setNSubPixels(nSubPixels);
// } // }
// threshold=0; threshold=0;
// cprintf(MAGENTA, "Subframes: "); cprintf(MAGENTA, "Subframes: ");
// subframes=0; subframes=0;
// //isubframe=0; //isubframe=0;
// insubframe=0; insubframe=0;
// subnorm=1; subnorm=1;
// f0=0; f0=0;
// nnsubframe=0; nnsubframe=0;
// if (doc.HasMember("subframes")) { if (addJsonHeader.find("subframes")!= addJsonHeader.end()) {
// if (doc["subframes"].IsInt()) { istringstream(addJsonHeader.at("subframes")) >> subframes ;
// subframes=doc["subframes"].GetInt(); }
// }
// } cprintf(MAGENTA, "%ld\n", subframes);
// cprintf(MAGENTA, "%ld\n", subframes);
newFrame=0; newFrame=0;
/* zmqsocket->CloseHeaderMessage();*/
} }
#endif #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(); frameIndex = zHeader.frameIndex;////doc["fIndex"].GetUint64();
@ -891,11 +804,45 @@ int main(int argc, char *argv[]) {
memcpy(buff,&frameIndex,sizeof(int)); memcpy(buff,&frameIndex,sizeof(int));
//length = //length =
zmqsocket->ReceiveData(0, buff+sizeof(int), size); 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->pushData(buff);
mt->nextThread(); mt->nextThread();
mt->popFree(buff); mt->popFree(buff);
insubframe++; insubframe++;
nsubframes=frameIndex+1-f0; nsubframes=frameIndex+1-f0;
// cout << "insubframe " << insubframe << endl;
// cout << "nsubframes " << nsubframes << endl;
// cout << "f0 " << f0 << endl;
// cout << "frameIndex " << frameIndex << endl;
} else { } else {
cprintf(RED, "Incomplete frame: received only %d packet\n", packetNumber); cprintf(RED, "Incomplete frame: received only %d packet\n", packetNumber);
//length = //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 while (mt->isBusy()) {;}//wait until all data are processed from the queues
usleep(100);
detimage=mt->getImage(nnx,nny,nnsx, nnsy); detimage=mt->getImage(nnx,nny,nnsx, nnsy);
cprintf(MAGENTA,"Get image!\n"); cprintf(MAGENTA,"Get image!\n");
dout= new int32_t[nnx*nny]; dout= new int32_t[nnx*nny];
doutf= new float[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); // 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"); cprintf(GREEN, "Sent subdata\n");
@ -950,18 +929,6 @@ int main(int argc, char *argv[]) {
} }
iframe++; iframe++;

View File

@ -125,8 +125,20 @@ public:
return fifoFree->pop(ptr); 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: //protected:
/** Implement this method in your subclass with the code you want your thread to run. */ /** Implement this method in your subclass with the code you want your thread to run. */
//virtual void InternalThreadEntry() = 0; //virtual void InternalThreadEntry() = 0;
@ -254,10 +266,15 @@ protected:
// busy=1; // busy=1;
while (!stop) { while (!stop) {
if (fifoData->isEmpty()) { if (fifoData->isEmpty()) {
busy=0;
usleep(100); usleep(100);
} else { if (fifoData->isEmpty()) {
busy=0;
} else
busy=1;
} else
busy=1; busy=1;
if (busy==1) {
fifoData->pop(data); //blocking! fifoData->pop(data); //blocking!
det->processData(data); det->processData(data);
fifoFree->push(data); fifoFree->push(data);
@ -298,7 +315,7 @@ public:
cout << "Ithread is " << ithread << endl; cout << "Ithread is " << ithread << endl;
} }
~multiThreadedAnalogDetector() { virtual ~multiThreadedAnalogDetector() {
StopThreads(); StopThreads();
for (int i=0; i<nThreads; i++) for (int i=0; i<nThreads; i++)
delete dets[i]; delete dets[i];

View File

@ -26,7 +26,7 @@ class multiThreadedCountingDetector : public multiThreadedAnalogDetector
{ {
public: public:
multiThreadedCountingDetector(singlePhotonDetector *d, int n, int fs=1000) : multiThreadedAnalogDetector(d,n,fs) { }; multiThreadedCountingDetector(singlePhotonDetector *d, int n, int fs=1000) : multiThreadedAnalogDetector(d,n,fs) { };
//virtual ~multiThreadedCountingDetector{multiThreadedAnalogDetector::~multiThreadedAnalogDetector();};
virtual double setNSigma(double n) {double ret=(dets[0])->setNSigma(n); for (int i=1; i<nThreads; i++) (dets[i])->setNSigma(n); return ret;}; virtual double setNSigma(double n) {double ret=(dets[0])->setNSigma(n); for (int i=1; i<nThreads; i++) (dets[i])->setNSigma(n); return ret;};
virtual void setEnergyRange(double emi, double ema) {for (int i=0; i<nThreads; i++) (dets[i])->setEnergyRange(emi,ema);}; virtual void setEnergyRange(double emi, double ema) {for (int i=0; i<nThreads; i++) (dets[i])->setEnergyRange(emi,ema);};

View File

@ -17,7 +17,7 @@ class multiThreadedInterpolatingDetector : public multiThreadedCountingDetector
{ {
public: public:
multiThreadedInterpolatingDetector(interpolatingDetector *d, int n, int fs=1000) : multiThreadedCountingDetector(d,n,fs) { }; multiThreadedInterpolatingDetector(interpolatingDetector *d, int n, int fs=1000) : multiThreadedCountingDetector(d,n,fs) { };
//virtual ~multiThreadedInterpolatingDetector() {multiThreadedCountingDetector::~multiThreadedCountingDetector();};
virtual void prepareInterpolation(int &ok){ virtual void prepareInterpolation(int &ok){
/* getFlatField(); //sum up all etas */ /* getFlatField(); //sum up all etas */
/* setFlatField(); //set etas to all detectors */ /* setFlatField(); //set etas to all detectors */

View File

@ -189,14 +189,13 @@ public analogDetector<uint16_t> {
*/ */
virtual int *getNPhotons(char *data, int *nph=NULL) { virtual int *getNPhotons(char *data, int *nph=NULL) {
// cout << "spc frame" << endl;
nphFrame=0; nphFrame=0;
double val; double val;
if (nph==NULL) if (nph==NULL)
nph=image; nph=image;
//nph=new int[nx*ny]; //nph=new int[nx*ny];
double rest[ny][nx];
//int cy=(clusterSizeY+1)/2; //quad size //int cy=(clusterSizeY+1)/2; //quad size
//int cs=(clusterSize+1)/2; //quad size //int cs=(clusterSize+1)/2; //quad size
@ -226,6 +225,7 @@ public analogDetector<uint16_t> {
return nph; return nph;
} else { } else {
if (thr>0) { if (thr>0) {
double *rest=new double[ny*nx];
newFrame(data); newFrame(data);
if (cmSub) { if (cmSub) {
cout << "add to common mode?"<< endl; cout << "add to common mode?"<< endl;
@ -236,14 +236,14 @@ public analogDetector<uint16_t> {
if (det->isGood(ix,iy)) { if (det->isGood(ix,iy)) {
val=subtractPedestal(data,ix,iy, cm); val=subtractPedestal(data,ix,iy, cm);
nn=analogDetector<uint16_t>::getNPhotons(data,ix,iy);//val/thr;// nn=analogDetector<uint16_t>::convertToPhotons(data,ix,iy);//val/thr;//
if (nn>0) { if (nn>0) {
nph[ix+nx*iy]+=nn; 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; nphFrame+=nn;
nphTot+=nn; nphTot+=nn;
} else } else
rest[iy][ix]=val; rest[iy*nx+ix]=val;
} }
} }
@ -262,7 +262,7 @@ public analogDetector<uint16_t> {
tot=0; tot=0;
quadTot=0; quadTot=0;
if (rest[iy][ix]>0.25*thr) { if (rest[iy*nx+ix]>0.25*thr) {
eventMask[iy][ix]=NEIGHBOUR; eventMask[iy][ix]=NEIGHBOUR;
for (int ir=-(clusterSizeY/2); ir<(clusterSizeY/2)+1; ir++) { for (int ir=-(clusterSizeY/2); ir<(clusterSizeY/2)+1; ir++) {
for (int ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) { for (int ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) {
@ -270,7 +270,7 @@ public analogDetector<uint16_t> {
//clusters->set_data(rest[iy+ir][ix+ic], ic, ir); //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; tot+=v;
if (ir<=0 && ic<=0) if (ir<=0 && ic<=0)
@ -290,7 +290,7 @@ public analogDetector<uint16_t> {
} }
} }
if (rest[iy][ix]>=max) { if (rest[iy*nx+ix]>=max) {
if (bl>=br && bl>=tl && bl>=tr) { if (bl>=br && bl>=tl && bl>=tr) {
quad=BOTTOM_LEFT; quad=BOTTOM_LEFT;
quadTot=bl; quadTot=bl;
@ -327,7 +327,7 @@ public analogDetector<uint16_t> {
if (tot>tthr1 || quadTot>tthr2 || max>tthr) { if (tot>tthr1 || quadTot>tthr2 || max>tthr) {
eventMask[iy][ix]=PHOTON; eventMask[iy][ix]=PHOTON;
nph[ix+nx*iy]++; nph[ix+nx*iy]++;
rest[iy][ix]-=thr; rest[iy*nx+ix]-=thr;
nphFrame++; nphFrame++;
nphTot++; nphTot++;
@ -338,6 +338,7 @@ public analogDetector<uint16_t> {
} }
} }
} }
delete [] rest;
} else return getClusters(data, nph); } else return getClusters(data, nph);
} }
return NULL; return NULL;
@ -372,7 +373,6 @@ int *getClusters(char *data, int *ph=NULL) {
//quadrant quad; //quadrant quad;
double rms; double rms;
//if (cmSub) cm=1; //if (cmSub) cm=1;
double val[ny][nx];
if (ph==NULL) if (ph==NULL)
ph=image; ph=image;
@ -389,6 +389,8 @@ int *getClusters(char *data, int *ph=NULL) {
cm=1; cm=1;
} }
double *val=new double[ny*nx];
for (iy=ymin; iy<ymax; ++iy) { for (iy=ymin; iy<ymax; ++iy) {
for (ix=xmin; ix<xmax; ++ix) { for (ix=xmin; ix<xmax; ++ix) {
if (det->isGood(ix,iy)==0) continue; if (det->isGood(ix,iy)==0) continue;
@ -416,8 +418,8 @@ int *getClusters(char *data, int *ph=NULL) {
for (ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) { for (ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) {
if ((iy+ir)>=iy && (iy+ir)<ny && (ix+ic)>=ix && (ix+ic)<nx) { if ((iy+ir)>=iy && (iy+ir)<ny && (ix+ic)>=ix && (ix+ic)<nx) {
val[iy+ir][ix+ic]=subtractPedestal(data,ix+ic,iy+ir, cm); val[(iy+ir)*nx+ix+ic]=subtractPedestal(data,ix+ic,iy+ir, cm);
v=&(val[iy+ir][ix+ic]); v=&(val[(iy+ir)*nx+ix+ic]);
tot+=*v; tot+=*v;
if (ir<=0 && ic<=0) if (ir<=0 && ic<=0)
bl+=*v; bl+=*v;
@ -438,14 +440,14 @@ int *getClusters(char *data, int *ph=NULL) {
} }
/* if (ix==50 && iy==50) */ /* if (ix==50 && iy==50) */
/* cout << id << " " << ix << " " << iy << " " << det->getValue(data,ix,iy)<< " " << val[iy][ix] << " " << getPedestal(ix,iy) << " " << rms << endl; */ /* cout << id << " " << ix << " " << iy << " " << det->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; ee=NEGATIVE_PEDESTAL;
continue; continue;
} }
if (max>nSigma*rms){ if (max>nSigma*rms){
// cout << "ph1 " << max << " " << nSigma*rms << endl; // cout << "ph1 " << max << " " << nSigma*rms << endl;
ee=PHOTON; ee=PHOTON;
if (val[iy][ix]<max) if (val[iy*nx+ix]<max)
continue; continue;
} }
else if (tot>c3*nSigma*rms) { else if (tot>c3*nSigma*rms) {
@ -478,7 +480,7 @@ int *getClusters(char *data, int *ph=NULL) {
#ifndef WRITE_QUAD #ifndef WRITE_QUAD
} }
#endif #endif
if (ee==PHOTON && val[iy][ix]==max) { if (ee==PHOTON && val[iy*nx+ix]==max) {
ee=PHOTON_MAX; ee=PHOTON_MAX;
// cout << "**" <<id<< " " << iframe << " " << nDark << " " << ix << " " << iy << " " << rms << " " << max << " " << quadTot << " " << tot << endl; // cout << "**" <<id<< " " << iframe << " " << nDark << " " << ix << " " << iy << " " << rms << " " << max << " " << quadTot << " " << tot << endl;
(clusters+nph)->tot=tot; (clusters+nph)->tot=tot;
@ -493,7 +495,7 @@ int *getClusters(char *data, int *ph=NULL) {
for (ir=-(clusterSizeY/2); ir<(clusterSizeY/2)+1; ir++) { for (ir=-(clusterSizeY/2); ir<(clusterSizeY/2)+1; ir++) {
for (ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) { for (ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) {
if ((iy+ir)>=0 && (iy+ir)<ny && (ix+ic)>=0 && (ix+ic)<nx) if ((iy+ir)>=0 && (iy+ir)<ny && (ix+ic)>=0 && (ix+ic)<nx)
(clusters+nph)->set_data(val[iy+ir][ix+ic],ic,ir); (clusters+nph)->set_data(val[(iy+ir)*nx+ix+ic],ic,ir);
} }
} }
good=1; good=1;
@ -519,6 +521,7 @@ int *getClusters(char *data, int *ph=NULL) {
//cout << nphFrame << endl; //cout << nphFrame << endl;
//cout <<id << " **********************************"<< iframe << " " << det->getFrameNumber(data) << " " << nphFrame << endl; //cout <<id << " **********************************"<< iframe << " " << det->getFrameNumber(data) << " " << nphFrame << endl;
writeClusters(det->getFrameNumber(data)); writeClusters(det->getFrameNumber(data));
delete [] val;
return image; return image;
}; };
@ -652,7 +655,7 @@ int *getClusters(char *data, int *ph=NULL) {
analogDetector<uint16_t>::processData(data,val); analogDetector<uint16_t>::processData(data,val);
break; break;
default: default:
// cout <<"spc " << endl; //cout <<"spc " << endl;
getNPhotons(data,val); getNPhotons(data,val);
} }
} }

View File

@ -690,7 +690,23 @@ void Module::setImageTestMode(const int value) {
} }
int Module::getADC(dacIndex index) const { int Module::getADC(dacIndex index) const {
return sendToDetectorStop<int>(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, others need
// configuration of adc in control server
return sendToDetectorStop<int>(F_GET_ADC, index);
default:
return sendToDetector<int>(F_GET_ADC, index);
}
} }
int Module::getOnChipDAC(slsDetectorDefs::dacIndex index, int chipIndex) const { int Module::getOnChipDAC(slsDetectorDefs::dacIndex index, int chipIndex) const {