CMS 3D CMS Logo

BXVector.h
Go to the documentation of this file.
1 #ifndef BXVector_h
2 #define BXVector_h
3 
4 // this class is an extension of std::vector
5 // designed to store objects corresponding to several time-samples (BX)
6 // the time sample is addressed by an integer index, eg. -1 to 1
7 
12 #include <vector>
13 
14 template <class T>
15 class BXVector {
16 public:
17  typedef typename std::vector<T>::iterator iterator;
18  typedef typename std::vector<T>::const_iterator const_iterator;
19  typedef T value_type;
21 
22 public:
23  // default ctor
24  BXVector(unsigned size = 0, // number of objects per BX
25  int bxFirst = 0, // first BX stored
26  int bxLast = 0); // last BX stored
27 
28  // copy ctor
29  // BXVector ( const BXVector& vector );
30 
31  // dtor
32  //~BXVector();
33 
34  // assignment operator (pass by value for exception safety)
35  //BXVector operator=(BXVector vector );
36 
37  // the methods given below are a minimal set
38  // other methods from the std::vector interface can be replicated as desired
39 
40  // set BX range
41  void setBXRange(int bxFirst, int bxLast);
42 
43  // set size for a given BX
44  void resize(int bx, unsigned size);
45 
46  // set size for all BXs
47  void resizeAll(unsigned size);
48 
49  // add one BX to end of BXVector
50  void addBX();
51 
52  // delete given bunch crossing
53  void deleteBX(int bx);
54 
55  // get the first BX stored
56  int getFirstBX() const;
57 
58  // get the last BX stored
59  int getLastBX() const;
60 
61  // iterator access by BX
62  const_iterator begin(int bx) const;
63 
64  // iterator access by BX
65  const_iterator end(int bx) const;
66 
67  // get N objects for a given BX
68  unsigned size(int bx) const;
69 
70  // get N objects for all BXs together
71  unsigned size() const { return data_.size(); }
72 
73  // add element with given BX index
74  void push_back(int bx, T object);
75 
76  // erase element with given location
77  void erase(int bx, unsigned i);
78 
79  // insert element with given location
80  void insert(int bx, unsigned i, T object);
81 
82  // clear entire BXVector
83  void clear();
84 
85  // clear bx
86  void clearBX(int bx);
87 
88  // access element
89  const T& at(int bx, unsigned i) const;
90 
91  // set element
92  void set(int bx, unsigned i, const T& object);
93 
94  // check if data has empty location
95  bool isEmpty(int bx) const;
96 
97  // support looping over entire collection (note also that begin() is needed by edm::Ref)
98  const_iterator begin() const { return data_.begin(); }
99  const_iterator end() const { return data_.end(); }
100  //int bx(const_iterator & iter) const; (potentially useful)
101  unsigned int key(const_iterator& iter) const { return iter - begin(); }
102 
103  // array subscript operator (incited by TriggerSummaryProducerAOD::fillTriggerObject...)
104  T& operator[](std::size_t i) { return data_[i]; }
105  const T& operator[](std::size_t i) const { return data_[i]; }
106 
107  // edm::View support
108  void fillView(edm::ProductID const& id, std::vector<void const*>& pointers, edm::FillViewHelperVector& helpers) const;
109  // edm::Ptr support
110  void setPtr(std::type_info const& toType, unsigned long index, void const*& ptr) const;
111  void fillPtrVector(std::type_info const& toType,
112  std::vector<unsigned long> const& indices,
113  std::vector<void const*>& ptrs) const;
114 
115 private:
116  // this method converts integer BX index into an unsigned index
117  // used by the internal data representation
118  unsigned indexFromBX(int bx) const;
119  unsigned numBX() const { return 1 + static_cast<const unsigned>(bxLast_ - bxFirst_); }
120 
121 private:
122  // need to keep a record of the BX ranges
123  // in order to convert from int BX to the unsigned index
124  int bxFirst_;
125  int bxLast_;
126 
128  // a flat vector is preferable from the persistency point of view
129  // but handling the start/end points for each BX is more complex
130  // a second vector is needed to store pointers into the first one
131  std::vector<T> data_;
132  std::vector<unsigned> itrs_;
133 };
134 
135 #include "BXVector.impl"
136 
137 #endif
int getLastBX() const
int getFirstBX() const
void resizeAll(unsigned size)
T value_type
Definition: BXVector.h:19
void insert(int bx, unsigned i, T object)
void clearBX(int bx)
unsigned int key(const_iterator &iter) const
Definition: BXVector.h:101
std::vector< T >::iterator iterator
Definition: BXVector.h:17
int bxFirst_
Definition: BXVector.h:124
T & operator[](std::size_t i)
Definition: BXVector.h:104
const T & operator[](std::size_t i) const
Definition: BXVector.h:105
bool isEmpty(int bx) const
std::vector< T > data_
internal data representation:
Definition: BXVector.h:131
void fillView(edm::ProductID const &id, std::vector< void const *> &pointers, edm::FillViewHelperVector &helpers) const
uint16_t size_type
unsigned size() const
Definition: BXVector.h:71
std::vector< T >::const_iterator const_iterator
Definition: BXVector.h:18
int bxLast_
Definition: BXVector.h:125
unsigned numBX() const
Definition: BXVector.h:119
std::vector< T >::size_type size_type
Definition: BXVector.h:20
const T & at(int bx, unsigned i) const
void deleteBX(int bx)
void clear()
void resize(int bx, unsigned size)
void setPtr(std::type_info const &toType, unsigned long index, void const *&ptr) const
void setBXRange(int bxFirst, int bxLast)
const_iterator begin() const
Definition: BXVector.h:98
void erase(int bx, unsigned i)
void fillPtrVector(std::type_info const &toType, std::vector< unsigned long > const &indices, std::vector< void const *> &ptrs) const
std::vector< unsigned > itrs_
Definition: BXVector.h:132
void addBX()
long double T
const_iterator end() const
Definition: BXVector.h:99
BXVector(unsigned size=0, int bxFirst=0, int bxLast=0)
unsigned indexFromBX(int bx) const
void push_back(int bx, T object)
std::vector< std::pair< edm::ProductID, unsigned long > > FillViewHelperVector