Project
Loading...
Searching...
No Matches
Event.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#include <algorithm>
14#include <iostream>
15
16using namespace o2::focal;
17
19{
20 check_pad_layers(index);
21 return mPadLayers[index];
22}
23
24const PadLayerEvent& Event::getPadLayer(unsigned int index) const
25{
26 check_pad_layers(index);
27 return mPadLayers[index];
28}
29
31{
32 check_pixel_layers(index);
33 return mPixelLayers[index];
34}
35const PixelLayerEvent& Event::getPixelLayer(unsigned int index) const
36{
37 check_pixel_layers(index);
38 return mPixelLayers[index];
39}
40
41void Event::setPadLayer(unsigned int layer, const PadLayerEvent& event)
42{
43 check_pad_layers(layer);
44 mPadLayers[layer] = event;
45}
46
48{
49 check_pixel_layers(layer);
50 mPixelLayers[layer] = event;
51}
52
54{
55 mInitialized = false;
56 for (auto& padlayer : mPadLayers) {
57 padlayer.reset();
58 }
59 for (auto& pixellayer : mPixelLayers) {
60 pixellayer.reset();
61 }
62}
63
64void Event::construct(const o2::InteractionRecord& interaction, gsl::span<const PadLayerEvent> pads, gsl::span<const PixelChipRecord> eventPixels, gsl::span<const PixelHit> pixelHits)
65{
66 reset();
67 mInteractionRecord = interaction;
68 int ilayer = 0;
69 for (auto& padlayer : pads) {
70 mPadLayers[ilayer] = padlayer;
71 ilayer++;
72 }
73
74 int currentlast = 0;
75 for (auto& chip : eventPixels) {
76 if (chip.getLayerID() > 1) {
77 std::cerr << "Invalid layer ID chip " << chip.getChipID() << ": " << chip.getLayerID() << std::endl;
78 continue;
79 }
80 if (chip.getNumberOfHits()) {
81 if (chip.getFirstHit() >= pixelHits.size()) {
82 std::cerr << "First hit index " << chip.getFirstHit() << " exceeding hit contiainer " << pixelHits.size() << std::endl;
83 continue;
84 }
85 if (chip.getFirstHit() + chip.getNumberOfHits() - 1 >= pixelHits.size()) {
86 std::cerr << "First hit index " << chip.getFirstHit() + chip.getNumberOfHits() - 1 << " exceeding hit contiainer " << pixelHits.size() << std::endl;
87 continue;
88 }
89 mPixelLayers[chip.getLayerID()].addChip(chip.getFeeID(), chip.getLaneID(), chip.getChipID(), chip.getStatusCode(), pixelHits.subspan(chip.getFirstHit(), chip.getNumberOfHits()));
90 }
91 currentlast = chip.getFirstHit() + chip.getNumberOfHits();
92 }
93 if (currentlast < pixelHits.size()) {
94 std::cerr << "Inconsistent number of hits / event : all chips -> " << currentlast << " hits, container size -> " << pixelHits.size() << std::endl;
95 }
96 mInitialized = true;
97}
98
99void Event::check_pad_layers(unsigned int index) const
100{
103 }
104}
105
106void Event::check_pixel_layers(unsigned int index) const
107{
110 }
111}
112
113void PadLayerEvent::setHeader(unsigned int half, uint8_t header, uint8_t bc, uint8_t wadd, uint8_t fourbits, uint8_t trailer)
114{
115 check_halfs(half);
116 auto& asicheader = mHeaders[half];
117 asicheader.mHeader = header;
118 asicheader.mBC = bc;
119 asicheader.mFourbits = fourbits;
120 asicheader.mWADD = wadd;
121 asicheader.mTrailer = trailer;
122}
123
124void PadLayerEvent::setChannel(unsigned int channel, uint16_t adc, uint16_t toa, uint16_t tot)
125{
126 check_channel(channel);
127 auto& asicchannel = mChannels[channel];
128 asicchannel.mADC = adc;
129 asicchannel.mTOA = toa;
130 asicchannel.mTOT = tot;
131}
132
133void PadLayerEvent::setCMN(unsigned int channel, uint16_t adc, uint16_t toa, uint16_t tot)
134{
135 check_halfs(channel);
136 auto& cmn = mCMN[channel];
137 cmn.mADC = adc;
138 cmn.mTOA = toa;
139 cmn.mTOT = tot;
140}
141
142void PadLayerEvent::setCalib(unsigned int channel, uint16_t adc, uint16_t toa, uint16_t tot)
143{
144 check_halfs(channel);
145 auto& calib = mCalib[channel];
146 calib.mADC = adc;
147 calib.mTOA = toa;
148 calib.mTOT = tot;
149}
150
151void PadLayerEvent::setTrigger(unsigned int window, uint32_t header0, uint32_t header1, const gsl::span<uint8_t> triggers)
152{
153 if (window >= constants::PADLAYER_WINDOW_LENGTH) {
155 }
156 auto& currenttrigger = mTriggers[window];
157 currenttrigger.mHeader0 = header0;
158 currenttrigger.mHeader1 = header1;
159 std::copy(triggers.begin(), triggers.end(), currenttrigger.mTriggers.begin());
160}
161
162const PadLayerEvent::Header& PadLayerEvent::getHeader(unsigned int half) const
163{
164 check_halfs(half);
165 return mHeaders[half];
166}
167
168const PadLayerEvent::Channel& PadLayerEvent::getChannel(unsigned int channel) const
169{
170 check_channel(channel);
171 return mChannels[channel];
172}
173const PadLayerEvent::Channel& PadLayerEvent::getCMN(unsigned int half) const
174{
175 check_halfs(half);
176 return mCMN[half];
177}
178const PadLayerEvent::Channel& PadLayerEvent::getCalib(unsigned int half) const
179{
180 check_halfs(half);
181 return mCalib[half];
182}
183
185{
186 if (window >= constants::PADLAYER_WINDOW_LENGTH) {
188 }
189 return mTriggers[window];
190}
191
192std::array<uint16_t, constants::PADLAYER_MODULE_NCHANNELS> PadLayerEvent::getADCs() const
193{
194 std::array<uint16_t, constants::PADLAYER_MODULE_NCHANNELS> adcs;
195 for (std::size_t ichan = 0; ichan < constants::PADLAYER_MODULE_NCHANNELS; ichan++) {
196 adcs[ichan] = mChannels[ichan].mADC;
197 }
198 return adcs;
199}
200std::array<uint16_t, constants::PADLAYER_MODULE_NCHANNELS> PadLayerEvent::getTOAs() const
201{
202 std::array<uint16_t, constants::PADLAYER_MODULE_NCHANNELS> toas;
203 for (std::size_t ichan = 0; ichan < constants::PADLAYER_MODULE_NCHANNELS; ichan++) {
204 toas[ichan] = mChannels[ichan].mTOA;
205 }
206 return toas;
207}
208std::array<uint16_t, constants::PADLAYER_MODULE_NCHANNELS> PadLayerEvent::getTOTs() const
209{
210 std::array<uint16_t, constants::PADLAYER_MODULE_NCHANNELS> tots;
211 for (std::size_t ichan = 0; ichan < constants::PADLAYER_MODULE_NCHANNELS; ichan++) {
212 tots[ichan] = mChannels[ichan].mTOT;
213 }
214 return tots;
215}
216
218{
219 for (auto& header : mHeaders) {
220 header.mBC = 0;
221 header.mHeader = 0;
222 header.mFourbits = 0;
223 header.mWADD = 0;
224 header.mTrailer = 0;
225 }
226 for (auto& chan : mChannels) {
227 chan.mADC = 0;
228 chan.mTOA = 0;
229 chan.mTOT = 0;
230 }
231 for (auto& calib : mCalib) {
232 calib.mADC = 0;
233 calib.mTOA = 0;
234 calib.mTOT = 0;
235 }
236 for (auto& cmn : mCMN) {
237 cmn.mADC = 0;
238 cmn.mTOA = 0;
239 cmn.mTOT = 0;
240 }
241 for (auto& trg : mTriggers) {
242 trg.mHeader0 = 0;
243 trg.mHeader1 = 0;
244 std::fill(trg.mTriggers.begin(), trg.mTriggers.end(), 0);
245 }
246}
247
248void PadLayerEvent::check_halfs(unsigned int half) const
249{
252 }
253}
254
255void PadLayerEvent::check_channel(unsigned int channel) const
256{
259 }
260}
261
263{
264 auto found = std::find_if(mChips.begin(), mChips.end(), [&chip](const PixelChip& testchip) { return chip == testchip; });
265 if (found != mChips.end()) {
266 std::copy(chip.mHits.begin(), chip.mHits.end(), std::back_inserter(found->mHits));
267 } else {
268 mChips.push_back(chip);
269 }
270}
271
272void PixelLayerEvent::addChip(int feeID, int laneID, int chipID, uint16_t statusCode, gsl::span<const PixelHit> hits)
273{
274 auto found = std::find_if(mChips.begin(), mChips.end(), [laneID, chipID, feeID](const PixelChip& testchip) { return chipID == testchip.mChipID && laneID == testchip.mLaneID && feeID == testchip.mFeeID; });
275 if (found != mChips.end()) {
276 std::copy(hits.begin(), hits.end(), std::back_inserter(found->mHits));
277 } else {
278 mChips.push_back({static_cast<uint8_t>(feeID), static_cast<uint8_t>(laneID), static_cast<uint8_t>(chipID), statusCode});
279 auto& currentchip = mChips.back();
280 std::copy(hits.begin(), hits.end(), std::back_inserter(currentchip.mHits));
281 }
282}
283
285{
286 mChips.clear();
287}
uint64_t bc
Definition RawEventData.h:5
void setPadLayer(unsigned int layer, const PadLayerEvent &event)
Definition Event.cxx:41
PadLayerEvent & getPadLayer(unsigned int index)
Definition Event.cxx:18
PixelLayerEvent & getPixelLayer(unsigned int index)
Definition Event.cxx:30
void construct(const o2::InteractionRecord &interaction, gsl::span< const PadLayerEvent > pads, gsl::span< const PixelChipRecord > eventPixels, gsl::span< const PixelHit > pixelHits)
Definition Event.cxx:64
void setPixelLayerEvent(unsigned int layer, const PixelLayerEvent &event)
Definition Event.cxx:47
std::array< uint16_t, constants::PADLAYER_MODULE_NCHANNELS > getADCs() const
Definition Event.cxx:192
const Channel & getCMN(unsigned int half) const
Definition Event.cxx:173
const TriggerWindow & getTrigger(unsigned int window) const
Definition Event.cxx:184
const Header & getHeader(unsigned int half) const
Definition Event.cxx:162
std::array< uint16_t, constants::PADLAYER_MODULE_NCHANNELS > getTOAs() const
Definition Event.cxx:200
const Channel & getChannel(unsigned int channel) const
Definition Event.cxx:168
void setCalib(unsigned int half, uint16_t adc, uint16_t toa, uint16_t tot)
Definition Event.cxx:142
std::array< uint16_t, constants::PADLAYER_MODULE_NCHANNELS > getTOTs() const
Definition Event.cxx:208
void setHeader(unsigned int half, uint8_t header, uint8_t bc, uint8_t wadd, uint8_t fourbits, uint8_t trialer)
Definition Event.cxx:113
const Channel & getCalib(unsigned int half) const
Definition Event.cxx:178
void setTrigger(unsigned int window, uint32_t header0, uint32_t header1, const gsl::span< uint8_t > triggers)
Definition Event.cxx:151
void setChannel(unsigned int channel, uint16_t adc, uint16_t toa, uint16_t tot)
Definition Event.cxx:124
void setCMN(unsigned int half, uint16_t adc, uint16_t toa, uint16_t tot)
Definition Event.cxx:133
void addChip(const PixelChip &chip)
Definition Event.cxx:262
struct _cl_event * event
Definition glcorearb.h:2982
GLuint index
Definition glcorearb.h:781
GLenum GLuint GLint GLint layer
Definition glcorearb.h:1310
constexpr int PADLAYER_MODULE_NCHANNELS
Definition Constants.h:16
constexpr int PADLAYER_MODULE_NHALVES
Definition Constants.h:17
constexpr int PIXELS_NLAYERS
Definition Constants.h:19
constexpr int PADLAYER_WINDOW_LENGTH
Definition Constants.h:20
constexpr int PADS_NLAYERS
Definition Constants.h:18
std::vector< PixelHit > mHits
Definition PixelChip.h:33
ArrayADC adc