ATLAS Offline Software
ChainNameParser.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include <string>
6 #include <regex>
7 #include <array>
8 #include <algorithm>
9 
11 
12 #include <iostream>
13 
14 namespace
15 {
16  std::string join(const std::vector<std::string> &parts, const std::string &piece)
17  {
18  std::string result;
19  if (parts.empty())
20  return result;
21  auto itr = parts.begin();
22  result = *itr;
23  for (++itr; itr != parts.end(); ++itr)
24  result += piece + *itr;
25  return result;
26  }
27 
28  const std::regex &legHeadRegex()
29  {
31  return re;
32  }
33 }
34 
35 namespace ChainNameParser {
36 
37  std::string LegInfo::legName() const
38  {
39  std::string result;
40  if (multiplicity != 1)
42  result += signature;
43  if (threshold != -1)
45  if (legParts.size())
46  result += "_" + join(legParts, "_");
47  return result;
48  }
49 
51  {
52  if (signature == "e")
53  {
54  if (std::find(legParts.begin(), legParts.end(), "etcut") != legParts.end())
55  return xAODType::CaloCluster;
56  else
57  return xAODType::Electron;
58  }
59  else if (signature == "g")
60  {
61  if (std::find(legParts.begin(), legParts.end(), "etcut") != legParts.end())
62  return xAODType::CaloCluster;
63  else
64  return xAODType::Photon;
65  }
66  else if (signature == "j")
67  return xAODType::Jet;
68  else if (signature == "mu")
69  return xAODType::Muon;
70  else if (signature == "tau")
71  return xAODType::Tau;
72  else
73  return xAODType::Other;
74  }
75 
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  }
85 
87  {
88  return m_itr == other.m_itr && m_end == other.m_end && m_peekSignature == other.m_peekSignature;
89  }
90 
92  {
93  return !(*this == other);
94  }
95 
97  {
98  return m_current;
99  }
100 
102  {
103  return &m_current;
104  }
105 
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  }
130 
132  {
133  LegInfoIterator itr(*this);
134  this->operator++();
135  return itr;
136  }
137 
139  {
140  return m_itr == std::string::const_iterator();
141  }
142 
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  }
178 
179  std::string HLTChainInfo::l1Item() const
180  {
181  std::size_t pos = m_chain.rfind("_L1");
182  if (pos == std::string::npos)
183  return "";
184  else
185  return "L1_" + m_chain.substr(pos+3);
186  }
187 
188  const std::vector<std::string> &allSignatures()
189  {
190  const static std::vector<std::string> signatures{
191  "e", "g", "j", "mu", "tau", "xe", "xs", "te", "ht", "noalg", "mb",
192  "l1calocalib", "lar", "zdc", "lumipeb", "alfacalib", "calibAFP", "afp"
193  };
194  return signatures;
195  }
196 
197  std::string legHeadPattern()
198  {
199  return "(\\d*)("+join(allSignatures(), "|")+")(\\d*)"+"(noL1|c|f|a)?";
200  }
201 
202  std::vector<int> multiplicities(const std::string &chain)
203  {
204  std::vector<int> multiplicities;
205  for (auto itr = LegInfoIterator(chain); !itr.exhausted(); ++itr)
206  multiplicities.push_back(itr->multiplicity);
207  return multiplicities;
208  }
209 
210  std::vector<std::string> signatures(const std::string &chain)
211  {
212  std::vector<std::string> signatures;
213  for (auto itr = LegInfoIterator(chain); !itr.exhausted(); ++itr)
214  signatures.push_back(itr->signature);
215  return signatures;
216  }
217 
218 } //> end namespace ChainNameParser
219 
ChainNameParser::allSignatures
const std::vector< std::string > & allSignatures()
A list of all signature names.
Definition: ChainNameParser.cxx:188
ChainNameParser::LegInfo::type
xAODType::ObjectType type() const
The type of xAOD IParticle produced by this signature if relevant.
Definition: ChainNameParser.cxx:50
ChainNameParser.h
ChainNameParser::LegInfoIterator::operator->
pointer operator->() const
Definition: ChainNameParser.cxx:101
get_generator_info.result
result
Definition: get_generator_info.py:21
ChainNameParser::LegInfoIterator
Iterate over the legs of a chain.
Definition: ChainNameParser.h:35
runLayerRecalibration.chain
chain
Definition: runLayerRecalibration.py:175
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
xAODType::Photon
@ Photon
The object is a photon.
Definition: ObjectType.h:47
ChainNameParser::LegInfoIterator::m_peekThreshold
int m_peekThreshold
Definition: ChainNameParser.h:77
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
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::LegInfoIterator::operator*
reference operator*() const
Dereference the iterator.
Definition: ChainNameParser.cxx:96
ChainNameParser::LegInfoIterator::exhausted
bool exhausted() const
Whether the iterator is exhausted.
Definition: ChainNameParser.cxx:138
ChainNameParser
Definition: ChainNameParser.cxx:35
ChainNameParser::LegInfo::threshold
int threshold
The threshold on the object.
Definition: ChainNameParser.h:26
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
PrepareReferenceFile.regex
regex
Definition: PrepareReferenceFile.py:43
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
xAODType::Jet
@ Jet
The object is a jet.
Definition: ObjectType.h:40
ChainNameParser::LegInfoIterator::operator==
bool operator==(const LegInfoIterator &other) const
Check (in)equality against another iterator.
Definition: ChainNameParser.cxx:86
xAODType::Other
@ Other
An object not falling into any of the other categories.
Definition: ObjectType.h:34
ChainNameParser::HLTChainInfo::l1Item
std::string l1Item() const
Read the L1 item from the chain. Returns the empty string if the L1 item isn't in the chain name.
Definition: ChainNameParser.cxx:179
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
ChainNameParser::multiplicities
std::vector< int > multiplicities(const std::string &chain)
Definition: ChainNameParser.cxx:202
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
xAODType::Muon
@ Muon
The object is a muon.
Definition: ObjectType.h:48
threshold
Definition: chainparser.cxx:74
ChainNameParser::LegInfo::legParts
std::vector< std::string > legParts
All the parts of the leg.
Definition: ChainNameParser.h:28
ChainNameParser::LegInfoIterator::operator!=
bool operator!=(const LegInfoIterator &other) const
Definition: ChainNameParser.cxx:91
ChainNameParser::signatures
std::vector< std::string > signatures(const std::string &chain)
Definition: ChainNameParser.cxx:210
xAODType::Electron
@ Electron
The object is an electron.
Definition: ObjectType.h:46
ChainNameParser::LegInfo
Struct containing information on each leg of a chain.
Definition: ChainNameParser.h:16
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
ChainNameParser::LegInfoIterator::m_peekSignature
std::string m_peekSignature
Definition: ChainNameParser.h:76
xAODType::CaloCluster
@ CaloCluster
The object is a calorimeter cluster.
Definition: ObjectType.h:39
re
const boost::regex re(r_e)
ChainNameParser::LegInfoIterator::operator++
LegInfoIterator & operator++()
pre-increment operator
Definition: ChainNameParser.cxx:106
xAODType::Tau
@ Tau
The object is a tau (jet)
Definition: ObjectType.h:49
doL1CaloHVCorrections.parts
parts
Definition: doL1CaloHVCorrections.py:334
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
ChainNameParser::HLTChainInfo::m_chain
std::string m_chain
Definition: ChainNameParser.h:99
ChainNameParser::legHeadPattern
std::string legHeadPattern()
Definition: ChainNameParser.cxx:197
xAODType::ObjectType
ObjectType
Type of objects that have a representation in the xAOD EDM.
Definition: ObjectType.h:32
ChainNameParser::LegInfo::legName
std::string legName() const
The name of the leg.
Definition: ChainNameParser.cxx:37
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