Project
Loading...
Searching...
No Matches
Number.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
13#include <fmt/core.h>
14#include <cstdint>
15
16namespace
17{
18
19int parseNumber(std::string_view alias, std::string_view key, uint8_t len)
20{
21 auto pos = alias.find(key);
22 std::string s{alias.substr(pos + key.size(), len)};
23 return std::stoi(s);
24}
25
26} // namespace
27
28namespace o2::mch::dcs
29{
30int aliasToNumber(std::string_view alias)
31{
32 if (alias.find("Slat") != std::string_view::npos) {
33 return parseNumber(alias, "Slat", 2);
34 } else if (alias.find("Quad") != std::string_view::npos) {
35 auto quad = parseNumber(alias, "Quad", 1);
36 auto sector = parseNumber(alias, "Sect", 1);
37 return quad * 10 + sector;
38 } else if (alias.find("SolCh") != std::string_view::npos) {
39 return parseNumber(alias, "Cr", 2);
40 } else if (alias.find("Group") != std::string_view::npos) {
41 return parseNumber(alias, "Group", 2);
42 }
43 throw std::invalid_argument(fmt::format("Cannot extract number from alias={}", alias));
44}
45} // namespace o2::mch::dcs
uint16_t pos
Definition RawData.h:3
StringRef key
GLenum GLenum GLsizei len
Definition glcorearb.h:4232
int aliasToNumber(std::string_view dcsAlias)
Definition Number.cxx:30