forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDigitsWriteoutBuffer.h
More file actions
132 lines (105 loc) · 5.04 KB
/
DigitsWriteoutBuffer.h
File metadata and controls
132 lines (105 loc) · 5.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
#ifndef ALICEO2_EMCAL_DIGITSWRITEOUTBUFFER_H_
#define ALICEO2_EMCAL_DIGITSWRITEOUTBUFFER_H_
#include <memory>
#include <unordered_map>
#include <vector>
#include <deque>
#include <list>
#include <gsl/span>
#include "DataFormatsEMCAL/Digit.h"
#include "CommonDataFormat/InteractionRecord.h"
#include "EMCALSimulation/LabeledDigit.h"
#include "EMCALSimulation/DigitsVectorStream.h"
namespace o2
{
namespace emcal
{
/// \class DigitsWriteoutBuffer
/// \brief Container class for time sampled digits
/// \ingroup EMCALsimulation
/// \author Hadi Hassan, ORNL
/// \author Markus Fasel, ORNL
/// \date 08/03/2021
class DigitsWriteoutBuffer
{
public:
/// Default constructor
DigitsWriteoutBuffer(unsigned int nTimeBins = 15);
/// Destructor
~DigitsWriteoutBuffer() = default;
/// clear the container
void clear();
/// clear DigitsVectorStream
void flush() { mDigitStream.clear(); }
void init();
/// Reserve space for the future container
void reserve();
/// This is for the readout window that was interrupted by the end of the run
void finish();
double getTriggerTime() const { return mTriggerTime; }
double getEventTime() const { return mLastEventTime; }
bool isLive(double t) const
{
return ((t - mTriggerTime) < mLiveTime || (t - mTriggerTime) >= (mLiveTime + mBusyTime - mPreTriggerTime));
}
bool isLive() const
{
return ((mLastEventTime - mTriggerTime) < (mLiveTime - mPreTriggerTime) || (mLastEventTime - mTriggerTime) >= (mLiveTime + mBusyTime - mPreTriggerTime));
}
/// Check if current collision was triggered
/// \return true if event was triggered
bool isCurrentEventTriggered() const
{
return mLastEventTime == mTriggerTime;
}
// function returns true if the collision occurs 600ns before the readout window is open
// Look here for more details https://alice.its.cern.ch/jira/browse/EMCAL-681
bool preTriggerCollision() const { return ((mLastEventTime - mTriggerTime) >= (mLiveTime + mBusyTime - mPreTriggerTime)); }
/// Add digit to the container
/// \param towerID Cell ID
/// \param dig Labaled digit to add
/// \param eventTime The time of the event (w.r.t Tigger time)
void addDigits(unsigned int towerID, std::vector<LabeledDigit>& digList);
/// This function sets the right time for all digits in the buffer
void setSampledDigitsTime();
/// Setting the buffer size
void setBufferSize(unsigned int nsamples) { mBufferSize = nsamples; }
unsigned int getBufferSize() const { return mBufferSize; }
/// forward the marker for every 100 ns
void forwardMarker(o2::InteractionTimeRecord record, bool trigger);
/// Setters for the live time, busy time, pre-trigger time
void setLiveTime(unsigned int liveTime) { mLiveTime = liveTime; }
void setBusyTime(unsigned int busyTime) { mBusyTime = busyTime; }
void setPreTriggerTime(unsigned int pretriggerTime) { mPreTriggerTime = pretriggerTime; }
unsigned int getPhase() const { return mPhase; }
const std::vector<o2::emcal::Digit>& getDigits() const { return mDigitStream.getDigits(); }
const std::vector<o2::emcal::TriggerRecord>& getTriggerRecords() const { return mDigitStream.getTriggerRecords(); }
const o2::dataformats::MCTruthContainer<o2::emcal::MCLabel>& getMCLabels() const { return mDigitStream.getMCLabels(); }
private:
unsigned int mBufferSize = 15; ///< The size of the buffer
unsigned int mLiveTime = 1500; ///< EMCal live time (ns)
unsigned int mBusyTime = 35000; ///< EMCal busy time (ns)
unsigned int mPreTriggerTime = 600; ///< EMCal pre-trigger time (ns)
unsigned long mTriggerTime = 0; ///< Time of the collision that fired the trigger (ns)
unsigned long mLastEventTime = 0; ///< The event time of last collisions in the readout window
unsigned int mPhase = 0; ///< The event L1 phase
unsigned int mSwapPhase = 0; ///< BC phase swap
bool mFirstEvent = true; ///< Flag to the first event in the run
std::deque<o2::emcal::DigitTimebin> mTimedDigitsFuture; ///< Container for time sampled digits per tower ID for future digits
std::deque<o2::emcal::DigitTimebin> mTimedDigitsPast; ///< Container for time sampled digits per tower ID for past digits
o2::emcal::DigitsVectorStream mDigitStream; ///< Output vector streamer
ClassDefNV(DigitsWriteoutBuffer, 1);
};
} // namespace emcal
} // namespace o2
#endif /* ALICEO2_EMCAL_DIGITSWRITEOUTBUFFER_H_ */