Project
Loading...
Searching...
No Matches
StatusMap.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 "MCHStatus/StatusMap.h"
13
14#include <stdexcept>
15
16#include "Framework/Logger.h"
19
20#include <fmt/format.h>
21
23
24namespace o2::mch
25{
26
27void assertValidMask(uint32_t mask)
28{
29 static constexpr uint32_t maxMask = StatusMap::kBadPedestal | StatusMap::kRejectList | StatusMap::kBadHV;
30 if (mask > maxMask) {
31 throw std::runtime_error(fmt::format("invalid mask {} (max allowed is {}",
32 mask, maxMask));
33 }
34}
35
36void StatusMap::add(gsl::span<const DsChannelId> badchannels, uint32_t mask)
37{
39 for (auto id : badchannels) {
40 try {
41 ChannelCode cc(id.getSolarId(), id.getElinkId(), id.getChannel());
42 mStatus[cc] |= mask;
43 } catch (const std::exception& e) {
44 LOGP(warning, "Error processing channel - SolarId: {} ElinkId: {} Channel: {}. Error: {}. This channel is skipped.",
45 id.getSolarId(), id.getElinkId(), id.getChannel(), e.what());
46 }
47 }
48}
49
50void StatusMap::add(gsl::span<const ChannelCode> badchannels, uint32_t mask)
51{
53 for (auto id : badchannels) {
54 mStatus[id] |= mask;
55 }
56}
57
58void StatusMap::addDS(DsIndex badDS, uint32_t mask)
59{
60 if (badDS >= NumberOfDualSampas) {
61 LOGP(warning, "Error processing Dual Sampa - index: {}. This DS is skipped.", badDS);
62 return;
63 }
64 addDS(getDsDetId(badDS), mask);
65}
66
67void StatusMap::addDS(raw::DsDetId badDS, uint32_t mask)
68{
70 auto deId = badDS.deId();
71 if (!constants::isValidDetElemId(deId)) {
72 LOGP(warning, "Error processing Dual Sampa - {}. This DS is skipped.", raw::asString(badDS));
73 return;
74 }
75 const auto& seg = mapping::segmentation(deId);
76 seg.forEachPadInDualSampa(badDS.dsId(), [&](int dePadIndex) {
77 try {
78 ChannelCode cc(deId, dePadIndex);
79 mStatus[cc] |= mask;
80 } catch (const std::exception& e) {
81 LOGP(warning, "Error processing channel - {} padIndex: {}. Error: {}. This channel is skipped.",
82 raw::asString(badDS), dePadIndex, e.what());
83 }
84 });
85}
86
87void StatusMap::addDE(uint16_t badDE, uint32_t mask)
88{
90 if (!constants::isValidDetElemId(badDE)) {
91 LOGP(warning, "Error processing DE - Id: {}. This DE is skipped.", badDE);
92 return;
93 }
94 const auto& seg = mapping::segmentation(badDE);
95 seg.forEachPad([&](int dePadIndex) {
96 try {
97 ChannelCode cc(badDE, dePadIndex);
98 mStatus[cc] |= mask;
99 } catch (const std::exception& e) {
100 LOGP(warning, "Error processing channel - deId: {} padIndex: {}. Error: {}. This channel is skipped.",
101 badDE, dePadIndex, e.what());
102 }
103 });
104}
105
106uint32_t StatusMap::status(const ChannelCode& id) const
107{
108 auto s = mStatus.find(id);
109 if (s != mStatus.end()) {
110 return s->second;
111 }
112 return 0;
113}
114
115std::map<int, std::vector<int>> applyMask(const o2::mch::StatusMap& statusMap,
116 uint32_t mask)
117{
118 std::map<int, std::vector<int>> rejectList;
119
120 if (mask == 0) {
121 return rejectList;
122 }
123
124 for (const auto& status : statusMap) {
125 auto channel = status.first;
126 if (!channel.isValid()) {
127 continue;
128 }
129 if ((mask & status.second) != 0) {
130 rejectList[channel.getDeId()].emplace_back(channel.getDePadIndex());
131 }
132 }
133 return rejectList;
134}
135
136} // namespace o2::mch
o2::mch::mapping::CathodeSegmentation seg
ClassImp(o2::mch::StatusMap)
void add(gsl::span< const DsChannelId > badchannels, uint32_t mask)
Definition StatusMap.cxx:36
void addDS(DsIndex badDS, uint32_t mask)
Definition StatusMap.cxx:58
void forEachPadInDualSampa(int dualSampaId, CALLABLE &&func) const
A DsDetId is just a pair (detection element id, dual sampa id)
Definition DsDetId.h:22
uint16_t deId() const
deId returns one of the 156 possible detection element id
Definition DsDetId.h:27
uint16_t dsId() const
Definition DsDetId.h:31
GLint GLuint mask
Definition glcorearb.h:291
GLuint id
Definition glcorearb.h:650
bool isValidDetElemId(int deId)
O2MCHMAPPINGIMPL3_EXPORT const Segmentation & segmentation(int detElemId)
std::string asString(const SampaCluster &sc)
std::map< int, std::vector< int > > applyMask(const o2::mch::StatusMap &statusMap, uint32_t mask)
uint16_t DsIndex
Definition DsIndex.h:26
void assertValidMask(uint32_t mask)
Definition StatusMap.cxx:27
constexpr uint16_t NumberOfDualSampas
Definition DsIndex.h:28
o2::mch::raw::DsDetId getDsDetId(DsIndex dsIndex)
Definition DsIndex.cxx:90
std::vector< o2::mch::ChannelCode > cc