File indexing completed on 2024-04-06 12:05:25
0001 #include "DetectorDescription/Core/interface/DDScope.h"
0002
0003 #include <ostream>
0004
0005 dd_scope_class DDScopeClassification::operator()(const DDGeoHistory& left, const DDGeoHistory& right) const {
0006 dd_scope_class result = subtree;
0007 DDGeoHistory::const_iterator lit = left.begin();
0008 DDGeoHistory::const_iterator rit = right.begin();
0009
0010 while (lit != left.end() && rit != right.end()) {
0011 if (lit->siblingno() != rit->siblingno()) {
0012 result = different_branch;
0013 break;
0014 }
0015 ++lit;
0016 ++rit;
0017 }
0018
0019 if (result != different_branch) {
0020 if (lit == left.end()) {
0021 result = supertree;
0022 } else {
0023 result = subtree;
0024 }
0025 }
0026 return result;
0027 }
0028
0029 DDScope::DDScope(void) : depth_(0) {}
0030
0031 DDScope::DDScope(const DDGeoHistory& h, int depth) : depth_(depth) { subtrees_.emplace_back(h); }
0032
0033 DDScope::~DDScope(void) {}
0034
0035 bool DDScope::addScope(const DDGeoHistory& h) {
0036 bool result = false;
0037 scope_type::iterator it = subtrees_.begin();
0038 scope_type buf;
0039 int supertreeCount = 0;
0040 bool diffBranch = false;
0041 bool subTree = false;
0042
0043 for (; it != subtrees_.end(); ++it) {
0044 dd_scope_class classification = classify_(h, *it);
0045 switch (classification) {
0046 case different_branch:
0047 buf.emplace_back(*it);
0048 diffBranch = true;
0049 break;
0050
0051 case subtree:
0052 buf.emplace_back(*it);
0053 subTree = true;
0054 break;
0055
0056 case supertree:
0057 ++supertreeCount;
0058 if (supertreeCount == 1)
0059 buf.emplace_back(h);
0060 break;
0061
0062 default:
0063 break;
0064 }
0065 }
0066
0067 if (diffBranch) {
0068 if (subTree == false) {
0069 buf.emplace_back(h);
0070 }
0071 }
0072
0073 if (subtrees_.empty())
0074 subtrees_.emplace_back(h);
0075 else
0076 subtrees_ = buf;
0077
0078 return result;
0079 }
0080
0081 void DDScope::setDepth(int d) { depth_ = d; }
0082
0083 int DDScope::depth(void) const { return depth_; }
0084
0085 const DDScope::scope_type& DDScope::scope(void) const { return subtrees_; }
0086
0087 std::ostream& operator<<(std::ostream& os, const DDScope& scope) {
0088 DDScope::scope_type::const_iterator it = scope.subtrees_.begin();
0089 for (; it != scope.subtrees_.end(); ++it) {
0090 os << *it << std::endl;
0091 }
0092 return os;
0093 }