16 #include "boost/algorithm/string.hpp"
17 #include "boost/lexical_cast.hpp"
19 #include <boost/algorithm/string/trim.hpp>
25 std::vector<std::string>
27 std::vector<std::string>
res;
47 for(
size_t i=0;
i<
s.size();
i++)
s[
i] += (
s[
i]>=
'A'&&
s[
i]<=
'Z')?
'a'-
'A':0;
55 parseToken(
const std::string& givenlogic,
56 std::string::size_type&
pos,
57 const std::vector<std::string>& conditions,
58 const std::vector<TrigConf::TriggerThreshold*>& thrs);
62 parseExpr(
const std::string& expr,
63 const std::vector<std::string>& conditions,
64 const std::vector<TrigConf::TriggerThreshold*>& thrs)
68 std::string::size_type
pos = 0;
69 std::string::size_type last = expr.size();
88 if(expr[
pos]==
'&' || expr[
pos]==
'|') {
89 typeFromChar = TriggerItemNode::typeFromChar(expr[
pos]);
91 throw std::logic_error(
string(
"Unexpected character '") + expr[
pos] +
"' in expression '" + expr
101 if(newNode->
type() != typeFromChar) {
102 throw std::logic_error(
string(
"Unexpected character '") + expr[
pos] +
"' in expression '" + expr
104 + TriggerItemNode::typeAsString(newNode->
type()) );
115 std::string getSubExpr(
const std::string &
exp,
const std::string::size_type
begin) {
117 std::string::size_type last =
exp.size();
122 if(
cc==
'(') openBrackets++;
123 if(
cc==
')') openBrackets--;
124 if(openBrackets==0 && (
cc==
'&' or
cc==
'|') )
break;
127 if (openBrackets>0) {
128 std::cout <<
"ERROR: No matching closing bracket in '" <<
exp <<
"'" << std::endl;
138 parseToken(
const std::string& logic,
139 std::string::size_type&
pos,
140 const std::vector<std::string>& conditions,
141 const std::vector<TrigConf::TriggerThreshold*>& thrs) {
164 std::string
se = getSubExpr(logic,
pos);
165 thisNode->addChild(
parse(
se,conditions,thrs) );
171 std::string
se = getSubExpr(logic,
pos);
174 std::string senop(
se, 1,
se.size()-2);
175 thisNode =
parse(senop,conditions,thrs);
178 case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
180 std::string
se = getSubExpr(logic,
pos);
182 uint32_t condIdx = boost::lexical_cast<uint32_t, std::string>(
se);
188 std::string errMsg =
"Unexpected character '";
189 errMsg += logic[
pos];
190 errMsg +=
"' in expression '" + logic +
"' at position" +
std::to_string(
pos) +
" [a]";
191 throw std::logic_error(errMsg);
205 const vector<string>& conditions,
206 const vector<TrigConf::TriggerThreshold*>& thrs) {
211 vector<string> condDef =
split(conditions[condIdx-1],
",");
213 if(condDef.size()==1) {
219 newNode->
setMultiplicity(boost::lexical_cast<int,std::string>(condDef[0]));
221 std::string&
name = condDef[2];
223 std::vector<TrigConf::TriggerThreshold*>::const_iterator thrIt = thrs.begin();
224 for(;thrIt!=thrs.end(); ++thrIt ) {
225 if((*thrIt)->name()==
name) {
236 std::cout <<
"Exeption caught in buildObjNode for " << conditions[condIdx-1] <<
": " <<
e.what() << std::endl;
245 const std::vector<std::string>& conditions,
246 const std::vector<TrigConf::TriggerThreshold*>& thrs) {
270 std::string::size_type
272 const std::string& logic) {
276 std::string::size_type last = logic.size();
277 while(openBrackets>0 &&
pos!=last) {
278 if(logic[
pos]==
')') openBrackets--;
279 if(logic[
pos]==
'(') openBrackets++;
282 if (openBrackets>0) {
283 std::string errMsg =
"No matching closing bracket in '";
286 throw std::logic_error(errMsg);
293 std::string logicWithPars(givenlogic);
294 size_t last = givenlogic.size()-1;
295 bool leadingAnd(
false);
297 char c = logicWithPars[
pos];
299 if(
c==
'&') leadingAnd=
true;
302 logicWithPars.insert(
pos,
")");
303 logicWithPars.insert(0,
"(");
308 return logicWithPars;
316 for(
char c: binary) {