Project
Loading...
Searching...
No Matches
AlignmentLabel.h
Go to the documentation of this file.
1// Copyright 2019-2026 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#ifndef O2_ITS3_ALIGNMENT_LABEL_H
13#define O2_ITS3_ALIGNMENT_LABEL_H
14
15#include <cstdint>
16#include <string>
17#include <format>
18
20{
21 // Millepede label is any positive integer [1....)
22 // Layout: DOF(5) | CALIB(1) | ID(22) | SENS(1) | DET(2) = 31 usable bits (MSB reserved, GBL uses signed int)
23 public:
24 using T = uint32_t;
25 static constexpr int DOF_BITS = 5; // bits 0-4
26 static constexpr int CALIB_BITS = 1; // bit 5: 0 = rigid body, 1 = calibration (only allow for one calibration, could be extended if needed)
27 static constexpr int ID_BITS = 22; // bits 6-27
28 static constexpr int SENS_BITS = 1; // bit 28
29 static constexpr int TOTAL_BITS = sizeof(T) * 8;
30 static constexpr int DET_BITS = TOTAL_BITS - (DOF_BITS + CALIB_BITS + ID_BITS + SENS_BITS) - 1; // one less bit since GBL uses int!
31 static constexpr T bitMask(int b) noexcept
32 {
33 return (T(1) << b) - T(1);
34 }
35 static constexpr int DOF_SHIFT = 0;
36 static constexpr T DOF_MAX = (T(1) << DOF_BITS) - T(1);
37 static constexpr T DOF_MASK = DOF_MAX << DOF_SHIFT;
38 static constexpr int CALIB_SHIFT = DOF_BITS;
39 static constexpr T CALIB_MAX = (T(1) << CALIB_BITS) - T(1);
40 static constexpr T CALIB_MASK = CALIB_MAX << CALIB_SHIFT;
41 static constexpr int ID_SHIFT = DOF_BITS + CALIB_BITS;
42 static constexpr T ID_MAX = (T(1) << ID_BITS) - T(1);
43 static constexpr T ID_MASK = ID_MAX << ID_SHIFT;
44 static constexpr int SENS_SHIFT = DOF_BITS + CALIB_BITS + ID_BITS;
45 static constexpr T SENS_MAX = (T(1) << SENS_BITS) - T(1);
46 static constexpr T SENS_MASK = SENS_MAX << SENS_SHIFT;
47 static constexpr int DET_SHIFT = DOF_BITS + CALIB_BITS + ID_BITS + SENS_BITS;
48 static constexpr T DET_MAX = (T(1) << DET_BITS) - T(1);
49 static constexpr T DET_MASK = DET_MAX << DET_SHIFT;
50
51 GlobalLabel(T det, T id, bool sens, bool calib = false)
52 : mID((((id + 1) & ID_MAX) << ID_SHIFT) |
53 ((det & DET_MAX) << DET_SHIFT) |
54 ((T(sens) & SENS_MAX) << SENS_SHIFT) |
55 ((T(calib) & CALIB_MAX) << CALIB_SHIFT))
56 {
57 }
58
60 constexpr T raw(T dof) const noexcept { return (mID & ~DOF_MASK) | ((dof & DOF_MAX) << DOF_SHIFT); }
61 constexpr int rawGBL(T dof) const noexcept { return static_cast<int>(raw(dof)); }
62
64 GlobalLabel asCalib() const noexcept
65 {
66 GlobalLabel c{*this};
67 c.mID |= (T(1) << CALIB_SHIFT);
68 return c;
69 }
70
71 constexpr T id() const noexcept { return ((mID >> ID_SHIFT) & ID_MAX) - 1; }
72 constexpr T det() const noexcept { return (mID & DET_MASK) >> DET_SHIFT; }
73 constexpr bool sens() const noexcept { return (mID & SENS_MASK) >> SENS_SHIFT; }
74 constexpr bool calib() const noexcept { return (mID & CALIB_MASK) >> CALIB_SHIFT; }
75
76 std::string asString() const
77 {
78 return std::format("Det:{} Id:{} Sens:{} Calib:{}", det(), id(), sens(), calib());
79 }
80
81 constexpr auto operator<=>(const GlobalLabel&) const noexcept = default;
82
83 private:
84 T mID{0};
85};
86
87#endif
uint32_t c
Definition RawData.h:2
constexpr T raw(T dof) const noexcept
produce the raw Millepede label for a given DOF index (rigid body: calib=0 in label)
static constexpr int ID_BITS
constexpr T det() const noexcept
static constexpr int DET_SHIFT
static constexpr int TOTAL_BITS
constexpr auto operator<=>(const GlobalLabel &) const noexcept=default
GlobalLabel asCalib() const noexcept
return a copy of this label with the CALIB bit set (for calibration DOFs on same volume)
static constexpr T ID_MASK
constexpr bool calib() const noexcept
GlobalLabel(T det, T id, bool sens, bool calib=false)
static constexpr int SENS_BITS
std::string asString() const
static constexpr int ID_SHIFT
static constexpr T ID_MAX
static constexpr T SENS_MAX
static constexpr int DOF_BITS
static constexpr T CALIB_MASK
static constexpr int CALIB_SHIFT
static constexpr int DOF_SHIFT
static constexpr T DOF_MAX
static constexpr T DET_MASK
static constexpr T DET_MAX
constexpr int rawGBL(T dof) const noexcept
static constexpr int SENS_SHIFT
static constexpr int CALIB_BITS
constexpr bool sens() const noexcept
static constexpr T bitMask(int b) noexcept
static constexpr int DET_BITS
static constexpr T DOF_MASK
constexpr T id() const noexcept
static constexpr T CALIB_MAX
static constexpr T SENS_MASK
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
GLuint id
Definition glcorearb.h:650