Belle II Software development
ARICHCopperMapping.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 <arich/dbobjects/ARICHCopperMapping.h>
10#include <framework/logging/Logger.h>
11
12#include <arich/dbobjects/ARICHMergerMapping.h>
13
14#include <iostream>
15#include <vector>
16#include <algorithm>
17
18using namespace std;
19using namespace Belle2;
20
22{
23 m_merger2copper.assign(N_MERGERS, std::make_pair(0, 0));
24}
25
26unsigned ARICHCopperMapping::getCopperID(unsigned mergerID) const
27{
28// if (mergerID > N_MERGERS + 1 || mergerID == 0) B2ERROR("ARICHCopperMapping::getCopperID: invalid merger ID number!");
29 return (unsigned)m_merger2copper[mergerID - 1].first;
30}
31
32unsigned ARICHCopperMapping::getFinesse(unsigned mergerID) const
33{
34// if (mergerID > N_MERGERS + 1 || mergerID == 0) B2ERROR("ARICHCopperMapping::getFinesse: invalid merger ID number!");
35 return (unsigned)m_merger2copper[mergerID - 1].second;
36}
37
38void ARICHCopperMapping::addMapping(unsigned mergerID, unsigned copperID, unsigned finesse)
39{
40
41// if (mergerID > N_MERGERS + 1 || mergerID == 0) B2ERROR("ARICHCopperMapping::addMapping: invalid merger ID number!");
42 if (finesse > 3) B2ERROR("ARICHCopperMapping::addMapping: invalid finesse number (0-3)!");
43
44 m_merger2copper[mergerID - 1] = std::make_pair(copperID, finesse);
45
46 if (m_copper2merger.find(copperID) == m_copper2merger.end()) {
47 std::vector<uint16_t> mergerList = {0, 0, 0, 0};
48 mergerList[finesse] = mergerID;
49 m_copper2merger.insert(std::pair<uint16_t, std::vector<uint16_t>>((uint16_t)copperID, mergerList));
50 } else {
51 std::vector<uint16_t>& mergerList = m_copper2merger[copperID];
52 mergerList[finesse] = mergerID;
53 }
54
55 if (std::find(m_copperIDs.begin(), m_copperIDs.end(), uint16_t(copperID)) == m_copperIDs.end()) m_copperIDs.push_back(copperID);
56}
57
58unsigned ARICHCopperMapping::getMergerID(unsigned copperID, unsigned finesse) const
59{
60 if (finesse > 3) B2ERROR("ARICHCopperMapping::getMergerID: invalid finesse number (0-3)!");
61 auto it = m_copper2merger.find(copperID);
62 if (it == m_copper2merger.end()) return 0;
63 return (unsigned)it->second[finesse];
64}
65
67{
68 cout << endl;
69 cout << "Mapping of merger to copper boards" << endl;
70 cout << endl;
71 for (auto copper : m_copperIDs) {
72 cout << " Merger boards connected to copper board " << copper << endl;
73 for (int i = 0; i < 4; i++) {
74 if (getMergerID(copper, i)) cout << " Finesse " << i << ": " << getMergerID(copper, i) << endl;
75 else cout << " Finesse " << i << ": not connected" << endl;
76 }
77 }
78}
unsigned getCopperID(unsigned mergerID) const
Get copper board to which merger is connected.
void addMapping(unsigned mergerID, unsigned copperID, unsigned finesse)
Add new entry to the mapping table.
unsigned getMergerID(unsigned copperID, unsigned finesse) const
Get ID of merger connected to the given finesse of copper board.
std::map< uint16_t, std::vector< uint16_t > > m_copper2merger
map coppers to mergers
std::vector< uint16_t > m_copperIDs
vector of IDs of used copper boards
ARICHCopperMapping()
Default constructor.
void print() const
Print mapping parameters.
std::vector< std::pair< uint16_t, uint16_t > > m_merger2copper
map of mergers to copper boards
unsigned getFinesse(unsigned mergerID) const
Get finesse of copper board to which merger is connected.
Abstract base class for different kinds of events.
STL namespace.