EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
materialPlotHelper.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file materialPlotHelper.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2016-2019 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #pragma once
10 
11 #include <cstdint>
12 #include <iosfwd>
13 
14 namespace Acts {
15 
27 class GeometryIdentifier {
28  public:
29  using Value = uint64_t;
30 
32  constexpr GeometryIdentifier(Value encoded) : m_value(encoded) {}
34  GeometryIdentifier() = default;
36  GeometryIdentifier(const GeometryIdentifier&) = default;
37  ~GeometryIdentifier() = default;
40 
42  constexpr Value value() const { return m_value; }
43 
45  constexpr Value volume() const { return getBits(volume_mask); }
47  constexpr Value boundary() const { return getBits(boundary_mask); }
49  constexpr Value layer() const { return getBits(layer_mask); }
51  constexpr Value approach() const { return getBits(approach_mask); }
53  constexpr Value sensitive() const { return getBits(sensitive_mask); }
54 
55  private:
56  // clang-format off
57  static constexpr Value volume_mask = 0xff00000000000000; // 255 volumes
58  static constexpr Value boundary_mask = 0x00ff000000000000; // 255 boundaries
59  static constexpr Value layer_mask = 0x0000fff000000000; // 4095 layers
60  static constexpr Value approach_mask = 0x0000000ff0000000; // 255 approach surfaces
61  static constexpr Value sensitive_mask = 0x000000000fffffff; // (2^28)-1 sensitive surfaces
62  // clang-format on
63 
64  Value m_value = 0;
65 
67  static constexpr int extractShift(Value mask) {
68  // use compiler builtin to extract the number of trailing bits from the
69  // mask. the builtin should be available on all supported compilers.
70  // need unsigned long long version (...ll) to ensure uint64_t compatibility.
71  // WARNING undefined behaviour for mask == 0 which we should not have.
72  return __builtin_ctzll(mask);
73  }
75  constexpr Value getBits(Value mask) const {
76  return (m_value & mask) >> extractShift(mask);
77  }
78 
79  friend constexpr bool operator==(GeometryIdentifier lhs,
80  GeometryIdentifier rhs) {
81  return lhs.m_value == rhs.m_value;
82  }
83  friend constexpr bool operator<(GeometryIdentifier lhs,
84  GeometryIdentifier rhs) {
85  return lhs.m_value < rhs.m_value;
86  }
87 };
88 
89 std::ostream& operator<<(std::ostream& os, GeometryIdentifier id);
90 
91 } // namespace Acts