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>
16 #include "FairMQLogger.h"
22 fOldFrameCount(0), fOldAllHeaderCount(0), fFirstHeader(kTRUE), fFE(-1),
23 fNonSequentialFC(0), fHammingLossFrameCount(0), fCRCLossFrameCount(0),
24 fTotalHitCount(0),fPreFrameLossHitCount(0), fHammingLossHitCount(0), fCRCLossHitCount(0), fCorrectHitCount(0),
25 fHeaderPresent(kFALSE), fTrailerPresent(kFALSE), fDoubleHeader(0), fDoubleTrailer(0),
fVerbose(0),
26 fFileCounter(0), fTotalFrameCount(0), fTotalHeaderCount(0), fTotalTrailerCount(0), fFileHandle(0),
27 fTimeStampCorrection(0.0), fFilter(kFALSE), fNFilteredHits(0)
45 if (ifs->good() == kFALSE)
57 std::vector<ULong64_t> rawArray;
75 LOG(
DEBUG) <<
"PndMvdReadInToPix4TBData::ReadInRawData reading file ";
79 }
catch (boost::archive::archive_exception& exception) {
80 LOG(WARN) <<
"PndMvdReadInToPix4TBData::ReadInRawData: Error found in reading file "
82 << exception.code <<
" " << exception.what();
84 if (exception.code == 3) {
89 std::ifstream* ifs =
new std::ifstream(fFileNames[
fFileCounter], std::ios::binary);
94 LOG(INFO) <<
fFE <<
" All files read! Finishing FE ";
102 LOG(ERROR) <<
fFE <<
" An error occured ";
103 LOG(ERROR) <<
fFE <<
" fFileHandle->good() " <<
fFileHandle->good();
104 LOG(ERROR) <<
fFE <<
" fFileHandle->eof() " <<
fFileHandle->eof();
105 LOG(ERROR) <<
fFE <<
" fFileHandle->fail() " <<
fFileHandle->fail();
106 LOG(ERROR) <<
fFE <<
" fFileHandle->bad() " <<
fFileHandle->bad();
207 std::vector<std::vector<PndSdsDigiTopix4> > result;
209 LOG(
DEBUG) <<
"PndMvdReadInToPix4TBData::AnalyzeData rawData.size(): " << rawData.size();
210 for (
int i = 0;
i < rawData.size();
i++) {
214 result.push_back(hitList);
243 if (deltaAllFrameCount > 1 &&
fVerbose > 0)
244 std::cout <<
"-W- deltaAllFrameCount > 1: " << deltaAllFrameCount << std::endl;
253 std::cout <<
"Double Header Found! count: " <<
fDoubleHeader <<
"| FE: " <<
fFE << std::hex <<
" last ToPixFrame element: "
254 <<
fToPixFrame.back() <<
" new frame header " << rawData << std::endl;
268 else if (header == 2)
279 std::cout <<
"Double Trailer Found! Double header counter: " <<
fDoubleTrailer << std::endl;
297 std::cout <<
"Trailer without header found! Double header counter: " <<
fDoubleHeader << std::endl;
307 }
else if (header == 3)
323 std::vector<PndSdsDigiTopix4> hitList;
325 std::cout <<
fFE <<
" PndMvdReadInToPix4TBData::AnalyzeToPixFrame: fToPixFrame size: "
342 std::cout <<
fFE <<
" FrameHeader: rawData: " << std::hex
348 if (deltaFrameCount > 1){
359 std::cout <<
fFE <<
" SuperFrameCount increased: " << std::dec <<
fSuperFrameCount <<
" oldFC "
384 std::cout << std::endl;
399 LOG(INFO) <<
"RecentPixel: " << recentPixel;
408 hitList.push_back(recentPixel);
410 std::cout <<
fFE <<
" Pixel: " << recentPixel << std::endl;
424 if (leadingEdge == 2729 || leadingEdge == 2730)
426 if (trailingEdge == 2730 || trailingEdge == 2731)
441 if (hammingcheck != 0) {
443 std::cout <<
"Wrong Hamming Code found! (Header) : " << std::hex<< topix4Frame[0] <<
" Parity bits " << hammingcheck << std::endl;
453 if (hammingcheck != 0) {
455 std::cout <<
"Wrong Hamming Code found! (Trailer): " << std::hex << topix4Frame[0] <<
" Parity bits " << hammingcheck << std::endl;
467 if (crc_calculated != ((topix4Frame.back() >> 6) & 0xffff)) {
473 std::cout <<
fFE <<
" CRC WRONG! Frame will be deleted. Calculated CRC: " << std::hex << crc_calculated <<
474 " topix CRC: " << ((topix4Frame.back() >> 6) & 0xffff) << std::endl;
476 for (
int y = 0;
y < topix4Frame.size();
y++) {
480 std::cout <<
fFE <<
" " << std::hex << topix4Frame[
y] << std::endl;
483 std::cout << std::endl;
494 if (
fVerbose > 1) std::cout <<
"PndMvdReadInToPix4TBData::ProcessData raw Data: " << data << std::endl;
507 std::vector<Int_t> indices;
509 PndSdsDigiTopix4 result(indices, 0,
fFE - 1, 0, pixelAddress.first, pixelAddress.second, pixelData.
fLeadingEdge, pixelData.
fTrailingEdge, header.
fFrameCount, timestamp,
fCorrectHitCount,
fTotalHitCount, timestamp_independent);
510 result.SetTimeStampError(1/clockFrequency * 1000);
std::vector< std::string > fFileNames
virtual Bool_t ReadInDataFromFile(TMrfData_8b *&data)
std::vector< char > ConvertData(std::vector< ULong64_t > topixFrame)
UInt_t fTotalTrailerCount
Data class to store the digi output of a pixel module.
std::vector< int > fStatusValues
PndMvdReadInToPix4TBData()
UInt_t fCRCLossFrameCount
ToPix4::frameTrailer BitAnalyzeTrailer(ULong64_t &trailer)
ToPix4::frameHeader BitAnalyzeHeader(ULong64_t &header)
Bool_t HitToFilter(PndSdsDigiTopix4 &hit)
ULong64_t ConvertToPix4HammingToStandardHamming(ULong64_t topixhamming)
Double_t fTimeStampCorrection
UInt_t fOldAllHeaderCount
ToPix4::pixel BitAnalyzePixelData(ULong64_t &data)
Int_t GetDeltaFrameCount()
std::vector< std::vector< PndSdsDigiTopix4 > > AnalyzeData(std::vector< ULong64_t > &rawData, Double_t clockFrequency)
UInt_t GetLeadingEdge() const
UInt_t GetTrailingEdge() const
PndSdsDigiTopix4 ProcessData(ULong64_t &data, ToPix4::frameHeader &header, Double_t &clockFrequency)
virtual ~PndMvdReadInToPix4TBData()
std::vector< ULong64_t > GetRawData(TMrfData_8b *data)
UInt_t fHammingLossFrameCount
std::pair< UInt_t, UInt_t > PixelNumberToMatrixAddress(UInt_t pixelnumber)
Base interface class for data storage and manipulation. Compatible with IO classes from MRF Suite...
Bool_t ReadInData(std::vector< std::vector< PndSdsDigiTopix4 > > &data)
ToPix4::frameTrailer fRecentFrameTrailer
UInt_t fHammingLossHitCount
ToPix4::frameHeader fRecentFrameHeader
ULong64_t CalculateCRCTableFast(std::vector< char > p, ULong64_t len)
int hit(Int_t nEvents=0, TString inFile="sim.root", TString parFile="par.root", TString inDigi="digi.root", TString outFile="hit.root", Int_t timeBased=0)
std::ifstream * fFileHandle
UInt_t fPreFrameLossHitCount
std::vector< PndSdsDigiTopix4 > AnalyzeToPixFrame(Double_t clockFrequency)
std::vector< ULong64_t > fToPixFrame
bool BuildFrame(ULong64_t &rawData)
PndHammingDecoder fHamming
int GetType(ULong64_t data)
returns if the data word is a header (0b01), trailer (0b10) or data (0b11)
bool CheckDataIntegrity(std::vector< ULong64_t > topix4Frame)
UShort_t CheckHammingCode(ULong64_t dataword, int dataword_length)