CMS 3D CMS Logo

Classes | Namespaces | Functions

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/DetectorDescription/Core/src/DDPartSelection.cc File Reference

#include "DetectorDescription/Base/interface/Singleton.h"
#include "DetectorDescription/Core/interface/DDPartSelection.h"
#include "DetectorDescription/Base/interface/DDException.h"
#include "DetectorDescription/Base/interface/DDdebug.h"
#include "DetectorDescription/Core/interface/DDSplit.h"
#include "boost/spirit/include/classic.hpp"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include <map>
#include <DetectorDescription/Base/interface/Singleton.icc>

Go to the source code of this file.

Classes

struct  DDCopyNoFtor
struct  DDIsChildFtor
struct  DDNameFtor
struct  DDNameSpaceFtor
struct  DDSelLevelCollector
struct  DDSelLevelFtor
struct  SpecParParser::definition< ScannerT >
struct  SpecParParser

Namespaces

namespace  boost
namespace  boost::spirit
namespace  boost::spirit::classic

Functions

void DDTokenize (const std::string &sel, std::vector< DDPartSelRegExpLevel > &path)
void DDTokenize2 (const std::string &sel, std::vector< DDPartSelRegExpLevel > &path)
void noNameSpace (char const *first, char const *last)
std::ostream & operator<< (std::ostream &os, const std::vector< DDPartSelection > &v)
std::ostream & operator<< (std::ostream &o, const DDPartSelection &p)

Function Documentation

void DDTokenize ( const std::string &  sel,
std::vector< DDPartSelRegExpLevel > &  path 
)

Definition at line 279 of file DDPartSelection.cc.

References DCOUT_V, ddanychild, ddanylogp, ddanynode, ddanyposp, ddchildlogp, ddchildposp, DDSplit(), ddunknown, i, gen::mint, L1TEmulatorMonitor_cff::p, asciidump::s, runTheMatrix::sel, tmp, and EcalElecEmulTccFlatFileProducerFromTPG_cfg::tokens.

{


  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 DDException(std::string("PartSelector: syntaxerror in ") + sel + 
                          std::string("\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 DDException( nm 
                      +std::string(" selection must not start with a LogicalPart-name")); 
  
  if ((toksVec[0] != "//"))
    throw DDException( nm 
                      +std::string(" selection must start with '//' !")); 
  
  if (textVec.size() < 2)
    throw DDException( nm + std::string(" 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 DDException( nm + std::string(" syntax error in:\n") + sel + 
                            std::string("\n  tkn=") + *tk_it + std::string("  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 DDException(std::string("PartSelector: last element in selection std::string in ") + sel + 
                          std::string("\nmust address a distinct LogicalPart or PosPart!") );
}
void DDTokenize2 ( const std::string &  sel,
std::vector< DDPartSelRegExpLevel > &  path 
)

Definition at line 264 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;
  }
}
void noNameSpace ( char const *  first,
char const *  last 
)
std::ostream& operator<< ( std::ostream &  os,
const std::vector< DDPartSelection > &  v 
)

Definition at line 510 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;
}
std::ostream& operator<< ( std::ostream &  o,
const DDPartSelection p 
)

Definition at line 485 of file DDPartSelection.cc.

References DDPartSelectionLevel::copyno_, ddanylogp, ddanyposp, ddchildlogp, ddchildposp, DDBase< N, C >::ddname(), DDPartSelectionLevel::lp_, 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;
}