![]() |
![]() |
00001 #include "DetectorDescription/Core/interface/DDFilteredView.h" 00002 #include "DetectorDescription/Core/interface/DDCompactView.h" 00003 00004 // Message logger. 00005 #include "FWCore/MessageLogger/interface/MessageLogger.h" 00006 00007 DDFilteredView::DDFilteredView(const DDCompactView & cpv) 00008 : epv_(cpv) 00009 { 00010 parents_.push_back(epv_.geoHistory()); 00011 } 00012 00013 00014 DDFilteredView::~DDFilteredView() 00015 { } 00016 00017 00018 const DDLogicalPart & DDFilteredView::logicalPart() const 00019 { 00020 return epv_.logicalPart(); 00021 } 00022 00023 00024 void DDFilteredView::addFilter(const DDFilter & f, log_op op) 00025 { 00026 criteria_.push_back(&f); 00027 logOps_.push_back(op); 00028 //DCOUT('F',"DDQuery::addFilter(): log-op=" << op ); 00029 } 00030 00031 00032 const DDTranslation & DDFilteredView::translation() const 00033 { 00034 return epv_.translation(); 00035 } 00036 00037 00038 const DDRotationMatrix & DDFilteredView::rotation() const 00039 { 00040 return epv_.rotation(); 00041 } 00042 00043 00044 const DDGeoHistory & DDFilteredView::geoHistory() const 00045 { 00046 return epv_.geoHistory(); 00047 } 00048 00049 00050 std::vector<const DDsvalues_type * > DDFilteredView::specifics() const 00051 { 00052 std::vector<const DDsvalues_type * > result; epv_.specificsV(result); 00053 return result; 00054 } 00055 00056 void DDFilteredView::specificsV(std::vector<const DDsvalues_type * > & result) const 00057 { 00058 epv_.specificsV(result); 00059 } 00060 00061 void DDFilteredView::mergedSpecificsV(DDsvalues_type & merged) const 00062 { 00063 epv_.mergedSpecificsV(merged); 00064 } 00065 00066 DDsvalues_type DDFilteredView::mergedSpecifics() const 00067 { 00068 DDsvalues_type merged;epv_.mergedSpecificsV(merged); 00069 return merged; 00070 } 00071 00072 00073 int DDFilteredView::copyno() const 00074 { 00075 return epv_.copyno(); 00076 } 00077 00078 00079 const DDGeoHistory & DDFilteredView::scope() const 00080 { 00081 return epv_.scope(); 00082 } 00083 00084 00085 bool DDFilteredView::setScope(const DDGeoHistory & hist) 00086 { 00087 bool result = epv_.setScope(hist,0); 00088 if (result) { 00089 parents_.clear(); 00090 parents_.push_back(hist); 00091 } 00092 return result; 00093 } 00094 00095 00096 void DDFilteredView::clearScope() 00097 { 00098 epv_.clearScope(); 00099 parents_.clear(); 00100 parents_.push_back(epv_.geoHistory()); 00101 } 00102 00103 00104 bool DDFilteredView::next() 00105 { 00106 bool result = false; 00107 int i=0; 00108 //epv_.scope_.clear(); 00109 //DCOUT('F', "DDFilteredView::next(): scope of ExpandedView = " << epv_.scope_ ); 00110 while(epv_.next()) { 00111 //DCOUT('F', " node " << i << " " << epv_.logicalPart().ddname() ); 00112 ++i; 00113 //DCOUT('F', "DDFilteredView::next() at " << epv_.geoHistory().back() ); 00114 if ( filter() ) { 00115 result = true; 00116 //DCOUT('F', "DDFilteredView::next(): filter()==true at " << epv_.geoHistory() ); 00117 break; 00118 } 00119 } 00120 //DCOUT('F', "DDFilteredView::next(): just iterated over " << i << " nodes."); 00121 return result; 00122 } 00123 00124 00131 bool DDFilteredView::firstChild() 00132 { 00133 bool result = false; 00134 00135 // save the current position 00136 DDGeoHistory savedPos = epv_.geoHistory(); 00137 00138 // save the current scope 00139 DDGeoHistory savedScope = epv_.scope_; 00140 int savedDepth = epv_.depth_; 00141 00142 // set current node to be the scope 00143 epv_.scope_ = epv_.geoHistory(); 00144 epv_.depth_ = 0; 00145 00146 // search the subtree for the first matching node 00147 if (next()) { 00148 result = true; 00149 epv_.scope_ = savedScope; 00150 epv_.depth_ = savedDepth; 00151 } 00152 else { // restore the starting point 00153 epv_.scope_ = savedScope; 00154 epv_.depth_ = savedDepth; 00155 epv_.goToHistory(savedPos); 00156 } 00157 00158 if (result) { 00159 parents_.push_back(epv_.geoHistory()); 00160 } 00161 00162 return result; 00163 } 00164 00165 00172 bool DDFilteredView::nextSibling() 00173 { 00174 //PRE: the current node A is one matching the filter or the (scoped) root 00175 //POST: current node is A if no filter has matched, or B with matching filter 00176 // B is the firstChild matching the filter in the subtrees of A's siblings 00177 bool result = false; 00178 DDGeoHistory savedPos = epv_.geoHistory(); 00179 00180 //DDGeoHistory::size_type level = parents_.back().size(); 00181 00182 bool flag = true; 00183 //bool shuffleParent = false; 00184 while (flag) { 00185 if (epv_.nextSibling()) { 00186 if ( filter() ) { 00187 result = true; 00188 break; 00189 } 00190 else if (firstChild()) { 00191 result = true; 00192 // firstChild increases parents! 00193 parents_.pop_back(); 00194 break; 00195 } 00196 } // <-- epv_.nextSibling 00197 else if (!epv_.parent()) { 00198 flag = false; 00199 } 00200 if (epv_.geoHistory().size() == parents_[parents_.size()-2].size()) { 00201 flag = false; 00202 } 00203 } 00204 00205 if (!result) 00206 epv_.goToHistory(savedPos); 00207 else 00208 parents_.back() = epv_.geoHistory(); 00209 00210 return result; 00211 } 00212 00213 00214 bool DDFilteredView::parent() 00215 { 00216 bool result = false; 00217 00218 if (parents_.size()==1) { 00219 result = false; 00220 } 00221 else { 00222 parents_.pop_back(); 00223 epv_.goToHistory(parents_.back()); 00224 result = true; 00225 } 00226 00227 // =====> CHECK WHETHER THE FOLLOWING REMARKS STILL REPRESENT THE IMPLEMENTATION ABOVE <=== 00228 // case 1: we've reached the (scoped) root of the underlying expanded-view 00229 // from the first child of the fitered-view; result must be true 00230 // case 2: we've reached a parent-node where the filter said 'yes'; 00231 // result must be true 00232 // case 3: we are already at the (scoped) root of the underlying expanded-view 00233 // result must be false 00234 00235 return result; 00236 } 00237 00238 00239 void DDFilteredView::reset() 00240 { 00241 //while (epv_.parent()) 00242 // ; 00243 epv_.reset(); 00244 parents_.clear(); 00245 parents_.push_back(epv_.geoHistory()); 00246 } 00247 00248 00249 bool DDFilteredView::filter() 00250 { 00251 bool result = true; 00252 //DCOUT('Q', "Filter: " << epv_.history_); 00253 criteria_type::const_iterator it = criteria_.begin(); 00254 logops_type::const_iterator logOpIt = logOps_.begin(); 00255 // loop over all user-supplied criteria (==filters) 00256 for (; it != criteria_.end(); ++it, ++logOpIt) { 00257 // avoid useless evaluations 00258 if ( ( result &&(*logOpIt)==OR ) || 00259 ( (!result)&&(*logOpIt)==AND) ) continue; 00260 00261 bool locres = (*it)->accept(epv_); 00262 // need correction DCOUT('F', " Filter(" << criteria_.end()-it << ") accepted: " << epv_.geoHistory().back()); 00263 00264 // now do the logical-operations on the results encountered so far: 00265 if (*logOpIt==AND) { // AND 00266 result &= locres; 00267 } 00268 else { // OR 00269 result |= locres; 00270 } 00271 } // <-- loop over filters 00272 return result; 00273 } 00274 00275 00276 DDFilteredView::nav_type DDFilteredView::navPos() const 00277 { 00278 return epv_.navPos(); 00279 } 00280 00281 00282 DDFilteredView::nav_type DDFilteredView::copyNumbers() const 00283 { 00284 return epv_.copyNumbers(); 00285 } 00286 00287 00288 bool DDFilteredView::goTo(const DDFilteredView::nav_type & n) 00289 { 00290 // WARNING!!!!!!!!!! 00291 // NOT IMPLEMENTED!!!!!!! 00292 bool result(false); 00293 return result; 00294 } 00295 00296 00297 void DDFilteredView::print() { 00298 edm::LogInfo("DDFliteredView") << "FilteredView Status" << std::endl 00299 << "-------------------" << std::endl 00300 << "scope = " << epv_.scope_ << std::endl 00301 << "parents:" << std::endl; 00302 for (unsigned int i=0; i<parents_.size(); ++i) 00303 edm::LogInfo("DDFliteredView") << " " << parents_[i] << std::endl; 00304 00305 } 00306 00307 00308 const std::vector<DDGeoHistory> & DDFilteredView::history() const 00309 { 00310 return parents_; 00311 }