ATLAS Offline Software
Loading...
Searching...
No Matches
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
12namespace 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}
const boost::regex re(r_e)
namespaced string utilities for TrkExTools
bool validToolName(const std::string &toolName)
indicate whether a string is a valid Tool variable name
std::vector< std::string > extractToolNames(const std::vector< std::string > &toolNameVector)
return a vector of extracted names
std::string getToolSuffix(const std::string &fullToolName)
Return the name suffix, e.g. return 'myNiceTool' from 'ToolSvc.myNiceTool'.
unsigned int numberOfUniqueEntries(const std::vector< std::string > &nameVector)
Give the number of unique entries in a vector.
std::string possibleToolNameError(const std::vector< std::string > &toolNameVector)
Give an error message if tool names are invalid; empty string if good.