mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-11 04:17:15 +02:00
added patternGenerator and slsDteectorCalibration directory in order to compile the ctbGui
This commit is contained in:
123
slsDetectorCalibration/dataStructures/Mythen3_01_jctbData.h
Normal file
123
slsDetectorCalibration/dataStructures/Mythen3_01_jctbData.h
Normal file
@ -0,0 +1,123 @@
|
||||
#ifndef MYTHEN301JCTBDATA_H
|
||||
#define MYTHEN301JCTBDATA_H
|
||||
|
||||
|
||||
class mythen3_01_jctbData : public slsDetectorData<short unsigned int> {
|
||||
|
||||
|
||||
public:
|
||||
mythen3_01_jctbData( int nch=64*3,int dr=24, int off=5): slsDetectorData<short unsigned int>(64*3,1,dr*8*nch,NULL,NULL,NULL), dynamicRange(dr), serialOffset(off), frameNumber(0), numberOfCounters(nch) {};
|
||||
|
||||
virtual void getPixel(int ip, int &x, int &y) {x=-1; y=-1;};
|
||||
|
||||
virtual short unsigned int getChannel(char *data, int ix, int iy=0) {
|
||||
int ret=-1;
|
||||
short unsigned int *val=mythen03_frame(data,dynamicRange,numberOfCounters,serialOffset);
|
||||
if (ix>=0 && ix<numberOfCounters) ret=val[ix];
|
||||
delete [] val;
|
||||
return ret;
|
||||
};
|
||||
|
||||
virtual int getFrameNumber(char *buff) {return frameNumber;};
|
||||
|
||||
virtual char *findNextFrame(char *data, int &ndata, int dsize) {
|
||||
ndata=dsize;
|
||||
return data;
|
||||
}
|
||||
|
||||
virtual char *readNextFrame(ifstream &filebin) {
|
||||
char *data=NULL;
|
||||
if (filebin.is_open()) {
|
||||
data=new char[dataSize];
|
||||
filebin.read(data,dataSize);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
virtual short unsigned int **getData(char *ptr, int dsize=-1) {
|
||||
short unsigned int **val;
|
||||
val=new short unsigned int*[1];
|
||||
val[0]=mythen03_frame(ptr,dynamicRange,nx,serialOffset);
|
||||
return val;
|
||||
|
||||
}
|
||||
|
||||
|
||||
virtual short unsigned int* mythen03_frame(char *ptr, int dr=24, int nch=64*3, int off=5) {
|
||||
// off=0;
|
||||
int iarg;
|
||||
int64_t word, *wp;
|
||||
short unsigned int* val=new short unsigned int[nch];
|
||||
int bit[64];
|
||||
int nb=2;
|
||||
int ioff=0;
|
||||
int idr=0;
|
||||
int ib=0;
|
||||
int iw=0;
|
||||
int ii=0;
|
||||
bit[0]=19;
|
||||
bit[1]=8;
|
||||
idr=0;
|
||||
for (ib=0; ib<nch; ib++) {
|
||||
val[ib]=0;
|
||||
}
|
||||
wp=(int64_t*)ptr;
|
||||
|
||||
for (iw=0; iw<nch/nb; iw) {
|
||||
word=*wp;;
|
||||
if (ioff<off) {
|
||||
ioff++;
|
||||
cout <<"*";
|
||||
} else {
|
||||
|
||||
if (idr<16) {
|
||||
for (ib=0; ib<nb; ib++) {
|
||||
if (word&(1<<bit[ib])) {
|
||||
cout << "+" ;
|
||||
val[iw+nch/nb*(ib)]|=(1<<idr);
|
||||
} else {
|
||||
cout << "-" ;
|
||||
}
|
||||
}//end for()
|
||||
}
|
||||
|
||||
idr++;
|
||||
|
||||
|
||||
if (idr==dr) {
|
||||
idr=0;
|
||||
// cout << dec << " " << iw << " " << val[iw] << " " << val[iw+nch/2] << endl;
|
||||
cout <<dec << iw<<endl;
|
||||
iw++;
|
||||
}//end if()
|
||||
|
||||
}//end else()
|
||||
wp+=1;
|
||||
ii++;
|
||||
}//end for
|
||||
|
||||
cout << "M3.01 Decoded "<<ii << " samples"<< endl;
|
||||
cout << "M3.01 Should be "<< nch/nb*dr+off << " samples"<< endl;
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
virtual int setFrameNumber(int f=0) {if (f>=0) frameNumber=f; return frameNumber; };
|
||||
virtual int setDynamicRange(int d=-1) {if (d>0 && d<=24) dynamicRange=d; return dynamicRange;};
|
||||
virtual int setSerialOffset(int d=-1) {if (d>=0) serialOffset=d; return serialOffset;};
|
||||
virtual int setNumberOfCounters(int d=-1) {if (d>=0) numberOfCounters=d; return numberOfCounters;};
|
||||
|
||||
|
||||
private:
|
||||
|
||||
int dynamicRange;
|
||||
int serialOffset;
|
||||
int frameNumber;
|
||||
int numberOfCounters;
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
130
slsDetectorCalibration/dataStructures/Mythen3_02_jctbData.h
Normal file
130
slsDetectorCalibration/dataStructures/Mythen3_02_jctbData.h
Normal file
@ -0,0 +1,130 @@
|
||||
#ifndef MYTHEN302JCTBDATA_H
|
||||
#define MYTHEN302JCTBDATA_H
|
||||
|
||||
|
||||
#include "Mythen3_01_jctbData.h"
|
||||
//class mythen3_02_jctbData : public slsDetectorData<short unsigned int> {
|
||||
class mythen3_02_jctbData : public mythen3_01_jctbData {
|
||||
|
||||
|
||||
public:
|
||||
mythen3_02_jctbData( int nch=64*3,int dr=24, int off=5): mythen3_01_jctbData( nch,dr, off)
|
||||
//slsDetectorData<short unsigned int>(64*3,1,dr*8*nch,NULL,NULL,NULL), dynamicRange(dr), serialOffset(off), frameNumber(0), numberOfCounters(nch)
|
||||
{};
|
||||
|
||||
/* virtual void getPixel(int ip, int &x, int &y) {x=-1; y=-1;}; */
|
||||
|
||||
/* virtual short unsigned int getChannel(char *data, int ix, int iy=0) { */
|
||||
/* int ret=-1; */
|
||||
/* short unsigned int *val=mythen03_frame(data,dynamicRange,numberOfCounters,serialOffset); */
|
||||
/* if (ix>=0 && ix<numberOfCounters) ret=val[ix]; */
|
||||
/* delete [] val; */
|
||||
/* return ret; */
|
||||
/* }; */
|
||||
|
||||
/* virtual int getFrameNumber(char *buff) {return frameNumber;}; */
|
||||
|
||||
/* virtual char *findNextFrame(char *data, int &ndata, int dsize) { */
|
||||
/* ndata=dsize; */
|
||||
/* return data; */
|
||||
/* } */
|
||||
|
||||
/* virtual char *readNextFrame(ifstream &filebin) { */
|
||||
/* char *data=NULL; */
|
||||
/* if (filebin.is_open()) { */
|
||||
/* data=new char[dataSize]; */
|
||||
/* filebin.read(data,dataSize); */
|
||||
/* } */
|
||||
/* return data; */
|
||||
/* } */
|
||||
|
||||
/* virtual short unsigned int **getData(char *ptr, int dsize=-1) { */
|
||||
/* short unsigned int **val; */
|
||||
/* val=new short unsigned int*[1]; */
|
||||
/* val[0]=mythen03_frame(ptr,dynamicRange,nx,serialOffset); */
|
||||
/* return val; */
|
||||
|
||||
/* } */
|
||||
|
||||
|
||||
virtual short unsigned int* mythen03_frame(char *ptr, int dr=24, int nch=64*3, int off=5) {
|
||||
// off=0;
|
||||
int iarg;
|
||||
int64_t word, *wp;
|
||||
short unsigned int* val=new short unsigned int[nch];
|
||||
int bit[64];
|
||||
int nb=2;
|
||||
int ioff=0;
|
||||
int idr=0;
|
||||
int ib=0;
|
||||
int ich=0;
|
||||
int ii=0;
|
||||
int iw=0;
|
||||
bit[0]=17;//19;
|
||||
bit[1]=6;//8;
|
||||
idr=0;
|
||||
for (ib=0; ib<nch; ib++) {
|
||||
val[ib]=0;
|
||||
}
|
||||
wp=(int64_t*)ptr;
|
||||
|
||||
for (iw=0; iw<nch/nb; iw) {
|
||||
word=*wp;
|
||||
|
||||
if (ioff<off) {
|
||||
ioff++;
|
||||
cout <<"*";
|
||||
} else {
|
||||
|
||||
if (idr<16) {
|
||||
for (ib=0; ib<nb; ib++) {
|
||||
if (word&(1<<bit[ib])) {
|
||||
cout << "+" ;
|
||||
val[iw+nch/nb*(ib)]|=(1<<idr);
|
||||
} else {
|
||||
cout << "-" ;
|
||||
}
|
||||
// cout << iw+nch/nb*(ib)<< " " ;
|
||||
}//end for()
|
||||
}
|
||||
|
||||
idr++;
|
||||
|
||||
|
||||
if (idr==dr) {
|
||||
idr=0;
|
||||
// cout << dec << " " << iw << " " << val[iw] << " " << val[iw+nch/2] << endl;
|
||||
cout <<dec << iw<<endl;
|
||||
iw++;
|
||||
}//end if()
|
||||
|
||||
}//end else()
|
||||
wp+=1;
|
||||
ii++;
|
||||
}//end for
|
||||
|
||||
cout << "M3.02 Decoded "<<ii << " samples"<< endl;
|
||||
cout << "M3.02 Should be "<< nch/nb*dr+off << " samples"<< endl;
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
/* virtual int setFrameNumber(int f=0) {if (f>=0) frameNumber=f; return frameNumber; }; */
|
||||
/* virtual int setDynamicRange(int d=-1) {if (d>0 && d<=24) dynamicRange=d; return dynamicRange;}; */
|
||||
/* virtual int setSerialOffset(int d=-1) {if (d>=0) serialOffset=d; return serialOffset;}; */
|
||||
/* virtual int setNumberOfCounters(int d=-1) {if (d>=0) numberOfCounters=d; return numberOfCounters;}; */
|
||||
|
||||
|
||||
/* private: */
|
||||
|
||||
/* int dynamicRange; */
|
||||
/* int serialOffset; */
|
||||
/* int frameNumber; */
|
||||
/* int numberOfCounters; */
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
63
slsDetectorCalibration/dataStructures/adcSar2_jctbData.h
Normal file
63
slsDetectorCalibration/dataStructures/adcSar2_jctbData.h
Normal file
@ -0,0 +1,63 @@
|
||||
#ifndef ADCSAR2_JCTBDATA_H
|
||||
#define ADCSAR2_JCTBDATA_H
|
||||
|
||||
|
||||
class adcSar2_jctbData : public slsDetectorData<short unsigned int> {
|
||||
|
||||
|
||||
public:
|
||||
adcSar2_jctbData(int nsamples=1000): slsDetectorData<short unsigned int>(nsamples,1,nsamples*8,NULL,NULL,NULL){};
|
||||
|
||||
virtual void getPixel(int ip, int &x, int &y) {x=ip/8; y=1;};
|
||||
|
||||
virtual short unsigned int getChannel(char *data, int ix, int iy=0) {
|
||||
int adcvalue=0;
|
||||
int vv1= *((int16_t*) (data+8*ix));
|
||||
int vv2= *((int16_t*) (data+8*ix+2));
|
||||
for (int jj=0;jj<8;jj++){
|
||||
adcvalue=adcvalue+ (((vv1>>(jj*2)) & 0x1)<<(jj));
|
||||
}
|
||||
for (int jj=0;jj<4;jj++){
|
||||
adcvalue=adcvalue+ (((vv2>>(jj*2)) & 0x1)<<(jj+8));
|
||||
}
|
||||
return adcvalue;
|
||||
};
|
||||
|
||||
virtual int getFrameNumber(char *buff) {return frameNumber;};
|
||||
|
||||
virtual char *findNextFrame(char *data, int &ndata, int dsize) {
|
||||
ndata=dsize;
|
||||
return data;
|
||||
}
|
||||
|
||||
virtual char *readNextFrame(ifstream &filebin) {
|
||||
char *data=NULL;
|
||||
if (filebin.is_open()) {
|
||||
data=new char[dataSize];
|
||||
filebin.read(data,dataSize);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
/* virtual int **getData(char *ptr, int dsize=-1) { */
|
||||
/* int **val; */
|
||||
/* val=new int*[1]; */
|
||||
/* val[0]=mythen03_frame(ptr,dynamicRange,nx,serialOffset); */
|
||||
/* return val; */
|
||||
|
||||
/* } */
|
||||
|
||||
|
||||
|
||||
virtual int setFrameNumber(int f=0) {if (f>=0) frameNumber=f; return frameNumber; };
|
||||
|
||||
private:
|
||||
|
||||
int frameNumber;
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
89
slsDetectorCalibration/dataStructures/chiptestBoardData.h
Normal file
89
slsDetectorCalibration/dataStructures/chiptestBoardData.h
Normal file
@ -0,0 +1,89 @@
|
||||
#ifndef CHIPTESTDATA_H
|
||||
#define CHIPTESTDATA_H
|
||||
|
||||
#include "slsDetectorData.h"
|
||||
|
||||
class chiptestBoardData : public slsDetectorData<uint16_t> {
|
||||
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
chiptestBoard data structure. Works for data acquired using the chiptestBoard.
|
||||
Inherits and implements slsDetectorData.
|
||||
|
||||
Constructor (no error checking if datasize and offsets are compatible!)
|
||||
\param npx number of pixels in the x direction
|
||||
\param npy number of pixels in the y direction (1 for strips)
|
||||
\param nadc number of adcs
|
||||
\param offset offset at the beginning of the pattern
|
||||
\param dMap array of size nx*ny storing the pointers to the data in the dataset (as offset)
|
||||
\param dMask Array of size nx*ny storing the polarity of the data in the dataset (should be 0 if no inversion is required, 0xffffffff is inversion is required)
|
||||
\param dROI Array of size nx*ny. The elements are 1s if the channel is good or in the ROI, 0 is bad or out of the ROI. NULL (default) means all 1s.
|
||||
|
||||
*/
|
||||
chiptestBoardData(int npx, int npy, int nadc, int offset, int **dMap=NULL, uint16_t **dMask=NULL, int **dROI=NULL): slsDetectorData<uint16_t>(npx, npy, nadc*(npx*npy)+offset, dMap, dMask, dROI), nAdc(nadc), offSize(offset), iframe(0) {}; // should be? nadc*(npx*npy+offset)
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Returns the frame number for the given dataset. Virtual func: works for slsDetectorReceiver data (also for each packet), but can be overloaded.
|
||||
\param buff pointer to the dataset
|
||||
\returns frame number
|
||||
|
||||
*/
|
||||
|
||||
virtual int getFrameNumber(char *buff){(void)buff; return iframe;};
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors!
|
||||
\param data pointer to the memory to be analyzed
|
||||
\param ndata size of frame returned
|
||||
\param dsize size of the memory slot to be analyzed
|
||||
\returns always return the pointer to data (no frame loss!)
|
||||
*/
|
||||
|
||||
virtual char *findNextFrame(char *data, int &ndata, int dsize) {ndata=dsize;setDataSize(dsize); return data;};
|
||||
|
||||
/**
|
||||
Loops over a file stream until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors!
|
||||
\param filebin input file stream (binary)
|
||||
\returns pointer to the first packet of the last good frame, NULL if no frame is found or last frame is incomplete
|
||||
*/
|
||||
|
||||
virtual char *readNextFrame(ifstream &filebin) {
|
||||
|
||||
int afifo_length=0;
|
||||
uint16_t *afifo_cont;
|
||||
|
||||
if (filebin.is_open()) {
|
||||
if (filebin.read((char*)&afifo_length,sizeof(uint32_t))) {
|
||||
setDataSize(afifo_length*nAdc*sizeof(uint16_t));
|
||||
afifo_cont=new uint16_t[afifo_length*nAdc];
|
||||
if (filebin.read((char*)afifo_cont,afifo_length*sizeof(uint16_t)*nAdc)) {
|
||||
iframe++;
|
||||
return (char*)afifo_cont;
|
||||
} else {
|
||||
delete [] afifo_cont;
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
};
|
||||
|
||||
private:
|
||||
const int nAdc; /**<number of ADC read out */
|
||||
const int offSize; /**< offset at the beginning of the frame (depends on the pattern) */
|
||||
int iframe; /**< frame number (calculated in software! not in the data)*/
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
@ -0,0 +1,172 @@
|
||||
#ifndef GOTTHARD2MODULEDATANEW_H
|
||||
#define GOTTHARD2MODULEDATANEW_H
|
||||
#include "gotthardModuleDataNew.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class gotthardDoubleModuleDataNew : public slsDetectorData<uint16_t> {
|
||||
|
||||
private:
|
||||
const int nModules;
|
||||
const int offset;
|
||||
int iframe;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Implements the slsReceiverData structure for the gotthard read out by a module i.e. using the slsReceiver
|
||||
(1x1280 pixels, 2 packets 1286 large etc.)
|
||||
\param c crosstalk parameter for the output buffer
|
||||
|
||||
*/
|
||||
|
||||
|
||||
gotthardDoubleModuleDataNew(int off=24*2, int nmod=2): slsDetectorData<uint16_t>(1280*nmod, 1, nmod*(1280*2+off)), nModules(nmod), offset(off),iframe(0) {
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef BCHIP074_BCHIP075
|
||||
cout << "This is a bchip074-bchip075 system " << endl;
|
||||
#endif
|
||||
|
||||
|
||||
uint16_t **dMask;
|
||||
int **dMap;
|
||||
int ix, iy;
|
||||
int ypixels=1;
|
||||
int xpixels=1280*nmod;
|
||||
int imod, ipix;
|
||||
dMask=new uint16_t*[1];
|
||||
dMap=new int*[1];
|
||||
dMap[0] = new int[1280*nmod];
|
||||
dMask[0] = new uint16_t[1280*nmod];
|
||||
|
||||
for(int ix=0; ix<xpixels; ix++) {
|
||||
imod=ix%2;
|
||||
if (imod==0)
|
||||
ipix=ix/2;
|
||||
else
|
||||
ipix=1280-1-ix/2;
|
||||
if (imod==0)
|
||||
dMap[0][ix] =ipix*2+offset;
|
||||
else
|
||||
dMap[0][ix] = 1280*2+2*offset+ipix*2;//dataSize-2-ix;//+2*offset;
|
||||
// dMap[0][ix] = 2*ipix+offset*(imod+1)+1280*2*imod;
|
||||
dMask[0][ix] = 0x0;
|
||||
#ifdef BCHIP074_BCHIP075
|
||||
int ibad=ix/2+1280*imod;
|
||||
if ((ibad>=128*4 && ibad<128*5) || (ibad>=9*128 && ibad<10*128) || (ibad>=(1280+128*4) && ibad<ibad>=(1280+128*6)))
|
||||
dataROIMask[0][ix]=0;
|
||||
#endif
|
||||
}
|
||||
|
||||
setDataMap(dMap);
|
||||
setDataMask(dMask);
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Returns the frame number for the given dataset.
|
||||
\param buff pointer to the dataset
|
||||
\returns frame number
|
||||
|
||||
*/
|
||||
|
||||
|
||||
int getFrameNumber(char *buff){if (offset>=sizeof(sls_detector_header)) return ((sls_detector_header*)buff)->frameNumber; return iframe;};//*((int*)(buff+5))&0xffffff;};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
gets the packets number (last packet is labelled with 0 and is replaced with 40)
|
||||
\param buff pointer to the memory
|
||||
\returns packet number
|
||||
|
||||
*/
|
||||
|
||||
int getPacketNumber(char *buff){if (offset>=sizeof(sls_detector_header))return ((sls_detector_header*)buff)->packetNumber;};
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func
|
||||
\param data pointer to the memory to be analyzed
|
||||
\param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot
|
||||
\param dsize size of the memory slot to be analyzed
|
||||
\returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found
|
||||
|
||||
*/
|
||||
virtual char *findNextFrame(char *data, int &ndata, int dsize){
|
||||
if (dsize<dataSize) ndata=dsize;
|
||||
else ndata=dataSize;
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
virtual char *readNextFrame(ifstream &filebin) {
|
||||
int ff=-1, np=-1;
|
||||
return readNextFrame(filebin, ff, np);
|
||||
};
|
||||
|
||||
virtual char *readNextFrame(ifstream &filebin, int &ff) {
|
||||
int np=-1;
|
||||
return readNextFrame(filebin, ff, np);
|
||||
};
|
||||
|
||||
virtual char *readNextFrame(ifstream &filebin, int& ff, int &np) {
|
||||
char *data=new char[dataSize];
|
||||
char *d=readNextFrame(filebin, ff, np, data);
|
||||
if (d==NULL) {delete [] data; data=NULL;}
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
virtual char *readNextFrame(ifstream &filebin, int& ff, int &np, char *data) {
|
||||
char *retval=0;
|
||||
int nd;
|
||||
int fnum = -1;
|
||||
np=0;
|
||||
int pn;
|
||||
|
||||
// cout << dataSize << endl;
|
||||
if (ff>=0)
|
||||
fnum=ff;
|
||||
|
||||
if (filebin.is_open()) {
|
||||
if (filebin.read(data, dataSize) ){
|
||||
ff=getFrameNumber(data);
|
||||
np=getPacketNumber(data);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
127
slsDetectorCalibration/dataStructures/gotthardShortModuleData.h
Normal file
127
slsDetectorCalibration/dataStructures/gotthardShortModuleData.h
Normal file
@ -0,0 +1,127 @@
|
||||
#ifndef GOTTHARDSHORTMODULEDATA_H
|
||||
#define GOTTHARDSHORTMODULEDATA_H
|
||||
#include "slsReceiverData.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class gotthardShortModuleData : public slsReceiverData<uint16_t> {
|
||||
public:
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Implements the slsReceiverData structure for the gotthard short read out by a module i.e. using the slsReceiver
|
||||
(1x256 pixels, 1 packet 256 large etc.)
|
||||
\param c crosstalk parameter for the output buffer
|
||||
|
||||
*/
|
||||
|
||||
|
||||
gotthardShortModuleData(double c=0): slsReceiverData<uint16_t>(xpixels, ypixels, npackets, buffersize), xtalk(c){
|
||||
|
||||
uint16_t **dMask;
|
||||
int **dMap;
|
||||
int ix, iy;
|
||||
int offset = 2;
|
||||
|
||||
dMask=new uint16_t*[ypixels];
|
||||
dMap=new int*[ypixels];
|
||||
for (int i = 0; i < ypixels; i++) {
|
||||
dMap[i] = new int[xpixels];
|
||||
dMask[i] = new uint16_t[xpixels];
|
||||
}
|
||||
|
||||
for(ix=0; ix<ypixels; ++ix)
|
||||
for(iy=0; iy<xpixels; ++iy)
|
||||
dMask[ix][iy] = 0x0;
|
||||
|
||||
for(ix=0; ix<ypixels; ++ix)
|
||||
for(iy=0; iy<xpixels; ++iy){
|
||||
dMap[ix][iy] = offset;
|
||||
offset++;
|
||||
}
|
||||
|
||||
setDataMap(dMap);
|
||||
setDataMask(dMask);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Returns the frame number for the given dataset.
|
||||
\param buff pointer to the dataset
|
||||
\returns frame number
|
||||
|
||||
*/
|
||||
|
||||
int getFrameNumber(char *buff){
|
||||
return (*(int*)buff);
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
gets the packets number (last packet is labelled with 0 and is replaced with 40)
|
||||
\param buff pointer to the memory
|
||||
\returns packet number
|
||||
|
||||
*/
|
||||
|
||||
int getPacketNumber(char *buff){
|
||||
return 1;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
returns the pixel value as double correcting for the output buffer crosstalk
|
||||
\param data pointer to the memory
|
||||
\param ix coordinate in the x direction
|
||||
\param iy coordinate in the y direction
|
||||
\returns channel value as double
|
||||
|
||||
*/
|
||||
double getValue(char *data, int ix, int iy=0) {
|
||||
//check how it is for gotthard
|
||||
if (xtalk==0)
|
||||
return slsDetectorData<uint16_t>::getValue(data, ix, iy);
|
||||
else
|
||||
return slsDetectorData<uint16_t>::getValue(data, ix, iy)-xtalk*slsDetectorData<uint16_t>::getValue(data, ix-1, iy);
|
||||
};
|
||||
|
||||
|
||||
|
||||
/** sets the output buffer crosstalk correction parameter
|
||||
\param c output buffer crosstalk correction parameter to be set
|
||||
\returns current value for the output buffer crosstalk correction parameter
|
||||
|
||||
*/
|
||||
double setXTalk(double c) {xtalk=c; return xtalk;}
|
||||
|
||||
|
||||
/** gets the output buffer crosstalk parameter
|
||||
\returns current value for the output buffer crosstalk correction parameter
|
||||
*/
|
||||
double getXTalk() {return xtalk;}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
double xtalk; /**<output buffer crosstalk correction parameter */
|
||||
const static int xpixels = 256;
|
||||
const static int ypixels = 1;
|
||||
const static int npackets = 1;
|
||||
const static int buffersize = 518;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
169
slsDetectorCalibration/dataStructures/moench02CtbData.h
Normal file
169
slsDetectorCalibration/dataStructures/moench02CtbData.h
Normal file
@ -0,0 +1,169 @@
|
||||
#ifndef MOENCH02CTBDATA_H
|
||||
#define MOENCH02CTBDATA_H
|
||||
#include "slsDetectorData.h"
|
||||
|
||||
|
||||
|
||||
class moench02CtbData : public slsDetectorData<uint16_t> {
|
||||
|
||||
private:
|
||||
|
||||
int iframe;
|
||||
// int *xmap, *ymap;
|
||||
int nadc;
|
||||
int sc_width;
|
||||
int sc_height;
|
||||
|
||||
int maplength;
|
||||
|
||||
|
||||
|
||||
public:
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Implements the slsReceiverData structure for the moench02 prototype read out by a module i.e. using the slsReceiver
|
||||
(160x160 pixels, 40 packets 1286 large etc.)
|
||||
\param c crosstalk parameter for the output buffer
|
||||
|
||||
*/
|
||||
|
||||
|
||||
moench02CtbData(int ns=6400): slsDetectorData<uint16_t>(160, 160, ns*2*32, NULL, NULL) , nadc(32), sc_width(40), sc_height(160) {
|
||||
|
||||
|
||||
int adc_off[4]={40,0,120,80};
|
||||
int adc_nr[4]={8,10,20,22};
|
||||
int row, col;
|
||||
|
||||
int isample;
|
||||
int iadc, iiadc;
|
||||
int ix, iy;
|
||||
maplength=this->getDataSize()/2;
|
||||
//cout << maplength << endl;
|
||||
|
||||
for (iiadc=0; iiadc<4; iiadc++) {
|
||||
|
||||
iadc=adc_nr[iiadc];
|
||||
//cout << iiadc << endl;
|
||||
for (int i=0; i<sc_width*sc_height; i++) {
|
||||
|
||||
col=adc_off[iiadc]+(i%sc_width);
|
||||
row=i/sc_width;
|
||||
dataMap[row][col]=(32*i+iadc)*2;
|
||||
if (dataMap[row][col]<0 || dataMap[row][col]>=dataSize) {
|
||||
cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
for (int i=0; i<maplength; i++) {
|
||||
//cout << i << endl;
|
||||
isample=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;
|
||||
iy=isample/sc_width;
|
||||
if(iadc>=0){
|
||||
xmap[i]=adc_off[iadc]+ix;
|
||||
ymap[i]=iy;
|
||||
}else{
|
||||
xmap[i]=-1;
|
||||
ymap[i]=-1;
|
||||
}
|
||||
}
|
||||
iframe=0;
|
||||
cout << "data struct created" << endl;
|
||||
};
|
||||
|
||||
void getPixel(int ip, int &x, int &y) {
|
||||
if(ip>=0 && ip<maplength){
|
||||
x=xmap[ip];
|
||||
y=ymap[ip];
|
||||
}/*else{
|
||||
cerr<<"WRONG ARRAY LENGTH"<<endl;
|
||||
cerr<<"Trying to access the "<<ip<<"-th element"<<endl;
|
||||
}*/
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Returns the frame number for the given dataset. Purely virtual func.
|
||||
\param buff pointer to the dataset
|
||||
\returns frame number
|
||||
|
||||
*/
|
||||
|
||||
|
||||
virtual int getFrameNumber(char *buff){(void)buff; return iframe;};
|
||||
|
||||
/**
|
||||
|
||||
Returns the packet number for the given dataset. purely virtual func
|
||||
\param buff pointer to the dataset
|
||||
\returns packet number number
|
||||
|
||||
|
||||
virtual int getPacketNumber(char *buff)=0;
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
|
||||
Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func
|
||||
\param data pointer to the memory to be analyzed
|
||||
\param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot
|
||||
\param dsize size of the memory slot to be analyzed
|
||||
\returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found
|
||||
|
||||
*/
|
||||
virtual char *findNextFrame(char *data, int &ndata, int dsize){ndata=dsize; setDataSize(dsize); return data;};
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Loops over a file stream until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors!
|
||||
\param filebin input file stream (binary)
|
||||
\returns pointer to the begin of the last good frame, NULL if no frame is found or last frame is incomplete
|
||||
|
||||
*/
|
||||
virtual char *readNextFrame(ifstream &filebin){
|
||||
// int afifo_length=0;
|
||||
uint16_t *afifo_cont;
|
||||
int ib=0;
|
||||
if (filebin.is_open()) {
|
||||
afifo_cont=new uint16_t[dataSize/2];
|
||||
while (filebin.read(((char*)afifo_cont)+ib,2)) {
|
||||
ib+=2;
|
||||
if (ib==dataSize) break;
|
||||
}
|
||||
if (ib>0) {
|
||||
iframe++;
|
||||
//cout << ib/2 << "-" << endl;
|
||||
//for (int i=0; i<ib/2; i++)
|
||||
//cout << i << " " << afifo_cont[i] << endl;
|
||||
return (char*)afifo_cont;
|
||||
} else {
|
||||
delete [] afifo_cont;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
157
slsDetectorCalibration/dataStructures/moench03CtbData.h
Normal file
157
slsDetectorCalibration/dataStructures/moench03CtbData.h
Normal file
@ -0,0 +1,157 @@
|
||||
#ifndef MOENCH03CTBDATA_H
|
||||
#define MOENCH03CTBDATA_H
|
||||
#include "slsDetectorData.h"
|
||||
|
||||
|
||||
|
||||
class moench03CtbData : public slsDetectorData<uint16_t> {
|
||||
|
||||
private:
|
||||
|
||||
int iframe;
|
||||
int nadc;
|
||||
int sc_width;
|
||||
int sc_height;
|
||||
public:
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Implements the slsReceiverData structure for the moench02 prototype read out by a module i.e. using the slsReceiver
|
||||
(160x160 pixels, 40 packets 1286 large etc.)
|
||||
\param c crosstalk parameter for the output buffer
|
||||
|
||||
*/
|
||||
|
||||
|
||||
moench03CtbData(int ns=5000): slsDetectorData<uint16_t>(400, 400, ns*2*32, NULL, NULL) , nadc(32), sc_width(25), sc_height(200) {
|
||||
|
||||
|
||||
int row, col;
|
||||
|
||||
int isample;
|
||||
int iadc;
|
||||
int ix, iy;
|
||||
|
||||
int adc_nr[32]={200,225,250,275,300,325,350,375,\
|
||||
0,25,50,75,100,125,150,175,\
|
||||
175,150,125,100,75,50,25,0,\
|
||||
375,350,325,300,275,250,225,200};
|
||||
|
||||
/* int adc_nr[32]={300,325,350,375,300,325,350,375, \ */
|
||||
/* 200,225,250,275,200,225,250,275,\ */
|
||||
/* 100,125,150,175,100,125,150,175,\ */
|
||||
/* 0,25,50,75,0,25,50,75}; */
|
||||
|
||||
|
||||
for (iadc=0; iadc<nadc; iadc++) {
|
||||
for (int i=0; i<sc_width*sc_height; i++) {
|
||||
col=adc_nr[iadc]+(i%sc_width);
|
||||
if (iadc<16) {
|
||||
row=199-i/sc_width;
|
||||
} else {
|
||||
row=200+i/sc_width;
|
||||
}
|
||||
dataMap[row][col]=(nadc*i+iadc)*2;
|
||||
if (dataMap[row][col]<0 || dataMap[row][col]>=2*400*400)
|
||||
cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl;
|
||||
|
||||
}
|
||||
}
|
||||
for (int i=0; i<nx*ny; i++) {
|
||||
isample=i/nadc;
|
||||
iadc=i%nadc;
|
||||
ix=isample%sc_width;
|
||||
iy=isample/sc_width;
|
||||
if (iadc<(nadc/2)) {
|
||||
xmap[i]=adc_nr[iadc]+ix;
|
||||
ymap[i]=ny/2-1-iy;
|
||||
} else {
|
||||
xmap[i]=adc_nr[iadc]+ix;
|
||||
ymap[i]=ny/2+iy;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
iframe=0;
|
||||
// cout << "data struct created" << endl;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Returns the frame number for the given dataset. Purely virtual func.
|
||||
\param buff pointer to the dataset
|
||||
\returns frame number
|
||||
|
||||
*/
|
||||
|
||||
|
||||
virtual int getFrameNumber(char *buff){(void)buff; return iframe;};
|
||||
|
||||
/**
|
||||
|
||||
Returns the packet number for the given dataset. purely virtual func
|
||||
\param buff pointer to the dataset
|
||||
\returns packet number number
|
||||
|
||||
|
||||
virtual int getPacketNumber(char *buff)=0;
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
|
||||
Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func
|
||||
\param data pointer to the memory to be analyzed
|
||||
\param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot
|
||||
\param dsize size of the memory slot to be analyzed
|
||||
\returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found
|
||||
|
||||
*/
|
||||
virtual char *findNextFrame(char *data, int &ndata, int dsize){ndata=dsize; setDataSize(dsize); return data;};
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Loops over a file stream until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors!
|
||||
\param filebin input file stream (binary)
|
||||
\returns pointer to the begin of the last good frame, NULL if no frame is found or last frame is incomplete
|
||||
|
||||
*/
|
||||
virtual char *readNextFrame(ifstream &filebin){
|
||||
// int afifo_length=0;
|
||||
uint16_t *afifo_cont;
|
||||
int ib=0;
|
||||
if (filebin.is_open()) {
|
||||
afifo_cont=new uint16_t[dataSize/2];
|
||||
while (filebin.read(((char*)afifo_cont)+ib,2)) {
|
||||
ib+=2;
|
||||
if (ib==dataSize) break;
|
||||
}
|
||||
if (ib>0) {
|
||||
iframe++;
|
||||
// cout << ib << "-" << endl;
|
||||
return (char*)afifo_cont;
|
||||
} else {
|
||||
delete [] afifo_cont;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
158
slsDetectorCalibration/dataStructures/moench03T1CtbData.h
Normal file
158
slsDetectorCalibration/dataStructures/moench03T1CtbData.h
Normal file
@ -0,0 +1,158 @@
|
||||
#ifndef MOENCH03T1CTBDATA_H
|
||||
#define MOENCH03T1CTBDATA_H
|
||||
#include "slsDetectorData.h"
|
||||
|
||||
|
||||
|
||||
class moench03T1CtbData : public slsDetectorData<uint16_t> {
|
||||
|
||||
private:
|
||||
|
||||
int iframe;
|
||||
int nadc;
|
||||
int sc_width;
|
||||
int sc_height;
|
||||
public:
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Implements the slsReceiverData structure for the moench02 prototype read out by a module i.e. using the slsReceiver
|
||||
(160x160 pixels, 40 packets 1286 large etc.)
|
||||
\param c crosstalk parameter for the output buffer
|
||||
|
||||
*/
|
||||
|
||||
|
||||
moench03T1CtbData(int ns=5000): slsDetectorData<uint16_t>(400, 400, ns*2*32, NULL, NULL) , nadc(32), sc_width(25), sc_height(200) {
|
||||
|
||||
|
||||
int adc_nr[32]={300,325,350,375,300,325,350,375, \
|
||||
200,225,250,275,200,225,250,275,\
|
||||
100,125,150,175,100,125,150,175,\
|
||||
0,25,50,75,0,25,50,75};
|
||||
|
||||
int row, col;
|
||||
|
||||
int isample;
|
||||
int iadc;
|
||||
int ix, iy;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
for (iadc=0; iadc<nadc; iadc++) {
|
||||
for (int i=0; i<sc_width*sc_height; i++) {
|
||||
col=adc_nr[iadc]+(i%sc_width);
|
||||
if (iadc<16) {
|
||||
row=199-i/sc_width;
|
||||
} else {
|
||||
row=200+i/sc_width;
|
||||
}
|
||||
dataMap[row][col]=(nadc*i+iadc)*2;
|
||||
if (dataMap[row][col]<0 || dataMap[row][col]>=2*400*400)
|
||||
cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl;
|
||||
|
||||
}
|
||||
}
|
||||
int adc4;
|
||||
for (int i=0; i<nx*ny; i++) {
|
||||
isample=i/nadc;
|
||||
iadc=i%nadc;
|
||||
ix=isample%sc_width;
|
||||
iy=isample/sc_width;
|
||||
adc4 = (int)iadc/4;
|
||||
// if (iadc<(nadc/2)) {
|
||||
if (adc4%2==0) {
|
||||
xmap[i]=adc_nr[iadc]+ix;
|
||||
ymap[i]=ny/2-1-iy;
|
||||
} else {
|
||||
xmap[i]=adc_nr[iadc]+ix;
|
||||
ymap[i]=ny/2+iy;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
iframe=0;
|
||||
// cout << "data struct created" << endl;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Returns the frame number for the given dataset. Purely virtual func.
|
||||
\param buff pointer to the dataset
|
||||
\returns frame number
|
||||
|
||||
*/
|
||||
|
||||
|
||||
virtual int getFrameNumber(char *buff){(void)buff; return iframe;};
|
||||
|
||||
/**
|
||||
|
||||
Returns the packet number for the given dataset. purely virtual func
|
||||
\param buff pointer to the dataset
|
||||
\returns packet number number
|
||||
|
||||
|
||||
virtual int getPacketNumber(char *buff)=0;
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
|
||||
Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func
|
||||
\param data pointer to the memory to be analyzed
|
||||
\param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot
|
||||
\param dsize size of the memory slot to be analyzed
|
||||
\returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found
|
||||
|
||||
*/
|
||||
virtual char *findNextFrame(char *data, int &ndata, int dsize){ndata=dsize; setDataSize(dsize); return data;};
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Loops over a file stream until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors!
|
||||
\param filebin input file stream (binary)
|
||||
\returns pointer to the begin of the last good frame, NULL if no frame is found or last frame is incomplete
|
||||
|
||||
*/
|
||||
virtual char *readNextFrame(ifstream &filebin){
|
||||
// int afifo_length=0;
|
||||
uint16_t *afifo_cont;
|
||||
int ib=0;
|
||||
if (filebin.is_open()) {
|
||||
afifo_cont=new uint16_t[dataSize/2];
|
||||
while (filebin.read(((char*)afifo_cont)+ib,2)) {
|
||||
ib+=2;
|
||||
if (ib==dataSize) break;
|
||||
}
|
||||
if (ib>0) {
|
||||
iframe++;
|
||||
// cout << ib << "-" << endl;
|
||||
return (char*)afifo_cont;
|
||||
} else {
|
||||
delete [] afifo_cont;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
@ -0,0 +1,290 @@
|
||||
#ifndef MOENCH03T1RECDATANEW_H
|
||||
#define MOENCH03T1RECDATANEW_H
|
||||
#include "slsDetectorData.h"
|
||||
|
||||
//#define VERSION_V2
|
||||
/**
|
||||
@short structure for a Detector Packet or Image Header
|
||||
@li frameNumber is the frame number
|
||||
@li expLength is the subframe number (32 bit eiger) or real time exposure time in 100ns (others)
|
||||
@li packetNumber is the packet number
|
||||
@li bunchId is the bunch id from beamline
|
||||
@li timestamp is the time stamp with 10 MHz clock
|
||||
@li modId is the unique module id (unique even for left, right, top, bottom)
|
||||
@li xCoord is the x coordinate in the complete detector system
|
||||
@li yCoord is the y coordinate in the complete detector system
|
||||
@li zCoord is the z coordinate in the complete detector system
|
||||
@li debug is for debugging purposes
|
||||
@li roundRNumber is the round robin set number
|
||||
@li detType is the detector type see :: detectorType
|
||||
@li version is the version number of this structure format
|
||||
*/
|
||||
typedef struct {
|
||||
uint64_t frameNumber; /**< is the frame number */
|
||||
uint32_t expLength; /**< is the subframe number (32 bit eiger) or real time exposure time in 100ns (others) */
|
||||
uint32_t packetNumber; /**< is the packet number */
|
||||
uint64_t bunchId; /**< is the bunch id from beamline */
|
||||
uint64_t timestamp; /**< is the time stamp with 10 MHz clock */
|
||||
uint16_t modId; /**< is the unique module id (unique even for left, right, top, bottom) */
|
||||
uint16_t xCoord; /**< is the x coordinate in the complete detector system */
|
||||
uint16_t yCoord; /**< is the y coordinate in the complete detector system */
|
||||
uint16_t zCoord; /**< is the z coordinate in the complete detector system */
|
||||
uint32_t debug; /**< is for debugging purposes */
|
||||
uint16_t roundRNumber; /**< is the round robin set number */
|
||||
uint8_t detType; /**< is the detector type see :: detectorType */
|
||||
uint8_t version; /**< is the version number of this structure format */
|
||||
#ifndef VERSION_V1
|
||||
uint64_t packetCaught[8]; /**< is the version number of this structure format */
|
||||
#endif
|
||||
|
||||
} sls_detector_header;
|
||||
|
||||
|
||||
|
||||
|
||||
class moench03T1ReceiverDataNew : public slsDetectorData<uint16_t> {
|
||||
|
||||
private:
|
||||
|
||||
int iframe;
|
||||
int nadc;
|
||||
int sc_width;
|
||||
int sc_height;
|
||||
const int nSamples;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Implements the slsReceiverData structure for the moench02 prototype read out by a module i.e. using the slsReceiver
|
||||
(160x160 pixels, 40 packets 1286 large etc.)
|
||||
\param c crosstalk parameter for the output buffer
|
||||
|
||||
*/
|
||||
moench03T1ReceiverDataNew(int ns=5000): slsDetectorData<uint16_t>(400, 400, ns*2*32+sizeof(sls_detector_header)), nSamples(ns) {
|
||||
|
||||
int nadc=32;
|
||||
int sc_width=25;
|
||||
int sc_height=200;
|
||||
|
||||
int adc_nr[32]={300,325,350,375,300,325,350,375, \
|
||||
200,225,250,275,200,225,250,275,\
|
||||
100,125,150,175,100,125,150,175,\
|
||||
0,25,50,75,0,25,50,75};
|
||||
|
||||
int row, col;
|
||||
|
||||
int isample;
|
||||
int iadc;
|
||||
int ix, iy;
|
||||
|
||||
int npackets=40;
|
||||
int i;
|
||||
int adc4(0);
|
||||
|
||||
for (int ip=0; ip<npackets; ip++) {
|
||||
for (int is=0; is<128; is++) {
|
||||
|
||||
for (iadc=0; iadc<nadc; iadc++) {
|
||||
i=128*ip+is;
|
||||
adc4=(int)iadc/4;
|
||||
if (i<sc_width*sc_height) {
|
||||
// for (int i=0; i<sc_width*sc_height; i++) {
|
||||
col=adc_nr[iadc]+(i%sc_width);
|
||||
if (adc4%2==0) {
|
||||
row=199-i/sc_width;
|
||||
} else {
|
||||
row=200+i/sc_width;
|
||||
}
|
||||
dataMap[row][col]=sizeof(sls_detector_header)+(nadc*i+iadc)*2;//+16*(ip+1);
|
||||
if (dataMap[row][col]<0 || dataMap[row][col]>=nSamples*2*32)
|
||||
cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int ipacket;
|
||||
int ibyte;
|
||||
int ii=0;
|
||||
for (ibyte=0; ibyte<sizeof(sls_detector_header)/2; ibyte++){
|
||||
xmap[ibyte]=-1;
|
||||
ymap[ibyte]=-1;
|
||||
}
|
||||
int off=sizeof(sls_detector_header)/2;
|
||||
for (ipacket=0; ipacket<npackets; ipacket++) {
|
||||
for (ibyte=0; ibyte< 8192/2; ibyte++) {
|
||||
i=ipacket*8208/2+ibyte;
|
||||
isample=ii/nadc;
|
||||
if (isample<nSamples) {
|
||||
iadc=ii%nadc;
|
||||
adc4 = (int)iadc/4;
|
||||
ix=isample%sc_width;
|
||||
iy=isample/sc_width;
|
||||
if (adc4%2==0) {
|
||||
xmap[i+off]=adc_nr[iadc]+ix;
|
||||
ymap[i+off]=ny/2-1-iy;
|
||||
} else {
|
||||
xmap[i+off]=adc_nr[iadc]+ix;
|
||||
ymap[i+off]=ny/2+iy;
|
||||
}
|
||||
}
|
||||
ii++;
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
iframe=0;
|
||||
// cout << "data struct created" << endl;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Returns the frame number for the given dataset. Purely virtual func.
|
||||
\param buff pointer to the dataset
|
||||
\returns frame number
|
||||
|
||||
*/
|
||||
|
||||
/* class jfrau_packet_header_t { */
|
||||
/* public: */
|
||||
/* unsigned char reserved[4]; */
|
||||
/* unsigned char packetNumber[1]; */
|
||||
/* unsigned char frameNumber[3]; */
|
||||
/* unsigned char bunchid[8]; */
|
||||
/* }; */
|
||||
|
||||
|
||||
|
||||
int getFrameNumber(char *buff){return ((sls_detector_header*)buff)->frameNumber;};//*((int*)(buff+5))&0xffffff;};
|
||||
|
||||
/**
|
||||
|
||||
Returns the packet number for the given dataset. purely virtual func
|
||||
\param buff pointer to the dataset
|
||||
\returns packet number number
|
||||
|
||||
|
||||
|
||||
*/
|
||||
int getPacketNumber(char *buff){return ((sls_detector_header*)buff)->packetNumber;}//((*(((int*)(buff+4))))&0xff)+1;};
|
||||
|
||||
/* /\** */
|
||||
|
||||
/* Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func */
|
||||
/* \param data pointer to the memory to be analyzed */
|
||||
/* \param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot */
|
||||
/* \param dsize size of the memory slot to be analyzed */
|
||||
/* \returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found */
|
||||
|
||||
/* *\/ */
|
||||
/* virtual char *findNextFrame(char *data, int &ndata, int dsize){ndata=dsize; setDataSize(dsize); return data;}; */
|
||||
|
||||
|
||||
/* /\** */
|
||||
|
||||
/* Loops over a file stream until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors! */
|
||||
/* \param filebin input file stream (binary) */
|
||||
/* \returns pointer to the begin of the last good frame, NULL if no frame is found or last frame is incomplete */
|
||||
|
||||
/* *\/ */
|
||||
/* virtual char *readNextFrame(ifstream &filebin){ */
|
||||
/* // int afifo_length=0; */
|
||||
/* uint16_t *afifo_cont; */
|
||||
/* int ib=0; */
|
||||
/* if (filebin.is_open()) { */
|
||||
/* afifo_cont=new uint16_t[dataSize/2]; */
|
||||
/* while (filebin.read(((char*)afifo_cont)+ib,2)) { */
|
||||
/* ib+=2; */
|
||||
/* if (ib==dataSize) break; */
|
||||
/* } */
|
||||
/* if (ib>0) { */
|
||||
/* iframe++; */
|
||||
/* // cout << ib << "-" << endl; */
|
||||
/* return (char*)afifo_cont; */
|
||||
/* } else { */
|
||||
/* delete [] afifo_cont; */
|
||||
/* return NULL; */
|
||||
/* } */
|
||||
/* } */
|
||||
/* return NULL; */
|
||||
/* }; */
|
||||
|
||||
|
||||
virtual char *readNextFrame(ifstream &filebin) {
|
||||
int ff=-1, np=-1;
|
||||
return readNextFrame(filebin, ff, np);
|
||||
};
|
||||
|
||||
virtual char *readNextFrame(ifstream &filebin, int &ff) {
|
||||
int np=-1;
|
||||
return readNextFrame(filebin, ff, np);
|
||||
};
|
||||
|
||||
virtual char *readNextFrame(ifstream &filebin, int& ff, int &np) {
|
||||
char *data=new char[dataSize];
|
||||
char *d=readNextFrame(filebin, ff, np, data);
|
||||
if (d==NULL) {delete [] data; data=NULL;}
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
virtual char *readNextFrame(ifstream &filebin, int& ff, int &np, char *data) {
|
||||
char *retval=0;
|
||||
int nd;
|
||||
int fnum = -1;
|
||||
np=0;
|
||||
int pn;
|
||||
|
||||
// cout << dataSize << endl;
|
||||
if (ff>=0)
|
||||
fnum=ff;
|
||||
|
||||
if (filebin.is_open()) {
|
||||
if (filebin.read(data, dataSize) ){
|
||||
ff=getFrameNumber(data);
|
||||
np=getPacketNumber(data);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func
|
||||
\param data pointer to the memory to be analyzed
|
||||
\param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot
|
||||
\param dsize size of the memory slot to be analyzed
|
||||
\returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found
|
||||
|
||||
*/
|
||||
virtual char *findNextFrame(char *data, int &ndata, int dsize){
|
||||
if (dsize<dataSize) ndata=dsize;
|
||||
else ndata=dataSize;
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//int getPacketNumber(int x, int y) {return dataMap[y][x]/packetSize;};
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
@ -0,0 +1,321 @@
|
||||
#ifndef MOENCH03T1RECDATANEWRECT_H
|
||||
#define MOENCH03T1RECDATANEWRECT_H
|
||||
#include "slsDetectorData.h"
|
||||
|
||||
#define VERT 1
|
||||
|
||||
/**
|
||||
@short structure for a Detector Packet or Image Header
|
||||
@li frameNumber is the frame number
|
||||
@li expLength is the subframe number (32 bit eiger) or real time exposure time in 100ns (others)
|
||||
@li packetNumber is the packet number
|
||||
@li bunchId is the bunch id from beamline
|
||||
@li timestamp is the time stamp with 10 MHz clock
|
||||
@li modId is the unique module id (unique even for left, right, top, bottom)
|
||||
@li xCoord is the x coordinate in the complete detector system
|
||||
@li yCoord is the y coordinate in the complete detector system
|
||||
@li zCoord is the z coordinate in the complete detector system
|
||||
@li debug is for debugging purposes
|
||||
@li roundRNumber is the round robin set number
|
||||
@li detType is the detector type see :: detectorType
|
||||
@li version is the version number of this structure format
|
||||
*/
|
||||
typedef struct {
|
||||
uint64_t frameNumber; /**< is the frame number */
|
||||
uint32_t expLength; /**< is the subframe number (32 bit eiger) or real time exposure time in 100ns (others) */
|
||||
uint32_t packetNumber; /**< is the packet number */
|
||||
uint64_t bunchId; /**< is the bunch id from beamline */
|
||||
uint64_t timestamp; /**< is the time stamp with 10 MHz clock */
|
||||
uint16_t modId; /**< is the unique module id (unique even for left, right, top, bottom) */
|
||||
uint16_t xCoord; /**< is the x coordinate in the complete detector system */
|
||||
uint16_t yCoord; /**< is the y coordinate in the complete detector system */
|
||||
uint16_t zCoord; /**< is the z coordinate in the complete detector system */
|
||||
uint32_t debug; /**< is for debugging purposes */
|
||||
uint16_t roundRNumber; /**< is the round robin set number */
|
||||
uint8_t detType; /**< is the detector type see :: detectorType */
|
||||
uint8_t version; /**< is the version number of this structure format */
|
||||
} sls_detector_header;
|
||||
|
||||
|
||||
|
||||
|
||||
class moench03T1ReceiverDataNew : public slsDetectorData<uint16_t> {
|
||||
|
||||
private:
|
||||
|
||||
int iframe;
|
||||
int nadc;
|
||||
int sc_width;
|
||||
int sc_height;
|
||||
const int nSamples;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Implements the slsReceiverData structure for the moench02 prototype read out by a module i.e. using the slsReceiver
|
||||
(160x160 pixels, 40 packets 1286 large etc.)
|
||||
\param c crosstalk parameter for the output buffer
|
||||
|
||||
*/
|
||||
#ifdef HOR
|
||||
moench03T1ReceiverDataNew(int ns=5000): slsDetectorData<uint16_t>(800, 200, ns*2*32+sizeof(sls_detector_header)), nSamples(ns) {
|
||||
#endif
|
||||
#ifdef VERT
|
||||
moench03T1ReceiverDataNew(int ns=5000): slsDetectorData<uint16_t>(200, 800, ns*2*32+sizeof(sls_detector_header)), nSamples(ns) {
|
||||
#endif
|
||||
int nadc=32;
|
||||
int sc_width=25;
|
||||
int sc_height=200;
|
||||
|
||||
int adc_nr[32]={300,325,350,375,300,325,350,375, \
|
||||
200,225,250,275,200,225,250,275,\
|
||||
100,125,150,175,100,125,150,175,\
|
||||
0,25,50,75,0,25,50,75};
|
||||
|
||||
int row, col;
|
||||
|
||||
int isample;
|
||||
int iadc;
|
||||
int ix, iy;
|
||||
|
||||
int npackets=40;
|
||||
int i;
|
||||
int adc4(0);
|
||||
int pix;
|
||||
|
||||
|
||||
int off=0;
|
||||
#ifdef OFF_1
|
||||
off=1;
|
||||
#endif
|
||||
cout << "This is a MOENCH with rectangular pixels!" << endl;
|
||||
|
||||
for (int ip=0; ip<npackets; ip++) {
|
||||
for (int is=0; is<128; is++) {
|
||||
|
||||
for (iadc=0; iadc<nadc; iadc++) {
|
||||
i=128*ip+is;
|
||||
adc4=(int)iadc/4;
|
||||
if (i<sc_width*sc_height) {
|
||||
// for (int i=0; i<sc_width*sc_height; i++) {
|
||||
col=adc_nr[iadc]+(i%sc_width);
|
||||
if (adc4%2==0) {
|
||||
row=199-i/sc_width;
|
||||
} else {
|
||||
row=200+i/sc_width;
|
||||
}
|
||||
pix=sizeof(sls_detector_header)+(nadc*i+iadc)*2;//+16*(ip+1);
|
||||
if (pix<0 || pix>=nSamples*2*32+sizeof(sls_detector_header))
|
||||
cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl;
|
||||
ix=col;
|
||||
iy=row;
|
||||
#ifdef HOR
|
||||
if (row%2==off) {
|
||||
ix=2*col;
|
||||
iy=row/2;
|
||||
} else {
|
||||
ix=2*col+1;
|
||||
iy=row/2;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef VERT
|
||||
if (col%2==off) {
|
||||
ix=col/2;
|
||||
iy=row*2+1;
|
||||
} else {
|
||||
ix=col/2;
|
||||
iy=row*2;
|
||||
}
|
||||
#endif
|
||||
dataMap[iy][ix]=pix;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* int ipacket; */
|
||||
/* int ibyte; */
|
||||
/* int ii=0; */
|
||||
/* for (ibyte=0; ibyte<sizeof(sls_detector_header)/2; ibyte++){ */
|
||||
/* xmap[ibyte]=-1; */
|
||||
/* ymap[ibyte]=-1; */
|
||||
/* } */
|
||||
/* int off=sizeof(sls_detector_header)/2; */
|
||||
/* for (ipacket=0; ipacket<npackets; ipacket++) { */
|
||||
/* for (ibyte=0; ibyte< 8192/2; ibyte++) { */
|
||||
/* i=ipacket*8208/2+ibyte; */
|
||||
/* isample=ii/nadc; */
|
||||
/* if (isample<nSamples) { */
|
||||
/* iadc=ii%nadc; */
|
||||
/* adc4 = (int)iadc/4; */
|
||||
/* ix=isample%sc_width; */
|
||||
/* iy=isample/sc_width; */
|
||||
/* if (adc4%2==0) { */
|
||||
/* xmap[i+off]=adc_nr[iadc]+ix; */
|
||||
/* ymap[i+off]=ny/2-1-iy; */
|
||||
/* } else { */
|
||||
/* xmap[i+off]=adc_nr[iadc]+ix; */
|
||||
/* ymap[i+off]=ny/2+iy; */
|
||||
/* } */
|
||||
/* } */
|
||||
/* ii++; */
|
||||
/* // } */
|
||||
/* } */
|
||||
/* } */
|
||||
|
||||
iframe=0;
|
||||
// cout << "data struct created" << endl;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Returns the frame number for the given dataset. Purely virtual func.
|
||||
\param buff pointer to the dataset
|
||||
\returns frame number
|
||||
|
||||
*/
|
||||
|
||||
/* class jfrau_packet_header_t { */
|
||||
/* public: */
|
||||
/* unsigned char reserved[4]; */
|
||||
/* unsigned char packetNumber[1]; */
|
||||
/* unsigned char frameNumber[3]; */
|
||||
/* unsigned char bunchid[8]; */
|
||||
/* }; */
|
||||
|
||||
|
||||
|
||||
int getFrameNumber(char *buff){return ((sls_detector_header*)buff)->frameNumber;};//*((int*)(buff+5))&0xffffff;};
|
||||
|
||||
/**
|
||||
|
||||
Returns the packet number for the given dataset. purely virtual func
|
||||
\param buff pointer to the dataset
|
||||
\returns packet number number
|
||||
|
||||
|
||||
|
||||
*/
|
||||
int getPacketNumber(char *buff){return ((sls_detector_header*)buff)->packetNumber;}//((*(((int*)(buff+4))))&0xff)+1;};
|
||||
|
||||
/* /\** */
|
||||
|
||||
/* Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func */
|
||||
/* \param data pointer to the memory to be analyzed */
|
||||
/* \param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot */
|
||||
/* \param dsize size of the memory slot to be analyzed */
|
||||
/* \returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found */
|
||||
|
||||
/* *\/ */
|
||||
/* virtual char *findNextFrame(char *data, int &ndata, int dsize){ndata=dsize; setDataSize(dsize); return data;}; */
|
||||
|
||||
|
||||
/* /\** */
|
||||
|
||||
/* Loops over a file stream until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors! */
|
||||
/* \param filebin input file stream (binary) */
|
||||
/* \returns pointer to the begin of the last good frame, NULL if no frame is found or last frame is incomplete */
|
||||
|
||||
/* *\/ */
|
||||
/* virtual char *readNextFrame(ifstream &filebin){ */
|
||||
/* // int afifo_length=0; */
|
||||
/* uint16_t *afifo_cont; */
|
||||
/* int ib=0; */
|
||||
/* if (filebin.is_open()) { */
|
||||
/* afifo_cont=new uint16_t[dataSize/2]; */
|
||||
/* while (filebin.read(((char*)afifo_cont)+ib,2)) { */
|
||||
/* ib+=2; */
|
||||
/* if (ib==dataSize) break; */
|
||||
/* } */
|
||||
/* if (ib>0) { */
|
||||
/* iframe++; */
|
||||
/* // cout << ib << "-" << endl; */
|
||||
/* return (char*)afifo_cont; */
|
||||
/* } else { */
|
||||
/* delete [] afifo_cont; */
|
||||
/* return NULL; */
|
||||
/* } */
|
||||
/* } */
|
||||
/* return NULL; */
|
||||
/* }; */
|
||||
|
||||
|
||||
virtual char *readNextFrame(ifstream &filebin) {
|
||||
int ff=-1, np=-1;
|
||||
return readNextFrame(filebin, ff, np);
|
||||
};
|
||||
|
||||
virtual char *readNextFrame(ifstream &filebin, int &ff) {
|
||||
int np=-1;
|
||||
return readNextFrame(filebin, ff, np);
|
||||
};
|
||||
|
||||
virtual char *readNextFrame(ifstream &filebin, int& ff, int &np) {
|
||||
char *data=new char[dataSize];
|
||||
char *d=readNextFrame(filebin, ff, np, data);
|
||||
if (d==NULL) {delete [] data; data=NULL;}
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
virtual char *readNextFrame(ifstream &filebin, int& ff, int &np, char *data) {
|
||||
char *retval=0;
|
||||
int nd;
|
||||
int fnum = -1;
|
||||
np=0;
|
||||
int pn;
|
||||
|
||||
// cout << dataSize << endl;
|
||||
if (ff>=0)
|
||||
fnum=ff;
|
||||
|
||||
if (filebin.is_open()) {
|
||||
if (filebin.read(data, dataSize) ){
|
||||
ff=getFrameNumber(data);
|
||||
np=getPacketNumber(data);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func
|
||||
\param data pointer to the memory to be analyzed
|
||||
\param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot
|
||||
\param dsize size of the memory slot to be analyzed
|
||||
\returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found
|
||||
|
||||
*/
|
||||
virtual char *findNextFrame(char *data, int &ndata, int dsize){
|
||||
if (dsize<dataSize) ndata=dsize;
|
||||
else ndata=dataSize;
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//int getPacketNumber(int x, int y) {return dataMap[y][x]/packetSize;};
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
176
slsDetectorCalibration/dataStructures/moench03T1ReorderedData.h
Normal file
176
slsDetectorCalibration/dataStructures/moench03T1ReorderedData.h
Normal file
@ -0,0 +1,176 @@
|
||||
#ifndef MOENCH03T1REORDERED_H
|
||||
#define MOENCH03T1REORDERED_H
|
||||
#include "slsDetectorData.h"
|
||||
|
||||
|
||||
class moench03T1ReorderedData : public slsDetectorData<uint16_t> {
|
||||
|
||||
private:
|
||||
|
||||
public:
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Implements the slsReceiverData structure for the moench02 prototype read out by a module i.e. using the slsReceiver
|
||||
(160x160 pixels, 40 packets 1286 large etc.)
|
||||
\param c crosstalk parameter for the output buffer
|
||||
|
||||
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
|
||||
*/
|
||||
moench03T1ReorderedData(): slsDetectorData<uint16_t>(400, 400, 2*400*400+2*8) {
|
||||
for (int iy=0; iy<400; iy++)
|
||||
for (int ix=0; ix<400; ix++)
|
||||
dataMap[iy][ix]=2*8+2*(iy*400+ix);
|
||||
|
||||
int ibyte;
|
||||
for (ibyte=0; ibyte<8; ibyte++){
|
||||
xmap[ibyte]=-1;
|
||||
ymap[ibyte]=-1;
|
||||
}
|
||||
for (ibyte=0; ibyte<400*400; ibyte++){
|
||||
xmap[ibyte+8]=ibyte%400;
|
||||
ymap[ibyte+8]=ibyte/400;
|
||||
}
|
||||
|
||||
// cout << "data struct created" << endl;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Returns the frame number for the given dataset. Purely virtual func.
|
||||
\param buff pointer to the dataset
|
||||
\returns frame number
|
||||
|
||||
*/
|
||||
|
||||
/* class jfrau_packet_header_t { */
|
||||
/* public: */
|
||||
/* unsigned char reserved[4]; */
|
||||
/* unsigned char packetNumber[1]; */
|
||||
/* unsigned char frameNumber[3]; */
|
||||
/* unsigned char bunchid[8]; */
|
||||
/* }; */
|
||||
|
||||
|
||||
|
||||
int getFrameNumber(char *buff){return *((int*)buff);};
|
||||
|
||||
/* /\** */
|
||||
|
||||
/* Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func */
|
||||
/* \param data pointer to the memory to be analyzed */
|
||||
/* \param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot */
|
||||
/* \param dsize size of the memory slot to be analyzed */
|
||||
/* \returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found */
|
||||
|
||||
/* *\/ */
|
||||
/* virtual char *findNextFrame(char *data, int &ndata, int dsize){ndata=dsize; setDataSize(dsize); return data;}; */
|
||||
|
||||
|
||||
/* /\** */
|
||||
|
||||
/* Loops over a file stream until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors! */
|
||||
/* \param filebin input file stream (binary) */
|
||||
/* \returns pointer to the begin of the last good frame, NULL if no frame is found or last frame is incomplete */
|
||||
|
||||
/* *\/ */
|
||||
/* virtual char *readNextFrame(ifstream &filebin){ */
|
||||
/* // int afifo_length=0; */
|
||||
/* uint16_t *afifo_cont; */
|
||||
/* int ib=0; */
|
||||
/* if (filebin.is_open()) { */
|
||||
/* afifo_cont=new uint16_t[dataSize/2]; */
|
||||
/* while (filebin.read(((char*)afifo_cont)+ib,2)) { */
|
||||
/* ib+=2; */
|
||||
/* if (ib==dataSize) break; */
|
||||
/* } */
|
||||
/* if (ib>0) { */
|
||||
/* iframe++; */
|
||||
/* // cout << ib << "-" << endl; */
|
||||
/* return (char*)afifo_cont; */
|
||||
/* } else { */
|
||||
/* delete [] afifo_cont; */
|
||||
/* return NULL; */
|
||||
/* } */
|
||||
/* } */
|
||||
/* return NULL; */
|
||||
/* }; */
|
||||
|
||||
|
||||
virtual char *readNextFrame(ifstream &filebin) {
|
||||
int ff=-1, np=-1;
|
||||
return readNextFrame(filebin, ff, np);
|
||||
};
|
||||
|
||||
virtual char *readNextFrame(ifstream &filebin, int &ff) {
|
||||
int np=-1;
|
||||
return readNextFrame(filebin, ff, np);
|
||||
};
|
||||
|
||||
virtual char *readNextFrame(ifstream &filebin, int& ff, int &np) {
|
||||
char *data=new char[dataSize];
|
||||
char *d=readNextFrame(filebin, ff, np, data);
|
||||
if (d==NULL) {delete [] data; data=NULL;}
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
virtual char *readNextFrame(ifstream &filebin, int& ff, int &np, char *data) {
|
||||
char *retval=0;
|
||||
int nd;
|
||||
int fnum = -1;
|
||||
np=0;
|
||||
int pn;
|
||||
|
||||
if (ff>=0)
|
||||
fnum=ff;
|
||||
|
||||
if (filebin.is_open()) {
|
||||
if (filebin.read(data, dataSize) ){
|
||||
ff=getFrameNumber(data);
|
||||
np=40;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func
|
||||
\param data pointer to the memory to be analyzed
|
||||
\param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot
|
||||
\param dsize size of the memory slot to be analyzed
|
||||
\returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found
|
||||
|
||||
*/
|
||||
virtual char *findNextFrame(char *data, int &ndata, int dsize){
|
||||
if (dsize<dataSize) ndata=dsize;
|
||||
else ndata=dataSize;
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//int getPacketNumber(int x, int y) {return dataMap[y][x]/packetSize;};
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
268
slsDetectorCalibration/dataStructures/moench03T1ZmqDataNew.h
Normal file
268
slsDetectorCalibration/dataStructures/moench03T1ZmqDataNew.h
Normal file
@ -0,0 +1,268 @@
|
||||
#ifndef MOENCH03T1ZMQDATANEW_H
|
||||
#define MOENCH03T1ZMQDATANEW_H
|
||||
#include "slsDetectorData.h"
|
||||
|
||||
|
||||
class moench03T1ZmqDataNew : public slsDetectorData<uint16_t> {
|
||||
|
||||
private:
|
||||
|
||||
// int iframe;
|
||||
int nadc;
|
||||
int sc_width;
|
||||
int sc_height;
|
||||
const int nSamples;
|
||||
const int offset;
|
||||
|
||||
public:
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Implements the slsReceiverData structure for the moench02 prototype read out by a module i.e. using the slsReceiver
|
||||
(160x160 pixels, 40 packets 1286 large etc.)
|
||||
\param c crosstalk parameter for the output buffer
|
||||
|
||||
*/
|
||||
moench03T1ZmqDataNew(int ns=5000): slsDetectorData<uint16_t>(400, 400, ns*32*2+sizeof(int)), nSamples(ns), offset(sizeof(int)) {
|
||||
|
||||
int nadc=32;
|
||||
int sc_width=25;
|
||||
int sc_height=200;
|
||||
|
||||
int adc_nr[32]={300,325,350,375,300,325,350,375, \
|
||||
200,225,250,275,200,225,250,275,\
|
||||
100,125,150,175,100,125,150,175,\
|
||||
0,25,50,75,0,25,50,75};
|
||||
|
||||
int row, col;
|
||||
|
||||
int isample;
|
||||
int iadc;
|
||||
int ix, iy;
|
||||
|
||||
int npackets=40;
|
||||
int i;
|
||||
int adc4(0);
|
||||
|
||||
for (int ip=0; ip<npackets; ip++) {
|
||||
for (int is=0; is<128; is++) {
|
||||
|
||||
for (iadc=0; iadc<nadc; iadc++) {
|
||||
i=128*ip+is;
|
||||
adc4=(int)iadc/4;
|
||||
if (i<sc_width*sc_height) {
|
||||
// for (int i=0; i<sc_width*sc_height; i++) {
|
||||
col=adc_nr[iadc]+(i%sc_width);
|
||||
if (adc4%2==0) {
|
||||
row=199-i/sc_width;
|
||||
} else {
|
||||
row=200+i/sc_width;
|
||||
}
|
||||
dataMap[row][col]=(nadc*i+iadc)*2+offset;//+16*(ip+1);
|
||||
if (dataMap[row][col]<0 || dataMap[row][col]>=dataSize)
|
||||
cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int ii=0;
|
||||
|
||||
for (i=0; i< dataSize; i++) {
|
||||
if (i<offset) {
|
||||
//header! */
|
||||
xmap[i]=-1;
|
||||
ymap[i]=-1;
|
||||
} else {
|
||||
// ii=ibyte+128*32*ipacket;
|
||||
isample=ii/nadc;
|
||||
if (isample<nSamples) {
|
||||
iadc=ii%nadc;
|
||||
adc4 = (int)iadc/4;
|
||||
ix=isample%sc_width;
|
||||
iy=isample/sc_width;
|
||||
if (adc4%2==0) {
|
||||
xmap[i]=adc_nr[iadc]+ix;
|
||||
ymap[i]=ny/2-1-iy;
|
||||
} else {
|
||||
xmap[i]=adc_nr[iadc]+ix;
|
||||
ymap[i]=ny/2+iy;
|
||||
}
|
||||
}
|
||||
|
||||
ii++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// iframe=0;
|
||||
// cout << "data struct created" << endl;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Returns the frame number for the given dataset. Purely virtual func.
|
||||
\param buff pointer to the dataset
|
||||
\returns frame number
|
||||
|
||||
*/
|
||||
|
||||
/* class jfrau_packet_header_t { */
|
||||
/* public: */
|
||||
/* unsigned char reserved[4]; */
|
||||
/* unsigned char packetNumber[1]; */
|
||||
/* unsigned char frameNumber[3]; */
|
||||
/* unsigned char bunchid[8]; */
|
||||
/* }; */
|
||||
|
||||
|
||||
|
||||
int getFrameNumber(char *buff){return *((int*)buff);};//*((int*)(buff+5))&0xffffff;};
|
||||
|
||||
/**
|
||||
|
||||
Returns the packet number for the given dataset. purely virtual func
|
||||
\param buff pointer to the dataset
|
||||
\returns packet number number
|
||||
|
||||
|
||||
|
||||
*/
|
||||
int getPacketNumber(char *buff){return 0;}//((*(((int*)(buff+4))))&0xff)+1;};
|
||||
|
||||
/* /\** */
|
||||
|
||||
/* Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func */
|
||||
/* \param data pointer to the memory to be analyzed */
|
||||
/* \param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot */
|
||||
/* \param dsize size of the memory slot to be analyzed */
|
||||
/* \returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found */
|
||||
|
||||
/* *\/ */
|
||||
/* virtual char *findNextFrame(char *data, int &ndata, int dsize){ndata=dsize; setDataSize(dsize); return data;}; */
|
||||
|
||||
|
||||
/* /\** */
|
||||
|
||||
/* Loops over a file stream until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors! */
|
||||
/* \param filebin input file stream (binary) */
|
||||
/* \returns pointer to the begin of the last good frame, NULL if no frame is found or last frame is incomplete */
|
||||
|
||||
/* *\/ */
|
||||
/* virtual char *readNextFrame(ifstream &filebin){ */
|
||||
/* // int afifo_length=0; */
|
||||
/* uint16_t *afifo_cont; */
|
||||
/* int ib=0; */
|
||||
/* if (filebin.is_open()) { */
|
||||
/* afifo_cont=new uint16_t[dataSize/2]; */
|
||||
/* while (filebin.read(((char*)afifo_cont)+ib,2)) { */
|
||||
/* ib+=2; */
|
||||
/* if (ib==dataSize) break; */
|
||||
/* } */
|
||||
/* if (ib>0) { */
|
||||
/* iframe++; */
|
||||
/* // cout << ib << "-" << endl; */
|
||||
/* return (char*)afifo_cont; */
|
||||
/* } else { */
|
||||
/* delete [] afifo_cont; */
|
||||
/* return NULL; */
|
||||
/* } */
|
||||
/* } */
|
||||
/* return NULL; */
|
||||
/* }; */
|
||||
|
||||
|
||||
virtual char *readNextFrame(ifstream &filebin) {
|
||||
int ff=-1, np=-1;
|
||||
return readNextFrame(filebin, ff, np);
|
||||
};
|
||||
|
||||
virtual char *readNextFrame(ifstream &filebin, int &ff) {
|
||||
int np=-1;
|
||||
return readNextFrame(filebin, ff, np);
|
||||
};
|
||||
|
||||
virtual char *readNextFrame(ifstream &filebin, int& ff, int &np) {
|
||||
char *data=new char[32*2*nSamples];
|
||||
char *d=readNextFrame(filebin, ff, np, data);
|
||||
if (d==NULL) {delete [] data; data=NULL;}
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
virtual char *readNextFrame(ifstream &filebin, int& ff, int &np, char *data) {
|
||||
char *retval=0;
|
||||
int nd;
|
||||
int fnum = -1;
|
||||
np=0;
|
||||
int pn;
|
||||
|
||||
|
||||
if (ff>=0)
|
||||
fnum=ff;
|
||||
|
||||
if (filebin.is_open()) {
|
||||
if (filebin.read(data, 32*2*nSamples) ){
|
||||
// iframe++;
|
||||
//ff=iframe;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func
|
||||
\param data pointer to the memory to be analyzed
|
||||
\param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot
|
||||
\param dsize size of the memory slot to be analyzed
|
||||
\returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found
|
||||
|
||||
*/
|
||||
virtual char *findNextFrame(char *data, int &ndata, int dsize){
|
||||
if (dsize<32*2*nSamples) ndata=dsize;
|
||||
else ndata=32*2*nSamples;
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// virtual int setFrameNumber(int ff){iframe=ff};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int getPacketNumber(int x, int y) {return 0;};
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
180
slsDetectorCalibration/dataStructures/moench03TCtbData.h
Normal file
180
slsDetectorCalibration/dataStructures/moench03TCtbData.h
Normal file
@ -0,0 +1,180 @@
|
||||
#ifndef MOENCH03TCTBDATA_H
|
||||
#define MOENCH03TCTBDATA_H
|
||||
#include "slsDetectorData.h"
|
||||
|
||||
|
||||
|
||||
class moench03TCtbData : public slsDetectorData<uint16_t> {
|
||||
|
||||
private:
|
||||
|
||||
int iframe;
|
||||
int nadc;
|
||||
int sc_width;
|
||||
int sc_height;
|
||||
public:
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Implements the slsReceiverData structure for the moench02 prototype read out by a module i.e. using the slsReceiver
|
||||
(160x160 pixels, 40 packets 1286 large etc.)
|
||||
\param c crosstalk parameter for the output buffer
|
||||
|
||||
*/
|
||||
|
||||
|
||||
moench03TCtbData(int ns=5000): slsDetectorData<uint16_t>(400, 400, ns*2*32, NULL, NULL) , nadc(32), sc_width(25), sc_height(200) {
|
||||
|
||||
|
||||
int row, col;
|
||||
|
||||
int isample;
|
||||
int iadc;
|
||||
int ix, iy;
|
||||
|
||||
|
||||
|
||||
int adc_nr[32]={300,325,350,375,300,325,350,375, \
|
||||
200,225,250,275,200,225,250,275,\
|
||||
100,125,150,175,100,125,150,175,\
|
||||
0,25,50,75,0,25,50,75};
|
||||
|
||||
|
||||
|
||||
/* int adc_nr[32]={200,225,250,275,300,325,350,375,\ */
|
||||
/* 0,25,50,75,100,125,150,175,\ */
|
||||
/* 175,150,125,100,75,50,25,0,\ */
|
||||
/* 375,350,325,300,275,250,225,200}; */
|
||||
|
||||
|
||||
for (iadc=0; iadc<nadc; iadc++) {
|
||||
for (int i=0; i<sc_width*sc_height; i++) {
|
||||
col=adc_nr[iadc]+(i%sc_width);
|
||||
if (iadc<16) {
|
||||
row=199-i/sc_width;
|
||||
} else {
|
||||
row=200+i/sc_width;
|
||||
}
|
||||
dataMap[row][col]=(nadc*i+iadc)*2;
|
||||
if (dataMap[row][col]<0 || dataMap[row][col]>=2*400*400)
|
||||
cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl;
|
||||
|
||||
}
|
||||
}
|
||||
int adc4;
|
||||
for (int i=0; i<nx*ny; i++) {
|
||||
isample=i/nadc;
|
||||
iadc=i%nadc;
|
||||
ix=isample%sc_width;
|
||||
iy=isample/sc_width;
|
||||
adc4 = (int)iadc/4;
|
||||
// if (iadc<(nadc/2)) {
|
||||
if (adc4%2==0) {
|
||||
xmap[i]=adc_nr[iadc]+ix;
|
||||
ymap[i]=ny/2-1-iy;
|
||||
} else {
|
||||
xmap[i]=adc_nr[iadc]+ix;
|
||||
ymap[i]=ny/2+iy;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/* for (int i=0; i<nx*ny; i++) { */
|
||||
/* isample=i/nadc; */
|
||||
/* iadc=i%nadc; */
|
||||
/* ix=isample%sc_width; */
|
||||
/* iy=isample/sc_width; */
|
||||
/* if (iadc<(nadc/2)) { */
|
||||
/* xmap[i]=adc_nr[iadc]+ix; */
|
||||
/* ymap[i]=ny/2-1-iy; */
|
||||
/* } else { */
|
||||
/* xmap[i]=adc_nr[iadc]+ix; */
|
||||
/* ymap[i]=ny/2+iy; */
|
||||
/* } */
|
||||
|
||||
|
||||
/* } */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
iframe=0;
|
||||
// cout << "data struct created" << endl;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Returns the frame number for the given dataset. Purely virtual func.
|
||||
\param buff pointer to the dataset
|
||||
\returns frame number
|
||||
|
||||
*/
|
||||
|
||||
|
||||
virtual int getFrameNumber(char *buff){(void)buff; return iframe;};
|
||||
|
||||
/**
|
||||
|
||||
Returns the packet number for the given dataset. purely virtual func
|
||||
\param buff pointer to the dataset
|
||||
\returns packet number number
|
||||
|
||||
|
||||
virtual int getPacketNumber(char *buff)=0;
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
|
||||
Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func
|
||||
\param data pointer to the memory to be analyzed
|
||||
\param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot
|
||||
\param dsize size of the memory slot to be analyzed
|
||||
\returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found
|
||||
|
||||
*/
|
||||
virtual char *findNextFrame(char *data, int &ndata, int dsize){ndata=dsize; setDataSize(dsize); return data;};
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Loops over a file stream until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors!
|
||||
\param filebin input file stream (binary)
|
||||
\returns pointer to the begin of the last good frame, NULL if no frame is found or last frame is incomplete
|
||||
|
||||
*/
|
||||
virtual char *readNextFrame(ifstream &filebin){
|
||||
// int afifo_length=0;
|
||||
uint16_t *afifo_cont;
|
||||
int ib=0;
|
||||
if (filebin.is_open()) {
|
||||
afifo_cont=new uint16_t[dataSize/2];
|
||||
while (filebin.read(((char*)afifo_cont)+ib,2)) {
|
||||
ib+=2;
|
||||
if (ib==dataSize) break;
|
||||
}
|
||||
if (ib>0) {
|
||||
iframe++;
|
||||
// cout << ib << "-" << endl;
|
||||
return (char*)afifo_cont;
|
||||
} else {
|
||||
delete [] afifo_cont;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
291
slsDetectorCalibration/dataStructures/moench04CtbReceiverData.h
Normal file
291
slsDetectorCalibration/dataStructures/moench04CtbReceiverData.h
Normal file
@ -0,0 +1,291 @@
|
||||
#ifndef MOENCH04RECDATA_H
|
||||
#define MOENCH04RECDATA_H
|
||||
#include "slsDetectorData.h"
|
||||
|
||||
//#define VERSION_V2
|
||||
/**
|
||||
@short structure for a Detector Packet or Image Header
|
||||
@li frameNumber is the frame number
|
||||
@li expLength is the subframe number (32 bit eiger) or real time exposure time in 100ns (others)
|
||||
@li packetNumber is the packet number
|
||||
@li bunchId is the bunch id from beamline
|
||||
@li timestamp is the time stamp with 10 MHz clock
|
||||
@li modId is the unique module id (unique even for left, right, top, bottom)
|
||||
@li xCoord is the x coordinate in the complete detector system
|
||||
@li yCoord is the y coordinate in the complete detector system
|
||||
@li zCoord is the z coordinate in the complete detector system
|
||||
@li debug is for debugging purposes
|
||||
@li roundRNumber is the round robin set number
|
||||
@li detType is the detector type see :: detectorType
|
||||
@li version is the version number of this structure format
|
||||
*/
|
||||
typedef struct {
|
||||
uint64_t frameNumber; /**< is the frame number */
|
||||
uint32_t expLength; /**< is the subframe number (32 bit eiger) or real time exposure time in 100ns (others) */
|
||||
uint32_t packetNumber; /**< is the packet number */
|
||||
uint64_t bunchId; /**< is the bunch id from beamline */
|
||||
uint64_t timestamp; /**< is the time stamp with 10 MHz clock */
|
||||
uint16_t modId; /**< is the unique module id (unique even for left, right, top, bottom) */
|
||||
uint16_t xCoord; /**< is the x coordinate in the complete detector system */
|
||||
uint16_t yCoord; /**< is the y coordinate in the complete detector system */
|
||||
uint16_t zCoord; /**< is the z coordinate in the complete detector system */
|
||||
uint32_t debug; /**< is for debugging purposes */
|
||||
uint16_t roundRNumber; /**< is the round robin set number */
|
||||
uint8_t detType; /**< is the detector type see :: detectorType */
|
||||
uint8_t version; /**< is the version number of this structure format */
|
||||
uint64_t packetCaught[8]; /**< is the version number of this structure format */
|
||||
|
||||
} sls_detector_header;
|
||||
|
||||
|
||||
|
||||
|
||||
class moench04ReceiverData : public slsDetectorData<uint16_t> {
|
||||
|
||||
private:
|
||||
|
||||
int iframe;
|
||||
int nadc;
|
||||
int sc_width;
|
||||
int sc_height;
|
||||
const int aSamples;
|
||||
const int dSamples;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Implements the slsReceiverData structure for the moench02 prototype read out by a module i.e. using the slsReceiver
|
||||
(160x160 pixels, 40 packets 1286 large etc.)
|
||||
\param c crosstalk parameter for the output buffer
|
||||
|
||||
*/
|
||||
moench04ReceiverData(int nas=5000, int nds=0): slsDetectorData<uint16_t>(400, 400, nas*2*32+sizeof(sls_detector_header)+nds*8), aSamples(nas), dSamples(nds) {
|
||||
|
||||
int nadc=32;
|
||||
int sc_width=25;
|
||||
int sc_height=200;
|
||||
|
||||
int adc_nr[32]={9, 8,11,10,13,12,15,14,1,0,3,2,5,4,7,6,23,22,21,20,19,18,17,16,31,30,29,28,27,26,25,24 };
|
||||
|
||||
int row, col;
|
||||
|
||||
int isample;
|
||||
int iadc;
|
||||
int ix, iy;
|
||||
|
||||
int npackets=40;
|
||||
int i;
|
||||
int adc4(0);
|
||||
|
||||
for (int ip=0; ip<npackets; ip++) {
|
||||
for (int is=0; is<128; is++) {
|
||||
|
||||
for (iadc=0; iadc<nadc; iadc++) {
|
||||
i=128*ip+is;
|
||||
adc4=(int)iadc/4;
|
||||
if (i<sc_width*sc_height) {
|
||||
// for (int i=0; i<sc_width*sc_height; i++) {
|
||||
col=(adc_nr[iadc]%16)*sc_width+(i%sc_width);
|
||||
// if (adc4%2==0) {
|
||||
if (iadc/16>0) {
|
||||
row=199-i/sc_width;
|
||||
} else {
|
||||
row=200+i/sc_width;
|
||||
}
|
||||
dataMap[row][col]=sizeof(sls_detector_header)+(nadc*i+iadc)*2;//+16*(ip+1);
|
||||
if (dataMap[row][col]<0 || dataMap[row][col]>=nSamples*2*32)
|
||||
cout << "Error: pointer " << dataMap[row][col] << " out of range "<< endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int ipacket;
|
||||
int ibyte;
|
||||
int ii=0;
|
||||
for (ibyte=0; ibyte<sizeof(sls_detector_header)/2; ibyte++){
|
||||
xmap[ibyte]=-1;
|
||||
ymap[ibyte]=-1;
|
||||
}
|
||||
/* int off=sizeof(sls_detector_header)/2; */
|
||||
|
||||
/* for (ibyte=0; ibyte<dataSize; ibyte++) { */
|
||||
|
||||
|
||||
/* for (ipacket=0; ipacket<npackets; ipacket++) { */
|
||||
/* for (ibyte=0; ibyte< 8192/2; ibyte++) { */
|
||||
/* i=ipacket*8208/2+ibyte; */
|
||||
/* isample=ii/nadc; */
|
||||
/* if (isample<nSamples) { */
|
||||
/* iadc=ii%nadc; */
|
||||
/* adc4 = (int)iadc/4; */
|
||||
/* ix=isample%sc_width; */
|
||||
/* iy=isample/sc_width; */
|
||||
/* if (adc4%2==0) { */
|
||||
/* xmap[i+off]=adc_nr[iadc]+ix; */
|
||||
/* ymap[i+off]=ny/2-1-iy; */
|
||||
/* } else { */
|
||||
/* xmap[i+off]=adc_nr[iadc]+ix; */
|
||||
/* ymap[i+off]=ny/2+iy; */
|
||||
/* } */
|
||||
/* } */
|
||||
/* ii++; */
|
||||
/* // } */
|
||||
/* } */
|
||||
/* } */
|
||||
|
||||
iframe=0;
|
||||
// cout << "data struct created" << endl;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Returns the frame number for the given dataset. Purely virtual func.
|
||||
\param buff pointer to the dataset
|
||||
\returns frame number
|
||||
|
||||
*/
|
||||
|
||||
/* class jfrau_packet_header_t { */
|
||||
/* public: */
|
||||
/* unsigned char reserved[4]; */
|
||||
/* unsigned char packetNumber[1]; */
|
||||
/* unsigned char frameNumber[3]; */
|
||||
/* unsigned char bunchid[8]; */
|
||||
/* }; */
|
||||
|
||||
|
||||
|
||||
int getFrameNumber(char *buff){return ((sls_detector_header*)buff)->frameNumber;};//*((int*)(buff+5))&0xffffff;};
|
||||
|
||||
/**
|
||||
|
||||
Returns the packet number for the given dataset. purely virtual func
|
||||
\param buff pointer to the dataset
|
||||
\returns packet number number
|
||||
|
||||
|
||||
|
||||
*/
|
||||
int getPacketNumber(char *buff){return ((sls_detector_header*)buff)->packetNumber;}//((*(((int*)(buff+4))))&0xff)+1;};
|
||||
|
||||
/* /\** */
|
||||
|
||||
/* Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func */
|
||||
/* \param data pointer to the memory to be analyzed */
|
||||
/* \param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot */
|
||||
/* \param dsize size of the memory slot to be analyzed */
|
||||
/* \returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found */
|
||||
|
||||
/* *\/ */
|
||||
/* virtual char *findNextFrame(char *data, int &ndata, int dsize){ndata=dsize; setDataSize(dsize); return data;}; */
|
||||
|
||||
|
||||
/* /\** */
|
||||
|
||||
/* Loops over a file stream until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors! */
|
||||
/* \param filebin input file stream (binary) */
|
||||
/* \returns pointer to the begin of the last good frame, NULL if no frame is found or last frame is incomplete */
|
||||
|
||||
/* *\/ */
|
||||
/* virtual char *readNextFrame(ifstream &filebin){ */
|
||||
/* // int afifo_length=0; */
|
||||
/* uint16_t *afifo_cont; */
|
||||
/* int ib=0; */
|
||||
/* if (filebin.is_open()) { */
|
||||
/* afifo_cont=new uint16_t[dataSize/2]; */
|
||||
/* while (filebin.read(((char*)afifo_cont)+ib,2)) { */
|
||||
/* ib+=2; */
|
||||
/* if (ib==dataSize) break; */
|
||||
/* } */
|
||||
/* if (ib>0) { */
|
||||
/* iframe++; */
|
||||
/* // cout << ib << "-" << endl; */
|
||||
/* return (char*)afifo_cont; */
|
||||
/* } else { */
|
||||
/* delete [] afifo_cont; */
|
||||
/* return NULL; */
|
||||
/* } */
|
||||
/* } */
|
||||
/* return NULL; */
|
||||
/* }; */
|
||||
|
||||
|
||||
virtual char *readNextFrame(ifstream &filebin) {
|
||||
int ff=-1, np=-1;
|
||||
return readNextFrame(filebin, ff, np);
|
||||
};
|
||||
|
||||
virtual char *readNextFrame(ifstream &filebin, int &ff) {
|
||||
int np=-1;
|
||||
return readNextFrame(filebin, ff, np);
|
||||
};
|
||||
|
||||
virtual char *readNextFrame(ifstream &filebin, int& ff, int &np) {
|
||||
char *data=new char[dataSize];
|
||||
char *d=readNextFrame(filebin, ff, np, data);
|
||||
if (d==NULL) {delete [] data; data=NULL;}
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
virtual char *readNextFrame(ifstream &filebin, int& ff, int &np, char *data) {
|
||||
char *retval=0;
|
||||
int nd;
|
||||
int fnum = -1;
|
||||
np=0;
|
||||
int pn;
|
||||
|
||||
// cout << dataSize << endl;
|
||||
if (ff>=0)
|
||||
fnum=ff;
|
||||
|
||||
if (filebin.is_open()) {
|
||||
if (filebin.read(data, dataSize) ){
|
||||
ff=getFrameNumber(data);
|
||||
np=getPacketNumber(data);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func
|
||||
\param data pointer to the memory to be analyzed
|
||||
\param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot
|
||||
\param dsize size of the memory slot to be analyzed
|
||||
\returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found
|
||||
|
||||
*/
|
||||
virtual char *findNextFrame(char *data, int &ndata, int dsize){
|
||||
if (dsize<dataSize) ndata=dsize;
|
||||
else ndata=dataSize;
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//int getPacketNumber(int x, int y) {return dataMap[y][x]/packetSize;};
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
338
slsDetectorCalibration/dataStructures/slsDetectorData.h
Normal file
338
slsDetectorCalibration/dataStructures/slsDetectorData.h
Normal file
@ -0,0 +1,338 @@
|
||||
#ifndef SLSDETECTORDATA_H
|
||||
#define SLSDETECTORDATA_H
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
template <class dataType>
|
||||
class slsDetectorData {
|
||||
|
||||
protected:
|
||||
const int nx; /**< Number of pixels in the x direction */
|
||||
const int ny; /**< Number of pixels in the y direction */
|
||||
int dataSize; /**<size of the data constituting one frame */
|
||||
int **dataMap; /**< Array of size nx*ny storing the pointers to the data in the dataset (as offset)*/
|
||||
dataType **dataMask; /**< Array of size nx*ny storing the polarity of the data in the dataset (should be 0 if no inversion is required, 0xffffffff is inversion is required) */
|
||||
int **dataROIMask; /**< Array of size nx*ny 1 if channel is good (or in the ROI), 0 if bad channel (or out of ROI) */
|
||||
int *xmap;
|
||||
int *ymap;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
|
||||
|
||||
General slsDetectors data structure. Works for data acquired using the slsDetectorReceiver. Can be generalized to other detectors (many virtual funcs).
|
||||
|
||||
Constructor (no error checking if datasize and offsets are compatible!)
|
||||
\param npx number of pixels in the x direction
|
||||
\param npy number of pixels in the y direction (1 for strips)
|
||||
\param dsize size of the data
|
||||
\param dMap array of size nx*ny storing the pointers to the data in the dataset (as offset)
|
||||
\param dMask Array of size nx*ny storing the polarity of the data in the dataset (should be 0 if no inversion is required, 0xffffffff is inversion is required)
|
||||
\param dROI Array of size nx*ny. The elements are 1s if the channel is good or in the ROI, 0 is bad or out of the ROI. NULL (default) means all 1s.
|
||||
|
||||
*/
|
||||
slsDetectorData(int npx, int npy, int dsize, int **dMap=NULL, dataType **dMask=NULL, int **dROI=NULL): nx(npx), ny(npy), dataSize(dsize) {
|
||||
|
||||
|
||||
xmap=new int[dsize/sizeof(dataType)];
|
||||
ymap=new int[dsize/sizeof(dataType)];
|
||||
|
||||
|
||||
// if (dataMask==NULL) {
|
||||
dataMask=new dataType*[ny];
|
||||
for(int i = 0; i < ny; i++) {
|
||||
dataMask[i] = new dataType[nx];
|
||||
}
|
||||
// }
|
||||
|
||||
// if (dataMap==NULL) {
|
||||
dataMap=new int*[ny];
|
||||
for(int i = 0; i < ny; i++) {
|
||||
dataMap[i] = new int[nx];
|
||||
}
|
||||
// }
|
||||
// if (dataROIMask==NULL) {
|
||||
dataROIMask=new int*[ny];
|
||||
for(int i = 0; i < ny; i++) {
|
||||
dataROIMask[i] = new int[nx];
|
||||
for (int j=0; j<nx; j++)
|
||||
dataROIMask[i][j]=1;
|
||||
}
|
||||
// }
|
||||
for (int ip=0; ip<dsize/sizeof(dataType); ip++){
|
||||
xmap[ip]=-1;
|
||||
ymap[ip]=-1;
|
||||
}
|
||||
|
||||
setDataMap(dMap);
|
||||
setDataMask(dMask);
|
||||
setDataROIMask(dROI);
|
||||
|
||||
};
|
||||
|
||||
virtual ~slsDetectorData() {
|
||||
for(int i = 0; i < ny; i++) {
|
||||
delete [] dataMap[i];
|
||||
delete [] dataMask[i];
|
||||
delete [] dataROIMask[i];
|
||||
}
|
||||
delete [] dataMap;
|
||||
delete [] dataMask;
|
||||
delete [] dataROIMask;
|
||||
delete [] xmap;
|
||||
delete [] ymap;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
defines the data map (as offset) - no error checking if datasize and offsets are compatible!
|
||||
\param dMap array of size nx*ny storing the pointers to the data in the dataset (as offset). If NULL (default),the data are arranged as if read out row by row (dataMap[iy][ix]=(iy*nx+ix)*sizeof(dataType);)
|
||||
*/
|
||||
void setDataMap(int **dMap=NULL) {
|
||||
|
||||
int ip=0;
|
||||
int ix, iy;
|
||||
if (dMap==NULL) {
|
||||
for (iy=0; iy<ny; iy++) {
|
||||
for (ix=0; ix<nx; ix++) {
|
||||
dataMap[iy][ix]=(iy*nx+ix)*sizeof(dataType);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//cout << "set dmap "<< dataMap << " " << dMap << endl;
|
||||
for (iy=0; iy<ny; iy++){
|
||||
// cout << iy << endl;
|
||||
for (ix=0; ix<nx; ix++) {
|
||||
dataMap[iy][ix]=dMap[iy][ix];
|
||||
// cout << ix << " " << iy << endl;
|
||||
/*ip=dataMap[ix][iy]/sizeof(dataType);
|
||||
xmap[ip]=ix;
|
||||
ymap[ip]=iy;Annaa*/
|
||||
}
|
||||
}
|
||||
}
|
||||
for (iy=0; iy<ny; iy++){
|
||||
for (ix=0; ix<nx; ix++) {
|
||||
ip=dataMap[iy][ix]/sizeof(dataType);
|
||||
xmap[ip]=ix;
|
||||
ymap[ip]=iy;
|
||||
}
|
||||
}
|
||||
|
||||
// cout << "nx:" <<nx << " ny:" << ny << endl;
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
defines the data mask i.e. the polarity of the data
|
||||
\param dMask Array of size nx*ny storing the polarity of the data in the dataset (should be 0 if no inversion is required, 0xffffffff is inversion is required)
|
||||
|
||||
*/
|
||||
void setDataMask(dataType **dMask=NULL){
|
||||
|
||||
if (dMask!=NULL) {
|
||||
|
||||
for (int iy=0; iy<ny; iy++)
|
||||
for (int ix=0; ix<nx; ix++)
|
||||
dataMask[iy][ix]=dMask[iy][ix];
|
||||
} else {
|
||||
for (int iy=0; iy<ny; iy++)
|
||||
for (int ix=0; ix<nx; ix++)
|
||||
dataMask[iy][ix]=0;
|
||||
}
|
||||
};
|
||||
/**
|
||||
defines the region of interest and/or the bad channels mask
|
||||
\param dROI Array of size nx*ny. The lements are 1s if the channel is good or in the ROI, 0 is bad or out of the ROI. NULL (default) means all 1s.
|
||||
|
||||
*/
|
||||
void setDataROIMask(int **dROI=NULL){
|
||||
|
||||
if (dROI!=NULL) {
|
||||
|
||||
for (int iy=0; iy<ny; iy++)
|
||||
for (int ix=0; ix<nx; ix++)
|
||||
dataROIMask[iy][ix]=dROI[iy][ix];
|
||||
} else {
|
||||
|
||||
for (int iy=0; iy<ny; iy++)
|
||||
for (int ix=0; ix<nx; ix++)
|
||||
dataROIMask[iy][ix]=1;
|
||||
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
Define bad channel or roi mask for a single channel
|
||||
\param ix channel x coordinate
|
||||
\param iy channel y coordinate (1 for strips)
|
||||
\param i 1 if pixel is good (or in the roi), 0 if bad
|
||||
\returns 1 if pixel is good, 0 if it's bad, -1 if pixel is out of range
|
||||
*/
|
||||
int setGood(int ix, int iy, int i=1) { if (ix>=0 && ix<nx && iy>=0 && iy<ny) dataROIMask[iy][ix]=i; return isGood(ix,iy);};
|
||||
/**
|
||||
Define bad channel or roi mask for a single channel
|
||||
\param ix channel x coordinate
|
||||
\param iy channel y coordinate (1 for strips)
|
||||
\returns 1 if pixel is good, 0 if it's bad, -1 if pixel is out of range
|
||||
*/
|
||||
int isGood(int ix, int iy) { if (ix>=0 && ix<nx && iy>=0 && iy<ny) return dataROIMask[iy][ix]; else return -1;};
|
||||
|
||||
/**
|
||||
Returns detector size in x,y
|
||||
\param npx reference to number of channels in x
|
||||
\param npy reference to number of channels in y (will be 1 for strips)
|
||||
\returns total number of channels
|
||||
*/
|
||||
int getDetectorSize(int &npx, int &npy){npx=nx; npy=ny; return nx*ny;};
|
||||
|
||||
/** Returns the size of the data frame */
|
||||
int getDataSize() {return dataSize;};
|
||||
|
||||
/** changes the size of the data frame */
|
||||
int setDataSize(int d) {dataSize=d; return dataSize;};
|
||||
|
||||
|
||||
virtual void getPixel(int ip, int &x, int &y) {x=xmap[ip]; y=ymap[ip];};
|
||||
|
||||
virtual dataType **getData(char *ptr, int dsize=-1) {
|
||||
|
||||
dataType **data;
|
||||
int ix,iy;
|
||||
data=new dataType*[ny];
|
||||
for(int i = 0; i < ny; i++) {
|
||||
data[i]=new dataType[nx];
|
||||
}
|
||||
if (dsize<=0 || dsize>dataSize) dsize=dataSize;
|
||||
for (int ip=0; ip<(dsize/sizeof(dataType)); ip++) {
|
||||
getPixel(ip,ix,iy);
|
||||
if (ix>=0 && ix<nx && iy>=0 && iy<ny) {
|
||||
data[iy][ix]=getChannel(ptr,ix,iy);
|
||||
}
|
||||
}
|
||||
return data;
|
||||
|
||||
};
|
||||
|
||||
virtual double **getImage(char *ptr, int dsize=-1) {
|
||||
|
||||
double **data;
|
||||
int ix,iy;
|
||||
data=new double*[ny];
|
||||
for(int i = 0; i < ny; i++) {
|
||||
data[i]=new double[nx];
|
||||
}
|
||||
if (dsize<=0 || dsize>dataSize) dsize=dataSize;
|
||||
for (int ip=0; ip<(dsize/sizeof(dataType)); ip++) {
|
||||
getPixel(ip,ix,iy);
|
||||
if (ix>=0 && ix<nx && iy>=0 && iy<ny) {
|
||||
data[iy][ix]=getValue(ptr,ix,iy);
|
||||
}
|
||||
}
|
||||
return data;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
Returns the value of the selected channel for the given dataset. Virtual function, can be overloaded.
|
||||
\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
|
||||
|
||||
*/
|
||||
virtual dataType getChannel(char *data, int ix, int iy=0) {
|
||||
dataType m=0, d=0;
|
||||
if (ix>=0 && ix<nx && iy>=0 && iy<ny && dataMap[iy][ix]>=0 && dataMap[iy][ix]<dataSize) {
|
||||
// cout << ix << " " << iy << " " ;
|
||||
//cout << dataMap[ix][iy] << " " << (void*)data << " " << dataSize<< endl;
|
||||
m=dataMask[iy][ix];
|
||||
d=*((dataType*)(data+dataMap[iy][ix]));
|
||||
}
|
||||
return d^m;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Returns the value of the selected channel for the given dataset. Virtual function, can be overloaded.
|
||||
\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 or -1 if its a missing packet
|
||||
|
||||
*/
|
||||
|
||||
virtual int getChannelwithMissingPackets(char *data, int ix, int iy) {
|
||||
return 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
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;*/
|
||||
return (double)getChannel(data, ix, iy);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
Returns the frame number for the given dataset. Purely virtual func.
|
||||
\param buff pointer to the dataset
|
||||
\returns frame number
|
||||
|
||||
*/
|
||||
virtual int getFrameNumber(char *buff)=0;
|
||||
|
||||
/**
|
||||
|
||||
Returns the packet number for the given dataset. purely virtual func
|
||||
\param buff pointer to the dataset
|
||||
\returns packet number number
|
||||
|
||||
|
||||
virtual int getPacketNumber(char *buff)=0;
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
|
||||
Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). purely virtual func
|
||||
\param data pointer to the memory to be analyzed
|
||||
\param ndata reference to the amount of data found for the frame, in case the frame is incomplete at the end of the memory slot
|
||||
\param dsize size of the memory slot to be analyzed
|
||||
\returns pointer to the beginning of the last good frame (might be incomplete if ndata smaller than dataSize), or NULL if no frame is found
|
||||
|
||||
*/
|
||||
virtual char *findNextFrame(char *data, int &ndata, int dsize)=0;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Loops over a file stream until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors!
|
||||
\param filebin input file stream (binary)
|
||||
\returns pointer to the begin of the last good frame, NULL if no frame is found or last frame is incomplete
|
||||
|
||||
*/
|
||||
virtual char *readNextFrame(ifstream &filebin)=0;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
238
slsDetectorCalibration/dataStructures/slsReceiverData.h
Normal file
238
slsDetectorCalibration/dataStructures/slsReceiverData.h
Normal file
@ -0,0 +1,238 @@
|
||||
#ifndef SLSRECEIVERDATA_H
|
||||
#define SLSRECEIVERDATA_H
|
||||
|
||||
#include "slsDetectorData.h"
|
||||
#include <cstring>
|
||||
#include <stdlib.h> // exit()
|
||||
template <class dataType>
|
||||
class slsReceiverData : public slsDetectorData<dataType> {
|
||||
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
slsReceiver data structure. Works for data acquired using the slsDetectorReceiver subdivided in different packets with headers and footers.
|
||||
Inherits and implements slsDetectorData.
|
||||
|
||||
Constructor (no error checking if datasize and offsets are compatible!)
|
||||
\param npx number of pixels in the x direction
|
||||
\param npy number of pixels in the y direction (1 for strips)
|
||||
\param np number of packets
|
||||
\param psize packets size
|
||||
\param dMap array of size nx*ny storing the pointers to the data in the dataset (as offset)
|
||||
\param dMask Array of size nx*ny storing the polarity of the data in the dataset (should be 0 if no inversion is required, 0xffffffff is inversion is required)
|
||||
\param dROI Array of size nx*ny. The elements are 1s if the channel is good or in the ROI, 0 is bad or out of the ROI. NULL (default) means all 1s.
|
||||
|
||||
*/
|
||||
slsReceiverData(int npx, int npy, int np, int psize, int **dMap=NULL, dataType **dMask=NULL, int **dROI=NULL): slsDetectorData<dataType>(npx, npy, np*psize, dMap, dMask, dROI), nPackets(np), packetSize(psize) {};
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Returns the frame number for the given dataset. Virtual func: works for slsDetectorReceiver data (also for each packet), but can be overloaded.
|
||||
\param buff pointer to the dataset
|
||||
\returns frame number
|
||||
|
||||
*/
|
||||
|
||||
virtual int getFrameNumber(char *buff){return ((*(int*)buff)&(0xffffff00))>>8;};
|
||||
|
||||
/**
|
||||
|
||||
Returns the packet number for the given dataset. Virtual func: works for slsDetectorReceiver packets, but can be overloaded.
|
||||
\param buff pointer to the dataset
|
||||
\returns packet number number
|
||||
|
||||
*/
|
||||
|
||||
virtual int getPacketNumber(char *buff){return (*(int*)buff)&0xff;};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Loops over a memory slot until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors!
|
||||
\param data pointer to the memory to be analyzed
|
||||
\param ndata size of frame returned
|
||||
\param dsize size of the memory slot to be analyzed
|
||||
\returns pointer to the first packet of the last good frame (might be incomplete if npackets lower than the number of packets), or NULL if no frame is found
|
||||
|
||||
*/
|
||||
|
||||
virtual char *findNextFrame(char *data, int &ndata, int dsize) {
|
||||
char *retval=NULL, *p=data;
|
||||
int dd=0;
|
||||
int fn, fnum=-1, np=0, pnum=-1;
|
||||
while (dd<=(dsize-packetSize)) {
|
||||
pnum=getPacketNumber(p);
|
||||
fn=getFrameNumber(p);
|
||||
//cout <<"fnum:"<<fn<<" pnum:"<<pnum<<" np:"<< np << "\t";
|
||||
|
||||
if (pnum<1 || pnum>nPackets) {
|
||||
//cout << "Bad packet number " << pnum << " frame "<< fn << endl;
|
||||
retval=NULL;
|
||||
np=0;
|
||||
} else if (pnum==1) {
|
||||
retval=p;
|
||||
if (np>0)
|
||||
/*cout << "*Incomplete frame number " << fnum << endl;*/
|
||||
np=0;
|
||||
fnum=fn;
|
||||
} else if (fn!=fnum) {
|
||||
if (fnum!=-1) {
|
||||
/* cout << " **Incomplete frame number " << fnum << " pnum " << pnum << " " << getFrameNumber(p) << endl;*/
|
||||
retval=NULL;
|
||||
}
|
||||
np=0;
|
||||
}
|
||||
p+=packetSize;
|
||||
dd+=packetSize;
|
||||
np++;
|
||||
//cout <<"fnum:"<<fn<<" pnum:"<<pnum<<" np:"<< np << "\t";
|
||||
// cout << pnum << " " << fn << " " << np << " " << dd << " " << dsize << endl;
|
||||
if (np==nPackets){
|
||||
if (pnum==nPackets) {
|
||||
//cprintf(BG_GREEN, "Frame Found\n");
|
||||
// cout << "Frame found!" << endl;
|
||||
break;
|
||||
} else {
|
||||
//cprintf(BG_RED, "Too many packets for this frame! fnum:%d, pnum:%d np:%d\n",fnum,pnum,np);
|
||||
cout << "Too many packets for this frame! "<< fnum << " " << pnum << endl;//cprintf(BG_RED,"Exiting\n");exit(-1);
|
||||
retval=NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (np<nPackets) {
|
||||
if (np>0){
|
||||
//cprintf(BG_RED, "Too few packets for this frame! fnum:%d, pnum:%d np:%d\n",fnum,pnum,np);
|
||||
cout << "Too few packets for this frame! "<< fnum << " " << pnum << " " << np <<endl;//cprintf(BG_RED,"Exiting\n");exit(-1);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
ndata=np*packetSize;
|
||||
// cout << "return " << ndata << endl;
|
||||
return retval;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Loops over a file stream until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors!
|
||||
\param filebin input file stream (binary)
|
||||
\returns pointer to the first packet of the last good frame, NULL if no frame is found or last frame is incomplete
|
||||
|
||||
*/
|
||||
|
||||
virtual char *readNextFrame(ifstream &filebin) {
|
||||
char *data=new char[packetSize*nPackets];
|
||||
char *retval=0;
|
||||
int np=0, nd;
|
||||
|
||||
if (filebin.is_open()) {
|
||||
while (filebin.read(data+np*packetSize,packetSize)) {
|
||||
|
||||
if (np==(nPackets-1)) {
|
||||
|
||||
retval=findNextFrame(data,nd,packetSize*nPackets);
|
||||
np=nd/packetSize;
|
||||
// cout << np << endl;
|
||||
|
||||
|
||||
if (retval==data && np==nPackets) {
|
||||
// cout << "-" << endl;
|
||||
return data;
|
||||
|
||||
} else if (np>nPackets) {
|
||||
cout << "too many packets!!!!!!!!!!" << endl;
|
||||
delete [] data;
|
||||
return NULL;
|
||||
} else if (retval!=NULL) {
|
||||
// cout << "+" << endl;;
|
||||
for (int ip=0; ip<np; ip++)
|
||||
memcpy(data+ip*packetSize,retval+ip*packetSize,packetSize);
|
||||
}
|
||||
|
||||
} else if (np>nPackets) {
|
||||
cout << "*******too many packets!!!!!!!!!!" << endl;
|
||||
delete [] data;
|
||||
return NULL;
|
||||
} else {
|
||||
// cout << "." << endl;;
|
||||
np++;
|
||||
}
|
||||
}
|
||||
}
|
||||
delete [] data;
|
||||
return NULL;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Loops over a file stream until a complete frame is found (i.e. all packets 0 to nPackets, same frame number). Can be overloaded for different kind of detectors!
|
||||
\param filebin input file stream (binary)
|
||||
\param fnum frame number of frame returned
|
||||
\returns pointer to the first packet of the last good frame, NULL if no frame is found or last frame is incomplete
|
||||
|
||||
*/
|
||||
|
||||
virtual char *readNextFrame(ifstream &filebin, int& fnum) {
|
||||
char *data=new char[packetSize*nPackets];
|
||||
char *retval=0;
|
||||
int np=0, nd;
|
||||
fnum = -1;
|
||||
|
||||
if (filebin.is_open()) {
|
||||
while (filebin.read(data+np*packetSize,packetSize)) {
|
||||
|
||||
if (np==(nPackets-1)) {
|
||||
|
||||
fnum=getFrameNumber(data); //cout << "fnum:"<<fnum<<endl;
|
||||
retval=findNextFrame(data,nd,packetSize*nPackets);
|
||||
np=nd/packetSize;
|
||||
// cout << np << endl;
|
||||
|
||||
|
||||
if (retval==data && np==nPackets) {
|
||||
// cout << "-" << endl;
|
||||
return data;
|
||||
|
||||
} else if (np>nPackets) {
|
||||
cout << "too many packets!!!!!!!!!!" << endl;
|
||||
delete [] data;
|
||||
return NULL;
|
||||
} else if (retval!=NULL) {
|
||||
// cout << "+" << endl;;
|
||||
for (int ip=0; ip<np; ip++)
|
||||
memcpy(data+ip*packetSize,retval+ip*packetSize,packetSize);
|
||||
}
|
||||
|
||||
} else if (np>nPackets) {
|
||||
cout << "*******too many packets!!!!!!!!!!" << endl;
|
||||
delete [] data;
|
||||
return NULL;
|
||||
} else {
|
||||
// cout << "." << endl;;
|
||||
np++;
|
||||
//cout<<"np:"<<np<<endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
delete [] data;
|
||||
return NULL;
|
||||
};
|
||||
|
||||
virtual int* readNextFramewithMissingPackets(ifstream &filebin, int& fnum) {return NULL;}
|
||||
virtual void getChannelArray(double* data, char* buffer){};
|
||||
virtual int* readNextFrameOnlyData(ifstream &filebin, int& fnum) {return NULL;};
|
||||
virtual int* decodeData(int* datain) {return NULL;};
|
||||
virtual int getPacketNumber(int x, int y) {return 0;};
|
||||
|
||||
protected:
|
||||
const int nPackets; /**<number of UDP packets constituting one frame */
|
||||
const int packetSize; /**< size of a udp packet */
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user