ATLAS Offline Software
Loading...
Searching...
No Matches
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
14namespace
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 {
30 const static std::regex re(ChainNameParser::legHeadPattern());
31 return re;
32 }
33}
34
35namespace ChainNameParser {
36
37 std::string LegInfo::legName() const
38 {
39 std::string result;
40 if (multiplicity != 1)
41 result += std::to_string(multiplicity);
43 if (threshold != -1)
44 result += std::to_string(threshold);
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())
56 else
57 return xAODType::Electron;
58 }
59 else if (signature == "g")
60 {
61 if (std::find(legParts.begin(), legParts.end(), "etcut") != legParts.end())
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
78 LegInfoIterator::LegInfoIterator(const std::string &chain) :
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
102
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();
117 m_peekThreshold = -1;
118 }
119 else
120 {
121 // Copy the peeked information into the current info
122 m_current.multiplicity = m_peekMultiplicity;
123 m_current.signature = m_peekSignature;
124 m_current.threshold = m_peekThreshold;
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())
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
const boost::regex re(r_e)
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.
Iterate over the legs of a chain.
bool exhausted() const
Whether the iterator is exhausted.
LegInfoIterator & operator++()
pre-increment operator
LegInfoIterator()=default
Default constructor creates a past-the-end iterator.
std::string::const_iterator m_itr
reference operator*() const
Dereference the iterator.
std::string::const_iterator m_end
bool operator!=(const LegInfoIterator &other) const
bool operator==(const LegInfoIterator &other) const
Check (in)equality against another iterator.
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:146
bool match(std::string s1, std::string s2)
match the individual directories of two strings
Definition hcg.cxx:357
const std::set< std::string > & singleLegIdentifiers()
A set of identifiers which are actually single leg, even if followed by other identifiers.
std::vector< int > multiplicities(const std::string &chain)
const std::vector< std::string > & allSignatures()
A list of all signature names.
std::string legHeadPattern()
const std::vector< std::string > & allSignaturePostfixQualifiers()
A list of all post-fix qualifiers which may come immediately after the "XSigY" pattern,...
std::vector< std::string > signatures(const std::string &chain)
std::string join(const std::vector< std::string > &v, const char c=',')
ObjectType
Type of objects that have a representation in the xAOD EDM.
Definition ObjectType.h:32
@ TrackParticle
The object is a charged track particle.
Definition ObjectType.h:43
@ Jet
The object is a jet.
Definition ObjectType.h:40
@ Photon
The object is a photon.
Definition ObjectType.h:47
@ Other
An object not falling into any of the other categories.
Definition ObjectType.h:34
@ CaloCluster
The object is a calorimeter cluster.
Definition ObjectType.h:39
@ Muon
The object is a muon.
Definition ObjectType.h:48
@ Electron
The object is an electron.
Definition ObjectType.h:46
@ Tau
The object is a tau (jet)
Definition ObjectType.h:49
std::size_t multiplicity
The multiplicity of the leg (number of objects returned by the leg)
xAODType::ObjectType type() const
The type of xAOD IParticle produced by this signature if relevant.
std::vector< std::string > legParts
All the parts of the leg.
std::string legName() const
The name of the leg.
int threshold
The threshold on the object.
std::string signature
The HLT signature responsible for creating the object.