Belle II Software  release-05-02-19
KLMChannelMapValue.h
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 #pragma once
12 
13 /* KLM headers. */
14 #include <klm/dataobjects/KLMChannelIndex.h>
15 
16 /* Belle 2 headers. */
17 #include <framework/logging/Logger.h>
18 
19 /* ROOT headers. */
20 #include <TNamed.h>
21 
22 /* C++ headers. */
23 #include <cstdint>
24 #include <map>
25 
26 namespace Belle2 {
35  template<class T> class KLMChannelMapValue : public TNamed {
36 
37  public:
38 
43  {
44  }
45 
50  {
51  }
52 
57  const T getChannelData(uint16_t channel) const
58  {
59  typename std::map<uint16_t, T>::const_iterator it;
60  it = m_ChannelData.find(channel);
61  if (it == m_ChannelData.end()) {
62  B2ERROR("No data for KLM channel in map." <<
63  LogVar("Channel number", channel));
64  }
65  return it->second;
66  }
67 
73  void setChannelData(uint16_t channel, const T data)
74  {
75  typename std::map<uint16_t, T>::iterator it;
76  it = m_ChannelData.find(channel);
77  if (it == m_ChannelData.end()) {
78  m_ChannelData.insert(std::pair<uint16_t, T>(channel, data));
79  } else {
80  it->second = data;
81  }
82  }
83 
88  void setDataAllChannels(const T data)
89  {
90  KLMChannelIndex klmChannels;
91  for (KLMChannelIndex& klmChannel : klmChannels)
92  setChannelData(klmChannel.getKLMChannelNumber(), data);
93  }
94 
95  private:
96 
98  std::map<uint16_t, T> m_ChannelData;
99 
102 
103  };
104 
106 }
Belle2::KLMChannelMapValue::KLMChannelMapValue
KLMChannelMapValue()
Constructor.
Definition: KLMChannelMapValue.h:50
Belle2::KLMChannelMapValue::~KLMChannelMapValue
~KLMChannelMapValue()
Destructor.
Definition: KLMChannelMapValue.h:57
Belle2::KLMChannelMapValue
KLM channel map.
Definition: KLMChannelMapValue.h:43
Belle2::KLMChannelMapValue::m_ChannelData
std::map< uint16_t, T > m_ChannelData
Channel data.
Definition: KLMChannelMapValue.h:106
Belle2::KLMChannelMapValue::ClassDef
ClassDef(Belle2::KLMChannelMapValue< T >, 1)
Class version.
Belle2::KLMChannelMapValue::setChannelData
void setChannelData(uint16_t channel, const T data)
Set channel data.
Definition: KLMChannelMapValue.h:81
Belle2::KLMChannelMapValue::setDataAllChannels
void setDataAllChannels(const T data)
Set data for all channels.
Definition: KLMChannelMapValue.h:96
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
LogVar
Class to store variables with their name which were sent to the logging service.
Definition: LogVariableStream.h:24
Belle2::KLMChannelMapValue::getChannelData
const T getChannelData(uint16_t channel) const
Get channel data.
Definition: KLMChannelMapValue.h:65