Belle II Software  release-08-01-10
ARICHModulesInfo.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 <framework/logging/Logger.h>
10 
11 #include <arich/dbobjects/ARICHModulesInfo.h>
12 #include <iostream>
13 #include<iomanip>
14 
15 using namespace std;
16 using namespace Belle2;
17 
18 ARICHModulesInfo::ARICHModulesInfo()
19 {
20  m_ChannelQE.assign(N_HAPDS * N_CHANNELS, 0);
21  std::fill_n(m_installed, N_HAPDS, false);
22  std::fill_n(m_active, N_HAPDS, false);
23 }
24 
25 double ARICHModulesInfo::getChannelQE(unsigned moduleID, unsigned channelID) const
26 {
27  if (moduleID > N_HAPDS
28  || channelID > N_CHANNELS - 1) B2ERROR("ARICHModulesInfo::getChannelQE: module ID or channel ID out of range");
29 
30  int id = (moduleID - 1) * N_CHANNELS + channelID;
31  return (double)m_ChannelQE[id] / 100.0;
32 }
33 
34 void ARICHModulesInfo::setChannelQE(unsigned modId, unsigned chId, double qe)
35 {
36  if (modId > N_HAPDS || chId > N_CHANNELS - 1) B2ERROR("ARICHModulesInfo::setChannelQE: module ID or channel ID out of range");
37 
38  int chid = (modId - 1) * N_CHANNELS + chId;
39  m_ChannelQE[chid] = uint8_t(qe * 100 + 0.5);
40 }
41 
42 void ARICHModulesInfo::addModule(unsigned modId, std::vector<float>& qeList, bool active)
43 {
44 
45  if (modId > N_HAPDS) B2ERROR("ARICHModulesInfo::addModule: module ID is out of range");
46  if (qeList.size() != N_CHANNELS) B2ERROR("ARICHModulesInfo::addModule: incomplete list of channels QEs");
47 
48  m_installed[modId - 1] = true;
49  m_active[modId - 1] = active;
50 
51  std::vector<uint8_t>::iterator it = m_ChannelQE.begin() + (modId - 1) * N_CHANNELS;
52  for (auto qe : qeList) {
53  *it = uint8_t(qe + 0.5);
54  ++it;
55  }
56 }
57 
58 bool ARICHModulesInfo::isInstalled(unsigned modId) const
59 {
60  if (modId > N_HAPDS) B2ERROR("ARICHModulesInfo::isInstalled: module ID is out of range");
61 
62  return m_installed[modId - 1];
63 }
64 
65 bool ARICHModulesInfo::isActive(unsigned modId) const
66 {
67  if (modId > N_HAPDS) B2ERROR("ARICHModulesInfo::isActive: module ID is out of range");
68 
69  return m_active[modId - 1];
70 }
71 
72 void ARICHModulesInfo::print() const
73 {
74  cout << "ARICHModulesInfo: " << endl;
75  cout << " Modules status " << endl;
76  cout << " ID / installed / active / avg. QE" << endl;
77  double maxQE = 0;
78  for (int i = 1; i < N_HAPDS + 1; i++) {
79  cout << right << setfill(' ') << setw(4) << i << ": ";
80  if (isInstalled(i)) cout << 1;
81  else cout << 0;
82  cout << " ";
83  if (isActive(i)) cout << 1;
84  else cout << 0;
85  double avgQE = 0;
86  for (int j = 0; j < N_CHANNELS; j++) {
87  double chQE = getChannelQE(i, j);
88  avgQE += chQE;
89  if (chQE > maxQE) maxQE = chQE;
90  }
91  avgQE /= double(N_CHANNELS);
92  cout << " " << left << setfill('0') << setw(4) << setprecision(2) << avgQE << " ";
93  if ((i) % 10 == 0) cout << endl;
94  }
95  cout << " Maximal channel QE: " << maxQE << endl;
96 }
Abstract base class for different kinds of events.