Belle II Software  release-05-01-25
ARICHChannelMapping.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Luka Santelj *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <framework/logging/Logger.h>
12 
13 #include <arich/dbobjects/ARICHChannelMapping.h>
14 #include <iostream>
15 #include<iomanip>
16 
17 using namespace std;
18 using namespace Belle2;
19 
20 ARICHChannelMapping::ARICHChannelMapping()
21 {
22  m_xy2asic.assign(N_XCHANNELS * N_YCHANNELS, -1);
23  m_asic2xy.assign(N_XCHANNELS * N_YCHANNELS, -1);
24 }
25 
26 bool ARICHChannelMapping::getXYFromAsic(unsigned asicChn, int& xChn, int& yChn) const
27 {
28  if (asicChn > N_XCHANNELS * N_YCHANNELS - 1) {
29  B2ERROR("ARICHChannelMapping::getXYFromAsic: invalid channel asic number!");
30  return false;
31  }
32  int chId = (int)m_asic2xy[asicChn];
33  if (chId == -1) return false;
34  xChn = chId % N_XCHANNELS;
35  yChn = chId / N_XCHANNELS;
36  return true;
37 }
38 
39 int ARICHChannelMapping::getAsicFromXY(unsigned xChn, unsigned yChn) const
40 {
41  unsigned chId = yChn * N_XCHANNELS + xChn;
42  if (chId > N_XCHANNELS * N_YCHANNELS - 1) B2FATAL("ARICHChannelMapping::getAsicFromXY: invalid channel X,Y number!");
43  return (int)m_xy2asic[chId];
44 }
45 
46 void ARICHChannelMapping::mapXY2Asic(unsigned xChn, unsigned yChn, unsigned asicChn)
47 {
48  if (asicChn > N_XCHANNELS * N_YCHANNELS - 1 || xChn > N_XCHANNELS - 1
49  || yChn > N_YCHANNELS - 1) B2ERROR("ARICHChannelMapping::mapXY2Asich: invalid channel number!");
50  unsigned chId = yChn * N_XCHANNELS + xChn;
51  m_xy2asic.at(chId) = asicChn;
52  m_asic2xy.at(asicChn) = chId;
53 }
54 
55 void ARICHChannelMapping::print() const
56 {
57  std::cout << std::endl;
58  std::cout << "HAPD X,Y channel mapping to asic channels" << std::endl << std::endl;
59  std::cout << " " << setfill('-') << setw(73) << "-" << std::endl;
60  for (int y = N_YCHANNELS - 1; y > -1; y--) {
61  std::cout << setfill(' ') << "y " << setw(2) << y << " ";
62  for (int x = 0; x < N_XCHANNELS; x++) {
63  std::cout << " | " << setw(3) << getAsicFromXY(x, y);
64  }
65  std::cout << " |" << std::endl;
66  std::cout << " " << setfill('-') << setw(73) << "-" << std::endl;
67  }
68  std::cout << setfill(' ') << " ";
69  for (int x = 0; x < N_XCHANNELS; x++) std::cout << "x " << setw(2) << x << " ";
70  std::cout << std::endl;
71 }
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19