ATLAS Offline Software
PhysicsAnalysis/JetTagging/FlavorTagDiscriminants/Root/StringUtils.cxx
Go to the documentation of this file.
2 
3 
4 namespace FlavorTagDiscriminants {
5 namespace str {
6 
7  // remap a variable name while keeping track of which remaps were used
8  const std::string remapName(const std::string& name,
9  std::map<std::string, std::string>& remap,
10  std::set<std::string>& usedRemap) {
11  if (auto h = remap.extract(name)) {
12  usedRemap.insert(h.key());
13  return h.mapped();
14  }
15  return name;
16 }
17 
18  // regex substitution for first match in a variable name
19  std::string sub_first(const StringRegexes& res,
20  const std::string& var_name,
21  const std::string& context) {
22  for (const auto& pair: res) {
23  const std::regex& re = pair.first;
24  const std::string& fmt = pair.second;
25  if (std::regex_match(var_name, re)) {
26  return std::regex_replace(var_name, re, fmt);
27  }
28  }
29  throw std::logic_error(
30  "no regex match found for variable '" + var_name + "' while " + context);
31  }
32 }
33 }
FlavorTagDiscriminants
This file contains "getter" functions used for accessing tagger inputs from the EDM.
Definition: AssociationEnums.h:11
CheckAppliedSFs.var_name
var_name
Definition: CheckAppliedSFs.py:241
PrepareReferenceFile.regex
regex
Definition: PrepareReferenceFile.py:43
FlavorTagDiscriminants::str::sub_first
std::string sub_first(const StringRegexes &res, const std::string &var_name, const std::string &context)
Definition: PhysicsAnalysis/JetTagging/FlavorTagDiscriminants/Root/StringUtils.cxx:19
FlavorTagDiscriminants::str::StringRegexes
std::vector< std::pair< std::regex, std::string > > StringRegexes
Definition: PhysicsAnalysis/JetTagging/FlavorTagDiscriminants/FlavorTagDiscriminants/StringUtils.h:16
res
std::pair< std::vector< unsigned int >, bool > res
Definition: JetGroupProductTest.cxx:14
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
FlavorTagDiscriminants::str::remapName
const std::string remapName(const std::string &name, std::map< std::string, std::string > &remap, std::set< std::string > &usedRemap)
Definition: PhysicsAnalysis/JetTagging/FlavorTagDiscriminants/Root/StringUtils.cxx:8
fmt
h
remap
std::map< std::string, std::string > remap
list of directories to be explicitly remapped
Definition: hcg.cxx:92
re
const boost::regex re(r_e)
str
Definition: BTagTrackIpAccessor.cxx:11
StringUtils.h