CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
8 #include <vector>
9 
10 template < class T >
11 class BXVector {
12 
13  public:
14 
15  typedef typename std::vector< T >::iterator iterator;
16  typedef typename std::vector< T >::const_iterator const_iterator;
17 
18  public:
19 
20  // default ctor
21  BXVector( unsigned size=0, // number of objects per BX
22  int bxFirst=0, // first BX stored
23  int bxLast=0 ); // last BX stored
24 
25  // copy ctor
26  // BXVector ( const BXVector& vector );
27 
28  // dtor
29  //~BXVector();
30 
31  // assignment operator (pass by value for exception safety)
32  //BXVector operator=(BXVector vector );
33 
34  // the methods given below are a minimal set
35  // other methods from the std::vector interface can be replicated as desired
36 
37  // set BX range
38  void setBXRange( int bxFirst, int bxLast );
39 
40  // set size for a given BX
41  void resize( int bx, unsigned size );
42 
43  // set size for all BXs
44  void resizeAll( unsigned size );
45 
46  // add one BX to end of BXVector
47  void addBX();
48 
49  // delete given bunch crossing
50  void deleteBX(int bx);
51 
52  // get the first BX stored
53  int getFirstBX() const;
54 
55  // get the last BX stored
56  int getLastBX() const;
57 
58  // iterator access by BX
59  const_iterator begin( int bx ) const;
60 
61  // iterator access by BX
62  const_iterator end( int bx ) const;
63 
64  // get N objects for a given BX
65  unsigned size( int bx ) const;
66 
67  // add element with given BX index
68  void push_back( int bx, T object );
69 
70  // erase element with given location
71  void erase( int bx, unsigned i);
72 
73  // insert element with given location
74  void insert( int bx, unsigned i, T object );
75 
76  // clear entire BXVector
77  void clear();
78 
79  // clear bx
80  void clearBX(int bx);
81 
82  // access element
83  const T& at( int bx, unsigned i ) const;
84 
85  // set element
86  void set( int bx, unsigned i , const T & object);
87 
88  // check if data has empty location
89  bool isEmpty(int bx) const;
90 
91  private:
92 
93  // this method converts integer BX index into an unsigned index
94  // used by the internal data representation
95  unsigned indexFromBX(int bx) const;
96  unsigned numBX() const {return static_cast<const unsigned>(bxLast_) - bxFirst_; }
97 
98  private:
99 
100  // need to keep a record of the BX ranges
101  // in order to convert from int BX to the unsigned index
102  int bxFirst_;
103  int bxLast_;
104 
106  // a flat vector is preferable from the persistency point of view
107  // but handling the start/end points for each BX is more complex
108  // a second vector is needed to store pointers into the first one
109  std::vector< T > data_;
110  std::vector<unsigned> itrs_;
111 };
112 
113 #include "BXVector.impl"
114 
115 #endif
const_iterator end(int bx) const
int i
Definition: DBlmapReader.cc:9
void resizeAll(unsigned size)
unsigned size(int bx) const
void insert(int bx, unsigned i, T object)
void clearBX(int bx)
int bxFirst_
Definition: BXVector.h:102
bool isEmpty(int bx) const
int bxLast_
Definition: BXVector.h:103
std::vector< T >::iterator iterator
Definition: BXVector.h:15
void set(int bx, unsigned i, const T &object)
int getFirstBX() const
unsigned indexFromBX(int bx) const
void deleteBX(int bx)
std::vector< T > data_
internal data representation:
Definition: BXVector.h:109
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:110
unsigned numBX() const
Definition: BXVector.h:96
void addBX()
long double T
const_iterator begin(int bx) const
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:16
const T & at(int bx, unsigned i) const