Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-07 04:35:57

0001 // -*- c++ -*-
0002 #ifndef DataFormats_SiPixelCluster_SiPixelClusterShapeData_h
0003 #define DataFormats_SiPixelCluster_SiPixelClusterShapeData_h
0004 
0005 #include "DataFormats/Provenance/interface/ProductID.h"
0006 #include "DataFormats/Common/interface/HandleBase.h"
0007 #include "DataFormats/Common/interface/Ref.h"
0008 #include "DataFormats/Common/interface/DetSetVectorNew.h"
0009 #include "DataFormats/SiPixelCluster/interface/SiPixelCluster.h"
0010 
0011 #include <utility>
0012 #include <vector>
0013 #include <algorithm>
0014 #include <cassert>
0015 #include <memory>
0016 
0017 class PixelGeomDetUnit;
0018 
0019 class SiPixelClusterShapeData {
0020 public:
0021   typedef std::vector<std::pair<int, int> >::const_iterator const_iterator;
0022   typedef std::pair<const_iterator, const_iterator> Range;
0023   SiPixelClusterShapeData(
0024       const_iterator begin, const_iterator end, bool isStraight, bool isComplete, bool hasBigPixelsOnlyInside)
0025       : begin_(begin),
0026         end_(end),
0027         isStraight_(isStraight),
0028         isComplete_(isComplete),
0029         hasBigPixelsOnlyInside_(hasBigPixelsOnlyInside) {}
0030   ~SiPixelClusterShapeData();
0031 
0032   Range size() const { return std::make_pair(begin_, end_); }
0033 
0034   bool isStraight() const { return isStraight_; }
0035   bool isComplete() const { return isComplete_; }
0036   bool hasBigPixelsOnlyInside() const { return hasBigPixelsOnlyInside_; }
0037 
0038 private:
0039   const_iterator begin_, end_;
0040   const bool isStraight_, isComplete_, hasBigPixelsOnlyInside_;
0041 };
0042 
0043 class SiPixelClusterShapeCache {
0044 public:
0045   typedef edm::Ref<edmNew::DetSetVector<SiPixelCluster>, SiPixelCluster> ClusterRef;
0046 
0047   struct Field {
0048     Field() : offset(0), size(0), straight(false), complete(false), has(false), filled(false) {}
0049 
0050     Field(unsigned off, unsigned siz, bool s, bool c, bool h)
0051         : offset(off), size(siz), straight(s), complete(c), has(h), filled(true) {}
0052     unsigned offset : 24;  // room for 2^24/9 = ~1.8e6 clusters, should be enough
0053     unsigned size : 4;     // max 9 elements / cluster (2^4-1=15)
0054     unsigned straight : 1;
0055     unsigned complete : 1;
0056     unsigned has : 1;
0057     unsigned filled : 1;
0058   };
0059 
0060   SiPixelClusterShapeCache() {}
0061   explicit SiPixelClusterShapeCache(const edm::HandleBase& handle) : productId_(handle.id()) {}
0062   explicit SiPixelClusterShapeCache(const edm::ProductID& id) : productId_(id) {}
0063   ~SiPixelClusterShapeCache();
0064 
0065   void resize(size_t size) {
0066     data_.resize(size);
0067     sizeData_.reserve(size);
0068   }
0069 
0070   void swap(SiPixelClusterShapeCache& other) {
0071     data_.swap(other.data_);
0072     sizeData_.swap(other.sizeData_);
0073     std::swap(productId_, other.productId_);
0074   }
0075 
0076 #if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__REFLEX__)
0077   void shrink_to_fit() {
0078     data_.shrink_to_fit();
0079     sizeData_.shrink_to_fit();
0080   }
0081 
0082   template <typename T>
0083   void insert(const ClusterRef& cluster, const T& data) {
0084     static_assert(T::ArrayType::capacity() <= 15, "T::ArrayType::capacity() more than 15, bit field too narrow");
0085     checkRef(cluster);
0086 
0087     data_[cluster.index()] =
0088         Field(sizeData_.size(), data.size.size(), data.isStraight, data.isComplete, data.hasBigPixelsOnlyInside);
0089     std::copy(data.size.begin(), data.size.end(), std::back_inserter(sizeData_));
0090   }
0091 
0092   bool isFilled(const ClusterRef& cluster) const {
0093     checkRef(cluster);
0094     return data_[cluster.index()].filled;
0095   }
0096 
0097   SiPixelClusterShapeData get(const ClusterRef& cluster, const PixelGeomDetUnit* pixDet) const {
0098     checkRef(cluster);
0099     Field f = data_[cluster.index()];
0100     assert(f.filled);
0101 
0102     auto beg = sizeData_.begin() + f.offset;
0103     auto end = beg + f.size;
0104 
0105     return SiPixelClusterShapeData(beg, end, f.straight, f.complete, f.has);
0106   }
0107 #endif
0108 
0109 private:
0110   void checkRef(const ClusterRef& cluster) const;
0111 
0112   std::vector<Field> data_;
0113   std::vector<std::pair<int, int> > sizeData_;
0114   edm::ProductID productId_;
0115 };
0116 
0117 #endif