Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:53:58

0001 #ifndef BXVector_h
0002 #define BXVector_h
0003 
0004 // this class is an extension of std::vector
0005 // designed to store objects corresponding to several time-samples (BX)
0006 // the time sample is addressed by an integer index, eg. -1 to 1
0007 
0008 #include "DataFormats/Common/interface/FillView.h"
0009 #include "DataFormats/Common/interface/fillPtrVector.h"
0010 #include "DataFormats/Common/interface/setPtr.h"
0011 #include "DataFormats/Common/interface/traits.h"
0012 #include <vector>
0013 
0014 template <class T>
0015 class BXVector {
0016 public:
0017   typedef typename std::vector<T>::iterator iterator;
0018   typedef typename std::vector<T>::const_iterator const_iterator;
0019   typedef T value_type;
0020   typedef typename std::vector<T>::size_type size_type;
0021 
0022 public:
0023   // default ctor
0024   BXVector(unsigned size = 0,  // number of objects per BX
0025            int bxFirst = 0,    // first BX stored
0026            int bxLast = 0);    // last BX stored
0027 
0028   // copy ctor
0029   // BXVector ( const BXVector& vector );
0030 
0031   // dtor
0032   //~BXVector();
0033 
0034   // assignment operator (pass by value for exception safety)
0035   //BXVector operator=(BXVector vector );
0036 
0037   // the methods given below are a minimal set
0038   // other methods from the std::vector interface can be replicated as desired
0039 
0040   // set BX range
0041   void setBXRange(int bxFirst, int bxLast);
0042 
0043   // set size for a given BX
0044   void resize(int bx, unsigned size);
0045 
0046   // set size for all BXs
0047   void resizeAll(unsigned size);
0048 
0049   // add one BX to end of BXVector
0050   void addBX();
0051 
0052   // delete given bunch crossing
0053   void deleteBX(int bx);
0054 
0055   // get the first BX stored
0056   int getFirstBX() const;
0057 
0058   // get the last BX stored
0059   int getLastBX() const;
0060 
0061   // iterator access by BX
0062   const_iterator begin(int bx) const;
0063 
0064   // iterator access by BX
0065   const_iterator end(int bx) const;
0066 
0067   // get N objects for a given BX
0068   unsigned size(int bx) const;
0069 
0070   // get N objects for all BXs together
0071   unsigned size() const { return data_.size(); }
0072 
0073   // add element with given BX index
0074   void push_back(int bx, T object);
0075 
0076   // erase element with given location
0077   void erase(int bx, unsigned i);
0078 
0079   // insert element with given location
0080   void insert(int bx, unsigned i, T object);
0081 
0082   // clear entire BXVector
0083   void clear();
0084 
0085   // clear bx
0086   void clearBX(int bx);
0087 
0088   // access element
0089   const T& at(int bx, unsigned i) const;
0090 
0091   // set element
0092   void set(int bx, unsigned i, const T& object);
0093 
0094   // check if data has empty location
0095   bool isEmpty(int bx) const;
0096 
0097   // support looping over entire collection (note also that begin() is needed by edm::Ref)
0098   const_iterator begin() const { return data_.begin(); }
0099   const_iterator end() const { return data_.end(); }
0100   //int bx(const_iterator & iter) const; (potentially useful)
0101   unsigned int key(const_iterator& iter) const { return iter - begin(); }
0102 
0103   // array subscript operator (incited by TriggerSummaryProducerAOD::fillTriggerObject...)
0104   T& operator[](std::size_t i) { return data_[i]; }
0105   const T& operator[](std::size_t i) const { return data_[i]; }
0106 
0107   // edm::View support
0108   void fillView(edm::ProductID const& id, std::vector<void const*>& pointers, edm::FillViewHelperVector& helpers) const;
0109   // edm::Ptr support
0110   void setPtr(std::type_info const& toType, unsigned long index, void const*& ptr) const;
0111   void fillPtrVector(std::type_info const& toType,
0112                      std::vector<unsigned long> const& indices,
0113                      std::vector<void const*>& ptrs) const;
0114 
0115 private:
0116   // this method converts integer BX index into an unsigned index
0117   // used by the internal data representation
0118   unsigned indexFromBX(int bx) const;
0119   unsigned numBX() const { return 1 + static_cast<const unsigned>(bxLast_ - bxFirst_); }
0120 
0121 private:
0122   //  need to keep a record of the BX ranges
0123   // in order to convert from int BX to the unsigned index
0124   int bxFirst_;
0125   int bxLast_;
0126 
0127   /// internal data representation:
0128   // a flat vector is preferable from the persistency point of view
0129   // but handling the start/end points for each BX is more complex
0130   // a second vector is needed to store pointers into the first one
0131   std::vector<T> data_;
0132   std::vector<unsigned> itrs_;
0133 };
0134 
0135 #include "BXVector.impl"
0136 
0137 #endif