Project
Loading...
Searching...
No Matches
UserLogicElinkDecoder.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
13
14namespace o2::mch::raw
15{
16
17template <>
18void UserLogicElinkDecoder<SampleMode>::prepareAndSendCluster()
19{
20 if (mDecodedDataHandlers.sampaChannelHandler) {
21 SampaCluster sc(mClusterTime, mSampaHeader.bunchCrossingCounter(), mSamples);
22 sendCluster(sc);
23 }
24 mSamples.clear();
25}
26
27template <>
28void UserLogicElinkDecoder<ChargeSumMode>::prepareAndSendCluster()
29{
30 if (mSamples.size() != 2) {
31 throw std::invalid_argument(fmt::format("expected sample size to be 2 but it is {}", mSamples.size()));
32 }
33 if (mDecodedDataHandlers.sampaChannelHandler) {
34 uint32_t q = (((static_cast<uint32_t>(mSamples[1]) & 0x3FF) << 10) | (static_cast<uint32_t>(mSamples[0]) & 0x3FF));
35 SampaCluster sc(mClusterTime, mSampaHeader.bunchCrossingCounter(), q, mClusterSize);
36 sendCluster(sc);
37 }
38 mSamples.clear();
39}
40
41template <>
42bool UserLogicElinkDecoder<SampleMode>::checkDataHeader()
43{
44 int chipAddMin = mDsId.elinkIndexInGroup() * 2;
45 int chipAddMax = chipAddMin + 1;
46
47 // the chip address from the SAMPA header must be consistent with
48 // the e-Link index
49 int chipAdd = mSampaHeader.chipAddress();
50 if (chipAdd < chipAddMin || chipAdd > chipAddMax) {
51 return false;
52 }
53
54 // we expect at least 3 10-bit words
55 int nof10BitWords = mSampaHeader.nof10BitWords();
56 if (nof10BitWords <= 2) {
57 return false;
58 }
59
60 return true;
61}
62
63template <>
64bool UserLogicElinkDecoder<ChargeSumMode>::checkDataHeader()
65{
66 int chipAddMin = mDsId.elinkIndexInGroup() * 2;
67 int chipAddMax = chipAddMin + 1;
68
69 // the chip address from the SAMPA header must be consistent with
70 // the e-Link index
71 int chipAdd = mSampaHeader.chipAddress();
72 if (chipAdd < chipAddMin || chipAdd > chipAddMax) {
73 return false;
74 }
75
76 // we expect at least 3 10-bit words
77 int nof10BitWords = mSampaHeader.nof10BitWords();
78 if (nof10BitWords <= 2) {
79 return false;
80 }
81 // in cluster sum mode the number of 10-bit words must be a multiple of 4
82 if ((nof10BitWords % 4) != 0) {
83 return false;
84 }
85
86 return true;
87}
88
89} // namespace o2::mch::raw