Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:27:48

0001 #ifndef RecoTracker_TkHitPairs_RegionsSeedingHitSets_H
0002 #define RecoTracker_TkHitPairs_RegionsSeedingHitSets_H
0003 
0004 #include "RecoTracker/TkSeedingLayers/interface/SeedingHitSet.h"
0005 #include "RecoTracker/TkHitPairs/interface/IntermediateHitDoublets.h"
0006 
0007 /**
0008  * Class to store SeedingHitSets (doublet/triplet/quadruplet) per TrackingRegion
0009  *
0010  * Defined in this package instead of RecoTracker/TkSeedingLayers to avoid circular dependencies
0011  */
0012 class RegionsSeedingHitSets {
0013 public:
0014   /// Helper class containing a region and indices to hitSets_
0015   using RegionIndex = ihd::RegionIndex;
0016 
0017   /// Helper class providing nice interface to loop over hit sets of a region
0018   using RegionSeedingHitSets = ihd::RegionLayerSets<SeedingHitSet>;
0019 
0020   /// Iterator over regions
0021   using const_iterator = ihd::const_iterator<RegionSeedingHitSets, RegionsSeedingHitSets>;
0022 
0023   /// Helper class enforcing correct way of filling the doublets of a region
0024   class RegionFiller {
0025   public:
0026     RegionFiller() : obj_(nullptr) {}
0027     explicit RegionFiller(RegionsSeedingHitSets* obj) : obj_(obj) {}
0028 
0029     ~RegionFiller() {
0030       if (obj_)
0031         obj_->regions_.back().setLayerSetsEnd(obj_->hitSets_.size());
0032     }
0033 
0034     bool valid() const { return obj_ != nullptr; }
0035 
0036     template <typename... Args>
0037     void emplace_back(Args&&... args) {
0038       obj_->hitSets_.emplace_back(std::forward<Args>(args)...);
0039     }
0040 
0041   private:
0042     RegionsSeedingHitSets* obj_;
0043   };
0044 
0045   // allows declaring local variables with auto
0046   static RegionFiller dummyFiller() { return RegionFiller(); }
0047 
0048   // constructors
0049   RegionsSeedingHitSets() = default;
0050   RegionsSeedingHitSets(const RegionsSeedingHitSets&) = delete;
0051   RegionsSeedingHitSets& operator=(const RegionsSeedingHitSets&) = delete;
0052   RegionsSeedingHitSets(RegionsSeedingHitSets&&) = default;
0053   RegionsSeedingHitSets& operator=(RegionsSeedingHitSets&&) = default;
0054   ~RegionsSeedingHitSets() = default;
0055 
0056   void reserve(size_t nregions, size_t nhitsets) {
0057     regions_.reserve(nregions);
0058     hitSets_.reserve(nhitsets);
0059   }
0060 
0061   void shrink_to_fit() {
0062     regions_.shrink_to_fit();
0063     hitSets_.shrink_to_fit();
0064   }
0065 
0066   RegionFiller beginRegion(const TrackingRegion* region) {
0067     regions_.emplace_back(region, hitSets_.size());
0068     return RegionFiller(this);
0069   }
0070 
0071   bool empty() const { return regions_.empty(); }
0072   size_t regionSize() const { return regions_.size(); }
0073   size_t size() const { return hitSets_.size(); }
0074 
0075   const_iterator begin() const { return const_iterator(this, regions_.begin()); }
0076   const_iterator cbegin() const { return begin(); }
0077   const_iterator end() const { return const_iterator(this, regions_.end()); }
0078   const_iterator cend() const { return end(); }
0079 
0080   // used internally by the helper classes
0081   std::vector<SeedingHitSet>::const_iterator layerSetsBegin() const { return hitSets_.begin(); }
0082   std::vector<SeedingHitSet>::const_iterator layerSetsEnd() const { return hitSets_.end(); }
0083 
0084 private:
0085   std::vector<RegionIndex> regions_;    /// Container of regions, each element has indices pointing to hitSets_
0086   std::vector<SeedingHitSet> hitSets_;  /// Container of hit sets for all regions
0087 };
0088 
0089 #endif