11 #include <boost/regex.hpp>
45 if (!config.
empty()) {
49 std::string myPath = trim(config.
getParameter<std::string>(
"TriggerSelector"));
50 if (!myPath.empty()) {
51 init(myPath, triggernames);
76 std::string
const & expression,
81 init (trim(expression),triggernames);
87 std::string
const& expression,
92 if (expression.empty())
97 if (expression.size()==1 && expression.at(0)==
'*') acceptAll_=
true;
98 else acceptAll_=
false;
102 using namespace boost;
104 temp = regex_replace( expression , regex(
".AND."),
"&&");
105 expression_ = regex_replace(
temp, regex(
".and."),
"&&");
106 temp = regex_replace( expression_, regex(
".OR."),
"||");
107 expression_ = regex_replace(
temp, regex(
".or."),
"||");
111 masterElement_.reset(
new TreeElement(expression_,triggernames));
117 std::vector<std::string>
137 unsigned char const* array_of_trigger_results,
138 int number_of_trigger_paths
143 return eventSelector_->acceptEvent(array_of_trigger_results,number_of_trigger_paths);
145 if (acceptAll_)
return true;
151 for (
int pathIndex = 0; pathIndex < number_of_trigger_paths; ++pathIndex)
153 int state = array_of_trigger_results[byteIndex] >> (subIndex * 2);
156 tr[pathIndex] = pathStatus;
165 return masterElement_->returnStatus(tr);
171 std::string
const& inputString,
178 std::string str_ = trim(inputString);
180 parent_ = parentElement;
183 bool occurrences_=
false;
187 <<
"Syntax Error (empty element)" << std::endl;
189 static const size_t bopsSize_ = 2;
190 static const std::string binaryOperators_[bopsSize_] = {
"||",
"&&"};
192 for (
size_t opr=0;opr<bopsSize_;opr++) {
193 bool exitloop_=
false;
197 std::string tmpStr = str_.substr(offset_);
198 t_end_ = tmpStr.find(binaryOperators_[opr]);
199 if (debug_)
std::cout <<
"offset: " << offset_ <<
" length: " << t_end_ <<
" string: " << tmpStr << std::endl;
201 if (t_end_ == std::string::npos) {
203 if (occurrences_) children_.push_back(
new TreeElement(tmpStr,tr,
this));
207 if (t_end_==0 || t_end_+2>=str_.size())
212 for (
size_t k=offset_;
k<t_end_;
k++) {
217 else if (str_.at(
k)==
')')
222 <<
"Syntax Error (brackets)\n";
231 std::string
next = str_.substr(offset_,t_end_-offset_);
232 children_.push_back(
new TreeElement(next,tr,
this));
239 for (
size_t k=offset_;
true;
k++) {
240 if (
k>=str_.size()) {
243 <<
"Syntax Error (brackets)\n";
246 children_.push_back(
new TreeElement(str_.substr(offset_),tr,
this));
251 if (
k>=t_end_+2 && bracketcnt_==0) {
252 std::string
temp = str_.substr(
k);
253 size_t pos = temp.find(binaryOperators_[opr]);
254 if (pos == std::string::npos) {
257 children_.push_back(
new TreeElement(str_.substr(offset_),tr,
this));
263 for (
size_t s=0;
s<
pos;
s++) {
265 if (temp.at(pos)==
'(')
269 else if (temp.at(pos)==
')')
274 <<
"Syntax error (brackets)\n";
284 <<
"Syntax error (brackets)\n";
286 children_.push_back(
new TreeElement(str_.substr(offset_,pos+
k),tr,
this));
289 if (offset_>=str_.size())
291 <<
"Syntax Error (operator is not unary)\n";
298 if (str_.at(
k)==
'(') bracketcnt_++;
299 if (str_.at(
k)==
')') bracketcnt_--;
315 if (debug_)
std::cout <<
"warning: empty element (will return true)"<< std::endl;
319 if (str_.at(0)==
'!') {
321 std::string
next = str_.substr(1);
322 children_.push_back(
new TreeElement(next,tr,
this));
325 size_t beginBlock_ =str_.find(
'(');
326 size_t endBlock_ =str_.rfind(
')');
327 bool found_lbracket = (beginBlock_ != std::string::npos);
328 bool found_rbracket = (endBlock_ != std::string::npos);
330 if (found_lbracket != found_rbracket) {
333 else if (found_lbracket && found_rbracket)
335 if (beginBlock_>=endBlock_) {
338 if (beginBlock_!=0 || endBlock_!=str_.size()-1)
341 std::string
next = str_.substr(beginBlock_+1,endBlock_-beginBlock_-1);
343 children_.push_back(
new TreeElement(next,tr,
this));
347 else if (!found_lbracket && !found_rbracket)
349 bool ignore_if_missing =
true;
350 size_t chr_pos = str_.find(
"@");
351 if (chr_pos!= std::string::npos) {
352 ignore_if_missing=
false;
353 str_=str_.substr(0,chr_pos);
356 std::vector<Strings::const_iterator> matches =
edm::regexMatch(tr,str_);
357 if (matches.empty()) {
358 if (!ignore_if_missing)
362 std::cout <<
"TriggerSelector: Couldn't match any triggers from: "<< str_<< std::endl
363 <<
" Node will not be added "<< std::endl;
368 if (matches.size()==1) {
370 trigBit_ = distance(tr.begin(),matches[0]);
371 if (debug_)
std::cout <<
"added trigger path: " << trigBit_ << std::endl;
374 if (matches.size()>1) {
376 for (
size_t l=0;
l<matches.size();
l++)
377 children_.push_back(
new TreeElement(*(matches[
l]),tr,
this));
387 if (pos != std::string::npos)
390 pos = input.find_last_not_of(
" ");
391 if (pos != std::string::npos)
400 if (!input.empty()) {
401 for (
size_t pos=0;
pos<input.size();
pos++) {
402 char ch = input.at(
pos);
403 if (ch==
'&') output.append(
"&");
404 else output.append(1,ch);
417 if (children_.empty()) {
419 if (op_==OR || op_==NOT)
return false;
420 if (op_==
AND || op_==
BR)
return true;
422 if (trigBit_<0 || (
unsigned int)trigBit_>=trStatus.
size())
424 <<
"Internal Error: array out of bounds " << std::endl;
432 return !children_[0]->returnStatus(trStatus);
435 return children_[0]->returnStatus(trStatus);
439 for (
size_t i=0;
i<children_.size();
i++) status = status && children_[
i]->returnStatus(trStatus);
444 for (
size_t i=0;
i<children_.size();
i++) status = status || children_[
i]->returnStatus(trStatus);
454 for (std::vector<TreeElement*>::iterator it=
children_.begin();it!=
children_.end();it++)
std::vector< TreeElement * > children_
T getParameter(std::string const &) const
bool AND(const PFCandidate &cand, const RecoTauQualityCuts::QCutFuncCollection &cuts)
void init(std::string const &path, Strings const &triggernames)
static std::vector< std::string > getEventSelectionVString(edm::ParameterSet const &pset)
std::vector< std::string > Strings
boost::shared_ptr< TreeElement > masterElement_
unsigned int size() const
Get number of paths stored.
static std::vector< std::string > getEventSelectionVString(edm::ParameterSet const &pset)
std::vector< std::vector< std::string >::const_iterator > regexMatch(std::vector< std::string > const &strings, boost::regex const ®exp)
bool returnStatus(edm::HLTGlobalStatus const &trStatus) const
static std::string makeXMLString(std::string const &input)
bool acceptEvent(edm::TriggerResults const &) const
boost::shared_ptr< edm::EventSelector > eventSelector_
TriggerSelector(Strings const &pathspecs, Strings const &names)
static std::string trim(std::string input)
static const HistoName names[]
TreeElement(std::string const &inputString, Strings const &tr, TreeElement *parentElement=NULL)