CMS 3D CMS Logo

DDFilter.cc
Go to the documentation of this file.
2 
3 #include <cstddef>
4 #include <iterator>
5 #include <string>
6 #include <utility>
7 
13 
15 { }
16 
18 { }
19 
20 // =======================================================================
21 // =======================================================================
22 
34 // ================================================================================================
36  : DDFilter()
37 { }
38 
40 
41 
42 void DDSpecificsFilter::setCriteria(const DDValue & nameVal, // name & value of a variable
43  DDCompOp op)
44 {
45  criteria_.emplace_back(SpecificCriterion(nameVal,op));
46  }
47 
48 bool DDSpecificsFilter::accept(const DDExpandedView & node) const
49 {
50  return accept_impl(node);
51 }
52 
54 {
55  bool result = true;
56  const DDLogicalPart & logp = node.logicalPart();
57 
58  for( auto it = begin(criteria_); it != end(criteria_); ++it) {
59  bool locres=false;
60  if (logp.hasDDValue(it->nameVal_)) {
61 
62  const auto& specs = logp.attachedSpecifics();
63 
64  const auto& hist = node.geoHistory();
65  bool decided = false;
66  for(auto const& spec: specs) {
67  if(DDCompareEqual(hist,*spec.first)()) {
68  for(auto const& v: *(spec.second) ) {
69  if(it->nameVal_.id() == v.first) {
70  switch (it->comp_) {
71  case DDCompOp::equals:
72  {
73  locres= (it->nameVal_.strings() == v.second.strings());
74  break;
75  }
77  {
78  locres= ( it->nameVal_.strings() != v.second.strings() );
79  break;
80  }
81  default:
82  return false;
83  }
84  decided = true;
85  break;
86  }
87  }
88  if(decided) {
89  break;
90  }
91  }
92  }
93  }
94  result &= locres;
95  // avoid useless evaluations
96  if(!result) {
97  break;
98  }
99  }
100  return result;
101 }
102 
103 bool
105  const DDLogicalPart & logp = node.logicalPart();
106 
107  if (logp.hasDDValue(attribute_)) {
108 
109  const auto& specs = logp.attachedSpecifics();
110 
111  const auto& hist = node.geoHistory();
112  for(auto const& spec: specs) {
113  for(auto const& v: *(spec.second) ) {
114  if(attribute_.id() == v.first) {
115  //DDCompareEqual is slow so only call
116  // when needed
117  if(DDCompareEqual(hist,*spec.first)()) {
118  return true;
119  } else {
120  //since we know this isn't in the correct
121  // geometry path we do not have to check
122  // anymore attributes
123  break;
124  }
125  }
126  }
127  }
128  }
129  return false;
130 }
131 
132 bool
134  const DDLogicalPart & logp = node.logicalPart();
135 
136  if (logp.hasDDValue(value_)) {
137 
138  const auto& specs = logp.attachedSpecifics();
139 
140  const auto& hist = node.geoHistory();
141  for(auto const& spec: specs) {
142  for(auto const& v: *(spec.second) ) {
143  if(value_.id() == v.first) {
144  if(DDCompareEqual(hist,*spec.first)()) {
145  return (value_.strings() == v.second.strings());
146  } else {
147  //since we know this isn't in the correct
148  // geometry path we do not have to check
149  // anymore attributes
150  break;
151  }
152  }
153  }
154  }
155  }
156  return false;
157 
158 }
bool accept(const DDExpandedView &) const final
true, if the DDExpandedNode fulfills the filter criteria
Definition: DDFilter.cc:133
virtual ~DDFilter()
Definition: DDFilter.cc:17
bool hasDDValue(const DDValue &) const
compares a given geometrical-history whether it corresponds to the given part-selector ...
Definition: DDComparator.h:16
bool accept_impl(const DDExpandedView &) const
Definition: DDFilter.cc:53
const DDGeoHistory & geoHistory() const
The list of ancestors up to the root-node of the current node.
std::vector< SpecificCriterion > criteria_
Definition: DDFilter.h:65
void setCriteria(const DDValue &nameVal, DDCompOp)
Definition: DDFilter.cc:42
bool accept(const DDExpandedView &) const final
true, if the DDExpandedNode fulfills the filter criteria
Definition: DDFilter.cc:48
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:93
#define end
Definition: vmac.h:39
DDCompOp
comparison operators to be used with this filter
Definition: DDFilter.h:12
DDFilter()
Definition: DDFilter.cc:14
#define begin
Definition: vmac.h:32
A Filter accepts or rejects a DDExpandedNode based on a user-coded decision rule. ...
Definition: DDFilter.h:15
const DDLogicalPart & logicalPart() const
The logical-part of the current node in the expanded-view.
~DDSpecificsFilter() override
Definition: DDFilter.cc:39
const std::vector< std::pair< const DDPartSelection *, const DDsvalues_type * > > & attachedSpecifics(void) const
Provides an exploded view of the detector (tree-view)
bool accept(const DDExpandedView &) const final
true, if the DDExpandedNode fulfills the filter criteria
Definition: DDFilter.cc:104