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