Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/Acts/EventData/TrackStateType.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 #include <bitset>
0012 #include <cassert>
0013 #include <cstddef>
0014 #include <cstdint>
0015 #include <limits>
0016 #include <ostream>
0017 #include <type_traits>
0018 
0019 namespace Acts {
0020 
0021 /// @enum TrackStateFlag
0022 ///
0023 /// This enum describes the type of TrackState
0024 enum TrackStateFlag {
0025   MeasurementFlag = 0,
0026   ParameterFlag = 1,
0027   OutlierFlag = 2,
0028   HoleFlag = 3,
0029   MaterialFlag = 4,
0030   SharedHitFlag = 5,
0031   SplitHitFlag = 6,
0032   NoExpectedHitFlag = 7,
0033   NumTrackStateFlags = 8,
0034 };
0035 
0036 class ConstTrackStateType;
0037 
0038 /// View type over a bitset stored in a 64 bit integer
0039 /// This view allows modifications.
0040 class TrackStateType {
0041  public:
0042   /// Type alias for underlying raw data type
0043   using raw_type = std::uint64_t;
0044   /// Number of bits available in the raw storage type
0045   static constexpr std::size_t kRawBits =
0046       std::numeric_limits<std::make_unsigned_t<raw_type>>::digits;
0047 
0048   // Delete default constructor
0049   TrackStateType() = delete;
0050 
0051   /// Constructor from a reference to the underlying value container
0052   /// @param raw the value container
0053   explicit TrackStateType(raw_type& raw) : m_raw{&raw} {
0054     assert(m_raw != nullptr);
0055   }
0056 
0057   // Delete copy constructor
0058   TrackStateType(const TrackStateType&) = delete;
0059 
0060   // Delete move constructor
0061   TrackStateType(TrackStateType&&) = delete;
0062 
0063   // Disable assignment
0064   TrackStateType& operator=(const TrackStateType&) = delete;
0065 
0066   // Disable move assignment
0067   TrackStateType& operator=(TrackStateType&&) = delete;
0068 
0069   /// Assign the value from another set of flags
0070   /// @param other the other set of flags to assign
0071   /// @return this object
0072   TrackStateType& operator=(const ConstTrackStateType& other);
0073 
0074   /// Return if the bit at position @p pos is 1
0075   /// @param pos the bit position
0076   /// @return if the bit at @p pos is one or not
0077   bool test(std::size_t pos) const {
0078     std::bitset<kRawBits> bs{*m_raw};
0079     return bs.test(pos);
0080   }
0081 
0082   /// Change the value of the bit at position @p pos to @p value.
0083   /// @param pos the position of the bit to change
0084   /// @param value the value to change the bit to
0085   void set(std::size_t pos, bool value = true) {
0086     std::bitset<kRawBits> bs{*m_raw};
0087     bs.set(pos, value);
0088     *m_raw = bs.to_ullong();
0089   }
0090 
0091   /// Change the value of the bit at position at @p pos to @c false
0092   /// @param pos the position of the bit to change
0093   void reset(std::size_t pos) { set(pos, false); }
0094 
0095   friend std::ostream& operator<<(std::ostream& os, const TrackStateType& t) {
0096     std::bitset<kRawBits> bs{*t.m_raw};
0097     std::bitset<TrackStateFlag::NumTrackStateFlags> trunc;
0098     for (std::size_t i = 0; i < TrackStateFlag::NumTrackStateFlags; i++) {
0099       trunc[i] = bs[i];
0100     }
0101     // SharedhitMaterialHoleOutlierParameterMeasurement
0102     os << "SMHOPM=" << trunc;
0103     return os;
0104   }
0105 
0106  private:
0107   raw_type* m_raw{nullptr};
0108 };
0109 
0110 /// View type over a bitset stored in a 64 bit integer
0111 /// This view does not allow modifications
0112 class ConstTrackStateType {
0113  public:
0114   /// Type alias for underlying raw storage type (64-bit unsigned integer)
0115   using raw_type = std::uint64_t;
0116   /// Number of bits available in the raw storage type
0117   static constexpr std::size_t kRawBits =
0118       std::numeric_limits<std::make_unsigned_t<raw_type>>::digits;
0119 
0120   // Delete default constructor
0121   ConstTrackStateType() = delete;
0122 
0123   /// Constructor from a reference to the underlying value container
0124   /// @param raw the value container
0125   explicit ConstTrackStateType(const raw_type& raw) : m_raw{&raw} {
0126     assert(m_raw != nullptr);
0127   }
0128 
0129   // Disable copy constructor
0130   ConstTrackStateType(const ConstTrackStateType& other) = delete;
0131 
0132   // Delete move constructor
0133   ConstTrackStateType(ConstTrackStateType&& other) = delete;
0134 
0135   // Disable assignment
0136   ConstTrackStateType& operator=(const ConstTrackStateType&) = delete;
0137 
0138   // Disable move assignment
0139   ConstTrackStateType& operator=(ConstTrackStateType&&) = delete;
0140 
0141   /// Return if the bit at position @p pos is 1
0142   /// @param pos the bit position
0143   /// @return if the bit at @p pos is one or not
0144   bool test(std::size_t pos) const {
0145     std::bitset<kRawBits> bs{*m_raw};
0146     return bs.test(pos);
0147   }
0148 
0149   friend std::ostream& operator<<(std::ostream& os,
0150                                   const ConstTrackStateType& t) {
0151     std::bitset<kRawBits> bs{*t.m_raw};
0152     std::bitset<TrackStateFlag::NumTrackStateFlags> trunc;
0153     for (std::size_t i = 0; i < TrackStateFlag::NumTrackStateFlags; i++) {
0154       trunc[i] = bs[i];
0155     }
0156     // SharedhitMaterialHoleOutlierParameterMeasurement
0157     os << "SMHOPM=" << trunc;
0158     return os;
0159   }
0160 
0161  private:
0162   friend class TrackStateType;
0163   const raw_type* m_raw{nullptr};
0164 };
0165 
0166 inline TrackStateType& TrackStateType::operator=(
0167     const ConstTrackStateType& other) {
0168   *m_raw = *other.m_raw;
0169   return *this;
0170 }
0171 
0172 }  // namespace Acts