Skip to content

Commit 7129f45

Browse files
aalkinktf
authored andcommitted
DPL Analysis: add parsing of expressions from strings
1 parent 6209646 commit 7129f45

File tree

5 files changed

+856
-157
lines changed

5 files changed

+856
-157
lines changed

Framework/Core/include/Framework/BasicOps.h

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
// or submit itself to any jurisdiction.
1111
#ifndef O2_FRAMEWORK_BASICOPS_H_
1212
#define O2_FRAMEWORK_BASICOPS_H_
13+
#include <array>
14+
#include <string_view>
15+
#include "CommonConstants/MathConstants.h"
1316

1417
namespace o2::framework
1518
{
@@ -46,6 +49,61 @@ enum BasicOp : unsigned int {
4649
BitwiseNot,
4750
Conditional // 3-ar functions
4851
};
52+
53+
static constexpr std::array<std::string_view, BasicOp::Conditional + 1> mapping{
54+
"&&",
55+
"||",
56+
"+",
57+
"-",
58+
"/",
59+
"*",
60+
"&",
61+
"|",
62+
"^",
63+
"<",
64+
"<=",
65+
">",
66+
">=",
67+
"==",
68+
"!=",
69+
"natan2",
70+
"npow",
71+
"nsqrt",
72+
"nexp",
73+
"nlog",
74+
"nlog10",
75+
"nsin",
76+
"ncos",
77+
"ntan",
78+
"nasin",
79+
"nacos",
80+
"natan",
81+
"nabs",
82+
"nround",
83+
"nbitwise_not",
84+
"ifnode"};
85+
86+
static constexpr std::array<std::string_view, 9> mathConstants{
87+
"Almost0",
88+
"Epsilon",
89+
"Almost1",
90+
"VeryBig",
91+
"PI",
92+
"TwoPI",
93+
"PIHalf",
94+
"PIThird",
95+
"PIQuarter"};
96+
97+
static constexpr std::array<float, 9> mathConstantsValues{
98+
o2::constants::math::Almost0,
99+
o2::constants::math::Epsilon,
100+
o2::constants::math::Almost1,
101+
o2::constants::math::VeryBig,
102+
o2::constants::math::PI,
103+
o2::constants::math::TwoPI,
104+
o2::constants::math::PIHalf,
105+
o2::constants::math::PIThird,
106+
o2::constants::math::PIQuarter};
49107
} // namespace o2::framework
50108

51109
#endif // O2_FRAMEWORK_BASICOPS_H_

Framework/Core/include/Framework/ExpressionHelpers.h

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,26 @@ struct DatumSpec {
2525
size_t hash = 0;
2626
atype::type type = atype::NA;
2727

28-
explicit DatumSpec(size_t index, atype::type type_) : datum{index}, type{type_} {}
29-
explicit DatumSpec(LiteralNode::var_t literal, atype::type type_) : datum{literal}, type{type_} {}
30-
explicit DatumSpec(std::string binding, size_t hash_, atype::type type_) : datum{binding}, hash{hash_}, type{type_} {}
28+
explicit constexpr DatumSpec(size_t index, atype::type type_) : datum{index}, type{type_} {}
29+
explicit constexpr DatumSpec(LiteralNode::var_t literal, atype::type type_) : datum{literal}, type{type_} {}
30+
explicit constexpr DatumSpec(std::string binding, size_t hash_, atype::type type_) : datum{binding}, hash{hash_}, type{type_} {}
3131
DatumSpec() = default;
3232
DatumSpec(DatumSpec const&) = default;
3333
DatumSpec(DatumSpec&&) = default;
3434
DatumSpec& operator=(DatumSpec const&) = default;
3535
DatumSpec& operator=(DatumSpec&&) = default;
36-
};
3736

38-
bool operator==(DatumSpec const& lhs, DatumSpec const& rhs);
37+
bool operator==(DatumSpec const& rhs) const
38+
{
39+
bool eqValue = this->datum == rhs.datum;
40+
bool eqHash = true;
41+
if (this->datum.index() == 3 && eqValue) {
42+
eqHash = this->hash == rhs.hash;
43+
}
44+
bool eqType = this->type == rhs.type;
45+
return eqValue && eqHash && eqType;
46+
}
47+
};
3948

4049
std::ostream& operator<<(std::ostream& os, DatumSpec const& spec);
4150

0 commit comments

Comments
 (0)