has_fillView

has_setPtr

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305
#include <cassert>

// FIXME: these 3 lines are required by other packages
#include <vector>
#include <iostream>
using namespace std;

#include "FWCore/MessageLogger/interface/MessageLogger.h"

template <class T>
BXVector<T>::BXVector(unsigned size,  // number of objects per BX
                      int bxFirst,    // first BX stored
                      int bxLast)     // last BX stored
    : bxFirst_(std::min(0, bxFirst)), bxLast_(std::max(0, bxLast)), data_(std::vector<T>(size * numBX())) {
  assert(bxFirst_ <= bxLast_);
  itrs_.clear();
  for (unsigned i = 0; i < numBX(); i++) {
    itrs_.push_back(i * size);
  }
}

// set BX range, adds an empty bx so you must push_pack to see anything
template <class T>
void BXVector<T>::setBXRange(int bxFirst, int bxLast) {
  int bxF = bxFirst_;
  int bxL = bxLast_;
  if (bxFirst < bxFirst_) {
    for (int i = 0; i < bxF - bxFirst; i++) {
      itrs_.insert(itrs_.begin(), itrs_[0]);
    }
  }
  if (bxFirst > bxFirst_) {
    for (int i = 0; i < bxFirst - bxF; i++) {
      deleteBX(bxF + i);
    }
  }
  if (bxLast > bxLast_) {
    for (int i = 0; i < bxLast - bxL; i++) {
      addBX();
    }
  }
  if (bxLast < bxLast_) {
    for (int i = 0; i < bxL - bxLast; i++) {
      deleteBX(bxL - i);
    }
  }
  bxFirst_ = bxFirst;
  bxLast_ = bxLast;
}

// add a BX, empty bx
template <class T>
void BXVector<T>::addBX() {
  itrs_.push_back(data_.size());
  bxLast_ = bxLast_ + 1;
}

// delete a BX
template <class T>
void BXVector<T>::deleteBX(int bx) {
  clearBX(bx);
  itrs_.erase(itrs_.begin() + indexFromBX(bx));
  if (bx == getFirstBX()) {
    bxFirst_ = bxFirst_ + 1;
  }
  if (bx == getLastBX()) {
    bxLast_ = bxLast_ - 1;
  }
}
// set size for a given BX
template <class T>
void BXVector<T>::resize(int bx, unsigned max) {
  T k;
  unsigned s = size(bx);
  if (size(bx) < max) {
    for (unsigned i = 0; i < max - s; i++) {
      push_back(bx, k);
    }
  } else {
    for (unsigned i = 0; i < s - max; i++) {
      erase(bx, s - i - 1);
    }
  }
}

// set size for all BXs
template <class T>
void BXVector<T>::resizeAll(unsigned size) {
  for (unsigned i = 0; i < itrs_.size(); ++i) {
    resize(i, size);
  }
}

// iterator access by BX
template <class T>
typename BXVector<T>::const_iterator BXVector<T>::begin(int bx) const {
  assert(!itrs_.empty());
  return data_.begin() + itrs_[indexFromBX(bx)];
}

// iterator access by BX
template <class T>
typename BXVector<T>::const_iterator BXVector<T>::end(int bx) const {
  return data_.begin() + itrs_[indexFromBX(bx)] + size(bx);
}

// get the first BX stored
template <class T>
int BXVector<T>::getFirstBX() const {
  return bxFirst_;
}

// get the last BX stored
template <class T>
int BXVector<T>::getLastBX() const {
  return bxLast_;
}

// get N objects for a given BX
template <class T>
unsigned BXVector<T>::size(int bx) const {
  if (isEmpty(bx)) {
    return 0;
  }

  if (indexFromBX(bx) == (itrs_.size() - 1)) {
    return (data_.size() - itrs_[itrs_.size() - 1]);
  } else {
    return (itrs_[indexFromBX(bx + 1)] - itrs_[indexFromBX(bx)]);
  }
}

// add element with given BX index
template <class T>
void BXVector<T>::push_back(int bx, T object) {
  if (bx >= bxFirst_ && bx <= bxLast_) {
    data_.insert(data_.begin() + itrs_[indexFromBX(bx)] + size(bx), object);
    for (unsigned k = 0; k < itrs_.size(); k++) {
      if (k > indexFromBX(bx)) {
        itrs_[k]++;
      }
    }
  } else {
    edm::LogWarning("BXVectorBXViolation")
        << "Something attempted to push to a BXVector BX that does not exist. The data will be ignored. bx: " << bx
        << " bxFirst: " << bxFirst_ << " bxLast: " << bxLast_;
  }
}

// clear entire BXVector
template <class T>
void BXVector<T>::clear() {
  data_.clear();
  for (unsigned k = 0; k < itrs_.size(); k++) {
    itrs_[k] = 0;
  }
}

// insert data in location i of bx
template <class T>
void BXVector<T>::insert(int bx, unsigned i, T object) {
  if (i > size(bx)) {
    //cout<<"ERROR: bx "<<bx<<" is only "<<size(bx)<<" long"<<endl;
  } else {
    data_.insert(data_.begin() + itrs_[indexFromBX(bx)] + i, object);

    for (unsigned k = 0; k < itrs_.size(); k++) {
      if (k > indexFromBX(bx)) {
        itrs_[k]++;
      }
    }
  }
}

// erase data in location i of bx
template <class T>
void BXVector<T>::erase(int bx, unsigned i) {
  if (i >= size(bx)) {
    //cout<<"ERROR: bx "<<bx<<" is only "<<size(bx)<<" long"<<endl;
  } else {
    data_.erase(data_.begin() + itrs_[indexFromBX(bx)] + i);
    for (unsigned k = 0; k < itrs_.size(); k++) {
      if (k > indexFromBX(bx)) {
        itrs_[k]--;
      }
    }
  }
}

// clear information for given bx but keeps record of the empty BX
template <class T>
void BXVector<T>::clearBX(int bx) {
  unsigned si = size(bx);
  for (unsigned i = 0; i < si; i++) {
    erase(bx, 0);
  }
}

// access data at a given location i in bunch crossing bx
template <class T>
const T& BXVector<T>::at(int bx, unsigned i) const {
  return data_.at(itrs_[indexFromBX(bx)] + i);
}

// set data at a given location i in bunch crossing bx
template <class T>
void BXVector<T>::set(int bx, unsigned i, const T& object) {
  if (i >= size(bx)) {
    //cout<<"ERROR: bx "<<bx<<" is only "<<size(bx)<<" long"<<endl;
  } else {
    data_.at(itrs_[indexFromBX(bx)] + i) = object;
  }
}

// redefine bunch crossing starting from 0
template <class T>
unsigned BXVector<T>::indexFromBX(int bx) const {
  return bx - bxFirst_;
}

// check to see if bx is empty
template <class T>
bool BXVector<T>::isEmpty(int bx) const {
  if (bx < bxFirst_) {
    return true;
  }

  auto const index_bx = indexFromBX(bx);

  if (index_bx >= itrs_.size()) {
    return true;
  }

  if (itrs_[index_bx] == data_.size()) {
    return true;
  }

  auto const index_bxPlus1 = indexFromBX(bx + 1);

  if (index_bxPlus1 >= itrs_.size()) {
    return false;
  }

  if (itrs_[index_bx] == itrs_[index_bxPlus1]) {
    return true;
  }

  return false;
}

// edm::View support
template <class T>
inline void BXVector<T>::fillView(edm::ProductID const& id,
                                  std::vector<void const*>& pointers,
                                  edm::FillViewHelperVector& helpers) const {
  edm::detail::reallyFillView(*this, id, pointers, helpers);
}
//
namespace edm {
  template <class T>
  inline void fillView(BXVector<T> const& obj,
                       edm::ProductID const& id,
                       std::vector<void const*>& pointers,
                       edm::FillViewHelperVector& helpers) {
    obj.fillView(id, pointers, helpers);
  }
  template <class T>
  struct has_fillView<BXVector<T> > {
    static bool const value = true;
  };
}  // namespace edm

// edm::Ptr support
template <class T>
inline void BXVector<T>::setPtr(std::type_info const& toType, unsigned long index, void const*& ptr) const {
  edm::detail::reallySetPtr<BXVector<T> >(*this, toType, index, ptr);
}
template <class T>
inline void BXVector<T>::fillPtrVector(std::type_info const& toType,
                                       std::vector<unsigned long> const& indices,
                                       std::vector<void const*>& ptrs) const {
  edm::detail::reallyfillPtrVector(*this, toType, indices, ptrs);
}
//
template <class T>
inline void setPtr(BXVector<T> const& obj, std::type_info const& toType, unsigned long index, void const*& ptr) {
  obj.setPtr(toType, index, ptr);
}
template <class T>
inline void fillPtrVector(BXVector<T> const& obj,
                          std::type_info const& toType,
                          std::vector<unsigned long> const& indices,
                          std::vector<void const*>& ptrs) {
  obj.fillPtrVector(toType, indices, ptrs);
}
namespace edm {
  template <class T>
  struct has_setPtr<BXVector<T> > {
    static bool const value = true;
  };
}  // namespace edm

// Local Variables:
// mode: c++
// End: