CMS 3D CMS Logo

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