Belle II Software  release-08-01-10
ARICHMergerMapping.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/ARICHMergerMapping.h>
12 #include <iostream>
13 
14 using namespace std;
15 using namespace Belle2;
16 
17 ARICHMergerMapping:: ARICHMergerMapping()
18 {
19  m_merger2module.assign(N_MERGERS * N_FEB2MERGER, 0);
20  m_module2merger.assign(N_MERGERS * N_FEB2MERGER, 0);
21  m_isMapped.assign(N_MERGERS * N_FEB2MERGER, 0);
22 }
23 
24 unsigned ARICHMergerMapping::getModuleID(unsigned mergerID, unsigned febSlot) const
25 {
26  if (!(mergerID > 0 && mergerID < N_MERGERS + 1 && febSlot > 0 && febSlot < N_FEB2MERGER + 1)) { B2ERROR("ARICHMergerMapping::getModuleID: invalid merger ID " << mergerID << " or febSlot " << febSlot); return 0;}
27  unsigned id = (mergerID - 1) * N_FEB2MERGER + (febSlot - 1);
28  return (unsigned)m_merger2module[id];
29 }
30 
31 unsigned ARICHMergerMapping::getMergerID(unsigned moduleID) const
32 {
33  if (!m_isMapped[moduleID - 1]) { B2WARNING("ARICHMergerMapping::getMergerID: Module " << moduleID << " not not mapped to merger!"); return 0;}
34  unsigned id = (unsigned)m_module2merger[moduleID - 1] / N_FEB2MERGER + 1;
35  return id;
36 }
37 
38 unsigned ARICHMergerMapping::getFEBSlot(unsigned moduleID) const
39 {
40  if (!m_isMapped[moduleID - 1]) { B2WARNING("ARICHMergerMapping::getMergerID: Module " << moduleID << " not not mapped to merger!"); return 0;}
41  unsigned id = (unsigned)m_module2merger[moduleID - 1] % N_FEB2MERGER + 1;
42  return id;
43 }
44 
45 unsigned ARICHMergerMapping::getMergerSN(unsigned mergerID) const
46 {
47  unsigned mergerSN = m_mergerID.find(mergerID)->second;
48  return mergerSN;
49 }
50 
51 unsigned ARICHMergerMapping::getMergerIDfromSN(unsigned mergerSN) const
52 {
53  unsigned mergerID = 99;
54  for (auto& i : m_mergerID) { if (i.second == mergerSN) mergerID = i.first; }
55 
56  return mergerID;
57 }
58 
59 void ARICHMergerMapping::addMapping(unsigned moduleID, unsigned mergerID, unsigned febSlot, unsigned mergerSN)
60 {
61 
62 // if (!(mergerID > 0 && mergerID < N_MERGERS + 1 && febSlot > 0 && febSlot < N_FEB2MERGER + 1 && moduleID < N_MERGERS * N_FEB2MERGER)) { B2ERROR("ARICHMergerMapping::addMapping: invalid mergerID/febSlot/moduleID!"); return;}
63 
64  m_module2merger[moduleID - 1] = (uint16_t)((mergerID - 1) * N_FEB2MERGER + (febSlot - 1));
65  m_merger2module[(mergerID - 1) * N_FEB2MERGER + (febSlot - 1)] = (uint16_t)moduleID;
66  m_isMapped[moduleID - 1] = 1;
67 
68  m_mergerID.insert(std::pair<unsigned, unsigned>(mergerID, mergerSN));
69 }
70 
71 void ARICHMergerMapping::print() const
72 {
73 
74  std::cout << std::endl;
75  std::cout << "Mapping of modules to mergers" << std::endl;
76  std::cout << std::endl;
77  for (int i = 1; i < N_MERGERS + 1; i++) {
78  bool isUsed = false;
79  for (int j = 1; j < N_FEB2MERGER + 1; j++) {
80  if (getModuleID(i, j)) { isUsed = true; break;}
81  }
82 
83  if (!isUsed) continue;
84  std::cout << " Modules connected to merger " << i << " (SN = " << getMergerSN(i) << ")" << std::endl;
85  for (int j = 1; j < N_FEB2MERGER + 1; j++) {
86  if (getModuleID(i, j)) std::cout << " FEB slot " << j << ": " << getModuleID(i, j) << std::endl;
87  else std::cout << " FEB slot " << j << " not connected" << std::endl;
88  }
89 
90  }
91 }
92 
Abstract base class for different kinds of events.