diff --git a/CMakeLists.txt b/CMakeLists.txt index bc37d79e6..e73075393 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -104,7 +104,6 @@ endif() if(SLS_USE_SANITIZER) # target_compile_options(slsProjectOptions INTERFACE -fsanitize=address,undefined -fno-omit-frame-pointer) - #target_compile_options(slsProjectOptions INTERFACE -fsanitize=address,undefined) # target_link_libraries(slsProjectOptions INTERFACE -fsanitize=address,undefined) target_compile_options(slsProjectOptions INTERFACE -fsanitize=thread) target_link_libraries(slsProjectOptions INTERFACE -fsanitize=thread) diff --git a/ctbGui/ctbAcquisition.cpp b/ctbGui/ctbAcquisition.cpp index 6a6c82086..1b385fe3e 100755 --- a/ctbGui/ctbAcquisition.cpp +++ b/ctbGui/ctbAcquisition.cpp @@ -773,9 +773,10 @@ void ctbAcquisition::setCanvas(TCanvas* c) { myCanvas->AddExec("dynamic",Form("((ctbAcquisition*)0x%x)->canvasClicked()",this)); // myCanvas->AddExec("ex","canvasClicked()"); } -int ctbAcquisition::dataCallback(detectorData *data, int index, int dum, void* pArgs) { +void ctbAcquisition::dataCallback(detectorData *data, long unsigned int index, unsigned int dum, void* pArgs) { - return ((ctbAcquisition*)pArgs)->plotData(data,index); + // return + ((ctbAcquisition*)pArgs)->plotData(data,index); } @@ -836,8 +837,8 @@ sample1 (dbit0 + dbit1 +...)if (cmd == "rx_dbitlist") { // cout <<"global plot is " << globalPlot << endl; - cout << "*******************************************" <progressIndex << " npoints:" << data->npoints << " npy: " << data->npy << " " << data->fileName << " bytes: " << data->databytes << " dr:"<< data->dynamicRange << " fi: " << data ->fileIndex << endl; + // cout << "*******************************************" <progressIndex << " npoints:" << data->npoints << " npy: " << data->npy << " " << data->fileName << " bytes: " << data->databytes << " dr:"<< data->dynamicRange << " fi: " << data ->fileIndex << endl; if (globalPlot || cbGetPedestal->IsOn()) { //#ifdef TESTADC // cout <<"------"<< index << " " << ip << " " << data->npoints << endl; @@ -904,7 +905,7 @@ sample1 (dbit0 + dbit1 +...)if (cmd == "rx_dbitlist") { i=0; - char *d_data= data->cvalues+2*nadc*nAnalogSamples; + char *d_data= data->data+2*nadc*nAnalogSamples; char dval; @@ -914,7 +915,7 @@ sample1 (dbit0 + dbit1 +...)if (cmd == "rx_dbitlist") { for (int x=0; xgetValue(data->cvalues,x,y); + aval=dataStructure->getValue(data->data,x,y); if (cbGetPedestal->IsOn()) { if (photonFinder) { @@ -934,7 +935,7 @@ sample1 (dbit0 + dbit1 +...)if (cmd == "rx_dbitlist") { if (h2DMapDig) - h2DMapDig->SetBinContent(x+1,y+1,dataStructure->getGain(data->cvalues,x,y)); + h2DMapDig->SetBinContent(x+1,y+1,dataStructure->getGain(data->data,x,y)); } @@ -1133,13 +1134,12 @@ void ctbAcquisition::changePlot(){ if (rb2D->IsOn()) { if (h2DMapDig) h2DMapDig->Draw("colz"); + else if (h1DMap) + h1DMap->Draw(); } else if (bitStack) bitStack->Draw("NOSTACK"); else cout << "bitStack is NULL" << endl; - - - } @@ -1685,7 +1685,7 @@ void* ctbAcquisition::ThreadHandle(void *arg) } - int ctbAcquisition::progressCallback(double f,void* arg) { + void ctbAcquisition::progressCallback(double f,void* arg) { // ctbAcquisition *acq = static_cast(arg); diff --git a/ctbGui/ctbAcquisition.h b/ctbGui/ctbAcquisition.h index 1f18dd2e5..12abd313e 100755 --- a/ctbGui/ctbAcquisition.h +++ b/ctbGui/ctbAcquisition.h @@ -191,8 +191,8 @@ class ctbAcquisition : public TGGroupFrame { void setGraph (int i ,int en, Pixel_t col); void setBitGraph (int i ,int en, Pixel_t col); void startAcquisition(); - static int progressCallback(double,void*); - static int dataCallback(detectorData*, int,int, void*); + static void progressCallback(double,void*); + static void dataCallback(detectorData*, long unsigned int, unsigned int, void*); int StopFlag; int plotData(detectorData*, int); diff --git a/ctbGui/ctbGui.cpp b/ctbGui/ctbGui.cpp index e5df8b6db..3cec6ea0d 100755 --- a/ctbGui/ctbGui.cpp +++ b/ctbGui/ctbGui.cpp @@ -64,7 +64,7 @@ int main(int argc, char **argv) { /****** Create detector ****************/ multiSlsDetector *myDet=new multiSlsDetector(id); - myDet->setOnline(slsDetectorDefs::ONLINE_FLAG); + // myDet->setOnline(slsDetectorDefs::ONLINE_FLAG); //cout << id << " " << myDet << " " << myDet->setOnline() << endl; if (cf) { diff --git a/ctbGui/ctbPattern.cpp b/ctbGui/ctbPattern.cpp index 4823f8570..e25974988 100755 --- a/ctbGui/ctbPattern.cpp +++ b/ctbGui/ctbPattern.cpp @@ -510,24 +510,24 @@ ctbPattern::ctbPattern(TGVerticalFrame *page, multiSlsDetector *det) e->Connect("ReturnPressed()","ctbPattern",this,"setCycles()"); - sprintf(tit, "Number of measurements: "); + // sprintf(tit, "Number of measurements: "); - label= new TGLabel(hframe, tit); - hframe->AddFrame(label,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 1, 1, 1, 1)); - label->MapWindow(); - label->SetTextJustify(kTextLeft); + // label= new TGLabel(hframe, tit); + // hframe->AddFrame(label,new TGLayoutHints(kLHintsTop | kLHintsLeft| kLHintsExpandX, 1, 1, 1, 1)); + // label->MapWindow(); + // label->SetTextJustify(kTextLeft); - eMeasurements = new TGNumberEntry(hframe, 0, 9,999, TGNumberFormat::kNESInteger, - TGNumberFormat::kNEANonNegative, - TGNumberFormat::kNELNoLimits); - hframe->AddFrame( eMeasurements,new TGLayoutHints(kLHintsTop | kLHintsExpandX, 1, 1, 1, 1)); - eMeasurements->MapWindow(); - eMeasurements->Resize(150,30); - e= eMeasurements->TGNumberEntry::GetNumberEntry(); - e->Connect("ReturnPressed()","ctbPattern",this,"setMeasurements()"); + // eMeasurements = new TGNumberEntry(hframe, 0, 9,999, TGNumberFormat::kNESInteger, + // TGNumberFormat::kNEANonNegative, + // TGNumberFormat::kNELNoLimits); + // hframe->AddFrame( eMeasurements,new TGLayoutHints(kLHintsTop | kLHintsExpandX, 1, 1, 1, 1)); + // eMeasurements->MapWindow(); + // eMeasurements->Resize(150,30); + // e= eMeasurements->TGNumberEntry::GetNumberEntry(); + // e->Connect("ReturnPressed()","ctbPattern",this,"setMeasurements()"); hframe=new TGHorizontalFrame(this, 800,800); @@ -910,14 +910,14 @@ try { eCycles->SetNumber(n); - try { - myDet->setTimer(slsDetectorDefs::MEASUREMENTS_NUMBER,-1); - } catch (...) { + // try { + // myDet->setTimer(slsDetectorDefs::MEASUREMENTS_NUMBER,-1); + // } catch (...) { - cout << "Do nothing for this error" << endl; - } + // cout << "Do nothing for this error" << endl; + // } - eMeasurements->SetNumber(n); + // eMeasurements->SetNumber(n); start=-1; stop=-1; @@ -1049,14 +1049,14 @@ void ctbPattern::setCycles() { } } -void ctbPattern::setMeasurements() { - try { - myDet->setTimer(slsDetectorDefs::MEASUREMENTS_NUMBER,eFrames->GetNumber()); - } catch (...) { +// void ctbPattern::setMeasurements() { +// try { +// myDet->setTimer(slsDetectorDefs::MEASUREMENTS_NUMBER,eFrames->GetNumber()); +// } catch (...) { - cout << "Do nothing for this error" << endl; - } -} +// cout << "Do nothing for this error" << endl; +// } +// } diff --git a/ctbGui/ctbPattern.h b/ctbGui/ctbPattern.h index fdfc0412b..b6fa45baa 100755 --- a/ctbGui/ctbPattern.h +++ b/ctbGui/ctbPattern.h @@ -100,7 +100,7 @@ private: TGNumberEntry *eFrames; TGNumberEntry *ePeriod; TGNumberEntry *eCycles; - TGNumberEntry *eMeasurements; + // TGNumberEntry *eMeasurements; TGNumberEntry *eAdcPipeline; TGNumberEntry *eDBitPipeline; @@ -139,7 +139,7 @@ public: void setDBitPipeline(); void setFrames(); void setCycles(); - void setMeasurements(); + // void setMeasurements(); void setPeriod(); diff --git a/manual/manual-client/Eiger_short.tex b/manual/manual-client/Eiger_short.tex index fe2457c3d..ddd858af2 100755 --- a/manual/manual-client/Eiger_short.tex +++ b/manual/manual-client/Eiger_short.tex @@ -326,7 +326,25 @@ The size of the gap pixels between modules to insert is GapPixelsBetweenModules_y = 36 \end{verbatim} where the {\tt{GapPixelsBetweenModules\_x}} are the one on the short side of the module, while {\tt{GapPixelsBetweenModules\_y}} are the ones on the long side of the module (where the wirebonds take physical space). - + \section{QUAD special geometry} +Starting from release 4.1.0, we support a special geometry with 2x2 pixels. This is for a Quad, where a single half module reads out 4 chips but in a quad shape. For now this hardware is only available as a PEEM detector at SIM. +The {\tt{detsizechan 1024 512}} needs to remain set like this for a half module. However, thanks to the command: + \begin{verbatim} +./sls_detector_put quad 1 +\end{verbatim} + +a 512x512 geomtry will be read out if {\tt{gappixels 0}} and 514x514 will be readout if {\tt{gappixels 1}}. Note that as above, {\tt{gappixels 1}} is not supported for {\tt{dr 4}}. +If {\tt{gappixels 0}}, in the master.raw file you will read: +\begin{verbatim} +row : 512 pixels +col : 256 pixels +\end{verbatim} +else if {\tt{gappixels 1}}, in the master.raw file you will read: +\begin{verbatim} +row : 514 pixels +col : 257 pixels +\end{verbatim} + \section{Readout timing- maximum frame rate}\label{timing} IMPORTANT: to have faster readout and smaller dead time, one can configure {\tt{clkdivider}}, i.e. the speed at which the data are read, i.e. 200/100/50~MHz for {\tt{clkdivider 0/1/2}} and the dead time between frames through {\tt{flags parallel}}, i.e. acquire and read at the same time or acquire and then read out. The configuration of this timing variables allows to achieve different frame rates. NOTE THAT IN EIGER, WHATEVER YOU DO, THE FRAME RATE LIMITATIONS COME FROM THE NETWORK BOTTLENECK AS THE HARDWARE GOES FASTER THAN THE DATA OUT. @@ -603,6 +621,9 @@ Here are the implemented options so far: \item {\tt{burst\_trigger}} gets only 1 trigger, but allows to take many frames. With {\tt{frames}} one can change the number of frames. {\tt{cycles}} needs to be 1. {\tt{exptime}} and {\tt{period}} have to be set. In the gui it is called trigger readout. \item{\tt{gating}} allows to get a frame only when the trigger pulse is gating. Note that in this case the exp time and period only depend on the gating signal. {\tt{cycles}} allows to select how many gates to consider. Set number of frames to 1 using {\tt{frames}}. IMPORTANT: Up to firmware 23, the last subframe is oblige to finish being taken, despite the gate signal going down. This will be configurable from later fw and software version. Also, in gating mode, due to timimg of the state machine, you need to leave 500~$\mu$s deadtime between the end on an acquisition and the next. This is as the state machine is unable to check for changes in the status in the first 500~$\mu$s. ATTENTION: if you are in 16 bit mode and you are applying online rate corrections, as now the exptime is generated by the trigger, you might not have correct rate corrections. If you know what the exposure time is in the gating signal, then you can set the {\tt{exptime}} once and the rate corrections will be correct. In 32 bit mode, it does not matter as the rate corrections depends on the {\tt{subexptime}} which is software set independently from the gate exptime. +When using 32-bit mode, by default the acquisition ends the last complete subframe that was started when still the acquisition time was valid. This has been chosen as many people wants to know the exact acquisition time for when the detector was taking data and also, if {\tt{ratecorr}} are active, the last subframe will be correctly corrected, while otherwise it will be corrected with a wrong subdeadtime. +However, from 4.1.0, in gating mode, an option to immediately terminate the subframe when the gate signal goes down it is implemented to stop the acquisition at the same time. This option is {\tt{./sls\_detector\_put interruptsubframe 1}} while the default option is {\tt{./sls\_detector\_put interruptsubframe 0}}. + \end{itemize} Hardware-wise, the ENABLE OUT signal outputs when the chips are really acquiring. This means that the single subframes will be output in 32 bit mode. The TRIGGER OUT outputs the sum-up-signal at the moment (which is useless). This will be changed in the future to output the envelop of the enable signal. diff --git a/slsDetectorCalibration/analogDetector.h b/slsDetectorCalibration/analogDetector.h index 49197f0a6..b10446d34 100644 --- a/slsDetectorCalibration/analogDetector.h +++ b/slsDetectorCalibration/analogDetector.h @@ -6,7 +6,8 @@ #include #include "slsDetectorData.h" #include "pedestalSubtraction.h" -#include "commonModeSubtraction.h" +#include "commonModeSubtractionNew.h" +#include "ghostSummation.h" #include "tiffIO.h" #include "slsInterpolation.h" @@ -61,7 +62,7 @@ template class analogDetector { analogDetector(slsDetectorData *d, int sign=1, - commonModeSubtraction *cm=NULL, int nped=1000, int nnx=-1, int nny=-1, double *gm=NULL) : det(d), nx(nnx), ny(nny), stat(NULL), cmSub(cm), iframe(-1), dataSign(sign), gmap(gm), id(0) { + commonModeSubtraction *cm=NULL, int nped=1000, int nnx=-1, int nny=-1, double *gm=NULL, ghostSummation *gs=NULL) : det(d), nx(nnx), ny(nny), stat(NULL), cmSub(cm), iframe(-1), dataSign(sign), gmap(gm), ghSum(gs), id(0) { if (det) det->getDetectorSize(nx,ny); @@ -118,7 +119,7 @@ template class analogDetector { dataSign=orig->dataSign; iframe=orig->iframe; gmap=orig->gmap; - cmSub=orig->cmSub; + // cmSub=orig->cmSub; id=orig->id; xmin=orig->xmin; xmax=orig->xmax; @@ -153,7 +154,9 @@ template class analogDetector { hs9=(TH2F*)(orig->hs9)->Clone();//new TH2F("hs","hs",(orig->hs)-getNbins,-500,9500,nx*ny,-0.5,nx*ny-0.5); #endif #endif - + if (orig->cmSub) cmSub=(orig->cmSub)->Clone(); + if (orig->ghSum) ghSum=(orig->ghSum)->Clone(); + else ghSum=NULL; } @@ -275,6 +278,9 @@ template class analogDetector { /** resets the commonModeSubtraction and increases the frame index */ virtual void newFrame(){iframe++; if (cmSub) cmSub->newFrame();}; + + /** resets the commonModeSubtraction and increases the frame index */ + virtual void newFrame(char *data){iframe++; if (cmSub) cmSub->newFrame(); calcGhost(data);}; /** sets the commonModeSubtraction algorithm to be used @@ -289,6 +295,11 @@ template class analogDetector { commonModeSubtraction *getCommonModeSubtraction() {return cmSub;}; + ghostSummation *getGhostSummation(){return ghSum;}; + ghostSummation *setGhostSummation(ghostSummation *gs){ghSum=gs; return ghSum;}; + + + /** sets the sign of the data \param sign 1 means positive values for photons, -1 negative, 0 gets @@ -306,9 +317,15 @@ template class analogDetector { */ virtual void addToPedestal(double val, int ix, int iy=0, int cm=0){ if (ix>=0 && ix=0 && iy0) { val-= getCommonMode(ix, iy); } + // cout << val << " " ; + val+=getGhost(ix,iy); + // cout << val ; + // cout << endl; stat[iy][ix].addToPedestal(val); /* if (cmSub && cm>0) { */ /* if (det) if (det->isGood(ix, iy)==0) return; */ @@ -324,23 +341,29 @@ template class analogDetector { virtual void addToCommonMode(char *data){ + // cout << "+"<< endl; if (cmSub) { + // cout << "*" << endl; for (int iy=ymin; iy0) - if (det->isGood(ix,iy)) + // if (det->isGood(ix,iy)) { addToCommonMode(data, ix, iy); - } + // cout << ":"; + // } } + } //cout << "cm " << getCommonMode(0,0) << " " << getCommonMode(1,0) << endl; } } + virtual void addToCommonMode(char *data, int ix, int iy=0){ if (cmSub) { if (det) if (det->isGood(ix, iy)==0) return; if (getNumpedestals(ix,iy)>0){ cmSub->addToCommonMode(subtractPedestal(data,ix,iy,0), ix, iy); - // cout << ix << " " < class analogDetector { \param cm 0 (default) without common mode subtraction, 1 with common mode subtraction (if defined) \returns pedestal value */ - virtual double getPedestal(int ix, int iy, int cm=0){ + virtual double getPedestal (int ix, int iy, int cm=0){ if (ix>=0 && ix=0 && iy0) return stat[iy][ix].getPedestal()+getCommonMode(ix,iy); @@ -482,7 +505,10 @@ template class analogDetector { } + virtual void calcGhost(char *data, int ix, int iy=1) {if (ghSum) ghSum->calcGhost(data, ix, iy);}; + virtual void calcGhost(char *data){if (ghSum) ghSum->calcGhost(data);}; + virtual double getGhost(int ix, int iy) {if (ghSum) return ghSum->getGhost(ix, iy); return 0;}; /** write 32bit tiff file with detector image data @@ -691,9 +717,12 @@ template class analogDetector { virtual void addToPedestal(char *data, int cm=0) { // cout << "add to pedestal " << endl; - newFrame(); + newFrame(data); - if (cmSub) { + //calcGhost(data); + + + if (cmSub && cm) { addToCommonMode(data); } @@ -702,7 +731,8 @@ template class analogDetector { for (int iy=ymin; iyisGood(ix,iy)) { - addToPedestal(data,ix,iy,1); + // addToPedestal(data,ix,iy,1); + addToPedestal(data,ix,iy,cm); //if (ix==10 && iy==10) // cout < class analogDetector { val=dataSign*det->getValue(data, ix, iy); else val=((double*)data)[iy*nx+ix]; - + // cout << val << endl; /* if (ix==10 && iy==10) */ /* cout << ix << " " << iy << " " << val ; */ /* if (ix==100 && iy==100) */ /* cout << ix << " " << iy << " " << val; */ addToPedestal(val,ix,iy); + // cout << val << endl; /* if (ix==10 && iy==10) */ /* cout <<" " << getPedestal(ix,iy)<< endl; */ /* if (ix==100 && iy==100) */ @@ -818,15 +849,17 @@ template class analogDetector { virtual int *subtractPedestal(char *data, int *val=NULL, int cm=0) { - newFrame(); + newFrame(data); if (val==NULL) val=image;//new double[nx*ny]; - for (int iy=ymin; iyisGood(ix,iy)) - val[iy*nx+ix]+=subtractPedestal(data, ix, iy,cm); + //calcGhost(data); + + for (int iy=ymin; iyisGood(ix,iy)) + val[iy*nx+ix]+=subtractPedestal(data, ix, iy,cm); } } return val; @@ -861,6 +894,8 @@ template class analogDetector { } else val= (((double*)data)[iy*nx+ix]-getPedestal(ix,iy))/g; + val+=getGhost(ix,iy)/g; + #ifdef ROOTSPECTRUM hs->Fill(val,(iy-ymin)*(xmax-xmin)+(ix-xmin)); #ifdef ROOTCLUST @@ -949,10 +984,10 @@ template class analogDetector { double val; if (nph==NULL) nph=image; - newFrame(); + newFrame(data); + //calcGhost(data); addToCommonMode(data); - for (int iy=ymin; iyisGood(ix,iy)) @@ -1032,13 +1067,16 @@ template class analogDetector { if (ymi<0) ymi=ymin; if (yma<0) yma=ymax; - for (int iy=ymi; iyisGood(ix,iy)) { if (ix>=0 && ix=0 && iy *ghSum;/**< ghostSummation class */ int *image; int id; //int xmin, xmax, ymin, ymax; int xmin; /**< minimum x of the region of interest */ diff --git a/slsDetectorCalibration/commonModeSubtractionNew.h b/slsDetectorCalibration/commonModeSubtractionNew.h index 255500644..5e32fd960 100644 --- a/slsDetectorCalibration/commonModeSubtractionNew.h +++ b/slsDetectorCalibration/commonModeSubtractionNew.h @@ -23,6 +23,13 @@ class commonModeSubtraction { /** destructor - deletes the moving average(s) and the sum of pedestals calculator(s) */ virtual ~commonModeSubtraction() {delete [] mean; delete [] mean2; delete [] nCm;}; + /* commonModeSubtraction(commonModeSubtraction *cs) { */ + /* if (cs) new commonModeSubtraction(cs->getNRoi(), cs->nsigma); */ + /* } */ + + virtual commonModeSubtraction *Clone() { + new commonModeSubtraction(this->nROI, this->nsigma); + } /** clears the moving average and the sum of pedestals calculation - virtual func*/ virtual void Clear(){ @@ -52,7 +59,9 @@ class commonModeSubtraction { // if (iroi==0) val=100; // else val=-100; // if (isc>=0 && isc=0 && iroi=0 && iroi0) + if (nCm[iroi]>0) return mean[iroi]/nCm[iroi]; } return 0; @@ -96,8 +105,7 @@ class commonModeSubtraction { gets the common mode ROI for pixel ix, iy -should be overloaded! */ virtual int getROI(int ix, int iy){ (void) ix; (void) iy; return 0;}; - - + int getNRoi(){return nROI;}; protected: double *mean; /** { } wp=(int64_t*)ptr; - for (iw=0; iw { int sc_height; const int nSamples; + double ghost[200][25]; public: @@ -64,7 +65,7 @@ class moench03T1ReceiverDataNew : public slsDetectorData { \param c crosstalk parameter for the output buffer */ - moench03T1ReceiverDataNew(int ns=5000): slsDetectorData(400, 400, ns*2*32+sizeof(sls_detector_header)), nSamples(ns) { + moench03T1ReceiverDataNew(int ns=5000): slsDetectorData(400, 400, ns*2*32+sizeof(sls_detector_header)), nSamples(ns) { int nadc=32; int sc_width=25; @@ -106,6 +107,11 @@ class moench03T1ReceiverDataNew : public slsDetectorData { } } } + // double ghost[200][25]; + + for (int ix=0; ix<25; ix++) + for (int iy=0; iy<200; iy++) + ghost[iy][ix]=0.; int ipacket; int ibyte; @@ -142,6 +148,73 @@ class moench03T1ReceiverDataNew : public slsDetectorData { }; + + /** + Returns the value of the selected channel for the given dataset as double. + \param data pointer to the dataset (including headers etc) + \param ix pixel number in the x direction + \param iy pixel number in the y direction + \returns data for the selected channel, with inversion if required as double + + */ + virtual double getValue(char *data, int ix, int iy=0) { + /* cout << " x "<< ix << " y"<< iy << " val " << getChannel(data, ix, iy)<< endl;*/ + /* double val=0, vout=getChannel(data, ix, iy); */ + /* int x1=ix%25; */ + /* for (int ix=0; ix<16; ix++) { */ + /* for (int ii=0; ii<2; ii++) { */ + /* val+=getChannel(data,x1+25*ix,iy); */ + /* val+=getChannel(data,x1+25*ix,399-iy); */ + /* } */ + /* } */ + /* vout+=0.0008*val-6224; */ + /* return vout; //(double)getChannel(data, ix, iy); + */ + uint16_t val=getChannel(data, ix, iy)&0x3fff; + return val; + }; + + + + virtual void calcGhost(char *data, int ix, int iy) { + double val=0; + /* for (int ix=0; ix<25; ix++){ */ + /* for (int iy=0; iy<200; iy++) { */ + val=0; + // cout << "** "; + for (int isc=0; isc<16; isc++) { + // for (int ii=0; ii<2; ii++) { + val+=getChannel(data,ix+25*isc,iy); + // cout << "(" << isc << "," << val << " " ; + val+=getChannel(data,ix+25*isc,399-iy); + // cout << val << " " ; + // } + } + ghost[iy][ix]=val;//-6224; + // cout << " --"<< endl; + /* } */ + /* } */ + // cout << "*" << endl; + + } + + + + virtual void calcGhost(char *data) { + for (int ix=0; ix<25; ix++){ + for (int iy=0; iy<200; iy++) { + calcGhost(data, ix,iy); + } + } + // cout << "*" << endl; + } + + + double getGhost(int ix, int iy) { + if (iy<200) return ghost[iy][ix%25]; + if (iy<400) return ghost[399-iy][ix%25]; + return 0; + }; /** @@ -278,8 +351,6 @@ class moench03T1ReceiverDataNew : public slsDetectorData { } - - //int getPacketNumber(int x, int y) {return dataMap[y][x]/packetSize;}; }; diff --git a/slsDetectorCalibration/dataStructures/moench03T1ZmqDataNew.h b/slsDetectorCalibration/dataStructures/moench03T1ZmqDataNew.h index 1622e2792..479170ea1 100644 --- a/slsDetectorCalibration/dataStructures/moench03T1ZmqDataNew.h +++ b/slsDetectorCalibration/dataStructures/moench03T1ZmqDataNew.h @@ -14,6 +14,9 @@ class moench03T1ZmqDataNew : public slsDetectorData { const int nSamples; const int offset; + double ghost[200][25]; + double xtalk; + public: @@ -25,7 +28,7 @@ class moench03T1ZmqDataNew : public slsDetectorData { \param c crosstalk parameter for the output buffer */ - moench03T1ZmqDataNew(int ns=5000): slsDetectorData(400, 400, ns*32*2+sizeof(int)), nSamples(ns), offset(sizeof(int)) { + moench03T1ZmqDataNew(int ns=5000): slsDetectorData(400, 400, ns*32*2+sizeof(int)), nSamples(ns), offset(sizeof(int)), xtalk(0.00021) { int nadc=32; int sc_width=25; @@ -100,12 +103,84 @@ class moench03T1ZmqDataNew : public slsDetectorData { + for (int ix=0; ix<25; ix++) + for (int iy=0; iy<200; iy++) + ghost[iy][ix]=0.; + // iframe=0; // cout << "data struct created" << endl; }; + double getXTalk(){return xtalk;}; + void setXTalk(double g) {xtalk=g;}; + + /** + Returns the value of the selected channel for the given dataset as double. + \param data pointer to the dataset (including headers etc) + \param ix pixel number in the x direction + \param iy pixel number in the y direction + \returns data for the selected channel, with inversion if required as double + + */ + virtual double getValue(char *data, int ix, int iy=0) { + /* cout << " x "<< ix << " y"<< iy << " val " << getChannel(data, ix, iy)<< endl;*/ + /* double val=0, vout=getChannel(data, ix, iy); */ + /* int x1=ix%25; */ + /* for (int ix=0; ix<16; ix++) { */ + /* for (int ii=0; ii<2; ii++) { */ + /* val+=getChannel(data,x1+25*ix,iy); */ + /* val+=getChannel(data,x1+25*ix,399-iy); */ + /* } */ + /* } */ + /* vout+=0.0008*val-6224; */ + /* return vout; //(double)getChannel(data, ix, iy); + */ + return ((double)getChannel(data, ix, iy))+xtalk*getGhost(iy,iy); + }; + + + + virtual void calcGhost(char *data, int ix, int iy) { + double val=0; + /* for (int ix=0; ix<25; ix++){ */ + /* for (int iy=0; iy<200; iy++) { */ + val=0; + for (int isc=0; isc<16; isc++) { + for (int ii=0; ii<2; ii++) { + val+=getChannel(data,ix+25*isc,iy); + // cout << val << " " ; + val+=getChannel(data,ix+25*isc,399-iy); + // cout << val << " " ; + } + } + ghost[iy][ix]=val;//-6224; + // cout << endl; + /* } */ + /* } */ + // cout << "*" << endl; + + } + + + + virtual void calcGhost(char *data) { + for (int ix=0; ix<25; ix++){ + for (int iy=0; iy<200; iy++) { + calcGhost(data, ix,iy); + } + } + // cout << "*" << endl; + } + + + double getGhost(int ix, int iy) { + if (iy<200) return ghost[iy][ix%25]; + if (iy<400) return ghost[399-iy][ix%25]; + return 0; + }; + /** diff --git a/slsDetectorCalibration/ghostSummation.h b/slsDetectorCalibration/ghostSummation.h new file mode 100644 index 000000000..02bb0a359 --- /dev/null +++ b/slsDetectorCalibration/ghostSummation.h @@ -0,0 +1,61 @@ +#ifndef GHOSTSUMMATION_H +#define GHOSTSUMMATION_H + +#include +#include "slsDetectorData.h" + +template class ghostSummation { + + /** @short virtual calss to handle ghosting*/ + + public: + + /** constructor + \param xt crosstalk + */ + ghostSummation(slsDetectorData *d, double xt) : xtalk(xt),det(d) { + if (det) + det->getDetectorSize(nx,ny); + ghost=new double[nx*ny]; + }; + + ghostSummation(ghostSummation *orig) { + xtalk=orig->xtalk; + det=orig->det; + ghost=new double[nx*ny]; + + } + ~ghostSummation() {delete [] ghost;}; + + virtual ghostSummation *Clone() { + new ghostSummation(this); + } + + double getXTalk(){return xtalk;}; + void setXTalk(double g) {xtalk=g;}; + + virtual double calcGhost(char *data, int ix, int iy=1){ghost[iy*nx+ix]=0;}; + + virtual void calcGhost(char *data){ + for (int iy=0; iy=nx || iy<0 || iy>=ny) return 0; + return ghost[iy*nx+ix]; + } + + protected: + double xtalk; + slsDetectorData *det; + double *ghost; + int nx, ny; + +}; + + + + + +#endif diff --git a/slsDetectorCalibration/interpolatingDetector.h b/slsDetectorCalibration/interpolatingDetector.h index f5ce437bd..dc9002caa 100644 --- a/slsDetectorCalibration/interpolatingDetector.h +++ b/slsDetectorCalibration/interpolatingDetector.h @@ -46,8 +46,8 @@ class interpolatingDetector : public singlePhotonDetector { int sign=1, commonModeSubtraction *cm=NULL, int nped=1000, - int nd=100, int nnx=-1, int nny=-1) : - singlePhotonDetector(d, 3,nsigma,sign, cm, nped, nd, nnx, nny) , interp(inte), id(0) { + int nd=100, int nnx=-1, int nny=-1, double *gm=NULL, ghostSummation *gs=NULL) : + singlePhotonDetector(d, 3,nsigma,sign, cm, nped, nd, nnx, nny, gm, gs) , interp(inte), id(0) { //cout << "**"<< xmin << " " << xmax << " " << ymin << " " << ymax << endl; fi=new pthread_mutex_t ; diff --git a/slsDetectorCalibration/moench03CommonMode.h b/slsDetectorCalibration/moench03CommonMode.h index 7c950a9e4..f4e3b1f43 100644 --- a/slsDetectorCalibration/moench03CommonMode.h +++ b/slsDetectorCalibration/moench03CommonMode.h @@ -1,43 +1,52 @@ #ifndef MOENCH03COMMONMODE_H #define MOENCH03COMMONMODE_H -#include "commonModeSubtraction.h" +#include "commonModeSubtractionNew.h" -class moench03CommonMode : public commonModeSubtraction { +class commonModeSubtractionColumn: public commonModeSubtraction{ +public: + commonModeSubtractionColumn(int nr=200) : commonModeSubtraction(800), rows(nr) {}; + virtual int getROI(int ix, int iy){return ix+(iy/200)*400;}; + + virtual void addToCommonMode(double val, int ix=0, int iy=0) { + if (ix399-rows) { + int iroi=getROI(ix,iy); + if (iroi>=0 && iroi=0 && isc=0 && isc0) return cmPed[isc]/nCm[isc]-cmStat[isc].Mean(); - } - return 0; - }; }; diff --git a/slsDetectorCalibration/moench03GhostSummation.h b/slsDetectorCalibration/moench03GhostSummation.h new file mode 100644 index 000000000..88377dbe8 --- /dev/null +++ b/slsDetectorCalibration/moench03GhostSummation.h @@ -0,0 +1,57 @@ +#ifndef MOENCH03GHOSTSUMMATION_H +#define MOENCH03GHOSTSUMMATION_H + +#include "ghostSummation.h" + +class moench03GhostSummation : public ghostSummation { + + /** @short virtual calss to handle ghosting*/ + + public: + + /** constructor + \param xt crosstalk + */ + moench03GhostSummation(slsDetectorData *d, double xt=0.0004) : ghostSummation(d, xt) {} + + virtual void calcGhost(char *data){ + for (int iy=0; iy<200; iy++){ + for (int ix=0; ix<25; ix++){ + calcGhost(data,ix,iy); + } + } + }; + + + virtual double calcGhost(char *data, int x, int y=0){ + int ix=x%25; + int iy=y; + if (y>=200) iy=399-y; + if (iy<0 || ix<0) return 0; + double val=0; + val=0; + for (int isc=0; isc<16; isc++) { + val+=det->getChannel(data,ix+25*isc,iy); + // cout << val << " " ; + val+=det->getChannel(data,ix+25*isc,399-iy); + // cout << val << " " ; + } + ghost[iy*nx+ix]=xtalk*val; + return ghost[iy*nx+ix]; + }; + + + virtual double getGhost(int ix, int iy) { + if (iy >=0 && iy<200) return ghost[iy*nx+(ix%25)]; + if (iy<400) return ghost[(399-iy)*nx+(ix%25)]; + return 0; + }; + + +}; + + + + + +#endif diff --git a/slsDetectorCalibration/moenchExecutables/moenchPhotonCounter.cpp b/slsDetectorCalibration/moenchExecutables/moenchPhotonCounter.cpp index 6ce266150..b371f8be3 100644 --- a/slsDetectorCalibration/moenchExecutables/moenchPhotonCounter.cpp +++ b/slsDetectorCalibration/moenchExecutables/moenchPhotonCounter.cpp @@ -1,6 +1,6 @@ //#include "ansi.h" #include - +#define CORR //#define VERSION_V1 @@ -28,8 +28,11 @@ //#include "etaInterpolationPosXY.h" // #include "linearInterpolation.h" // #include "noInterpolation.h" -#include "multiThreadedAnalogDetector.h" +#include "multiThreadedCountingDetector.h" +//#include "multiThreadedAnalogDetector.h" #include "singlePhotonDetector.h" +#include "moench03GhostSummation.h" +#include "moench03CommonMode.h" //#include "interpolatingDetector.h" #include @@ -89,7 +92,18 @@ int main(int argc, char *argv[]) { decoder->getDetectorSize(nx,ny); - singlePhotonDetector *filter=new singlePhotonDetector(decoder,csize, nsigma, 1, 0, nped, 200); + int ncol_cm=20; + double xt_ghost=0.0004; + moench03CommonMode *cm=NULL; + moench03GhostSummation *gs; + double *gainmap=NULL; +#ifdef CORR + cout << "Applying common mode and ghost correction " << endl; + cm=new moench03CommonMode(ncol_cm); + gs=new moench03GhostSummation(decoder, xt_ghost); +#endif + + singlePhotonDetector *filter=new singlePhotonDetector(decoder,csize, nsigma, 1, cm, nped, 200, -1, -1, gainmap, gs); int size = 327680;////atoi(argv[3]); @@ -171,9 +185,10 @@ int main(int argc, char *argv[]) { if (thr>0) { cout << "threshold is " << thr << endl; - //#ifndef ANALOG +#ifndef ANALOG filter->setThreshold(thr); - //#endif +#endif + cf=0; } else cf=1; @@ -181,17 +196,13 @@ int main(int argc, char *argv[]) { filter->setROI(xmin,xmax,ymin,ymax); -#ifdef SOLEIL - filter->setROI(150,210,170,230); - nframes=-1; -#endif std::time(&end_time); cout << std::ctime(&end_time) << endl; char* buff; - multiThreadedAnalogDetector *mt=new multiThreadedAnalogDetector(filter,nthreads,fifosize); - + // multiThreadedAnalogDetector *mt=new multiThreadedAnalogDetector(filter,nthreads,fifosize); + multiThreadedCountingDetector *mt=new multiThreadedCountingDetector(filter,nthreads,fifosize); #ifndef ANALOG mt->setDetectorMode(ePhotonCounting); cout << "Counting!" << endl; @@ -204,7 +215,7 @@ int main(int argc, char *argv[]) { mt->setDetectorMode(eAnalog); cout << "Analog!" << endl; cf=0; - // thr1=thr; + thr1=thr; #endif // } @@ -240,7 +251,7 @@ int main(int argc, char *argv[]) { mt->nextThread(); mt->popFree(buff); ifr++; - if (ifr%10000==0) + if (ifr%100==0) cout << ifr << " " << ff << " " << np << endl; } else cout << ifr << " " << ff << " " << np << endl; @@ -308,7 +319,7 @@ int main(int argc, char *argv[]) { // // // cout << " " << (void*)buff; mt->popFree(buff); ifr++; - if (ifr%1000==0) cout << ifr << " " << ff << endl; + if (ifr%100==0) cout << ifr << " " << ff << endl; if (nframes>0) { if (ifr%nframes==0) { //The name has an additional "_fXXXXX" at the end, where "XXXXX" is the initial frame number of the image (0,1000,2000...) @@ -334,9 +345,10 @@ int main(int argc, char *argv[]) { if (nframes>0) { sprintf(ffname,"%s/%s_f%05d.tiff",outdir,fformat,ifile); sprintf(imgfname,ffname,irun); + } else { + sprintf(ffname,"%s/%s.tiff",outdir,fformat); + sprintf(imgfname,ffname,irun); } - sprintf(ffname,"%s/%s.tiff",outdir,fformat); - sprintf(imgfname,ffname,irun); cout << "Writing tiff to " << imgfname << " " << thr1 <writeImage(imgfname, thr1); mt->clearImage(); @@ -351,6 +363,13 @@ int main(int argc, char *argv[]) { } else cout << "Could not open "<< fname << " for reading " << endl; } + if (nframes<0){ + sprintf(ffname,"%s/%s.tiff",outdir,fformat); + strcpy(imgfname,ffname); + cout << "Writing tiff to " << imgfname << " " << thr1 <writeImage(imgfname, thr1); + } + return 0; diff --git a/slsDetectorCalibration/moenchExecutables/moenchZmqProcess.cpp b/slsDetectorCalibration/moenchExecutables/moenchZmqProcess.cpp index 3eb1a039f..e256dd5d2 100644 --- a/slsDetectorCalibration/moenchExecutables/moenchZmqProcess.cpp +++ b/slsDetectorCalibration/moenchExecutables/moenchZmqProcess.cpp @@ -3,13 +3,15 @@ #include "sls_detector_defs.h" #include "ZmqSocket.h" #include "moench03T1ZmqDataNew.h" +#include "moench03GhostSummation.h" +#include "moench03CommonMode.h" #include #include #include #include #include #include "tiffIO.h" -//#include + #include //json header in zmq stream #include @@ -110,12 +112,16 @@ int main(int argc, char *argv[]) { int dataSize=size; char dummybuff[size]; - - - + + int ncol_cm=20; + double xt_ghost=0.00045; + moench03CommonMode *cm=new moench03CommonMode(ncol_cm); + moench03GhostSummation *gs=new moench03GhostSummation(det, xt_ghost); + double *gainmap=NULL; + //analogDetector *filter=new analogDetector(det,1,NULL,1000); #ifndef INTERP - singlePhotonDetector *filter=new singlePhotonDetector(det,3, 5, 1, 0, 1000, 10); + singlePhotonDetector *filter=new singlePhotonDetector(det,3, 5, 1, cm, 1000, 10, -1, -1, gainmap, gs); multiThreadedCountingDetector *mt=new multiThreadedCountingDetector(filter,nthreads,fifosize); @@ -126,7 +132,7 @@ int main(int argc, char *argv[]) { if (etafname) interp->readFlatField(etafname); - interpolatingDetector *filter=new interpolatingDetector(det,interp, 5, 1, 0, 1000, 10); + interpolatingDetector *filter=new interpolatingDetector(det,interp, 5, 1, cm, 1000, 10, -1, -1, gainmap, gs); multiThreadedInterpolatingDetector *mt=new multiThreadedInterpolatingDetector(filter,nthreads,fifosize); #endif @@ -392,17 +398,20 @@ int main(int argc, char *argv[]) { } + //// int SendHeaderData ( int index, bool dummy, uint32_t jsonversion, uint32_t dynamicrange = 0, uint64_t fileIndex = 0, + // uint32_t ndetx = 0, uint32_t ndety = 0, uint32_t npixelsx = 0, uint32_t npixelsy = 0, uint32_t imageSize = 0, + // uint64_t acqIndex = 0, uint64_t fIndex = 0, const char* fname = NULL, + // uint64_t frameNumber = 0, uint32_t expLength = 0, uint32_t packetNumber = 0, + // uint64_t bunchId = 0, uint64_t timestamp = 0, + // uint16_t modId = 0, uint16_t row = 0, uint16_t column = 0, uint16_t reserved = 0, + // uint32_t debug = 0, uint16_t roundRNumber = 0, + // uint8_t detType = 0, uint8_t version = 0, int gapPixelsEnable = 0, int flippedDataX = 0, + // char* additionalJsonHeader = 0) { -#ifdef NEWZMQ - cout << "Sending image size " << nnx << " " << nny << endl; - zmqsocket2->SendHeaderData (0, false, SLS_DETECTOR_JSON_HEADER_VERSION, dr, fileindex, nnx, nny, nnx*nny*dr/8,acqIndex, frameIndex, fname, acqIndex, subFrameIndex, packetNumber,bunchId, timestamp, modId, xCoord, yCoord, zCoord,debug, roundRNumber, detType, version, flippedData, additionalJsonHeader); - -#endif -#ifndef NEWZMQ - 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); -#endif - + // cout << "Sending image size " << nnx << " " << nny << endl; + zmqsocket2->SendHeaderData (0, false, SLS_DETECTOR_JSON_HEADER_VERSION, dr, fileindex, 0,0, nnx, nny, nnx*nny*dr/8,acqIndex, frameIndex, fname, acqIndex,0 , packetNumber,bunchId, timestamp, modId, xCoord, yCoord, zCoord,debug, roundRNumber, detType, version, 0,0, additionalJsonHeader); + zmqsocket2->SendData((char*)dout,nnx*nny*dr/8); cprintf(GREEN, "Sent Data\n"); @@ -654,7 +663,12 @@ int main(int argc, char *argv[]) { // cout << "file" << endl; // cout << "data " << endl; if (of==NULL) { +#ifdef WRITE_QUAD + sprintf(ofname,"%s_%d.clust2",filename.c_str(),fileindex); +#endif +#ifndef WRITE_QUAD sprintf(ofname,"%s_%d.clust",filename.c_str(),fileindex); +#endif of=fopen(ofname,"w"); if (of) { mt->setFilePointer(of); diff --git a/slsDetectorCalibration/singlePhotonDetector.h b/slsDetectorCalibration/singlePhotonDetector.h index 0ff15b03f..6ef4eee2f 100644 --- a/slsDetectorCalibration/singlePhotonDetector.h +++ b/slsDetectorCalibration/singlePhotonDetector.h @@ -58,7 +58,7 @@ public analogDetector { int sign=1, commonModeSubtraction *cm=NULL, int nped=1000, - int nd=100, int nnx=-1, int nny=-1, double *gm=NULL) : analogDetector(d, sign, cm, nped, nnx, nny, gm), nDark(nd), eventMask(NULL),nSigma (nsigma), clusterSize(csize), clusterSizeY(csize), clusters(NULL), quad(UNDEFINED_QUADRANT), tot(0), quadTot(0), eMin(-1), eMax(-1) { + int nd=100, int nnx=-1, int nny=-1, double *gm=NULL, ghostSummation *gs=NULL) : analogDetector(d, sign, cm, nped, nnx, nny, gm, gs), nDark(nd), eventMask(NULL),nSigma (nsigma), clusterSize(csize), clusterSizeY(csize), clusters(NULL), quad(UNDEFINED_QUADRANT), tot(0), quadTot(0), eMin(-1), eMax(-1) { @@ -213,7 +213,7 @@ public analogDetector { return nph; } else { if (thr>0) { - newFrame(); + newFrame(data); if (cmSub) { cout << "add to common mode?"<< endl; addToCommonMode(data); @@ -362,7 +362,7 @@ int *getClusters(char *data, int *ph=NULL) { addToPedestal(data); return 0; } - newFrame(); + newFrame(data); diff --git a/slsDetectorServers/ctbDetectorServer/Makefile b/slsDetectorServers/ctbDetectorServer/Makefile index 6d8ddd9f4..10e446362 100755 --- a/slsDetectorServers/ctbDetectorServer/Makefile +++ b/slsDetectorServers/ctbDetectorServer/Makefile @@ -13,7 +13,8 @@ INSTMODE = 0777 SRCS = $(main_server)communication_funcs.c $(main_server)slsDetectorServer.c $(main_server)slsDetectorServer_funcs.c slsDetectorFunctionList.c OBJS = $(SRCS:.c=.o) -all: clean versioning $(PROGS) +all: clean versioning $(PROGS) +#all: clean $(PROGS) boot: $(OBJS) diff --git a/slsDetectorServers/ctbDetectorServer/RegisterDefs.h b/slsDetectorServers/ctbDetectorServer/RegisterDefs.h index 8aa6c2ff7..e5b21dc28 100755 --- a/slsDetectorServers/ctbDetectorServer/RegisterDefs.h +++ b/slsDetectorServers/ctbDetectorServer/RegisterDefs.h @@ -364,23 +364,23 @@ #define PATTERN_CNTRL_RD_OFST (1) #define PATTERN_CNTRL_RD_MSK (0x00000001 << PATTERN_CNTRL_RD_OFST) #define PATTERN_CNTRL_ADDR_OFST (16) -#define PATTERN_CNTRL_ADDR_MSK (0x0000FFFF << PATTERN_CNTRL_ADDR_OFST) +#define PATTERN_CNTRL_ADDR_MSK (0x00001FFF << PATTERN_CNTRL_ADDR_OFST) /* Pattern Limit RW regiser */ #define PATTERN_LIMIT_REG (0x53 << MEM_MAP_SHIFT) #define PATTERN_LIMIT_STRT_OFST (0) -#define PATTERN_LIMIT_STRT_MSK (0x0000FFFF << PATTERN_LIMIT_STRT_OFST) +#define PATTERN_LIMIT_STRT_MSK (0x00001FFF << PATTERN_LIMIT_STRT_OFST) #define PATTERN_LIMIT_STP_OFST (16) -#define PATTERN_LIMIT_STP_MSK (0x0000FFFF << PATTERN_LIMIT_STP_OFST) +#define PATTERN_LIMIT_STP_MSK (0x00001FFF << PATTERN_LIMIT_STP_OFST) /* Pattern Loop 0 Address RW regiser */ #define PATTERN_LOOP_0_ADDR_REG (0x54 << MEM_MAP_SHIFT) #define PATTERN_LOOP_0_ADDR_STRT_OFST (0) -#define PATTERN_LOOP_0_ADDR_STRT_MSK (0x0000FFFF << PATTERN_LOOP_0_ADDR_STRT_OFST) +#define PATTERN_LOOP_0_ADDR_STRT_MSK (0x00001FFF << PATTERN_LOOP_0_ADDR_STRT_OFST) #define PATTERN_LOOP_0_ADDR_STP_OFST (16) -#define PATTERN_LOOP_0_ADDR_STP_MSK (0x0000FFFF << PATTERN_LOOP_0_ADDR_STP_OFST) +#define PATTERN_LOOP_0_ADDR_STP_MSK (0x00001FFF << PATTERN_LOOP_0_ADDR_STP_OFST) /* Pattern Loop 0 Iteration RW regiser */ #define PATTERN_LOOP_0_ITERATION_REG (0x55 << MEM_MAP_SHIFT) @@ -389,9 +389,9 @@ #define PATTERN_LOOP_1_ADDR_REG (0x56 << MEM_MAP_SHIFT) #define PATTERN_LOOP_1_ADDR_STRT_OFST (0) -#define PATTERN_LOOP_1_ADDR_STRT_MSK (0x0000FFFF << PATTERN_LOOP_1_ADDR_STRT_OFST) +#define PATTERN_LOOP_1_ADDR_STRT_MSK (0x00001FFF << PATTERN_LOOP_1_ADDR_STRT_OFST) #define PATTERN_LOOP_1_ADDR_STP_OFST (16) -#define PATTERN_LOOP_1_ADDR_STP_MSK (0x0000FFFF << PATTERN_LOOP_1_ADDR_STP_OFST) +#define PATTERN_LOOP_1_ADDR_STP_MSK (0x00001FFF << PATTERN_LOOP_1_ADDR_STP_OFST) /* Pattern Loop 1 Iteration RW regiser */ #define PATTERN_LOOP_1_ITERATION_REG (0x57 << MEM_MAP_SHIFT) @@ -400,9 +400,9 @@ #define PATTERN_LOOP_2_ADDR_REG (0x58 << MEM_MAP_SHIFT) #define PATTERN_LOOP_2_ADDR_STRT_OFST (0) -#define PATTERN_LOOP_2_ADDR_STRT_MSK (0x0000FFFF << PATTERN_LOOP_2_ADDR_STRT_OFST) +#define PATTERN_LOOP_2_ADDR_STRT_MSK (0x00001FFF << PATTERN_LOOP_2_ADDR_STRT_OFST) #define PATTERN_LOOP_2_ADDR_STP_OFST (16) -#define PATTERN_LOOP_2_ADDR_STP_MSK (0x0000FFFF << PATTERN_LOOP_2_ADDR_STP_OFST) +#define PATTERN_LOOP_2_ADDR_STP_MSK (0x00001FFF << PATTERN_LOOP_2_ADDR_STP_OFST) /* Pattern Loop 2 Iteration RW regiser */ #define PATTERN_LOOP_2_ITERATION_REG (0x59 << MEM_MAP_SHIFT) @@ -411,20 +411,20 @@ #define PATTERN_WAIT_0_ADDR_REG (0x5A << MEM_MAP_SHIFT) #define PATTERN_WAIT_0_ADDR_OFST (0) -#define PATTERN_WAIT_0_ADDR_MSK (0x0000FFFF << PATTERN_WAIT_0_ADDR_OFST) +#define PATTERN_WAIT_0_ADDR_MSK (0x00001FFF << PATTERN_WAIT_0_ADDR_OFST) //FIXME: is mask 3FF /* Pattern Wait 1 RW regiser */ #define PATTERN_WAIT_1_ADDR_REG (0x5B << MEM_MAP_SHIFT) #define PATTERN_WAIT_1_ADDR_OFST (0) -#define PATTERN_WAIT_1_ADDR_MSK (0x0000FFFF << PATTERN_WAIT_1_ADDR_OFST) +#define PATTERN_WAIT_1_ADDR_MSK (0x00001FFF << PATTERN_WAIT_1_ADDR_OFST) /* Pattern Wait 2 RW regiser */ #define PATTERN_WAIT_2_ADDR_REG (0x5C << MEM_MAP_SHIFT) #define PATTERN_WAIT_2_ADDR_OFST (0) -#define PATTERN_WAIT_2_ADDR_MSK (0x0000FFFF << PATTERN_WAIT_2_ADDR_OFST) +#define PATTERN_WAIT_2_ADDR_MSK (0x00001FFF << PATTERN_WAIT_2_ADDR_OFST) /* Samples RW register */ #define SAMPLES_REG (0x5D << MEM_MAP_SHIFT) diff --git a/slsDetectorServers/ctbDetectorServer/bin/ctbDetectorServer_developer b/slsDetectorServers/ctbDetectorServer/bin/ctbDetectorServer_developer index a2f52fdb6..d555e70ef 100755 Binary files a/slsDetectorServers/ctbDetectorServer/bin/ctbDetectorServer_developer and b/slsDetectorServers/ctbDetectorServer/bin/ctbDetectorServer_developer differ diff --git a/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c index e40696de4..d03f5d053 100755 --- a/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c @@ -2163,8 +2163,9 @@ int startStateMachine(){ FILE_LOG(logINFOGREEN, ("Virtual Acquisition started\n")); return OK; #endif + int send_to_10g = enableTenGigabitEthernet(-1); // 1 giga udp - if (!enableTenGigabitEthernet(-1)) { + if (send_to_10g == 0) { // create udp socket if(createUDPSocket(0) != OK) { return FAIL; @@ -2175,7 +2176,9 @@ int startStateMachine(){ FILE_LOG(logINFOBLUE, ("Starting State Machine\n")); cleanFifos(); - unsetFifoReadStrobes(); // FIXME: unnecessary to write bus_w(dumm, 0) as it is 0 in the beginnig and the strobes are always unset if set + if (send_to_10g == 0) { + unsetFifoReadStrobes(); // FIXME: unnecessary to write bus_w(dumm, 0) as it is 0 in the beginnig and the strobes are always unset if set + } //start state machine bus_w(CONTROL_REG, bus_r(CONTROL_REG) | CONTROL_STRT_ACQSTN_MSK | CONTROL_STRT_EXPSR_MSK); @@ -2332,14 +2335,13 @@ void readFrame(int *ret, char *mess) { // frames left to give status int64_t retval = getTimeLeft(FRAME_NUMBER) + 2; if ( retval > 1) { - *ret = (int)FAIL; sprintf(mess,"No data and run stopped: %lld frames left\n",(long long int)retval); FILE_LOG(logERROR, (mess)); } else { - *ret = (int)OK; FILE_LOG(logINFOGREEN, ("Acquisition successfully finished\n")); } } + *ret = (int)OK; } void unsetFifoReadStrobes() { @@ -2430,12 +2432,12 @@ uint32_t checkDataInFifo() { uint32_t dataPresent = 0; if (analogEnable) { uint32_t analogFifoEmpty = bus_r(FIFO_EMPTY_REG); - FILE_LOG(logDEBUG2, ("Analog Fifo Empty (32 channels): 0x%x\n", analogFifoEmpty)); + FILE_LOG(logINFO, ("Analog Fifo Empty (32 channels): 0x%08x\n", analogFifoEmpty)); dataPresent = (~analogFifoEmpty); } if (!dataPresent && digitalEnable) { int digitalFifoEmpty = ((bus_r(FIFO_DIN_STATUS_REG) & FIFO_DIN_STATUS_FIFO_EMPTY_MSK) >> FIFO_DIN_STATUS_FIFO_EMPTY_OFST); - FILE_LOG(logDEBUG2, ("Digital Fifo Empty: %d\n",digitalFifoEmpty)); + FILE_LOG(logINFO, ("Digital Fifo Empty: %d\n",digitalFifoEmpty)); dataPresent = (digitalFifoEmpty ? 0 : 1); } FILE_LOG(logDEBUG2, ("Data in Fifo :0x%x\n", dataPresent)); diff --git a/slsDetectorServers/ctbDetectorServer/slsDetectorServer_defs.h b/slsDetectorServers/ctbDetectorServer/slsDetectorServer_defs.h index 9b116d70a..33b5c5e5e 100755 --- a/slsDetectorServers/ctbDetectorServer/slsDetectorServer_defs.h +++ b/slsDetectorServers/ctbDetectorServer/slsDetectorServer_defs.h @@ -4,7 +4,7 @@ #define MIN_REQRD_VRSN_T_RD_API 0x181130 -#define REQRD_FRMWR_VRSN 0x190402 +#define REQRD_FRMWR_VRSN 0x190821 #define CTRL_SRVR_INIT_TIME_US (2 * 1000 * 1000) @@ -59,9 +59,9 @@ enum DACINDEX {D0, D1, D2, D3, D4, D5, D6, D7, D8, D9, #define DEFAULT_VLIMIT (-100) #define DEFAULT_TIMING_MODE (AUTO_TIMING) #define DEFAULT_TX_UDP_PORT (0x7e9a) -#define DEFAULT_RUN_CLK (40) -#define DEFAULT_ADC_CLK (20) -#define DEFAULT_SYNC_CLK (20) +#define DEFAULT_RUN_CLK (200) // 40 +#define DEFAULT_ADC_CLK (40) // 20 +#define DEFAULT_SYNC_CLK (40) // 20 #define DEFAULT_DBIT_CLK (200) #define HIGHVOLTAGE_MIN (60) @@ -76,7 +76,7 @@ enum DACINDEX {D0, D1, D2, D3, D4, D5, D6, D7, D8, D9, #define VIO_MIN_MV (1200) // for fpga to function /* Defines in the Firmware */ -#define MAX_PATTERN_LENGTH (0x7FFF) +#define MAX_PATTERN_LENGTH (0x2000) #define DIGITAL_IO_DELAY_MAXIMUM_PS ((OUTPUT_DELAY_0_OTPT_STTNG_MSK >> OUTPUT_DELAY_0_OTPT_STTNG_OFST) * OUTPUT_DELAY_0_OTPT_STTNG_STEPS) #define MAX_PHASE_SHIFTS_STEPS (8) diff --git a/slsReceiverSoftware/include/DataProcessor.h b/slsReceiverSoftware/include/DataProcessor.h index d4fc0ef71..61dbe3b66 100755 --- a/slsReceiverSoftware/include/DataProcessor.h +++ b/slsReceiverSoftware/include/DataProcessor.h @@ -18,6 +18,7 @@ class File; class DataStreamer; #include +#include class DataProcessor : private virtual slsDetectorDefs, public ThreadObject { @@ -305,7 +306,7 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject { static const std::string TypeName; /** Object running status */ - bool runningFlag; + std::atomic runningFlag; /** GeneralData (Detector Data) object */ const GeneralData* generalData; diff --git a/slsReceiverSoftware/include/GeneralData.h b/slsReceiverSoftware/include/GeneralData.h index 99beeeddd..9a3c4f422 100755 --- a/slsReceiverSoftware/include/GeneralData.h +++ b/slsReceiverSoftware/include/GeneralData.h @@ -120,18 +120,13 @@ public: * Get Header Infomation (frame number, packet number) * @param index thread index for debugging purposes * @param packetData pointer to data - * @param dynamicRange dynamic range to assign subframenumber if 32 bit mode * @param oddStartingPacket odd starting packet (gotthard) * @param frameNumber frame number * @param packetNumber packet number - * @param subFrameNumber sub frame number if applicable - * @param bunchId bunch id */ - virtual void GetHeaderInfo(int index, char* packetData, uint32_t dynamicRange, bool oddStartingPacket, - uint64_t& frameNumber, uint32_t& packetNumber, uint32_t& subFrameNumber, uint64_t& bunchId) const + virtual void GetHeaderInfo(int index, char* packetData, bool oddStartingPacket, + uint64_t& frameNumber, uint32_t& packetNumber) const { - subFrameNumber = -1; - bunchId = -1; frameNumber = ((uint32_t)(*((uint32_t*)(packetData)))); frameNumber++; packetNumber = frameNumber&packetIndexMask; @@ -280,27 +275,20 @@ private: * Get Header Infomation (frame number, packet number) * @param index thread index for debugging purposes * @param packetData pointer to data - * @param dynamicRange dynamic range to assign subframenumber if 32 bit mode * @param oddStartingPacket odd starting packet (gotthard) * @param frameNumber frame number * @param packetNumber packet number - * @param subFrameNumber sub frame number if applicable - * @param bunchId bunch id */ - void GetHeaderInfo(int index, char* packetData, uint32_t dynamicRange, bool oddStartingPacket, - uint64_t& frameNumber, uint32_t& packetNumber, uint32_t& subFrameNumber, uint64_t& bunchId) const + void GetHeaderInfo(int index, char* packetData, bool oddStartingPacket, + uint64_t& frameNumber, uint32_t& packetNumber) const { if (nPixelsX == 1280) { - subFrameNumber = -1; - bunchId = -1; frameNumber = *reinterpret_cast(packetData); if (oddStartingPacket) frameNumber++; packetNumber = frameNumber&packetIndexMask; frameNumber = (frameNumber & frameIndexMask) >> frameIndexOffset; } else { - subFrameNumber = -1; - bunchId = -1; frameNumber = *reinterpret_cast(packetData); packetNumber = 0; } @@ -548,6 +536,14 @@ private: const int NCHAN_DIGITAL = 64; /** Number of bytes per analog channel */ const int NUM_BYTES_PER_ANALOG_CHANNEL = 2; + + struct ctb_10g_packet_header { + unsigned char emptyHeader[6]; + unsigned char reserved[4]; + uint32_t packetFrameNumber; + uint64_t bunchid; + } __attribute__((packed)); + public: @@ -561,6 +557,9 @@ public: packetSize = headerSizeinPacket + dataSize; //packetsPerFrame = 1; imageSize = nPixelsX * nPixelsY * 2; + frameIndexMask = 0xFFFFFF; // 10g + frameIndexOffset = 8; // 10g + packetIndexMask = 0xFF; //10g packetsPerFrame = ceil((double)imageSize / (double)UDP_PACKET_DATA_BYTES); maxFramesPerFile = CTB_MAX_FRAMES_PER_FILE; fifoBufferHeaderSize= FIFO_HEADER_NUMBYTES + sizeof(slsDetectorDefs::sls_receiver_header); @@ -612,12 +611,20 @@ public: nPixelsY = 1; // 10G if (t) { + /* headerSizeinPacket = sizeof(slsDetectorDefs::sls_detector_header); dataSize = UDP_PACKET_DATA_BYTES; packetSize = headerSizeinPacket + dataSize; imageSize = adatabytes + ddatabytes; packetsPerFrame = ceil((double)imageSize / (double)dataSize); standardheader = true; + */ + headerSizeinPacket = 22; + dataSize = 8192; + packetSize = headerSizeinPacket + dataSize; + imageSize = adatabytes + ddatabytes; + packetsPerFrame = ceil((double)imageSize / (double)dataSize); + standardheader = false; } // 1g udp (via fifo readout) else { @@ -631,6 +638,22 @@ public: return adatabytes; } + /** + * Get Header Infomation (frame number, packet number) + * @param index thread index for debugging purposes + * @param packetData pointer to data + * @param oddStartingPacket odd starting packet (gotthard) + * @param frameNumber frame number + * @param packetNumber packet number + */ + void GetHeaderInfo(int index, char* packetData, bool oddStartingPacket, + uint64_t& frameNumber, uint32_t& packetNumber) const + { + auto header = reinterpret_cast(packetData); + frameNumber = (header->packetFrameNumber >> frameIndexOffset) & frameIndexMask; + packetNumber = header->packetFrameNumber & packetIndexMask; + } + }; diff --git a/slsReceiverSoftware/include/Listener.h b/slsReceiverSoftware/include/Listener.h index 2ee15c75a..efdb3a1e6 100755 --- a/slsReceiverSoftware/include/Listener.h +++ b/slsReceiverSoftware/include/Listener.h @@ -10,7 +10,7 @@ */ #include - +#include #include "ThreadObject.h" class GeneralData; @@ -39,7 +39,7 @@ class Listener : private virtual slsDetectorDefs, public ThreadObject { * @param depaden pointer to deactivated padding enable * @param sm pointer to silent mode */ - Listener(int ind, detectorType dtype, Fifo* f, runStatus* s, + Listener(int ind, detectorType dtype, Fifo* f, std::atomic* s, uint32_t* portno, char* e, uint64_t* nf, uint32_t* dr, int64_t* us, int64_t* as, uint32_t* fpf, frameDiscardPolicy* fdp, bool* act, bool* depaden, bool* sm); @@ -151,7 +151,6 @@ class Listener : private virtual slsDetectorDefs, public ThreadObject { void SetHardCodedPosition(uint16_t r, uint16_t c); - private: /** @@ -201,7 +200,7 @@ class Listener : private virtual slsDetectorDefs, public ThreadObject { static const std::string TypeName; /** Object running status */ - bool runningFlag; + std::atomic runningFlag; /** GeneralData (Detector Data) object */ GeneralData* generalData; @@ -214,7 +213,7 @@ class Listener : private virtual slsDetectorDefs, public ThreadObject { detectorType myDetectorType; /** Receiver Status */ - runStatus* status; + std::atomic* status; /** UDP Socket - Detector to Receiver */ std::unique_ptr udpSocket; @@ -264,10 +263,10 @@ class Listener : private virtual slsDetectorDefs, public ThreadObject { // acquisition start /** Aquisition Started flag */ - bool acquisitionStartedFlag; + std::atomic acquisitionStartedFlag; /** Measurement Started flag */ - bool measurementStartedFlag; + std::atomic measurementStartedFlag; /** Frame Number of First Frame of an entire Acquisition (including all scans) */ uint64_t firstAcquisitionIndex; @@ -278,10 +277,10 @@ class Listener : private virtual slsDetectorDefs, public ThreadObject { // for acquisition summary /** Number of complete Packets caught for each real time acquisition (eg. for each scan (start& stop of receiver)) */ - volatile uint64_t numPacketsCaught; + std::atomic numPacketsCaught; /** Last Frame Index caught from udp network */ - uint64_t lastCaughtFrameIndex; + std::atomic lastCaughtFrameIndex; // parameters to acquire image @@ -300,12 +299,11 @@ class Listener : private virtual slsDetectorDefs, public ThreadObject { std::unique_ptr listeningPacket; /** if the udp socket is connected */ - bool udpSocketAlive; + std::atomic udpSocketAlive; /** Semaphore to synchonize deleting udp socket */ sem_t semaphore_socket; - // for print progress during acqusition /** number of packets for statistic */ uint32_t numPacketsStatistic; diff --git a/slsReceiverSoftware/include/slsReceiverImplementation.h b/slsReceiverSoftware/include/slsReceiverImplementation.h index 1e5dc2e88..f80bf91ac 100755 --- a/slsReceiverSoftware/include/slsReceiverImplementation.h +++ b/slsReceiverSoftware/include/slsReceiverImplementation.h @@ -21,6 +21,7 @@ class DataStreamer; class Fifo; class slsDetectorDefs; +#include #include #include #include @@ -910,7 +911,7 @@ class slsReceiverImplementation : private virtual slsDetectorDefs { /** Maximum Number of Listening Threads/ UDP Ports */ const static int MAX_NUMBER_OF_LISTENING_THREADS = 2; /** Receiver Status */ - runStatus status; + std::atomic status; /** Activated/Deactivated */ bool activated; /** Deactivated padding enable */ diff --git a/slsReceiverSoftware/src/Listener.cpp b/slsReceiverSoftware/src/Listener.cpp index 4ffccbd32..e1deb6ba8 100755 --- a/slsReceiverSoftware/src/Listener.cpp +++ b/slsReceiverSoftware/src/Listener.cpp @@ -20,7 +20,7 @@ const std::string Listener::TypeName = "Listener"; -Listener::Listener(int ind, detectorType dtype, Fifo* f, runStatus* s, +Listener::Listener(int ind, detectorType dtype, Fifo* f, std::atomic* s, uint32_t* portno, char* e, uint64_t* nf, uint32_t* dr, int64_t* us, int64_t* as, uint32_t* fpf, frameDiscardPolicy* fdp, bool* act, bool* depaden, bool* sm) : @@ -348,8 +348,8 @@ void Listener::StopListening(char* buf) { uint32_t Listener::ListenToAnImage(char* buf) { int rc = 0; - uint64_t fnum = 0, bid = 0; - uint32_t pnum = 0, snum = 0; + uint64_t fnum = 0; + uint32_t pnum = 0; uint32_t numpackets = 0; uint32_t dsize = generalData->dataSize; uint32_t hsize = generalData->headerSizeinPacket; //(includes empty header) @@ -402,8 +402,7 @@ uint32_t Listener::ListenToAnImage(char* buf) { } // -------------------old header ----------------------------------------------------------------------------- else { - generalData->GetHeaderInfo(index, &carryOverPacket[0], - *dynamicRange, oddStartingPacket, fnum, pnum, snum, bid); + generalData->GetHeaderInfo(index, &carryOverPacket[0], oddStartingPacket, fnum, pnum); } //------------------------------------------------------------------------------------------------------------ if (fnum != currentFrameIndex) { @@ -476,9 +475,6 @@ uint32_t Listener::ListenToAnImage(char* buf) { } - - - //until last packet isHeaderEmpty to account for gotthard short frame, else never entering this loop) while ( numpackets < pperFrame) { //listen to new packet @@ -525,8 +521,7 @@ uint32_t Listener::ListenToAnImage(char* buf) { oddStartingPacket = generalData->SetOddStartingPacket(index, &listeningPacket[0]); } - generalData->GetHeaderInfo(index, &listeningPacket[0], - *dynamicRange, oddStartingPacket, fnum, pnum, snum, bid); + generalData->GetHeaderInfo(index, &listeningPacket[0], oddStartingPacket, fnum, pnum); } //------------------------------------------------------------------------------------------------------------ diff --git a/slsSupportLib/include/genericSocket.h b/slsSupportLib/include/genericSocket.h index 220aa5e8f..1b7e7d00f 100755 --- a/slsSupportLib/include/genericSocket.h +++ b/slsSupportLib/include/genericSocket.h @@ -44,7 +44,6 @@ class sockaddr_in; #include #include "logger.h" - #define DEFAULT_PACKET_SIZE 1286 #define SOCKET_BUFFER_SIZE (100*1024*1024) //100 MB #define DEFAULT_BACKLOG 5 diff --git a/slsSupportLib/include/versionAPI.h b/slsSupportLib/include/versionAPI.h index a21736ff5..aeb36a6d9 100644 --- a/slsSupportLib/include/versionAPI.h +++ b/slsSupportLib/include/versionAPI.h @@ -5,6 +5,6 @@ #define APIGUI 0x190723 #define APIMOENCH 0x190820 #define APIGOTTHARD 0x190820 -#define APICTB 0x190820 -#define APIJUNGFRAU 0x190820 #define APIEIGER 0x190820 +#define APIJUNGFRAU 0x190820 +#define APICTB 0x190821