ATLAS Offline Software
Classes | Public Types | Public Member Functions | Private Types | Private Attributes | Friends | List of all members
MultiRange Class Reference

A MultiRange combines several Ranges. More...

#include <MultiRange.h>

Collaboration diagram for MultiRange:

Classes

class  const_identifier_factory
 
class  identifier_factory
 This factory is able to generate all possible identifiers, from a
fully bounded Range. More...
 

Public Types

using range_vector = std::vector< Range >
 
using element_type = ExpandedIdentifier::element_type
 
using size_type = ExpandedIdentifier::size_type
 
using const_iterator = range_vector::const_iterator
 

Public Member Functions

 MultiRange ()=default
 
 MultiRange (const Range &r, const Range &s)
 Construct a non-overlapping MultiRange from two overlapping ones. More...
 
void clear ()
 
void add (const Range &range)
 
void add (Range &&range)
 Add with move semantics. More...
 
void add (const ExpandedIdentifier &id)
 Add a Range made from a single ExpandedIdentifier. More...
 
void remove_range (const ExpandedIdentifier &id)
 Remove a Range made from a single ExpandedIdentifier. More...
 
Rangeback ()
 Get the last entered Range. More...
 
int match (const ExpandedIdentifier &id) const
 Match an identifier. More...
 
const Rangeoperator[] (size_type index) const
 Accessors. More...
 
size_type size () const
 
const_iterator begin () const
 
const_iterator end () const
 
size_type cardinality () const
 Computes a possible cardinality from all ranges. More...
 
size_type cardinalityUpTo (const ExpandedIdentifier &id) const
 
bool has_overlap () const
 Check if there are overlaps between any couple of Ranges. More...
 
identifier_factory factory_begin ()
 
const_identifier_factory factory_begin () const
 
identifier_factory factory_end ()
 
const_identifier_factory factory_end () const
 
void show () const
 
void show (std::ostream &s) const
 
 operator std::string () const
 Generate a textual representation of the multirange using the input format. More...
 

Private Types

using id_vec = std::vector< ExpandedIdentifier >
 

Private Attributes

range_vector m_ranges
 

Friends

class identifier_factory
 
class const_identifier_factory
 

Detailed Description

A MultiRange combines several Ranges.

Definition at line 17 of file MultiRange.h.

Member Typedef Documentation

◆ const_iterator

using MultiRange::const_iterator = range_vector::const_iterator

Definition at line 22 of file MultiRange.h.

◆ element_type

Definition at line 20 of file MultiRange.h.

◆ id_vec

using MultiRange::id_vec = std::vector<ExpandedIdentifier>
private

Definition at line 130 of file MultiRange.h.

◆ range_vector

using MultiRange::range_vector = std::vector<Range>

Definition at line 19 of file MultiRange.h.

◆ size_type

Definition at line 21 of file MultiRange.h.

Constructor & Destructor Documentation

◆ MultiRange() [1/2]

MultiRange::MultiRange ( )
default

◆ MultiRange() [2/2]

MultiRange::MultiRange ( const Range r,
const Range s 
)

Construct a non-overlapping MultiRange from two overlapping ones.

Definition at line 11 of file MultiRange.cxx.

11  {
12  m_ranges.push_back (r);
13  m_ranges.push_back (s);
14 }

Member Function Documentation

◆ add() [1/3]

void MultiRange::add ( const ExpandedIdentifier id)

Add a Range made from a single ExpandedIdentifier.

Definition at line 38 of file MultiRange.cxx.

38  {
39  m_ranges.emplace_back (id);
40 }

◆ add() [2/3]

void MultiRange::add ( const Range range)

Definition at line 22 of file MultiRange.cxx.

22  {
23  // Add new range ONLY if an equivalent does NOT exist
24  if (std::ranges::find(m_ranges, range) == m_ranges.end()) {
25  m_ranges.push_back(range);
26  }
27 }

◆ add() [3/3]

void MultiRange::add ( Range &&  range)

Add with move semantics.

Definition at line 30 of file MultiRange.cxx.

30  {
31  // Add new range ONLY if an equivalent does NOT exist
32  if (std::ranges::find(m_ranges, range) == m_ranges.end()) {
33  m_ranges.emplace_back (std::move(range));
34  }
35 }

◆ back()

Range & MultiRange::back ( )

Get the last entered Range.

Definition at line 52 of file MultiRange.cxx.

52  {
53  return (m_ranges.back());
54 }

◆ begin()

MultiRange::const_iterator MultiRange::begin ( ) const

Definition at line 74 of file MultiRange.cxx.

74  {
75  return (m_ranges.begin ());
76 }

◆ cardinality()

MultiRange::size_type MultiRange::cardinality ( ) const

Computes a possible cardinality from all ranges.

Definition at line 82 of file MultiRange.cxx.

82  {
83  size_type init = 0;
84  return std::accumulate(m_ranges.begin(), m_ranges.end(), init,
85  [](size_type a, const Range& b){return a + b.cardinality();});
86 }

◆ cardinalityUpTo()

MultiRange::size_type MultiRange::cardinalityUpTo ( const ExpandedIdentifier id) const

Definition at line 88 of file MultiRange.cxx.

88  {
89  // Loop over ranges in MultiRange and calculate hash for each
90  // range
91  size_type init = 0;
92  return std::accumulate(m_ranges.begin(), m_ranges.end(), init,
93  [&id](size_type a, const Range& b){return a + b.cardinalityUpTo(id);});
94 }

◆ clear()

void MultiRange::clear ( )

Definition at line 17 of file MultiRange.cxx.

17  {
18  m_ranges.clear ();
19 }

◆ end()

MultiRange::const_iterator MultiRange::end ( ) const

Definition at line 78 of file MultiRange.cxx.

78  {
79  return (m_ranges.end ());
80 }

◆ factory_begin() [1/2]

MultiRange::identifier_factory MultiRange::factory_begin ( )

Definition at line 112 of file MultiRange.cxx.

112  {
113  const MultiRange& me = *this;
114  return (identifier_factory (me));
115 }

◆ factory_begin() [2/2]

MultiRange::const_identifier_factory MultiRange::factory_begin ( ) const

Definition at line 118 of file MultiRange.cxx.

118  {
119  const MultiRange& me = *this;
120  return (const_identifier_factory (me));
121 }

◆ factory_end() [1/2]

MultiRange::identifier_factory MultiRange::factory_end ( )

Definition at line 124 of file MultiRange.cxx.

124  {
125  static const identifier_factory factory(*this);
126  return (factory);
127 }

◆ factory_end() [2/2]

MultiRange::const_identifier_factory MultiRange::factory_end ( ) const

Definition at line 130 of file MultiRange.cxx.

130  {
131  static const const_identifier_factory factory;
132  return (factory);
133 }

◆ has_overlap()

bool MultiRange::has_overlap ( ) const

Check if there are overlaps between any couple of Ranges.

Definition at line 98 of file MultiRange.cxx.

98  {
99  range_vector::size_type i;
100  range_vector::size_type j;
101  for (i = 0; i < m_ranges.size (); ++i) {
102  const Range& r = m_ranges[i];
103  for (j = i + 1; j < m_ranges.size (); ++j) {
104  const Range& s = m_ranges[j];
105  if (r.overlaps_with (s)) return (true);
106  }
107  }
108  return (false);
109 }

◆ match()

int MultiRange::match ( const ExpandedIdentifier id) const

Match an identifier.

Definition at line 57 of file MultiRange.cxx.

57  {
58  bool result = std::ranges::any_of(m_ranges, [&id](const Range & r){return r.match(id);});
59  return result ? 1:0;
60 }

◆ operator std::string()

MultiRange::operator std::string ( ) const

Generate a textual representation of the multirange using the input format.

Definition at line 251 of file MultiRange.cxx.

251  {
252  std::string result;
253  range_vector::size_type i{};
254  for ( ; i < m_ranges.size (); ++i){
255  if (i > 0) result += " | ";
256  const Range& r = m_ranges[i];
257  result += (std::string) r;
258  }
259  return (result);
260 }

◆ operator[]()

const Range & MultiRange::operator[] ( MultiRange::size_type  index) const

Accessors.

Definition at line 63 of file MultiRange.cxx.

63  {
64  static const Range null_range;
65  if (index >= m_ranges.size ()) return (null_range);
66  return (m_ranges[index]);
67 }

◆ remove_range()

void MultiRange::remove_range ( const ExpandedIdentifier id)

Remove a Range made from a single ExpandedIdentifier.

Definition at line 43 of file MultiRange.cxx.

43  {
44  // Remove all ranges for which id matches
45  [[maybe_unused]] auto erased = std::erase_if (m_ranges,
46  [&id] (const Range& r) { return r.match(id); });
47 }

◆ show() [1/2]

void MultiRange::show ( ) const

Definition at line 237 of file MultiRange.cxx.

237  {
238  show (std::cout);
239 }

◆ show() [2/2]

void MultiRange::show ( std::ostream &  s) const

Definition at line 241 of file MultiRange.cxx.

241  {
242  range_vector::size_type i;
243  for (i = 0; i < m_ranges.size (); ++i) {
244  if (i > 0) s << std::endl;
245  const Range& r = m_ranges[i];
246  r.show (s);
247  }
248 }

◆ size()

MultiRange::size_type MultiRange::size ( ) const

Definition at line 70 of file MultiRange.cxx.

70  {
71  return (m_ranges.size ());
72 }

Friends And Related Function Documentation

◆ const_identifier_factory

friend class const_identifier_factory
friend

Definition at line 129 of file MultiRange.h.

◆ identifier_factory

friend class identifier_factory
friend

Definition at line 128 of file MultiRange.h.

Member Data Documentation

◆ m_ranges

range_vector MultiRange::m_ranges
private

Definition at line 131 of file MultiRange.h.


The documentation for this class was generated from the following files:
beamspotman.r
def r
Definition: beamspotman.py:676
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
get_generator_info.result
result
Definition: get_generator_info.py:21
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
index
Definition: index.py:1
accumulate
bool accumulate(AccumulateMap &map, std::vector< module_t > const &modules, FPGATrackSimMatrixAccumulator const &acc)
Accumulates an accumulator (e.g.
Definition: FPGATrackSimMatrixAccumulator.cxx:22
MultiRange::size_type
ExpandedIdentifier::size_type size_type
Definition: MultiRange.h:21
MultiRange::m_ranges
range_vector m_ranges
Definition: MultiRange.h:131
lumiFormat.i
int i
Definition: lumiFormat.py:85
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
MultiRange::const_identifier_factory
friend class const_identifier_factory
Definition: MultiRange.h:129
std::erase_if
std::size_t erase_if(T_container &container, T_Func pred)
Definition: TruthParticleHitCountAlg.cxx:29
MultiRange
A MultiRange combines several Ranges.
Definition: MultiRange.h:17
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
Range
A Range describes the possible ranges for the field values of an ExpandedIdentifier.
Definition: DetectorDescription/Identifier/Identifier/Range.h:29
python.PyKernel.init
def init(v_theApp, v_rootStream=None)
Definition: PyKernel.py:45
a
TList * a
Definition: liststreamerinfos.cxx:10
MultiRange::show
void show() const
Definition: MultiRange.cxx:237
MultiRange::identifier_factory
friend class identifier_factory
Definition: MultiRange.h:128