Belle II Software development
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
14using namespace std;
15using namespace Belle2;
16
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
24unsigned 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
31unsigned 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
38unsigned 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
45unsigned ARICHMergerMapping::getMergerSN(unsigned mergerID) const
46{
47 unsigned mergerSN = m_mergerID.find(mergerID)->second;
48 return mergerSN;
49}
50
51unsigned 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
59void 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
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
unsigned getMergerIDfromSN(unsigned mergerSN) const
Get ID of merger from serial number.
unsigned getModuleID(unsigned mergerID, unsigned febSlot) const
Get ID of module connected to merger at FEB slot.
std::vector< uint16_t > m_module2merger
map of modules to mergers
ARICHMergerMapping()
Default constructor.
std::vector< bool > m_isMapped
vector of mapped modules
std::vector< uint16_t > m_merger2module
map of mergers to modules
void addMapping(unsigned moduleID, unsigned mergerID, unsigned febSlot, unsigned mergerSN)
Add mapping entry.
unsigned getMergerID(unsigned moduleID) const
Get ID of merger to which module is connected.
unsigned getMergerSN(unsigned mergerID) const
Get serial number of marger from its ID.
void print() const
Pring mapping.
unsigned getFEBSlot(unsigned moduleID) const
Get FEB slot to which module is connected.
std::map< unsigned, unsigned > m_mergerID
map mergers ID to SN
Abstract base class for different kinds of events.
STL namespace.