CMS 3D CMS Logo

Classes | Enumerations | Functions

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/DetectorDescription/Core/interface/DDPartSelection.h File Reference

#include <vector>
#include <string>
#include <iostream>
#include "DetectorDescription/Core/interface/DDLogicalPart.h"

Go to the source code of this file.

Classes

class  DDPartSelection
struct  DDPartSelectionLevel
struct  DDPartSelRegExpLevel

Enumerations

enum  ddselection_type {
  ddunknown, ddanynode, ddanychild, ddanylogp,
  ddanyposp, ddchildlogp, ddchildposp
}

Functions

void DDTokenize (const std::string &selectionString, std::vector< DDPartSelRegExpLevel > &result)
void DDTokenize2 (const std::string &selectionString, std::vector< DDPartSelRegExpLevel > &result)
std::ostream & operator<< (std::ostream &, const DDPartSelection &)
std::ostream & operator<< (std::ostream &, const std::vector< DDPartSelection > &)

Enumeration Type Documentation

Enumerator:
ddunknown 
ddanynode 
ddanychild 
ddanylogp 
ddanyposp 
ddchildlogp 
ddchildposp 

Definition at line 14 of file DDPartSelection.h.

                      { ddunknown,   //   ->    (should never appear!)
                        ddanynode,   //   ->    //*
                        ddanychild,  //   ->    /*
                        ddanylogp,   //   ->    //NameOfLogicalPart
                        ddanyposp,   //   ->    //NameOfLogicalPart[copyno]
                        ddchildlogp, //   ->    /NameOfLogicalPart
                        ddchildposp  //   ->    /NameOfLogicalPart[copyno]
                       };

Function Documentation

void DDTokenize ( const std::string &  selectionString,
std::vector< DDPartSelRegExpLevel > &  result 
)

Definition at line 278 of file DDPartSelection.cc.

References DCOUT_V, ddanychild, ddanylogp, ddanynode, ddanyposp, ddchildlogp, ddchildposp, DDSplit(), ddunknown, Exception, i, mint, AlCaHLTBitMon_ParallelJobs::p, alignCSCRings::s, EgammaValidation_Wenu_cff::sel, and tmp.

{


  static bool isInit(false);
  static std::vector<std::string> tokens;
  if(!isInit) {
    // initialize with valid tokens
    tokens.push_back("/"); 
    tokens.push_back("//");
    tokens.push_back("[");
    tokens.push_back("]");
  }
  std::string s = sel;
  std::string::size_type st = std::string::npos;
  std::string::size_type cu = 0;
  std::vector<std::string> toksVec;
  std::vector<std::string> textVec;
  std::string tkn, txt;
  bool braceOpen(false);
  /*
    the following code should decompose a selection std::string into 2 std::vectors,
    a token-std::vector and a text-std::vector. Tokens are /,//,[,] 
    example: "//Abc[3]/Def" ->
             tokens  text
             //      ""
             [       Abc
             ]       3
             /       ""
                     "Def"
  */  
  
  while (s.size()) {
    std::vector<std::string>::iterator tkit = tokens.begin();
    std::vector<std::string>::iterator mint = tokens.end();
    st=s.size();
    std::string::size_type ts;
    for(;tkit!=tokens.end();++tkit) { // find the first match of one of the token std::strings
      ts = s.find(*tkit); 
      if (ts<=st) { 
        st=ts;
        mint = tkit;
      }  
    }
    
    if (mint!=tokens.end())     
     tkn = s.substr(st,mint->size());
    else
     tkn=""; 
    txt = s.substr(cu,st);
    toksVec.push_back(tkn);
    textVec.push_back(txt);
    if (braceOpen) {
      if (tkn!="]")
        throw cms::Exception("DDException") << "PartSelector: syntaxerror in " << sel 
         << "\ncheck the braces!";
      else
        braceOpen=false;
    }           
    if (tkn=="[")
      braceOpen=true;
    DCOUT_V('C',"tkn=" << tkn << " txt=" << txt);   
    if (mint!=tokens.end())
      s.erase(cu,st+mint->size()); 
    else
      s.erase();  
    DCOUT_V('C', std::endl << "s=" << s);   
    //break;    
  }
  DCOUT_V('C', "The original std::string was:" << std::endl);
  unsigned int i=0;
  DCOUT_V('C', "toks\ttext");
  for (i=0; i<toksVec.size();++i) {
    DCOUT_V('C',  toksVec[i] << "\t" << textVec[i]);
  }  
  DCOUT_V('C', std::endl); 
  
  // now some spaghetti code 
  std::string nm = "blabla" ; // std::string("PartSelector=") + ns() + std::string(":") + name();
  if (textVec[0] != "")
    throw cms::Exception("DDException") << nm << " selection must not start with a LogicalPart-name"; 
  
  if ((toksVec[0] != "//"))
    throw cms::Exception("DDException") << nm << " selection must start with '//' !"; 
  
  if (textVec.size() < 2)
    throw cms::Exception("DDException") << nm << " internal error [textVec.size()<2]!";
    
  std::vector<std::string>::iterator tk_it = toksVec.begin();
  std::vector<std::string>::iterator tx_it = textVec.begin(); ++tx_it;
  // the BIG switch - yes, this is OO!!!
  while(tk_it != toksVec.end() && tx_it != textVec.end()) {
 
    // anynode ... token //* makes no sense (except as last entry which is forbidden ...)
    DCOUT_V('C', ">- anynode tkn=" << *tk_it << " d=" << tk_it-toksVec.begin() << " txt=" << *tx_it << std::endl);
    if ( *tk_it == "//" && *tx_it=="*" ) { 
      path.push_back(DDPartSelRegExpLevel("","",0,ddanynode));
      DCOUT_V('C', "--anynode: //*" << std::endl);
      ++tk_it;
      ++tx_it;
      continue;
    }
             
    // anychild
    DCOUT_V('C', ">- anychild tkn=" << *tk_it << " d=" << tk_it-toksVec.begin() << " txt=" << *tx_it << std::endl);
    if ( *tk_it == "/" && *tx_it=="*" ) { 
      path.push_back(DDPartSelRegExpLevel("","",0,ddanychild));
      DCOUT_V('C', "--anychild: /*" << std::endl);
      ++tk_it;
      ++tx_it;
      continue;
    }    

    // anylogp
    DCOUT_V('C', ">- anylogp tkn=" << *tk_it << " d=" << tk_it-toksVec.begin() << " txt=" << *tx_it << std::endl);
    if ( *tk_it == "//" && tx_it->size()) {
      ++tk_it;
      if ( tk_it != toksVec.end() && *tk_it != "[" && *tk_it != "]") {
        std::pair<std::string,std::string> p(DDSplit(*tx_it));
          path.push_back(DDPartSelRegExpLevel(p.second,p.first,0,ddanylogp));
        DCOUT_V('C', "--anylogp: " << *tx_it << std::endl);
        ++tx_it;
        continue;
      } 
      --tk_it;
    }    

    // childlogp
    DCOUT_V('C', ">- childlogp tkn=" << *tk_it << " d=" << tk_it-toksVec.begin() << " txt=" << *tx_it << std::endl);
    if ( *tk_it == "/" && tx_it->size()) {
      ++tk_it;
      if ( tk_it == toksVec.end() - 1 ) {
        DCOUT_V('C', "--childlogp: " << *tx_it << std::endl);
        std::pair<std::string,std::string> p(DDSplit(*tx_it));
          path.push_back(DDPartSelRegExpLevel(p.second,p.first,0,ddchildlogp));
        ++tx_it;   
        continue;
      }
      if ( *tk_it == "/" || *tk_it=="//") {
        DCOUT_V('C', "--childlogp: " << *tx_it << std::endl);
        std::pair<std::string,std::string> p(DDSplit(*tx_it));
          path.push_back(DDPartSelRegExpLevel(p.second,p.first,0,ddchildlogp));
        ++tx_it;
        continue;
      }
      --tk_it;
    }   


    // anyposp
    DCOUT_V('C', ">- anyposp tkn=" << *tk_it << " d=" << tk_it-toksVec.begin() << " txt=" << *tx_it << std::endl);
    if ( *tk_it == "//" && tx_it->size()) {
      ++tk_it;
      if ( tk_it != toksVec.end() && *tk_it == "[" ) {
        ++tk_it;
        if ( tk_it == toksVec.end() || (tk_it != toksVec.end() && *tk_it != "]")) {
         DCOUT_V('C', *tk_it << " " << *tx_it );
           break;
        }  
        ++tx_it;
        ++tk_it;
        std::pair<std::string,std::string> p(DDSplit(*(tx_it-1)));
          path.push_back(DDPartSelRegExpLevel(p.second,p.first,atoi(tx_it->c_str()),ddanyposp));
        DCOUT_V('C', "--anyposp: " << *tx_it << " " << atoi(tx_it->c_str()) << std::endl);
        ++tx_it;
        ++tx_it;
        continue;
      } 
    }    
        
         
    // childposp
    DCOUT_V('C', ">- childposp tkn=" << *tk_it << " d=" << tk_it-toksVec.begin() << " txt=" << *tx_it << std::endl);
    if ( *tk_it == "/" && tx_it->size()) {
      ++tk_it;
      if ( tk_it != toksVec.end() && *tk_it=="[" ) {
        DCOUT_V('C', "--childposp: " << *tx_it << " " << *tk_it << *(tx_it+1) << std::endl);
        std::pair<std::string,std::string> p(DDSplit(*tx_it));
          path.push_back(DDPartSelRegExpLevel(p.second,p.first,atoi((tx_it+1)->c_str()),ddchildposp));

        ++tx_it;

        ++tx_it;
        ++tk_it;
        if (tk_it != toksVec.end() && *tk_it != "]") 
          break;
        ++tk_it;
        ++tx_it;
        continue;  
      }
    }
    
    // any
    throw cms::Exception("DDException") << nm << " syntax error in:\n" << sel 
     << "\n  tkn=" << *tk_it << "  txt=" << *tx_it;                                 
  }
  //FIXME: DDPartSelectorImpl::tokenize : prototype has restricted support for selection std::string (code below restricts)
  ddselection_type tmp = path.back().selectionType_;
  if (tmp==ddunknown || tmp==ddanynode || tmp==ddanychild ) 
        throw cms::Exception("DDException") << "PartSelector: last element in selection std::string in " << sel 
                                            << "\nmust address a distinct LogicalPart or PosPart!";
}
void DDTokenize2 ( const std::string &  selectionString,
std::vector< DDPartSelRegExpLevel > &  result 
)

Definition at line 263 of file DDPartSelection.cc.

References full, DDI::Singleton< I >::instance(), triggerExpression::parse(), geometryXMLtoCSV::parser, and query::result.

Referenced by DDI::Specific::createPartSelections().

{
  static SpecParParser parser;
  DDI::Singleton<DDSelLevelCollector>::instance().path(&path);
  bool result = parse(sel.c_str(), parser).full;
  if (!result) {
    edm::LogError("DDPartSelection") << "DDTokenize2() error in parsing of " << sel << std::endl;
  }
}
std::ostream & operator<< ( std::ostream &  ,
const DDPartSelection  
)

Definition at line 482 of file DDPartSelection.cc.

References DDPartSelectionLevel::copyno_, ddanylogp, ddanyposp, ddchildlogp, ddchildposp, DDBase< N, C >::ddname(), DDPartSelectionLevel::lp_, python::connectstrParser::o, and DDPartSelectionLevel::selectionType_.

{
  DDPartSelection::const_iterator it(p.begin()), ed(p.end());
  for (; it != ed; ++it) {
    const DDPartSelectionLevel lv  =*it;
    switch (lv.selectionType_) {
    case ddanylogp:
      o << "//" << lv.lp_.ddname();
      break;
    case ddanyposp:
      o << "//" << lv.lp_.ddname() << '[' << lv.copyno_ << ']';
      break;
    case ddchildlogp:
      o << "/" << lv.lp_.ddname();
      break;
    case ddchildposp:
      o << "/" << lv.lp_.ddname() << '[' << lv.copyno_ << ']';
      break;
    default:
      o << "{Syntax ERROR}";
    }
  }
  return o;
}
std::ostream& operator<< ( std::ostream &  ,
const std::vector< DDPartSelection > &   
)

Definition at line 507 of file DDPartSelection.cc.

References v.

{
  std::vector<DDPartSelection>::const_iterator it(v.begin()), ed(v.end());
  for (; it != (ed-1); ++it) {
    os << *it << std::endl;
  }
  if ( it != ed ) {
    ++it;
    os << *it;
  }
  return os;
}