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++) {
213 if (str_.at(
k)==
'(') brackets_++;
214 if (str_.at(
k)==
')') brackets_--;
217 <<
"Syntax Error (brackets)\n";
220 std::string next = str_.substr(offset_,t_end_-offset_);
221 children_.push_back(
new TreeElement(next,tr,
this));
228 for (
size_t k=offset_;
true;
k++) {
229 if (
k>=str_.size()) {
232 <<
"Syntax Error (brackets)\n";
235 children_.push_back(
new TreeElement(str_.substr(offset_),tr,
this));
240 if (
k>=t_end_+2 && bracketcnt_==0) {
241 std::string
temp = str_.substr(
k);
242 size_t pos = temp.find(binaryOperators_[opr]);
243 if (pos == std::string::npos) {
246 children_.push_back(
new TreeElement(str_.substr(offset_),tr,
this));
252 for (
size_t s=0;
s<
pos;
s++) {
254 if (temp.at(pos)==
'(') brcount_++;
255 if (temp.at(pos)==
')') brcount_--;
258 <<
"Syntax error (brackets)\n";
262 <<
"Syntax error (brackets)\n";
264 children_.push_back(
new TreeElement(str_.substr(offset_,pos+
k),tr,
this));
267 if (offset_>=str_.size())
269 <<
"Syntax Error (operator is not unary)\n";
276 if (str_.at(
k)==
'(') bracketcnt_++;
277 if (str_.at(
k)==
')') bracketcnt_--;
293 if (debug_)
std::cout <<
"warning: empty element (will return true)"<< std::endl;
297 if (str_.at(0)==
'!') {
299 std::string next = str_.substr(1);
300 children_.push_back(
new TreeElement(next,tr,
this));
303 size_t beginBlock_ =str_.find(
'(');
304 size_t endBlock_ =str_.rfind(
')');
305 bool found_lbracket = (beginBlock_ != std::string::npos);
306 bool found_rbracket = (endBlock_ != std::string::npos);
308 if (found_lbracket != found_rbracket) {
311 else if (found_lbracket && found_rbracket)
313 if (beginBlock_>=endBlock_) {
316 if (beginBlock_!=0 || endBlock_!=str_.size()-1)
319 std::string next = str_.substr(beginBlock_+1,endBlock_-beginBlock_-1);
321 children_.push_back(
new TreeElement(next,tr,
this));
325 else if (!found_lbracket && !found_rbracket)
327 bool ignore_if_missing =
true;
328 size_t chr_pos = str_.find(
"@");
329 if (chr_pos!= std::string::npos) {
330 ignore_if_missing=
false;
331 str_=str_.substr(0,chr_pos);
334 std::vector<Strings::const_iterator> matches =
edm::regexMatch(tr,str_);
335 if (matches.empty()) {
336 if (!ignore_if_missing)
340 std::cout <<
"TriggerSelector: Couldn't match any triggers from: "<< str_<< std::endl
341 <<
" Node will not be added "<< std::endl;
346 if (matches.size()==1) {
348 trigBit_ = distance(tr.begin(),matches[0]);
349 if (debug_)
std::cout <<
"added trigger path: " << trigBit_ << std::endl;
352 if (matches.size()>1) {
354 for (
size_t l=0;
l<matches.size();
l++)
355 children_.push_back(
new TreeElement(*(matches[
l]),tr,
this));
365 if (pos != std::string::npos)
368 pos = input.find_last_not_of(
" ");
369 if (pos != std::string::npos)
378 if (!input.empty()) {
379 for (
size_t pos=0;
pos<input.size();
pos++) {
380 char ch = input.at(
pos);
381 if (ch==
'&') output.append(
"&");
382 else output.append(1,ch);
395 if (children_.empty()) {
397 if (op_==OR || op_==NOT)
return false;
398 if (op_==
AND || op_==BR)
return true;
400 if (trigBit_<0 || (
unsigned int)trigBit_>=trStatus.
size())
402 <<
"Internal Error: array out of bounds " << std::endl;
410 return !children_[0]->returnStatus(trStatus);
413 return children_[0]->returnStatus(trStatus);
417 for (
size_t i=0;
i<children_.size();
i++) status = status && children_[
i]->returnStatus(trStatus);
422 for (
size_t i=0;
i<children_.size();
i++) status = status || children_[
i]->returnStatus(trStatus);
432 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)