16#include "boost/algorithm/string.hpp"
18#include <boost/algorithm/string/trim.hpp>
24std::vector<std::string>
26 std::vector<std::string>
res;
27 boost::split(
res, line, boost::is_any_of(del));
34 boost::algorithm::trim(
str);
39 std::replace(
str.begin(),
str.end(),
'\t',
' ');
46 for(
size_t i=0; i<s.size(); i++) s[i] += (s[i]>=
'A'&&s[i]<=
'Z')?
'a'-
'A':0;
54 parseToken(
const std::string& givenlogic,
55 std::string::size_type& pos,
56 const std::vector<std::string>& conditions,
57 const std::vector<TrigConf::TriggerThreshold*>& thrs);
61 parseExpr(
const std::string& expr,
62 const std::vector<std::string>& conditions,
63 const std::vector<TrigConf::TriggerThreshold*>& thrs)
67 std::string::size_type pos = 0;
68 std::string::size_type last = expr.size();
87 if(expr[pos]==
'&' || expr[pos]==
'|') {
90 throw std::logic_error(
string(
"Unexpected character '") + expr[pos] +
"' in expression '" + expr
91 +
"' at position" + std::to_string(pos) +
" [b]");
100 if(newNode->
type() != typeFromChar) {
101 throw std::logic_error(
string(
"Unexpected character '") + expr[pos] +
"' in expression '" + expr
102 +
"' at position" + std::to_string(pos) +
" [c] Expected "
114 std::string getSubExpr(
const std::string &exp,
const std::string::size_type begin) {
116 std::string::size_type last =
exp.size();
121 if(cc==
'(') openBrackets++;
122 if(cc==
')') openBrackets--;
123 if(openBrackets==0 && (cc==
'&' or cc==
'|') )
break;
126 if (openBrackets>0) {
127 std::cout <<
"ERROR: No matching closing bracket in '" <<
exp <<
"'" << std::endl;
130 std::string
se(exp, begin, pos-begin);
137 parseToken(
const std::string& logic,
138 std::string::size_type& pos,
139 const std::vector<std::string>& conditions,
140 const std::vector<TrigConf::TriggerThreshold*>& thrs) {
163 std::string
se = getSubExpr(logic,pos);
164 thisNode->addChild(
parse(se,conditions,thrs) );
170 std::string
se = getSubExpr(logic,pos);
173 std::string senop(se, 1,
se.size()-2);
174 thisNode =
parse(senop,conditions,thrs);
177 case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
179 std::string
se = getSubExpr(logic,pos);
187 std::string errMsg =
"Unexpected character '";
188 errMsg += logic[
pos];
189 errMsg +=
"' in expression '" + logic +
"' at position" + std::to_string(pos) +
" [a]";
190 throw std::logic_error(errMsg);
204 const vector<string>& conditions,
205 const vector<TrigConf::TriggerThreshold*>& thrs) {
210 vector<string> condDef =
split(conditions[condIdx-1],
",");
212 if(condDef.size()==1) {
220 std::string&
name = condDef[2];
222 std::vector<TrigConf::TriggerThreshold*>::const_iterator thrIt = thrs.begin();
223 for(;thrIt!=thrs.end(); ++thrIt ) {
224 if((*thrIt)->name()==
name) {
234 catch(
const std::exception& e) {
235 std::cout <<
"Exeption caught in buildObjNode for " << conditions[condIdx-1] <<
": " << e.what() << std::endl;
244 const std::vector<std::string>& conditions,
245 const std::vector<TrigConf::TriggerThreshold*>& thrs) {
269std::string::size_type
271 const std::string& logic) {
274 uint32_t openBrackets = 1;
275 std::string::size_type last = logic.size();
276 while(openBrackets>0 && pos!=last) {
277 if(logic[pos]==
')') openBrackets--;
278 if(logic[pos]==
'(') openBrackets++;
281 if (openBrackets>0) {
282 std::string errMsg =
"No matching closing bracket in '";
285 throw std::logic_error(errMsg);
292 std::string logicWithPars(givenlogic);
293 size_t last = givenlogic.size()-1;
294 bool leadingAnd(
false);
295 for(
size_t pos = 0;pos<last;pos++) {
296 char c = logicWithPars[pos];
298 if(c==
'&') leadingAnd=
true;
301 logicWithPars.insert(pos,
")");
302 logicWithPars.insert(0,
"(");
307 return logicWithPars;
315 for(
char c: binary) {
317 if(c==
'1') value += 1;
326 for(uint32_t mask = 1 << (
width-1); mask>0; mask>>=1)
327 ss << ( (value & mask) == 0 ?
'0' :
'1' );
std::pair< std::vector< unsigned int >, bool > res
static NodeType typeFromChar(const char &c)
void setMultiplicity(int mult)
static std::string typeAsString(NodeType)
void setInternalTrigger(L1DataDef::TriggerType x, unsigned int thresholdNumber)
void addChild(TriggerItemNode *node)
void setTriggerThreshold(TriggerThreshold *thr)
void setThresholdName(const std::string &thrname)
Forward iterator to traverse the main components of the trigger configuration.
std::string uint2bin(uint32_t uinteger, uint16_t width)
std::string insertParenthesis(const std::string &givenlogic)
void replaceTabs(std::string &str)
std::string::size_type findClosingBracket(std::string::size_type pos, const std::string &logic)
uint32_t bin2uint(const std::string &binary)
void toLower(std::string &)
std::vector< std::string > split(const std::string &line, const std::string &del=" ")
TrigConf::TriggerItemNode * buildObjNode(uint32_t condIdx, const std::vector< std::string > &conditions, const std::vector< TrigConf::TriggerThreshold * > &thrs)
std::vector< std::string > parse(std::string names)
void strip(std::string &str)