Belle II Software  release-05-02-19
KLMChannelStatus.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2019 Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Kirill Chilikin *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 /* Own header. */
12 #include <klm/dbobjects/KLMChannelStatus.h>
13 
14 /* KLM headers. */
15 #include <klm/dataobjects/KLMChannelIndex.h>
16 #include <klm/dataobjects/KLMElementNumbers.h>
17 
18 /* Belle 2 headers. */
19 #include <framework/logging/Logger.h>
20 
21 using namespace Belle2;
22 
24 {
25 }
26 
28 {
29 }
30 
32 KLMChannelStatus::getChannelStatus(uint16_t channel) const {
33  std::map<uint16_t, enum ChannelStatus>::const_iterator it;
34  it = m_ChannelStatus.find(channel);
35  if (it == m_ChannelStatus.end())
36  return c_Unknown;
37  return it->second;
38 }
39 
40 void KLMChannelStatus::setChannelStatus(uint16_t channel,
41  enum ChannelStatus status)
42 {
43  std::map<uint16_t, enum ChannelStatus>::iterator it;
44  it = m_ChannelStatus.find(channel);
45  if (it == m_ChannelStatus.end()) {
46  m_ChannelStatus.insert(
47  std::pair<uint16_t, enum ChannelStatus>(channel, status));
48  } else {
49  it->second = status;
50  }
51 }
52 
54 {
55  KLMChannelIndex klmChannels;
56  for (KLMChannelIndex& klmChannel : klmChannels)
57  setChannelStatus(klmChannel.getKLMChannelNumber(), status);
58 }
59 
61 {
62  int active;
63  int subdetector, section, sector, layer;
64  const KLMElementNumbers* elementNumbers =
66  elementNumbers->moduleNumberToElementNumbers(
67  module, &subdetector, &section, &sector, &layer);
68  KLMChannelIndex klmModule(subdetector, section, sector, layer, 1, 1);
69  /* Plane number is 0-based for BKLM. */
70  if (subdetector == KLMElementNumbers::c_BKLM) {
71  KLMChannelIndex klmModuleTemp(subdetector, section, sector, layer, 0, 1);
72  klmModule = klmModuleTemp;
73  }
75  KLMChannelIndex klmNextModule(klmModule);
76  ++klmNextModule;
77  KLMChannelIndex klmChannel(klmModule);
79  active = 0;
80  for (; klmChannel != klmNextModule; ++klmChannel) {
81  uint16_t channel = klmChannel.getKLMChannelNumber();
82  ChannelStatus status = getChannelStatus(channel);
83  if (status == c_Unknown)
84  B2FATAL("Incomplete KLM channel data.");
85  if (status != c_Dead)
86  active++;
87  }
88  return active;
89 }
90 
92 {
93  if (this->m_ChannelStatus.size() != status.m_ChannelStatus.size())
94  return false;
95  std::map<uint16_t, enum ChannelStatus>::iterator it, it2;
96  it = this->m_ChannelStatus.begin();
97  it2 = status.m_ChannelStatus.begin();
98  while (it != this->m_ChannelStatus.end()) {
99  if (it->first != it2->first)
100  return false;
101  if (it->second != it2->second)
102  return false;
103  ++it;
104  ++it2;
105  }
106  return true;
107 }
108 
110 {
111  unsigned int channels = 0;
112  if (this->m_ChannelStatus.size() != status.m_ChannelStatus.size())
113  return 0;
114  std::map<uint16_t, enum ChannelStatus>::iterator it, it2;
115  it = this->m_ChannelStatus.begin();
116  it2 = status.m_ChannelStatus.begin();
117  while (it != this->m_ChannelStatus.end()) {
118  if (it->first != it2->first)
119  return 0;
120  if ((it->second == c_Normal) && (it2->second != c_Normal))
121  ++channels;
122  ++it;
123  ++it2;
124  }
125  return channels;
126 }
Belle2::KLMChannelStatus
KLM channel status.
Definition: KLMChannelStatus.h:37
Belle2::KLMChannelIndex::c_IndexLevelLayer
@ c_IndexLevelLayer
Layer.
Definition: KLMChannelIndex.h:52
Belle2::KLMChannelStatus::newNormalChannels
unsigned int newNormalChannels(KLMChannelStatus &status)
Number of new channels with status c_Normal that have a different status in another channel-status da...
Definition: KLMChannelStatus.cc:109
Belle2::KLMChannelStatus::ChannelStatus
ChannelStatus
Channel status.
Definition: KLMChannelStatus.h:44
Belle2::KLMElementNumbers::Instance
static const KLMElementNumbers & Instance()
Instantiation.
Definition: KLMElementNumbers.cc:31
Belle2::KLMElementNumbers::moduleNumberToElementNumbers
void moduleNumberToElementNumbers(uint16_t module, int *subdetector, int *section, int *sector, int *layer) const
Get element numbers by module number.
Definition: KLMElementNumbers.cc:186
Belle2::KLMChannelIndex::getKLMChannelNumber
uint16_t getKLMChannelNumber() const
Get KLM channel number.
Definition: KLMChannelIndex.cc:145
Belle2::KLMChannelStatus::operator==
bool operator==(KLMChannelStatus &status)
Operator ==.
Definition: KLMChannelStatus.cc:91
Belle2::KLMChannelStatus::c_Dead
@ c_Dead
Dead channel (no signal).
Definition: KLMChannelStatus.h:53
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::KLMChannelStatus::KLMChannelStatus
KLMChannelStatus()
Constructor.
Definition: KLMChannelStatus.cc:23
Belle2::KLMChannelStatus::setChannelStatus
void setChannelStatus(uint16_t channel, enum ChannelStatus status)
Set channel status.
Definition: KLMChannelStatus.cc:40
Belle2::KLMElementNumbers::c_BKLM
@ c_BKLM
BKLM.
Definition: KLMElementNumbers.h:47
Belle2::KLMChannelStatus::m_ChannelStatus
std::map< uint16_t, enum ChannelStatus > m_ChannelStatus
Channel data.
Definition: KLMChannelStatus.h:112
Belle2::KLMChannelStatus::c_Unknown
@ c_Unknown
Unknown status (no data).
Definition: KLMChannelStatus.h:47
Belle2::KLMChannelIndex
KLM channel index.
Definition: KLMChannelIndex.h:33
Belle2::KLMChannelStatus::getActiveStripsInModule
int getActiveStripsInModule(uint16_t module) const
Get number of active strips in the specified KLM module.
Definition: KLMChannelStatus.cc:60
Belle2::KLMChannelStatus::setStatusAllChannels
void setStatusAllChannels(enum ChannelStatus status)
Set staus for all channels.
Definition: KLMChannelStatus.cc:53
Belle2::KLMElementNumbers
KLM element numbers.
Definition: KLMElementNumbers.h:37
Belle2::KLMChannelStatus::~KLMChannelStatus
~KLMChannelStatus()
Destructor.
Definition: KLMChannelStatus.cc:27
Belle2::KLMChannelStatus::c_Normal
@ c_Normal
Normally operating channel.
Definition: KLMChannelStatus.h:50
Belle2::KLMChannelIndex::setIndexLevel
void setIndexLevel(enum IndexLevel indexLevel)
Set index level.
Definition: KLMChannelIndex.cc:67
Belle2::KLMChannelStatus::getChannelStatus
enum ChannelStatus getChannelStatus(uint16_t channel) const
Get channel status.
Definition: KLMChannelStatus.cc:32
Belle2::KLMChannelIndex::c_IndexLevelStrip
@ c_IndexLevelStrip
Strip.
Definition: KLMChannelIndex.h:58