CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Classes | Enumerations | Functions
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.

14  { ddunknown, // -> (should never appear!)
15  ddanynode, // -> //*
16  ddanychild, // -> /*
17  ddanylogp, // -> //NameOfLogicalPart
18  ddanyposp, // -> //NameOfLogicalPart[copyno]
19  ddchildlogp, // -> /NameOfLogicalPart
20  ddchildposp // -> /NameOfLogicalPart[copyno]
21  };

Function Documentation

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

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.

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

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

265 {
266  static SpecParParser parser;
268  bool result = parse(sel.c_str(), parser).full;
269  if (!result) {
270  edm::LogError("DDPartSelection") << "DDTokenize2() error in parsing of " << sel << std::endl;
271  }
272 }
Evaluator * parse(const T &text)
int path() const
Definition: HLTadd.h:3
static value_type & instance()
tuple result
Definition: query.py:137
Definition: GenABIO.cc:193
std::ostream & operator<< ( std::ostream &  ,
const DDPartSelection  
)

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

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

Definition at line 510 of file DDPartSelection.cc.

References v.

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