CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Classes | Namespaces | Functions
DDPartSelection.cc File Reference
#include "DetectorDescription/Base/interface/Singleton.h"
#include "DetectorDescription/Core/interface/DDPartSelection.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

 boost
 
 boost::spirit
 
 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 *, char const *)
 
std::ostream & operator<< (std::ostream &o, const DDPartSelection &p)
 
std::ostream & operator<< (std::ostream &os, const std::vector< DDPartSelection > &v)
 

Function Documentation

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

Definition at line 278 of file DDPartSelection.cc.

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

279 {
280 
281 
282  static bool isInit(false);
283  static std::vector<std::string> tokens;
284  if(!isInit) {
285  // initialize with valid tokens
286  tokens.push_back("/");
287  tokens.push_back("//");
288  tokens.push_back("[");
289  tokens.push_back("]");
290  }
291  std::string s = sel;
292  std::string::size_type st = std::string::npos;
293  std::string::size_type cu = 0;
294  std::vector<std::string> toksVec;
295  std::vector<std::string> textVec;
296  std::string tkn, txt;
297  bool braceOpen(false);
298  /*
299  the following code should decompose a selection std::string into 2 std::vectors,
300  a token-std::vector and a text-std::vector. Tokens are /,//,[,]
301  example: "//Abc[3]/Def" ->
302  tokens text
303  // ""
304  [ Abc
305  ] 3
306  / ""
307  "Def"
308  */
309 
310  while (s.size()) {
311  std::vector<std::string>::iterator tkit = tokens.begin();
312  std::vector<std::string>::iterator mint = tokens.end();
313  st=s.size();
315  for(;tkit!=tokens.end();++tkit) { // find the first match of one of the token std::strings
316  ts = s.find(*tkit);
317  if (ts<=st) {
318  st=ts;
319  mint = tkit;
320  }
321  }
322 
323  if (mint!=tokens.end())
324  tkn = s.substr(st,mint->size());
325  else
326  tkn="";
327  txt = s.substr(cu,st);
328  toksVec.push_back(tkn);
329  textVec.push_back(txt);
330  if (braceOpen) {
331  if (tkn!="]")
332  throw cms::Exception("DDException") << "PartSelector: syntaxerror in " << sel
333  << "\ncheck the braces!";
334  else
335  braceOpen=false;
336  }
337  if (tkn=="[")
338  braceOpen=true;
339  DCOUT_V('C',"tkn=" << tkn << " txt=" << txt);
340  if (mint!=tokens.end())
341  s.erase(cu,st+mint->size());
342  else
343  s.erase();
344  DCOUT_V('C', std::endl << "s=" << s);
345  //break;
346  }
347  DCOUT_V('C', "The original std::string was:" << std::endl);
348  unsigned int i=0;
349  DCOUT_V('C', "toks\ttext");
350  for (i=0; i<toksVec.size();++i) {
351  DCOUT_V('C', toksVec[i] << "\t" << textVec[i]);
352  }
353  DCOUT_V('C', std::endl);
354 
355  // now some spaghetti code
356  std::string nm = "blabla" ; // std::string("PartSelector=") + ns() + std::string(":") + name();
357  if (textVec[0] != "")
358  throw cms::Exception("DDException") << nm << " selection must not start with a LogicalPart-name";
359 
360  if ((toksVec[0] != "//"))
361  throw cms::Exception("DDException") << nm << " selection must start with '//' !";
362 
363  if (textVec.size() < 2)
364  throw cms::Exception("DDException") << nm << " internal error [textVec.size()<2]!";
365 
366  std::vector<std::string>::iterator tk_it = toksVec.begin();
367  std::vector<std::string>::iterator tx_it = textVec.begin(); ++tx_it;
368  // the BIG switch - yes, this is OO!!!
369  while(tk_it != toksVec.end() && tx_it != textVec.end()) {
370 
371  // anynode ... token //* makes no sense (except as last entry which is forbidden ...)
372  DCOUT_V('C', ">- anynode tkn=" << *tk_it << " d=" << tk_it-toksVec.begin() << " txt=" << *tx_it << std::endl);
373  if ( *tk_it == "//" && *tx_it=="*" ) {
374  path.push_back(DDPartSelRegExpLevel("","",0,ddanynode));
375  DCOUT_V('C', "--anynode: //*" << std::endl);
376  ++tk_it;
377  ++tx_it;
378  continue;
379  }
380 
381  // anychild
382  DCOUT_V('C', ">- anychild tkn=" << *tk_it << " d=" << tk_it-toksVec.begin() << " txt=" << *tx_it << std::endl);
383  if ( *tk_it == "/" && *tx_it=="*" ) {
384  path.push_back(DDPartSelRegExpLevel("","",0,ddanychild));
385  DCOUT_V('C', "--anychild: /*" << std::endl);
386  ++tk_it;
387  ++tx_it;
388  continue;
389  }
390 
391  // anylogp
392  DCOUT_V('C', ">- anylogp tkn=" << *tk_it << " d=" << tk_it-toksVec.begin() << " txt=" << *tx_it << std::endl);
393  if ( *tk_it == "//" && tx_it->size()) {
394  ++tk_it;
395  if ( tk_it != toksVec.end() && *tk_it != "[" && *tk_it != "]") {
396  std::pair<std::string,std::string> p(DDSplit(*tx_it));
397  path.push_back(DDPartSelRegExpLevel(p.second,p.first,0,ddanylogp));
398  DCOUT_V('C', "--anylogp: " << *tx_it << std::endl);
399  ++tx_it;
400  continue;
401  }
402  --tk_it;
403  }
404 
405  // childlogp
406  DCOUT_V('C', ">- childlogp tkn=" << *tk_it << " d=" << tk_it-toksVec.begin() << " txt=" << *tx_it << std::endl);
407  if ( *tk_it == "/" && tx_it->size()) {
408  ++tk_it;
409  if ( tk_it == toksVec.end() - 1 ) {
410  DCOUT_V('C', "--childlogp: " << *tx_it << std::endl);
411  std::pair<std::string,std::string> p(DDSplit(*tx_it));
412  path.push_back(DDPartSelRegExpLevel(p.second,p.first,0,ddchildlogp));
413  ++tx_it;
414  continue;
415  }
416  if ( *tk_it == "/" || *tk_it=="//") {
417  DCOUT_V('C', "--childlogp: " << *tx_it << std::endl);
418  std::pair<std::string,std::string> p(DDSplit(*tx_it));
419  path.push_back(DDPartSelRegExpLevel(p.second,p.first,0,ddchildlogp));
420  ++tx_it;
421  continue;
422  }
423  --tk_it;
424  }
425 
426 
427  // anyposp
428  DCOUT_V('C', ">- anyposp tkn=" << *tk_it << " d=" << tk_it-toksVec.begin() << " txt=" << *tx_it << std::endl);
429  if ( *tk_it == "//" && tx_it->size()) {
430  ++tk_it;
431  if ( tk_it != toksVec.end() && *tk_it == "[" ) {
432  ++tk_it;
433  if ( tk_it == toksVec.end() || (tk_it != toksVec.end() && *tk_it != "]")) {
434  DCOUT_V('C', *tk_it << " " << *tx_it );
435  break;
436  }
437  ++tx_it;
438  ++tk_it;
439  std::pair<std::string,std::string> p(DDSplit(*(tx_it-1)));
440  path.push_back(DDPartSelRegExpLevel(p.second,p.first,atoi(tx_it->c_str()),ddanyposp));
441  DCOUT_V('C', "--anyposp: " << *tx_it << " " << atoi(tx_it->c_str()) << std::endl);
442  ++tx_it;
443  ++tx_it;
444  continue;
445  }
446  }
447 
448 
449  // childposp
450  DCOUT_V('C', ">- childposp tkn=" << *tk_it << " d=" << tk_it-toksVec.begin() << " txt=" << *tx_it << std::endl);
451  if ( *tk_it == "/" && tx_it->size()) {
452  ++tk_it;
453  if ( tk_it != toksVec.end() && *tk_it=="[" ) {
454  DCOUT_V('C', "--childposp: " << *tx_it << " " << *tk_it << *(tx_it+1) << std::endl);
455  std::pair<std::string,std::string> p(DDSplit(*tx_it));
456  path.push_back(DDPartSelRegExpLevel(p.second,p.first,atoi((tx_it+1)->c_str()),ddchildposp));
457 
458  ++tx_it;
459 
460  ++tx_it;
461  ++tk_it;
462  if (tk_it != toksVec.end() && *tk_it != "]")
463  break;
464  ++tk_it;
465  ++tx_it;
466  continue;
467  }
468  }
469 
470  // any
471  throw cms::Exception("DDException") << nm << " syntax error in:\n" << sel
472  << "\n tkn=" << *tk_it << " txt=" << *tx_it;
473  }
474  //FIXME: DDPartSelectorImpl::tokenize : prototype has restricted support for selection std::string (code below restricts)
475  ddselection_type tmp = path.back().selectionType_;
476  if (tmp==ddunknown || tmp==ddanynode || tmp==ddanychild )
477  throw cms::Exception("DDException") << "PartSelector: last element in selection std::string in " << sel
478  << "\nmust address a distinct LogicalPart or PosPart!";
479 }
int i
Definition: DBlmapReader.cc:9
int mint[400]
uint16_t size_type
list path
Definition: scaleCards.py:51
ddselection_type
#define DCOUT_V(M_v_Y, M_v_S)
Definition: DDdebug.h:54
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
std::pair< std::string, std::string > DDSplit(const std::string &n)
split into (name,namespace), separator = &#39;:&#39;
Definition: DDSplit.cc:4
void DDTokenize2 ( const std::string &  sel,
std::vector< DDPartSelRegExpLevel > &  path 
)

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().

264 {
265  static SpecParParser parser;
267  bool result = parse(sel.c_str(), parser).full;
268  if (!result) {
269  edm::LogError("DDPartSelection") << "DDTokenize2() error in parsing of " << sel << std::endl;
270  }
271 }
Evaluator * parse(const T &text)
static value_type & instance()
list path
Definition: scaleCards.py:51
tuple result
Definition: query.py:137
Definition: GenABIO.cc:193
void noNameSpace ( char const *  ,
char const *   
)

Definition at line 38 of file DDPartSelection.cc.

References DDI::Singleton< I >::instance().

Referenced by SpecParParser::definition< ScannerT >::definition().

38  {
40 }
static value_type & instance()
std::ostream& operator<< ( std::ostream &  o,
const DDPartSelection p 
)

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_.

483 {
484  DDPartSelection::const_iterator it(p.begin()), ed(p.end());
485  for (; it != ed; ++it) {
486  const DDPartSelectionLevel lv =*it;
487  switch (lv.selectionType_) {
488  case ddanylogp:
489  o << "//" << lv.lp_.ddname();
490  break;
491  case ddanyposp:
492  o << "//" << lv.lp_.ddname() << '[' << lv.copyno_ << ']';
493  break;
494  case ddchildlogp:
495  o << "/" << lv.lp_.ddname();
496  break;
497  case ddchildposp:
498  o << "/" << lv.lp_.ddname() << '[' << lv.copyno_ << ']';
499  break;
500  default:
501  o << "{Syntax ERROR}";
502  }
503  }
504  return o;
505 }
ddselection_type selectionType_
const N & ddname() const
Definition: DDBase.h:84
std::ostream& operator<< ( std::ostream &  os,
const std::vector< DDPartSelection > &  v 
)

Definition at line 507 of file DDPartSelection.cc.

References v.

508 {
509  std::vector<DDPartSelection>::const_iterator it(v.begin()), ed(v.end());
510  for (; it != (ed-1); ++it) {
511  os << *it << std::endl;
512  }
513  if ( it != ed ) {
514  ++it;
515  os << *it;
516  }
517  return os;
518 }
mathSSE::Vec4< T > v