Belle II Software development
TOPCalChannelMask.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include <top/dbobjects/TOPCalChannelMask.h>
10
11#include <framework/logging/Logger.h>
12
13using namespace std;
14
15namespace Belle2 {
21 void TOPCalChannelMask::setStatus(int moduleID, unsigned channel, EStatus status)
22 {
23 int module = moduleID - 1;
24 if (!check(module, channel)) {
25 B2WARNING("Channel status not set");
26 return;
27 }
28 m_status[module][channel] = status;
29 }
30
31 void TOPCalChannelMask::setActive(int moduleID, unsigned channel)
32 {
33 int module = moduleID - 1;
34 if (!check(module, channel)) {
35 B2WARNING("Channel status 'active' not set");
36 return;
37 }
38 m_status[module][channel] = c_Active;
39 }
40
41 void TOPCalChannelMask::setDead(int moduleID, unsigned channel)
42 {
43 int module = moduleID - 1;
44 if (!check(module, channel)) {
45 B2WARNING("Channel status 'dead' not set");
46 return;
47 }
48 m_status[module][channel] = c_Dead;
49 }
50
51 void TOPCalChannelMask::setNoisy(int moduleID, unsigned channel)
52 {
53 int module = moduleID - 1;
54 if (!check(module, channel)) {
55 B2WARNING("Channel status 'noisy' not set");
56 return;
57 }
58 m_status[module][channel] = c_Noisy;
59 }
60
62 unsigned channel) const
63 {
64 int module = moduleID - 1;
65 if (!check(module, channel)) {
66 B2WARNING("Returning dead channel value");
67 return c_Dead;
68 }
69 return m_status[module][channel];
70 }
71
72 bool TOPCalChannelMask::isActive(int moduleID, unsigned channel) const
73 {
74 int module = moduleID - 1;
75 if (!check(module, channel)) {
76 B2WARNING("Returning false");
77 return false;
78 }
79 return (m_status[module][channel] == c_Active);
80 }
81
82 bool TOPCalChannelMask::check(const int module, const unsigned channel) const
83 {
84 if (module >= c_numModules) {
85 B2ERROR("Invalid module number (" << ClassName() << ")");
86 return false;
87 }
88 if (module < 0) {
89 B2ERROR("Invalid module number (" << ClassName() << ")");
90 return false;
91 }
92 if (channel >= c_numChannels) {
93 B2ERROR("Invalid channel number (" << ClassName() << ")");
94 return false;
95 }
96 return true;
97 }
98
100 {
101 int n = 0;
102 for (const auto& statuses : m_status) {
103 for (const auto status : statuses) {
104 if (status == check) n++;
105 }
106 }
107 return n;
108 }
109
110 int TOPCalChannelMask::getNumOf(EStatus check, int moduleID) const
111 {
112 unsigned module = moduleID - 1;
113 if (module < c_numModules) {
114 int n = 0;
115 const auto& statuses = m_status[module];
116 for (const auto status : statuses) {
117 if (status == check) n++;
118 }
119 return n;
120 }
121 B2ERROR("Invalid module number (" << ClassName() << ")");
122 return 0;
123 }
124
126} // end Belle2 namespace
EStatus m_status[c_numModules][c_numChannels]
channel status
@ c_numChannels
number of channels per module
@ c_numModules
number of modules
EStatus
Status of the channel.
void setActive(int moduleID, unsigned channel)
Sets a specific channel as active.
int getNumOf(EStatus check) const
Counts and returns the number of channels having a given status.
void setNoisy(int moduleID, unsigned channel)
Sets a specific channel as noisy.
void setDead(int moduleID, unsigned channel)
Sets a specific channel as dead.
void setStatus(int moduleID, unsigned channel, EStatus status)
Sets the status for a single channel.
bool isActive(int moduleID, unsigned channel) const
Returns false if the channel is dead or noisy, and true is the channel is active.
EStatus getStatus(int moduleID, unsigned channel) const
Returns the status of a single channel.
bool check(const int module, const unsigned channel) const
Check input module and channel arguments are sane.
Abstract base class for different kinds of events.
STL namespace.