Project
Loading...
Searching...
No Matches
DsIndex.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
14#include <map>
15#include <stdexcept>
16#include <vector>
17
18#include "Framework/Logger.h"
20
21namespace o2::mch
22{
23
24template <typename KEY, typename VALUE>
25std::map<VALUE, KEY> inverseMap(const std::map<KEY, VALUE>& src)
26{
27 std::map<VALUE, KEY> dest;
28 for (auto p : src) {
29 dest.emplace(p.second, p.first);
30 }
31 return dest;
32}
33
35{
36 static std::vector<uint8_t> channelsPerDS;
37 if (channelsPerDS.empty()) {
38 for (uint16_t dsIndex = 0; dsIndex < o2::mch::NumberOfDualSampas; ++dsIndex) {
40 uint8_t nch{0};
41 auto dsId = det.dsId();
42 auto deId = det.deId();
43 const auto& seg = o2::mch::mapping::segmentation(deId);
44 seg.forEachPadInDualSampa(dsId, [&nch](int /*dePadIndex*/) { ++nch; });
45 channelsPerDS.emplace_back(nch);
46 }
47 }
48 if (dsIndex < o2::mch::NumberOfDualSampas) {
49 return channelsPerDS[dsIndex];
50 } else {
51 LOGP(error, "invalid Dual Sampa index: {}", dsIndex);
52 }
53 return 0;
54}
55
56std::map<uint32_t, uint16_t> buildDetId2DsIndexMap()
57{
58 static std::map<uint32_t, uint16_t> m;
59 if (m.empty()) {
60 uint16_t dsIndex{0};
62 const auto& seg = o2::mch::mapping::segmentation(deId);
63 std::vector<int> dsids;
64 seg.forEachDualSampa([&](int dsid) {
65 dsids.emplace_back(dsid);
66 });
67 // ensure dual sampa are sorted by dsid
68 std::sort(dsids.begin(), dsids.end());
69 for (auto dsId : dsids) {
70 raw::DsDetId det{deId, dsId};
71 m.emplace(encode(det), dsIndex);
72 ++dsIndex;
73 }
74 });
75 }
76 return m;
77}
78
80{
81 static std::map<uint32_t, uint16_t> m = buildDetId2DsIndexMap();
82 try {
83 return m.at(encode(dsDetId));
84 } catch (const std::exception&) {
85 LOGP(error, "invalid Dual Sampa Id: {}", raw::asString(dsDetId));
86 }
87 return NumberOfDualSampas;
88}
89
91{
92 static std::map<uint16_t, uint32_t> m = inverseMap(buildDetId2DsIndexMap());
93 try {
94 return raw::decodeDsDetId(m.at(dsIndex));
95 } catch (const std::exception&) {
96 LOGP(error, "invalid Dual Sampa index: {}", dsIndex);
97 }
98 return raw::DsDetId(0, 0);
99}
100
101} // namespace o2::mch
o2::mch::mapping::CathodeSegmentation seg
void forEachPadInDualSampa(int dualSampaId, CALLABLE &&func) const
void forEachDualSampa(std::function< void(int dualSampaId)> func) const
Loop over dual sampas of this detection element.
A DsDetId is just a pair (detection element id, dual sampa id)
Definition DsDetId.h:22
const GLfloat * m
Definition glcorearb.h:4066
GLenum src
Definition glcorearb.h:1767
O2MCHMAPPINGIMPL3_EXPORT const Segmentation & segmentation(int detElemId)
void forEachDetectionElement(CALLABLE &&func)
std::string asString(const SampaCluster &sc)
DsDetId decodeDsDetId(uint32_t code)
Create a DsDetId object from a integer code.
Definition DsDetId.cxx:33
uint64_t encode(uint32_t a, uint32_t b)
Definition ErrorMap.cxx:19
std::map< uint32_t, uint16_t > buildDetId2DsIndexMap()
Definition DsIndex.cxx:56
DsIndex getDsIndex(const o2::mch::raw::DsDetId &dsDetId)
Definition DsIndex.cxx:79
uint16_t DsIndex
Definition DsIndex.h:26
uint8_t numberOfDualSampaChannels(DsIndex dsIndex)
Definition DsIndex.cxx:34
constexpr uint16_t NumberOfDualSampas
Definition DsIndex.h:28
std::map< VALUE, KEY > inverseMap(const std::map< KEY, VALUE > &src)
Definition DsIndex.cxx:25
o2::mch::raw::DsDetId getDsDetId(DsIndex dsIndex)
Definition DsIndex.cxx:90