Project
Loading...
Searching...
No Matches
ClustersPerLayer.h
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
15
16#ifndef ALICEO2_ITSMFT_CLUSTERSPERLAYER_H
17#define ALICEO2_ITSMFT_CLUSTERSPERLAYER_H
18
20#include "Framework/Logger.h"
21#include <array>
22#include <vector>
23
24namespace o2::itsmft
25{
26
45template <typename T>
47{
48 public:
50 void init(int nLr)
51 {
52 if (nLr < 1 || nLr > MaxClusLayers) {
53 LOGP(fatal, "Clusters container cannot be initialized for {} layers, must be within 1:{}", nLr, MaxClusLayers);
54 }
55 mClusters.clear();
56 mLrFirst.fill(0);
57 mNLayers = nLr;
58 }
59
61 void beginLayer(int lr)
62 {
63 if (lr < 0 || lr >= mNLayers) {
64 LOGP(fatal, "Clusters container was initialized for {} layers, cannot fill the layer {}", mNLayers, lr);
65 }
66 mLrFirst[lr] = int(mClusters.size());
67 }
68
70 void finalize()
71 {
72 for (int lr = mNLayers; lr <= MaxClusLayers; lr++) { // the slots above the filled ones are empty
73 mLrFirst[lr] = int(mClusters.size());
74 }
75 }
76
77 void clear()
78 {
79 mClusters.clear();
80 mLrFirst.fill(0);
81 mNLayers = 1;
82 }
83
85 auto& getClusters() { return mClusters; }
86 const auto& getClusters() const { return mClusters; }
87
88 auto getNLayers() const { return mNLayers; }
89 auto getFirstIndex(int lr) const { return mLrFirst[lr]; }
90 auto getNClusters(int lr) const { return mLrFirst[lr + 1] - mLrFirst[lr]; }
91 auto size() const { return mClusters.size(); }
92 bool empty() const { return mClusters.empty(); }
93
95 int flatIndex(int composedID) const
96 {
97 return mLrFirst[clusID2Layer(composedID)] + clusID2Index(composedID);
98 }
99 const T& operator[](int composedID) const { return mClusters[flatIndex(composedID)]; }
100
101 private:
102 std::vector<T> mClusters{};
103 std::array<int, MaxClusLayers + 1> mLrFirst{};
104 int mNLayers = 1;
105};
106
107} // namespace o2::itsmft
108
109#endif
Composition/decomposition of the ITS/MFT cluster IDs referring to per-layer cluster arrays.
auto getFirstIndex(int lr) const
void clear()
the clusters of all layers, to be appended to by the caller between beginLayer and finalize
const auto & getClusters() const
void beginLayer(int lr)
to be called once all the layers were filled
auto getNClusters(int lr) const
void init(int nLr)
< prepare for filling nLr layer slots, discarding the previous content
bool empty() const
flat index of the cluster referred to by its composed ID
const T & operator[](int composedID) const
int flatIndex(int composedID) const
constexpr int clusID2Layer(int id)
Definition ClusterID.h:38
constexpr int MaxClusLayers
Definition ClusterID.h:25
constexpr int clusID2Index(int id)
Definition ClusterID.h:39