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