|
| 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_ */ |
0 commit comments