Go to the documentation of this file.00001 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
00002 #include "LogicalPart.h"
00003 #include "DetectorDescription/Base/interface/DDdebug.h"
00004 #include <ostream>
00005
00006
00007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00008
00009
00010
00011
00012
00013
00014
00015
00016 void DD_NC(const DDName & n) {
00017 std::vector<DDName> & ns = LPNAMES::instance()[n.name()];
00018 typedef std::vector<DDName>::iterator IT;
00019 bool alreadyIn(false);
00020 for(IT p = ns.begin(); p != ns.end() ; ++p) {
00021 if ( p->ns() == n.ns()) {
00022 alreadyIn = true;
00023 break;
00024 }
00025 }
00026 if (!alreadyIn) {
00027 ns.push_back(n);
00028 }
00029 }
00030
00031
00032 std::ostream &
00033 operator<<(std::ostream & os, const DDLogicalPart & part)
00034 {
00035 DDBase<DDName,DDI::LogicalPart*>::def_type defined(part.isDefined());
00036 if (defined.first) {
00037 os << *(defined.first) << " ";
00038 if (defined.second) {
00039 part.rep().stream(os);
00040 }
00041 else {
00042 os << "* logicalpart not defined * ";
00043 }
00044 }
00045 else {
00046 os << "* logicalpart not declared * ";
00047 }
00048 return os;
00049 }
00050
00051
00052
00065
00066
00099 DDLogicalPart::DDLogicalPart(const DDName & name) : DDBase<DDName,DDI::LogicalPart*>()
00100 {
00101 prep_ = StoreT::instance().create(name);
00102 DD_NC(name);
00103 }
00104
00117 DDLogicalPart::DDLogicalPart(const DDName & ddname,
00118 const DDMaterial & material,
00119 const DDSolid & solid,
00120 DDEnums::Category cat)
00121 : DDBase<DDName,DDI::LogicalPart*>()
00122 {
00123 DCOUT('C', "create LogicalPart ddname=" << ddname << " mat=" << material.name() << " sol=" << solid.name());
00124 prep_ = StoreT::instance().create(ddname, new DDI::LogicalPart(material,solid,cat));
00125 DD_NC(ddname);
00126 }
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136 DDEnums::Category DDLogicalPart::category() const
00137 {
00138 return rep().category();
00139 }
00140
00141
00142 const DDMaterial & DDLogicalPart::material() const
00143 {
00144 return rep().material();
00145 }
00146
00147
00148 const DDSolid & DDLogicalPart::solid() const
00149 {
00150 return rep().solid();
00151 }
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165 double & DDLogicalPart::weight()
00166 {
00167 return rep().weight();
00168 }
00169
00170
00224 std::vector<const DDsvalues_type *> DDLogicalPart::specifics() const
00225 {
00226 std::vector<const DDsvalues_type*> result;
00227 rep().specificsV(result);
00228 return result;
00229 }
00230
00231
00232 DDsvalues_type DDLogicalPart::mergedSpecifics() const
00233 {
00234 DDsvalues_type result;
00235 rep().mergedSpecificsV(result);
00236 return result;
00237 }
00238
00239
00240 void DDLogicalPart::addSpecifics(const std::pair<DDPartSelection*,DDsvalues_type*> & s)
00241 {
00242 DCOUT('S', "lp=" << name());
00243 rep().addSpecifics(s);
00244 }
00245 void DDLogicalPart::removeSpecifics(const std::pair<DDPartSelection*,DDsvalues_type*> & s)
00246 {
00247 rep().removeSpecifics(s);
00248 }
00249 bool DDLogicalPart::hasDDValue(const DDValue & v) const
00250 {
00251 return rep().hasDDValue(v);
00252 }
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272 #include <regex.h>
00273 #include <set>
00274
00275 namespace {
00276
00277 struct Regex {
00278
00279 explicit Regex(const std::string & s) : m_ok(false), me(s) {
00280 size_t p = me.find(".");
00281 m_ok = p!=std::string::npos;
00282 if(m_ok) {
00283 if (p>0) {
00284 m_range.first = me.substr(0,p);
00285 m_range.second = m_range.first+"{";
00286 }
00287 me = "^" + me + "$";
00288 regcomp(&m_regex,me.c_str(),0);
00289 }
00290 }
00291
00292 ~Regex() { if(m_ok) regfree(&m_regex); }
00293
00294 bool empty() const { return me.empty();}
00295
00296 bool notRegex() const { return !m_ok;}
00297
00298 const std::string & value() const { return me;}
00299
00300 bool match(const std::string & s) const {
00301 if (m_ok)
00302 return !regexec(&m_regex, s.c_str(), 0,0,0);
00303 else
00304 return me==s;
00305 }
00306
00307 const std::pair< std::string, std::string> & range() const { return m_range;}
00308 private:
00309 bool m_ok;
00310 regex_t m_regex;
00311 std::string me;
00312
00313 std::pair<std::string, std::string> m_range;
00314 };
00315
00316 }
00317
00318 std::pair<bool,std::string> DDIsValid(const std::string & ns, const std::string & nm, std::vector<DDLogicalPart> & result, bool doRegex)
00319 {
00320
00321 if (!doRegex) {
00322 DDName ddnm(nm,ns);
00323 result.push_back(DDLogicalPart(ddnm));
00324 return std::make_pair(true,"");
00325 }
00326 std::string status;
00327 Regex aRegex(nm);
00328 Regex aNsRegex(ns);
00329 bool emptyNs = aNsRegex.empty();
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344 LPNAMES::value_type::const_iterator bn(LPNAMES::instance().begin()),
00345 ed(LPNAMES::instance().end());
00346 typedef std::vector< LPNAMES::value_type::const_iterator> Candidates;
00347 Candidates candidates;
00348 if ( aRegex.notRegex() ) {
00349 LPNAMES::value_type::const_iterator it = LPNAMES::instance().find(aRegex.value());
00350 if (it!=ed) candidates.push_back(it);
00351 }
00352 else {
00353 if ( !aRegex.range().first.empty()) {
00354 bn = LPNAMES::instance().lower_bound(aRegex.range().first);
00355 ed = LPNAMES::instance().upper_bound(aRegex.range().second);
00356 }
00357 for (LPNAMES::value_type::const_iterator it=bn; it != ed; ++it)
00358 if(aRegex.match(it->first)) candidates.push_back(it);
00359 }
00360 for (int i=0; i<int(candidates.size()); ++i) {
00361 LPNAMES::value_type::const_iterator it = candidates[i];
00362
00363 std::vector<DDName>::size_type sz = it->second.size();
00364 if ( emptyNs && (sz==1) ) {
00365 result.push_back(it->second[0]);
00366
00367
00368
00369
00370
00371 }
00372 else if ( !emptyNs ) {
00373 std::vector<DDName>::const_iterator nsit(it->second.begin()), nsed(it->second.end());
00374 for (; nsit !=nsed; ++nsit) {
00375
00376 bool another_doit = aNsRegex.match(nsit->ns());
00377 if ( another_doit ) {
00378
00379 result.push_back(DDLogicalPart(*nsit));
00380 }
00381 }
00382 }
00383 else {
00384 std::string message = "DDLogicalPart-name \"" + it->first +"\" matching regex \""
00385 + nm + "\" has been found at least in following namespaces:\n";
00386 std::vector<DDName>::const_iterator vit = it->second.begin();
00387 for(; vit != it->second.end(); ++vit) {
00388 message += vit->ns();
00389 message += " ";
00390 }
00391 message += "\nQualify the name with a regexp for the namespace, i.e \".*:name-regexp\" !";
00392 return std::make_pair(false,message);
00393 }
00394 }
00395 bool flag=true;
00396 std::string message;
00397
00398
00399 if (result.size()) {
00400 std::vector<DDLogicalPart>::const_iterator lpit(result.begin()), lped(result.end());
00401 for (; lpit != lped; ++lpit) {
00402
00403 if (!lpit->isDefined().second) {
00404 message = message + "LogicalPart " + lpit->name().fullname() + " not (yet) defined!\n";
00405 flag = false;
00406 }
00407 }
00408 }
00409 else {
00410 flag = false;
00411 message = "No regex-match for namespace=" + ns + " name=" + nm + "\n";
00412 }
00413
00414
00415 return std::make_pair(flag,message);
00416 }
00417
00418
00419 const std::vector< std::pair<DDPartSelection*,DDsvalues_type*> > &
00420 DDLogicalPart::attachedSpecifics() const
00421 {
00422 return rep().attachedSpecifics();
00423 }
00424
00425
00426
00427
00428
00429
00430