8 #include <boost/regex.hpp>
43 if (!config.
empty()) {
47 if (!myPath.empty()) {
48 init(myPath, triggernames);
78 init (trim(expression),triggernames);
89 if (expression.empty())
94 if (expression.size()==1 && expression.at(0)==
'*') acceptAll_=
true;
95 else acceptAll_=
false;
99 using namespace boost;
101 temp = regex_replace( expression , regex(
".AND."),
"&&");
102 expression_ = regex_replace(
temp, regex(
".and."),
"&&");
103 temp = regex_replace( expression_, regex(
".OR."),
"||");
104 expression_ = regex_replace(
temp, regex(
".or."),
"||");
108 masterElement_.reset(
new TreeElement(expression_,triggernames));
114 std::vector<std::string>
134 unsigned char const* array_of_trigger_results,
135 int number_of_trigger_paths
139 return eventSelector_->acceptEvent(array_of_trigger_results,number_of_trigger_paths);
141 if (acceptAll_)
return true;
147 for (
int pathIndex = 0; pathIndex < number_of_trigger_paths; ++pathIndex)
149 int state = array_of_trigger_results[byteIndex] >> (subIndex * 2);
152 tr[pathIndex] = pathStatus;
161 masterElement_->returnStatus(tr);
162 return masterElement_->returnStatus(tr);
177 parent_ = parentElement;
180 bool occurrences_=
false;
184 <<
"Syntax Error (empty element)" << std::endl;
186 static const size_t bopsSize_ = 2;
187 static const std::string binaryOperators_[bopsSize_] = {
"||",
"&&"};
189 for (
size_t opr=0;opr<bopsSize_;opr++) {
190 bool exitloop_=
false;
195 t_end_ = tmpStr.find(binaryOperators_[opr]);
196 if (debug_)
std::cout <<
"offset: " << offset_ <<
" length: " << t_end_ <<
" string: " << tmpStr << std::endl;
198 if (t_end_ == std::string::npos) {
200 if (occurrences_) children_.push_back(
new TreeElement(tmpStr,tr,
this));
204 if (t_end_==0 || t_end_+2>=str_.size())
209 for (
size_t k=offset_;
k<t_end_;
k++) {
214 else if (str_.at(
k)==
')')
219 <<
"Syntax Error (brackets)\n";
229 children_.push_back(
new TreeElement(next,tr,
this));
236 for (
size_t k=offset_;
true;
k++) {
237 if (
k>=str_.size()) {
240 <<
"Syntax Error (brackets)\n";
243 children_.push_back(
new TreeElement(str_.substr(offset_),tr,
this));
248 if (
k>=t_end_+2 && bracketcnt_==0) {
250 size_t pos = temp.find(binaryOperators_[opr]);
251 if (pos == std::string::npos) {
254 children_.push_back(
new TreeElement(str_.substr(offset_),tr,
this));
260 for (
size_t s=0;
s<pos;
s++) {
262 if (temp.at(pos)==
'(')
266 else if (temp.at(pos)==
')')
271 <<
"Syntax error (brackets)\n";
281 <<
"Syntax error (brackets)\n";
283 children_.push_back(
new TreeElement(str_.substr(offset_,pos+
k),tr,
this));
286 if (offset_>=str_.size())
288 <<
"Syntax Error (operator is not unary)\n";
295 if (str_.at(
k)==
'(') bracketcnt_++;
296 if (str_.at(
k)==
')') bracketcnt_--;
312 if (debug_)
std::cout <<
"warning: empty element (will return true)"<< std::endl;
316 if (str_.at(0)==
'!') {
319 children_.push_back(
new TreeElement(next,tr,
this));
322 size_t beginBlock_ =str_.find(
'(');
323 size_t endBlock_ =str_.rfind(
')');
324 bool found_lbracket = (beginBlock_ != std::string::npos);
325 bool found_rbracket = (endBlock_ != std::string::npos);
327 if (found_lbracket != found_rbracket) {
330 else if (found_lbracket && found_rbracket)
332 if (beginBlock_>=endBlock_) {
335 if (beginBlock_!=0 || endBlock_!=str_.size()-1)
340 children_.push_back(
new TreeElement(next,tr,
this));
344 else if (!found_lbracket && !found_rbracket)
346 bool ignore_if_missing =
true;
347 size_t chr_pos = str_.find(
"@");
348 if (chr_pos!= std::string::npos) {
349 ignore_if_missing=
false;
350 str_=str_.substr(0,chr_pos);
353 std::vector<Strings::const_iterator> matches =
edm::regexMatch(tr,str_);
354 if (matches.empty()) {
355 if (!ignore_if_missing)
359 std::cout <<
"TriggerSelector: Couldn't match any triggers from: "<< str_<< std::endl
360 <<
" Node will not be added "<< std::endl;
365 if (matches.size()==1) {
367 trigBit_ = distance(tr.begin(),matches[0]);
368 if (debug_)
std::cout <<
"added trigger path: " << trigBit_ << std::endl;
371 if (matches.size()>1) {
373 for (
size_t l=0;
l<matches.size();
l++)
374 children_.push_back(
new TreeElement(*(matches[
l]),tr,
this));
384 if (pos != std::string::npos)
387 pos = input.find_last_not_of(
" ");
388 if (pos != std::string::npos)
397 if (!input.empty()) {
398 for (
size_t pos=0;pos<input.size();pos++) {
399 char ch = input.at(pos);
400 if (ch==
'&') output.append(
"&");
401 else output.append(1,ch);
414 if (children_.empty()) {
416 if (op_==OR || op_==NOT)
return false;
417 if (op_==
AND || op_==BR)
return true;
419 if (trigBit_<0 || (
unsigned int)trigBit_>=trStatus.
size())
421 <<
"Internal Error: array out of bounds " << std::endl;
429 return !children_[0]->returnStatus(trStatus);
432 return children_[0]->returnStatus(trStatus);
436 for (
size_t i=0;
i<children_.size();
i++) status = status && children_[
i]->returnStatus(trStatus);
441 for (
size_t i=0;
i<children_.size();
i++) status = status || children_[
i]->returnStatus(trStatus);
451 for (std::vector<TreeElement*>::iterator it=
children_.begin();it!=
children_.end();it++)
T getParameter(std::string const &) const
boost::shared_ptr< TreeElement > masterElement_
static std::string makeXMLString(std::string const &input)
std::vector< std::string > Strings
static const HistoName names[]
void init(std::string const &path, Strings const &triggernames)
boost::shared_ptr< edm::EventSelector > eventSelector_
static std::string const input
bool returnStatus(edm::HLTGlobalStatus const &trStatus) const
unsigned int size() const
Get number of paths stored.
static std::vector< std::string > getEventSelectionVString(edm::ParameterSet const &pset)
TreeElement(std::string const &inputString, Strings const &tr, TreeElement *parentElement=NULL)
std::vector< std::vector< std::string >::const_iterator > regexMatch(std::vector< std::string > const &strings, boost::regex const ®exp)
bool acceptEvent(edm::TriggerResults const &) const
static std::string trim(std::string input)
static std::vector< std::string > getEventSelectionVString(edm::ParameterSet const &pset)
bool AND(const TrackBaseRef &track, const RecoTauQualityCuts::TrackQCutFuncCollection &cuts)
std::vector< TreeElement * > children_
TriggerSelector(Strings const &pathspecs, Strings const &names)