Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:28:56

0001 #ifndef RecoTracker_TkTrackingRegions_TrackingRegionsSeedingLayerSets_H
0002 #define RecoTracker_TkTrackingRegions_TrackingRegionsSeedingLayerSets_H
0003 
0004 #include "RecoTracker/TkTrackingRegions/interface/TrackingRegion.h"
0005 #include "TrackingTools/TransientTrackingRecHit/interface/SeedingLayerSetsHits.h"
0006 
0007 #include <vector>
0008 #include <memory>
0009 
0010 class TrackingRegionsSeedingLayerSets {
0011   class Element;
0012 
0013 public:
0014   class RegionLayers {
0015   public:
0016     using SeedingLayerSet = SeedingLayerSetsHits::SeedingLayerSet;
0017 
0018     RegionLayers(const Element* elem, const SeedingLayerSetsHits* seedingLayerSetsHits)
0019         : elem_(elem), seedingLayerSetsHits_(seedingLayerSetsHits) {}
0020 
0021     const TrackingRegion& region() const;
0022     std::vector<SeedingLayerSet> layerPairs() const;
0023 
0024   private:
0025     const Element* elem_;
0026     const SeedingLayerSetsHits* seedingLayerSetsHits_;
0027   };
0028 
0029   class const_iterator {
0030   public:
0031     using internal_iterator_type = std::vector<Element>::const_iterator;
0032     using value_type = RegionLayers;
0033     using difference_type = internal_iterator_type::difference_type;
0034 
0035     const_iterator(internal_iterator_type iter, const SeedingLayerSetsHits* seedingLayerSetsHits)
0036         : iter_(iter), seedingLayerSetsHits_(seedingLayerSetsHits) {}
0037 
0038     value_type operator*() const { return RegionLayers(&(*iter_), seedingLayerSetsHits_); }
0039     const_iterator& operator++() {
0040       ++iter_;
0041       return *this;
0042     }
0043     const_iterator operator++(int) {
0044       const_iterator clone(*this);
0045       ++(*this);
0046       return clone;
0047     }
0048 
0049     bool operator==(const const_iterator& other) const { return iter_ == other.iter_; }
0050     bool operator!=(const const_iterator& other) const { return !operator==(other); }
0051 
0052   private:
0053     internal_iterator_type iter_;
0054     const SeedingLayerSetsHits* seedingLayerSetsHits_;
0055   };
0056 
0057   TrackingRegionsSeedingLayerSets() = default;
0058   explicit TrackingRegionsSeedingLayerSets(const SeedingLayerSetsHits* seedingLayerSetsHits)
0059       : seedingLayerSetsHits_(seedingLayerSetsHits) {}
0060   ~TrackingRegionsSeedingLayerSets() = default;
0061   TrackingRegionsSeedingLayerSets(TrackingRegionsSeedingLayerSets const&) = delete;
0062   TrackingRegionsSeedingLayerSets& operator=(TrackingRegionsSeedingLayerSets const&) = delete;
0063   TrackingRegionsSeedingLayerSets(TrackingRegionsSeedingLayerSets&&) = default;
0064   TrackingRegionsSeedingLayerSets& operator=(TrackingRegionsSeedingLayerSets&&) = default;
0065 
0066   void reserve(size_t s) { regionLayers_.reserve(s); }
0067 
0068   // layerSets index points to a layer set within seedingLayerSetsHits_
0069   void emplace_back(std::unique_ptr<TrackingRegion>&& region,
0070                     std::vector<SeedingLayerSetsHits::LayerSetIndex>&& layerSets) {
0071     regionLayers_.emplace_back(std::move(region), std::move(layerSets));
0072   }
0073 
0074   void swap(TrackingRegionsSeedingLayerSets& other) {
0075     std::swap(seedingLayerSetsHits_, other.seedingLayerSetsHits_);
0076     regionLayers_.swap(other.regionLayers_);
0077   }
0078 
0079   const SeedingLayerSetsHits& seedingLayerSetsHits() const { return *seedingLayerSetsHits_; }
0080   size_t regionsSize() const { return regionLayers_.size(); }
0081 
0082   const_iterator begin() const { return const_iterator(regionLayers_.begin(), seedingLayerSetsHits_); }
0083   const_iterator cbegin() const { return begin(); }
0084   const_iterator end() const { return const_iterator(regionLayers_.end(), seedingLayerSetsHits_); }
0085   const_iterator cend() const { return end(); }
0086 
0087 private:
0088   class Element {
0089   public:
0090     Element(std::unique_ptr<TrackingRegion>&& region, std::vector<SeedingLayerSetsHits::LayerSetIndex>&& layerSets)
0091         : region_(std::move(region)), layerSets_(std::move(layerSets)) {}
0092     ~Element() = default;
0093     Element(Element const&) = delete;
0094     Element& operator=(Element const&) = delete;
0095     Element(Element&&) = default;
0096     Element& operator=(Element&&) = default;
0097 
0098     const TrackingRegion& region() const { return *region_; }
0099     const std::vector<SeedingLayerSetsHits::LayerSetIndex>& layerSets() const { return layerSets_; }
0100 
0101   private:
0102     std::unique_ptr<TrackingRegion> region_;
0103     std::vector<SeedingLayerSetsHits::LayerSetIndex> layerSets_;
0104   };
0105 
0106   const SeedingLayerSetsHits* seedingLayerSetsHits_ = nullptr;
0107   std::vector<Element> regionLayers_;
0108 };
0109 
0110 inline const TrackingRegion& TrackingRegionsSeedingLayerSets::RegionLayers::region() const { return elem_->region(); }
0111 
0112 inline std::vector<TrackingRegionsSeedingLayerSets::RegionLayers::SeedingLayerSet>
0113 TrackingRegionsSeedingLayerSets::RegionLayers::layerPairs() const {
0114   std::vector<SeedingLayerSet> ret;  // TODO: get rid of the vector with more boilerplate code (sigh)
0115 
0116   const auto& layerSets = elem_->layerSets();
0117   ret.reserve(layerSets.size());
0118   for (const auto& ind : layerSets) {
0119     ret.push_back((*seedingLayerSetsHits_)[ind]);
0120   }
0121   return ret;
0122 }
0123 
0124 #endif