Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-02 08:37:59

0001 // AUTOMATICALLY GENERATED FILE - DO NOT EDIT
0002 
0003 #ifndef ACTSPODIOEDM_TrackCollection_H
0004 #define ACTSPODIOEDM_TrackCollection_H
0005 
0006 // datamodel specific includes
0007 #include "ActsPodioEdm/MutableTrack.h"
0008 #include "ActsPodioEdm/Track.h"
0009 #include "ActsPodioEdm/TrackCollectionData.h"
0010 #include "ActsPodioEdm/TrackObj.h"
0011 
0012 // podio specific includes
0013 #include "podio/CollectionBase.h"
0014 #include "podio/ICollectionProvider.h"
0015 #include "podio/detail/Pythonizations.h"
0016 #include "podio/utilities/TypeHelpers.h"
0017 
0018 #if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
0019 #include "nlohmann/json_fwd.hpp"
0020 #endif
0021 
0022 #include <algorithm>
0023 #include <cstddef>
0024 #include <memory>
0025 #include <mutex>
0026 #include <ostream>
0027 #include <string_view>
0028 #include <vector>
0029 
0030 namespace podio {
0031 struct RelationNames;
0032 }
0033 
0034 namespace ActsPodioEdm {
0035 
0036 class TrackCollectionIterator {
0037  public:
0038   using value_type = Track;
0039   using difference_type = ptrdiff_t;
0040   using reference = Track;
0041   using pointer = Track*;
0042   using iterator_category = std::input_iterator_tag;
0043   // `std::forward_iterator` is supported except that the pointers obtained with
0044   // `operator->()` remain valid as long as the iterator is valid, not as long
0045   // as the range is valid.
0046   using iterator_concept = std::random_access_iterator_tag;
0047 
0048   TrackCollectionIterator(size_t index,
0049                           const TrackObjPointerContainer* collection)
0050       : m_index(index),
0051         m_object(podio::utils::MaybeSharedPtr<TrackObj>{nullptr}),
0052         m_collection(collection) {}
0053   TrackCollectionIterator() = default;
0054 
0055   TrackCollectionIterator(const TrackCollectionIterator&) = default;
0056   TrackCollectionIterator(TrackCollectionIterator&&) = default;
0057   TrackCollectionIterator& operator=(const TrackCollectionIterator&) = default;
0058   TrackCollectionIterator& operator=(TrackCollectionIterator&&) = default;
0059   ~TrackCollectionIterator() = default;
0060 
0061   constexpr auto operator<=>(const TrackCollectionIterator& other) const {
0062     return m_index <=> other.m_index;
0063   }
0064 
0065   constexpr bool operator==(const TrackCollectionIterator& x) const {
0066     return m_index == x.m_index;
0067   }
0068 
0069   reference operator*() const;
0070   pointer operator->();
0071   TrackCollectionIterator& operator++();
0072   TrackCollectionIterator operator++(int);
0073   TrackCollectionIterator& operator--();
0074   TrackCollectionIterator operator--(int);
0075   TrackCollectionIterator& operator+=(difference_type n);
0076   TrackCollectionIterator operator+(difference_type n) const;
0077   friend TrackCollectionIterator operator+(difference_type n,
0078                                            const TrackCollectionIterator& it);
0079   TrackCollectionIterator& operator-=(difference_type n);
0080   TrackCollectionIterator operator-(difference_type n) const;
0081   reference operator[](difference_type n) const;
0082   difference_type operator-(const TrackCollectionIterator& other) const;
0083 
0084  private:
0085   size_t m_index{0};
0086   Track m_object{podio::utils::MaybeSharedPtr<TrackObj>{nullptr}};
0087   const TrackObjPointerContainer* m_collection{nullptr};
0088 };
0089 
0090 class TrackMutableCollectionIterator {
0091  public:
0092   using value_type = Track;
0093   using difference_type = ptrdiff_t;
0094   using reference = MutableTrack;
0095   using pointer = MutableTrack*;
0096   using iterator_category = std::input_iterator_tag;
0097   // `std::forward_iterator` is supported except that the pointers obtained with
0098   // `operator->()` remain valid as long as the iterator is valid, not as long
0099   // as the range is valid.
0100   using iterator_concept = std::random_access_iterator_tag;
0101 
0102   TrackMutableCollectionIterator(size_t index,
0103                                  const TrackObjPointerContainer* collection)
0104       : m_index(index),
0105         m_object(podio::utils::MaybeSharedPtr<TrackObj>{nullptr}),
0106         m_collection(collection) {}
0107   TrackMutableCollectionIterator() = default;
0108 
0109   TrackMutableCollectionIterator(const TrackMutableCollectionIterator&) =
0110       default;
0111   TrackMutableCollectionIterator(TrackMutableCollectionIterator&&) = default;
0112   TrackMutableCollectionIterator& operator=(
0113       const TrackMutableCollectionIterator&) = default;
0114   TrackMutableCollectionIterator& operator=(TrackMutableCollectionIterator&&) =
0115       default;
0116   ~TrackMutableCollectionIterator() = default;
0117 
0118   constexpr auto operator<=>(
0119       const TrackMutableCollectionIterator& other) const {
0120     return m_index <=> other.m_index;
0121   }
0122 
0123   constexpr bool operator==(const TrackMutableCollectionIterator& x) const {
0124     return m_index == x.m_index;
0125   }
0126 
0127   reference operator*() const;
0128   pointer operator->();
0129   TrackMutableCollectionIterator& operator++();
0130   TrackMutableCollectionIterator operator++(int);
0131   TrackMutableCollectionIterator& operator--();
0132   TrackMutableCollectionIterator operator--(int);
0133   TrackMutableCollectionIterator& operator+=(difference_type n);
0134   TrackMutableCollectionIterator operator+(difference_type n) const;
0135   friend TrackMutableCollectionIterator operator+(
0136       difference_type n, const TrackMutableCollectionIterator& it);
0137   TrackMutableCollectionIterator& operator-=(difference_type n);
0138   TrackMutableCollectionIterator operator-(difference_type n) const;
0139   reference operator[](difference_type n) const;
0140   difference_type operator-(const TrackMutableCollectionIterator& other) const;
0141 
0142  private:
0143   size_t m_index{0};
0144   MutableTrack m_object{podio::utils::MaybeSharedPtr<TrackObj>{nullptr}};
0145   const TrackObjPointerContainer* m_collection{nullptr};
0146 };
0147 
0148 /**
0149 A Collection is identified by an ID.
0150 */
0151 class TrackCollection : public podio::CollectionBase {
0152  public:
0153   using value_type = Track;
0154   using mutable_type = MutableTrack;
0155   using const_iterator = TrackCollectionIterator;
0156   using iterator = TrackMutableCollectionIterator;
0157   using difference_type = ptrdiff_t;
0158   using size_type = size_t;
0159   using const_reverse_iterator = std::reverse_iterator<const_iterator>;
0160   using reverse_iterator = std::reverse_iterator<iterator>;
0161 
0162   TrackCollection() = default;
0163   TrackCollection(TrackCollectionData&& data, bool isSubsetColl);
0164   // This is a move-only type
0165   TrackCollection(const TrackCollection&) = delete;
0166   TrackCollection& operator=(const TrackCollection&) = delete;
0167   TrackCollection(TrackCollection&&) = default;
0168   TrackCollection& operator=(TrackCollection&&) = default;
0169 
0170   ~TrackCollection() override;
0171 #if defined(__cpp_lib_containers_ranges)
0172   template <podio::detail::RangeConvertibleTo<value_type> R>
0173   TrackCollection(std::from_range_t, R&& range);
0174 #endif
0175 
0176   /// Construct a Track collection from a range of mutable or
0177   /// immutable handles
0178   template <podio::detail::RangeConvertibleTo<value_type> R>
0179   static TrackCollection from(R&& range);
0180 
0181   constexpr static std::string_view typeName = "ActsPodioEdm::TrackCollection";
0182   constexpr static std::string_view valueTypeName = "ActsPodioEdm::Track";
0183   constexpr static std::string_view dataTypeName = "ActsPodioEdm::TrackData";
0184 
0185   void clear() final;
0186 
0187   /// Cppyy protocol to setup the pythonizations for this class. Not to be
0188   /// called directly.
0189   static void __cppyy_pythonize__(PyObject* klass, const std::string& name) {
0190     podio::detail::pythonizations::pythonize_subscript(klass, name);
0191   }
0192 
0193   /// Print this collection to the passed stream
0194   void print(std::ostream& os = std::cout, bool flush = true) const final;
0195 
0196   /// Append a new object to the collection, and return this object.
0197   MutableTrack create();
0198 
0199   /// Append a new object to the collection, and return this object.
0200   /// Initialized with the parameters given
0201   template <typename... Args>
0202   MutableTrack create(Args&&... args);
0203 
0204   /// number of elements in the collection
0205   std::size_t size() const final;
0206 
0207   /// maximal number of elements in the collection
0208   std::size_t max_size() const final;
0209 
0210   /// Is the collection empty
0211   bool empty() const final;
0212 
0213   /// fully qualified type name
0214   const std::string_view getTypeName() const final { return typeName; }
0215   /// fully qualified type name of elements - with namespace
0216   const std::string_view getValueTypeName() const final {
0217     return valueTypeName;
0218   }
0219   /// fully qualified type name of stored POD elements - with namespace
0220   const std::string_view getDataTypeName() const final { return dataTypeName; }
0221   /// schema version
0222   podio::SchemaVersionT getSchemaVersion() const final;
0223 
0224   bool isSubsetCollection() const final { return m_isSubsetColl; }
0225 
0226   void setSubsetCollection(bool setSubset = true) final;
0227 
0228   /// Returns the const object of given index
0229   Track operator[](std::size_t index) const;
0230   /// Returns the object of a given index
0231   MutableTrack operator[](std::size_t index);
0232   /// Returns the const object of given index
0233   Track at(std::size_t index) const;
0234   /// Returns the object of given index
0235   MutableTrack at(std::size_t index);
0236 
0237   /// Append object to the collection
0238   void push_back(const MutableTrack& object);
0239   /// Append an object to the (subset) collection
0240   void push_back(const Track& object);
0241 
0242   void prepareForWrite() const final;
0243   void prepareAfterRead() final;
0244   bool setReferences(
0245       const podio::ICollectionProvider* collectionProvider) final;
0246 
0247   /// Get the collection buffers for this collection
0248   podio::CollectionWriteBuffers getBuffers() final;
0249 
0250   void setID(uint32_t ID) final {
0251     m_collectionID = ID;
0252     if (!m_isSubsetColl) {
0253       std::for_each(m_storage.entries.begin(), m_storage.entries.end(),
0254                     [ID](TrackObj* obj) {
0255                       obj->id = {obj->id.index, static_cast<uint32_t>(ID)};
0256                     });
0257     }
0258   }
0259 
0260   uint32_t getID() const final { return m_collectionID; }
0261 
0262   /// check if the collection has a valid ID
0263   bool hasID() const final {
0264     return getID() != static_cast<uint32_t>(podio::ObjectID::untracked) &&
0265            getID() != static_cast<uint32_t>(podio::ObjectID::invalid);
0266   }
0267 
0268   [[deprecated(
0269       "isValid will be removed, use hasID() if you want to check if it has an "
0270       "ID, otherwise assume the "
0271       "collection is valid")]]
0272   bool isValid() const final {
0273     return hasID();
0274   }
0275 
0276   size_t getDatamodelRegistryIndex() const final;
0277 
0278   // support for the iterator protocol
0279   iterator begin() { return iterator(0, &m_storage.entries); }
0280   const_iterator begin() const { return const_iterator(0, &m_storage.entries); }
0281   const_iterator cbegin() const { return begin(); }
0282   iterator end() {
0283     return iterator(m_storage.entries.size(), &m_storage.entries);
0284   }
0285   const_iterator end() const {
0286     return const_iterator(m_storage.entries.size(), &m_storage.entries);
0287   }
0288   const_iterator cend() const { return end(); }
0289   // reverse iterators
0290   reverse_iterator rbegin() { return reverse_iterator(end()); }
0291   const_reverse_iterator rbegin() const {
0292     return const_reverse_iterator(end());
0293   }
0294   const_reverse_iterator crbegin() const { return rbegin(); }
0295   reverse_iterator rend() { return reverse_iterator(begin()); }
0296   const_reverse_iterator rend() const {
0297     return const_reverse_iterator(begin());
0298   }
0299   const_reverse_iterator crend() const { return rend(); }
0300 
0301   std::vector<ActsPodioEdm::TrackInfo> data(const size_t nElem = 0) const;
0302   std::vector<ActsPodioEdm::Surface> referenceSurface(
0303       const size_t nElem = 0) const;
0304   std::vector<ActsPodioEdm::ParticleHypothesis> particleHypothesis(
0305       const size_t nElem = 0) const;
0306 
0307  private:
0308   // For setReferences, we need to give our own CollectionData access to our
0309   // private entries. Otherwise we would need to expose a public member function
0310   // that gives access to the Obj* which is definitely not what we want
0311   friend class TrackCollectionData;
0312 
0313   mutable bool m_isPrepared{false};
0314   bool m_isSubsetColl{false};
0315   uint32_t m_collectionID{static_cast<uint32_t>(podio::ObjectID::untracked)};
0316   mutable std::unique_ptr<std::mutex> m_storageMtx{
0317       std::make_unique<std::mutex>()};
0318   mutable TrackCollectionData m_storage{};
0319 };
0320 
0321 std::ostream& operator<<(std::ostream& o, const TrackCollection& v);
0322 
0323 template <typename... Args>
0324 MutableTrack TrackCollection::create(Args&&... args) {
0325   if (m_isSubsetColl) {
0326     throw std::logic_error("Cannot create new elements on a subset collection");
0327   }
0328   auto obj =
0329       new TrackObj({static_cast<int>(m_storage.entries.size()), m_collectionID},
0330                    {std::forward<Args>(args)...});
0331   m_storage.entries.push_back(obj);
0332 
0333   return MutableTrack(podio::utils::MaybeSharedPtr(obj));
0334 }
0335 
0336 #if defined(__cpp_lib_containers_ranges)
0337 template <podio::detail::RangeConvertibleTo<TrackCollection::value_type> R>
0338 TrackCollection::TrackCollection(std::from_range_t, R&& range)
0339     : TrackCollection() {
0340   setSubsetCollection(podio::detail::RangeOf<R, value_type>);
0341 
0342   for (auto&& elem : range) {
0343     push_back(std::forward<decltype(elem)>(elem));
0344   }
0345 }
0346 #endif
0347 
0348 template <podio::detail::RangeConvertibleTo<TrackCollection::value_type> R>
0349 TrackCollection TrackCollection::from(R&& range) {
0350   TrackCollection coll;
0351   if constexpr (podio::detail::RangeOf<R, value_type>) {
0352     coll.setSubsetCollection();
0353   }
0354 
0355   for (auto&& elem : range) {
0356     coll.push_back(std::forward<decltype(elem)>(elem));
0357   }
0358 
0359   return coll;
0360 }
0361 
0362 #if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
0363 void to_json(nlohmann::json& j, const TrackCollection& collection);
0364 #endif
0365 
0366 }  // namespace ActsPodioEdm
0367 
0368 // This is needed to avoid triggering opening every library in LD_LIBRARY_PATH
0369 // until it's fixed in ROOT. See
0370 // https://github.com/root-project/root/issues/18489 and
0371 // https://github.com/AIDASoft/podio/issues/770
0372 #if defined(__clang__)
0373 #pragma clang diagnostic push
0374 #pragma clang diagnostic ignored "-Wunknown-warning-option"
0375 #pragma clang diagnostic ignored "-Wdeprecated-redundant-constexpr-static-def"
0376 #pragma clang diagnostic ignored "-Wdeprecated"
0377 constexpr std::string_view ActsPodioEdm::TrackCollection::typeName;
0378 constexpr std::string_view ActsPodioEdm::TrackCollection::valueTypeName;
0379 constexpr std::string_view ActsPodioEdm::TrackCollection::dataTypeName;
0380 #pragma clang diagnostic pop
0381 #elif defined(__GNUC__)
0382 #pragma GCC diagnostic push
0383 #pragma GCC diagnostic ignored "-Wdeprecated"
0384 constexpr std::string_view ActsPodioEdm::TrackCollection::typeName;
0385 constexpr std::string_view ActsPodioEdm::TrackCollection::valueTypeName;
0386 constexpr std::string_view ActsPodioEdm::TrackCollection::dataTypeName;
0387 #pragma GCC diagnostic pop
0388 #endif
0389 
0390 #endif