Belle II Software light-2406-ragdoll
MakeROOTCompatible Class Reference

Helper class for converting strings into a ROOT-friendly format (e.g.: removing special characters in branch names, etc.) More...

#include <MakeROOTCompatible.h>

Static Public Member Functions

static std::string makeROOTCompatible (std::string str)
 Remove special characters that ROOT dislikes in branch names, e.g.
 
static std::string invertMakeROOTCompatible (std::string str)
 Invert makeROOTCompatible operation.
 
static std::map< std::string, std::string > getSubstitutionMap ()
 Substituation map for makeROOTCompatible.
 

Detailed Description

Helper class for converting strings into a ROOT-friendly format (e.g.: removing special characters in branch names, etc.)

Definition at line 24 of file MakeROOTCompatible.h.

Member Function Documentation

◆ getSubstitutionMap()

std::map< std::string, std::string > getSubstitutionMap ( )
static

Substituation map for makeROOTCompatible.

Definition at line 18 of file MakeROOTCompatible.cc.

19{
20 return std::map<std::string, std::string> {
21 {" ", "__sp"},
22 {",", "__cm"},
23 {":", "__cl"},
24 {"=", "__eq"},
25 {"<", "__st"},
26 {">", "__gt"},
27 {".", "__pt"},
28 {"+", "__pl"},
29 {"-", "__mi"},
30 {"(", "__bo"},
31 {")", "__bc"},
32 {"{", "__co"},
33 {"}", "__cc"},
34 {"[", "__so"},
35 {"]", "__sc"},
36 {"`", "__to"},
37 {"´", "__tc"},
38 {"^", "__ha"},
39 {"°", "__ci"},
40 {"$", "__do"},
41 {"§", "__pa"},
42 {"%", "__pr"},
43 {"!", "__em"},
44 {"?", "__qm"},
45 {";", "__sm"},
46 {"#", "__hs"},
47 {"*", "__mu"},
48 {"/", "__sl"},
49 {"\\", "__bl"},
50 {"'", "__sq"},
51 {"\"", "__dq"},
52 {"~", "__ti"},
53 {"-", "__da"},
54 {"|", "__pi"},
55 {"&", "__am"},
56 {"@", "__at"},
57 };
58}

◆ invertMakeROOTCompatible()

std::string invertMakeROOTCompatible ( std::string  str)
static

Invert makeROOTCompatible operation.

Definition at line 75 of file MakeROOTCompatible.cc.

76{
77 auto replace = getSubstitutionMap();
78 for (auto& pair : replace) {
79 boost::replace_all(str, pair.second, pair.first);
80 }
81 return str;
82}
static std::map< std::string, std::string > getSubstitutionMap()
Substituation map for makeROOTCompatible.

◆ makeROOTCompatible()

std::string makeROOTCompatible ( std::string  str)
static

Remove special characters that ROOT dislikes in branch names, e.g.

(, ), :, etc

Definition at line 60 of file MakeROOTCompatible.cc.

61{
62 if (str.find("__") != std::string::npos) {
63 B2WARNING("String passed to makeROOTCompatible contains double-underscore __, which is used internally for escaping special characters. "
64 "It is recommended to avoid this. However escaping a string twice with makeROOTCompatible is safe, but will print this warning. "
65 "Passed string: " + str);
66 }
67 auto replace = getSubstitutionMap();
68 for (auto& pair : replace) {
69 boost::replace_all(str, pair.first, pair.second);
70 }
71 const static std::regex blackList("[^a-zA-Z0-9_]");
72 return std::regex_replace(str, blackList, "");
73}

The documentation for this class was generated from the following files: