CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DDQuery.cc
Go to the documentation of this file.
3 
5  : epv_(cpv), scope_(0)
6 { }
7 
8 
10 { }
11 
12 
17 {
18  // cheating a bit with const ....
19  // Filters have a non-const ::accept(..) member function to allow
20  // a possible internal state change in a particular filter implementation ...
21  DDFilter * nonConstFilter = const_cast<DDFilter *>(&f);
22  criteria_.push_back(std::make_pair(false,nonConstFilter));
23  logOps_.push_back(op);
24 }
25 
26 
27 void DDQuery::setScope(const DDScope & s)
28 {
29  scope_ = &s;
30 }
31 
32 
33 const std::vector<DDExpandedNode> & DDQuery::exec()
34 {
35  result_.clear();
36  epv_.reset();
37 
38  // currently at least one filter must be set, because
39  // the query simply consists in applying at least one filter!
40  if(criteria_.size()) { // <- remove the 'if' when implementing 'the QUERY'
41  int depth = 0;
42  bool scoped = false;
43  DDScope::scope_type dummy;
44  DDScope::scope_type::const_iterator it = dummy.begin();
45  DDScope::scope_type::const_iterator it_end = dummy.end();
46  if (scope_) {
47  const DDScope & sc = *scope_;
48  it = sc.scope().begin();
49  depth = sc.depth();
50  scoped = bool(sc.scope().end()-it);
51  }
52 
53  bool runonce = scoped ? false : true;
54 
55  while (runonce || (it != it_end) ) {
56  if (scoped) epv_.setScope(*it,depth); // set the subtree-scope & depth within
57  bool run = true;
58  while(run) {
59  std::vector<const DDsvalues_type *> specs = epv_.specifics();
60  auto logOpIt = logOps_.begin();
61  // loop over all user-supplied criteria (==filters)
62  bool result=true;
63  for( auto it = begin(criteria_); it != end(criteria_); ++it, ++logOpIt) {
64  DDFilter * filter = it->second;
65  if (filter->accept(epv_)) {
66  it->first=true;
67  }
68  else {
69  it->first=false;
70  }
71 
72  // now do the logical-operations on the results encountered so far:
73  if (*logOpIt == DDLogOp::AND) { // AND
74  result &= it->first;
75  }
76  else { // OR
77  result |= it->first;
78  }
79  } // <-- loop over filters
80  if (result) {
81  // HERE THE ACTUAL QUERY SHOULD BE INVOKED!!!
82  result_.push_back(epv_.geoHistory().back());
83  }
84  //} <-- loop over std::vector of specifics_type ...
85  run = epv_.next();
86  }
87  if (scoped)
88  ++it;
89  else
90  runonce=false;
91  }
92  }
93  return result_;
94 }
bool next()
set current node to the next node in the expanded tree
DDLogOp
logical operations to obtain one result from two filter comparisons
Definition: DDFilter.h:15
virtual const std::vector< DDExpandedNode > & exec()
Definition: DDQuery.cc:33
std::vector< const DDsvalues_type * > specifics() const
User specific data attached to the current node.
virtual void addFilter(const DDFilter &, DDLogOp op=DDLogOp::AND)
Definition: DDQuery.cc:16
virtual void setScope(const DDScope &)
Definition: DDQuery.cc:27
type of data representation of DDCompactView
Definition: DDCompactView.h:77
std::vector< DDExpandedNode > result_
Definition: DDQuery.h:32
tuple result
Definition: mps_fire.py:95
const DDGeoHistory & geoHistory() const
The list of ancestors up to the root-node of the current node.
virtual ~DDQuery()
Definition: DDQuery.cc:9
std::vector< DDGeoHistory > scope_type
Definition: DDScope.h:31
int depth(void) const
return the depth to wich the subtrees are restricted
Definition: DDScope.cc:106
const DDScope * scope_
Definition: DDQuery.h:28
double f[11][100]
#define end
Definition: vmac.h:37
bool setScope(const DDGeoHistory &hist, int depth=0)
sets the scope of the expanded view
DDQuery(const DDCompactView &)
sets up a query
Definition: DDQuery.cc:4
defines subtrees in the expanded-view
Definition: DDScope.h:26
void reset()
true, if a call to firstChild() would succeed (current node has at least one child) ...
DDExpandedView epv_
Definition: DDQuery.h:27
#define begin
Definition: vmac.h:30
A Filter accepts or rejects a DDExpandedNode based on a user-coded decision rule. ...
Definition: DDFilter.h:18
virtual bool accept(const DDExpandedView &) const =0
true, if the DDExpandedNode fulfills the filter criteria
std::vector< std::pair< bool, DDFilter * > > criteria_
Definition: DDQuery.h:30
const scope_type & scope(void) const
returns the scope container
Definition: DDScope.cc:112
std::vector< DDLogOp > logOps_
Definition: DDQuery.h:31