ATLAS Offline Software
TrkExToolsStringUtility.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3  */
4 
6 #include <regex>
7 #include <algorithm>
8 #include <functional> //for reference wrapper
9 #include <set>
10 
11 
12 namespace TrkExTools{
13  std::string
14  getToolSuffix(const std::string& fullToolName){
15  return fullToolName.substr(fullToolName.find_last_of('.') + 1);
16  }
17 
18  std::vector<std::string>
19  extractToolNames(const std::vector<std::string> & toolNameVector){
20  std::vector<std::string> result(toolNameVector.size());
21  std::transform(toolNameVector.begin(),toolNameVector.end(),result.begin(), getToolSuffix );
22  return result;
23  }
24 
25  bool
26  validToolName(const std::string & toolName){
27  //valid name can contain underscore or alphanumeric characters, but cannot start
28  //with a number
29  std::regex re{"^[a-zA-Z_][a-zA-Z0-9_]*(::)?[a-zA-Z0-9_]*$"};
30  return std::regex_match(toolName, re);
31  }
32 
33  std::string
34  possibleToolNameError(const std::vector<std::string> & toolNameVector){
35  std::string result{};
36  auto isEmpty = [](const std::string & s){return s.empty();};
37  if (std::any_of(toolNameVector.begin(), toolNameVector.end(), isEmpty) ) return "A tool name was empty.";
38  if (auto pTheTool=std::find_if_not(toolNameVector.begin(), toolNameVector.end(), validToolName); pTheTool != toolNameVector.end()) {
39  result = "A tool name was invalid: " + *pTheTool;
40  }
41  return result;
42  }
43 
44  unsigned int
45  numberOfUniqueEntries(const std::vector<std::string> & nameVector){
46  std::set<std::string> setOfNames(nameVector.begin(), nameVector.end());
47  return setOfNames.size();
48  }
49 
50 
51 
52 }
TrkExTools::getToolSuffix
std::string getToolSuffix(const std::string &fullToolName)
Return the name suffix, e.g. return 'myNiceTool' from 'ToolSvc.myNiceTool'.
Definition: TrkExToolsStringUtility.cxx:14
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
TrkExTools
Definition: TrkExToolsStringUtility.cxx:12
get_generator_info.result
result
Definition: get_generator_info.py:21
TrkExTools::numberOfUniqueEntries
unsigned int numberOfUniqueEntries(const std::vector< std::string > &nameVector)
Give the number of unique entries in a vector.
Definition: TrkExToolsStringUtility.cxx:45
TrkExTools::possibleToolNameError
std::string possibleToolNameError(const std::vector< std::string > &toolNameVector)
Give an error message if tool names are invalid; empty string if good.
Definition: TrkExToolsStringUtility.cxx:34
TrkExTools::extractToolNames
std::vector< std::string > extractToolNames(const std::vector< std::string > &toolNameVector)
return a vector of extracted names
Definition: TrkExToolsStringUtility.cxx:19
PrepareReferenceFile.regex
regex
Definition: PrepareReferenceFile.py:43
TrkExToolsStringUtility.h
namespaced string utilities for TrkExTools
Amg::transform
Amg::Vector3D transform(Amg::Vector3D &v, Amg::Transform3D &tr)
Transform a point from a Trasformation3D.
Definition: GeoPrimitivesHelpers.h:156
TrkExTools::validToolName
bool validToolName(const std::string &toolName)
indicate whether a string is a valid Tool variable name
Definition: TrkExToolsStringUtility.cxx:26
re
const boost::regex re(r_e)