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" or signature == "dispjet")
67  return xAODType::Jet;
68  else if (signature == "mu")
69  return xAODType::Muon;
70  else if (signature == "tau")
71  return xAODType::Tau;
72  else if (signature == "isotrk")
74  else
75  return xAODType::Other;
76  }
77 
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  }
87 
89  {
90  return m_itr == other.m_itr && m_end == other.m_end && m_peekSignature == other.m_peekSignature;
91  }
92 
94  {
95  return !(*this == other);
96  }
97 
99  {
100  return m_current;
101  }
102 
104  {
105  return &m_current;
106  }
107 
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  }
132 
134  {
135  LegInfoIterator itr(*this);
136  this->operator++();
137  return itr;
138  }
139 
141  {
142  return m_itr == std::string::const_iterator();
143  }
144 
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  }
181 
182  std::string HLTChainInfo::l1Item() const
183  {
184  std::size_t pos = m_chain.rfind("_L1");
185  if (pos == std::string::npos)
186  return "";
187  else
188  return "L1_" + m_chain.substr(pos+3);
189  }
190 
191  const std::vector<std::string> &allSignatures()
192  {
193  const static std::vector<std::string> signatures{
194  "e", "g", "j", "dispjet", "mu", "tau", "xe", "xs", "te", "ht", "noalg", "mb", "hi", "eb",
195  "l1calocalib", "lar", "zdc", "lumipeb", "alfacalib", "calibAFP", "afp", "distrk",
196  "hitdvjet", "isotrk", "dedxtrk", "l1topoPh1debug", "caloclustermon", "fslrt",
197  "beamspot", "cosmic", "timeburner", "mistimemonj400", "larsupercellmon", "larnoiseburst",
198  "acceptedevts", "larpsall", "larpsallem", "idcalib", "metcalo", "mettrk",
199  };
200  return signatures;
201  }
202 
203  const std::vector<std::string> &allSignaturePostfixQualifiers()
204  {
205  const static std::vector<std::string> postfixQualifiers{
206  "noL1", "vtx", "c", "C", "f", "a"
207  };
208  return postfixQualifiers;
209  }
210 
211  const std::set<std::string> &singleLegIdentifiers()
212  {
213  const static std::set<std::string> singleLegIDs{
214  "noalg", "acceptedevts"
215  };
216  return singleLegIDs;
217  }
218 
219  std::string legHeadPattern()
220  {
221  // Pattern looks like an expanded version of "(\d*)(e|g|j|mu|tau|xe)(\d*)(noL1|vtx|c|f|a)?";
222  // i.e. between 0-inf digits, followed by a signature, followed by another 0-inf digits, optionally followed by 0-1 a postfix qualifiers
223  return "(\\d*)("+join(allSignatures(), "|")+")(\\d*)"+"("+join(allSignaturePostfixQualifiers(), "|")+")?";
224  }
225 
226  std::vector<int> multiplicities(const std::string &chain)
227  {
228  std::vector<int> multiplicities;
229  for (auto itr = LegInfoIterator(chain); !itr.exhausted(); ++itr) {
230  multiplicities.push_back(itr->multiplicity);
231  if (singleLegIdentifiers().count(itr->signature) == 1)
232  return multiplicities;
233  }
234  return multiplicities;
235  }
236 
237  std::vector<std::string> signatures(const std::string &chain)
238  {
239  std::vector<std::string> signatures;
240  for (auto itr = LegInfoIterator(chain); !itr.exhausted(); ++itr) {
241  signatures.push_back(itr->signature);
242  if (singleLegIdentifiers().count(itr->signature) == 1)
243  return signatures;
244  }
245  return signatures;
246  }
247 
248 } //> end namespace ChainNameParser
249 
xAODType::TrackParticle
@ TrackParticle
The object is a charged track particle.
Definition: ObjectType.h:43
ChainNameParser::allSignatures
const std::vector< std::string > & allSignatures()
A list of all signature names.
Definition: ChainNameParser.cxx:191
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:103
get_generator_info.result
result
Definition: get_generator_info.py:21
ChainNameParser::LegInfoIterator
Iterate over the legs of a chain.
Definition: ChainNameParser.h:36
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:78
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
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::LegInfoIterator::operator*
reference operator*() const
Dereference the iterator.
Definition: ChainNameParser.cxx:98
ChainNameParser::LegInfoIterator::exhausted
bool exhausted() const
Whether the iterator is exhausted.
Definition: ChainNameParser.cxx:140
XMLtoHeader.count
count
Definition: XMLtoHeader.py:84
ChainNameParser
Definition: ChainNameParser.cxx:35
ChainNameParser::LegInfo::threshold
int threshold
The threshold on the object.
Definition: ChainNameParser.h:27
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:92
PrepareReferenceFile.regex
regex
Definition: PrepareReferenceFile.py:43
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
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:88
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:182
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:226
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:29
ChainNameParser::LegInfoIterator::operator!=
bool operator!=(const LegInfoIterator &other) const
Definition: ChainNameParser.cxx:93
ChainNameParser::signatures
std::vector< std::string > signatures(const std::string &chain)
Definition: ChainNameParser.cxx:237
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:17
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:16
ChainNameParser::allSignaturePostfixQualifiers
const std::vector< std::string > & allSignaturePostfixQualifiers()
A list of all post-fix qualifiers which may come immediately after the "XSigY" pattern,...
Definition: ChainNameParser.cxx:203
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
ChainNameParser::LegInfoIterator::m_peekSignature
std::string m_peekSignature
Definition: ChainNameParser.h:77
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:108
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::singleLegIdentifiers
const std::set< std::string > & singleLegIdentifiers()
A set of identifiers which are actually single leg, even if followed by other identifiers.
Definition: ChainNameParser.cxx:211
ChainNameParser::HLTChainInfo::m_chain
std::string m_chain
Definition: ChainNameParser.h:100
ChainNameParser::legHeadPattern
std::string legHeadPattern()
Definition: ChainNameParser.cxx:219
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:145
ChainNameParser::LegInfo::multiplicity
std::size_t multiplicity
The multiplicity of the leg (number of objects returned by the leg)
Definition: ChainNameParser.h:23