ATLAS Offline Software
L1ThresholdBase.icc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 namespace TrigConf {
6 
7 
8  template<class T>
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)
11  {}
12 
13 
14  template<class T>
15  size_t ValueWithEtaDependence<T>::size() const {
16  return m_rangeValues.size();
17  }
18 
19  template<class T>
20  bool ValueWithEtaDependence<T>::empty() const {
21  return m_rangeValues.empty();
22  }
23 
24  template<class T>
25  typename ValueWithEtaDependence<T>::const_iterator ValueWithEtaDependence<T>::begin() const noexcept {
26  return m_rangeValues.begin();
27  }
28  template<class T>
29  typename ValueWithEtaDependence<T>::const_iterator ValueWithEtaDependence<T>::end() const noexcept {
30  return m_rangeValues.end();
31  }
32 
33  template<class T>
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 )
38  continue;
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");
42  }
43  }
44  m_rangeValues.emplace_back( std::move(rv) );
45  }
46 
47 
48  template<class T>
49  void ValueWithEtaDependence<T>::setOutsideRangeValue(const T & value) {
50  m_outsideRangeValue = value;
51  }
52 
53  template<class T>
54  std::optional<std::reference_wrapper<const T>>
55  ValueWithEtaDependence<T>::outsideRangeValue() const {
56  return m_outsideRangeValue;
57  }
58 
59 
60  template<class T>
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
69  continue;
70  if(int(rv.priority()) < current_priority)
71  continue;
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));
75  }
76  current_priority = (int)rv.priority();
77  retVal = & rv.value();
78  }
79  if( retVal ) {
80  return * retVal;
81  } else if(m_outsideRangeValue) {
82  return *m_outsideRangeValue;
83  } else {
84  throw std::out_of_range(name() + ": no value found with eta = " + std::to_string(eta));
85  }
86  }
87 
88 }