CMS 3D CMS Logo

Public Member Functions | Private Types | Private Attributes

stor::TriggerSelector::TreeElement Class Reference

List of all members.

Public Member Functions

TreeOperator op () const
TreeElementparent () const
bool returnStatus (edm::HLTGlobalStatus const &trStatus) const
 TreeElement (std::string const &inputString, Strings const &tr, TreeElement *parentElement=NULL)
 ~TreeElement ()

Private Types

enum  TreeOperator {
  NonInit = 0, AND = 1, OR = 2, NOT = 3,
  BR = 4
}

Private Attributes

std::vector< TreeElement * > children_
TreeOperator op_
TreeElementparent_
int trigBit_

Detailed Description

Definition at line 109 of file TriggerSelector.h.


Member Enumeration Documentation

Enumerator:
NonInit 
AND 
OR 
NOT 
BR 

Definition at line 111 of file TriggerSelector.h.

                          {
          NonInit = 0,
          AND = 1,
          OR  = 2,
          NOT = 3,
          BR = 4
        };

Constructor & Destructor Documentation

stor::TriggerSelector::TreeElement::TreeElement ( std::string const &  inputString,
Strings const &  tr,
TreeElement parentElement = NULL 
)

Definition at line 170 of file TriggerSelector.cc.

References reco::tau::qcuts::AND(), edm::errors::Configuration, gather_cfg::cout, Exception, gen::k, prof2calltree::l, pos, edm::regexMatch(), asciidump::s, and cond::rpcobtemp::temp.

    :
    op_(NonInit),
    trigBit_(-1)
  {
    std::string str_ = trim(inputString);
    children_.clear();
    parent_ = parentElement;

    size_t offset_=0;
    bool occurrences_=false;

    if (str_.empty())
      throw edm::Exception(edm::errors::Configuration)
        << "Syntax Error (empty element)" << std::endl;

    static const size_t bopsSize_ = 2;
    static const std::string binaryOperators_[bopsSize_] = {"||","&&"};

    for (size_t opr=0;opr<bopsSize_;opr++) {
      bool exitloop_=false;
      while(!exitloop_) {
        size_t t_end_;

        std::string tmpStr = str_.substr(offset_);
        t_end_ = tmpStr.find(binaryOperators_[opr]);
        if (debug_) std::cout << "offset: " << offset_ << " length: " << t_end_ <<" string: " << tmpStr << std::endl;

        if (t_end_ == std::string::npos) {
          //right side element
          if (occurrences_) children_.push_back(new TreeElement(tmpStr,tr,this));
          break;
        }
        t_end_ += offset_;
        if (t_end_==0 || t_end_+2>=str_.size()) 
          throw edm::Exception(edm::errors::Configuration) << "Syntax Error (operator is not unary)\n";
        else {
          //count bracket in preceeding part
          int brackets_=0;
          for (size_t k=offset_;k<t_end_;k++) {
            if (str_.at(k)=='(') brackets_++;
            if (str_.at(k)==')') brackets_--;
            if (brackets_<0)
              throw edm::Exception(edm::errors::Configuration)
                << "Syntax Error (brackets)\n";
          }
          if (brackets_==0) {
            std::string next = str_.substr(offset_,t_end_-offset_);
            children_.push_back(new TreeElement(next,tr,this));
            occurrences_=true;
            offset_ = t_end_+2;
          }
          else {
            //operator is inside brackets, find another
            int bracketcnt_ = 0;
            for (size_t k=offset_;true;k++) {
              if (k>=str_.size()) {
                if (bracketcnt_!=0)
                  throw edm::Exception(edm::errors::Configuration)
                    << "Syntax Error (brackets)\n";
                exitloop_=true;
                if (occurrences_) {
                  children_.push_back(new TreeElement(str_.substr(offset_),tr,this));
                }
                break;
              }
              //look for another operator
              if (k>=t_end_+2 && bracketcnt_==0) {
                std::string temp = str_.substr(k);
                size_t pos = temp.find(binaryOperators_[opr]);
                if (pos == std::string::npos) {
                  exitloop_=true;
                  if (occurrences_) {
                    children_.push_back(new TreeElement(str_.substr(offset_),tr,this));
                  }
                  break;
                }
                else {
                  int brcount_ = 0;
                  for (size_t s=0;s<pos;s++) {
                    //counting check of brackets from last position to operator
                    if (temp.at(pos)=='(') brcount_++;
                    if (temp.at(pos)==')') brcount_--;
                    if (brcount_<0)
                      throw edm::Exception(edm::errors::Configuration)
                        << "Syntax error (brackets)\n";
                  }
                  if (brcount_!=0) 
                    throw edm::Exception(edm::errors::Configuration)
                      << "Syntax error (brackets)\n";

                  children_.push_back(new TreeElement(str_.substr(offset_,pos+k),tr,this));
                  offset_=k+pos+2;
                  occurrences_=true;
                  if (offset_>=str_.size())
                    throw edm::Exception(edm::errors::Configuration) 
                      << "Syntax Error (operator is not unary)\n";
                  break;
                }

              }


              if (str_.at(k)=='(') bracketcnt_++;
              if (str_.at(k)==')') bracketcnt_--;

            }
          }
        }

      }
      if (occurrences_) {
        if (opr==0) op_=OR;
        else        op_=AND;
        return;
      }
    }

    if (str_.empty()) {
      op_=AND;
      if (debug_) std::cout << "warning: empty element (will return true)"<< std::endl;
      return;
    }

    if (str_.at(0)=='!') {
      op_=NOT;
      std::string next = str_.substr(1);
      children_.push_back(new TreeElement(next,tr,this));
      return;
    }
    size_t beginBlock_ =str_.find('(');
    size_t endBlock_ =str_.rfind(')');
    bool found_lbracket = (beginBlock_ != std::string::npos);
    bool found_rbracket = (endBlock_ != std::string::npos);

    if (found_lbracket != found_rbracket) {
      throw edm::Exception(edm::errors::Configuration) << "Syntax Error (brackets)\n";
    }
    else if (found_lbracket && found_rbracket)
    {
      if (beginBlock_>=endBlock_) {
        throw edm::Exception(edm::errors::Configuration) << "Syntax Error (brackets)\n";
      }
      if (beginBlock_!=0 || endBlock_!=str_.size()-1)
        throw edm::Exception(edm::errors::Configuration) << "Syntax Error (invalid character)\n";

      std::string next = str_.substr(beginBlock_+1,endBlock_-beginBlock_-1);

      children_.push_back(new TreeElement(next,tr,this));
      op_=BR; //a bracket
      return;
    }
    else if (!found_lbracket && !found_rbracket) //assume single trigger or wildcard (parsing)
    {
      bool ignore_if_missing = true;
      size_t chr_pos = str_.find("@");
      if (chr_pos!= std::string::npos) {
        ignore_if_missing=false;
        str_=str_.substr(0,chr_pos);
      }

      std::vector<Strings::const_iterator> matches = edm::regexMatch(tr,str_);
      if (matches.empty()) {
        if (!ignore_if_missing)// && !edm::is_glob(str_)) 
          throw edm::Exception(edm::errors::Configuration) << "Trigger name (or match) not present" << std::endl;
        else { 
          if (debug_)
            std::cout << "TriggerSelector: Couldn't match any triggers from: "<< str_<< std::endl
              << "                 Node will not be added "<< std::endl;
          op_=OR;
          return;
        }
      }
      if (matches.size()==1) {
        //Single Trigger match
        trigBit_ = distance(tr.begin(),matches[0]);
        if (debug_) std::cout << "added trigger path: " << trigBit_ << std::endl;
        return;
      }
      if (matches.size()>1) {
        op_=OR;
        for (size_t l=0;l<matches.size();l++)
          children_.push_back(new TreeElement(*(matches[l]),tr,this));
      }
    }
  }
stor::TriggerSelector::TreeElement::~TreeElement ( )

Definition at line 430 of file TriggerSelector.cc.

References children_.

  {
    for (std::vector<TreeElement*>::iterator it=children_.begin();it!=children_.end();it++)
      delete *it;
    children_.clear();
  }

Member Function Documentation

TreeOperator stor::TriggerSelector::TreeElement::op ( ) const [inline]

Definition at line 135 of file TriggerSelector.h.

References op_.

{return op_;}
TreeElement* stor::TriggerSelector::TreeElement::parent ( void  ) const [inline]

Definition at line 140 of file TriggerSelector.h.

References parent_.

{return parent_;}
bool stor::TriggerSelector::TreeElement::returnStatus ( edm::HLTGlobalStatus const &  trStatus) const

Definition at line 390 of file TriggerSelector.cc.

References reco::tau::qcuts::AND(), edm::errors::Configuration, Exception, i, Pass, edm::HLTGlobalStatus::size(), and ntuplemaker::status.

  {

    if (children_.empty()) {

      if (op_==OR  || op_==NOT) return false;
      if (op_==AND || op_==BR) return true;

      if (trigBit_<0 || (unsigned int)trigBit_>=trStatus.size())
        throw edm::Exception(edm::errors::Configuration)
          << "Internal Error: array out of bounds " << std::endl;

      if ((trStatus[trigBit_]).state() == edm::hlt::Pass) return true;
      //else if ((trStatus[trigBit]).state() == edm::hlt::Fail) return false;

      return false;
    }
    if (op_==NOT) { //NEGATION
      return !children_[0]->returnStatus(trStatus);
    }
    if (op_==BR) { //BRACKET
      return children_[0]->returnStatus(trStatus);
    } 
    if (op_==AND) { //AND
      bool status = true;
      for (size_t i=0;i<children_.size();i++) status = status && children_[i]->returnStatus(trStatus);
      return status;
    }
    else if (op_==OR) { //OR
      bool status = false;
      for (size_t i=0;i<children_.size();i++) status = status || children_[i]->returnStatus(trStatus);
      return status;
    }
    throw edm::Exception(edm::errors::Configuration) << "Internal error: reached end of returnStatus(...)  op:state= " << op_ << std::endl;
    return false;
  }

Member Data Documentation

Definition at line 145 of file TriggerSelector.h.

Referenced by ~TreeElement().

Definition at line 146 of file TriggerSelector.h.

Referenced by op().

Definition at line 144 of file TriggerSelector.h.

Referenced by parent().

Definition at line 147 of file TriggerSelector.h.