PandaRoot
PndMvdReadInTBData.h
Go to the documentation of this file.
1 /*
2  * PndMvdReadInTBData.h
3  *
4  * Created on: 23.10.2014
5  * Author: Stockmanns
6  */
7 
8 #ifndef PNDMVDREADINTBDATA_H_
9 #define PNDMVDREADINTBDATA_H_
10 
11 #include "Rtypes.h"
12 #include "TClonesArray.h"
13 #include "TString.h"
14 
15 #include "PndSdsDigiTopix4.h"
16 #include "PndSdsDigiTopix4Header.h"
17 
18 #include <fstream>
19 #include <iostream>
20 #include <utility>
21 #include <vector>
22 
23 struct frameHeader {
25 
26  UInt_t fChipAddress;
27  UInt_t fFrameCount;
28  UInt_t fECC;
29 };
30 
31 struct frameTrailer {
32  frameTrailer() : fNEvents(0), fFrameCRC(0), fECC(0){};
33 
34  UInt_t fNEvents;
35  UInt_t fFrameCRC;
36  UInt_t fECC;
37 };
38 
39 struct pixel {
40  pixel() : fPixelAddress(0), fLeadingEdge(0), fTrailingEdge(0){};
41 
42  UInt_t fPixelAddress;
43  UInt_t fLeadingEdge;
44  UInt_t fTrailingEdge;
45 };
46 
48  public:
50  virtual ~PndMvdReadInTBData();
51  void SetFileName(std::vector<TString> fileName)
52  {
53 
54  std::cout << "number of entires " << fileName.size() << std::endl;
55  for (int i = 0; i < fileName.size(); i++) {
56  std::cout << i << " " << fileName[i] << std::endl;
57  }
58  fFileNames = fileName;
59  }
60 
61  void Init();
62 
63  Bool_t ReadInData(TClonesArray *sdsDigiContainer, TClonesArray *headerContainer, TClonesArray *allheaderContainer);
64  Bool_t ReadInRawData(std::ifstream *fileHandle, std::vector<ULong64_t> &rawData); //<input is fileHandle, output vector of raw data, output is end of file
65  void AnalyzeData(std::vector<ULong64_t> &rawData, Double_t clockFrequency);
66 
67  pixel BitAnalyzePixelData(ULong64_t &data);
68  frameHeader BitAnalyzeHeader(ULong64_t &header);
69  frameTrailer BitAnalyzeTrailer(ULong64_t &trailer);
70 
71  std::pair<UInt_t, UInt_t> PixeladdressToMatrixAddress(UInt_t pixelglobaladdress);
72 
73  void SetClockFrequency(Double_t val) { fClockFrequency = val; }
74  void SetFE(Int_t val) { fFE = val; }
75  UInt_t GetNonSequenctialFC() const { return fNonSequentialFC; }
76  UInt_t GetDoubleHeader() const { return fDoubleHeader; }
77  UInt_t GetDoubleTrailer() const { return fDoubleTrailer; }
78  UInt_t GetSuperFrameCount() const { return fSuperFrameCount; }
79 
80  UInt_t GetTotalHitCount() const { return fTotalHitCount; }
81  UInt_t GetCorrectHitCount() const { return fCorrectHitCount; }
82  UInt_t GetPreFrameLossHitCount() const { return fPreFrameLossHitCount; }
83  UInt_t GetHammingLossHitCount() const { return fHammingLossHitCount; }
84  UInt_t GetCRCLossHitCount() const { return fCRCLossHitCount; }
85 
86  UInt_t GetTotalFrameCount() const { return fTotalFrameCount; }
87  UInt_t GetCorrectFrameCount() const { return fCorrectFrameCount; }
88  UInt_t GetHammingLossFrameCount() const { return fHammingLossFrameCount; }
89  UInt_t GetCRCLossFrameCount() const { return fCRCLossFrameCount; }
90 
91  UInt_t GetTotalHeaderCount() const { return fTotalHeaderCount; }
92  UInt_t GetTotalTrailerCount() const { return fTotalTrailerCount; }
93 
94  PndSdsDigiTopix4 ProcessData(ULong64_t &data, frameHeader &header, Double_t &clockFrequency);
95  ULong64_t ReflectBitsStream(ULong64_t crc, int bitnum);
96  ULong64_t CalculateCRCTableFast(std::vector<char> p, ULong64_t len);
97  void GenerateCRCTable();
98  UShort_t CheckHammingCode(ULong64_t dataword, int dataword_length);
99  ULong64_t ConvertToPix4HammingToStandardHamming(ULong64_t topixhamming);
100  void AnalyzeToPixFrame(Double_t clockFrequency);
101  void SetVerbose(Int_t val) { fVerbose = val; }
102 
103  private:
104  std::vector<TString> fFileNames;
105  std::ifstream *fFileHandle;
106  Double_t fClockFrequency;
107  TClonesArray *fOutputArray;
108  TClonesArray *fOutputArrayHeader;
109  TClonesArray *fOutputArrayAllHeader;
110  UInt_t fSuperFrameCount;
111  UInt_t fOldFrameCount;
112  UInt_t fOldAllHeaderCount;
113  UInt_t fNonSequentialFC;
114  UInt_t fHammingLossFrameCount;
115  UInt_t fCRCLossFrameCount;
116 
117  UInt_t fTotalHitCount;
118  UInt_t fPreFrameLossHitCount;
119  UInt_t fHammingLossHitCount;
120  UInt_t fCRCLossHitCount;
121  UInt_t fCorrectHitCount;
122 
123  frameHeader fRecentFrameHeader;
124  frameHeader fRecentAllFrameHeader;
125  frameTrailer fRecentFrameTrailer;
126  Bool_t fFirstHeader;
127  Bool_t fHeaderPresent;
128  Bool_t fTrailerPresent;
129  UInt_t fDoubleHeader;
130  UInt_t fDoubleTrailer;
131 
132  UInt_t fTotalHeaderCount;
133  UInt_t fTotalTrailerCount;
134 
135  Int_t fVerbose; // fVerbose==5 gives all detected errors from ToPix build in error detection
136  Int_t fFE;
137  Int_t fFileCounter;
138  UInt_t fDataCount;
139  UInt_t fTotalFrameCount;
140  UInt_t fCorrectFrameCount;
141  std::vector<ULong64_t> fToPixFrame;
142 
143  TClonesArray *fDigiArray;
144  // CRC parameters :
145 
146  const UInt_t fOrder;
147  const ULong64_t fPolynom;
148  const ULong64_t fCRCXor;
149  const UInt_t fRefIn;
150  const UInt_t fRefOut;
151 
152  ULong64_t fCRCMask;
153  ULong64_t fCRCHighBit;
154  ULong64_t fCRCInit_direct;
155  ULong64_t fCRCTab[256];
156 };
157 
158 #endif /* PNDMVDREADINTBDATA_H_ */
UInt_t GetNonSequenctialFC() const
void SetFE(Int_t val)
Data class to store the digi output of a pixel module.
UInt_t GetDoubleHeader() const
UInt_t GetDoubleTrailer() const
UInt_t GetPreFrameLossHitCount() const
UInt_t GetHammingLossHitCount() const
unsigned int i
Definition: P4_F32vec4.h:21
UInt_t fLeadingEdge
UInt_t GetTotalHeaderCount() const
void SetVerbose(Int_t val)
UInt_t fTrailingEdge
UInt_t GetTotalHitCount() const
UInt_t GetCRCLossHitCount() const
UInt_t GetTotalFrameCount() const
UInt_t GetTotalTrailerCount() const
UInt_t GetCorrectFrameCount() const
UInt_t GetCorrectHitCount() const
UInt_t GetCRCLossFrameCount() const
UInt_t GetSuperFrameCount() const
void SetFileName(std::vector< TString > fileName)
UInt_t GetHammingLossFrameCount() const
void SetClockFrequency(Double_t val)