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 35 of file ChainNameParser.h.

Member Typedef Documentation

◆ difference_type

Definition at line 42 of file ChainNameParser.h.

◆ iterator_category

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

Definition at line 38 of file ChainNameParser.h.

◆ pointer

Definition at line 41 of file ChainNameParser.h.

◆ reference

Definition at line 40 of file ChainNameParser.h.

◆ value_type

Definition at line 39 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 78 of file ChainNameParser.cxx.

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

Member Function Documentation

◆ advance()

bool ChainNameParser::LegInfoIterator::advance ( )
private

Definition at line 145 of file ChainNameParser.cxx.

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

◆ exhausted()

bool ChainNameParser::LegInfoIterator::exhausted ( ) const

Whether the iterator is exhausted.

Definition at line 140 of file ChainNameParser.cxx.

141  {
142  return m_itr == std::string::const_iterator();
143  }

◆ operator!=()

Definition at line 93 of file ChainNameParser.cxx.

94  {
95  return !(*this == other);
96  }

◆ operator*()

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

Dereference the iterator.

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

Definition at line 98 of file ChainNameParser.cxx.

99  {
100  return m_current;
101  }

◆ operator++() [1/2]

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

pre-increment operator

Definition at line 108 of file ChainNameParser.cxx.

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

◆ operator++() [2/2]

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

post-increment operator

Definition at line 133 of file ChainNameParser.cxx.

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

◆ operator->()

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

Definition at line 103 of file ChainNameParser.cxx.

104  {
105  return &m_current;
106  }

◆ operator==()

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

Check (in)equality against another iterator.

Definition at line 88 of file ChainNameParser.cxx.

89  {
90  return m_itr == other.m_itr && m_end == other.m_end && m_peekSignature == other.m_peekSignature;
91  }

Member Data Documentation

◆ m_current

LegInfo ChainNameParser::LegInfoIterator::m_current
private

Definition at line 75 of file ChainNameParser.h.

◆ m_end

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

Definition at line 74 of file ChainNameParser.h.

◆ m_itr

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

Definition at line 73 of file ChainNameParser.h.

◆ m_peekMultiplicity

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

Definition at line 76 of file ChainNameParser.h.

◆ m_peekSignature

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

Definition at line 77 of file ChainNameParser.h.

◆ m_peekThreshold

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

Definition at line 78 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:78
ChainNameParser::LegInfoIterator::m_current
LegInfo m_current
Definition: ChainNameParser.h:75
ChainNameParser::LegInfo::signature
std::string signature
The HLT signature responsible for creating the object.
Definition: ChainNameParser.h:25
ChainNameParser::LegInfo::threshold
int threshold
The threshold on the object.
Definition: ChainNameParser.h:27
ChainNameParser::LegInfoIterator::m_peekMultiplicity
std::size_t m_peekMultiplicity
Definition: ChainNameParser.h:76
ChainNameParser::LegInfoIterator::m_itr
std::string::const_iterator m_itr
Definition: ChainNameParser.h:73
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:74
fillPileUpNoiseLumi.next
next
Definition: fillPileUpNoiseLumi.py:52
ChainNameParser::LegInfo::legParts
std::vector< std::string > legParts
All the parts of the leg.
Definition: ChainNameParser.h:29
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
ChainNameParser::LegInfoIterator::m_peekSignature
std::string m_peekSignature
Definition: ChainNameParser.h:77
ChainNameParser::LegInfoIterator::operator++
LegInfoIterator & operator++()
pre-increment operator
Definition: ChainNameParser.cxx:108
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:145
ChainNameParser::LegInfo::multiplicity
std::size_t multiplicity
The multiplicity of the leg (number of objects returned by the leg)
Definition: ChainNameParser.h:23