Project
Loading...
Searching...
No Matches
MapFEC.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12#include "MapFEC.h"
13#include <iostream>
14#include <fstream>
15#include <algorithm>
16#include <string>
17#include <sstream>
18
19namespace o2::mch::raw
20{
21
22MapFEC::MapFEC(std::string_view content)
23{
24 mDsMap.fill({-1, -1, -1});
25 int link_id, group_id, de, ds_id[5];
26 std::istringstream in(std::string{content});
27 while (in >> link_id >> group_id >> de >> ds_id[0] >> ds_id[1] >> ds_id[2] >> ds_id[3] >> ds_id[4]) {
28 for (int i = 0; i < 5; i++) {
29 if (ds_id[i] <= 0) {
30 continue;
31 }
32 int ds_addr = group_id * 5 + i;
33 int ix = index(link_id, ds_addr);
34 if (ix < 0) {
35 continue;
36 }
37 mDsMap.at(ix) = {de, ds_id[i], 0};
38 }
39 }
40
41 mSize = size();
42}
43
44int MapFEC::index(uint32_t linkId, uint32_t dsAddr) const
45{
46 if (linkId < 0 || linkId > sMaxLinkId) {
47 return -1;
48 }
49 if (dsAddr < 0 || dsAddr >= sMaxDs) {
50 return -1;
51 }
52 return linkId * sMaxDs + dsAddr;
53}
54
55size_t MapFEC::size() const
56{
57 return std::count_if(mDsMap.begin(), mDsMap.end(), [](const MapDualSampa& m) {
58 return m.deId >= 0 && m.dsId >= 0 && m.bad == 0;
59 });
60}
61
62std::optional<o2::mch::raw::DsDetId> MapFEC::operator()(const o2::mch::raw::DsElecId& dsElecId) const
63{
64 auto link_id = dsElecId.solarId();
65 auto ds_addr = dsElecId.elinkId();
66
67 if (!mSize) {
68 return std::nullopt;
69 }
70
71 int ix = index(link_id, ds_addr);
72 if (ix < 0) {
73 return std::nullopt;
74 }
75 if (mDsMap.at(ix).bad == 1) {
76 return std::nullopt;
77 }
78 auto de = mDsMap.at(ix).deId;
79 auto dsid = mDsMap.at(ix).dsId;
80 if (de >= 0 && dsid >= 0) {
81 return o2::mch::raw::DsDetId(de, dsid);
82 }
83 return std::nullopt;
84}
85} // namespace o2::mch::raw
int32_t i
A DsDetId is just a pair (detection element id, dual sampa id)
Definition DsDetId.h:22
constexpr uint8_t elinkId() const
Definition DsElecId.h:44
constexpr uint16_t solarId() const
solarId is an identifier that uniquely identify a solar board
Definition DsElecId.h:50
std::optional< DsDetId > operator()(const DsElecId &elecId) const
Definition MapFEC.cxx:62
size_t size() const
Definition MapFEC.cxx:55
MapFEC(std::string_view content)
Definition MapFEC.cxx:22
const GLfloat * m
Definition glcorearb.h:4066
GLuint index
Definition glcorearb.h:781
uint16_t de