FairRoot/PandaRoot
PndRingSorter.cxx
Go to the documentation of this file.
1 /*
2  * PndRingSorterT.cxx
3  *
4  * Created on: Jul 30, 2010
5  * Author: stockman
6  */
7 
8 #include "PndRingSorter.h"
9 
10 void PndRingSorter::AddElement(FairTimeStamp* digi, double timestamp){
11 
12  FairTimeStamp* newElement = CreateElement(digi);
13 
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) std::cout << "-I- PndRingSorterT::AddElement : Timestamp " << timestamp << " larger than 2 * bufferspace: " << fLowerBoundPointer.second + GetBufferSize() << " writing out " << index+1 << std::endl;
23  WriteOutAll();
24  SetLowerBound(timestamp);
25  }
26  else if (timestamp >= fLowerBoundPointer.second + GetBufferSize()){
27  if (fVerbose > 0) std::cout << "-I- PndRingSorterT::AddElement : Timestamp " << timestamp << " larger than bufferspace: " << fLowerBoundPointer.second + GetBufferSize() << " writing out " << index+1 << std::endl;
28  WriteOutElements(index+1);
29  SetLowerBound(timestamp);
30  }
31  fRingBuffer[index].insert(std::pair<double, FairTimeStamp*> (timestamp, newElement));
32 }
33 
34  void PndRingSorter::SetLowerBound(double timestampOfHitToWrite){
35  int index = CalcIndex(timestampOfHitToWrite + fCellWidth);
36 
37  int cellValue = timestampOfHitToWrite / fCellWidth;
38 
39  fLowerBoundPointer.second = ((cellValue + 1) * fCellWidth) - GetBufferSize();
40  fLowerBoundPointer.first = index;
41  if (fVerbose > 0) std::cout << "-I- PndRingSorter::SetLowerBound " << index << " / " << fLowerBoundPointer.second << std::endl;
42 }
43 
45  if (fLowerBoundPointer.first >= index){
46  for (int i = fLowerBoundPointer.first; i < fRingBuffer.size(); i++)
48  for (int i = 0; i < index; i++)
50  }
51  else{
52  for (int i = fLowerBoundPointer.first; i < index; i++)
54  }
55 // if (fVerbose > 1){
56  std::cout << "-I- PndRingSorter::WriteOutElements: Size of Output-Array: " << fOutputData.size() << std::endl;
57 // for (int i = 0; i < fOutputData.size(); i++)
58 // std::cout << fOutputData[i].size() << " | ";
59 // std::cout << std::endl;
60 // }
61 }
62 
64  std::multimap<double, FairTimeStamp*>* myDataField = &fRingBuffer.at(index);
65  std::multimap<double, FairTimeStamp*>::iterator it;
66  if (!myDataField->empty()) {
67  if (fVerbose > 1);
68  std::cout << "-I- PndRingSorterT:WriteOutElement ";
69  myDataField->begin()->second->Print();
70  std::cout << std::endl;
71  for (it = myDataField->begin(); it != myDataField->end(); it++){
72  fOutputData.push_back(it->second);
73  }
74  myDataField->clear();
75  }
76 }
77 
79  int index = val / fCellWidth;
80  while (index >= fRingBuffer.size()){
81  index -= fRingBuffer.size();
82  }
83  return index;
84 }
85 
virtual void AddElement(FairTimeStamp *digi, double timestamp)
std::vector< FairTimeStamp * > fOutputData
Definition: PndRingSorter.h:59
TClonesArray * digi
Int_t i
Definition: run_full.C:25
Double_t val[nBoxes][nFEBox]
Definition: createCalib.C:11
virtual FairTimeStamp * CreateElement(FairTimeStamp *data)=0
double fCellWidth
Definition: PndRingSorter.h:61
virtual void WriteOutAll()
Definition: PndRingSorter.h:34
int CalcIndex(double val)
virtual void SetLowerBound(double timestampOfHitToWrite)
virtual double GetBufferSize()
Definition: PndRingSorter.h:37
ClassImp(PndAnaContFact)
std::pair< int, double > fLowerBoundPointer
Definition: PndRingSorter.h:60
virtual void WriteOutElement(int index)
writes out the entry at the index and clears it
virtual void WriteOutElements(int index)
writes out the entries from LowerBoundPointer up to index
std::vector< std::multimap< double, FairTimeStamp * > > fRingBuffer
Definition: PndRingSorter.h:58