#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.hpp"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include <map>
Go to the source code of this file.
Namespaces | |
namespace | boost |
namespace | boost::spirit |
Classes | |
struct | DDCopyNoFtor |
struct | DDIsChildFtor |
struct | DDNameFtor |
struct | DDNameSpaceFtor |
struct | DDSelLevelCollector |
struct | DDSelLevelFtor |
struct | SpecParParser |
A boost::spirit parser for the <SpecPar path="xxx"> syntax. More... | |
struct | SpecParParser::definition< ScannerT > |
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) |
void DDTokenize | ( | const std::string & | sel, | |
std::vector< DDPartSelRegExpLevel > & | path | |||
) |
Definition at line 280 of file DDPartSelection.cc.
References DCOUT_V, ddanychild, ddanylogp, ddanynode, ddanyposp, ddchildlogp, ddchildposp, DDSplit(), ddunknown, lat::endl(), i, mint, p, s, st, tmp, and cmsScimarkStop::tokens.
00281 { 00282 00283 00284 static bool isInit(false); 00285 static std::vector<std::string> tokens; 00286 if(!isInit) { 00287 // initialize with valid tokens 00288 tokens.push_back("/"); 00289 tokens.push_back("//"); 00290 tokens.push_back("["); 00291 tokens.push_back("]"); 00292 } 00293 std::string s = sel; 00294 std::string::size_type st = std::string::npos; 00295 std::string::size_type cu = 0; 00296 std::vector<std::string> toksVec; 00297 std::vector<std::string> textVec; 00298 std::string tkn, txt; 00299 bool braceOpen(false); 00300 /* 00301 the following code should decompose a selection std::string into 2 std::vectors, 00302 a token-std::vector and a text-std::vector. Tokens are /,//,[,] 00303 example: "//Abc[3]/Def" -> 00304 tokens text 00305 // "" 00306 [ Abc 00307 ] 3 00308 / "" 00309 "Def" 00310 */ 00311 00312 while (s.size()) { 00313 std::vector<std::string>::iterator tkit = tokens.begin(); 00314 std::vector<std::string>::iterator mint = tokens.end(); 00315 st=s.size(); 00316 std::string::size_type ts; 00317 for(;tkit!=tokens.end();++tkit) { // find the first match of one of the token std::strings 00318 ts = s.find(*tkit); 00319 if (ts<=st) { 00320 st=ts; 00321 mint = tkit; 00322 } 00323 } 00324 00325 if (mint!=tokens.end()) 00326 tkn = s.substr(st,mint->size()); 00327 else 00328 tkn=""; 00329 txt = s.substr(cu,st); 00330 toksVec.push_back(tkn); 00331 textVec.push_back(txt); 00332 if (braceOpen) { 00333 if (tkn!="]") 00334 throw DDException(std::string("PartSelector: syntaxerror in ") + sel + 00335 std::string("\ncheck the braces!") ); 00336 else 00337 braceOpen=false; 00338 } 00339 if (tkn=="[") 00340 braceOpen=true; 00341 DCOUT_V('C',"tkn=" << tkn << " txt=" << txt); 00342 if (mint!=tokens.end()) 00343 s.erase(cu,st+mint->size()); 00344 else 00345 s.erase(); 00346 DCOUT_V('C', std::endl << "s=" << s); 00347 //break; 00348 } 00349 DCOUT_V('C', "The original std::string was:" << std::endl); 00350 unsigned int i=0; 00351 DCOUT_V('C', "toks\ttext"); 00352 for (i=0; i<toksVec.size();++i) { 00353 DCOUT_V('C', toksVec[i] << "\t" << textVec[i]); 00354 } 00355 DCOUT_V('C', std::endl); 00356 00357 // now some spaghetti code 00358 std::string nm = "blabla" ; // std::string("PartSelector=") + ns() + std::string(":") + name(); 00359 if (textVec[0] != "") 00360 throw DDException( nm 00361 +std::string(" selection must not start with a LogicalPart-name")); 00362 00363 if ((toksVec[0] != "//")) 00364 throw DDException( nm 00365 +std::string(" selection must start with '//' !")); 00366 00367 if (textVec.size() < 2) 00368 throw DDException( nm + std::string(" internal error [textVec.size()<2]!")); 00369 00370 std::vector<std::string>::iterator tk_it = toksVec.begin(); 00371 std::vector<std::string>::iterator tx_it = textVec.begin(); ++tx_it; 00372 // the BIG switch - yes, this is OO!!! 00373 while(tk_it != toksVec.end() && tx_it != textVec.end()) { 00374 00375 // anynode ... token //* makes no sense (except as last entry which is forbidden ...) 00376 DCOUT_V('C', ">- anynode tkn=" << *tk_it << " d=" << tk_it-toksVec.begin() << " txt=" << *tx_it << std::endl); 00377 if ( *tk_it == "//" && *tx_it=="*" ) { 00378 path.push_back(DDPartSelRegExpLevel("","",0,ddanynode)); 00379 DCOUT_V('C', "--anynode: //*" << std::endl); 00380 ++tk_it; 00381 ++tx_it; 00382 continue; 00383 } 00384 00385 // anychild 00386 DCOUT_V('C', ">- anychild tkn=" << *tk_it << " d=" << tk_it-toksVec.begin() << " txt=" << *tx_it << std::endl); 00387 if ( *tk_it == "/" && *tx_it=="*" ) { 00388 path.push_back(DDPartSelRegExpLevel("","",0,ddanychild)); 00389 DCOUT_V('C', "--anychild: /*" << std::endl); 00390 ++tk_it; 00391 ++tx_it; 00392 continue; 00393 } 00394 00395 // anylogp 00396 DCOUT_V('C', ">- anylogp tkn=" << *tk_it << " d=" << tk_it-toksVec.begin() << " txt=" << *tx_it << std::endl); 00397 if ( *tk_it == "//" && tx_it->size()) { 00398 ++tk_it; 00399 if ( tk_it != toksVec.end() && *tk_it != "[" && *tk_it != "]") { 00400 std::pair<std::string,std::string> p(DDSplit(*tx_it)); 00401 path.push_back(DDPartSelRegExpLevel(p.second,p.first,0,ddanylogp)); 00402 DCOUT_V('C', "--anylogp: " << *tx_it << std::endl); 00403 ++tx_it; 00404 continue; 00405 } 00406 --tk_it; 00407 } 00408 00409 // childlogp 00410 DCOUT_V('C', ">- childlogp tkn=" << *tk_it << " d=" << tk_it-toksVec.begin() << " txt=" << *tx_it << std::endl); 00411 if ( *tk_it == "/" && tx_it->size()) { 00412 ++tk_it; 00413 if ( tk_it == toksVec.end() - 1 ) { 00414 DCOUT_V('C', "--childlogp: " << *tx_it << std::endl); 00415 std::pair<std::string,std::string> p(DDSplit(*tx_it)); 00416 path.push_back(DDPartSelRegExpLevel(p.second,p.first,0,ddchildlogp)); 00417 ++tx_it; 00418 continue; 00419 } 00420 if ( *tk_it == "/" || *tk_it=="//") { 00421 DCOUT_V('C', "--childlogp: " << *tx_it << std::endl); 00422 std::pair<std::string,std::string> p(DDSplit(*tx_it)); 00423 path.push_back(DDPartSelRegExpLevel(p.second,p.first,0,ddchildlogp)); 00424 ++tx_it; 00425 continue; 00426 } 00427 --tk_it; 00428 } 00429 00430 00431 // anyposp 00432 DCOUT_V('C', ">- anyposp tkn=" << *tk_it << " d=" << tk_it-toksVec.begin() << " txt=" << *tx_it << std::endl); 00433 if ( *tk_it == "//" && tx_it->size()) { 00434 ++tk_it; 00435 if ( tk_it != toksVec.end() && *tk_it == "[" ) { 00436 ++tk_it; 00437 if ( tk_it == toksVec.end() || (tk_it != toksVec.end() && *tk_it != "]")) { 00438 DCOUT_V('C', *tk_it << " " << *tx_it ); 00439 break; 00440 } 00441 ++tx_it; 00442 ++tk_it; 00443 std::pair<std::string,std::string> p(DDSplit(*(tx_it-1))); 00444 path.push_back(DDPartSelRegExpLevel(p.second,p.first,atoi(tx_it->c_str()),ddanyposp)); 00445 DCOUT_V('C', "--anyposp: " << *tx_it << " " << atoi(tx_it->c_str()) << std::endl); 00446 ++tx_it; 00447 ++tx_it; 00448 continue; 00449 } 00450 } 00451 00452 00453 // childposp 00454 DCOUT_V('C', ">- childposp tkn=" << *tk_it << " d=" << tk_it-toksVec.begin() << " txt=" << *tx_it << std::endl); 00455 if ( *tk_it == "/" && tx_it->size()) { 00456 ++tk_it; 00457 if ( tk_it != toksVec.end() && *tk_it=="[" ) { 00458 DCOUT_V('C', "--childposp: " << *tx_it << " " << *tk_it << *(tx_it+1) << std::endl); 00459 std::pair<std::string,std::string> p(DDSplit(*tx_it)); 00460 path.push_back(DDPartSelRegExpLevel(p.second,p.first,atoi((tx_it+1)->c_str()),ddchildposp)); 00461 00462 ++tx_it; 00463 00464 ++tx_it; 00465 ++tk_it; 00466 if (tk_it != toksVec.end() && *tk_it != "]") 00467 break; 00468 ++tk_it; 00469 ++tx_it; 00470 continue; 00471 } 00472 } 00473 00474 // any 00475 throw DDException( nm + std::string(" syntax error in:\n") + sel + 00476 std::string("\n tkn=") + *tk_it + std::string(" txt=")+ *tx_it); 00477 } 00478 //FIXME: DDPartSelectorImpl::tokenize : prototype has restricted support for selection std::string (code below restricts) 00479 ddselection_type tmp = path.back().selectionType_; 00480 if (tmp==ddunknown || tmp==ddanynode || tmp==ddanychild ) 00481 throw DDException(std::string("PartSelector: last element in selection std::string in ") + sel + 00482 std::string("\nmust address a distinct LogicalPart or PosPart!") ); 00483 }
void DDTokenize2 | ( | const std::string & | sel, | |
std::vector< DDPartSelRegExpLevel > & | path | |||
) |
Definition at line 265 of file DDPartSelection.cc.
References lat::endl(), full, DDI::Singleton< I >::instance(), parse(), indexGen::parser, and HLT_VtxMuL3::result.
Referenced by DDI::Specific::createPartSelections().
00266 { 00267 static SpecParParser parser; 00268 DDI::Singleton<DDSelLevelCollector>::instance().path(&path); 00269 bool result = parse(sel.c_str(), parser).full; 00270 if (!result) { 00271 edm::LogError("DDPartSelection") << "DDTokenize2() error in parsing of " << sel << std::endl; 00272 } 00273 }
void noNameSpace | ( | char const * | first, | |
char const * | last | |||
) |
Definition at line 39 of file DDPartSelection.cc.
References DDI::Singleton< I >::instance().
Referenced by SpecParParser::definition< ScannerT >::definition().
00039 { 00040 DDI::Singleton<DDSelLevelCollector>::instance().namespace_=""; 00041 }
std::ostream& operator<< | ( | std::ostream & | os, | |
const std::vector< DDPartSelection > & | v | |||
) |
Definition at line 511 of file DDPartSelection.cc.
References lat::endl(), it, and v.
00512 { 00513 std::vector<DDPartSelection>::const_iterator it(v.begin()), ed(v.end()); 00514 for (; it != (ed-1); ++it) { 00515 os << *it << std::endl; 00516 } 00517 if ( it != ed ) { 00518 ++it; 00519 os << *it; 00520 } 00521 return os; 00522 }
std::ostream& operator<< | ( | std::ostream & | o, | |
const DDPartSelection & | p | |||
) |
Definition at line 486 of file DDPartSelection.cc.
References DDPartSelectionLevel::copyno_, ddanylogp, ddanyposp, ddchildlogp, ddchildposp, DDBase< N, C >::ddname(), it, DDPartSelectionLevel::lp_, lv, and DDPartSelectionLevel::selectionType_.
00487 { 00488 DDPartSelection::const_iterator it(p.begin()), ed(p.end()); 00489 for (; it != ed; ++it) { 00490 const DDPartSelectionLevel lv =*it; 00491 switch (lv.selectionType_) { 00492 case ddanylogp: 00493 o << "//" << lv.lp_.ddname(); 00494 break; 00495 case ddanyposp: 00496 o << "//" << lv.lp_.ddname() << '[' << lv.copyno_ << ']'; 00497 break; 00498 case ddchildlogp: 00499 o << "/" << lv.lp_.ddname(); 00500 break; 00501 case ddchildposp: 00502 o << "/" << lv.lp_.ddname() << '[' << lv.copyno_ << ']'; 00503 break; 00504 default: 00505 o << "{Syntax ERROR}"; 00506 } 00507 } 00508 return o; 00509 }