Belle II Software  release-05-01-25
TOPCalChannelMask.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2019 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Marko Staric *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <top/dbobjects/TOPCalChannelMask.h>
12 
13 #include <framework/logging/Logger.h>
14 
15 using namespace std;
16 
17 namespace Belle2 {
23  void TOPCalChannelMask::setStatus(int moduleID, unsigned channel, EStatus status)
24  {
25  int module = moduleID - 1;
26  if (!check(module, channel)) {
27  B2WARNING("Channel status not set");
28  return;
29  }
30  m_status[module][channel] = status;
31  }
32 
33  void TOPCalChannelMask::setActive(int moduleID, unsigned channel)
34  {
35  int module = moduleID - 1;
36  if (!check(module, channel)) {
37  B2WARNING("Channel status 'active' not set");
38  return;
39  }
40  m_status[module][channel] = c_Active;
41  }
42 
43  void TOPCalChannelMask::setDead(int moduleID, unsigned channel)
44  {
45  int module = moduleID - 1;
46  if (!check(module, channel)) {
47  B2WARNING("Channel status 'dead' not set");
48  return;
49  }
50  m_status[module][channel] = c_Dead;
51  }
52 
53  void TOPCalChannelMask::setNoisy(int moduleID, unsigned channel)
54  {
55  int module = moduleID - 1;
56  if (!check(module, channel)) {
57  B2WARNING("Channel status 'noisy' not set");
58  return;
59  }
60  m_status[module][channel] = c_Noisy;
61  }
62 
63  TOPCalChannelMask::EStatus TOPCalChannelMask::getStatus(int moduleID,
64  unsigned channel) const
65  {
66  int module = moduleID - 1;
67  if (!check(module, channel)) {
68  B2WARNING("Returning dead channel value");
69  return c_Dead;
70  }
71  return m_status[module][channel];
72  }
73 
74  bool TOPCalChannelMask::isActive(int moduleID, unsigned channel) const
75  {
76  int module = moduleID - 1;
77  if (!check(module, channel)) {
78  B2WARNING("Returning false");
79  return false;
80  }
81  return (m_status[module][channel] == c_Active);
82  }
83 
84  bool TOPCalChannelMask::check(const int module, const unsigned channel) const
85  {
86  if (module >= c_numModules) {
87  B2ERROR("Invalid module number (" << ClassName() << ")");
88  return false;
89  }
90  if (module < 0) {
91  B2ERROR("Invalid module number (" << ClassName() << ")");
92  return false;
93  }
94  if (channel >= c_numChannels) {
95  B2ERROR("Invalid channel number (" << ClassName() << ")");
96  return false;
97  }
98  return true;
99  }
100 
101  int TOPCalChannelMask::getNumOf(EStatus check) const
102  {
103  int n = 0;
104  for (const auto& statuses : m_status) {
105  for (const auto status : statuses) {
106  if (status == check) n++;
107  }
108  }
109  return n;
110  }
111 
112  int TOPCalChannelMask::getNumOf(EStatus check, int moduleID) const
113  {
114  unsigned module = moduleID - 1;
115  if (module < c_numModules) {
116  int n = 0;
117  const auto& statuses = m_status[module];
118  for (const auto status : statuses) {
119  if (status == check) n++;
120  }
121  return n;
122  }
123  B2ERROR("Invalid module number (" << ClassName() << ")");
124  return 0;
125  }
126 
128 } // end Belle2 namespace
Belle2::TOPCalChannelMask::EStatus
EStatus
Status of the channel.
Definition: TOPCalChannelMask.h:45
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19