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( int 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, int size );
42 
43  // set size for all BXs
44  void resizeAll( int size );
45 
46  // get the first BX stored
47  int getFirstBX() const;
48 
49  // get the last BX stored
50  int getLastBX() const;
51 
52  // get N objects for a given BX
53  unsigned size( int bx ) const;
54 
55  // add element with given BX index
56  void push_back( int bx, T object );
57 
58  // add clear member
59  void clear();
60 
61  // random access
62  const T& at( int bx, int i ) 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  private:
71 
72  // this method converts integer BX index into an unsigned index
73  // used by the internal data representation
74  unsigned indexFromBX(int bx) const;
75 
76 
77  private:
78 
79  // need to keep a record of the BX ranges
80  // in order to convert from int BX to the unsigned index
81  int bxFirst_;
82  int bxLast_;
83 
85 
86  // Version 1
87  // this version is easy to handle
88  // but nested template containers are disfavoured by persistency layer
89  std::vector< std::vector< T > > data_;
90 
91  // Version 2
92  // a flat vector is preferable from the persistency point of view
93  // but handling the start/end points for each BX is more complex
94  // a second vector is needed to store pointers into the first one
95  /* std::vector< T > data_; */
96  /* std::vector< std::vector::iterator > itrs_; */
97 
98 };
99 
100 #include "BXVector.impl"
101 
102 #endif
const_iterator end(int bx) const
int i
Definition: DBlmapReader.cc:9
unsigned size(int bx) const
int bxFirst_
Definition: BXVector.h:81
int bxLast_
Definition: BXVector.h:82
std::vector< T >::iterator iterator
Definition: BXVector.h:15
int getFirstBX() const
unsigned indexFromBX(int bx) const
void clear()
BXVector(int size=0, int bxFirst=0, int bxLast=0)
void setBXRange(int bxFirst, int bxLast)
void resizeAll(int size)
int getLastBX() const
void resize(int bx, int size)
const T & at(int bx, int i) const
long double T
const_iterator begin(int bx) const
std::vector< std::vector< T > > data_
internal data representation
Definition: BXVector.h:89
void push_back(int bx, T object)
std::vector< T >::const_iterator const_iterator
Definition: BXVector.h:16