Project
Loading...
Searching...
No Matches
RingBuffer.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12#ifndef O2_CALIBRATION_PHOS_RINGBUFFER_H
13#define O2_CALIBRATION_PHOS_RINGBUFFER_H
14
17
18#include <TLorentzVector.h>
19#include <TVector3.h>
20#include <array>
21
22namespace o2
23{
24namespace phos
25{
26
27// For real/mixed distribution calculation
29{
30 public:
31 RingBuffer() = default;
32 ~RingBuffer() = default;
33
34 short size()
35 {
36 if (mFilled) {
37 return kBufferSize;
38 } else {
39 return mCurrent;
40 }
41 }
42 void addEntry(TLorentzVector& v)
43 {
44 mBuffer[mCurrent] = v;
45 mCurrent++;
46 if (mCurrent >= kBufferSize) {
47 mFilled = true;
48 mCurrent -= kBufferSize;
49 }
50 }
51 const TLorentzVector& getEntry(short index) const
52 {
53 //get entry from (mCurrent-1) corresponding to index=size()-1 down to size
54 if (mFilled) {
55 index += mCurrent;
56 }
57 index = index % kBufferSize;
58 return mBuffer[index];
59 }
60 //mark that next added entry will be from next event
61 void startNewEvent() { mStartCurrentEvent = mCurrent; }
62
63 bool isCurrentEvent(short index) const
64 {
65 if (mCurrent >= mStartCurrentEvent) {
66 return (index >= mStartCurrentEvent && index < mCurrent);
67 } else {
68 return (index >= mStartCurrentEvent || index < mCurrent);
69 }
70 }
71
72 private:
73 static constexpr short kBufferSize = 100;
74 std::array<TLorentzVector, kBufferSize> mBuffer;
75 bool mFilled = false;
76 short mCurrent = 0;
77 short mStartCurrentEvent = 0;
78};
79} // namespace phos
80} // namespace o2
81
82#endif
bool isCurrentEvent(short index) const
Definition RingBuffer.h:63
void addEntry(TLorentzVector &v)
Definition RingBuffer.h:42
const TLorentzVector & getEntry(short index) const
Definition RingBuffer.h:51
const GLdouble * v
Definition glcorearb.h:832
GLuint index
Definition glcorearb.h:781
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...