Back to home page

EIC code displayed by LXR

 
 

    


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

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   /// Invalidates all iterators.
0186   void clear() final;
0187 
0188   /// Cppyy protocol to setup the pythonizations for this class. Not to be
0189   /// called directly.
0190   static void __cppjit_pythonize__(PyObject* klass, const std::string& name) {
0191     podio::detail::pythonizations::pythonize_subscript(klass, name);
0192   }
0193   /// Pythonizations for ROOT <= 6.40 before the switch to cppjit
0194   static void __cppyy_pythonize__(PyObject* klass, const std::string& name) {
0195     __cppjit_pythonize__(klass, name);
0196   }
0197 
0198   /// Print this collection to the passed stream
0199   void print(std::ostream& os = std::cout, bool flush = true) const final;
0200 
0201   /// Append a new object to the collection, and return this object.
0202   /// Does not invalidate iterators.
0203   MutableTrack create();
0204 
0205   /// Append a new object to the collection, and return this object.
0206   /// Initialized with the parameters given.
0207   /// Does not invalidate iterators.
0208   template <typename... Args>
0209   MutableTrack create(Args&&... args);
0210 
0211   /// number of elements in the collection
0212   std::size_t size() const final;
0213 
0214   /// maximal number of elements in the collection
0215   std::size_t max_size() const final;
0216 
0217   /// Is the collection empty
0218   bool empty() const final;
0219 
0220   /// fully qualified type name
0221   const std::string_view getTypeName() const final { return typeName; }
0222   /// fully qualified type name of elements - with namespace
0223   const std::string_view getValueTypeName() const final {
0224     return valueTypeName;
0225   }
0226   /// fully qualified type name of stored POD elements - with namespace
0227   const std::string_view getDataTypeName() const final { return dataTypeName; }
0228   /// schema version
0229   podio::SchemaVersionT getSchemaVersion() const final;
0230 
0231   bool isSubsetCollection() const final { return m_isSubsetColl; }
0232 
0233   void setSubsetCollection(bool setSubset = true) final;
0234 
0235   /// Returns the const object of given index
0236   Track operator[](std::size_t index) const;
0237   /// Returns the object of a given index
0238   MutableTrack operator[](std::size_t index);
0239   /// Returns the const object of given index
0240   Track at(std::size_t index) const;
0241   /// Returns the object of given index
0242   MutableTrack at(std::size_t index);
0243 
0244   /// Append object to the collection.
0245   /// Does not invalidate iterators.
0246   void push_back(const MutableTrack& object);
0247   /// Append an object to the (subset) collection.
0248   /// Does not invalidate iterators.
0249   void push_back(const Track& object);
0250 
0251   void prepareForWrite() const final;
0252   void prepareAfterRead() final;
0253   bool setReferences(
0254       const podio::ICollectionProvider* collectionProvider) final;
0255 
0256   /// Get the collection buffers for this collection
0257   podio::CollectionWriteBuffers getBuffers() final;
0258 
0259   void setID(uint32_t ID) final {
0260     m_collectionID = ID;
0261     if (!m_isSubsetColl) {
0262       std::for_each(m_storage.entries.begin(), m_storage.entries.end(),
0263                     [ID](TrackObj* obj) {
0264                       obj->id = {obj->id.index, static_cast<uint32_t>(ID)};
0265                     });
0266     }
0267   }
0268 
0269   uint32_t getID() const final { return m_collectionID; }
0270 
0271   /// check if the collection has a valid ID
0272   bool hasID() const final {
0273     return getID() != static_cast<uint32_t>(podio::ObjectID::untracked) &&
0274            getID() != static_cast<uint32_t>(podio::ObjectID::invalid);
0275   }
0276 
0277   size_t getDatamodelRegistryIndex() const final;
0278 
0279   // support for the iterator protocol
0280   iterator begin() { return iterator(0, &m_storage.entries); }
0281   const_iterator begin() const { return const_iterator(0, &m_storage.entries); }
0282   const_iterator cbegin() const { return begin(); }
0283   iterator end() {
0284     return iterator(m_storage.entries.size(), &m_storage.entries);
0285   }
0286   const_iterator end() const {
0287     return const_iterator(m_storage.entries.size(), &m_storage.entries);
0288   }
0289   const_iterator cend() const { return end(); }
0290   // reverse iterators
0291   reverse_iterator rbegin() { return reverse_iterator(end()); }
0292   const_reverse_iterator rbegin() const {
0293     return const_reverse_iterator(end());
0294   }
0295   const_reverse_iterator crbegin() const { return rbegin(); }
0296   reverse_iterator rend() { return reverse_iterator(begin()); }
0297   const_reverse_iterator rend() const {
0298     return const_reverse_iterator(begin());
0299   }
0300   const_reverse_iterator crend() const { return rend(); }
0301 
0302   std::vector<ActsPodioEdm::TrackInfo> data(const size_t nElem = 0) const;
0303   std::vector<ActsPodioEdm::Surface> referenceSurface(
0304       const size_t nElem = 0) const;
0305   std::vector<ActsPodioEdm::ParticleHypothesis> particleHypothesis(
0306       const size_t nElem = 0) const;
0307 
0308  private:
0309   // For setReferences, we need to give our own CollectionData access to our
0310   // private entries. Otherwise we would need to expose a public member function
0311   // that gives access to the Obj* which is definitely not what we want
0312   friend class TrackCollectionData;
0313 
0314   mutable bool m_isPrepared{false};
0315   bool m_isSubsetColl{false};
0316   uint32_t m_collectionID{static_cast<uint32_t>(podio::ObjectID::untracked)};
0317   mutable std::unique_ptr<std::mutex> m_storageMtx{
0318       std::make_unique<std::mutex>()};
0319   mutable TrackCollectionData m_storage{};
0320 };
0321 
0322 std::ostream& operator<<(std::ostream& o, const TrackCollection& v);
0323 
0324 template <typename... Args>
0325 MutableTrack TrackCollection::create(Args&&... args) {
0326   if (m_isSubsetColl) {
0327     throw std::logic_error("Cannot create new elements on a subset collection");
0328   }
0329   auto obj =
0330       new TrackObj({static_cast<int>(m_storage.entries.size()), m_collectionID},
0331                    {std::forward<Args>(args)...});
0332   m_storage.entries.push_back(obj);
0333 
0334   return MutableTrack(podio::utils::MaybeSharedPtr(obj));
0335 }
0336 
0337 #if defined(__cpp_lib_containers_ranges)
0338 template <podio::detail::RangeConvertibleTo<TrackCollection::value_type> R>
0339 TrackCollection::TrackCollection(std::from_range_t, R&& range)
0340     : TrackCollection() {
0341   setSubsetCollection(podio::detail::RangeOf<R, value_type>);
0342 
0343   for (auto&& elem : range) {
0344     push_back(std::forward<decltype(elem)>(elem));
0345   }
0346 }
0347 #endif
0348 
0349 template <podio::detail::RangeConvertibleTo<TrackCollection::value_type> R>
0350 TrackCollection TrackCollection::from(R&& range) {
0351   TrackCollection coll;
0352   if constexpr (podio::detail::RangeOf<R, value_type>) {
0353     coll.setSubsetCollection();
0354   }
0355 
0356   for (auto&& elem : range) {
0357     coll.push_back(std::forward<decltype(elem)>(elem));
0358   }
0359 
0360   return coll;
0361 }
0362 
0363 #if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
0364 void to_json(nlohmann::json& j, const TrackCollection& collection);
0365 #endif
0366 
0367 }  // namespace ActsPodioEdm
0368 
0369 // This is needed to avoid triggering opening every library in LD_LIBRARY_PATH
0370 // until it's fixed in ROOT. See
0371 // https://github.com/root-project/root/issues/18489 and
0372 // https://github.com/AIDASoft/podio/issues/770
0373 #if defined(__clang__)
0374 #pragma clang diagnostic push
0375 #pragma clang diagnostic ignored "-Wunknown-warning-option"
0376 #pragma clang diagnostic ignored "-Wdeprecated-redundant-constexpr-static-def"
0377 #pragma clang diagnostic ignored "-Wdeprecated"
0378 constexpr std::string_view ActsPodioEdm::TrackCollection::typeName;
0379 constexpr std::string_view ActsPodioEdm::TrackCollection::valueTypeName;
0380 constexpr std::string_view ActsPodioEdm::TrackCollection::dataTypeName;
0381 #pragma clang diagnostic pop
0382 #elif defined(__GNUC__)
0383 #pragma GCC diagnostic push
0384 #pragma GCC diagnostic ignored "-Wdeprecated"
0385 constexpr std::string_view ActsPodioEdm::TrackCollection::typeName;
0386 constexpr std::string_view ActsPodioEdm::TrackCollection::valueTypeName;
0387 constexpr std::string_view ActsPodioEdm::TrackCollection::dataTypeName;
0388 #pragma GCC diagnostic pop
0389 #endif
0390 
0391 #endif