Belle II Software light-2406-ragdoll
make_root_compatible.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8#include <framework/utilities/TestHelpers.h>
9#include <framework/utilities/MakeROOTCompatible.h>
10
11#include <gtest/gtest.h>
12
13using namespace std;
14using namespace Belle2;
15
16namespace {
17
18 TEST(VariableTest, makeROOTCompatible)
19 {
21 EXPECT_EQ("test", MakeROOTCompatible::makeROOTCompatible("test"));
22 EXPECT_EQ("test213", MakeROOTCompatible::makeROOTCompatible("test213"));
23 EXPECT_EQ("test_23", MakeROOTCompatible::makeROOTCompatible("test_23"));
24
26 EXPECT_EQ("test", MakeROOTCompatible::makeROOTCompatible("test"));
27 EXPECT_EQ("test213", MakeROOTCompatible::makeROOTCompatible("test213"));
28 EXPECT_EQ("test_23", MakeROOTCompatible::makeROOTCompatible("test_23"));
29
30 EXPECT_EQ("test__bo23__bc", MakeROOTCompatible::makeROOTCompatible("test(23)"));
31 EXPECT_EQ("test__so23__sc", MakeROOTCompatible::makeROOTCompatible("test[23]"));
32 EXPECT_EQ("test__co23__cc", MakeROOTCompatible::makeROOTCompatible("test{23}"));
33 EXPECT_EQ("test__boe__pl__clgamma__cm__spM__sp__st__sp3__bc", MakeROOTCompatible::makeROOTCompatible("test(e+:gamma, M < 3)"));
34 EXPECT_EQ("__cl__bo__bc__sp__bo__bc__cm", MakeROOTCompatible::makeROOTCompatible(":() (),"));
35 EXPECT_EQ("c__cl__bo__bcb__sp__bo__bc__cma", MakeROOTCompatible::makeROOTCompatible("c:()b (),a"));
36 EXPECT_EQ("c__cl__bo__cm__pl8951aBZWVZUEOH_Rhtnsq__bcb__sp__bo__bc__cma",
37 MakeROOTCompatible::makeROOTCompatible("c:(,+8951aBZWVZUEOH_Rhtnsq)b (),a"));
38 EXPECT_EQ("foo__bobar__cm__mi0__pt123__cm__sp94__bc", MakeROOTCompatible::makeROOTCompatible("foo(bar,-0.123, 94)"));
39
40 for (const auto& pair : MakeROOTCompatible::getSubstitutionMap()) {
41 EXPECT_EQ(pair.second, MakeROOTCompatible::makeROOTCompatible(pair.first));
42 }
43
44 EXPECT_NO_B2WARNING(MakeROOTCompatible::makeROOTCompatible("test_a"));
45 EXPECT_B2WARNING(MakeROOTCompatible::makeROOTCompatible("test__a"));
46 }
47
48 TEST(VariableTest, invertMakeROOTCompatible)
49 {
51 EXPECT_EQ(MakeROOTCompatible::invertMakeROOTCompatible("test"), "test");
52 EXPECT_EQ(MakeROOTCompatible::invertMakeROOTCompatible("test213"), "test213");
53 EXPECT_EQ(MakeROOTCompatible::invertMakeROOTCompatible("test_23"), "test_23");
54
56 EXPECT_EQ(MakeROOTCompatible::invertMakeROOTCompatible("test"), "test");
57 EXPECT_EQ(MakeROOTCompatible::invertMakeROOTCompatible("test213"), "test213");
58 EXPECT_EQ(MakeROOTCompatible::invertMakeROOTCompatible("test_23"), "test_23");
59
60 EXPECT_EQ(MakeROOTCompatible::invertMakeROOTCompatible("test__bo23__bc"), "test(23)");
61 EXPECT_EQ(MakeROOTCompatible::invertMakeROOTCompatible("test__so23__sc"), "test[23]");
62 EXPECT_EQ(MakeROOTCompatible::invertMakeROOTCompatible("test__co23__cc"), "test{23}");
63 EXPECT_EQ(MakeROOTCompatible::invertMakeROOTCompatible("test__boe__pl__clgamma__cm__spM__sp__st__sp3__bc"),
64 "test(e+:gamma, M < 3)");
65 EXPECT_EQ(MakeROOTCompatible::invertMakeROOTCompatible("__cl__bo__bc__sp__bo__bc__cm"), ":() (),");
66 EXPECT_EQ(MakeROOTCompatible::invertMakeROOTCompatible("c__cl__bo__bcb__sp__bo__bc__cma"), "c:()b (),a");
67 EXPECT_EQ(MakeROOTCompatible::invertMakeROOTCompatible("c__cl__bo__cm__pl8951aBZWVZUEOH_Rhtnsq__bcb__sp__bo__bc__cma"),
68 "c:(,+8951aBZWVZUEOH_Rhtnsq)b (),a");
69 EXPECT_EQ(MakeROOTCompatible::invertMakeROOTCompatible("foo__bobar__cm__mi0__pt123__cm__sp94__bc"), "foo(bar,-0.123, 94)");
70
71 for (const auto& pair : MakeROOTCompatible::getSubstitutionMap()) {
72 EXPECT_EQ(pair.first, MakeROOTCompatible::invertMakeROOTCompatible(pair.second));
73 }
74 }
75
76}
static std::map< std::string, std::string > getSubstitutionMap()
Substituation map for makeROOTCompatible.
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.
Abstract base class for different kinds of events.
Definition: ClusterUtils.h:24
STL namespace.