Skip to content

Commit

Permalink
do not allow crashes in isEmpty(int bx) method of BXVector
Browse files Browse the repository at this point in the history
  • Loading branch information
missirol committed May 6, 2023
1 parent adad4fd commit e6b2866
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
6 changes: 3 additions & 3 deletions DataFormats/L1Trigger/interface/BXVector.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef BXVector_h
#define BXVector_h
#ifndef DataFormats_L1Trigger_BXVector_h
#define DataFormats_L1Trigger_BXVector_h

// this class is an extension of std::vector
// designed to store objects corresponding to several time-samples (BX)
Expand Down Expand Up @@ -134,4 +134,4 @@ class BXVector {

#include "BXVector.icc"

#endif
#endif // DataFormats_L1Trigger_BXVector_h
21 changes: 15 additions & 6 deletions DataFormats/L1Trigger/interface/BXVector.icc
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#include <vector>
#include <iostream>
#include <cassert>
using namespace std;

template <class T>
BXVector<T>::BXVector(unsigned size, // number of objects per BX
Expand Down Expand Up @@ -211,15 +208,27 @@ unsigned BXVector<T>::indexFromBX(int bx) const {
// check to see if bx is empty
template <class T>
bool BXVector<T>::isEmpty(int bx) const {
if (itrs_[indexFromBX(bx)] == data_.size()) {
if (bx < bxFirst_) {
return true;
}

if (indexFromBX(bx + 1) >= itrs_.size()) {
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_[indexFromBX(bx)] == itrs_[indexFromBX(bx + 1)]) {
if (itrs_[index_bx] == itrs_[index_bxPlus1]) {
return true;
}

Expand Down

0 comments on commit e6b2866

Please sign in to comment.