16 #include "boost/algorithm/string.hpp"
17 #include "boost/lexical_cast.hpp"
19 #include <boost/algorithm/string/trim.hpp>
20 #include <boost/algorithm/string/erase.hpp>
26 std::vector<std::string>
28 std::vector<std::string>
res;
41 boost::algorithm::erase_all(
str,
" ");
54 for(
size_t i=0;
i<
s.size();
i++)
s[
i] += (
s[
i]>=
'A'&&
s[
i]<=
'Z')?
'a'-
'A':0;
62 parseToken(
const std::string& givenlogic,
63 std::string::size_type&
pos,
64 const std::vector<std::string>& conditions,
65 const std::vector<TrigConf::TriggerThreshold*>& thrs);
69 parseExpr(
const std::string& expr,
70 const std::vector<std::string>& conditions,
71 const std::vector<TrigConf::TriggerThreshold*>& thrs)
75 std::string::size_type
pos = 0;
76 std::string::size_type last = expr.size();
95 if(expr[
pos]==
'&' || expr[
pos]==
'|') {
96 typeFromChar = TriggerItemNode::typeFromChar(expr[
pos]);
98 throw std::logic_error(
string(
"Unexpected character '") + expr[
pos] +
"' in expression '" + expr
99 +
"' at position" + boost::lexical_cast<std::string,int>(
pos) +
" [b]");
108 if(newNode->
type() != typeFromChar) {
109 throw std::logic_error(
string(
"Unexpected character '") + expr[
pos] +
"' in expression '" + expr
110 +
"' at position" + boost::lexical_cast<std::string,int>(
pos) +
" [c] Expected "
111 + TriggerItemNode::typeAsString(newNode->
type()) );
122 std::string getSubExpr(
const std::string &
exp,
const std::string::size_type
begin) {
124 std::string::size_type last =
exp.size();
129 if(
cc==
'(') openBrackets++;
130 if(
cc==
')') openBrackets--;
131 if(openBrackets==0 && (
cc==
'&' or
cc==
'|') )
break;
134 if (openBrackets>0) {
135 std::cout <<
"ERROR: No matching closing bracket in '" <<
exp <<
"'" << std::endl;
145 parseToken(
const std::string& logic,
146 std::string::size_type&
pos,
147 const std::vector<std::string>& conditions,
148 const std::vector<TrigConf::TriggerThreshold*>& thrs) {
171 std::string
se = getSubExpr(logic,
pos);
172 thisNode->addChild(
parse(
se,conditions,thrs) );
178 std::string
se = getSubExpr(logic,
pos);
181 std::string senop(
se, 1,
se.size()-2);
182 thisNode =
parse(senop,conditions,thrs);
185 case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
187 std::string
se = getSubExpr(logic,
pos);
189 uint32_t condIdx = boost::lexical_cast<uint32_t, std::string>(
se);
195 std::string errMsg =
"Unexpected character '";
196 errMsg += logic[
pos];
197 errMsg +=
"' in expression '" + logic +
"' at position" + boost::lexical_cast<std::string,int>(
pos) +
" [a]";
198 throw std::logic_error(errMsg);
212 const vector<string>& conditions,
213 const vector<TrigConf::TriggerThreshold*>& thrs) {
218 vector<string> condDef =
split(conditions[condIdx-1],
",");
220 if(condDef.size()==1) {
226 newNode->
setMultiplicity(boost::lexical_cast<int,std::string>(condDef[0]));
228 std::string&
name = condDef[2];
230 std::vector<TrigConf::TriggerThreshold*>::const_iterator thrIt = thrs.begin();
231 for(;thrIt!=thrs.end(); ++thrIt ) {
232 if((*thrIt)->name()==
name) {
243 std::cout <<
"Exeption caught in buildObjNode for " << conditions[condIdx-1] <<
": " <<
e.what() << std::endl;
252 const std::vector<std::string>& conditions,
253 const std::vector<TrigConf::TriggerThreshold*>& thrs) {
277 std::string::size_type
279 const std::string& logic) {
283 std::string::size_type last = logic.size();
284 while(openBrackets>0 &&
pos!=last) {
285 if(logic[
pos]==
')') openBrackets--;
286 if(logic[
pos]==
'(') openBrackets++;
289 if (openBrackets>0) {
290 std::string errMsg =
"No matching closing bracket in '";
293 throw std::logic_error(errMsg);
300 std::string logicWithPars(givenlogic);
301 size_t last = givenlogic.size()-1;
302 bool leadingAnd(
false);
304 char c = logicWithPars[
pos];
306 if(
c==
'&') leadingAnd=
true;
309 logicWithPars.insert(
pos,
")");
310 logicWithPars.insert(0,
"(");
315 return logicWithPars;
323 for(
char c: binary) {