Skip to content

Commit ed32825

Browse files
hahassan7sawenzel
authored andcommitted
[EMCAL-685] Implementation of a ring buffer for EMCAL digits
1 parent cefbedd commit ed32825

4 files changed

Lines changed: 149 additions & 2 deletions

File tree

Detectors/EMCAL/simulation/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@
1010

1111
o2_add_library(EMCALSimulation
1212
SOURCES src/Detector.cxx src/Digitizer.cxx src/DigitizerTask.cxx
13-
src/SpaceFrame.cxx src/SimParam.cxx src/LabeledDigit.cxx
14-
src/RawWriter.cxx
13+
src/DigitsWriteoutBuffer.cxx src/SpaceFrame.cxx src/SimParam.cxx
14+
src/LabeledDigit.cxx src/RawWriter.cxx
1515
PUBLIC_LINK_LIBRARIES O2::EMCALBase O2::DetectorsBase O2::SimConfig O2::SimulationDataFormat O2::Headers O2::DetectorsRaw)
1616

1717
o2_target_root_dictionary(EMCALSimulation
1818
HEADERS include/EMCALSimulation/Detector.h
1919
include/EMCALSimulation/Digitizer.h
2020
include/EMCALSimulation/DigitizerTask.h
21+
include/EMCALSimulation/DigitsWriteoutBuffer.h
2122
include/EMCALSimulation/RawWriter.h
2223
include/EMCALSimulation/SpaceFrame.h
2324
include/EMCALSimulation/SimParam.h
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
#ifndef ALICEO2_EMCAL_DIGITSWRITEOUTBUFFER_H_
12+
#define ALICEO2_EMCAL_DIGITSWRITEOUTBUFFER_H_
13+
14+
#include <memory>
15+
#include <unordered_map>
16+
#include <vector>
17+
#include <deque>
18+
#include "DataFormatsEMCAL/Digit.h"
19+
#include "EMCALSimulation/LabeledDigit.h"
20+
21+
namespace o2
22+
{
23+
namespace emcal
24+
{
25+
26+
/// \class DigitsWriteoutBuffer
27+
/// \brief Container class for time sampled digits
28+
/// \ingroup EMCALsimulation
29+
/// \author Hadi Hassan, ORNL
30+
/// \author Markus Fasel, ORNL
31+
/// \date 08/03/2021
32+
33+
class DigitsWriteoutBuffer
34+
{
35+
public:
36+
/// Default constructor
37+
DigitsWriteoutBuffer(unsigned int nTimeBins = 30, unsigned int binWidth = 100);
38+
39+
/// Destructor
40+
~DigitsWriteoutBuffer() = default;
41+
42+
/// Reset the container
43+
void reset();
44+
45+
/// Add digit to the container
46+
/// \param towerID Cell ID
47+
/// \param dig Labaled digit to add
48+
/// \param eventTime The time of the event (w.r.t Tigger time)
49+
void addDigit(unsigned int towerID, LabeledDigit dig, double eventTime);
50+
51+
/// Getter for the last N entries (time samples) in the ring buffer
52+
/// \param nsample number of entries to be written
53+
/// \return Vector of map of cell IDs and labeled digits in that cell
54+
gsl::span<std::unordered_map<int, LabeledDigit>> getLastNSamples(int nsample = 15);
55+
56+
/// Forwards the marker to the next time sample every mTimeBinWidth
57+
void forwardMarker(double eventTime);
58+
59+
void setNumberReadoutSamples(unsigned int nsamples) { mNumberReadoutSamples = nsamples; }
60+
61+
/// Getter for current position in the ring buffer
62+
/// \return current position
63+
std::tuple<double, int> getCurrentTimeAndPosition() const { return std::make_tuple(mMarker.mReferenceTime, mMarker.mPositionInBuffer - mTimedDigits.begin()); }
64+
65+
private:
66+
struct Marker {
67+
double mReferenceTime;
68+
std::deque<std::unordered_map<int, LabeledDigit>>::iterator mPositionInBuffer;
69+
};
70+
71+
unsigned int mBufferSize = 30; ///< The size of the buffer, it has to be at least 2 times the size of the readout cycle
72+
unsigned int mTimeBinWidth = 100; ///< The size of the time bin (ns)
73+
unsigned int mNumberReadoutSamples = 15; ///< The number of smaples in a readout window
74+
Marker mMarker; ///< Marker for the current time sample
75+
std::deque<std::unordered_map<int, LabeledDigit>> mTimedDigits; ///< Container for time sampled digits per tower ID
76+
77+
ClassDefNV(DigitsWriteoutBuffer, 1);
78+
};
79+
80+
} // namespace emcal
81+
82+
} // namespace o2
83+
84+
#endif /* ALICEO2_EMCAL_DIGITSWRITEOUTBUFFER_H_ */
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
#include <unordered_map>
12+
#include <vector>
13+
#include <deque>
14+
#include <gsl/span>
15+
#include "EMCALSimulation/LabeledDigit.h"
16+
#include "EMCALSimulation/DigitsWriteoutBuffer.h"
17+
18+
using namespace o2::emcal;
19+
20+
DigitsWriteoutBuffer::DigitsWriteoutBuffer(unsigned int nTimeBins, unsigned int binWidth) : mBufferSize(nTimeBins),
21+
mTimeBinWidth(binWidth)
22+
{
23+
mTimedDigits.resize(nTimeBins);
24+
mMarker.mReferenceTime = 0.;
25+
mMarker.mPositionInBuffer = mTimedDigits.begin();
26+
}
27+
28+
void DigitsWriteoutBuffer::reset()
29+
{
30+
mTimedDigits.clear();
31+
mMarker.mReferenceTime = 0.;
32+
mMarker.mPositionInBuffer = mTimedDigits.begin();
33+
}
34+
35+
void DigitsWriteoutBuffer::addDigit(unsigned int towerID, LabeledDigit dig, double eventTime)
36+
{
37+
38+
int nsamples = int((eventTime - mMarker.mReferenceTime) / mTimeBinWidth);
39+
auto timeEntry = mMarker.mPositionInBuffer + nsamples;
40+
timeEntry->insert(std::make_pair(towerID, dig));
41+
}
42+
43+
void DigitsWriteoutBuffer::forwardMarker(double eventTime)
44+
{
45+
mMarker.mReferenceTime = eventTime;
46+
mMarker.mPositionInBuffer++;
47+
48+
// Allocate new memory at the end
49+
mTimedDigits.push_back(std::unordered_map<int, LabeledDigit>());
50+
51+
// Drop entry at the front, because it is outside the current readout window
52+
// only done if we have at least 15 entries
53+
if (mMarker.mPositionInBuffer - mTimedDigits.begin() > mNumberReadoutSamples) {
54+
mTimedDigits.pop_front();
55+
}
56+
}
57+
58+
gsl::span<std::unordered_map<int, LabeledDigit>> DigitsWriteoutBuffer::getLastNSamples(int nsamples)
59+
{
60+
return gsl::span<std::unordered_map<int, LabeledDigit>>(&mTimedDigits[int(mMarker.mPositionInBuffer - mTimedDigits.begin() - nsamples)], nsamples);
61+
}

Detectors/EMCAL/simulation/src/EMCALSimulationLinkDef.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#pragma link C++ class o2::base::DetImpl < o2::emcal::Detector> + ;
1919
#pragma link C++ class o2::emcal::Digitizer + ;
2020
#pragma link C++ class o2::emcal::DigitizerTask + ;
21+
#pragma link C++ class o2::emcal::DigitsWriteoutBuffer + ;
2122
#pragma link C++ class o2::emcal::SimParam + ;
2223
#pragma link C++ class o2::emcal::LabeledDigit + ;
2324
#pragma link C++ class o2::emcal::RawWriter + ;

0 commit comments

Comments
 (0)