2 Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
9 ValueWithEtaDependence<T>::RangeValue::RangeValue(const T & value, int etaMin, int etaMax, unsigned int priority, bool symmetric) :
10 m_value(value), m_etaMin(etaMin), m_etaMax(etaMax), m_priority(priority), m_symmetric(symmetric)
15 size_t ValueWithEtaDependence<T>::size() const {
16 return m_rangeValues.size();
20 bool ValueWithEtaDependence<T>::empty() const {
21 return m_rangeValues.empty();
25 typename ValueWithEtaDependence<T>::const_iterator ValueWithEtaDependence<T>::begin() const noexcept {
26 return m_rangeValues.begin();
29 typename ValueWithEtaDependence<T>::const_iterator ValueWithEtaDependence<T>::end() const noexcept {
30 return m_rangeValues.end();
34 void ValueWithEtaDependence<T>::addRangeValue(const T & value, int etaMin, int etaMax, unsigned int priority, bool symmetric) {
35 auto rv = RangeValue{ value, etaMin, etaMax, priority, symmetric };
36 for( const auto & rv : m_rangeValues ) {
37 if( rv.priority() != priority )
39 if( (etaMax > rv.etaMin()) and (etaMin < rv.etaMax()) ) { // overlaps with existing range of the same priority
40 throw std::runtime_error( "Range eta " + std::to_string(etaMin) + " - " + std::to_string(etaMax) +
41 " (priority " + std::to_string(priority) + ") overlaps with existing range of the same priority");
44 m_rangeValues.emplace_back( std::move(rv) );
49 void ValueWithEtaDependence<T>::setOutsideRangeValue(const T & value) {
50 m_outsideRangeValue = value;
54 std::optional<std::reference_wrapper<const T>>
55 ValueWithEtaDependence<T>::outsideRangeValue() const {
56 return m_outsideRangeValue;
61 const T & ValueWithEtaDependence<T>::at(int eta) const {
62 // the ranges are by definition such that the lower boundary is inclusive, while the upper boundary is exclusive
63 // this has been the convention for Run 2 and will remain like this in Run 3
64 // this has been agreed upon by L1Calo and L1Topo
65 int current_priority = -1;
66 const T * retVal { nullptr };
67 for( const auto & rv : m_rangeValues ) {
68 if( eta >= rv.etaMax() or eta < rv.etaMin()) // outside the window
70 if(int(rv.priority()) < current_priority)
72 if(int(rv.priority()) == current_priority) {
73 throw std::runtime_error(name() + ": found two values with the same priority " + std::to_string(rv.priority())
74 + " for eta = " + std::to_string(eta));
76 current_priority = (int)rv.priority();
77 retVal = & rv.value();
81 } else if(m_outsideRangeValue) {
82 return *m_outsideRangeValue;
84 throw std::out_of_range(name() + ": no value found with eta = " + std::to_string(eta));