ATLAS Offline Software
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
ChainNameParser::LegInfoIterator Class Reference

Iterate over the legs of a chain. More...

#include <ChainNameParser.h>

Collaboration diagram for ChainNameParser::LegInfoIterator:

Public Types

using iterator_category = std::input_iterator_tag
 
using value_type = LegInfo
 
using reference = const value_type &
 
using pointer = const value_type *
 
using difference_type = std::ptrdiff_t
 

Public Member Functions

 LegInfoIterator ()=default
 Default constructor creates a past-the-end iterator. More...
 
 LegInfoIterator (const std::string &chain)
 Create an iterator from the beginning of a chain name. More...
 
bool operator== (const LegInfoIterator &other) const
 Check (in)equality against another iterator. More...
 
bool operator!= (const LegInfoIterator &other) const
 
reference operator* () const
 Dereference the iterator. More...
 
pointer operator-> () const
 
LegInfoIteratoroperator++ ()
 pre-increment operator More...
 
LegInfoIterator operator++ (int)
 post-increment operator More...
 
bool exhausted () const
 Whether the iterator is exhausted. More...
 

Private Member Functions

bool advance ()
 

Private Attributes

std::string::const_iterator m_itr
 
std::string::const_iterator m_end
 
LegInfo m_current
 
std::size_t m_peekMultiplicity {0}
 
std::string m_peekSignature {""}
 
int m_peekThreshold {-1}
 

Detailed Description

Iterate over the legs of a chain.

Definition at line 34 of file ChainNameParser.h.

Member Typedef Documentation

◆ difference_type

Definition at line 41 of file ChainNameParser.h.

◆ iterator_category

using ChainNameParser::LegInfoIterator::iterator_category = std::input_iterator_tag

Definition at line 37 of file ChainNameParser.h.

◆ pointer

Definition at line 40 of file ChainNameParser.h.

◆ reference

Definition at line 39 of file ChainNameParser.h.

◆ value_type

Definition at line 38 of file ChainNameParser.h.

Constructor & Destructor Documentation

◆ LegInfoIterator() [1/2]

ChainNameParser::LegInfoIterator::LegInfoIterator ( )
default

Default constructor creates a past-the-end iterator.

◆ LegInfoIterator() [2/2]

ChainNameParser::LegInfoIterator::LegInfoIterator ( const std::string &  chain)

Create an iterator from the beginning of a chain name.

Parameters
chainThe full chain name

Definition at line 76 of file ChainNameParser.cxx.

76  :
77  m_itr(chain.begin()), m_end(chain.end())
78  {
79  // Move the iterator until we've found the start of a leg
80  while (!advance()) {}
81  // Now we have the next leg info stored in the peek variables, but not the current.
82  // Advance the iterator once to store these in the current
83  this->operator++();
84  }

Member Function Documentation

◆ advance()

bool ChainNameParser::LegInfoIterator::advance ( )
private

Definition at line 143 of file ChainNameParser.cxx.

144  {
145  std::string::const_iterator next = std::find(m_itr, m_end, '_');
146  std::smatch match;
147  if (std::regex_match(m_itr, next, match, legHeadRegex()))
148  {
149  // This means we've found the start of the next leg. Record its data and return true
150  if (match.str(1).empty())
151  m_peekMultiplicity = 1;
152  else
153  m_peekMultiplicity = std::atoi(match.str(1).c_str());
154  m_peekSignature = match.str(2);
155  if (match.str(3).empty())
156  m_peekThreshold = -1;
157  else
158  m_peekThreshold = std::atoi(match.str(3).c_str());
159  // Advance the iterator (skip the underscore if there is one)
160  m_itr = next == m_end ? next : next + 1;
161  return true;
162  }
163  else if (next == m_end)
164  {
165  // Setting the iterator to the end
166  m_itr = m_end;
167  return true;
168  }
169  else
170  {
171  // Otherwise this is just a leg
172  m_current.legParts.emplace_back(m_itr, next);
173  // Advance the iterator (skip the underscore if there is one)
174  m_itr = next == m_end ? next : next + 1;
175  return false;
176  }
177  }

◆ exhausted()

bool ChainNameParser::LegInfoIterator::exhausted ( ) const

Whether the iterator is exhausted.

Definition at line 138 of file ChainNameParser.cxx.

139  {
140  return m_itr == std::string::const_iterator();
141  }

◆ operator!=()

Definition at line 91 of file ChainNameParser.cxx.

92  {
93  return !(*this == other);
94  }

◆ operator*()

LegInfoIterator::reference ChainNameParser::LegInfoIterator::operator* ( ) const

Dereference the iterator.

Dereferencing a past-the-end iterator returns an invalid LegInfo object

Definition at line 96 of file ChainNameParser.cxx.

97  {
98  return m_current;
99  }

◆ operator++() [1/2]

LegInfoIterator & ChainNameParser::LegInfoIterator::operator++ ( )

pre-increment operator

Definition at line 106 of file ChainNameParser.cxx.

107  {
108  if (m_peekSignature.empty() && m_itr == m_end)
109  {
110  // No more signatures to find, exhaust the iterator
111  m_current = {};
112  m_itr = std::string::const_iterator();
113  m_end = std::string::const_iterator();
114  m_peekMultiplicity = 0;
115  m_peekThreshold = -1;
116  }
117  else
118  {
119  // Copy the peeked information into the current info
123  m_current.legParts.clear();
124  m_peekSignature.clear();
125  // Now step through until we find the next leg
126  while (!advance()) {}
127  }
128  return *this;
129  }

◆ operator++() [2/2]

LegInfoIterator ChainNameParser::LegInfoIterator::operator++ ( int  )

post-increment operator

Definition at line 131 of file ChainNameParser.cxx.

132  {
133  LegInfoIterator itr(*this);
134  this->operator++();
135  return itr;
136  }

◆ operator->()

LegInfoIterator::pointer ChainNameParser::LegInfoIterator::operator-> ( ) const

Definition at line 101 of file ChainNameParser.cxx.

102  {
103  return &m_current;
104  }

◆ operator==()

bool ChainNameParser::LegInfoIterator::operator== ( const LegInfoIterator other) const

Check (in)equality against another iterator.

Definition at line 86 of file ChainNameParser.cxx.

87  {
88  return m_itr == other.m_itr && m_end == other.m_end && m_peekSignature == other.m_peekSignature;
89  }

Member Data Documentation

◆ m_current

LegInfo ChainNameParser::LegInfoIterator::m_current
private

Definition at line 74 of file ChainNameParser.h.

◆ m_end

std::string::const_iterator ChainNameParser::LegInfoIterator::m_end
private

Definition at line 73 of file ChainNameParser.h.

◆ m_itr

std::string::const_iterator ChainNameParser::LegInfoIterator::m_itr
private

Definition at line 72 of file ChainNameParser.h.

◆ m_peekMultiplicity

std::size_t ChainNameParser::LegInfoIterator::m_peekMultiplicity {0}
private

Definition at line 75 of file ChainNameParser.h.

◆ m_peekSignature

std::string ChainNameParser::LegInfoIterator::m_peekSignature {""}
private

Definition at line 76 of file ChainNameParser.h.

◆ m_peekThreshold

int ChainNameParser::LegInfoIterator::m_peekThreshold {-1}
private

Definition at line 77 of file ChainNameParser.h.


The documentation for this class was generated from the following files:
runLayerRecalibration.chain
chain
Definition: runLayerRecalibration.py:175
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
ChainNameParser::LegInfoIterator::m_peekThreshold
int m_peekThreshold
Definition: ChainNameParser.h:77
ChainNameParser::LegInfoIterator::m_current
LegInfo m_current
Definition: ChainNameParser.h:74
ChainNameParser::LegInfo::signature
std::string signature
The HLT signature responsible for creating the object.
Definition: ChainNameParser.h:24
ChainNameParser::LegInfo::threshold
int threshold
The threshold on the object.
Definition: ChainNameParser.h:26
ChainNameParser::LegInfoIterator::m_peekMultiplicity
std::size_t m_peekMultiplicity
Definition: ChainNameParser.h:75
ChainNameParser::LegInfoIterator::m_itr
std::string::const_iterator m_itr
Definition: ChainNameParser.h:72
ChainNameParser::LegInfoIterator::LegInfoIterator
LegInfoIterator()=default
Default constructor creates a past-the-end iterator.
ChainNameParser::LegInfoIterator::m_end
std::string::const_iterator m_end
Definition: ChainNameParser.h:73
fillPileUpNoiseLumi.next
next
Definition: fillPileUpNoiseLumi.py:52
ChainNameParser::LegInfo::legParts
std::vector< std::string > legParts
All the parts of the leg.
Definition: ChainNameParser.h:28
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
ChainNameParser::LegInfoIterator::m_peekSignature
std::string m_peekSignature
Definition: ChainNameParser.h:76
ChainNameParser::LegInfoIterator::operator++
LegInfoIterator & operator++()
pre-increment operator
Definition: ChainNameParser.cxx:106
CxxUtils::atoi
int atoi(std::string_view str)
Helper functions to unpack numbers decoded in string into integers and doubles The strings are requir...
Definition: Control/CxxUtils/Root/StringUtils.cxx:85
match
bool match(std::string s1, std::string s2)
match the individual directories of two strings
Definition: hcg.cxx:356
ChainNameParser::LegInfoIterator::advance
bool advance()
Definition: ChainNameParser.cxx:143
ChainNameParser::LegInfo::multiplicity
std::size_t multiplicity
The multiplicity of the leg (number of objects returned by the leg)
Definition: ChainNameParser.h:22