-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFWDataCollection.h
154 lines (138 loc) · 4.07 KB
/
FWDataCollection.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#ifndef FWVCollection_h
#define FWVCollection_h
#include "ROOT/REveDataCollection.hxx"
#include "ROOT/REveDataProxyBuilderBase.hxx"
#include "nlohmann/json.hpp"
class FWDataCollection : public ROOT::Experimental::REveDataCollection
{
private:
ROOT::Experimental::REveDataProxyBuilderBase *m_builder{nullptr};
public:
FWDataCollection(const std::string &n = "FWDataCollection", const std::string &varconfig = "") : ROOT::Experimental::REveDataCollection(n, "")
{
if (varconfig.empty())
{
m_config = nlohmann::json::array();
}
else
{
m_config = nlohmann::json::parse(varconfig);
}
}
~FWDataCollection() override {}
// config handling
nlohmann::json m_config;
bool hasConfigWithName(const std::string &n)
{
for (auto &elem : m_config)
{
std::string cfgn = elem["name"];
if (cfgn == n)
return true;
}
return false;
}
void assertParamter(nlohmann::json j)
{
if (hasConfigWithName(j["name"]))
return;
m_config.push_back(j);
}
void setGLBuilder(ROOT::Experimental::REveDataProxyBuilderBase *ib)
{
m_builder = ib;
}
int WriteCoreJson(nlohmann::json &j, int rnr_offset) override
{
int res = REveDataCollection::WriteCoreJson(j, -1);
j["var"] = m_config;
return res;
}
void UpdatePBParameter(char *name, char *val)
{
printf("Udate PB paramter %s %s \n", name, val);
std::string ssn = name;
for (auto &elem : m_config)
{
std::string confn = elem["name"];
if (confn == ssn)
{
std::cout << "match " << elem.dump(3) << "\n";
std::string typen = elem["type"];
if (typen == "Bool")
{
int x = strcmp(val, "true");
elem["val"] = (x == 0);
}
else if (typen == "Long")
{
char *eptr;
long x = strtol(val, &eptr, 10);
if (errno == EINVAL)
{
printf("Conversion error occurred: %d\n", errno);
return;
}
else
{
elem["val"] = x;
}
}
}
}
StampObjProps();
if (m_builder)
m_builder->Build();
}
long getLongParameter(const std::string &name)
{
for (auto &elem : m_config)
{
std::string confn = elem["name"];
if (confn == name)
{
// std::cout << "match " << elem.dump(3) << "\n";
std::string typen = elem["type"];
if (typen == "Long")
{
/*
const char* val = elem["val"];
char *eptr;
long x = strtol(val, &eptr, 10);
if (errno == EINVAL)
{
printf("Conversion error occurred: %d\n", errno);
return;
}
return x;*/
return elem["val"];
}
}
}
printf("can't locate long paramter\n");
return 0;
}
bool getBoolParameter(const std::string &name)
{
for (auto &elem : m_config)
{
std::string confn = elem["name"];
if (confn == name)
{
// std::cout << "gert bool match " << elem.dump(3) << "\n";
std::string typen = elem["type"];
/*
const char* val = elem["val"];
if (typen == "Bool")
{
int x = strcmp("val", "true");
return x;
}*/
return elem["val"];
}
}
printf("can't locate bool paramter\n");
return false;
}
};
#endif