File indexing completed on 2026-10-06 09:09:17
0001
0002
0003 #ifndef EDM4HEP_MutableTrack_H
0004 #define EDM4HEP_MutableTrack_H
0005
0006 #include "edm4hep/TrackObj.h"
0007
0008 #include "edm4hep/Track.h"
0009
0010 #include "edm4hep/TrackState.h"
0011 #include "edm4hep/TrackerHit.h"
0012 #include "podio/RelationRange.h"
0013 #include <algorithm>
0014 #include <cstdint>
0015 #include <optional>
0016 #include <ranges>
0017 #include <vector>
0018
0019 #include "podio/utilities/MaybeSharedPtr.h"
0020
0021 #include <cstdint>
0022
0023 #if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
0024 #include "nlohmann/json_fwd.hpp"
0025 #endif
0026
0027
0028 namespace edm4hep {
0029 class TrackCollection;
0030 }
0031
0032 namespace edm4hep {
0033
0034
0035
0036
0037
0038 class MutableTrack {
0039
0040 friend class TrackCollection;
0041 friend class TrackMutableCollectionIterator;
0042 friend class Track;
0043
0044 public:
0045 using object_type = Track;
0046 using collection_type = TrackCollection;
0047
0048
0049 MutableTrack() = default;
0050
0051
0052 MutableTrack(const std::int32_t type, const float chi2, const std::int32_t ndf, const std::int32_t Nholes);
0053
0054
0055 MutableTrack(const MutableTrack& other) = default;
0056
0057
0058 MutableTrack& operator=(MutableTrack other) &;
0059 MutableTrack&
0060 operator=(MutableTrack other) && = delete;
0061
0062
0063
0064 MutableTrack clone(bool cloneRelations = true) const;
0065
0066
0067 ~MutableTrack() = default;
0068
0069 public:
0070
0071 std::int32_t getType() const;
0072
0073
0074 float getChi2() const;
0075
0076
0077 std::int32_t getNdf() const;
0078
0079
0080 std::int32_t getNholes() const;
0081
0082
0083 void setType(const std::int32_t type);
0084
0085 std::int32_t& getType();
0086
0087
0088 void setChi2(const float chi2);
0089
0090 float& getChi2();
0091
0092
0093 void setNdf(const std::int32_t ndf);
0094
0095 std::int32_t& getNdf();
0096
0097
0098 void setNholes(const std::int32_t Nholes);
0099
0100 std::int32_t& getNholes();
0101
0102 void addToTrackerHits(const edm4hep::TrackerHit&);
0103 std::size_t trackerHits_size() const;
0104 edm4hep::TrackerHit getTrackerHits(std::size_t) const;
0105 std::vector<edm4hep::TrackerHit>::const_iterator trackerHits_begin() const;
0106 std::vector<edm4hep::TrackerHit>::const_iterator trackerHits_end() const;
0107 podio::RelationRange<edm4hep::TrackerHit> getTrackerHits() const;
0108 void addToTracks(const edm4hep::Track&);
0109 std::size_t tracks_size() const;
0110 edm4hep::Track getTracks(std::size_t) const;
0111 std::vector<edm4hep::Track>::const_iterator tracks_begin() const;
0112 std::vector<edm4hep::Track>::const_iterator tracks_end() const;
0113 podio::RelationRange<edm4hep::Track> getTracks() const;
0114 void addToSubdetectorHitNumbers(const std::int32_t&);
0115 std::size_t subdetectorHitNumbers_size() const;
0116 std::int32_t getSubdetectorHitNumbers(std::size_t) const;
0117 std::vector<std::int32_t>::const_iterator subdetectorHitNumbers_begin() const;
0118 std::vector<std::int32_t>::const_iterator subdetectorHitNumbers_end() const;
0119 podio::RelationRange<std::int32_t> getSubdetectorHitNumbers() const;
0120 void addToSubdetectorHoleNumbers(const std::int32_t&);
0121 std::size_t subdetectorHoleNumbers_size() const;
0122 std::int32_t getSubdetectorHoleNumbers(std::size_t) const;
0123 std::vector<std::int32_t>::const_iterator subdetectorHoleNumbers_begin() const;
0124 std::vector<std::int32_t>::const_iterator subdetectorHoleNumbers_end() const;
0125 podio::RelationRange<std::int32_t> getSubdetectorHoleNumbers() const;
0126 void addToTrackStates(const edm4hep::TrackState&);
0127 std::size_t trackStates_size() const;
0128 edm4hep::TrackState getTrackStates(std::size_t) const;
0129 std::vector<edm4hep::TrackState>::const_iterator trackStates_begin() const;
0130 std::vector<edm4hep::TrackState>::const_iterator trackStates_end() const;
0131 podio::RelationRange<edm4hep::TrackState> getTrackStates() const;
0132
0133
0134
0135
0136
0137 std::optional<edm4hep::TrackState> getTrackState(edm4hep::TrackState::Location location) const {
0138 const auto trackStates = getTrackStates();
0139 const auto it = std::ranges::find(trackStates, location, &edm4hep::TrackState::location);
0140 return it != trackStates.end() ? std::optional{*it} : std::nullopt;
0141 }
0142
0143
0144 [[deprecated("Use getTrackState(edm4hep::TrackState::Location) instead")]] std::optional<edm4hep::TrackState>
0145 getTrackState(std::int32_t location) const {
0146 return getTrackState(static_cast<edm4hep::TrackState::Location>(location));
0147 }
0148
0149
0150
0151
0152 edm4hep::TrackState getTrackStates(edm4hep::TrackState::Location) const = delete;
0153
0154
0155 bool isAvailable() const;
0156
0157 void unlink() { m_obj = podio::utils::MaybeSharedPtr<TrackObj>{nullptr}; }
0158
0159 constexpr bool operator==(const MutableTrack& other) const { return m_obj == other.m_obj; }
0160 bool operator==(const Track& other) const;
0161
0162 constexpr bool operator!=(const MutableTrack& other) const { return !(*this == other); }
0163 bool operator!=(const Track& other) const { return !(*this == other); }
0164
0165
0166 bool operator<(const MutableTrack& other) const {
0167 return podio::detail::getOrderKey(*this) < podio::detail::getOrderKey(other);
0168 }
0169
0170 podio::ObjectID id() const { return getObjectID(); }
0171
0172 const podio::ObjectID getObjectID() const;
0173
0174 friend std::hash<MutableTrack>;
0175
0176 friend void swap(MutableTrack& a, MutableTrack& b) {
0177 using std::swap;
0178 swap(a.m_obj, b.m_obj);
0179 }
0180
0181 private:
0182
0183 explicit MutableTrack(podio::utils::MaybeSharedPtr<TrackObj> obj);
0184
0185 podio::utils::MaybeSharedPtr<TrackObj> m_obj{new TrackObj{}, podio::utils::MarkOwned};
0186 };
0187
0188 #if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
0189 void to_json(nlohmann::json& j, const MutableTrack& value);
0190 #endif
0191
0192 }
0193
0194 template <>
0195 struct std::hash<edm4hep::MutableTrack> {
0196 std::size_t operator()(const edm4hep::MutableTrack& obj) const {
0197 return std::hash<edm4hep::TrackObj*>{}(obj.m_obj.get());
0198 }
0199 };
0200
0201 #endif