CMS 3D CMS Logo

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>

List of all members.

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
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.

{ AND, OR };

Constructor & Destructor Documentation

DDQuery::DDQuery ( const DDCompactView cpv)

sets up a query

Definition at line 6 of file DDQuery.cc.

 :   epv_(cpv), scope_(0)
{ }
DDQuery::~DDQuery ( ) [virtual]

Definition at line 11 of file DDQuery.cc.

{ }

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_.

{
  // cheating a bit with const ....
  // Filters have a non-const ::accept(..) member function to allow
  // a possible internal state change in a particular filter implementation ...
  DDFilter * nonConstFilter = const_cast<DDFilter *>(&f);
  criteria_.push_back(std::make_pair(false,nonConstFilter)); 
  logOps_.push_back(op);
  //DCOUT('F',"DDQuery::addFilter(): log-op=" << op );
}
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().

{
   result_.clear();
   epv_.reset();

   //bool filtered = bool(filters_.size());
   //bool unfiltered = !filtered;
   
   // currently at least one filter must be set, because
   // the query simply consists in applying at least one filter!
   if(criteria_.size()) { // <- remove the 'if' when implementing 'the QUERY'
     int depth = 0;
     bool scoped = false;
     DDScope::scope_type dummy;
     DDScope::scope_type::const_iterator it = dummy.begin();
     DDScope::scope_type::const_iterator it_end = dummy.end();
     if (scope_) {
       const DDScope & sc = *scope_;
       it = sc.scope().begin();
       depth = sc.depth();
       scoped = bool(sc.scope().end()-it);  
     }
     
     bool runonce = scoped ? false : true;
            
     while (runonce || (it != it_end) ) {
        if (scoped) epv_.setScope(*it,depth); // set the subtree-scope & depth within
        bool run = true;
        while(run) {
          //DCOUT('F', "DDQuery: examining " << epv_.geoHistory().back() );
          
          std::vector<const DDsvalues_type *> specs = epv_.specifics();
//        std::vector<const DDsvalues_type *>::const_iterator sit = specs.begin();
          //FIXME: find a solution when more then one specifics_type is attached to
          //FIXME: particlular nodes ... (merging the specifics-map, etc ...)
          //FIXME: for (; sit != specs.end() ; ++sit) {
//          DDsvalues_type dummy;
//          const DDsvalues_type * specifics;
//          if (sit==specs.end())
//            specifics = &dummy;
//          else
//            specifics = *sit;
              
            criteria_type::iterator it = criteria_.begin();
            logops_type::iterator logOpIt = logOps_.begin();
            // loop over all user-supplied criteria (==filters)
            bool result=true;
            for (; it != criteria_.end(); ++it, ++logOpIt) {
              DDFilter * filter = it->second;
              if (filter->accept(epv_)) {
                                      //.geoHistory().back(), // expanded node
                                      //epv_.geoHistory(),
                                      //specifics)) { // geom.history
               
                it->first=true;
                //DCOUT('F', " Filter(" << criteria_.end()-it << ") accepted: " << epv_.geoHistory().back());
              }
              else {
                it->first=false;
              }
                
              // now do the logical-operations on the results encountered so far:
              if (*logOpIt==AND) { // AND
                result &= it->first; 
              }
              else { // OR
                result |= it->first;  
              }
            } // <-- loop over filters 
            //DCOUT('f', "-------------------");
          if (result) {
            // HERE THE ACTUAL QUERY SHOULD BE INVOKED!!!
            result_.push_back(epv_.geoHistory().back());  
          }  
          //} <-- loop over std::vector of specifics_type ...
          run = epv_.next();
        }
        if (scoped)
          ++it;
        else
          runonce=false;        
     } 
   }  
   return result_;
}
void DDQuery::setScope ( const DDScope s) [virtual]

Definition at line 30 of file DDQuery.cc.

References alignCSCRings::s, and scope_.

{
  scope_ = &s;
}

Member Data Documentation

Definition at line 40 of file DDQuery.h.

Referenced by addFilter(), and exec().

Definition at line 34 of file DDQuery.h.

Referenced by exec().

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().