Skip to content

Commit

Permalink
Merge pull request #40458 from missirol/devel_hltGlobalStatusAt
Browse files Browse the repository at this point in the history
use `std::vector<T>::operator[]` in `edm::HLTGlobalStatus::operator[]`
  • Loading branch information
cmsbuild committed Jan 13, 2023
2 parents 8caf101 + 453dd74 commit c0c2b19
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
14 changes: 8 additions & 6 deletions DataFormats/Common/interface/HLTGlobalStatus.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
#include "DataFormats/Common/interface/HLTenums.h"
#include "DataFormats/Common/interface/HLTPathStatus.h"

#include <vector>
#include <string>
#include <ostream>
#include <vector>

namespace edm {

class HLTGlobalStatus {
private:
/// Status of each HLT path
Expand Down Expand Up @@ -50,12 +52,12 @@ namespace edm {
/// Has any path encountered an error (exception)
bool error() const { return State(2); }

// get hold of individual elements, using safe indexing with "at" which throws!
// accessors to ith element of paths_

const HLTPathStatus& at(const unsigned int i) const { return paths_.at(i); }
HLTPathStatus& at(const unsigned int i) { return paths_.at(i); }
const HLTPathStatus& operator[](const unsigned int i) const { return paths_.at(i); }
HLTPathStatus& operator[](const unsigned int i) { return paths_.at(i); }
const HLTPathStatus& operator[](const unsigned int i) const { return paths_[i]; }
HLTPathStatus& operator[](const unsigned int i) { return paths_[i]; }

/// Was ith path run?
bool wasrun(const unsigned int i) const { return at(i).wasrun(); }
Expand Down Expand Up @@ -102,7 +104,7 @@ namespace edm {
/// Free swap function
inline void swap(HLTGlobalStatus& lhs, HLTGlobalStatus& rhs) { lhs.swap(rhs); }

/// Formatted printout of trigger tbale
/// Formatted printout of trigger table
inline std::ostream& operator<<(std::ostream& ost, const HLTGlobalStatus& hlt) {
std::vector<std::string> text(4);
text[0] = "n";
Expand All @@ -111,7 +113,7 @@ namespace edm {
text[3] = "e";
const unsigned int n(hlt.size());
for (unsigned int i = 0; i != n; ++i)
ost << text.at(hlt.state(i));
ost << text[hlt.state(i)];
return ost;
}

Expand Down
4 changes: 2 additions & 2 deletions FWCore/Framework/src/EventSelector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ namespace edm {
bool lookForException = (s == hlt::Exception);
for (auto const& bit : b) {
hlt::HLTState bstate = lookForException ? hlt::Exception : bit.accept_state_ ? hlt::Pass : hlt::Fail;
if (tr[bit.pos_].state() == bstate)
if (tr.at(bit.pos_).state() == bstate)
return true;
}
return false;
Expand All @@ -381,7 +381,7 @@ namespace edm {
bool EventSelector::acceptAllBits(Bits const& b, HLTGlobalStatus const& tr) const {
for (auto const& bit : b) {
hlt::HLTState bstate = bit.accept_state_ ? hlt::Pass : hlt::Fail;
if (tr[bit.pos_].state() != bstate)
if (tr.at(bit.pos_).state() != bstate)
return false;
}
return true;
Expand Down
2 changes: 1 addition & 1 deletion FWCore/Framework/src/Path.cc
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ namespace edm {

void Path::recordStatus(int nwrwue, hlt::HLTState state) {
if (trptr_) {
(*trptr_)[bitpos_] = HLTPathStatus(state, nwrwue);
trptr_->at(bitpos_) = HLTPathStatus(state, nwrwue);
}
}

Expand Down
10 changes: 7 additions & 3 deletions FWCore/Framework/test/stubs/TestTriggerNames.cc
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,11 @@ namespace edmtest {

if (expectedTriggerResultsHLT_.size() > 0) {
if (e.getByLabel(tag, hTriggerResults)) {
if (hTriggerResults->size() == 0) {
throw cms::Exception("Test Failure") << "TestTriggerNames: TriggerResults object from the Event "
"(InputTag = \"TriggerResults::HLT\") is empty (size == 0)";
}

edm::TriggerResultsByName resultsByNameHLT = e.triggerResultsByName(*hTriggerResults);

if (hTriggerResults->parameterSetID() != resultsByNameHLT.parameterSetID() ||
Expand All @@ -263,9 +268,8 @@ namespace edmtest {
hTriggerResults->error(0) != resultsByNameHLT.error(0) ||
hTriggerResults->state(0) != resultsByNameHLT.state(0) ||
hTriggerResults->index(0) != resultsByNameHLT.index(0)) {
throw cms::Exception("Test Failure")
<< "TestTriggerNames: While testing TriggerResultsByName class\n"
<< "TriggerResults values do not match TriggerResultsByName values" << std::endl;
throw cms::Exception("Test Failure") << "TestTriggerNames: While testing TriggerResultsByName class\n"
<< "TriggerResults values do not match TriggerResultsByName values";
}
edm::TriggerNames const& names = e.triggerNames(*hTriggerResults);
if (names.triggerNames() != resultsByNameHLT.triggerNames() || names.size() != resultsByNameHLT.size() ||
Expand Down

0 comments on commit c0c2b19

Please sign in to comment.