Project
Loading...
Searching...
No Matches
ChannelCode.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
18#include <fmt/format.h>
19
20namespace o2::mch
21{
22ChannelCode::ChannelCode(uint16_t deId, uint16_t dePadIndex)
23{
24 auto deIndexOpt = constants::deId2DeIndex(deId);
25 if (deIndexOpt == std::nullopt) {
26 throw std::runtime_error(fmt::format("invalid deId {}", deId));
27 }
28 auto deIndex = deIndexOpt.value();
29 const auto& seg = o2::mch::mapping::segmentation(deId);
30 if (!seg.isValid(dePadIndex)) {
31 throw std::runtime_error(fmt::format("invalid dePadIndex {} for deId {}",
32 dePadIndex, deId));
33 }
34 auto dsId = seg.padDualSampaId(dePadIndex);
35 o2::mch::raw::DsDetId dsDetId(deId, dsId);
36 auto dsIndex = o2::mch::getDsIndex(dsDetId);
37 uint8_t channel = seg.padDualSampaChannel(dePadIndex);
38
39 static auto det2elec = raw::createDet2ElecMapper<raw::ElectronicMapperGenerated>();
40
41 auto elec = det2elec(dsDetId);
42 if (elec == std::nullopt) {
43 throw std::runtime_error(fmt::format("could not get solar,elink for {}",
44 raw::asString(dsDetId)));
45 }
46 uint16_t solarId = elec->solarId();
47 auto solarIndex = raw::solarId2Index<raw::ElectronicMapperGenerated>(solarId);
48 if (solarIndex == std::nullopt) {
49 throw std::runtime_error(fmt::format("could not get index from solarId {}",
50 solarId));
51 }
52 uint8_t elinkIndex = elec->elinkId();
53 set(deIndex, dePadIndex, dsIndex, solarIndex.value(), elinkIndex, channel);
54}
55
56ChannelCode::ChannelCode(uint16_t solarId, uint8_t elinkId, uint8_t channel)
57{
58 auto solarIndexOpt = raw::solarId2Index<raw::ElectronicMapperGenerated>(solarId);
59 if (solarIndexOpt == std::nullopt) {
60 throw std::runtime_error(fmt::format("invalid solarId {}", solarId));
61 }
62 static auto elec2det = raw::createElec2DetMapper<raw::ElectronicMapperGenerated>();
63 auto group = raw::groupFromElinkId(elinkId);
64 auto index = raw::indexFromElinkId(elinkId);
65 raw::DsElecId dsElecId{solarId, group.value(), index.value()};
66 auto dsDetIdOpt = elec2det(dsElecId);
67 if (dsDetIdOpt == std::nullopt) {
68 throw std::runtime_error(fmt::format("invalid solarid {} elinkid {}",
69 solarId, elinkId));
70 }
71 auto deId = dsDetIdOpt->deId();
72 auto deIndexOpt = constants::deId2DeIndex(deId);
73 if (deIndexOpt == std::nullopt) {
74 throw std::runtime_error(fmt::format("invalid deId {}", deId));
75 }
76 const auto& seg = o2::mch::mapping::segmentation(deId);
77 auto dsId = dsDetIdOpt->dsId();
78 int dePadIndex = seg.findPadByFEE(dsId, channel);
79 if (!seg.isValid(dePadIndex)) {
80 throw std::runtime_error(fmt::format("invalid dePadIndex {} for deId {}",
81 dePadIndex, deId));
82 }
83 auto dsIndex = o2::mch::getDsIndex(dsDetIdOpt.value());
84 auto solarIndex = solarIndexOpt.value();
85 set(deIndexOpt.value(), dePadIndex, dsIndex, solarIndex, elinkId, channel);
86}
87
97void ChannelCode::set(uint8_t deIndex,
98 uint16_t dePadIndex,
99 uint16_t dsIndex,
100 uint16_t solarIndex,
101 uint8_t elinkIndex,
102 uint8_t channel)
103{
104 mValue = (static_cast<uint64_t>(deIndex & 0xFF) << 52) +
105 (static_cast<uint64_t>(dePadIndex & 0x7FFF) << 37) +
106 (static_cast<uint64_t>(dsIndex & 0x7FFF) << 22) +
107 (static_cast<uint64_t>(solarIndex & 0x3FF) << 12) +
108 (static_cast<uint64_t>(elinkIndex & 0x3F) << 6) +
109 (static_cast<uint64_t>(channel & 0x3F));
110}
111
113{
114 return static_cast<uint8_t>((mValue >> 52) & 0xFF);
115}
116
118{
119 return static_cast<uint16_t>((mValue >> 37) & 0x7FFF);
120}
121
123{
124 return static_cast<uint16_t>((mValue >> 22) & 0x7FFF);
125}
126
128{
129 return static_cast<uint16_t>((mValue >> 12) & 0x3FF);
130}
131
133{
134 return static_cast<uint8_t>((mValue >> 6) & 0x3F);
135}
136
138{
139 return static_cast<uint8_t>(mValue & 0x3F);
140}
141
142uint16_t ChannelCode::getDeId() const
143{
144 auto deIndex = getDeIndex();
146}
147
148uint16_t ChannelCode::getDsId() const
149{
150 auto dsIndex = getDsIndex();
151 o2::mch::raw::DsDetId dsDetId = getDsDetId(dsIndex);
152 return dsDetId.dsId();
153}
154
156{
157 auto solarIndex = getSolarIndex();
158 return raw::solarIndex2Id<raw::ElectronicMapperGenerated>(solarIndex).value();
159}
160
161std::string asString(const ChannelCode& cc)
162{
163 return fmt::format("deid {:4d} dsid {:4d} ch {:2d} depadindex {:5d} solarid {:4d} elink {:2d}",
164 cc.getDeId(),
165 cc.getDsId(),
166 cc.getChannel(),
167 cc.getDePadIndex(),
168 cc.getSolarId(),
169 cc.getElinkId());
170}
171} // namespace o2::mch
o2::mch::mapping::CathodeSegmentation seg
uint16_t getDsIndex() const
uint8_t getDeIndex() const
uint16_t getSolarId() const
uint16_t getDeId() const
uint16_t getSolarIndex() const
uint16_t getDsId() const
uint8_t getElinkId() const
uint8_t getChannel() const
uint16_t getDePadIndex() const
int padDualSampaChannel(int catPadIndex) const
int padDualSampaId(int catPadIndex) const
int findPadByFEE(int dualSampaId, int dualSampaChannel) const
bool isValid(int catPadIndex) const
Not every integer is a valid catPadIndex. This method will tell if catPadIndex is a valid one.
A DsDetId is just a pair (detection element id, dual sampa id)
Definition DsDetId.h:22
uint16_t dsId() const
Definition DsDetId.h:31
GLuint index
Definition glcorearb.h:781
GLboolean GLuint group
Definition glcorearb.h:3991
std::array< int, 156 > deIdsForAllMCH
std::optional< int > deId2DeIndex(int deId)
O2MCHMAPPINGIMPL3_EXPORT const Segmentation & segmentation(int detElemId)
std::optional< uint8_t > indexFromElinkId(uint8_t elinkId)
Extracts the index from the elinkId.
Definition DsElecId.cxx:132
std::optional< uint8_t > groupFromElinkId(uint8_t elinkId)
Extracts the group from the elinkId.
Definition DsElecId.cxx:124
std::string asString(const SampaCluster &sc)
std::string asString(const o2::mch::TrackMCH &t)
Definition TrackMCH.cxx:104
DsIndex getDsIndex(const o2::mch::raw::DsDetId &dsDetId)
Definition DsIndex.cxx:79
o2::mch::raw::DsDetId getDsDetId(DsIndex dsIndex)
Definition DsIndex.cxx:90
std::vector< o2::mch::ChannelCode > cc