reverted singlephotondetector and slreceiverdata

git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorCalibration@51 113b152e-814d-439b-b186-022a431db7b5
This commit is contained in:
l_maliakal_d 2014-04-10 12:48:55 +00:00
parent f8aeb91752
commit c352fbec21
2 changed files with 112 additions and 109 deletions

View File

@ -345,10 +345,14 @@ class singlePhotonDetector {
char tit[100]; char tit[100];
sprintf(tit,"data[%d]/D",clusterSize*clusterSizeY); sprintf(tit,"data[%d]/D",clusterSize*clusterSizeY);
tall->Branch("data",cluster->data,tit); tall->Branch("data",cluster->data,tit);
// tall->Branch("pedestal",&(cluster->ped),"pedestal/D"); tall->Branch("pedestal",&(cluster->ped),"pedestal/D");
// tall->Branch("rms",&(cluster->rms),"rms/D"); tall->Branch("rms",&(cluster->rms),"rms/D");
return tall; return tall;
}; };
#else
/** write cluster to filer*/
void writeCluster(FILE* myFile){cluster->write(myFile);};
#endif #endif

View File

@ -7,9 +7,9 @@ template <class dataType>
class slsReceiverData : public slsDetectorData<dataType> { class slsReceiverData : public slsDetectorData<dataType> {
public: public:
/** /**
slsReceiver data structure. Works for data acquired using the slsDetectorReceiver subdivided in different packets with headers and footers. slsReceiver data structure. Works for data acquired using the slsDetectorReceiver subdivided in different packets with headers and footers.
Inherits and implements slsDetectorData. Inherits and implements slsDetectorData.
@ -22,35 +22,34 @@ class slsReceiverData : public slsDetectorData<dataType> {
\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 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. \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) {}; 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. 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 \param buff pointer to the dataset
\returns frame number \returns frame number
*/ */
virtual int getFrameNumber(char *buff){return ((*(int*)buff)&(0xffffff00))>>8;}; 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. Returns the packet number for the given dataset. Virtual func: works for slsDetectorReceiver packets, but can be overloaded.
\param buff pointer to the dataset \param buff pointer to the dataset
\returns packet number number \returns packet number number
*/ */
virtual int getPacketNumber(char *buff) {return (*(int*)buff)&0xff;}; 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! 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 data pointer to the memory to be analyzed
@ -58,113 +57,113 @@ class slsReceiverData : public slsDetectorData<dataType> {
\param dsize size of the memory slot to be analyzed \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 \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) { virtual char *findNextFrame(char *data, int &ndata, int dsize) {
char *retval=NULL, *p=data; char *retval=NULL, *p=data;
int dd=0; int dd=0;
int fn, fnum=-1, np=0, pnum=-1; int fn, fnum=-1, np=0, pnum=-1;
while (dd<=(dsize-packetSize)) { while (dd<=(dsize-packetSize)) {
pnum=getPacketNumber(p); pnum=getPacketNumber(p);
fn=getFrameNumber(p); fn=getFrameNumber(p);
if (pnum<1 || pnum>nPackets) { if (pnum<1 || pnum>nPackets) {
cout << "Bad packet number " << pnum << " frame "<< fn << endl; cout << "Bad packet number " << pnum << " frame "<< fn << endl;
retval=NULL; retval=NULL;
np=0; np=0;
} else if (pnum==1) { } else if (pnum==1) {
fnum=fn; retval=p;
retval=p; if (np>0)
if (np>0) /*cout << "*Incomplete frame number " << fnum << endl;*/
/*cout << "*Incomplete frame number " << fnum << endl;*/ np=0;
np=0; fnum=fn;
} else if (fn!=fnum) { } else if (fn!=fnum) {
if (fnum!=-1) { if (fnum!=-1) {
/* cout << " **Incomplete frame number " << fnum << " pnum " << pnum << " " << getFrameNumber(p) << endl;*/ /* cout << " **Incomplete frame number " << fnum << " pnum " << pnum << " " << getFrameNumber(p) << endl;*/
retval=NULL; retval=NULL;
} }
np=0; np=0;
} }
p+=packetSize; p+=packetSize;
dd+=packetSize; dd+=packetSize;
np++; np++;
// cout << pnum << " " << fn << " " << np << " " << dd << " " << dsize << endl; // cout << pnum << " " << fn << " " << np << " " << dd << " " << dsize << endl;
if (np==nPackets) if (np==nPackets)
if (pnum==nPackets) { if (pnum==nPackets) {
// cout << "Frame found!" << endl; // cout << "Frame found!" << endl;
break; break;
} else { } else {
cout << "Too many packets for this frame! "<< fnum << " " << pnum << endl; cout << "Too many packets for this frame! "<< fnum << " " << pnum << endl;
retval=NULL; retval=NULL;
} }
} }
if (np<nPackets) { if (np<nPackets) {
if (np>0) if (np>0)
cout << "Too few packets for this frame! "<< fnum << " " << pnum << endl; cout << "Too few packets for this frame! "<< fnum << " " << pnum << endl;
} }
ndata=np*packetSize; ndata=np*packetSize;
// cout << "return " << ndata << endl; // cout << "return " << ndata << endl;
return retval; 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! 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 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 \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) { virtual char *readNextFrame(ifstream &filebin) {
char *data=new char[packetSize*nPackets]; char *data=new char[packetSize*nPackets];
char *retval=0; char *retval=0;
int np=0, nd; int np=0, nd;
if (filebin.is_open()) { if (filebin.is_open()) {
while (filebin.read(data+np*packetSize,packetSize)) { while (filebin.read(data+np*packetSize,packetSize)) {
if (np==(nPackets-1)) { if (np==(nPackets-1)) {
retval=findNextFrame(data,nd,packetSize*nPackets); retval=findNextFrame(data,nd,packetSize*nPackets);
np=nd/packetSize; np=nd/packetSize;
// cout << np << endl; // cout << np << endl;
if (retval==data && np==nPackets) { if (retval==data && np==nPackets) {
// cout << "-" << endl; // cout << "-" << endl;
return data; return data;
} else if (np>nPackets) { } else if (np>nPackets) {
cout << "too many packets!!!!!!!!!!" << endl; cout << "too many packets!!!!!!!!!!" << endl;
delete [] data; delete [] data;
return NULL; return NULL;
} else if (retval!=NULL) { } else if (retval!=NULL) {
// cout << "+" << endl;; // cout << "+" << endl;;
for (int ip=0; ip<np; ip++) for (int ip=0; ip<np; ip++)
memcpy(data+ip*packetSize,retval+ip*packetSize,packetSize); memcpy(data+ip*packetSize,retval+ip*packetSize,packetSize);
} }
} else if (np>nPackets) { } else if (np>nPackets) {
cout << "*******too many packets!!!!!!!!!!" << endl; cout << "*******too many packets!!!!!!!!!!" << endl;
delete [] data; delete [] data;
return NULL; return NULL;
} else { } else {
// cout << "." << endl;; // cout << "." << endl;;
np++; np++;
} }
} }
} }
delete [] data; delete [] data;
return NULL; return NULL;
}; };
private: private:
const int nPackets; /**<number of UDP packets constituting one frame */ const int nPackets; /**<number of UDP packets constituting one frame */
const int packetSize; /**< size of a udp packet */ const int packetSize; /**< size of a udp packet */
}; };