Project
Loading...
Searching...
No Matches
Array2D.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 <Framework/Array2D.h>
15
16template class std::unordered_map<std::string, u_int32_t>;
17
18namespace o2::framework
19{
20
21labelmap_t LabelMap::populate(uint32_t size, std::vector<std::string> labels)
22{
23 labelmap_t map;
24 if (labels.empty() == false) {
25 if (labels.size() != size) {
26 throw runtime_error("labels array size != array dimension");
27 }
28 for (auto i = 0u; i < size; ++i) {
29 map.emplace(labels[i], (uint32_t)i);
30 }
31 }
32 return map;
33}
34
35void LabelMap::replaceLabelsRows(uint32_t size, std::vector<std::string> const& labels)
36{
37 if (O2_BUILTIN_UNLIKELY(size != labels.size())) {
38 throw runtime_error_f("Row labels array has different size (%d) than number of rows (%d)", labels.size(), size);
39 };
40 labels_rows = labels;
41 rowmap.clear();
42 rowmap = populate(labels.size(), labels);
43}
44
45void LabelMap::replaceLabelsCols(uint32_t size, std::vector<std::string> const& labels)
46{
47 if (O2_BUILTIN_UNLIKELY(size != labels.size())) {
48 throw runtime_error_f("Column labels array has different size (%d) than number of columns (%d)", labels.size(), size);
49 };
50 labels_cols = labels;
51 colmap.clear();
52 colmap = populate(labels.size(), labels);
53}
54LabelMap::LabelMap()
55 : rowmap{},
56 colmap{},
59{
60}
61
62LabelMap::LabelMap(uint32_t rows, uint32_t cols, std::vector<std::string> labels_rows_, std::vector<std::string> labels_cols_)
63 : rowmap{populate(rows, labels_rows_)},
64 colmap{populate(cols, labels_cols_)},
65 labels_rows{labels_rows_},
66 labels_cols{labels_cols_}
67{
68}
69
70LabelMap::LabelMap(uint32_t size, std::vector<std::string> labels)
71 : rowmap{},
72 colmap{populate(size, labels)},
74 labels_cols{labels}
75{
76}
77
78LabelMap::LabelMap(LabelMap const& other) = default;
82
83} // namespace o2::framework
#define O2_BUILTIN_UNLIKELY(x)
int32_t i
uint32_t cols
std::vector< std::string > labels_rows
std::vector< std::string > labels_cols
GLsizeiptr size
Definition glcorearb.h:659
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
RuntimeErrorRef runtime_error(const char *)
std::unordered_map< std::string, uint32_t > labelmap_t
Definition Array2D.h:127
RuntimeErrorRef runtime_error_f(const char *,...)
LabelMap & operator=(LabelMap const &other)
VectorOfTObjectPtrs other
std::vector< ReadoutWindowData > rows