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.
1 
4 //#include "DetectorDescription/Base/interface/DDdebug.h"
5 
7  : epv_(cpv), scope_(0)
8 { }
9 
10 
12 { }
13 
14 
19 {
20  // cheating a bit with const ....
21  // Filters have a non-const ::accept(..) member function to allow
22  // a possible internal state change in a particular filter implementation ...
23  DDFilter * nonConstFilter = const_cast<DDFilter *>(&f);
24  criteria_.push_back(std::make_pair(false,nonConstFilter));
25  logOps_.push_back(op);
26  //DCOUT('F',"DDQuery::addFilter(): log-op=" << op );
27 }
28 
29 
30 void DDQuery::setScope(const DDScope & s)
31 {
32  scope_ = &s;
33 }
34 
35 
36 const std::vector<DDExpandedNode> & DDQuery::exec()
37 {
38  result_.clear();
39  epv_.reset();
40 
41  //bool filtered = bool(filters_.size());
42  //bool unfiltered = !filtered;
43 
44  // currently at least one filter must be set, because
45  // the query simply consists in applying at least one filter!
46  if(criteria_.size()) { // <- remove the 'if' when implementing 'the QUERY'
47  int depth = 0;
48  bool scoped = false;
49  DDScope::scope_type dummy;
50  DDScope::scope_type::const_iterator it = dummy.begin();
51  DDScope::scope_type::const_iterator it_end = dummy.end();
52  if (scope_) {
53  const DDScope & sc = *scope_;
54  it = sc.scope().begin();
55  depth = sc.depth();
56  scoped = bool(sc.scope().end()-it);
57  }
58 
59  bool runonce = scoped ? false : true;
60 
61  while (runonce || (it != it_end) ) {
62  if (scoped) epv_.setScope(*it,depth); // set the subtree-scope & depth within
63  bool run = true;
64  while(run) {
65  //DCOUT('F', "DDQuery: examining " << epv_.geoHistory().back() );
66 
67  std::vector<const DDsvalues_type *> specs = epv_.specifics();
68 // std::vector<const DDsvalues_type *>::const_iterator sit = specs.begin();
69  //FIXME: find a solution when more then one specifics_type is attached to
70  //FIXME: particlular nodes ... (merging the specifics-map, etc ...)
71  //FIXME: for (; sit != specs.end() ; ++sit) {
72 // DDsvalues_type dummy;
73 // const DDsvalues_type * specifics;
74 // if (sit==specs.end())
75 // specifics = &dummy;
76 // else
77 // specifics = *sit;
78 
79  criteria_type::iterator it = criteria_.begin();
80  logops_type::iterator logOpIt = logOps_.begin();
81  // loop over all user-supplied criteria (==filters)
82  bool result=true;
83  for (; it != criteria_.end(); ++it, ++logOpIt) {
84  DDFilter * filter = it->second;
85  if (filter->accept(epv_)) {
86  //.geoHistory().back(), // expanded node
87  //epv_.geoHistory(),
88  //specifics)) { // geom.history
89 
90  it->first=true;
91  //DCOUT('F', " Filter(" << criteria_.end()-it << ") accepted: " << epv_.geoHistory().back());
92  }
93  else {
94  it->first=false;
95  }
96 
97  // now do the logical-operations on the results encountered so far:
98  if (*logOpIt==AND) { // AND
99  result &= it->first;
100  }
101  else { // OR
102  result |= it->first;
103  }
104  } // <-- loop over filters
105  //DCOUT('f', "-------------------");
106  if (result) {
107  // HERE THE ACTUAL QUERY SHOULD BE INVOKED!!!
108  result_.push_back(epv_.geoHistory().back());
109  }
110  //} <-- loop over std::vector of specifics_type ...
111  run = epv_.next();
112  }
113  if (scoped)
114  ++it;
115  else
116  runonce=false;
117  }
118  }
119  return result_;
120 }
bool next()
set current node to the next node in the expanded tree
virtual void addFilter(const DDFilter &, log_op op=AND)
Definition: DDQuery.cc:18
criteria_type criteria_
Definition: DDQuery.h:40
virtual const std::vector< DDExpandedNode > & exec()
Definition: DDQuery.cc:36
std::vector< const DDsvalues_type * > specifics() const
User specific data attached to the current node.
virtual void setScope(const DDScope &)
Definition: DDQuery.cc:30
type of data representation of DDCompactView
Definition: DDCompactView.h:77
std::vector< DDExpandedNode > result_
Definition: DDQuery.h:43
const DDGeoHistory & geoHistory() const
The list of ancestors up to the root-node of the current node.
virtual ~DDQuery()
Definition: DDQuery.cc:11
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:35
tuple result
Definition: query.py:137
double f[11][100]
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:6
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:34
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
logops_type logOps_
Definition: DDQuery.h:41
const scope_type & scope(void) const
returns the scope container
Definition: DDScope.cc:112
log_op
Definition: DDQuery.h:18