Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Barcode.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Barcode.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2018-2020 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 
12 
13 #include <cstdint>
14 
15 namespace ActsFatras {
16 
94 class Barcode : public Acts::MultiIndex<uint64_t, 12, 12, 16, 8, 16> {
96 
97  public:
98  using Base::Base;
99  using Base::Value;
100 
101  // Construct an invalid barcode with all levels set to zero.
102  Barcode() : Base(Base::Zeros()) {}
103  Barcode(const Barcode&) = default;
104  Barcode(Barcode&&) = default;
105  Barcode& operator=(const Barcode&) = default;
106  Barcode& operator=(Barcode&&) = default;
107 
109  constexpr Value vertexPrimary() const { return level(0); }
111  constexpr Value vertexSecondary() const { return level(1); }
113  constexpr Value particle() const { return level(2); }
115  constexpr Value generation() const { return level(3); }
117  constexpr Value subParticle() const { return level(4); }
118 
120  constexpr Barcode& setVertexPrimary(Value id) { return set(0, id), *this; }
122  constexpr Barcode& setVertexSecondary(Value id) { return set(1, id), *this; }
124  constexpr Barcode& setParticle(Value id) { return set(2, id), *this; }
126  constexpr Barcode& setGeneration(Value id) { return set(3, id), *this; }
128  constexpr Barcode& setSubParticle(Value id) { return set(4, id), *this; }
129 
133  Barcode makeDescendant(Value sub = 0u) const {
134  return Barcode(*this).setGeneration(generation() + 1).setSubParticle(sub);
135  }
136 };
137 
138 } // namespace ActsFatras
139 
140 // specialize std::hash so Barcode can be used e.g. in an unordered_map
141 namespace std {
142 template <>
143 struct hash<ActsFatras::Barcode> {
144  auto operator()(ActsFatras::Barcode barcode) const noexcept {
145  return std::hash<ActsFatras::Barcode::Value>()(barcode.value());
146  }
147 };
148 } // namespace std