some changes in the moench executables

This commit is contained in:
bergamaschi 2018-08-08 10:23:35 +02:00
parent 9ae1289616
commit 44fdc46c11
24 changed files with 829 additions and 263 deletions

View File

@ -709,6 +709,7 @@ template <class dataType> class analogDetector {
/** /**
Sets region of interest in which data should be processed Sets region of interest in which data should be processed
\param xmi minimum x. if -1 or out of range remains unchanged \param xmi minimum x. if -1 or out of range remains unchanged

View File

@ -31,23 +31,28 @@ class moench02CtbData : public slsDetectorData<uint16_t> {
*/ */
moench02CtbData(int ns=6400): slsDetectorData<uint16_t>(160, 160, ns*2*32, NULL, NULL) , nadc(4), sc_width(40), sc_height(160) { moench02CtbData(int ns=6400): slsDetectorData<uint16_t>(160, 160, ns*2*32, NULL, NULL) , nadc(32), sc_width(40), sc_height(160) {
int adc_nr[4]={120,0,80,40}; int adc_off[4]={0,40,80,120};
int adc_nr[4]={8,10,20,23};
int row, col; int row, col;
int isample; int isample;
int iadc; int iadc, iiadc;
int ix, iy; int ix, iy;
maplength=this->getDataSize()/2; maplength=this->getDataSize()/2;
//cout << maplength << endl;
for (iadc=0; iadc<nadc; iadc++) { for (iiadc=0; iiadc<4; iiadc++) {
iadc=adc_nr[iiadc];
//cout << iiadc << endl;
for (int i=0; i<sc_width*sc_height; i++) { for (int i=0; i<sc_width*sc_height; i++) {
col=adc_nr[iadc]+(i%sc_width);
col=adc_off[iiadc]+(i%sc_width);
row=i/sc_width; row=i/sc_width;
dataMap[row][col]=(32*i+iadc+2)*2; dataMap[row][col]=(32*i+iadc)*2;
if (dataMap[row][col]<0 || dataMap[row][col]>=dataSize) { if (dataMap[row][col]<0 || dataMap[row][col]>=dataSize) {
cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl; cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl;
} }
@ -56,12 +61,17 @@ class moench02CtbData : public slsDetectorData<uint16_t> {
} }
for (int i=0; i<maplength; i++) { for (int i=0; i<maplength; i++) {
//cout << i << endl;
isample=i/32; isample=i/32;
iadc=i%32; iiadc=i%32;
iadc=-1;
for (int iii=0; iii<4; iii++) {
if (iiadc==adc_nr[iii]) iadc=iii;
}
ix=isample%sc_width; ix=isample%sc_width;
iy=isample/sc_width; iy=isample/sc_width;
if(iadc>1 && iadc<6){ if(iadc>=0){
xmap[i]=adc_nr[iadc-2]+ix; xmap[i]=adc_off[iadc]+ix;
ymap[i]=iy; ymap[i]=iy;
}else{ }else{
xmap[i]=-1; xmap[i]=-1;
@ -71,7 +81,7 @@ class moench02CtbData : public slsDetectorData<uint16_t> {
iframe=0; iframe=0;
cout << "data struct created" << endl; cout << "data struct created" << endl;
}; };
void getPixel(int ip, int &x, int &y) { void getPixel(int ip, int &x, int &y) {
if(ip>=0 && ip<maplength){ if(ip>=0 && ip<maplength){
x=xmap[ip]; x=xmap[ip];
@ -137,7 +147,9 @@ class moench02CtbData : public slsDetectorData<uint16_t> {
} }
if (ib>0) { if (ib>0) {
iframe++; iframe++;
//cout << ib << "-" << endl; //cout << ib/2 << "-" << endl;
//for (int i=0; i<ib/2; i++)
//cout << i << " " << afifo_cont[i] << endl;
return (char*)afifo_cont; return (char*)afifo_cont;
} else { } else {
delete [] afifo_cont; delete [] afifo_cont;

View File

@ -17,10 +17,7 @@
#include <iostream> #include <iostream>
using namespace std; using namespace std;
#define XMIN 350/2
#define XMAX 600/2
#define YMIN 0
#define YMAX 400
class interpolatingDetector : public singlePhotonDetector { class interpolatingDetector : public singlePhotonDetector {
@ -50,7 +47,7 @@ class interpolatingDetector : public singlePhotonDetector {
commonModeSubtraction *cm=NULL, commonModeSubtraction *cm=NULL,
int nped=1000, int nped=1000,
int nd=100, int nnx=-1, int nny=-1) : int nd=100, int nnx=-1, int nny=-1) :
singlePhotonDetector(d, 3,nsigma,sign, cm, nped, nd, nnx, nny) , interp(inte), id(0), xmin(XMIN), xmax(XMAX), ymin(YMIN), ymax(YMAX) { singlePhotonDetector(d, 3,nsigma,sign, cm, nped, nd, nnx, nny) , interp(inte), id(0) {
cout << "**"<< xmin << " " << xmax << " " << ymin << " " << ymax << endl; cout << "**"<< xmin << " " << xmax << " " << ymin << " " << ymax << endl;
}; };
@ -60,10 +57,10 @@ class interpolatingDetector : public singlePhotonDetector {
interpolatingDetector(interpolatingDetector *orig) : singlePhotonDetector(orig) { interpolatingDetector(interpolatingDetector *orig) : singlePhotonDetector(orig) {
interp=(orig->interp)->Clone(); interp=(orig->interp)->Clone();
id=orig->id; id=orig->id;
xmin=orig->xmin; /* xmin=orig->xmin; */
xmax=orig->xmax; /* xmax=orig->xmax; */
ymin=orig->ymin; /* ymin=orig->ymin; */
ymax=orig->ymax; /* ymax=orig->ymax; */
} }
@ -157,10 +154,10 @@ int addFrame(char *data, int *ph=NULL, int ff=0) {
int cy=(clusterSizeY+1)/2; int cy=(clusterSizeY+1)/2;
int cs=(clusterSize+1)/2; int cs=(clusterSize+1)/2;
int ir, ic; int ir, ic;
double rms;
double int_x,int_y, eta_x, eta_y; double int_x,int_y, eta_x, eta_y;
double max=0, tl=0, tr=0, bl=0,br=0, *v, vv; double max=0, tl=0, tr=0, bl=0,br=0, *v, vv;
// cout << "********** Add frame "<< iframe << endl;
if (ph==NULL) if (ph==NULL)
ph=image; ph=image;
@ -169,6 +166,7 @@ int addFrame(char *data, int *ph=NULL, int ff=0) {
return 0; return 0;
} }
newFrame(); newFrame();
// cout << "********** Data "<< endl;
for (int ix=xmin; ix<xmax; ix++) { for (int ix=xmin; ix<xmax; ix++) {
for (int iy=ymin; iy<ymax; iy++) { for (int iy=ymin; iy<ymax; iy++) {
@ -185,8 +183,8 @@ int addFrame(char *data, int *ph=NULL, int ff=0) {
eventMask[iy][ix]=PEDESTAL; eventMask[iy][ix]=PEDESTAL;
rms=getPedestalRMS(ix,iy);
(clusters+nph)->rms=getPedestalRMS(ix,iy); (clusters+nph)->rms=rms;
@ -213,7 +211,7 @@ int addFrame(char *data, int *ph=NULL, int ff=0) {
if (ir==0 && ic==0) { if (ir==0 && ic==0) {
if (*v<-nSigma*cluster->rms) if (*v<-nSigma*rms)
eventMask[iy][ix]=NEGATIVE_PEDESTAL; eventMask[iy][ix]=NEGATIVE_PEDESTAL;
} }
@ -234,7 +232,7 @@ int addFrame(char *data, int *ph=NULL, int ff=0) {
(clusters+nph)->quadTot=tr; (clusters+nph)->quadTot=tr;
} }
if (max>nSigma*cluster->rms || tot>sqrt(clusterSizeY*clusterSize)*nSigma*cluster->rms || ((clusters+nph)->quadTot)>sqrt(cy*cs)*nSigma*cluster->rms) { if (max>nSigma*rms || tot>sqrt(clusterSizeY*clusterSize)*nSigma*rms || ((clusters+nph)->quadTot)>sqrt(cy*cs)*nSigma*rms) {
if (val[iy][ix]>=max) { if (val[iy][ix]>=max) {
eventMask[iy][ix]=PHOTON_MAX; eventMask[iy][ix]=PHOTON_MAX;
(clusters+nph)->tot=tot; (clusters+nph)->tot=tot;
@ -646,8 +644,6 @@ int addFrame(char *data, int *ph=NULL, int ff=0) {
slsInterpolation *interp; slsInterpolation *interp;
int id; int id;
//should put it to analogDetector
int xmin, xmax, ymin, ymax;
}; };

View File

@ -97,7 +97,9 @@ class etaInterpolationBase : public slsInterpolation {
#ifndef MYROOT1 #ifndef MYROOT1
int *setEta(int *h, int nb=-1, double emin=1, double emax=0) int *setEta(int *h, int nb=-1, double emin=1, double emax=0)
{ {
if (h) {heta=h; if (h) {
if (heta) delete [] heta;
heta=h;
nbeta=nb; nbeta=nb;
if (nb<=0) nbeta=nSubPixels*10; if (nb<=0) nbeta=nSubPixels*10;
etamin=emin; etamin=emin;

View File

@ -15,11 +15,11 @@ class etaInterpolationPosXY : public virtual etaInterpolationBase{
etaInterpolationPosXY(etaInterpolationPosXY *orig): etaInterpolationBase(orig) {}; etaInterpolationPosXY(etaInterpolationPosXY *orig): etaInterpolationBase(orig) {};
virtual etaInterpolationPosXY* Clone()=0;/** { virtual etaInterpolationPosXY* Clone()=0; /* { */
return new etaInterpolationPosXY(this); /* return new etaInterpolationPosXY(this); */
};*/ /* }; */
virtual void prepareInterpolation(int &ok) virtual void prepareInterpolation(int &ok)
{ {

View File

@ -40,7 +40,21 @@ class linearInterpolation : public slsInterpolation{
return; return;
}; };
virtual void getInterpolatedPosition(int x, int y, int *data, double &int_x, double &int_y)
{
double sDum[2][2];
double tot, totquad;
double etax,etay;
int corner;
corner=calcQuad(data, tot, totquad, sDum);
if (nSubPixels>2)
calcEta(totquad, sDum, etax, etay);
getInterpolatedPosition(x,y,etax,etay,corner,int_x,int_y);
return;
};
virtual void getInterpolatedPosition(int x, int y, double totquad,int quad,double *cl,double &int_x, double &int_y) { virtual void getInterpolatedPosition(int x, int y, double totquad,int quad,double *cl,double &int_x, double &int_y) {
double eta_x, eta_y; double eta_x, eta_y;
@ -78,6 +92,7 @@ class linearInterpolation : public slsInterpolation{
cc[1][1]=cluster[yoff+1][xoff+1]; cc[1][1]=cluster[yoff+1][xoff+1];
calcEta(totquad,cc,eta_x,eta_y); calcEta(totquad,cc,eta_x,eta_y);
} }
// cout << x << " " << y << " " << eta_x << " " << eta_y << " " << int_x << " " << int_y << endl;
return getInterpolatedPosition(x,y,eta_x, eta_y,quad,int_x,int_y); return getInterpolatedPosition(x,y,eta_x, eta_y,quad,int_x,int_y);
@ -86,6 +101,49 @@ class linearInterpolation : public slsInterpolation{
}
virtual void getInterpolatedPosition(int x, int y, double totquad,int quad,int *cl,double &int_x, double &int_y) {
double cc[2][2];
int *cluster[3];
int xoff, yoff;
cluster[0]=cl;
cluster[1]=cl+3;
cluster[2]=cl+6;
switch (quad) {
case BOTTOM_LEFT:
xoff=0;
yoff=0;
break;
case BOTTOM_RIGHT:
xoff=1;
yoff=0;
break;
case TOP_LEFT:
xoff=0;
yoff=1;
break;
case TOP_RIGHT:
xoff=1;
yoff=1;
break;
default:
;
}
double etax, etay;
if (nSubPixels>2) {
cc[0][0]=cluster[yoff][xoff];
cc[1][0]=cluster[yoff+1][xoff];
cc[0][1]=cluster[yoff][xoff+1];
cc[1][1]=cluster[yoff+1][xoff+1];
calcEta(totquad,cc,etax,etay);
}
// cout << x << " " << y << " " << etax << " " << etay << " " << int_x << " " << int_y << endl;
return getInterpolatedPosition(x,y,etax, etay,quad,int_x,int_y);
} }
@ -125,11 +183,11 @@ class linearInterpolation : public slsInterpolation{
ypos_eta=(etay)+dY; ypos_eta=(etay)+dY;
} else { } else {
xpos_eta=0.5*dX+0.25; xpos_eta=0.5*dX+0.25;
xpos_eta=0.5*dY+0.25; ypos_eta=0.5*dY+0.25;
} }
int_x=((double)x) + xpos_eta; int_x=((double)x) + xpos_eta;
int_y=((double)y) + ypos_eta; int_y=((double)y) + ypos_eta;
// cout <<"**"<< x << " " << y << " " << xpos_eta << " " << ypos_eta << " " << corner << endl;
return; return;
}; };
@ -162,8 +220,10 @@ class linearInterpolation : public slsInterpolation{
//////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////
virtual int addToFlatField(double *cluster, double &etax, double &etay){}; virtual int addToFlatField(double *cluster, double &etax, double &etay){};
virtual int addToFlatField(int *cluster, double &etax, double &etay){};
virtual int addToFlatField(double etax, double etay){}; virtual int addToFlatField(double etax, double etay){};
virtual int addToFlatField(double totquad,int quad,double *cl,double &etax, double &etay) {}; virtual int addToFlatField(double totquad,int quad,double *cl,double &etax, double &etay) {};
virtual int addToFlatField(double totquad,int quad,int *cl,double &etax, double &etay) {};
protected: protected:
; ;

View File

@ -24,7 +24,10 @@
#endif #endif
#include <memory.h> #include <memory.h>
#include <stdio.h>
#include <iostream>
using namespace std; using namespace std;
//#ifdef MYROOT1 //#ifdef MYROOT1
//: public TObject //: public TObject
//#endif //#endif
@ -84,7 +87,13 @@ hint=new TH2F("hint","hint",ns*nx, 0, nx, ns*ny, 0, ny);
#endif #endif
#ifndef MYROOT1 #ifndef MYROOT1
virtual int *getInterpolatedImage(){return hint;}; virtual int *getInterpolatedImage(){
// cout << "return interpolated image " << endl;
/* for (int i=0; i<nSubPixels* nSubPixels* nPixelsX*nPixelsY; i++) { */
/* cout << i << " " << hint[i] << endl; */
/* } */
return hint;
};
#endif #endif
@ -146,8 +155,13 @@ hint=new TH2F("hint","hint",ns*nx, 0, nx, ns*ny, 0, ny);
virtual int *addToImage(double int_x, double int_y){ virtual int *addToImage(double int_x, double int_y){
int iy=((double)nSubPixels)*int_y; int iy=((double)nSubPixels)*int_y;
int ix=((double)nSubPixels)*int_x; int ix=((double)nSubPixels)*int_x;
// cout << int_x << " " << int_y << " " << " " << ix << " " << iy << " " << ix+iy*nPixelsX*nSubPixels << endl; if (ix>=0 && ix<(nPixelsX*nSubPixels) && iy<(nSubPixels*nPixelsY) && iy>=0 ){
if (ix>=0 && ix<(nPixelsX*nSubPixels) && iy<(nSubPixels*nPixelsY) && iy>=0 )(*(hint+ix+iy*nPixelsX*nSubPixels))+=1; // cout << int_x << " " << int_y << " " << " " << ix << " " << iy << " " << ix+iy*nPixelsX*nSubPixels << " " << hint[ix+iy*nPixelsX*nSubPixels];
(*(hint+ix+iy*nPixelsX*nSubPixels))+=1;
// cout << " " << hint[ix+iy*nPixelsX*nSubPixels] << endl;
}// else
// cout << "bad! "<< int_x << " " << int_y << " " << " " << ix << " " << iy << " " << ix+iy*nPixelsX*nSubPixels << endl;
return hint; return hint;
}; };
#endif #endif

View File

@ -0,0 +1,22 @@
CBFLIBDIR= /afs/psi.ch/project/sls_det_software/CBFlib-0.9.5/
#ZMQLIB=../slsReceiverSoftware/include
INCDIR=-I. -I../ -I../interpolations -I../interpolations/etaVEL -I../dataStructures -I../../slsReceiverSoftware/include -I$(CBFLIBDIR)/include/
LDFLAG= ../tiffIO.cpp -L/usr/lib64/ -lpthread -lm -lstdc++ -L. -pthread -lrt -L$(CBFLIBDIR)/lib/ -ltiff
MAIN=moench03ReorderImage.cpp
all: moenchReorderImage moenchClusterFinder
moenchReorderImage: $(MAIN) $(INCS) clean
g++ -o moenchReorderImage $(MAIN) $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DSAVE_ALL -DNEWRECEIVER
moenchClusterFinder: moench03ClusterFinder.cpp
g++ -o moenchClusterFinder $(MAIN) $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) -DSAVE_ALL -DNEWRECEIVER
clean:
rm -f moenchReorderImage moenchClusterFinder

View File

@ -2,12 +2,14 @@
#INCS= $(INCSROOT) moench03_receiver.h #INCS= $(INCSROOT) moench03_receiver.h
#LINKDEF=receiverGuiLinkDef.h #LINKDEF=receiverGuiLinkDef.h
CBFLIBDIR= /afs/psi.ch/project/sls_det_software/CBFlib-0.9.5/ #CBFLIBDIR= /afs/psi.ch/project/sls_det_software/CBFlib-0.9.5/
ZMQLIB=../slsReceiverSoftware/include #ZMQLIB=../slsReceiverSoftware/include
LIBRARYCBF=$(CBFLIBDIR)/lib/*.o #LIBRARYCBF=$(CBFLIBDIR)/lib/*.o
INCDIR=-I. -I../ -I../interpolations -I../interpolations/etaVEL -I../dataStructures -I../../slsReceiverSoftware/include -I$(CBFLIBDIR)/include/ -I$(ROOTSYS)/include INCDIR=-I. -I../ -I../interpolations -I../interpolations/etaVEL -I../dataStructures -I../../slsReceiverSoftware/include -I$(ROOTSYS)/include
#-I$(CBFLIBDIR)/include/
#LIBHDF5= #LIBHDF5=
LDFLAG= -L/usr/lib64/ -lpthread -lm -lstdc++ -L. -pthread -lrt -L$(CBFLIBDIR)/lib/ -lhdf5 -ltiff LDFLAG= -L/usr/lib64/ -lpthread -lm -lstdc++ -L. -pthread -lrt -ltiff
#-L$(CBFLIBDIR)/lib/ -lhdf5
MAIN=tiff_to_th2f.cpp MAIN=tiff_to_th2f.cpp
@ -18,8 +20,8 @@ all: tiff_to_th2f
tiff_to_th2f: $(MAIN) $(INCS) tiff_to_th2f: $(MAIN) $(INCS)
g++ -o tiff_to_th2f $(MAIN) `root-config --cflags --glibs` -lMinuit -lm -ltiff -lstdc++ $(LDFLAG) $(INCDIR) $(LIBHDF5) $(LIBRARYCBF) ../tiffIO.cpp g++ -o tiff_to_th2f $(MAIN) `root-config --cflags --glibs` -lMinuit -lm -ltiff -lstdc++ $(LDFLAG) $(INCDIR) ../tiffIO.cpp
#$(LIBRARYCBF) $(LIBHDF5)
clean: clean:
rm -f tiff_to_th2f rm -f tiff_to_th2f

View File

@ -40,7 +40,7 @@ int main(int argc, char *argv[]) {
} }
int p=10000; int p=10000;
int fifosize=1000; int fifosize=1000;
int nthreads=8; int nthreads=1;
int nsubpix=25; int nsubpix=25;
int etabins=nsubpix*10; int etabins=nsubpix*10;
double etamin=-1, etamax=2; double etamin=-1, etamax=2;

View File

@ -30,9 +30,10 @@ int main(int argc, char *argv[]) {
cout << "Usage is " << argv[0] << "indir outdir fname runmin runmax " << endl; cout << "Usage is " << argv[0] << "indir outdir fname runmin runmax " << endl;
return 0; return 0;
} }
int ii=0;
int p=10000; int p=10000;
int fifosize=1000; int fifosize=1000;
int nthreads=1; int nthreads=5;
int nsubpix=25; int nsubpix=25;
int etabins=nsubpix*10; int etabins=nsubpix*10;
double etamin=-1, etamax=2; double etamin=-1, etamax=2;
@ -165,6 +166,14 @@ int main(int argc, char *argv[]) {
mt->popFree(buff); mt->popFree(buff);
ff=-1; ff=-1;
ii++;
if (ii%10000==0) {
cout << ii << endl;
while (mt->isBusy()) {;}//wait until all data are processed from the queues
mt->writeImage("/scratch/tmp.tiff");
}
} }
// cout << "--" << endl; // cout << "--" << endl;
filebin.close(); filebin.close();

View File

@ -0,0 +1,163 @@
//#include "ansi.h"
#include <iostream>
//#include "moench03T1ZmqData.h"
#include "moench03T1ReceiverDataNew.h"
// #include "interpolatingDetector.h"
//#include "etaInterpolationPosXY.h"
// #include "linearInterpolation.h"
// #include "noInterpolation.h"
//#include "interpolatingDetector.h"
#include <stdio.h>
#include <map>
#include <fstream>
#include <sys/stat.h>
#include <cstdlib>
#include <ctime>
using namespace std;
#define NX 400 //number of x pixels
#define NY 400 //number of y pixels
int main(int argc, char *argv[]) {
if (argc<6) {
cout << "Usage is " << argv[0] << "indir outdir fname runmin runmax " << endl;
return 1;
}
int p=10000;
int fifosize=1000;
int nthreads=8;
int nsubpix=25;
int etabins=nsubpix*10;
double etamin=-1, etamax=2;
int csize=3;
int nx=400, ny=400;
int save=1;
int nsigma=5;
int nped=1000;
int ndark=100;
int ok;
int iprog=0;
moench03T1ReceiverDataNew *decoder=new moench03T1ReceiverDataNew();
uint16_t data[NY*NX];
int size = 327680;////atoi(argv[3]);
int* image;
int ff, np;
int dsize=decoder->getDataSize();
//char data[dsize];
ifstream filebin;
char *indir=argv[1];
char *outdir=argv[2];
char *fformat=argv[3];
int runmin=atoi(argv[4]);
int runmax=atoi(argv[5]);
char fname[10000];
char outfname[10000];
char imgfname[10000];
char pedfname[10000];
// strcpy(pedfname,argv[6]);
char fn[10000];
std::time_t end_time;
FILE *of=NULL;
cout << "input directory is " << indir << endl;
cout << "output directory is " << outdir << endl;
cout << "fileformat is " << fformat << endl;
std::time(&end_time);
cout << std::ctime(&end_time) << endl;
char* buff;
int ifr=0;
for (int irun=runmin; irun<runmax; irun++) {
sprintf(fn,fformat,irun);
sprintf(fname,"%s/%s.raw",indir,fn);
sprintf(outfname,"%s/%s_image.raw",outdir,fn);
std::time(&end_time);
cout << std::ctime(&end_time) << endl;
cout << fname << " " << outfname << " " << imgfname << endl;
filebin.open((const char *)(fname), ios::in | ios::binary);
// //open file
if (filebin.is_open()){
of=fopen(outfname,"w");
if (of) {
;
} else {
cout << "Could not open "<< outfname << " for writing " << endl;
return 1;
}
// //while read frame
ff=-1;
while (decoder->readNextFrame(filebin, ff, np,buff)) {
for (int ix=0; ix<400; ix++)
for (int iy=0; iy<400; iy++)
data[iy*NX+ix]=decoder->getChannel(buff,ix,iy);
ifr++;
fwrite(&ff, 8, 1,of);//write detector frame number
fwrite(&ifr, 8, 1,of);//write datset frame number
fwrite(data,2,NX*NY,of);//write reordered data
if (ifr%10000==0) cout << ifr << " " << ff << endl;
ff=-1;
}
cout << "--" << endl;
filebin.close();
// //close file
// //join threads
if (of)
fclose(of);
std::time(&end_time);
cout << std::ctime(&end_time) << endl;
} else
cout << "Could not open "<< fname << " for reading " << endl;
}
return 0;
}

View File

@ -22,15 +22,19 @@ using namespace std;
#define SLS_DETECTOR_JSON_HEADER_VERSION 0x2 #define SLS_DETECTOR_JSON_HEADER_VERSION 0x2
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
/** /**
* trial.o [socket ip] [starting port number] [send_socket ip] [send port number] * trial.o [socket ip] [starting port number] [send_socket ip] [send port number]
* *
*/ */
FILE *of=NULL; FILE *of=NULL;
int fifosize=1000; int fifosize=1000;
int nthreads=20; int nthreads=20;
int nsubpixels=2; int int_ready=0;
int ok;
// 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]\n"); cprintf(RED, "Help: ./trial [receive socket ip] [receive starting port number] [send_socket ip] [send starting port number]\n");
@ -58,6 +62,10 @@ int main(int argc, char *argv[]) {
"\nsd port num : " << portnum2; "\nsd port num : " << portnum2;
} }
cout << endl; cout << endl;
int nsubpixels=2;
if (argc > 5) {
nsubpixels=atoi(argv[5]);
}
//slsDetectorData *det=new moench03T1ZmqDataNew(); //slsDetectorData *det=new moench03T1ZmqDataNew();
int npx, npy; int npx, npy;
moench03T1ZmqDataNew *det=new moench03T1ZmqDataNew(); moench03T1ZmqDataNew *det=new moench03T1ZmqDataNew();
@ -70,7 +78,8 @@ int main(int argc, char *argv[]) {
char* buff; char* buff;
multiThreadedAnalogDetector *mt=new multiThreadedAnalogDetector(filter,nthreads,fifosize); multiThreadedAnalogDetector *mt=new multiThreadedAnalogDetector(filter,nthreads,fifosize);
mt->setFrameMode(eFrame); int frameMode=eFrame;
mt->setFrameMode(frameMode);
mt->StartThreads(); mt->StartThreads();
mt->popFree(buff); mt->popFree(buff);
@ -113,6 +122,9 @@ int main(int argc, char *argv[]) {
uint32_t subframeIndex = -1; uint32_t subframeIndex = -1;
uint64_t fileindex = -1; uint64_t fileindex = -1;
string filename = ""; string filename = "";
char ffname[10000];
int ffindex;
char* image = new char[size]; char* image = new char[size];
//int* image = new int[(size/sizeof(int))](); //int* image = new int[(size/sizeof(int))]();
@ -139,35 +151,42 @@ int main(int argc, char *argv[]) {
// cprintf(RED, "Got Dummy\n"); // cprintf(RED, "Got Dummy\n");
while (mt->isBusy()) {;}//wait until all data are processed from the queues while (mt->isBusy()) {;}//wait until all data are processed from the queues
if (frameMode==eFrame) {
detimage=mt->getImage(nix,niy,nis); detimage=mt->getImage(nix,niy,nis);
if (detimage) { if (detimage) {
for (ix=0; ix<nnx; ix++) { for (ix=0; ix<nnx/nis; ix++) {
for (iy=0; iy<nny; iy++) { for (iy=0; iy<nny/nis; iy++) {
dout[iy*nnx+ix]=0; dout[iy*nnx+ix]=0;
for (isx=0; isx<nis; isx++) { for (isx=0; isx<nis; isx++) {
for (isy=0; isy<nis; isy++) { for (isy=0; isy<nis; isy++) {
dout[iy*nnx+ix]+=detimage[(iy+isy)*nix+(ix+isx)]; dout[iy*nnx+ix]+=detimage[(iy+isy)*nix+(ix+isx)];
// if (detimage[(iy+isy)*nix+(ix+isx)]) cout << ix << " " << iy << " " << isx << " " << isy << " " << detimage[(iy+isy)*nix+(ix+isx)] << " " << dout[iy*nnx+ix] << endl;
} }
} }
} }
}
if (send) {
strcpy(fname,filename.c_str());
// zmqsocket2->SendHeaderData(0, false, SLS_DETECTOR_JSON_HEADER_VERSION,16,fileindex,400,400,400*400, acqIndex,frameIndex,fname, acqIndex, 0,0,0,0,0,0,0,0,0,0,0,1);
zmqsocket2->SendHeaderData(0, false, SLS_DETECTOR_JSON_HEADER_VERSION,0,0,0,0,0, 0,0,fname, 0, 0,0,0,0,0,0,0,0,0,0,0,1);
zmqsocket2->SendData((char*)dout,length);
cprintf(GREEN, "Sent Data\n");
} }
sprintf(ofname,"%s_%d.tiff",filename.c_str(),fileindex);
mt->writeImage(ofname);
} }
}
if (send) {
strcpy(fname,filename.c_str());
// zmqsocket2->SendHeaderData(0, false, SLS_DETECTOR_JSON_HEADER_VERSION,16,fileindex,400,400,400*400, acqIndex,frameIndex,fname, acqIndex, 0,0,0,0,0,0,0,0,0,0,0,1);
zmqsocket2->SendHeaderData(0, false, SLS_DETECTOR_JSON_HEADER_VERSION,0,0,0,0,0, 0,0,fname, 0, 0,0,0,0,0,0,0,0,0,0,0,1);
zmqsocket2->SendData((char*)dout,length);
cprintf(GREEN, "Sent Data\n");
}
sprintf(ofname,"%s_%d.tiff",ffname,ffindex);
if (frameMode==eFlat)
mt->writeFlatField(ofname);
else if (frameMode==ePedestal)
mt->writePedestal(ofname);
else
mt->writeImage(ofname);
// stream dummy to socket2 to signal end of acquisition // stream dummy to socket2 to signal end of acquisition
if (send) { if (send) {
zmqsocket2->SendHeaderData(0, true, SLS_DETECTOR_JSON_HEADER_VERSION); zmqsocket2->SendHeaderData(0, true, SLS_DETECTOR_JSON_HEADER_VERSION);
@ -184,7 +203,8 @@ int main(int argc, char *argv[]) {
} }
if (of==NULL) { if (of==NULL) {
while (mt->isBusy()) {;}
sprintf(ofname,"%s_%d.clust",filename.c_str(),fileindex); sprintf(ofname,"%s_%d.clust",filename.c_str(),fileindex);
of=fopen(ofname,"w"); of=fopen(ofname,"w");
if (of) { if (of) {
@ -193,6 +213,32 @@ int main(int argc, char *argv[]) {
cout << "Could not open "<< ofname << " for writing " << endl; cout << "Could not open "<< ofname << " for writing " << endl;
mt->setFilePointer(NULL); mt->setFilePointer(NULL);
} }
ffindex=fileindex;
strcpy(ffname,filename.c_str());
if (filename.find("flat")!=std::string::npos) {
cout << "add to ff" << endl;
frameMode=eFlat;//ePedestal;
int_ready=0;
} else if (filename.find("newped")!=std::string::npos) {
frameMode=ePedestal;
cout << "new pedestal" << endl;
mt->newDataSet();
} else if (filename.find("ped")!=std::string::npos){
frameMode=ePedestal;
cout << "pedestal" << endl;
} else {
frameMode=eFrame;
cout << "data" << endl;
if (int_ready==0) {
mt->prepareInterpolation(ok);
cout << "prepare interpolation " << endl;
int_ready=1;
}
}
mt->setFrameMode(frameMode);
} }
// get data // get data

View File

@ -50,7 +50,7 @@ public:
virtual int setFrameMode(int fm) {fMode=fm; if (fMode>=0) det->setFrameMode((frameMode)fMode);}; virtual int setFrameMode(int fm) {fMode=fm; if (fMode>=0) det->setFrameMode((frameMode)fMode);};
virtual void newDataSet(){det->newDataSet();};
//fMode=fm; return fMode;} //fMode=fm; return fMode;}
/* void prepareInterpolation(int &ok) { */ /* void prepareInterpolation(int &ok) { */
@ -235,6 +235,7 @@ public:
int setFrameMode(int fm) { int ret; for (int i=0; i<nThreads; i++) ret=dets[i]->setFrameMode(fm); return ret;}; int setFrameMode(int fm) { int ret; for (int i=0; i<nThreads; i++) ret=dets[i]->setFrameMode(fm); return ret;};
void newDataSet(){for (int i=0; i<nThreads; i++) dets[i]->newDataSet();};
int *getImage(int &nnx, int &nny, int &ns) { int *getImage(int &nnx, int &nny, int &ns) {
int *img; int *img;
// int nnx, nny, ns; // int nnx, nny, ns;
@ -242,13 +243,14 @@ public:
//for (i=0; i<nn; i++) image[i]=0; //for (i=0; i<nn; i++) image[i]=0;
for (int ii=0; ii<nThreads; ii++) { for (int ii=0; ii<nThreads; ii++) {
// cout << ii << " " << dets[ii]->getImageSize(nnx, nny, ns) << " " << nnx << " " << nny << " " << ns << endl; //cout << ii << " " << nn << " " << nnx << " " << nny << " " << ns << endl;
img=dets[ii]->getImage(); img=dets[ii]->getImage();
for (int i=0; i<nn; i++) { for (int i=0; i<nn; i++) {
if (ii==0) if (ii==0)
image[i]=img[i]; image[i]=img[i];
else else
image[i]+=img[i]; image[i]+=img[i];
//if (img[i]) cout << "det " << ii << " pix " << i << " val " << img[i] << " " << image[i] << endl;
} }
} }
@ -280,8 +282,8 @@ public:
float *gm=new float[nn]; float *gm=new float[nn];
if (gm) { if (gm) {
for (int ix=0; ix<nn; ix++) { for (int ix=0; ix<nn; ix++) {
// if (image[ix]>0) cout << ix << " " << image[ix]<< endl;
gm[ix]=image[ix]; gm[ix]=image[ix];
// if (image[ix]>0 && ix/nnx<350) cout << ix/nnx << " " << ix%nnx << " " << image[ix]<< " " << gm[ix] << endl;
} }
//cout << "image " << nnx << " " << nny << endl; //cout << "image " << nnx << " " << nny << endl;
WriteToTiff(gm,imgname ,nnx, nny); WriteToTiff(gm,imgname ,nnx, nny);
@ -403,7 +405,7 @@ public:
} else cout << "Could not allocate float image " << endl; } else cout << "Could not allocate float image " << endl;
} }
} else } else
cout << "Not interpolating detector! " << endl; cout << "Detector without flat field! " << endl;
return NULL; return NULL;

View File

@ -187,10 +187,10 @@ public analogDetector<uint16_t> {
double g=1.; double g=1.;
double tthr=thr; double tthr=thr, tthr1, tthr2;
int nn=0; int nn=0;
double max=0, tl=0, tr=0, bl=0,br=0, v; double max=0, tl=0, tr=0, bl=0,br=0, v;
double rms=0;
int cm=0; int cm=0;
if (cmSub) cm=1; if (cmSub) cm=1;
@ -240,56 +240,62 @@ public analogDetector<uint16_t> {
tot=0; tot=0;
quadTot=0; quadTot=0;
for (int ir=-(clusterSizeY/2); ir<(clusterSizeY/2)+1; ir++) { if (rest[iy][ix]>0.25*tthr) {
for (int ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) { eventMask[iy][ix]=NEIGHBOUR;
if ((iy+ir)>=0 && (iy+ir)<ny && (ix+ic)>=0 && (ix+ic)<nx) { for (int ir=-(clusterSizeY/2); ir<(clusterSizeY/2)+1; ir++) {
//clusters->set_data(rest[iy+ir][ix+ic], ic, ir); for (int ic=-(clusterSize/2); ic<(clusterSize/2)+1; ic++) {
if ((iy+ir)>=0 && (iy+ir)<ny && (ix+ic)>=0 && (ix+ic)<nx) {
//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][ix+ic];//clusters->get_data(ic,ir);
tot+=v; tot+=v;
if (ir<=0 && ic<=0) if (ir<=0 && ic<=0)
bl+=v; bl+=v;
if (ir<=0 && ic>=0) if (ir<=0 && ic>=0)
br+=v; br+=v;
if (ir>=0 && ic<=0) if (ir>=0 && ic<=0)
tl+=v; tl+=v;
if (ir>=0 && ic>=0) if (ir>=0 && ic>=0)
tr+=v; tr+=v;
if (v>max) { if (v>max) {
max=v; max=v;
}
// if (ir==0 && ic==0) {
if (v>tthr) {
eventMask[iy][ix]=NEIGHBOUR;
} }
// if (ir==0 && ic==0) {
//} //}
}
} }
} }
}
if (rest[iy][ix]>=max) { if (rest[iy][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;
} else if (br>=bl && br>=tl && br>=tr) { } else if (br>=bl && br>=tl && br>=tr) {
quad=BOTTOM_RIGHT; quad=BOTTOM_RIGHT;
quadTot=br; quadTot=br;
} else if (tl>=br && tl>=bl && tl>=tr) { } else if (tl>=br && tl>=bl && tl>=tr) {
quad=TOP_LEFT; quad=TOP_LEFT;
quadTot=tl; quadTot=tl;
} else if (tr>=bl && tr>=tl && tr>=br) { } else if (tr>=bl && tr>=tl && tr>=br) {
quad=TOP_RIGHT; quad=TOP_RIGHT;
quadTot=tr; quadTot=tr;
}
rms=getPedestalRMS(ix,iy);
tthr1=tthr-sqrt(ccy*ccs)*rms;
tthr2=tthr-sqrt(cy*cs)*rms;
if (tthr>sqrt(ccy*ccs)*rms) tthr1=tthr-sqrt(ccy*ccs)*rms; else tthr1=sqrt(ccy*ccs)*rms;
if (tthr>sqrt(cy*cs)*rms) tthr2=tthr-sqrt(cy*cs)*rms; else tthr2=sqrt(cy*cs)*rms;
if (tot>tthr1 || quadTot>tthr2) {
eventMask[iy][ix]=PHOTON;
nph[ix+nx*iy]++;
nphFrame++;
nphTot++;
}
} }
if (max>tthr || tot>sqrt(ccy*ccs)*tthr || quadTot>sqrt(cy*cs)*tthr) {
eventMask[iy][ix]=PHOTON;
nph[ix+nx*iy]++;
nphFrame++;
nphTot++;
}
} }
} }
} }

View File

@ -104,7 +104,7 @@ void qTabSettings::SetupDetectorSettings(){
int sett = (int)myDet->getSettings();cout<<"sett:"<<sett<<endl; int sett = (int)myDet->getSettings();cout<<"sett:"<<sett<<endl;
qDefs::checkErrorMessage(myDet,"qTabSettings::SetupDetectorSettings"); qDefs::checkErrorMessage(myDet,"qTabSettings::SetupDetectorSettings");
if(sett==-1) sett = Undefined; if(sett==-1) sett = Undefined;
if(detType == slsDetectorDefs::JUNGFRAUCTB && sett > slsDetectorDefs::UNDEFINED) sett = Uninitialized; if(detType == slsDetectorDefs::JUNGFRAUCTB) sett = Uninitialized;
else if(sett == slsDetectorDefs::UNDEFINED) sett = Undefined; else if(sett == slsDetectorDefs::UNDEFINED) sett = Undefined;
else if(sett == slsDetectorDefs::UNINITIALIZED) sett = Uninitialized; else if(sett == slsDetectorDefs::UNINITIALIZED) sett = Uninitialized;
// To be able to index items on a combo box // To be able to index items on a combo box
@ -186,7 +186,7 @@ void qTabSettings::SetupDetectorSettings(){
default: default:
cout << "Unknown detector type. Exiting GUI." << endl; cout << "Unknown detector type. Exiting GUI." << endl;
qDefs::Message(qDefs::CRITICAL,"Unknown detector type. Exiting GUI.","qTabSettings::SetupDetectorSettings"); qDefs::Message(qDefs::CRITICAL,"Unknown detector type. Exiting GUI.","qTabSettings::SetupDetectorSettings");
exit(-1); exit(-1);
break; break;
} }
// detector settings selected NOT ENABLED. // detector settings selected NOT ENABLED.
@ -197,7 +197,8 @@ void qTabSettings::SetupDetectorSettings(){
#ifdef VERBOSE #ifdef VERBOSE
cout << "ERROR: Unknown Detector Settings retrieved from detector." << endl; cout << "ERROR: Unknown Detector Settings retrieved from detector." << endl;
#endif #endif
exit(-1); sett= Undefined;
// exit(-1);
} }
// Setting the detector settings // Setting the detector settings
else comboSettings->setCurrentIndex(sett); else comboSettings->setCurrentIndex(sett);

View File

@ -0,0 +1,141 @@
#ifndef AD9257_H
#define AD9257_H
#include "ansi.h"
#include "commonServerFunctions.h"
#include <stdio.h>
/* AD9257 ADC DEFINES */
#define AD9257_ADC_NUMBITS (24)
#define AD9257_DEV_IND_2_REG (0x04)
#define AD9257_CHAN_H_OFST (0)
#define AD9257_CHAN_H_MSK (0x00000001 << AD9257_CHAN_H_OFST)
#define AD9257_CHAN_G_OFST (1)
#define AD9257_CHAN_G_MSK (0x00000001 << AD9257_CHAN_G_OFST)
#define AD9257_CHAN_F_OFST (2)
#define AD9257_CHAN_F_MSK (0x00000001 << AD9257_CHAN_F_OFST)
#define AD9257_CHAN_E_OFST (3)
#define AD9257_CHAN_E_MSK (0x00000001 << AD9257_CHAN_E_OFST)
#define AD9257_DEV_IND_1_REG (0x05)
#define AD9257_CHAN_D_OFST (0)
#define AD9257_CHAN_D_MSK (0x00000001 << AD9257_CHAN_D_OFST)
#define AD9257_CHAN_C_OFST (1)
#define AD9257_CHAN_C_MSK (0x00000001 << AD9257_CHAN_C_OFST)
#define AD9257_CHAN_B_OFST (2)
#define AD9257_CHAN_B_MSK (0x00000001 << AD9257_CHAN_B_OFST)
#define AD9257_CHAN_A_OFST (3)
#define AD9257_CHAN_A_MSK (0x00000001 << AD9257_CHAN_A_OFST)
#define AD9257_CLK_CH_DCO_OFST (4)
#define AD9257_CLK_CH_DCO_MSK (0x00000001 << AD9257_CLK_CH_DCO_OFST)
#define AD9257_CLK_CH_IFCO_OFST (5)
#define AD9257_CLK_CH_IFCO_MSK (0x00000001 << AD9257_CLK_CH_IFCO_OFST)
#define AD9257_POWER_MODE_REG (0x08)
#define AD9257_POWER_INTERNAL_OFST (0)
#define AD9257_POWER_INTERNAL_MSK (0x00000003 << AD9257_POWER_INTERNAL_OFST)
#define AD9257_INT_RESET_VAL (0x3)
#define AD9257_INT_CHIP_RUN_VAL (0x0)
#define AD9257_POWER_EXTERNAL_OFST (5)
#define AD9257_POWER_EXTERNAL_MSK (0x00000001 << AD9257_POWER_EXTERNAL_OFST)
#define AD9257_EXT_FULL_POWER_VAL (0x0)
#define AD9257_EXT_STANDBY_VAL (0x1)
#define AD9257_OUT_MODE_REG (0x14)
#define AD9257_OUT_FORMAT_OFST (0)
#define AD9257_OUT_FORMAT_MSK (0x00000001 << AD9257_OUT_FORMAT_OFST)
#define AD9257_OUT_BINARY_OFST_VAL (0)
#define AD9257_OUT_TWOS_COMPL_VAL (1)
#define AD9257_OUT_LVDS_OPT_OFST (6)
#define AD9257_OUT_LVDS_OPT_MSK (0x00000001 << AD9257_OUT_LVDS_OPT_OFST)
#define AD9257_OUT_LVDS_ANSI_VAL (0)
#define AD9257_OUT_LVDS_IEEE_VAL (1)
#define AD9257_OUT_PHASE_REG (0x16)
#define AD9257_OUT_CLK_OFST (0)
#define AD9257_OUT_CLK_MSK (0x0000000F << AD9257_OUT_CLK_OFST)
#define AD9257_OUT_CLK_60_VAL (0x1)
#define AD9257_IN_CLK_OFST (4)
#define AD9257_IN_CLK_MSK (0x00000007 << AD9257_IN_CLK_OFST)
#define AD9257_IN_CLK_0_VAL (0x0)
#define AD9257_VREF_REG (0x18)
#define AD9257_VREF_OFST (0)
#define AD9257_VREF_MSK (0x00000003 << AD9257_VREF_OFST)
#define AD9257_VREF_1_33_VAL (0x2)
#define AD9257_TEST_MODE_REG (0x0D)
#define AD9257_OUT_TEST_OFST (0)
#define AD9257_OUT_TEST_MSK (0x0000000F << AD9257_OUT_TEST_OFST)
#define AD9257_NONE_VAL (0x0)
#define AD9257_MIXED_BIT_FREQ_VAL (0xC)
#define AD9257_TEST_RESET_SHORT_GEN (4)
#define AD9257_TEST_RESET_LONG_GEN (5)
#define AD9257_USER_IN_MODE_OFST (6)
#define AD9257_USER_IN_MODE_MSK (0x00000003 << AD9257_USER_IN_MODE_OFST)
void setAdc(int addr, int val) {
u_int32_t codata;
codata = val + (addr << 8);
printf(" Setting ADC SPI Register. Wrote 0x%04x at 0x%04x\n", val, addr);
serializeToSPI(ADC_SPI_REG, codata, ADC_SERIAL_CS_OUT_MSK, AD9257_ADC_NUMBITS,
ADC_SERIAL_CLK_OUT_MSK, ADC_SERIAL_DATA_OUT_MSK, ADC_SERIAL_DATA_OUT_OFST);
}
void prepareADC(){
printf("\n\nPreparing ADC ... \n");
//power mode reset
printf("power mode reset:\n");
setAdc(AD9257_POWER_MODE_REG,
(AD9257_INT_RESET_VAL << AD9257_POWER_INTERNAL_OFST) & AD9257_POWER_INTERNAL_MSK);
//power mode chip run
printf("power mode chip run:\n");
setAdc(AD9257_POWER_MODE_REG,
(AD9257_INT_CHIP_RUN_VAL << AD9257_POWER_INTERNAL_OFST) & AD9257_POWER_INTERNAL_MSK);
//output clock phase
printf("output clock phase:\n");
setAdc(AD9257_OUT_PHASE_REG,
(AD9257_OUT_CLK_60_VAL << AD9257_OUT_CLK_OFST) & AD9257_OUT_CLK_MSK);
// lvds-iee reduced , binary offset
printf("lvds-iee reduced, binary offset:\n");
setAdc(AD9257_OUT_MODE_REG,
(AD9257_OUT_LVDS_IEEE_VAL << AD9257_OUT_LVDS_OPT_OFST) & AD9257_OUT_LVDS_OPT_MSK);
// all devices on chip to receive next command
printf("all devices on chip to receive next command:\n");
setAdc(AD9257_DEV_IND_2_REG,
AD9257_CHAN_H_MSK | AD9257_CHAN_G_MSK | AD9257_CHAN_F_MSK | AD9257_CHAN_E_MSK);
setAdc(AD9257_DEV_IND_1_REG,
AD9257_CHAN_D_MSK | AD9257_CHAN_C_MSK | AD9257_CHAN_B_MSK | AD9257_CHAN_A_MSK |
AD9257_CLK_CH_DCO_MSK | AD9257_CLK_CH_IFCO_MSK);
// vref 1.33
printf("vref 1.33:\n");
setAdc(AD9257_VREF_REG,
(AD9257_VREF_1_33_VAL << AD9257_VREF_OFST) & AD9257_VREF_MSK);
// no test mode
printf("no test mode:\n");
setAdc(AD9257_TEST_MODE_REG,
(AD9257_NONE_VAL << AD9257_OUT_TEST_OFST) & AD9257_OUT_TEST_MSK);
#ifdef TESTADC
printf("***************************************** *******\n");
printf("******* PUTTING ADC IN TEST MODE!!!!!!!!! *******\n");
printf("***************************************** *******\n");
// mixed bit frequency test mode
printf("mixed bit frequency test mode:\n");
setAdc(AD9257_TEST_MODE_REG,
(AD9257_MIXED_BIT_FREQ_VAL << AD9257_OUT_TEST_OFST) & AD9257_OUT_TEST_MSK);
#endif
}
#endif //AD9257_H

View File

@ -6,10 +6,10 @@
CROSS = bfin-uclinux- CROSS = bfin-uclinux-
CC = $(CROSS)gcc CC = $(CROSS)gcc
CFLAGS += -Wall -DMOENCHD -DMCB_FUNCS -DDACS_INT -DDEBUG -DV1 -DCTB #-DVERBOSE #-DVERYVERBOSE #-DVIRTUAL #-DDACS_INT_CSERVER CFLAGS += -Wall -DMOENCHD -DMCB_FUNCS -DDACS_INT -DDEBUG -DV1 -DCTB -DOLDVERSION #-DVERBOSE #-DVERYVERBOSE #-DVIRTUAL #-DDACS_INT_CSERVER
PROGS= jctbDetectorServer PROGS= jctbDetectorServer
INSTDIR= /tftpboot INSTDIR= /tftpboot
INSTMODE= 0777 INSTMODE= 0777
@ -31,10 +31,14 @@ boot: $(OBJS)
versioning: versioning:
@echo `tput setaf 6; ./updateGitVersion.sh; tput sgr0;` @echo `tput setaf 6; ./updateGitVersion.sh; tput sgr0;`
jctbDetectorServer: $(OBJS) jctbDetectorServerNew: $(OBJS)
echo $(OBJS) echo $(OBJS)
$(CC) $(CFLAGS) -o $@ $^ $(LDLIBS_$@) $(LDFLAGS_$@) $(CC) $(CFLAGS) -o $@ $^ $(LDLIBS_$@) $(LDFLAGS_$@)
jctbDetectorServer: $(OBJS)
echo $(OBJS)
$(CC) $(CFLAGS) -o $@ $^ $(LDLIBS_$@) $(LDFLAGS_$@) -DOLDVERSION
jungfrauADCTEst: $(OBJS) jungfrauADCTEst: $(OBJS)
echo $(OBJS) echo $(OBJS)
$(CC) $(CFLAGS) -o $@ $^ $(LDLIBS_$@) $(LDFLAGS_$@) -DTESTADC $(CC) $(CFLAGS) -o $@ $^ $(LDLIBS_$@) $(LDFLAGS_$@) -DTESTADC

View File

@ -2,9 +2,13 @@
#define BLACKFIN_H #define BLACKFIN_H
#define CSP0 0x20200000 #define CSP0 0x20200000
#define MEM_SIZE 0x100000 #define MEM_SIZE 0x100000
#ifndef OLDVERSION
#define MEM_MAP_SHIFT 1 #define MEM_MAP_SHIFT 1
#endif
#ifdef OLDVERSION
#define MEM_MAP_SHIFT 11
#endif
#include <sys/types.h> #include <sys/types.h>
int mapCSP0(void); int mapCSP0(void);

View File

@ -0,0 +1,73 @@
#ifndef COMMON_SERVER_FUNCTIONS_H
#define COMMON_SERVER_FUNCTIONS_H
#ifndef GOTTHARDD //gotthard already had bus_w etc defined in its firmware_funcs.c (not yet made with common files)
#include "blackfin.h"
#endif
/* global variables */
void SPIChipSelect (u_int32_t* valw, u_int32_t addr, u_int32_t csmask) {
// start point
(*valw) = 0xffffffff; // old board compatibility (not using specific bits)
bus_w (addr, (*valw));
// chip sel bar down
(*valw) &= ~csmask; /* todo with test: done a bit different, not with previous value */
bus_w (addr, (*valw));
}
void SPIChipDeselect (u_int32_t* valw, u_int32_t addr, u_int32_t csmask, u_int32_t clkmask) {
// chip sel bar up
(*valw) |= csmask; /* todo with test: not done for spi */
bus_w (addr, (*valw));
//clk down
(*valw) &= ~clkmask;
bus_w (addr, (*valw));
// stop point = start point of course
(*valw) = 0xffffffff; // old board compatibility (not using specific bits)
bus_w (addr, (*valw));
}
void sendDataToSPI (u_int32_t* valw, u_int32_t addr, u_int32_t val, int numbitstosend, u_int32_t clkmask, u_int32_t digoutmask, int digofset) {
int i = 0;
for (i = 0; i < numbitstosend; ++i) {
// clk down
(*valw) &= ~clkmask;
bus_w (addr, (*valw));
// write data (i)
(*valw) = (((*valw) & ~digoutmask) + // unset bit
(((val >> (numbitstosend - 1 - i)) & 0x1) << digofset)); // each bit from val starting from msb
bus_w (addr, (*valw));
// clk up
(*valw) |= clkmask ;
bus_w (addr, (*valw));
}
}
void serializeToSPI(u_int32_t addr, u_int32_t val, u_int32_t csmask, int numbitstosend, u_int32_t clkmask, u_int32_t digoutmask, int digofset) {
#ifdef VERBOSE
if (numbitstosend == 16)
printf("Writing to SPI Register: 0x%04x\n",val);
else
printf("Writing to SPI Register: 0x%08x\n", val);
#endif
u_int32_t valw;
SPIChipSelect (&valw, addr, csmask);
sendDataToSPI(&valw, addr, val, numbitstosend, clkmask, digoutmask, digofset);
SPIChipDeselect(&valw, addr, csmask, clkmask);
}
#endif //COMMON_SERVER_FUNCTIONS_H

View File

@ -8,6 +8,16 @@
#include "mcb_funcs.h" #include "mcb_funcs.h"
#include "slow_adc.h" #include "slow_adc.h"
#include "registers_m.h" #include "registers_m.h"
#define ADC_SPI_REG ADC_WRITE_REG
#define ADC_SERIAL_CLK_OUT_OFST (0)
#define ADC_SERIAL_CLK_OUT_MSK (0x00000001 << ADC_SERIAL_CLK_OUT_OFST)
#define ADC_SERIAL_DATA_OUT_OFST (1)
#define ADC_SERIAL_DATA_OUT_MSK (0x00000001 << ADC_SERIAL_DATA_OUT_OFST)
#define ADC_SERIAL_CS_OUT_OFST (2)
#define ADC_SERIAL_CS_OUT_MSK (0x0000000F << ADC_SERIAL_CS_OUT_OFST)
#include "AD9257.h"
//#define VERBOSE //#define VERBOSE
//#define VERYVERBOSE //#define VERYVERBOSE
@ -1718,60 +1728,60 @@ int initConfGain(int isettings,int val,int imod){
int setADC(int adc){ /* int setADC(int adc){ */
/* int reg,nchips,mask,nchans; */ /* /\* int reg,nchips,mask,nchans; *\/ */
/* if(adc==-1) ROI_flag=0; */ /* /\* if(adc==-1) ROI_flag=0; *\/ */
/* else ROI_flag=1; */ /* /\* else ROI_flag=1; *\/ */
/* // setDAQRegister();//token timing */ /* /\* // setDAQRegister();//token timing *\/ */
/* cleanFifo();//adc sync */ /* /\* cleanFifo();//adc sync *\/ */
/* //with gotthard module */ /* /\* //with gotthard module *\/ */
/* if(withGotthard){ */ /* /\* if(withGotthard){ *\/ */
/* //set packet size */ /* /\* //set packet size *\/ */
/* ipPacketSize= DEFAULT_IP_PACKETSIZE; */ /* /\* ipPacketSize= DEFAULT_IP_PACKETSIZE; *\/ */
/* udpPacketSize=DEFAULT_UDP_PACKETSIZE; */ /* /\* udpPacketSize=DEFAULT_UDP_PACKETSIZE; *\/ */
/* //set channel mask */ /* /\* //set channel mask *\/ */
/* nchips = GOTTHARDNCHIP; */ /* /\* nchips = GOTTHARDNCHIP; *\/ */
/* nchans = GOTTHARDNCHAN; */ /* /\* nchans = GOTTHARDNCHAN; *\/ */
/* mask = ACTIVE_ADC_MASK; */ /* /\* mask = ACTIVE_ADC_MASK; *\/ */
/* } */ /* /\* } *\/ */
/* //with moench module all adc */ /* /\* //with moench module all adc *\/ */
/* else{/\* if(adc==-1){*\/ */ /* /\* else{/\\* if(adc==-1){*\\/ *\/ */
/* //set packet size */ /* /\* //set packet size *\/ */
/* ipPacketSize= DEFAULT_IP_PACKETSIZE; */ /* /\* ipPacketSize= DEFAULT_IP_PACKETSIZE; *\/ */
/* udpPacketSize=DEFAULT_UDP_PACKETSIZE; */ /* /\* udpPacketSize=DEFAULT_UDP_PACKETSIZE; *\/ */
/* //set channel mask */ /* /\* //set channel mask *\/ */
/* nchips = N_CHIP; */ /* /\* nchips = N_CHIP; *\/ */
/* nchans = N_CHANS; */ /* /\* nchans = N_CHANS; *\/ */
/* mask = ACTIVE_ADC_MASK; */ /* /\* mask = ACTIVE_ADC_MASK; *\/ */
/* }/\* */ /* /\* }/\\* *\/ */
/* //with moench module 1 adc -- NOT IMPLEMENTED */ /* /\* //with moench module 1 adc -- NOT IMPLEMENTED *\/ */
/* else{ */ /* /\* else{ *\/ */
/* ipPacketSize= ADC1_IP_PACKETSIZE; */ /* /\* ipPacketSize= ADC1_IP_PACKETSIZE; *\/ */
/* udpPacketSize=ADC1_UDP_PACKETSIZE; */ /* /\* udpPacketSize=ADC1_UDP_PACKETSIZE; *\/ */
/* //set channel mask */ /* /\* //set channel mask *\/ */
/* nchips = NCHIPS_PER_ADC; */ /* /\* nchips = NCHIPS_PER_ADC; *\/ */
/* nchans = GOTTHARDNCHAN; */ /* /\* nchans = GOTTHARDNCHAN; *\/ */
/* mask = 1<<adc; */ /* /\* mask = 1<<adc; *\/ */
/* }*\/ */ /* /\* }*\\/ *\/ */
/* //set channel mask */ /* /\* //set channel mask *\/ */
/* reg = (nchans*nchips)<<CHANNEL_OFFSET; */ /* /\* reg = (nchans*nchips)<<CHANNEL_OFFSET; *\/ */
/* reg&=CHANNEL_MASK; */ /* /\* reg&=CHANNEL_MASK; *\/ */
/* reg|=(ACTIVE_ADC_MASK & mask); */ /* /\* reg|=(ACTIVE_ADC_MASK & mask); *\/ */
/* bus_w(CHIP_OF_INTRST_REG,reg); */ /* /\* bus_w(CHIP_OF_INTRST_REG,reg); *\/ */
/* //#ifdef DDEBUG */ /* /\* //#ifdef DDEBUG *\/ */
/* printf("Chip of Interest Reg:%x\n",bus_r(CHIP_OF_INTRST_REG)); */ /* /\* printf("Chip of Interest Reg:%x\n",bus_r(CHIP_OF_INTRST_REG)); *\/ */
/* //#endif */ /* /\* //#endif *\/ */
/* adcConfigured = adc; */ /* /\* adcConfigured = adc; *\/ */
return adcConfigured; /* return adcConfigured; */
} /* } */
@ -2450,103 +2460,101 @@ int allocateRAM() {
int writeADC(int addr, int val) { int writeADC(int addr, int val) {
setAdc(addr,val);
u_int32_t valw,codata,csmask;
int i,cdx,ddx;
cdx=0; ddx=1;
csmask=0xfc; // 1111100
codata=val + (addr<< 8);
printf("***** ADC SPI WRITE TO REGISTER %04X value %04X\n",addr,val);
// start point
valw=0xff;
bus_w16(ADC_WRITE_REG,(valw));
//chip sel bar down
valw=((0xffffffff&(~csmask)));
bus_w16(ADC_WRITE_REG,valw);
for (i=0;i<24;i++) {
//cldwn
valw=valw&(~(0x1<<cdx));
bus_w16(ADC_WRITE_REG,valw);
// usleep(0);
//write data (i)
valw=(valw&(~(0x1<<ddx)))+(((codata>>(23-i))&0x1)<<ddx);
bus_w16(ADC_WRITE_REG,valw);
// usleep(0);
//clkup
valw=valw+(0x1<<cdx);
bus_w16(ADC_WRITE_REG,valw);
// usleep(0);
}
// stop point =start point
valw=valw&(~(0x1<<cdx));
// usleep(0);
valw=0xff;
bus_w16(ADC_WRITE_REG,(valw));
//usleep in between
// usleep(50000);
return OK; return OK;
/* u_int32_t valw,codata,csmask; */
/* int i,cdx,ddx; */
/* cdx=0; ddx=1; */
/* csmask=0xfc; // 1111100 */
/* codata=val + (addr<< 8); */
/* printf("***** ADC SPI WRITE TO REGISTER %04X value %04X\n",addr,val); */
/* // start point */
/* valw=0xff; */
/* bus_w16(ADC_WRITE_REG,(valw)); */
/* //chip sel bar down */
/* valw=((0xffffffff&(~csmask))); */
/* bus_w16(ADC_WRITE_REG,valw); */
/* for (i=0;i<24;i++) { */
/* //cldwn */
/* valw=valw&(~(0x1<<cdx)); */
/* bus_w16(ADC_WRITE_REG,valw); */
/* // usleep(0); */
/* //write data (i) */
/* valw=(valw&(~(0x1<<ddx)))+(((codata>>(23-i))&0x1)<<ddx); */
/* bus_w16(ADC_WRITE_REG,valw); */
/* // usleep(0); */
/* //clkup */
/* valw=valw+(0x1<<cdx); */
/* bus_w16(ADC_WRITE_REG,valw); */
/* // usleep(0); */
/* } */
/* // stop point =start point */
/* valw=valw&(~(0x1<<cdx)); */
/* // usleep(0); */
/* valw=0xff; */
/* bus_w16(ADC_WRITE_REG,(valw)); */
/* //usleep in between */
/* // usleep(50000); */
/* return OK; */
} }
int prepareADC(){ /* int prepareADC(){ */
printf("Preparing ADC\n"); /* printf("Preparing ADC\n"); */
u_int32_t codata,csmask; /* u_int32_t codata,csmask; */
int cdx,ddx; /* int cdx,ddx; */
cdx=0; ddx=1; /* cdx=0; ddx=1; */
csmask=0x7c; // 1111100 /* csmask=0x7c; // 1111100 */
/* #define ADCREG1 0x08 */ /* /\* #define ADCREG1 0x08 *\/ */
/* #define ADCREG2 0x14//20 */ /* /\* #define ADCREG2 0x14//20 *\/ */
/* #define ADCREG3 0x4 */ /* /\* #define ADCREG3 0x4 *\/ */
/* #define ADCREG4 0x5 */ /* /\* #define ADCREG4 0x5 *\/ */
codata=0; /* codata=0; */
writeADC(0x08,0x3);//reset /* writeADC(0x08,0x3);//reset */
writeADC(0x08,0x0);//run! /* writeADC(0x08,0x0);//run! */
writeADC(0x04,0xf);//all chans /* writeADC(0x04,0xf);//all chans */
writeADC(0x04,0x3f);//all chans /* writeADC(0x04,0x3f);//all chans */
// writeADC(0x16,0x4);//output clock phase /* // writeADC(0x16,0x4);//output clock phase */
// writeADC(0x18,0x4);// vref 1V /* // writeADC(0x18,0x4);// vref 1V */
// writeADC(0x14,0x0); /* // writeADC(0x14,0x0); */
writeADC(0x14,0x40);//lvds reduced range -- offset binary /* writeADC(0x14,0x40);//lvds reduced range -- offset binary */
writeADC(0xD,0x0);//no test mode /* writeADC(0xD,0x0);//no test mode */
#ifdef TESTADC /* #ifdef TESTADC */
////////////TEST ADC!!!!!!!!!! /* ////////////TEST ADC!!!!!!!!!! */
printf("***************************************** *******\n"); /* printf("***************************************** *******\n"); */
printf("******* PUTTING ADC IN TEST MODE!!!!!!!!! *******\n"); /* printf("******* PUTTING ADC IN TEST MODE!!!!!!!!! *******\n"); */
printf("***************************************** *******\n"); /* printf("***************************************** *******\n"); */
// writeADC(0xD,0x4);//ALTERNATING CHECKERBOARD /* // writeADC(0xD,0x4);//ALTERNATING CHECKERBOARD */
// writeADC(0xD,0x7);//ONE/ZERO WORD TOGGLE /* // writeADC(0xD,0x7);//ONE/ZERO WORD TOGGLE */
/* writeADC(0x19,0xf0);//user input */ /* /\* writeADC(0x19,0xf0);//user input *\/ */
/* writeADC(0x1A,0xf0);//user input */ /* /\* writeADC(0x1A,0xf0);//user input *\/ */
/* writeADC(0x1B,0x0f);//user input */ /* /\* writeADC(0x1B,0x0f);//user input *\/ */
/* writeADC(0x1C,0x0f);//user input */ /* /\* writeADC(0x1C,0x0f);//user input *\/ */
/* writeADC(0xD,0x48);//user input, alternate */ /* /\* writeADC(0xD,0x48);//user input, alternate *\/ */
/* //writeADC(0xD,0xA);//1xsync */ /* /\* //writeADC(0xD,0xA);//1xsync *\/ */
// writeADC(0xD,0xB);//1xbit high /* // writeADC(0xD,0xB);//1xbit high */
writeADC(0xD,0xC);//1xmixed frequqncy /* writeADC(0xD,0xC);//1xmixed frequqncy */
#endif /* #endif */
@ -2554,15 +2562,15 @@ int prepareADC(){
bus_w(ADC_LATCH_DISABLE_REG,0x0); // enable all ADCs /* bus_w(ADC_LATCH_DISABLE_REG,0x0); // enable all ADCs */
// bus_w(DAQ_REG,0x12); //adc pipeline=18 /* // bus_w(DAQ_REG,0x12); //adc pipeline=18 */
//bus_w(DAQ_REG,0xbbbbbbbb); /* //bus_w(DAQ_REG,0xbbbbbbbb); */
// bus_w(ADC_INVERSION_REG,0x1f6170c6); /* // bus_w(ADC_INVERSION_REG,0x1f6170c6); */
return OK; /* return OK; */
} /* } */
int clearRAM() { int clearRAM() {

View File

@ -81,7 +81,7 @@ int getTemperature(int tempSensor);
int initHighVoltage(int val,int imod); int initHighVoltage(int val,int imod);
int initConfGain(int isettings,int val,int imod); int initConfGain(int isettings,int val,int imod);
int setADC(int adc); //int setADC(int adc);
//int configureMAC(int ipad, long long int macad, long long int detectormacadd, int detipad, int ival, int udpport); //int configureMAC(int ipad, long long int macad, long long int detectormacadd, int detipad, int ival, int udpport);
int configureMAC(uint32_t destip,uint64_t destmac,uint64_t sourcemac,int detipad,int ival,uint32_t destport); int configureMAC(uint32_t destip,uint64_t destmac,uint64_t sourcemac,int detipad,int ival,uint32_t destport);
int getAdcConfigured(); int getAdcConfigured();
@ -160,7 +160,7 @@ int allocateRAM();
int writeADC(int addr, int val); int writeADC(int addr, int val);
int prepareADC(); //int prepareADC();

View File

@ -1,9 +1,9 @@
Path: slsDetectorsPackage/slsDetectorSoftware/jctbDetectorServer Path: slsDetectorsPackage/slsDetectorSoftware/jctbDetectorServer
URL: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git URL: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git
Repository Root: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git Repository Root: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git
Repsitory UUID: c35203ebfb35ba605eaff601ce46e4d29c1f5690 Repsitory UUID: 9ae128961675230ad322ff2867f1862dbe8566a7
Revision: 24 Revision: 25
Branch: developer Branch: developer
Last Changed Author: Anna_Bergamaschi Last Changed Author: Anna_Bergamaschi
Last Changed Rev: 3761 Last Changed Rev: 3764
Last Changed Date: 2018-04-27 14:46:10.176661554 +0200 ./server_funcs.h Last Changed Date: 2018-05-07 14:30:14.000000002 +0200 ./Makefile

View File

@ -1,6 +1,6 @@
#define GITURL "git@github.com:slsdetectorgroup/slsDetectorPackage.git" #define GITURL "git@github.com:slsdetectorgroup/slsDetectorPackage.git"
#define GITREPUUID "c35203ebfb35ba605eaff601ce46e4d29c1f5690" #define GITREPUUID "9ae128961675230ad322ff2867f1862dbe8566a7"
#define GITAUTH "Anna_Bergamaschi" #define GITAUTH "Anna_Bergamaschi"
#define GITREV 0x3761 #define GITREV 0x3764
#define GITDATE 0x20180427 #define GITDATE 0x20180507
#define GITBRANCH "developer" #define GITBRANCH "developer"