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
bTagCombinedSVVariables_cff.indices
indices
Definition: bTagCombinedSVVariables_cff.py:67
edm::FillViewHelperVector
std::vector< std::pair< edm::ProductID, unsigned long > > FillViewHelperVector
Definition: FillViewHelperVector.h:30
BXVector::end
const_iterator end() const
Definition: BXVector.h:99
BXVector::fillPtrVector
void fillPtrVector(std::type_info const &toType, std::vector< unsigned long > const &indices, std::vector< void const * > &ptrs) const
BXVector::bxFirst_
int bxFirst_
Definition: BXVector.h:124
mps_fire.i
i
Definition: mps_fire.py:355
BXVector::erase
void erase(int bx, unsigned i)
BXVector::size
unsigned size() const
Definition: BXVector.h:71
BXVector::const_iterator
std::vector< T >::const_iterator const_iterator
Definition: BXVector.h:18
BXVector::numBX
unsigned numBX() const
Definition: BXVector.h:119
l1GtPatternGenerator_cfi.bx
bx
Definition: l1GtPatternGenerator_cfi.py:18
BXVector::fillView
void fillView(edm::ProductID const &id, std::vector< void const * > &pointers, edm::FillViewHelperVector &helpers) const
BXVector::insert
void insert(int bx, unsigned i, T object)
BXVector::isEmpty
bool isEmpty(int bx) const
BXVector::operator[]
const T & operator[](std::size_t i) const
Definition: BXVector.h:105
BXVector::itrs_
std::vector< unsigned > itrs_
Definition: BXVector.h:132
BXVector
Definition: BXVector.h:15
BXVector::getFirstBX
int getFirstBX() const
trigger::size_type
uint16_t size_type
Definition: TriggerTypeDefs.h:18
BXVector::BXVector
BXVector(unsigned size=0, int bxFirst=0, int bxLast=0)
BXVector::setPtr
void setPtr(std::type_info const &toType, unsigned long index, void const *&ptr) const
BXVector::begin
const_iterator begin() const
Definition: BXVector.h:98
BXVector::iterator
std::vector< T >::iterator iterator
Definition: BXVector.h:17
BXVector::clear
void clear()
BXVector::clearBX
void clearBX(int bx)
BXVector::key
unsigned int key(const_iterator &iter) const
Definition: BXVector.h:101
helpers
Definition: makeCompositeCandidate.h:8
BXVector::at
const T & at(int bx, unsigned i) const
FillView.h
BXVector::data_
std::vector< T > data_
internal data representation:
Definition: BXVector.h:131
BXVector::resize
void resize(int bx, unsigned size)
BXVector::bxLast_
int bxLast_
Definition: BXVector.h:125
simCaloStage2Layer1Digis_cfi.bxFirst
bxFirst
Definition: simCaloStage2Layer1Digis_cfi.py:7
BXVector::resizeAll
void resizeAll(unsigned size)
BXVector::operator[]
T & operator[](std::size_t i)
Definition: BXVector.h:104
BXVector::addBX
void addBX()
simCaloStage2Layer1Digis_cfi.bxLast
bxLast
Definition: simCaloStage2Layer1Digis_cfi.py:8
T
long double T
Definition: Basic3DVectorLD.h:48
BXVector::value_type
T value_type
Definition: BXVector.h:19
BXVector::set
void set(int bx, unsigned i, const T &object)
setPtr.h
BXVector::indexFromBX
unsigned indexFromBX(int bx) const
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
BXVector::size_type
std::vector< T >::size_type size_type
Definition: BXVector.h:20
BXVector::deleteBX
void deleteBX(int bx)
traits.h
BXVector::setBXRange
void setBXRange(int bxFirst, int bxLast)
fillPtrVector.h
BXVector::getLastBX
int getLastBX() const
BXVector::push_back
void push_back(int bx, T object)
edm::ProductID
Definition: ProductID.h:27