FairRoot/PandaRoot
Functions | Variables
PastaTBRawToRoot.C File Reference

Go to the source code of this file.

Functions

void PrintFrame (std::vector< ULong64_t > &frame)
 
bool CheckHitCount (std::vector< ULong64_t > frame)
 
bool CheckFrameCount (std::vector< ULong64_t > frame)
 
bool CheckCRC (std::vector< ULong64_t > frame)
 
std::vector< PndMvdPastaDigiProcessFrame (std::vector< ULong64_t > frame)
 
int PastaTBRawToRoot (TString fileName)
 

Variables

PndCRCCalculator decoder (16, 0x1021, 0, 0, 0, 0x0F4A)
 
PndMvdPasta pastaConv
 
RunSummary summary
 
unsigned int oldFrameCount = 0
 
ULong64_t framesSinceLastData = 0
 
ULong64_t diffAllFrameCount = 0
 
int oldDiffAllFrameCount = 0
 
int verbose = 1
 

Function Documentation

bool CheckCRC ( std::vector< ULong64_t >  frame)

Definition at line 100 of file PastaTBRawToRoot.C.

References PndCRCCalculator::CalculateCRCTableFast(), PndMvdPasta::ConvertData(), decoder, PrintFrame(), and verbose.

Referenced by ProcessFrame().

101 {
102  std::vector<char> frameInChar = pastaConv.ConvertData(frame);
103 
104  ULong64_t calculatedCRC = decoder.CalculateCRCTableFast(frameInChar, frameInChar.size());
105  if (verbose > 1) std::cout << "CalculatedCRC: " << hex << calculatedCRC << std::endl;
106  if (calculatedCRC == frame.back()){
107  return true;
108  } else {
109  if (verbose > 0){
110  std::cout << "***** Error CRC ***** CalculatedCRC: " << calculatedCRC << std::endl;
111  PrintFrame(frame);
112  }
113  return false;
114  }
115  return false;
116 }
void PrintFrame(std::vector< ULong64_t > &frame)
PndMvdPasta pastaConv
PndCRCCalculator decoder(16, 0x1021, 0, 0, 0, 0x0F4A)
std::vector< char > ConvertData(std::vector< ULong64_t > frame)
Definition: PndMvdPasta.cxx:50
ULong64_t CalculateCRCTableFast(std::vector< char > p, ULong64_t len)
int verbose
bool CheckFrameCount ( std::vector< ULong64_t >  frame)

Definition at line 47 of file PastaTBRawToRoot.C.

References RunSummary::fAllCountedFrames, RunSummary::fAllPartialResets, RunSummary::fMissingFrames, framesSinceLastData, RunSummary::fSuperFrameCount, oldDiffAllFrameCount, oldFrameCount, PrintFrame(), and verbose.

Referenced by ProcessFrame().

48 {
49  ULong64_t header;
50  if (frame.size() > 0)
51  header = frame[0];
52  else
53  return false;
54 
55  unsigned int frameCount = header & 0xffffffff;
56  ULong64_t calcFrameCount = oldFrameCount + framesSinceLastData;
57 
58  if (oldFrameCount == 0){
59  summary.fAllCountedFrames.push_back(frameCount); //sets the first "allCountedFrames" to the start value
60  if (verbose > 0) std::cout << "****** Info Setting allCountedFrames to start frames ***** " << summary.fAllCountedFrames.back() << std::endl;
61  }
62  else if (calcFrameCount > frameCount) {
63  if (verbose > 0) std::cout << "***** Info PartialReset? calcFrameCount " << calcFrameCount << " > frameCount " << frameCount << std::endl;
64  summary.fAllCountedFrames.push_back(frameCount); //sets the first "allCountedFrames" to the start value
65  summary.fAllPartialResets++; //if a partial reset has happened the allCountedFrames has to be corrected
66  }
67  if (frameCount - summary.fAllCountedFrames.back() != oldDiffAllFrameCount){
68  if (verbose > 0) std::cout << "Error allCountedFrames does not match!" << std::endl;
69  if (frameCount - summary.fAllCountedFrames.back() < 1000000)
70  oldDiffAllFrameCount = (frameCount - summary.fAllCountedFrames.back());
71  }
72 
73  if ((oldFrameCount > 0) && (frameCount > calcFrameCount))
74  summary.fMissingFrames += frameCount - calcFrameCount;
75 
76  if (verbose > 1) std::cout << "oldFrameCount " << oldFrameCount << " framesSince: " << framesSinceLastData << " newFrame " << frameCount <<
77  " difference: " << std::dec << frameCount - calcFrameCount <<
78  " allFrameCount " << std::hex << summary.fAllCountedFrames.back() << std::dec <<
79  " difference " << frameCount - summary.fAllCountedFrames.back() <<
80  " total missing Frames: " << summary.fMissingFrames << std::endl;
81 
82  if (calcFrameCount > 0x100000000){
83  if (verbose > 0) std::cout << "New Super Frame: calcFrame " << calcFrameCount << std::endl;
85  calcFrameCount = calcFrameCount & 0xffffffff;
86  }
87 
88  if (calcFrameCount == frameCount){
89  oldFrameCount = frameCount;
90  return true;
91  }
92  if (verbose > 0){
93  std::cout << "***** Error Frame Count ***** : calcFrameCount " << calcFrameCount << " frameCount " << frameCount << " allCountedFrames " << summary.fAllCountedFrames.back() << std::endl;
94  PrintFrame(frame);
95  }
96 
97  oldFrameCount = frameCount;
98  return false;
99 }
void PrintFrame(std::vector< ULong64_t > &frame)
int oldDiffAllFrameCount
unsigned int oldFrameCount
int fAllPartialResets
count of all partial resets detected
int fMissingFrames
count of all missing frames (not very reliable)
std::vector< ULong64_t > fAllCountedFrames
counts all frames within a partial reset
int fSuperFrameCount
count of frame counter overflow (should not happen because the frame counter is HUGE ...
int verbose
ULong64_t framesSinceLastData
RunSummary summary
bool CheckHitCount ( std::vector< ULong64_t >  frame)

Definition at line 25 of file PastaTBRawToRoot.C.

References nHits, PrintFrame(), and verbose.

Referenced by ProcessFrame().

26 {
27  ULong64_t header;
28  if (frame.size() > 0)
29  header = frame[0];
30  else
31  return false;
32 
33  unsigned int nHits = (header >> 32) & 0xff;
34  if (verbose > 1) std::cout << "Hits in Frame: " << nHits << std::endl;
35  if (nHits == frame.size() - 2){
36  return true;
37  }
38  else if (nHits == 0xff && frame.size() == 2)
39  return true;
40  if (verbose > 0){
41  std::cout << "***** Error Hit Count ***** Header: " << header << " nHits: " << nHits << " size frame: " << frame.size() - 2 << std::endl;
42  PrintFrame(frame);
43  }
44  return false;
45 }
void PrintFrame(std::vector< ULong64_t > &frame)
int nHits
Definition: RiemannTest.C:16
int verbose
int PastaTBRawToRoot ( TString  fileName)

Definition at line 165 of file PastaTBRawToRoot.C.

References creator, f, RunSummary::fAllCountedFrames, RunSummary::fCrcErrorCount, RunSummary::fCrcMatchCount, RunSummary::fMissingFrames, framesSinceLastData, RunSummary::fSingleWordFrames, RunSummary::fSuperFrameCount, RunSummary::fWrongFrameCount, RunSummary::fWrongHitCount, i, ProcessFrame(), t, TString, and verbose.

166 {
167  PndFileNameCreator creator(fileName.Data());
168  TString outputFileName = creator.GetDigiFileName();
169  TFile f(outputFileName, "RECREATE");
170  TTree t("PastaTB","Pasta Digis from TestBeam");
171 
172  TClonesArray* pastadata = new TClonesArray("PndMvdPastaDigi");
173  t.Branch("data", &pastadata);
174 // t.Branch("header", &summary);
175 
176 
177  std::ifstream inputFile(fileName.Data());
178  ULong64_t data;
179  std::vector<ULong64_t> frame;
180 
181  while (!(inputFile.eof())){
182  inputFile >> std::hex >> data;
183  if (verbose > 1) std::cout << std::hex << data << std::endl;
184  if (data == 0xffffffffff){
185  if (frame.size() > 1){
186  std::vector<PndMvdPastaDigi> pastavec = ProcessFrame(frame);
187  for (int i = 0; i < pastavec.size(); i++)
188  new((*pastadata)[pastadata->GetEntries()]) PndMvdPastaDigi(pastavec[i]);
189  if (pastavec.size() > 0){
190  t.Fill();
191  pastadata->Delete();
192  }
194  }
195  else if (frame.size() == 1) {
197  }
198  frame.erase(frame.begin(), frame.end());
200  if (summary.fAllCountedFrames.size() > 0)
201  summary.fAllCountedFrames.back()++;
202  } else {
203  frame.push_back(data);
204  }
205  }
206  std::cout << "*************** Summary **************" << std::endl;
207  std::cout << std::dec << "CRCMatch: " << summary.fCrcMatchCount <<
208  " CRCErrors: " << summary.fCrcErrorCount <<
209  " SingleWordFrames: " << summary.fSingleWordFrames <<
210  " WrongHitCount: " << summary.fWrongHitCount <<
211  " WrongFrameCount: " << summary.fWrongFrameCount <<
212  " missing Frames: " << summary.fMissingFrames <<
213  " SuperFrameCount: " << summary.fSuperFrameCount <<
214  std::endl;
215  summary.Write();
216  f.Write();
217  return 0;
218 }
Int_t i
Definition: run_full.C:25
int fWrongFrameCount
count of all frames where the expected frame ID did not match the frameID in the header ...
int fWrongHitCount
count of all frames where the hits in the header do not match the data
int fSingleWordFrames
count of all frames with just one word. This is an error a frame has at least two words ...
std::vector< PndMvdPastaDigi > ProcessFrame(std::vector< ULong64_t > frame)
A simple class which adds the corresponding file extensions to a given base class.
int fMissingFrames
count of all missing frames (not very reliable)
TFile * f
Definition: bump_analys.C:12
int fCrcErrorCount
count of all frames with wrong CRC
std::vector< ULong64_t > fAllCountedFrames
counts all frames within a partial reset
PndMvdCreateDefaultApvMap * creator
TTree * t
Definition: bump_analys.C:13
int fSuperFrameCount
count of frame counter overflow (should not happen because the frame counter is HUGE ...
int verbose
ULong64_t framesSinceLastData
RunSummary summary
int fCrcMatchCount
count of all frames with correct CRC
void PrintFrame ( std::vector< ULong64_t > &  frame)

Definition at line 19 of file PastaTBRawToRoot.C.

Referenced by CheckCRC(), CheckFrameCount(), and CheckHitCount().

19  {
20  for (auto data : frame)
21  std::cout << std::hex << data << std::endl;
22  std::cout << std::endl;
23 }
std::vector<PndMvdPastaDigi> ProcessFrame ( std::vector< ULong64_t >  frame)

Definition at line 118 of file PastaTBRawToRoot.C.

References PndMvdPasta::AnalyzeHeader(), PndMvdPasta::AnalyzeThresholdWordFull(), CheckCRC(), CheckFrameCount(), CheckHitCount(), RunSummary::fCrcErrorCount, RunSummary::fCrcMatchCount, framesSinceLastData, RunSummary::fWrongFrameCount, RunSummary::fWrongHitCount, i, FrameHeader::nEvents, and verbose.

Referenced by PastaTBRawToRoot().

119 {
120  std::vector<PndMvdPastaDigi> digis;
121  FrameHeader header = pastaConv.AnalyzeHeader(frame[0]);
122  if (header.nEvents == 0x21){
123  frame.erase(frame.begin());
124  pastaConv.AnalyzeHeader(frame[0]);
125  }
126  bool CRC_Ok = CheckCRC(frame);
127 
128  if (CRC_Ok == true){
129  if (verbose > 1) std::cout << "CRC match!" << std::endl;
131  } else {
132  if (verbose > 0) std::cout << "*********** CRC error *************" << std::endl;
135  return digis; // if CRC is corrupt then the analysis of the other data does not make sense!
136  }
137 
138  bool HitCount_Ok = CheckHitCount(frame);
139  bool FrameCount_Ok = CheckFrameCount(frame);
140 
141  if (HitCount_Ok == true){
142  if (verbose > 1) std::cout << "Correct Hit Count!" << std::endl;
143  } else {
144  if (verbose > 0) std::cout << "************* Wrong Hit Counts ***************" << std::endl;
146  }
147  if (FrameCount_Ok == true){
148  if (verbose > 1) std::cout << "Correct Frame Count!" << std::endl;
149  } else {
150  if (verbose > 0) std::cout << "************** Wrong Frame Count *************" << std::endl;
152  }
153  if (verbose > 1) std::cout << std::endl;
154 
155  if (CRC_Ok && HitCount_Ok && FrameCount_Ok && (frame.size() % 2 == 0)){
156  for (int i = 1; i < frame.size() -1; i+=2){
158  if (verbose > 1) std::cout << newDigi;
159  digis.push_back(newDigi);
160  }
161  }
162  return digis;
163 }
bool CheckCRC(std::vector< ULong64_t > frame)
Int_t i
Definition: run_full.C:25
ThresholdDataFullMode AnalyzeThresholdWordFull(ULong64_t word)
Definition: PndMvdPasta.cxx:22
PndMvdPasta pastaConv
int fWrongFrameCount
count of all frames where the expected frame ID did not match the frameID in the header ...
int fWrongHitCount
count of all frames where the hits in the header do not match the data
int fCrcErrorCount
count of all frames with wrong CRC
bool CheckFrameCount(std::vector< ULong64_t > frame)
FrameHeader AnalyzeHeader(ULong64_t word)
Definition: PndMvdPasta.cxx:39
int verbose
ULong64_t framesSinceLastData
RunSummary summary
bool CheckHitCount(std::vector< ULong64_t > frame)
int fCrcMatchCount
count of all frames with correct CRC

Variable Documentation

PndCRCCalculator decoder(16, 0x1021, 0, 0,0, 0x0F4A)

Referenced by CheckCRC().

ULong64_t diffAllFrameCount = 0

Definition at line 14 of file PastaTBRawToRoot.C.

ULong64_t framesSinceLastData = 0

Definition at line 13 of file PastaTBRawToRoot.C.

Referenced by CheckFrameCount(), PastaTBRawToRoot(), and ProcessFrame().

int oldDiffAllFrameCount = 0

Definition at line 15 of file PastaTBRawToRoot.C.

Referenced by CheckFrameCount().

unsigned int oldFrameCount = 0

Definition at line 12 of file PastaTBRawToRoot.C.

Referenced by CheckFrameCount().

PndMvdPasta pastaConv

Definition at line 9 of file PastaTBRawToRoot.C.

RunSummary summary

Definition at line 10 of file PastaTBRawToRoot.C.

Referenced by CreateErrorHisto().

int verbose = 1