Project
Loading...
Searching...
No Matches
MapCRU.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 "MapCRU.h"
13#include <fstream>
14#include <iostream>
15#include <optional>
16#include <sstream>
17#include <algorithm>
18#include <limits>
19
20namespace
21{
22bool isValid(uint16_t solarId)
23{
24 return solarId != std::numeric_limits<uint16_t>::max();
25}
26} // namespace
27
28namespace o2::mch::raw
29{
30
31MapCRU::MapCRU(std::string_view content)
32{
33 mFeeLink2Solar.fill(std::numeric_limits<uint16_t>::max());
34 std::istringstream input(content.data());
35 std::string s;
36 while (std::getline(input, s)) {
37 if (s.empty()) {
38 continue;
39 }
40 std::istringstream line(s);
41 int f, l, link_id;
42 line >> link_id >> f >> l;
43 auto ix = indexFeeLink(f, l);
44 if (ix < 0) {
45 continue;
46 }
47 mFeeLink2Solar.at(ix) = link_id;
48 }
49
50 mSize = size();
51}
52
53std::set<uint16_t> MapCRU::getSolarUIDs() const
54{
55 std::set<uint16_t> solarIds;
56 for (auto s : mFeeLink2Solar) {
57 if (s != std::numeric_limits<uint16_t>::max()) {
58 solarIds.emplace(s);
59 }
60 }
61 return solarIds;
62}
63
64std::optional<FeeLinkId> MapCRU::operator()(uint16_t solarId) const
65{
66 auto it = std::find(begin(mFeeLink2Solar),
67 end(mFeeLink2Solar), solarId);
68 if (it == mFeeLink2Solar.end()) {
69 return std::nullopt;
70 }
71 auto d = std::distance(mFeeLink2Solar.begin(), it);
72 int feeId = d / sMaxLinkId;
73 int linkId = d % sMaxLinkId;
74 return FeeLinkId(feeId, linkId);
75}
76
77int MapCRU::indexFeeLink(int feeid, int linkid) const
78{
79 if (feeid < 0 || feeid >= sMaxFeeId) {
80 return -1;
81 }
82 if (linkid < 0 || linkid >= sMaxLinkId) {
83 return -1;
84 }
85 return feeid * sMaxLinkId + linkid;
86}
87
88size_t MapCRU::size() const
89{
90 return std::count_if(mFeeLink2Solar.begin(), mFeeLink2Solar.end(), [](uint16_t a) { return a != std::numeric_limits<uint16_t>::max(); });
91}
92
93std::optional<uint16_t> MapCRU::operator()(const o2::mch::raw::FeeLinkId& feeLinkId) const
94{
95 if (!mSize) {
96 return std::nullopt;
97 }
98 auto ix = indexFeeLink(feeLinkId.feeId(), feeLinkId.linkId());
99 if (ix < 0) {
100 return std::nullopt;
101 }
102 auto solarId = mFeeLink2Solar.at(ix);
103 if (isValid(solarId)) {
104 return solarId;
105 }
106 return std::nullopt;
107}
108} // namespace o2::mch::raw
unsigned short int uint16_t
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error s
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char Directory with events to Events directory is and not inside events d
uint8_t linkId() const
Definition FeeLinkId.h:27
uint16_t feeId() const
Definition FeeLinkId.h:26
std::optional< uint16_t > operator()(const FeeLinkId &feeLinkId) const
Definition MapCRU.cxx:93
MapCRU(std::string_view content)
Definition MapCRU.cxx:31
size_t size() const
Definition MapCRU.cxx:88
std::set< uint16_t > getSolarUIDs() const
Definition MapCRU.cxx:53
GLuint GLuint end
Definition glcorearb.h:469
GLdouble f
Definition glcorearb.h:310
GLboolean GLboolean GLboolean GLboolean a
Definition glcorearb.h:1233
bool isValid(std::string alias)