10#include <boost/algorithm/string/trim.hpp>
11#include "boost/algorithm/string.hpp"
26std::vector<std::string>
28 std::vector<std::string>
res;
29 boost::split(
res, line, boost::is_any_of(del));
36 boost::algorithm::trim(
str);
41 std::replace(
str.begin(),
str.end(),
'\t',
' ');
48 for(
size_t i=0; i<s.size(); i++) s[i] += (s[i]>=
'A'&&s[i]<=
'Z')?
'a'-
'A':0;
56 parseToken(
const std::string& givenlogic,
57 std::string::size_type& pos,
58 const std::vector<std::string>& conditions,
59 const std::vector<TrigConf::TriggerThreshold*>& thrs);
63 parseExpr(
const std::string& expr,
64 const std::vector<std::string>& conditions,
65 const std::vector<TrigConf::TriggerThreshold*>& thrs)
69 std::string::size_type pos = 0;
70 std::string::size_type last = expr.size();
89 if(expr[pos]==
'&' || expr[pos]==
'|') {
92 throw std::logic_error(
string(
"Unexpected character '") + expr[pos] +
"' in expression '" + expr
93 +
"' at position" + std::to_string(pos) +
" [b]");
102 if(newNode->
type() != typeFromChar) {
103 throw std::logic_error(
string(
"Unexpected character '") + expr[pos] +
"' in expression '" + expr
104 +
"' at position" + std::to_string(pos) +
" [c] Expected "
116 std::string getSubExpr(
const std::string &exp,
const std::string::size_type begin) {
118 std::string::size_type last =
exp.size();
120 int openBrackets = 0;
123 if(cc==
'(') openBrackets++;
124 if(cc==
')') openBrackets--;
125 if(openBrackets==0 && (cc==
'&' or cc==
'|') )
break;
128 if (openBrackets>0) {
129 std::cout <<
"ERROR: No matching closing bracket in '" <<
exp <<
"'" << std::endl;
132 std::string
se(exp, begin, pos-begin);
139 parseToken(
const std::string& logic,
140 std::string::size_type& pos,
141 const std::vector<std::string>& conditions,
142 const std::vector<TrigConf::TriggerThreshold*>& thrs) {
165 std::string
se = getSubExpr(logic,pos);
166 thisNode->addChild(
parse(se,conditions,thrs) );
172 std::string
se = getSubExpr(logic,pos);
175 std::string senop(se, 1,
se.size()-2);
176 thisNode =
parse(senop,conditions,thrs);
179 case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
181 std::string
se = getSubExpr(logic,pos);
189 std::string errMsg =
"Unexpected character '";
190 errMsg += logic[
pos];
191 errMsg +=
"' in expression '" + logic +
"' at position" + std::to_string(pos) +
" [a]";
192 throw std::logic_error(errMsg);
206 const vector<string>& conditions,
207 const vector<TrigConf::TriggerThreshold*>& thrs) {
212 vector<string> condDef =
split(conditions[condIdx-1],
",");
214 if(condDef.size()==1) {
222 std::string&
name = condDef[2];
224 std::vector<TrigConf::TriggerThreshold*>::const_iterator thrIt = thrs.begin();
225 for(;thrIt!=thrs.end(); ++thrIt ) {
226 if((*thrIt)->name()==
name) {
236 catch(
const std::exception& e) {
237 std::cout <<
"Exeption caught in buildObjNode for " << conditions[condIdx-1] <<
": " << e.what() << std::endl;
246 const std::vector<std::string>& conditions,
247 const std::vector<TrigConf::TriggerThreshold*>& thrs) {
271std::string::size_type
273 const std::string& logic) {
276 uint32_t openBrackets = 1;
277 std::string::size_type last = logic.size();
278 while(openBrackets>0 && pos!=last) {
279 if(logic[pos]==
')') openBrackets--;
280 if(logic[pos]==
'(') openBrackets++;
283 if (openBrackets>0) {
284 std::string errMsg =
"No matching closing bracket in '";
287 throw std::logic_error(errMsg);
294 std::string logicWithPars(givenlogic);
295 size_t last = givenlogic.size()-1;
296 bool leadingAnd(
false);
297 for(
size_t pos = 0;pos<last;pos++) {
298 char c = logicWithPars[pos];
300 if(c==
'&') leadingAnd=
true;
303 logicWithPars.insert(pos,
")");
304 logicWithPars.insert(0,
"(");
309 return logicWithPars;
316 auto [ptr, ec] = std::from_chars(binary.data(),
317 binary.data() + binary.size(), value, 2);
318 if (ec != std::errc{} || ptr != binary.data() + binary.size()) {
319 throw std::invalid_argument(
"Invalid binary string");
327 std::string s(
width,
'0');
328 for (uint16_t i = 0; i <
width; ++i) {
329 s[
width - 1 - i] =
'0' + ((value >> i) & 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)