Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:54:56

0001 #include "DetectorDescription/Core/interface/DDFilteredView.h"
0002 
0003 #include <iterator>
0004 #include <memory>
0005 #include <ostream>
0006 
0007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0008 
0009 class DDCompactView;
0010 class DDLogicalPart;
0011 
0012 DDFilteredView::DDFilteredView(const DDCompactView& cpv, const DDFilter& fltr) : epv_(cpv), filter_(&fltr) {
0013   parents_.emplace_back(epv_.geoHistory());
0014 }
0015 
0016 const DDLogicalPart& DDFilteredView::logicalPart() const { return epv_.logicalPart(); }
0017 
0018 const std::string& DDFilteredView::name() const { return epv_.logicalPart().name().name(); }
0019 
0020 const DDSolidShape DDFilteredView::shape() const { return epv_.logicalPart().solid().shape(); }
0021 
0022 std::string const DDFilteredView::material() const { return epv_.logicalPart().material().name().fullname(); }
0023 
0024 const std::vector<double>& DDFilteredView::parameters() const { return epv_.logicalPart().solid().parameters(); }
0025 
0026 const DDTranslation& DDFilteredView::translation() const { return epv_.translation(); }
0027 
0028 const DDRotationMatrix& DDFilteredView::rotation() const { return epv_.rotation(); }
0029 
0030 const DDGeoHistory& DDFilteredView::geoHistory() const { return epv_.geoHistory(); }
0031 
0032 std::vector<const DDsvalues_type*> DDFilteredView::specifics() const {
0033   std::vector<const DDsvalues_type*> result;
0034   epv_.specificsV(result);
0035   return result;
0036 }
0037 
0038 void DDFilteredView::specificsV(std::vector<const DDsvalues_type*>& result) const { epv_.specificsV(result); }
0039 
0040 void DDFilteredView::mergedSpecificsV(DDsvalues_type& merged) const { epv_.mergedSpecificsV(merged); }
0041 
0042 DDsvalues_type DDFilteredView::mergedSpecifics() const {
0043   DDsvalues_type merged;
0044   epv_.mergedSpecificsV(merged);
0045   return merged;
0046 }
0047 
0048 int DDFilteredView::copyno() const { return epv_.copyno(); }
0049 
0050 const DDGeoHistory& DDFilteredView::scope() const { return epv_.scope(); }
0051 
0052 bool DDFilteredView::setScope(const DDGeoHistory& hist) {
0053   bool result = epv_.setScope(hist, 0);
0054   if (result) {
0055     parents_.clear();
0056     parents_.emplace_back(hist);
0057   }
0058   return result;
0059 }
0060 
0061 void DDFilteredView::clearScope() {
0062   epv_.clearScope();
0063   parents_.clear();
0064   parents_.emplace_back(epv_.geoHistory());
0065 }
0066 
0067 bool DDFilteredView::next() {
0068   bool result = false;
0069   int i = 0;
0070   while (epv_.next()) {
0071     ++i;
0072     if (filter()) {
0073       result = true;
0074       break;
0075     }
0076   }
0077   return result;
0078 }
0079 
0080 /**
0081  Algorithm:
0082   
0083   - find the first child matching the filter down the current subtree using next()
0084     which transverses already in the required hierarchical sequence ... 
0085 */
0086 bool DDFilteredView::firstChild() {
0087   bool result = false;
0088 
0089   // save the current position
0090   DDGeoHistory savedPos = epv_.geoHistory();
0091 
0092   // save the current scope
0093   DDGeoHistory savedScope = epv_.scope_;
0094   int savedDepth = epv_.depth_;
0095 
0096   // set current node to be the scope
0097   epv_.scope_ = epv_.geoHistory();
0098   epv_.depth_ = 0;
0099 
0100   // search the subtree for the first matching node
0101   if (next()) {
0102     result = true;
0103     epv_.scope_ = savedScope;
0104     epv_.depth_ = savedDepth;
0105   } else {  // restore the starting point
0106     epv_.scope_ = savedScope;
0107     epv_.depth_ = savedDepth;
0108     epv_.goToHistory(savedPos);
0109   }
0110 
0111   if (result) {
0112     parents_.emplace_back(epv_.geoHistory());
0113   }
0114 
0115   return result;
0116 }
0117 
0118 /**
0119   Algorithm:
0120   
0121   - find the first node - which matches the filter - in the subtrees of the siblings of
0122     the current node
0123 */
0124 bool DDFilteredView::nextSibling() {
0125   //PRE:  the current node A is one matching the filter or the (scoped) root
0126   //POST: current node is A if no filter has matched, or B with matching filter
0127   //      B is the firstChild matching the filter in the subtrees of A's siblings
0128   bool result = false;
0129   DDGeoHistory savedPos = epv_.geoHistory();
0130 
0131   bool flag = true;
0132   //bool shuffleParent = false;
0133   while (flag) {
0134     if (epv_.nextSibling()) {
0135       if (filter()) {
0136         result = true;
0137         break;
0138       } else if (firstChild()) {
0139         result = true;
0140         // firstChild increases parents!
0141         parents_.pop_back();
0142         break;
0143       }
0144     }  // <-- epv_.nextSibling
0145     else if (!epv_.parent()) {
0146       flag = false;
0147     }
0148     if (epv_.geoHistory().size() == parents_[parents_.size() - 2].size()) {
0149       flag = false;
0150     }
0151   }
0152 
0153   if (!result)
0154     epv_.goToHistory(savedPos);
0155   else
0156     parents_.back() = epv_.geoHistory();
0157 
0158   return result;
0159 }
0160 
0161 bool DDFilteredView::parent() {
0162   bool result = false;
0163 
0164   if (parents_.size() == 1) {
0165     result = false;
0166   } else {
0167     parents_.pop_back();
0168     epv_.goToHistory(parents_.back());
0169     result = true;
0170   }
0171 
0172   // =====> CHECK WHETHER THE FOLLOWING REMARKS STILL REPRESENT THE IMPLEMENTATION ABOVE <===
0173   // case 1: we've reached the (scoped) root of the underlying expanded-view
0174   //         from the first child of the fitered-view; result must be true
0175   // case 2: we've reached a parent-node where the filter said 'yes';
0176   //         result must be true
0177   // case 3: we are already at the (scoped) root of the underlying expanded-view
0178   //         result must be false
0179 
0180   return result;
0181 }
0182 
0183 void DDFilteredView::reset() {
0184   epv_.reset();
0185   parents_.clear();
0186   parents_.emplace_back(epv_.geoHistory());
0187 }
0188 
0189 bool DDFilteredView::filter() { return filter_->accept(epv_); }
0190 
0191 DDFilteredView::nav_type DDFilteredView::navPos() const { return epv_.navPos(); }
0192 
0193 DDFilteredView::nav_type DDFilteredView::copyNumbers() const { return epv_.copyNumbers(); }
0194 
0195 bool DDFilteredView::goTo(const DDFilteredView::nav_type& /*n*/) {
0196   // WARNING!!!!!!!!!!
0197   // NOT IMPLEMENTED!!!!!!!
0198   bool result(false);
0199   return result;
0200 }
0201 
0202 void DDFilteredView::print() {
0203   edm::LogInfo("DDFliteredView") << "FilteredView Status" << std::endl
0204                                  << "-------------------" << std::endl
0205                                  << "scope = " << epv_.scope_ << std::endl
0206                                  << "parents:" << std::endl;
0207   for (const auto& parent : parents_)
0208     edm::LogInfo("DDFliteredView") << "  " << parent << std::endl;
0209 }
0210 
0211 const std::vector<DDGeoHistory>& DDFilteredView::history() const { return parents_; }