forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRangeReference.h
More file actions
103 lines (90 loc) · 3.49 KB
/
RangeReference.h
File metadata and controls
103 lines (90 loc) · 3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
/// \file RangeReference.h
/// \brief Class to refer to the 1st entry and N elements of some group in the continuous container
/// \author ruben.shahoyan@cern.ch
#ifndef ALICEO2_RANGEREFERENCE_H
#define ALICEO2_RANGEREFERENCE_H
#include "GPUCommonRtypes.h"
#include "GPUCommonDef.h"
namespace o2
{
namespace dataformats
{
// Composed range reference
template <typename FirstEntry = int, typename NElem = int>
class RangeReference
{
public:
GPUhd() RangeReference(FirstEntry ent, NElem n) { set(ent, n); }
GPUhdDefault() RangeReference(const RangeReference<FirstEntry, NElem>& src) = default;
GPUhdDefault() RangeReference() = default;
GPUhdDefault() ~RangeReference() = default;
GPUhd() void set(FirstEntry ent, NElem n)
{
mFirstEntry = ent;
mEntries = n;
}
GPUhd() void clear() { set(0, 0); }
GPUhd() FirstEntry getFirstEntry() const { return mFirstEntry; }
GPUhd() FirstEntry getEntriesBound() const { return mFirstEntry + mEntries; }
GPUhd() NElem getEntries() const { return mEntries; }
GPUhd() void setFirstEntry(FirstEntry ent) { mFirstEntry = ent; }
GPUhd() void setEntries(NElem n) { mEntries = n; }
GPUhd() void changeEntriesBy(NElem inc) { mEntries += inc; }
GPUhd() bool operator==(const RangeReference& other) const
{
return mFirstEntry == other.mFirstEntry && mEntries == other.mEntries;
}
private:
FirstEntry mFirstEntry; ///< 1st entry of the group
NElem mEntries = 0; ///< number of entries
ClassDefNV(RangeReference, 1);
};
// Compact (32bit long) range reference
template <int NBitsN>
class RangeRefComp
{
using Base = unsigned int;
private:
static constexpr int NBitsTotal = sizeof(Base) * 8;
static constexpr Base MaskN = ((0x1 << NBitsN) - 1);
static constexpr Base MaskR = (~Base(0)) & (~MaskN);
Base mData = 0; ///< packed 1st entry reference + N entries
GPUhd() void sanityCheck()
{
static_assert(NBitsN < NBitsTotal, "NBitsN too large");
}
public:
GPUhd() RangeRefComp(int ent, int n) { set(ent, n); }
GPUhdDefault() RangeRefComp() = default;
GPUhdDefault() RangeRefComp(const RangeRefComp& src) = default;
GPUhd() void set(int ent, int n)
{
mData = (Base(ent) << NBitsN) + (Base(n) & MaskN);
}
GPUhd() static constexpr Base getMaxFirstEntry() { return MaskR >> NBitsN; }
GPUhd() static constexpr Base getMaxEntries() { return MaskN; }
GPUhd() int getFirstEntry() const { return mData >> NBitsN; }
GPUhd() int getEntries() const { return mData & ((0x1 << NBitsN) - 1); }
GPUhd() int getEntriesBound() const { return getFirstEntry() + getEntries(); }
GPUhd() void setFirstEntry(int ent) { mData = (Base(ent) << NBitsN) | (mData & MaskN); }
GPUhd() void setEntries(int n) { mData = (mData & MaskR) | (Base(n) & MaskN); }
GPUhd() void changeEntriesBy(int inc) { setEntries(getEntries() + inc); }
GPUhd() bool operator==(const RangeRefComp& other) const
{
return mData == other.mData;
}
ClassDefNV(RangeRefComp, 1);
};
} // namespace dataformats
} // namespace o2
#endif