#ifndef SLSDETECTORDATA_H #define SLSDETECTORDATA_H #include #include using namespace std; template class slsDetectorData { public: /** 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 \param ds size of the dataset \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) */ slsDetectorData(int npx, int npy, int np, int psize, int **dMap=NULL, dataType **dMask=NULL, int **dROI=NULL): nx(npx), ny(npy), nPackets(np), packetSize(psize) { dataMask=new dataType*[ny]; for(int i = 0; i < ny; i++) { dataMask[i] = new dataType[nx]; } dataMap=new int*[ny]; for(int i = 0; i < ny; i++) { dataMap[i] = new int[nx]; } dataROIMask=new int*[ny]; for(int i = 0; i < ny; i++) { dataROIMask[i] = new int[nx]; } 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; } void setDataMap(int **dMap=NULL) { if (dMap==NULL) { for (int iy=0; iy=0 && ix=0 && iy=0 && ix=0 && iy=0 && ix=0 && iy=0 && dataMap[iy][ix]>8;}; virtual int getPacketNumber(char *buff) {return (*(int*)buff)&0xff;}; virtual char *findNextFrame(char *data, int &npackets, 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); if (pnum<0 || pnum>=nPackets) { cout << "Bad packet number " << pnum << " frame "<< fn << endl; retval=NULL; continue; } if (pnum==1) { fnum=fn; retval=p; if (np>0) cout << "*Incomplete frame number " << fnum << endl; np=0; } 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++; if (np==nPackets) if (pnum==nPackets) break; else { cout << "Too many packets for this frame! "<< fnum << " " << pnum << endl; retval=NULL; } } if (np<40) { if (np>0) cout << "Too few packets for this frame! "<< fnum << " " << pnum << endl; } npackets=np; return retval; }; virtual char *readNextFrame(ifstream &filebin) { /* if (oldbuff) */ /* delete [] oldbuff; */ /* oldbuff=buff; */ // char *p=new char[1286]; char *data=new char[packetSize*nPackets]; char *retval=0; int np=40; if (filebin.is_open()) { while (filebin.read(data+np*packetSize,packetSize)) { if (np==nPackets) { retval=findNextFrame(data,np,packetSize*nPackets); if (retval==data && np==nPackets) return data; else if (np>nPackets) { cout << "too many packets!!!!!!!!!!" << endl; delete [] data; return NULL; } else { for (int ip=0; ipnPackets) { cout << "*******too many packets!!!!!!!!!!" << endl; delete [] data; return NULL; } else { // memcpy(data+np*1286,p,1286); np++; } } } delete [] data; return NULL; }; private: const int nx; /**< Number of pixels in the x direction */ const int ny; /**< Number of pixels in the y direction */ const int nPackets; /**