Project
Loading...
Searching...
No Matches
DigitsWriteoutBufferTRU.cxx
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#include <unordered_map>
13#include <vector>
14#include <list>
15#include <deque>
16#include <iostream>
17#include <gsl/span>
21#include <fairlogger/Logger.h> // for LOG
23
24using namespace o2::emcal;
25
26//_____________________________________________________________________
27//
28void DigitsWriteoutBufferTRU::fillOutputContainer(bool isEndOfTimeFrame, InteractionRecord& nextInteractionRecord, std::vector<TRUElectronics>& patchesFromAllTRUs, LZEROElectronics& LZERO)
29{
30 int eventTimeBin = 13;
31 bool needsEmptyTimeBins = false;
32 int nProcessedTimeBins = 0;
33
34 std::deque<o2::emcal::DigitTimebinTRU>
35 mDequeTime;
36
37 // If end of run or end of timeframe read out what we have
38 bool isEnd = mEndOfRun || isEndOfTimeFrame;
39 // Checking the Interaction Record for the time of the next event in BC units
40 // Difference becomes the new marker if the collision happens before 13 samples
41 auto difference = nextInteractionRecord.toLong() - mCurrentInteractionRecord.toLong();
42 if (mNoPileupMode || difference >= 13 || isEnd) {
43 // Next collision happening way after the current one, just
44 // send out and clear entire buffer
45 // Simplification and optimization at software level - hardware would continuosly sample, but here we don't need to allocate memory dynamically which we are never going to use
46 // Also in a dedicated no-pileup mode we always write out after each collision.
47 for (auto& time : mTimeBins) {
48 mDequeTime.push_back(time);
49 }
50 LZERO.fill(mDequeTime, mCurrentInteractionRecord, patchesFromAllTRUs);
51 auto TriggerInputs = LZERO.getTriggerInputs();
52 auto TriggerInputsPatches = LZERO.getTriggerInputsPatches();
53 int nIter = TriggerInputs.size();
54 LOG(debug) << "DIG TRU fillOutputContainer in DigitsWriteoutBufferTRU: size of TriggerInputs = " << nIter;
55 // for (auto& patches : patchesFromAllTRUs) {
56 // LZERO.updatePatchesADC(patches);
57 // LZERO.peakFinderOnAllPatches(patches);
58 // }
59 LOG(debug) << "DIG TRU fillOutputContainer in DigitsWriteoutBufferTRU: LOW IR";
60
61 mCurrentInteractionRecord = nextInteractionRecord;
62 clear();
63
64 } else {
65 // Next collsions happing in the tail of the current one,
66 // Copy out up to difference and pop and push this amount
67 // of samples
68
69 // Now filling the vector stream
70 for (auto& time : mTimeBins) {
71 if (!(nProcessedTimeBins + mFirstTimeBin < difference)) {
72 break;
73 }
74
75 mDequeTime.push_back(time);
76
77 ++nProcessedTimeBins;
78 }
79
80 LZERO.fill(mDequeTime, mCurrentInteractionRecord, patchesFromAllTRUs);
81 auto TriggerInputs = LZERO.getTriggerInputs();
82 auto TriggerInputsPatches = LZERO.getTriggerInputsPatches();
83 int nIter = TriggerInputs.size();
84 LOG(debug) << "DIG TRU fillOutputContainer in DigitsWriteoutBufferTRU: size of TriggerInputs = " << nIter;
85 // for (auto& patches : patchesFromAllTRUs) {
86 // LZERO.updatePatchesADC(patches);
87 // LZERO.peakFinderOnAllPatches(patches);
88 // }
89 mCurrentInteractionRecord = nextInteractionRecord;
90
91 if (nProcessedTimeBins > 0) {
92 mFirstTimeBin += nProcessedTimeBins;
93 while (nProcessedTimeBins--) {
94 mTimeBins.pop_front(); // deque
95 }
96 }
97 reserve(15);
98
99 LOG(debug) << "DIG TRU fillOutputContainer in DigitsWriteoutBufferTRU: HIGH IR";
100 }
101}
102//________________________________________________________
103// Constructor: reserves space to keep always a minimum buffer size
104DigitsWriteoutBufferTRU::DigitsWriteoutBufferTRU(unsigned int nTimeBins) : mBufferSize(nTimeBins)
105{
106 for (int itime = 0; itime < nTimeBins; itime++) {
107 mTimeBins.push_back(o2::emcal::DigitTimebinTRU());
108 }
109}
110//________________________________________________________
111// Reserve space to keep always a minimum buffer size (put it in the cpp)
113{
114 const auto space = mBufferSize + eventTimeBin - mFirstTimeBin;
115 if (mTimeBins.size() < space) {
116 mTimeBins.resize(space);
117 }
118}
119//________________________________________________________
121{
122 const SimParam* simParam = &(o2::emcal::SimParam::Instance());
123
124 mLiveTime = simParam->getLiveTime();
125 mBusyTime = simParam->getBusyTime();
126 mNoPileupMode = simParam->isDisablePileup();
127 mEndOfRun = 0;
128
129 // mDigitStream.init();
130}
131//________________________________________________________
133{
134 mTimeBins.clear();
135 reserve(15);
136 // mEndOfRun = 0;
137}
138//________________________________________________________
140{
141 mEndOfRun = 1;
142}
143//________________________________________________________
144// Add digits to the buffer
145void DigitsWriteoutBufferTRU::addDigits(unsigned int towerID, std::vector<Digit>& digList)
146{
147 // mTimeBin has to have the absolute time information
148 for (int ientry = 0; ientry < digList.size(); ientry++) {
149
150 auto& buffEntry = mTimeBins[ientry];
151 auto& dig = digList.at(ientry);
152
153 auto towerEntry = buffEntry.mDigitMap->find(towerID);
154 if (towerEntry == buffEntry.mDigitMap->end()) {
155 towerEntry = buffEntry.mDigitMap->insert(std::pair<int, std::list<o2::emcal::Digit>>(towerID, std::list<o2::emcal::Digit>())).first;
156 }
157 towerEntry->second.push_back(dig);
158 }
159}
int16_t time
Definition RawEventData.h:4
std::ostringstream debug
void addDigits(unsigned int towerID, std::vector< o2::emcal::Digit > &digList)
DigitsWriteoutBufferTRU(unsigned int nTimeBins=15)
Default constructor.
void finish()
This is for the readout window that was interrupted by the end of the run.
void fillOutputContainer(bool isEndOfTimeFrame, InteractionRecord &nextInteractionRecord, std::vector< TRUElectronics > &patchesFromAllTRUs, LZEROElectronics &LZERO)
Container class for Digits, MC lebels, and trigger records.
void fill(const std::deque< o2::emcal::DigitTimebinTRU > &digitlist, const o2::InteractionRecord record, std::vector< TRUElectronics > &patchesFromAllTRUs)
const std::vector< EMCALTriggerInputsPatch > & getTriggerInputsPatches() const
Getter for the trigger inputs per patches found by the LZERO algorithm.
const std::vector< EMCALTriggerInputs > & getTriggerInputs() const
Getter for the trigger inputs found by the LZERO algorithm.
EMCal simulation parameters.
Definition SimParam.h:28
Float_t getBusyTime() const
Definition SimParam.h:64
Bool_t isDisablePileup() const
Definition SimParam.h:73
Float_t getLiveTime() const
Definition SimParam.h:63
DigitTimebinBase templated, used for the DigitsWriteoutBuffer and DigitsWriteoutBufferTRU.
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"