12 #include "boost/archive/binary_oarchive.hpp"
13 #include "boost/archive/binary_iarchive.hpp"
14 #include "boost/serialization/binary_object.hpp"
15 #include <boost/archive/archive_exception.hpp>
18 fOldFrameCount(0), fOldAllHeaderCount(0), fFirstHeader(kTRUE), fFE(-1),
19 fNonSequentialFC(0), fHammingLossFrameCount(0), fCRCLossFrameCount(0),
20 fTotalHitCount(0),fPreFrameLossHitCount(0), fHammingLossHitCount(0), fCRCLossHitCount(0), fCorrectHitCount(0),
21 fHeaderPresent(kFALSE), fTrailerPresent(kFALSE), fDoubleHeader(0), fDoubleTrailer(0),
fVerbose(0),
22 fOrder(16), fPolynom(0x8005), fCRCXor(0x0000), fRefIn(0), fRefOut(0), fCRCInit_direct(0), fDataCount(0),
23 fFileCounter(0), fTotalFrameCount(0), fTotalHeaderCount(0), fTotalTrailerCount(0) {
39 for (
int i=0;
i<256;
i++) {
47 for (
int j=0; j<8; j++)
73 ULong64_t hamming_code=0;
75 if(dataword_length > 63)
77 std::cout <<
"Error: maximum length of datastream is 63" << std::endl;
82 for (
int i = 0; pow(2,
i) < dataword_length; ++
i)
85 int stepwidth=2*start;
87 for (
int j = start; j < dataword_length+1; j+=stepwidth)
89 for (
int k = j; k < j+stepwidth/2 && k < dataword_length+1; ++k)
91 parity_bit ^= ((dataword & (shift <<(k-1)))>> (k-1));
94 hamming_code += (parity_bit <<
i);
107 ULong64_t standard_hamming = 0;
109 standard_hamming = ( topixhamming & 0xff00000000);
110 standard_hamming += ((topixhamming & 0x00fffe0000) >> 1 );
111 standard_hamming += ((topixhamming & 0x000001fc00) >> 2 );
112 standard_hamming += ((topixhamming & 0x0000000380) >> 3 );
113 standard_hamming += ((topixhamming & 0x0000000040) >> 4 );
115 standard_hamming += ((topixhamming & 0x0000000020) << 26 );
116 standard_hamming += ((topixhamming & 0x0000000010) << 11 );
117 standard_hamming += ((topixhamming & 0x0000000008) << 4 );
118 standard_hamming += ((topixhamming & 0x0000000004) << 1 );
119 standard_hamming += ( topixhamming & 0x0000000002);
120 standard_hamming += ( topixhamming & 0x0000000001);
122 return standard_hamming;
139 Bool_t endOfFile = kFALSE;
144 std::vector<ULong64_t> rawArray;
154 Bool_t endOfFile = kFALSE;
155 if(fileHandle->good())
159 std::cout << std::endl;
160 std::cout <<
"PndMvdReadInTBData::ReadInRawData reading file " << std::endl;
164 boost::archive::binary_iarchive iar(*fileHandle);
167 catch (boost::archive::archive_exception& exception){
170 std::cout <<
"PndMvdReadInTBData::ReadInRawData: Error found in reading file " <<
" : " << fileHandle->good() <<
" " << fileHandle->eof() <<
" Exception: " << exception.code << std::endl;
174 std::cout << exception.what() << std::endl;
176 if (exception.code == 3)
189 std::cout <<
fFE <<
" All files read! Finishing FE " << std::endl;
195 if (
fVerbose > 2) std::cout <<
fFE <<
" PndMvdReadInTBData::ReadInRawData: NWords: " << tempdata->
getNumWords() << std::endl;
199 for(uint j=0; j< 5 ; j++)
201 dataword = dataword << 8;
204 rawData.push_back(dataword);
205 ULong_t frameCount = dataword & 0x3FC0000;
206 frameCount = frameCount >> 18;
207 if (
fVerbose > 2) std::cout << std::dec <<
"dataword No "<<
i/5<<
"/"<< tempdata->
getNumWords()/5 <<
": "<<std::hex << dataword <<
" " << std::dec << frameCount << std::endl;
213 std::cout <<
fFE <<
" An error occured " << std::endl;
214 std::cout <<
fFE <<
" fileHandle->good() " << fileHandle->good() << std::endl;
215 std::cout <<
fFE <<
" fileHandle->eof() " << fileHandle->eof() << std::endl;
216 std::cout <<
fFE <<
" fileHandle->fail() " << fileHandle->fail() << std::endl;
217 std::cout <<
fFE <<
" fileHandle->bad() " << fileHandle->bad() << std::endl;
232 std::vector<char>::iterator it=p.begin();
243 crc = (crc << 8) ^ fCRCTab[ ((crc >> (
fOrder-8)) & 0xff) ^ (*it & 0xff)];
251 crc = (crc >> 8) ^
fCRCTab[ (crc & 0xff) ^ (*it & 0xff)];
269 ULong64_t
i, j=1, crcout=0;
271 for (i=(ULong64_t)1<<(bitnum-1);
i; i>>=1)
286 std::cout <<
fFE <<
" PndMvdReadInTBData::AnalyzeToPixFrame: fToPixFrame size: " << std::dec <<
fToPixFrame.size() <<
" header " << std::hex <<
fToPixFrame[0] << std::endl;
295 std::cout <<
"Wrong Hamming Code found! (Header) : " << std::hex<<
fToPixFrame[0] <<
" Parity bits "<< hammingcheck << std::endl;
307 std::cout <<
"Wrong Hamming Code found! (Trailer): " << std::hex<<
fToPixFrame[0] <<
" Parity bits "<< hammingcheck << std::endl;
316 std::vector<char> topix_data;
320 for(
int j=0; j<8 ;j++)
322 if(j==0 or j==1 or j==2)
324 topix_data.push_back(0x00);
328 topix_data.push_back((
fToPixFrame[
i] >> (7-j)*2*4) & 0xff);
335 if(crc_calculated != ((
fToPixFrame.back()>>6) & 0xffff))
341 std::cout <<
fFE <<
" CRC WRONG! Frame will be deleted. Calculated CRC: " <<std::hex << crc_calculated <<
" topix CRC: "<< ((
fToPixFrame.back()>>6) & 0xffff) << std::endl;
354 std::cout << std::endl;
362 ULong64_t header = (
fToPixFrame[
i] & 0xC000000000) >> 38;
386 if (deltaFrameCount > 1) std::cout <<
"-W- OutputArrayHeader deltaFrameCount > 1 " << deltaFrameCount << std::endl;
410 std::cout << std::endl;
421 if (
fVerbose > 2) std::cout <<
fFE <<
" Pixel: " << recentPixel << std::endl;
431 if (
fVerbose > 2) std::cout <<
"PndMvdReadInTBData::AnalyzeData rawData.size(): " << rawData.size() << std::endl;
432 for (
int i = 0;
i < rawData.size();
i++){
433 ULong_t header = rawData[
i] & 0xC000000000;
434 header = header >> 38;
451 if (deltaAllFrameCount > 1) std::cout <<
"-W- deltaAllFrameCount > 1: " << deltaAllFrameCount << std::endl;
461 std::cout <<
"Double Header Found! count: " <<
fDoubleHeader <<
"| FE: " <<
fFE << std::hex <<
" last ToPixFrame element: "<<
fToPixFrame.back()<<
" new frame header " << rawData[
i] << std::endl;
488 std::cout <<
"Double Trailer Found! Double header counter: " <<
fDoubleTrailer << std::endl;
512 std::cout <<
"Trailer without header found! Double header counter: " <<
fDoubleHeader << std::endl;
549 ULong_t temp = header;
550 tempHeader.
fECC = temp & 0x3F;
563 ULong_t temp = trailer;
564 tempTrailer.
fECC = temp & 0x3F;
570 tempTrailer.
fNEvents = temp & 0xFFFF;
600 if (
fVerbose > 1) std::cout <<
"PndMvdReadInTBData::ProcessData raw Data: " << data << std::endl;
606 std::vector<Int_t> indices;
608 return PndSdsDigiTopix4(indices, 0,
fFE - 1, 0, pixelAddress.first, pixelAddress.second, pixelData.
fLeadingEdge, pixelData.
fTrailingEdge, header.
fFrameCount, timestamp,
fCorrectHitCount,
fTotalHitCount, timestamp_independent);
616 UInt_t double_column_address =0;
617 UInt_t double_column_side=0;
618 UInt_t pixel_address=0;
620 UInt_t matrix_column, matrix_row;
622 UInt_t temp = pixelglobaladdress;
624 pixel_address= temp & 0x7f;
626 double_column_side= temp & 0x1;
628 double_column_address= temp & 0x3f;
643 UInt_t sel = (double_column_address<<1) | (double_column_side);
647 matrix_row = pixel_address;
652 matrix_row = pixel_address;
657 matrix_row = pixel_address;
662 matrix_row = pixel_address;
667 if (pixel_address <32)
669 matrix_row = pixel_address;
672 else if (pixel_address < 64)
674 matrix_row = 31 - (pixel_address-32);
677 else if (pixel_address < 96)
679 matrix_row = (pixel_address-64);
682 else if (pixel_address < 128)
684 matrix_row = 31 - (pixel_address-96);
690 if (pixel_address <32)
692 matrix_row = pixel_address;
695 else if (pixel_address < 64)
697 matrix_row = 31 - (pixel_address-32);
700 else if (pixel_address < 96)
702 matrix_row = (pixel_address-64);
705 else if (pixel_address < 128)
707 matrix_row = 31 - (pixel_address-96);
713 if (pixel_address < 32)
715 matrix_row = pixel_address;
718 else if (pixel_address < 64)
720 matrix_row = 31 - (pixel_address-32);
723 else if (pixel_address < 96)
725 matrix_row = (pixel_address-64);
728 else if (pixel_address < 128)
730 matrix_row = 31 - (pixel_address-96);
736 if (pixel_address < 32)
738 matrix_row = pixel_address;
741 else if (pixel_address < 64)
743 matrix_row = 31 - (pixel_address-32);
746 else if (pixel_address < 96)
748 matrix_row = (pixel_address-64);
751 else if (pixel_address < 128)
753 matrix_row = 31 - (pixel_address-96);
758 return std::pair<UInt_t, UInt_t>(matrix_column, matrix_row);
Bool_t ReadInRawData(std::ifstream *fileHandle, std::vector< ULong64_t > &rawData)
TClonesArray * fOutputArrayHeader
UInt_t fHammingLossFrameCount
Data class to store the digi output of a pixel module.
ULong64_t CalculateCRCTableFast(std::vector< char > p, ULong64_t len)
TClonesArray * fOutputArray
Bool_t ReadInData(TClonesArray *sdsDigiContainer, TClonesArray *headerContainer, TClonesArray *allheaderContainer)
std::ifstream * fFileHandle
UInt_t fTotalTrailerCount
ULong64_t ConvertToPix4HammingToStandardHamming(ULong64_t topixhamming)
virtual ~PndMvdReadInTBData()
std::vector< ULong64_t > fToPixFrame
PndSdsDigiTopix4 ProcessData(ULong64_t &data, frameHeader &header, Double_t &clockFrequency)
frameHeader fRecentFrameHeader
UInt_t fOldAllHeaderCount
Base interface class for data storage and manipulation. Compatible with IO classes from MRF Suite...
std::pair< UInt_t, UInt_t > PixeladdressToMatrixAddress(UInt_t pixelglobaladdress)
frameHeader fRecentAllFrameHeader
pixel BitAnalyzePixelData(ULong64_t &data)
std::vector< TString > fFileNames
void AnalyzeToPixFrame(Double_t clockFrequency)
UShort_t CheckHammingCode(ULong64_t dataword, int dataword_length)
const UChar_t & getWord(const UInt_t &position) const
Retrieves the word found at position.
frameTrailer BitAnalyzeTrailer(ULong64_t &trailer)
TClonesArray * fOutputArrayAllHeader
UInt_t fCRCLossFrameCount
ULong64_t fCRCInit_direct
UInt_t fHammingLossHitCount
ULong64_t ReflectBitsStream(ULong64_t crc, int bitnum)
UInt_t fPreFrameLossHitCount
void AnalyzeData(std::vector< ULong64_t > &rawData, Double_t clockFrequency)
frameTrailer fRecentFrameTrailer
frameHeader BitAnalyzeHeader(ULong64_t &header)
const UInt_t & getNumWords() const
Retrieves the length of the register in words.