#include <iostream>
#include <vector>
#include <string>
#include <map>
#include "DetectorDescription/Core/interface/DDName.h"
#include "DetectorDescription/Core/interface/DDBase.h"
#include "DetectorDescription/Core/interface/DDEnums.h"
#include "DetectorDescription/Base/interface/Singleton.h"
#include "DetectorDescription/Core/interface/DDsvalues.h"
Go to the source code of this file.
Namespaces | |
namespace | DDI |
Classes | |
class | DDLogicalPart |
A DDLogicalPart aggregates information concerning material, solid and sensitveness ... More... | |
Typedefs | |
typedef DDI::Singleton < std::map< std::string, std::vector< DDName > > > | LPNAMES |
Functions | |
void | DD_NC (const DDName &) |
std::pair< bool, std::string > | DDIsValid (const std::string &ns, const std::string &name, std::vector< DDLogicalPart > &result, bool doRegex=true) |
std::ostream & | operator<< (std::ostream &, const DDLogicalPart &) |
typedef DDI::Singleton<std::map<std::string,std::vector<DDName> > > LPNAMES |
Definition at line 156 of file DDLogicalPart.h.
Definition at line 15 of file DDLogicalPart.cc.
References DDI::Singleton< I >::instance(), DDName::name(), DDName::ns(), and p.
Referenced by DDDivision::DDDivision(), and DDLogicalPart::DDLogicalPart().
00015 { 00016 std::vector<DDName> & ns = LPNAMES::instance()[n.name()]; 00017 typedef std::vector<DDName>::iterator IT; 00018 bool alreadyIn(false); 00019 for(IT p = ns.begin(); p != ns.end() ; ++p) { 00020 if ( p->ns() == n.ns()) { 00021 alreadyIn = true; 00022 break; 00023 } 00024 } 00025 if (!alreadyIn) { 00026 ns.push_back(n); 00027 } 00028 }
std::pair<bool,std::string> DDIsValid | ( | const std::string & | ns, | |
const std::string & | name, | |||
std::vector< DDLogicalPart > & | result, | |||
bool | doRegex = true | |||
) |
Definition at line 317 of file DDLogicalPart.cc.
References DDBase< DDName, DDI::LogicalPart * >::begin(), DDLogicalPart::DDLogicalPart(), DDBase< DDName, DDI::LogicalPart * >::end(), i, DDI::Singleton< I >::instance(), int, it, and StDecayID::status.
Referenced by DDI::Specific::createPartSelections().
00318 { 00319 //return std::make_pair(true,""); 00320 if (!doRegex) { 00321 DDName ddnm(nm,ns); 00322 result.push_back(DDLogicalPart(ddnm)); 00323 return std::make_pair(true,""); 00324 } 00325 std::string status; 00326 Regex aRegex(nm); 00327 Regex aNsRegex(ns); 00328 bool emptyNs = aNsRegex.empty(); 00329 // std::cerr << "regex " << nm << " " << ns << std::endl; 00330 00331 //edm::LogInfo("DDLogicalPart") << " . emptyNs=" << emptyNs << std::endl; 00332 //edm::LogInfo("DDLogicalPart") << " . qname=[" << ns << ":" << nm << "]" << std::endl; 00333 00334 // THIS IS THE SLOW PART: I have to compare every namespace & name of every 00335 // logical part with a regex-comparison .... a linear search always through the 00336 // full range of logical parts!!!! 00337 /* 00338 Algorithm description: 00339 x. empty nm and ns argument of method means: use all matching regex ^.*$ 00340 a. iterate over all logical part names, match against regex for names 00341 b. iterate over all namespaces of names found in a & match against regex for namespaces 00342 */ 00343 LPNAMES::value_type::const_iterator bn(LPNAMES::instance().begin()), 00344 ed(LPNAMES::instance().end()); 00345 typedef std::vector< LPNAMES::value_type::const_iterator> Candidates; 00346 Candidates candidates; 00347 if ( aRegex.notRegex() ) { 00348 LPNAMES::value_type::const_iterator it = LPNAMES::instance().find(aRegex.value()); 00349 if (it!=ed) candidates.push_back(it); 00350 } 00351 else { 00352 if ( !aRegex.range().first.empty()) { 00353 bn = LPNAMES::instance().lower_bound(aRegex.range().first); 00354 ed = LPNAMES::instance().upper_bound(aRegex.range().second); 00355 } 00356 for (LPNAMES::value_type::const_iterator it=bn; it != ed; ++it) 00357 if(aRegex.match(it->first)) candidates.push_back(it); 00358 } 00359 for (int i=0; i<int(candidates.size()); ++i) { 00360 LPNAMES::value_type::const_iterator it = candidates[i]; 00361 //if (doit) edm::LogInfo("DDLogicalPart") << "rgx: " << aName << ' ' << it->first << ' ' << doit << std::endl; 00362 std::vector<DDName>::size_type sz = it->second.size(); // no of 'compatible' namespaces 00363 if ( emptyNs && (sz==1) ) { // accept all logical parts in all the namespaces 00364 result.push_back(it->second[0]); 00365 //std::vector<DDName>::const_iterator nsIt(it->second.begin()), nsEd(it->second.end()); 00366 //for(; nsIt != nsEd; ++nsIt) { 00367 // result.push_back(DDLogicalPart(*nsIt)); 00368 // edm::LogInfo("DDLogicalPart") << "DDD-WARNING: multiple namespaces match (in SpecPars PartSelector): " << *nsIt << std::endl; 00369 //} 00370 } 00371 else if ( !emptyNs ) { // only accept matching namespaces 00372 std::vector<DDName>::const_iterator nsit(it->second.begin()), nsed(it->second.end()); 00373 for (; nsit !=nsed; ++nsit) { 00374 //edm::LogInfo("DDLogicalPart") << "comparing " << aNs << " with " << *nsit << std::endl; 00375 bool another_doit = aNsRegex.match(nsit->ns()); 00376 if ( another_doit ) { 00377 //temp.push_back(std::make_pair(it->first,*nsit)); 00378 result.push_back(DDLogicalPart(*nsit)); 00379 } 00380 } 00381 } 00382 else { // emtpyNs and sz>1 -> error, too ambigous 00383 std::string message = "DDLogicalPart-name \"" + it->first +"\" matching regex \"" 00384 + nm + "\" has been found at least in following namespaces:\n"; 00385 std::vector<DDName>::const_iterator vit = it->second.begin(); 00386 for(; vit != it->second.end(); ++vit) { 00387 message += vit->ns(); 00388 message += " "; 00389 } 00390 message += "\nQualify the name with a regexp for the namespace, i.e \".*:name-regexp\" !"; 00391 return std::make_pair(false,message); 00392 } 00393 } 00394 bool flag=true; 00395 std::string message; 00396 00397 // check whether the found logical-parts are also defined (i.e. have material, solid ...) 00398 if (result.size()) { 00399 std::vector<DDLogicalPart>::const_iterator lpit(result.begin()), lped(result.end()); 00400 for (; lpit != lped; ++lpit) { 00401 // std::cout << "VI- " << std::string(lpit->name()) << std::endl; 00402 if (!lpit->isDefined().second) { 00403 message = message + "LogicalPart " + std::string(lpit->name()) + " not (yet) defined!\n"; 00404 flag = false; 00405 } 00406 } 00407 } 00408 else { 00409 flag = false; 00410 message = "No regex-match for namespace=" + ns + " name=" + nm + "\n"; 00411 } 00412 00413 00414 return std::make_pair(flag,message); 00415 }
std::ostream& operator<< | ( | std::ostream & | , | |
const DDLogicalPart & | ||||
) |
Definition at line 32 of file DDLogicalPart.cc.
References DDBase< N, C >::isDefined(), and DDBase< N, C >::rep().
00033 { 00034 DDBase<DDName,DDI::LogicalPart*>::def_type defined(part.isDefined()); 00035 if (defined.first) { 00036 os << *(defined.first) << " "; 00037 if (defined.second) { 00038 part.rep().stream(os); 00039 } 00040 else { 00041 os << "* logicalpart not defined * "; 00042 } 00043 } 00044 else { 00045 os << "* logicalpart not declared * "; 00046 } 00047 return os; 00048 }