CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Types | Public Member Functions | Protected Types | Protected Attributes
DDQuery Class Reference

Base class for querying for nodes in the DDExpandedView. More...

#include <DDQuery.h>

Public Types

enum  log_op { AND, OR }
 

Public Member Functions

virtual void addFilter (const DDFilter &, log_op op=AND)
 
 DDQuery (const DDCompactView &)
 sets up a query More...
 
virtual const std::vector
< DDExpandedNode > & 
exec ()
 
virtual void setScope (const DDScope &)
 
virtual ~DDQuery ()
 

Protected Types

typedef std::vector
< criterion_type
criteria_type
 
typedef std::pair< bool,
DDFilter * > 
criterion_type
 
typedef std::vector< log_oplogops_type
 

Protected Attributes

criteria_type criteria_
 
DDExpandedView epv_
 
logops_type logOps_
 
std::vector< DDExpandedNoderesult_
 
const DDScopescope_
 

Detailed Description

Base class for querying for nodes in the DDExpandedView.

Definition at line 15 of file DDQuery.h.

Member Typedef Documentation

typedef std::vector<criterion_type> DDQuery::criteria_type
protected

Definition at line 37 of file DDQuery.h.

typedef std::pair<bool, DDFilter *> DDQuery::criterion_type
protected

Definition at line 36 of file DDQuery.h.

typedef std::vector<log_op> DDQuery::logops_type
protected

Definition at line 38 of file DDQuery.h.

Member Enumeration Documentation

Enumerator
AND 
OR 

Definition at line 18 of file DDQuery.h.

18 { AND, OR };

Constructor & Destructor Documentation

DDQuery::DDQuery ( const DDCompactView cpv)

sets up a query

Definition at line 6 of file DDQuery.cc.

7  : epv_(cpv), scope_(0)
8 { }
const DDScope * scope_
Definition: DDQuery.h:35
DDExpandedView epv_
Definition: DDQuery.h:34
DDQuery::~DDQuery ( )
virtual

Definition at line 11 of file DDQuery.cc.

12 { }

Member Function Documentation

void DDQuery::addFilter ( const DDFilter f,
log_op  op = AND 
)
virtual

the standard DDQuery only support one single filter. Memory management of DDFilter* is NOT delegated to DDQuery

Definition at line 18 of file DDQuery.cc.

References criteria_, f, and logOps_.

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 }
criteria_type criteria_
Definition: DDQuery.h:40
double f[11][100]
A Filter accepts or rejects a DDExpandedNode based on a user-coded decision rule. ...
Definition: DDFilter.h:18
logops_type logOps_
Definition: DDQuery.h:41
const std::vector< DDExpandedNode > & DDQuery::exec ( )
virtual

Definition at line 36 of file DDQuery.cc.

References DDFilter::accept(), AND, criteria_, DDScope::depth(), epv_, alcazmumu_cfi::filter, DDExpandedView::geoHistory(), logOps_, DDExpandedView::next(), DDExpandedView::reset(), query::result, result_, DTTTrigCorrFirst::run, DDScope::scope(), scope_, DDExpandedView::setScope(), and DDExpandedView::specifics().

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
criteria_type criteria_
Definition: DDQuery.h:40
std::vector< const DDsvalues_type * > specifics() const
User specific data attached to the current node.
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.
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
bool setScope(const DDGeoHistory &hist, int depth=0)
sets the scope of the expanded view
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
void DDQuery::setScope ( const DDScope s)
virtual

Definition at line 30 of file DDQuery.cc.

References alignCSCRings::s, and scope_.

31 {
32  scope_ = &s;
33 }
const DDScope * scope_
Definition: DDQuery.h:35

Member Data Documentation

criteria_type DDQuery::criteria_
protected

Definition at line 40 of file DDQuery.h.

Referenced by addFilter(), and exec().

DDExpandedView DDQuery::epv_
protected

Definition at line 34 of file DDQuery.h.

Referenced by exec().

logops_type DDQuery::logOps_
protected

Definition at line 41 of file DDQuery.h.

Referenced by addFilter(), and exec().

std::vector<DDExpandedNode> DDQuery::result_
protected

Definition at line 43 of file DDQuery.h.

Referenced by exec().

const DDScope* DDQuery::scope_
protected

Definition at line 35 of file DDQuery.h.

Referenced by exec(), and setScope().