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 <stdexcept>
17#include <string>
18#include <format>
19
21{
22 // Millepede label is any positive integer [1....)
23 // Layout: DOF(8) | CALIB(1) | ID(19) | SENS(1) | DET(2) = 31 usable bits (MSB reserved, GBL uses signed int)
24 public:
25 using T = uint32_t;
26 static constexpr int DOF_BITS = 8; // bits 0-7
27 static constexpr int CALIB_BITS = 1; // bit 8: 0 = rigid body, 1 = calibration (only allow for one calibration, could be extended if needed)
28 static constexpr int ID_BITS = 19; // bits 9-27
29 static constexpr int SENS_BITS = 1; // bit 28
30 static constexpr int TOTAL_BITS = sizeof(T) * 8;
31 static constexpr int DET_BITS = TOTAL_BITS - (DOF_BITS + CALIB_BITS + ID_BITS + SENS_BITS) - 1; // one less bit since GBL uses int!
32 static constexpr T bitMask(int b) noexcept
33 {
34 return (T(1) << b) - T(1);
35 }
36 static constexpr int DOF_SHIFT = 0;
37 static constexpr T DOF_MAX = (T(1) << DOF_BITS) - T(1);
38 static constexpr T DOF_MASK = DOF_MAX << DOF_SHIFT;
39 static constexpr int CALIB_SHIFT = DOF_BITS;
40 static constexpr T CALIB_MAX = (T(1) << CALIB_BITS) - T(1);
41 static constexpr T CALIB_MASK = CALIB_MAX << CALIB_SHIFT;
42 static constexpr int ID_SHIFT = DOF_BITS + CALIB_BITS;
43 static constexpr T ID_MAX = (T(1) << ID_BITS) - T(1);
44 static constexpr T ID_MASK = ID_MAX << ID_SHIFT;
45 static constexpr int SENS_SHIFT = DOF_BITS + CALIB_BITS + ID_BITS;
46 static constexpr T SENS_MAX = (T(1) << SENS_BITS) - T(1);
47 static constexpr T SENS_MASK = SENS_MAX << SENS_SHIFT;
48 static constexpr int DET_SHIFT = DOF_BITS + CALIB_BITS + ID_BITS + SENS_BITS;
49 static constexpr T DET_MAX = (T(1) << DET_BITS) - T(1);
50 static constexpr T DET_MASK = DET_MAX << DET_SHIFT;
51
53 static constexpr int MAX_DOFS = static_cast<int>(DOF_MAX) + 1;
54
56 static void checkDOFCount(int nDOFs)
57 {
58 if (nDOFs > MAX_DOFS) {
59 throw std::out_of_range(std::format(
60 "DOF set with {} parameters exceeds the {} labelable DOFs (DOF_BITS={}); "
61 "distinct parameters would alias onto the same Millepede label",
62 nDOFs, MAX_DOFS, DOF_BITS));
63 }
64 }
65
66 GlobalLabel(T det, T id, bool sens, bool calib = false)
67 : mID((((id + 1) & ID_MAX) << ID_SHIFT) |
68 ((det & DET_MAX) << DET_SHIFT) |
69 ((T(sens) & SENS_MAX) << SENS_SHIFT) |
70 ((T(calib) & CALIB_MAX) << CALIB_SHIFT))
71 {
72 if ((id + 1) > ID_MAX) {
73 throw std::out_of_range(std::format("Volume id {} exceeds the {} labelable ids (ID_BITS={})",
74 id, ID_MAX - 1, ID_BITS));
75 }
76 }
77
79 constexpr T raw(T dof) const noexcept { return (mID & ~DOF_MASK) | ((dof & DOF_MAX) << DOF_SHIFT); }
80 constexpr int rawGBL(T dof) const noexcept { return static_cast<int>(raw(dof)); }
81
83 GlobalLabel asCalib() const noexcept
84 {
85 GlobalLabel c{*this};
86 c.mID |= (T(1) << CALIB_SHIFT);
87 return c;
88 }
89
90 constexpr T id() const noexcept { return ((mID >> ID_SHIFT) & ID_MAX) - 1; }
91 constexpr T det() const noexcept { return (mID & DET_MASK) >> DET_SHIFT; }
92 constexpr bool sens() const noexcept { return (mID & SENS_MASK) >> SENS_SHIFT; }
93 constexpr bool calib() const noexcept { return (mID & CALIB_MASK) >> CALIB_SHIFT; }
94
95 std::string asString() const
96 {
97 return std::format("Det:{} Id:{} Sens:{} Calib:{}", det(), id(), sens(), calib());
98 }
99
100 constexpr auto operator<=>(const GlobalLabel&) const noexcept = default;
101
102 private:
103 T mID{0};
104};
105
106#endif
o2::raw::RawFileWriter * raw
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 int MAX_DOFS
maximum number of DOFs that can be labelled on one volume (per calib bit)
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 void checkDOFCount(int nDOFs)
throws if a DOF set is too large to be labelled without aliasing
static constexpr T CALIB_MAX
static constexpr T SENS_MASK
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
GLuint id
Definition glcorearb.h:650