Go to the documentation of this file.00001 #include "DetectorDescription/Core/interface/DDExpandedView.h"
00002 #include "DetectorDescription/Core/interface/DDComparator.h"
00003
00007 DDExpandedView::DDExpandedView(const DDCompactView & cpv)
00008 : walker_(0),w2_(cpv.graph(),cpv.root()), trans_(DDTranslation()), rot_(DDRotationMatrix()),
00009 depth_(0), worldpos_(0)
00010 {
00011
00012
00013
00014
00015 DDRotation::StoreT::instance().setReadOnly(false);
00016 worldpos_ = new DDPosData(DDTranslation(),DDRotation(),0);
00017 DDRotation::StoreT::instance().setReadOnly(true);
00018
00019 walker_ = &w2_;
00020
00021
00022
00023
00024 DDPosData * pd((*walker_).current().second);
00025 if (!pd)
00026 pd = worldpos_;
00027 DDExpandedNode expn((*walker_).current().first,
00028 pd,
00029 trans_,
00030 rot_,
00031 0);
00032
00033
00034 history_.push_back(expn);
00035 }
00036
00037
00038 DDExpandedView::~DDExpandedView() { }
00039
00040
00041 const DDLogicalPart & DDExpandedView::logicalPart() const
00042 {
00043 return history_.back().logp_;
00044 }
00045
00046
00047 const DDTranslation & DDExpandedView::translation() const
00048 {
00049 return history_.back().trans_;
00050 }
00051
00052
00053 const DDRotationMatrix & DDExpandedView::rotation() const
00054 {
00055 return history_.back().rot_;
00056 }
00057
00058
00059 const DDGeoHistory & DDExpandedView::geoHistory() const
00060 {
00061 return history_;
00062 }
00063
00064
00065 int DDExpandedView::depth() const
00066 {
00067 return depth_;
00068 }
00069
00070
00071 int DDExpandedView::copyno() const
00072 {
00073 return history_.back().copyno();
00074 }
00075
00076
00077 namespace {
00078
00079 struct Counter {
00080 int same;
00081 int diff;
00082 ~Counter() {
00083 }
00084
00085 };
00086
00087 inline Counter & counter() {
00088 static Counter local;
00089 return local;
00090 }
00091
00092
00093 }
00094
00095
00101 bool DDExpandedView::nextSibling()
00102 {
00103 bool result(false);
00104 if (scope_.size() && history_.back() == scope_.back()) {
00105 ;
00106 }
00107 else {
00108 if ((*walker_).nextSibling()) {
00109 DDExpandedNode & expn(history_.back());
00110 DDCompactView::walker_type::value_type curr = (*walker_).current();
00111 DDPosData const * posdOld = expn.posd_;
00112 expn.logp_=curr.first;
00113 expn.posd_=curr.second;
00114
00115 DDGeoHistory::size_type hsize = history_.size();
00116
00117
00118 if (hsize>1) {
00119 const DDExpandedNode & expnBefore(history_[hsize-2]);
00120
00121
00122 expn.trans_ = expnBefore.trans_ + (expnBefore.rot_ * expn.posd_->trans_);
00123
00124
00125
00126 if ( !(expn.posd_->rot()==posdOld->rot()) ) {
00127 expn.rot_ = expnBefore.rot_ * expn.posd_->rot();
00128 ++counter().diff;
00129 }else ++counter().same;
00130
00131 }
00132 else {
00133 expn.trans_ = expn.posd_->trans_;
00134 expn.rot_ = expn.posd_->rot();
00135 }
00136 ++expn.siblingno_;
00137 result = true;
00138 }
00139 }
00140 return result;
00141 }
00142
00143
00148 bool DDExpandedView::firstChild()
00149 {
00150 bool result(false);
00151 bool depthNotReached(true);
00152
00153
00154 if (depth_) {
00155 if ( (history_.size()-scope_.size())==depth_ ) {
00156 depthNotReached=false;
00157 }
00158 }
00159 if (depthNotReached) {
00160 if ((*walker_).firstChild()) {
00161 DDExpandedNode & expnBefore(history_.back());
00162 DDCompactView::walker_type::value_type curr = (*walker_).current();
00163
00164 DDPosData * newPosd = curr.second;
00165
00166
00167 DDTranslation newTrans = expnBefore.trans_ + expnBefore.rot_ * newPosd->trans_;
00168
00169
00170 DDRotationMatrix newRot = expnBefore.rot_ * newPosd->rot();
00171
00172
00173 DDExpandedNode expn(curr.first, curr.second,
00174 newTrans, newRot, 0);
00175
00176 history_.push_back(expn);
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188 result = true;
00189 }
00190 }
00191 return result;
00192 }
00193
00194
00199 bool DDExpandedView::parent()
00200 {
00201 bool result(false);
00202 bool scopeRoot(false);
00203
00204
00205 if (scope_.size()) {
00206 if (scope_.back() == history_.back()) {
00207
00208 scopeRoot = true;
00209 }
00210 }
00211
00212 if (!scopeRoot) {
00213 if ((*walker_).parent()) {
00214 history_.pop_back();
00215 result = true;
00216 }
00217 }
00218
00219 return result;
00220 }
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00246 bool DDExpandedView::next()
00247 {
00248 bool res(false);
00249 if(firstChild())
00250 res=true;
00251 else if(nextSibling())
00252 res=true;
00253 else {
00254 while(parent()) {
00255
00256 if(nextSibling()) {
00257
00258 res=true;
00259 break;
00260 }
00261 }
00262
00263 }
00264 return res;
00265 }
00266
00267
00269 bool DDExpandedView::nextB()
00270 {
00271 bool res(false);
00272 return res;
00273 }
00274
00275
00276 void dump(const DDGeoHistory & h)
00277 {
00278 DDGeoHistory::const_iterator it = h.begin();
00279 edm::LogInfo("DDExpandedView") << "--GeoHistory-Dump--[" << std::endl;
00280 int i=0;
00281 for (; it != h.end(); ++it) {
00282 edm::LogInfo("DDExpandedView") << " " << i << it->logicalPart() << std::endl;
00283
00284
00285
00286
00287 ++i;
00288 }
00289 edm::LogInfo("DDExpandedView") << "]---------" << std::endl;
00290 }
00291
00300 std::vector< const DDsvalues_type *> DDExpandedView::specifics() const
00301 {
00302
00303 std::vector<const DDsvalues_type * > result;
00304 specificsV(result);
00305 return result;
00306 }
00307
00308 void DDExpandedView::specificsV(std::vector<const DDsvalues_type * > & result) const
00309 {
00310 unsigned int i(0);
00311
00312 const std::vector<std::pair<DDPartSelection*, DDsvalues_type*> > & specs = logicalPart().attachedSpecifics();
00313 if (specs.size()) {
00314
00315 result.reserve(specs.size());
00316 for (; i<specs.size(); ++i) {
00317 const std::pair<DDPartSelection*,DDsvalues_type*>& sp = specs[i];
00318
00319 const DDPartSelection & psel = *(sp.first);
00320
00321
00322 const DDGeoHistory & hist = geoHistory();
00323
00324
00325
00326
00327 if (DDCompareEqual(hist, psel)())
00328 result.push_back( sp.second );
00329 }
00330 }
00331 }
00332
00333
00334 DDsvalues_type DDExpandedView::mergedSpecifics() const {
00335 DDsvalues_type merged;
00336 mergedSpecificsV(merged);
00337 return merged;
00338 }
00339
00340
00341 void DDExpandedView::mergedSpecificsV(DDsvalues_type & merged) const
00342 {
00343
00344 merged.clear();
00345 const std::vector<std::pair<DDPartSelection*, DDsvalues_type*> > & specs = logicalPart().attachedSpecifics();
00346 if (specs.empty()) return;
00347 const DDGeoHistory & hist = geoHistory();
00348 for (size_t i=0; i<specs.size(); ++i) {
00349 const std::pair<DDPartSelection*,DDsvalues_type*>& sp = specs[i];
00350 const DDPartSelection & psel = *(sp.first);
00351 if (DDCompareEqual(hist, psel)())
00352 merge(merged,*sp.second);
00353 }
00354
00355 }
00356
00357
00364 const DDGeoHistory & DDExpandedView::scope() const
00365 {
00366 return scope_;
00367 }
00368
00369 void DDExpandedView::clearScope()
00370 {
00371 scope_.clear();
00372 depth_=0;
00373 }
00374
00375
00376 void DDExpandedView::reset()
00377 {
00378 clearScope();
00379 while(parent())
00380 ;
00381 }
00382
00383
00394 bool DDExpandedView::setScope(const DDGeoHistory & sc, int depth)
00395 {
00396 bool result(false);
00397
00398 DDGeoHistory buf = scope_;
00399 scope_.clear();
00400
00401 while (parent()) ;
00402
00403 if (descend(sc)) {
00404 scope_ = sc;
00405 depth_ = depth;
00406 result = true;
00407 }
00408 else {
00409 scope_ = buf;
00410 }
00411
00412 return result;
00413 }
00414
00415
00422 bool DDExpandedView::goToHistory(const DDGeoHistory & pos)
00423 {
00424 bool result = true;
00425 int tempD = depth_;
00426
00427 DDGeoHistory tempScope = scope_;
00428 reset();
00429 DDGeoHistory::size_type s = pos.size();
00430 for( DDGeoHistory::size_type j=1; j<s; ++j) {
00431 if (! firstChild()) {
00432 result = false;
00433
00434
00435 break;
00436 }
00437 int i=0;
00438 for (; i<pos[j].siblingno(); ++i) {
00439 if (! nextSibling()) {
00440
00441 result = false;
00442 }
00443 }
00444 }
00445
00446 if (!result) {
00447 reset();
00448 setScope(tempScope, tempD);
00449 }
00450 else {
00451 scope_ = tempScope;
00452 depth_ = tempD;
00453 }
00454
00455
00456 return result;
00457 }
00458
00460 bool DDExpandedView::descend(const DDGeoHistory & sc)
00461 {
00462 DDGeoHistory::size_type mxx = sc.size();
00463 DDGeoHistory::size_type cur = 0;
00464 bool result(false);
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475 const DDExpandedNode & curNode = history_.back();
00476
00477 if (sc.size()) {
00478
00479 if (curNode==sc[cur]) {
00480 bool res(false);
00481 while(cur+1 < mxx && firstChild()) {
00482 ++cur;
00483
00484 if (!(history_.back()==sc[cur])) {
00485 while(nextSibling()) {
00486
00487 if (history_.back()==sc[cur]) {
00488 res=true;
00489 break;
00490 }
00491 }
00492 }
00493 else {
00494 res=true;
00495 }
00496 if (res==false)
00497 break;
00498 }
00499 result = res;
00500 }
00501 }
00502 return result;
00503 }
00504
00505
00506 bool DDExpandedView::goTo(const nav_type & newpos) {
00507 return goTo(&newpos.front(),newpos.size());
00508
00509 }
00510
00511 bool DDExpandedView::goTo(NavRange newpos) {
00512 return goTo(newpos.first,newpos.second);
00513 }
00514
00515 bool DDExpandedView::goTo(int const * newpos, size_t sz)
00516 {
00517 bool result(false);
00518
00519
00520
00521 DDGeoHistory savedPos = history_;
00522
00523
00524
00525 reset();
00526
00527
00528 for (size_t i = 1; i < sz; ++i) {
00529 result = firstChild();
00530 if (result) {
00531 int pos = newpos[i];
00532 for(int k=0; k<pos; ++k) {
00533 result = nextSibling();
00534 }
00535 }
00536 else {
00537 break;
00538 }
00539 }
00540
00541 if (!result) {
00542 goToHistory(savedPos);
00543 }
00544 return result;
00545 }
00546
00547
00548 DDExpandedView::nav_type DDExpandedView::navPos() const
00549 {
00550 DDGeoHistory::size_type i=0;
00551 DDGeoHistory::size_type j=history_.size();
00552 nav_type pos(j);
00553
00554 for (;i<j;++i)
00555 pos[i] = history_[i].siblingno();
00556
00557 return pos;
00558 }
00559
00560 DDExpandedView::nav_type DDExpandedView::copyNumbers() const
00561 {
00562 DDGeoHistory::size_type it = 0;
00563 DDGeoHistory::size_type sz = history_.size();
00564 nav_type result(sz);
00565
00566 for (; it < sz; ++it) {
00567 result[it] = history_[it].copyno();
00568 }
00569 return result;
00570 }
00571
00572 std::ostream & printNavType(std::ostream & os, int const * n, size_t sz){
00573 os << '(' ;
00574 for (int const * it=n; it != n+sz; ++it) {
00575 os << *it << ',';
00576 }
00577 os << ')';
00578 return os;
00579 }
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612
00613