EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FairRingSorter.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file FairRingSorter.cxx
1 // -------------------------------------------------------------------------
2 // FairRingSorter.cxx
3 // Created on: Jul 30, 2010
4 // Author: stockman
5 // -------------------------------------------------------------------------
6 
7 #include "FairRingSorter.h"
8 
9 
10 
11 void FairRingSorter::AddElement(FairTimeStamp* digi, double timestamp)
12 {
13  FairTimeStamp* newElement = CreateElement(digi);
14  if (timestamp < fLowerBoundPointer.second) {
15  std::cout << "-E- Timestamp " << timestamp << " below lower bound " << fLowerBoundPointer.second << std::endl;
16  newElement->Print();
17  return;
18  }
19  int index = CalcIndex(timestamp);
20 
21  if (timestamp >= fLowerBoundPointer.second + (2 * GetBufferSize())) {
22  if (fVerbose > 0) {
23  std::cout << "-I- FairRingSorterT::AddElement : Timestamp "
24  << timestamp << " larger than 2 * bufferspace: " << fLowerBoundPointer.second + GetBufferSize() << " writing out " << index+1 << std::endl;
25  }
26  WriteOutAll();
27  SetLowerBound(timestamp);
28  } else if (timestamp >= fLowerBoundPointer.second + GetBufferSize()) {
29  if (fVerbose > 0) {
30  std::cout << "-I- FairRingSorterT::AddElement :Timestamp "
31  << timestamp << " larger than bufferspace: "
32  << fLowerBoundPointer.second + GetBufferSize() << " writing out " << index+1 << std::endl;
33  }
34  WriteOutElements(index+1);
35  SetLowerBound(timestamp);
36  }
37  fRingBuffer[index].insert(std::pair<double, FairTimeStamp*> (timestamp, newElement));
38 }
39 
40 void FairRingSorter::SetLowerBound(double timestampOfHitToWrite)
41 {
42  int index = CalcIndex(timestampOfHitToWrite + fCellWidth);
43 
44  int cellValue = (int)(timestampOfHitToWrite / fCellWidth);
45 
46  fLowerBoundPointer.second = ((cellValue + 1) * fCellWidth) - GetBufferSize();
47  fLowerBoundPointer.first = index;
48  if (fVerbose > 0) { std::cout << "-I- FairRingSorter::SetLowerBound " << index << " / " << fLowerBoundPointer.second << std::endl; }
49 }
50 
52 {
53  if (fLowerBoundPointer.first >= index) {
54  for (int i = fLowerBoundPointer.first; i < fRingBuffer.size(); i++) {
55  WriteOutElement(i);
56  }
57  for (int i = 0; i < index; i++) {
58  WriteOutElement(i);
59  }
60  } else {
61  for (int i = fLowerBoundPointer.first; i < index; i++) {
62  WriteOutElement(i);
63  }
64  }
65  if (fVerbose > 1) {
66  std::cout << "-I- FairRingSorter::WriteOutElements: Size of Output-Array: " << fOutputData.size() << std::endl;
67  for (int i = 0; i < fOutputData.size(); i++) {
68  fOutputData[i]->Print();
69  std::cout << " | ";
70  }
71  std::cout << std::endl;
72  }
73 }
74 
76 {
77  std::multimap<double, FairTimeStamp*>* myDataField = &fRingBuffer.at(index);
78  std::multimap<double, FairTimeStamp*>::iterator it;
79  if (!myDataField->empty()) {
80  if (fVerbose > 1) { ; }
81  std::cout << "-I- FairRingSorterT:WriteOutElement ";
82  myDataField->begin()->second->Print();
83  std::cout << std::endl;
84  for (it = myDataField->begin(); it != myDataField->end(); it++) {
85  fOutputData.push_back(it->second);
86  }
87  myDataField->clear();
88  }
89 }
90 
92 {
93  int index = (int)(val / fCellWidth);
94  while (index >= fRingBuffer.size()) {
95  index -= fRingBuffer.size();
96  }
97  return index;
98 }
99