Belle II Software  release-08-01-10
ARICHChannelMapping.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/ARICHChannelMapping.h>
12 #include <iostream>
13 #include<iomanip>
14 
15 using namespace std;
16 using namespace Belle2;
17 
18 ARICHChannelMapping::ARICHChannelMapping()
19 {
20  m_xy2asic.assign(N_XCHANNELS * N_YCHANNELS, -1);
21  m_asic2xy.assign(N_XCHANNELS * N_YCHANNELS, -1);
22 }
23 
24 bool ARICHChannelMapping::getXYFromAsic(unsigned asicChn, int& xChn, int& yChn) const
25 {
26  if (asicChn > N_XCHANNELS * N_YCHANNELS - 1) {
27  B2ERROR("ARICHChannelMapping::getXYFromAsic: invalid channel asic number!");
28  return false;
29  }
30  int chId = (int)m_asic2xy[asicChn];
31  if (chId == -1) return false;
32  xChn = chId % N_XCHANNELS;
33  yChn = chId / N_XCHANNELS;
34  return true;
35 }
36 
37 int ARICHChannelMapping::getAsicFromXY(unsigned xChn, unsigned yChn) const
38 {
39  unsigned chId = yChn * N_XCHANNELS + xChn;
40  if (chId > N_XCHANNELS * N_YCHANNELS - 1) B2FATAL("ARICHChannelMapping::getAsicFromXY: invalid channel X,Y number!");
41  return (int)m_xy2asic[chId];
42 }
43 
44 void ARICHChannelMapping::mapXY2Asic(unsigned xChn, unsigned yChn, unsigned asicChn)
45 {
46  if (asicChn > N_XCHANNELS * N_YCHANNELS - 1 || xChn > N_XCHANNELS - 1
47  || yChn > N_YCHANNELS - 1) B2ERROR("ARICHChannelMapping::mapXY2Asich: invalid channel number!");
48  unsigned chId = yChn * N_XCHANNELS + xChn;
49  m_xy2asic.at(chId) = asicChn;
50  m_asic2xy.at(asicChn) = chId;
51 }
52 
53 void ARICHChannelMapping::print() const
54 {
55  std::cout << std::endl;
56  std::cout << "HAPD X,Y channel mapping to asic channels" << std::endl << std::endl;
57  std::cout << " " << setfill('-') << setw(73) << "-" << std::endl;
58  for (int y = N_YCHANNELS - 1; y > -1; y--) {
59  std::cout << setfill(' ') << "y " << setw(2) << y << " ";
60  for (int x = 0; x < N_XCHANNELS; x++) {
61  std::cout << " | " << setw(3) << getAsicFromXY(x, y);
62  }
63  std::cout << " |" << std::endl;
64  std::cout << " " << setfill('-') << setw(73) << "-" << std::endl;
65  }
66  std::cout << setfill(' ') << " ";
67  for (int x = 0; x < N_XCHANNELS; x++) std::cout << "x " << setw(2) << x << " ";
68  std::cout << std::endl;
69 }
Abstract base class for different kinds of events.