diff --git a/slsDetectorCalibration/eigerHalfModuleData.h b/slsDetectorCalibration/eigerHalfModuleData.h index 56d48e6e7..c9087e8a7 100644 --- a/slsDetectorCalibration/eigerHalfModuleData.h +++ b/slsDetectorCalibration/eigerHalfModuleData.h @@ -19,169 +19,91 @@ public: */ - eigerHalfModuleData(int dr, int np, int bsize, int dsize, bool top, double c=0): slsReceiverData(xpixels, ypixels, np, bsize), - xtalk(c), bufferSize(bsize), actualDataSize(dsize), dynamicRange(dr), numberOfPackets(np), top(top),header_t(0), footer_t(0){ + eigerHalfModuleData(bool t, bool l, int dr, int tg, int psize, int dsize, int npf, int x, int y, double c=0): + slsReceiverData(x, y, npf, psize), + top(t), left(l), + dynamicRange(dr), tenGiga(tg), + packetSize(psize), onepacketdataSize(dsize), numberofPacketsPerFrame(npf), + xtalk(c), + header_t(0), footer_t(0){ - tenGiga = false; - if(actualDataSize == TEN_GIGA_PACKET_SIZE) - tenGiga = true; int **dMap; uint32_t **dMask; - dMap=new int*[ypixels]; - dMask=new uint32_t*[ypixels]; + dMap=new int*[ny]; + dMask=new uint32_t*[ny]; - for (int i = 0; i < ypixels; i++) { - dMap[i] = new int[xpixels]; - dMask[i] = new uint32_t[xpixels]; + for (int i = 0; i < ny; i++) { + dMap[i] = new int[nx]; + dMask[i] = new uint32_t[nx]; } //Map - int totalNumberOfBytes = numberOfPackets * bufferSize; - int iPacket1 = 8; - int iPacket2 = (totalNumberOfBytes/2) + 8; - int iData1 = 0, iData2 = 0; + int totalNumberOfBytes = numberofPacketsPerFrame * packetSize; + int iPacket = 8; + int iData = 0; int increment = (dynamicRange/8); int ic_increment = 1; if (dynamicRange == 4) { increment = 1; ic_increment = 2; } - int iPort; if(top){ - for (int ir=0; ir= actualDataSize){ - iPacket1 += 16; - iData1 = 0; - } - }else{ - dMap[ir][ic] = iPacket2; - iPacket2 += increment; - iData2 += increment; - //increment header - if(iData2 >= actualDataSize){ - iPacket2 += 16; - iData2 = 0; - } + for (int ir=0; ir= onepacketdataSize){ + iPacket += 16; + iData = 0; } + } } } - //bottom else{ - iData1 = 0; iData2 = 0; - int numbytesperlineperport; - + iData = 0; + int numbytesperline; switch(dynamicRange){ - case 4: numbytesperlineperport = 256; break; - case 8: numbytesperlineperport = 512; break; - case 16:numbytesperlineperport = 1024; break; - case 32:numbytesperlineperport = 2048; break; + case 4: numbytesperline = 256; break; + case 8: numbytesperline = 512; break; + case 16:numbytesperline = 1024; break; + case 32:numbytesperline = 2048; break; } + iPacket = totalNumberOfBytes - numbytesperline - 8; + if((dynamicRange == 32) && (!tenGiga)) + iPacket -= 16; - - - iPacket1 = (totalNumberOfBytes/2) - numbytesperlineperport - 8; - iPacket2 = totalNumberOfBytes - numbytesperlineperport - 8; - if (dynamicRange == 32){ - if(numbytesperlineperport>actualDataSize){ //1Giga - iPacket1 -= 16; - iPacket2 -= 16; - }else{ //10Giga - ;//iPacket1 -= numbytesperlineperport; - //iPacket2 -= numbytesperlineperport; - } - } - - for (int ir=0; iractualDataSize){ //1Giga - if(iData1 == numbytesperlineperport){ - iPacket1 -= (numbytesperlineperport*2 + 16*3);//1giga - iData1 = 0; - } - if(iData1 == actualDataSize){ - iPacket1 += 16; - } - }else{ //10Giga - if((iData1 % numbytesperlineperport)==0){ - iPacket1 -= (numbytesperlineperport*2); - } - if(iData1 == actualDataSize){ - iPacket1 -= 16; - iData1 = 0; - } - } - }//------------end of 32 bit ------------------------- - - else if((iData1 % numbytesperlineperport) == 0){ - iPacket1 -= (numbytesperlineperport*2); - if(iData1 == actualDataSize){ - iPacket1 -= 16; - iData1 = 0; - } + for (int ir=0; iractualDataSize){ //1Giga - if(iData2 == numbytesperlineperport){ - iPacket2 -= (numbytesperlineperport*2 + 16*3); - iData2 = 0; - } - if(iData2 == actualDataSize){ - iPacket2 += 16; - } - }else{//10Giga - if((iData2 % numbytesperlineperport)==0){ - iPacket2 -= (numbytesperlineperport*2); - } - if(iData2 == actualDataSize){ - iPacket2 -= 16; - iData2 = 0; - } - } - }//------------end of 32 bit ------------------------- - - else if((iData2 % numbytesperlineperport) == 0){ - iPacket2 -= (numbytesperlineperport*2); - if(iData2 == actualDataSize){ - iPacket2 -= 16; - iData2 = 0; - } + if(iData == onepacketdataSize){ + iPacket += 16; + } + }//------------end of 32 bit ------------------------- + else if((iData % numbytesperline) == 0){ + iPacket -= (numbytesperline*2); + if(iData == onepacketdataSize){ + iPacket -= 16; + iData = 0; } - //------------end of other bits ------------------------- - } + //--------------------------------------------------- } } } @@ -190,16 +112,13 @@ public: //Mask - for(int ir=0; irpacketnum)); }; @@ -287,10 +206,10 @@ public: // ------check if missing packet, get to pixel at start of packet----------------- - //to get the starting of a packet, ix is divided by 512pixels because of 2 ports (except 1g 32 bit) - newix = ix - (ix%512); + //to get the starting of a packet (except 1g 32 bit) + newix = 0; // 0.5 Lines per packet for 1g 32 bit - if(dynamicRange ==32 && !tenGiga) + if(dynamicRange == 32 && !tenGiga) newix = ix - (ix%256); //iy divided by linesperpacket depending on bitmode @@ -300,9 +219,11 @@ public: newiy = (iy - (iy%linesperpacket)); header_t = (eiger_packet_header_t*)((char*)(data +(dataMap[newiy][newix]-8))); - if(*( (uint16_t*) header_t->missingpacket)==0xFFFF){ - // cprintf(RED,"missing packet\n"); - return -1; + uint16_t identifier = (uint16_t)*( (uint16_t*) header_t->missingpacket); + + if(identifier==deactivatedPacketValue){ + // cprintf(RED,"deactivated packet\n"); + return -2; } // -----END OF CHECK ------------------------------------------------------------- @@ -342,25 +263,188 @@ public: */ double getXTalk() {return xtalk;} + void getChannelArray(double* data, char* buffer){ + for(int iy = 0; iy < ny; iy++){ + for(int ix = 0; ix < nx; ix++){ + data[iy*nx+ix] = getValue((char*)buffer,ix,iy); + //cprintf(BLUE,"%d,%d :%f\n",ix,iy,value); + } + } + } + + + int* decodeData(int *datain) { + + int dataBytes = numberofPacketsPerFrame * onepacketdataSize; + int nch = nx*ny; + int* dataout = new int [nch]; + char *ptr=(char*)datain; + char iptr; + + const int bytesize=8; + int ival=0; + int ipos=0, ichan=0, ibyte; + + switch (dynamicRange) { + case 4: + for (ibyte=0; ibyte>(ipos*4))&0xf; //pick the right 4bit + dataout[ichan]=ival; + ichan++; + } + } + break; + case 8: + for (ichan=0; ichan