CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DDFilter.cc
Go to the documentation of this file.
3 
4 // Message logger.
6 
8 { }
9 
10 
12 { }
13 
14 
15 // =======================================================================
16 // =======================================================================
17 
29 namespace {
30 
31 
32 // SpecificsFilterString-comparison (sfs)
33  inline bool sfs_compare(const DDSpecificsFilter::SpecificCriterion & crit,
34  const DDsvalues_type & sv) {
35  DDsvalues_type::const_iterator it = find(sv,crit.nameVal_.id());
36  if (it == sv.end()) return false;
37  switch (crit.comp_) {
39  return ( crit.nameVal_.strings() == it->second.strings() );
41  return ( crit.nameVal_.strings() != it->second.strings() );
43  return ( it->second.strings() <= crit.nameVal_.strings() );
45  return ( it->second.strings() < crit.nameVal_.strings() );
47  return ( it->second.strings() >= crit.nameVal_.strings() );
49  return ( it->second.strings() > crit.nameVal_.strings() );
50  default:
51  return false;
52  }
53  return false;
54  }
55 
56  inline bool sfd_compare(const DDSpecificsFilter::SpecificCriterion & crit,
57  const DDsvalues_type & sv)
58  {
59  DDsvalues_type::const_iterator it = find(sv,crit.nameVal_.id());
60  if (it == sv.end()) return false;
61  if (it->second.isEvaluated() ) {
62  switch (crit.comp_) {
64  return (crit.nameVal_.doubles() == it->second.doubles() );
66  return (crit.nameVal_.doubles() != it->second.doubles() );
68  return ( it->second.doubles() <= crit.nameVal_.doubles() );
70  return ( it->second.doubles() < crit.nameVal_.doubles() );
72  return ( it->second.doubles() >= crit.nameVal_.doubles() );
74  return ( it->second.doubles() > crit.nameVal_.doubles() );
75  default:
76  return false;
77  }
78  } else {
79  edm::LogWarning("DD:Filter") << "Attempt to access a DDValue as doubles but DDValue is NOT Evaluated!"
80  << crit.nameVal_.name();
81  }
82  return false;
83  }
84 
85  inline bool sfs_compare_nm (const DDSpecificsFilter::SpecificCriterion & crit,
86  const std::vector<const DDsvalues_type *> & specs)
87  {
88  // The meaning of this is defined for each operator below.
89  bool result = false;
90 
91  std::vector<const DDsvalues_type *>::const_iterator spit = specs.begin();
92 
93  // go through all specifics
94  // edm::LogInfo("DDFilter") << "Checking all specifics." << std::endl;
95  for (; spit != specs.end(); ++spit) {
96  DDsvalues_type::const_iterator it = (**spit).begin();
97 
98  // go through all DDValues of the current specific.
99  for (; it != (**spit).end(); ++it) {
100 
101  size_t ci = 0; // criteria values index
102  size_t si = 0; // specs values index
103  // compare all the crit values to all the specs values when the name matches.
104 
105  while ( !result && ci < crit.nameVal_.strings().size()) {
106  if (it->second.id() == crit.nameVal_.id()) {
107  // edm::LogInfo("DDFilter") << " Actually checking " << it->second.name() << std::endl;
108  while ( !result && si < it->second.strings().size()) {
109  // edm::LogInfo("DDFilter") << "**** is " << crit.nameVal_.strings()[ci] << " = " << it->second.strings()[si] << " ?" << std::endl;
110 
111  switch (crit.comp_) {
112  // equals means at least one value in crit matches one value
113  // in specs.
114  //
115  // not equals means that no values in crit match no values in specs
116  // (see below the ! (not))
117  //
118  // Maybe we should have an 'in' or 'contains' operator and equals would meaning
119  // would be changed to mean ALL equal.
124  result = ( crit.nameVal_.strings()[ci] == it->second.strings()[si] );
125  break;
126 
127  // less than or equals means that ALL values in specs
128  // are less than or equals ALL values in crit. therefore
129  // if even ONE is bigger, then this is false.
131  result = ( it->second.strings()[si] > crit.nameVal_.strings()[ci] );
132  break;
133 
134  // less than means that all are strictly less than, therefore
135  // if one is greater than or equal, then this is false
137  result = ( it->second.strings()[si] >= crit.nameVal_.strings()[ci] );
138  break;
139 
140  // greater or equal to means that all values in specs are
141  // greater than or equals to all values in crit. therefore
142  // if even ONE is less than, then this is false
144  result = ( it->second.strings()[si] < crit.nameVal_.strings()[ci] );
145  break;
146 
147  // greater means that all values in specs are greater than
148  // all values in crit. therefore if even one is less than or
149  // equal to crit, then this is false;
151  result = ( it->second.strings() <= crit.nameVal_.strings() );
152  }
153  //edm::LogInfo("DDFilter") << " si = " << si << " result = " << result ;
154  si ++;
155  }
156  //edm::LogInfo("DDFilter") << " ci = " << ci << std::endl;
157 
162  || crit.comp_ == DDSpecificsFilter::bigger)
163  result = !result;
164 
165  //edm::LogInfo("DDFilter") << " it = " << it->second.name() << " final result = " << result << std::endl;
166  }
167  ++ci;
168  }
169  }
170  }
171 
172  return result;
173  }
174 
175  inline bool sfd_compare_nm(const DDSpecificsFilter::SpecificCriterion & crit,
176  const std::vector<const DDsvalues_type *> & specs)
177  {
178  // The meaning of this is defined for each operator below.
179  bool result = false;
180 
181  // edm::LogInfo("DDFilter") << "specs.size()=" << specs.size() << std::endl;
182  // edm::LogInfo("DDFilter") << "crit.nameVal_.doubles().size()=" << crit.nameVal_.doubles().size() << std::endl;
183  std::vector<const DDsvalues_type *>::const_iterator spit = specs.begin();
184 
185  // go through all specifics
186  for (; spit != specs.end(); ++spit) {
187 
188  DDsvalues_type::const_iterator it = (**spit).begin();
189 
190  // go through all DDValues of the current specific.
191  for (; it != (**spit).end(); ++it) {
192  if ( !it->second.isEvaluated() ) {
193  edm::LogWarning("DD:Filter") << "(nm) Attempt to access a DDValue as doubles but DDValue is NOT Evaluated!"
194  << crit.nameVal_.name();
195  continue; // go on to next one, do not attempt to acess doubles()
196  }
197  size_t ci = 0; // criteria values index
198  size_t si = 0; // specs values index
199  // compare all the crit values to all the specs values when the name matches.
200 
201  while ( !result && ci < crit.nameVal_.doubles().size()) {
202 
203  if (it->second.id() == crit.nameVal_.id()) {
204  // edm::LogInfo("DDFilter") << " Actually checking " << it->second.name() << std::endl;
205  while ( !result && si < it->second.doubles().size()) {
206  // edm::LogInfo("DDFilter") << "**** is " << crit.nameVal_.doubles()[ci] << " = " << it->second.doubles()[ci] << " ?" << std::endl;
207  switch (crit.comp_) {
208 
209  // equals means at least one value in crit matches one value
210  // in specs.
211  //
212  // not equals means that no values in crit match no values in specs
213  // (see below the ! (not))
218  result = ( crit.nameVal_.doubles()[ci] == it->second.doubles()[si] );
219  break;
220 
221  // less than or equals means that ALL values in specs
222  // are less than or equals ALL values in crit. therefore
223  // if even ONE is bigger, then this is false.
225  result = ( it->second.doubles()[si] > crit.nameVal_.doubles()[ci] );
226  break;
227 
228  // less than means that all are strictly less than, therefore
229  // if one is greater than or equal, then this is false
231  result = ( it->second.doubles()[si] >= crit.nameVal_.doubles()[ci] );
232  break;
233 
234  // greater or equal to means that all values in specs are
235  // greater than or equals to all values in crit. therefore
236  // if even ONE is less than, then this is false
238  result = ( it->second.doubles()[si] < crit.nameVal_.doubles()[ci] );
239  break;
240 
241  // greater means that all values in specs are greater than
242  // all values in crit. therefore if even one is less than or
243  // equal to crit, then this is false;
245  result = ( it->second.doubles() <= crit.nameVal_.doubles() );
246  }
247  // edm::LogInfo("DDFilter") << " si = " << si << " result = " << result ;
248  si ++;
249 
250  }
251  // edm::LogInfo("DDFilter") << " ci = " << ci << std::endl;
252 
257  || crit.comp_ == DDSpecificsFilter::bigger)
258  result = !result;
259 
260  // edm::LogInfo("DDFilter") << " it = " << it->second.name() << " final result = " << result << std::endl;
261 
262  }
263 
264  ++ci;
265  }
266  }
267  }
268 
269  return result;
270  }
271 
272 
273 
274 }
275 
276 // ================================================================================================
277 
279  : DDFilter()
280 { }
281 
283 
284 
285 void DDSpecificsFilter::setCriteria(const DDValue & nameVal, // name & value of a variable
286  comp_op op,
287  log_op l,
288  bool asStrin, // compare std::strings otherwise doubles
289  bool merged // use merged-specifics or simple-specifics
290  )
291 {
292  criteria_.push_back(SpecificCriterion(nameVal,op,asStrin,merged));
293  logOps_.push_back(l);
294  }
295 
297 {
298  return accept_impl(node);
299 }
300 
301 
303 {
304  bool result = true;
305  criteria_type::const_iterator it = criteria_.begin();
306  criteria_type::const_iterator crEnd = criteria_.end();
307  logops_type::const_iterator logOpIt = logOps_.begin();
308  //logops_type::iterator logOpEnd = logOps_.end();
309  const DDLogicalPart & logp = node.logicalPart();
310  DDsvalues_type sv;
311  std::vector<const DDsvalues_type *> specs;
312  for (; it != crEnd; ++it, ++logOpIt) {
313  // avoid useless evaluations
314  if ( ( result &&(*logOpIt)==OR ) ||
315  ( (!result)&&(*logOpIt)==AND) ) continue;
316 
317  bool locres=false;
318  if (logp.hasDDValue(it->nameVal_)) {
319 
320  if (it->merged_) {
321 
322  if (sv.empty()) node.mergedSpecificsV(sv);
323 
324  if (it->asString_) { // merged specifics & compare std::strings
325  locres = sfs_compare(*it,sv);
326  }
327  else { // merged specifics & compare doubles
328  locres = sfd_compare(*it,sv);
329  }
330  }
331  else {
332 
333  if (specs.empty()) node.specificsV(specs);
334 
335  if (it->asString_) { // non-merged specifics & compare std::strings
336  locres = sfs_compare_nm(*it, specs);
337  }
338  else { // non-merged specifics & compare doubles
339  locres = sfd_compare_nm(*it, specs);
340  }
341  }
342  }
343  if (*logOpIt==AND) {
344  result &= locres;
345  }
346  else {
347  result |= locres;
348  }
349  }
350  return result;
351 }
const std::string & name(void) const
the name of the DDValue
Definition: DDValue.h:64
virtual ~DDFilter()
Definition: DDFilter.cc:11
bool hasDDValue(const DDValue &) const
const std::vector< double > & doubles() const
a reference to the double-valued values stored in the given instance of DDValue
Definition: DDValue.cc:134
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
log_op
logical operations to obtain one result from two filter comparisons
Definition: DDFilter.h:48
unsigned int id(void) const
returns the ID of the DDValue
Definition: DDValue.h:58
bool accept_impl(const DDExpandedView &) const
Definition: DDFilter.cc:302
tuple node
Definition: Node.py:50
U second(std::pair< T, U > const &p)
criteria_type criteria_
Definition: DDFilter.h:89
void specificsV(std::vector< const DDsvalues_type * > &vc) const
tuple result
Definition: query.py:137
std::vector< std::pair< unsigned int, DDValue > > DDsvalues_type
std::maps an index to a DDValue. The index corresponds to the index assigned to the name of the std::...
Definition: DDsvalues.h:19
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:88
const std::vector< std::string > & strings() const
a reference to the std::string-valued values stored in the given instance of DDValue ...
Definition: DDValue.h:71
DDFilter()
Definition: DDFilter.cc:7
A Filter accepts or rejects a DDExpandedNode based on a user-coded decision rule. ...
Definition: DDFilter.h:18
void setCriteria(const DDValue &nameVal, comp_op, log_op l=AND, bool asString=true, bool merged=true)
Definition: DDFilter.cc:285
bool accept(const DDExpandedView &) const
true, if the DDExpandedNode fulfills the filter criteria
Definition: DDFilter.cc:296
logops_type logOps_
Definition: DDFilter.h:90
const DDLogicalPart & logicalPart() const
The logical-part of the current node in the expanded-view.
Provides an exploded view of the detector (tree-view)
void mergedSpecificsV(DDsvalues_type &res) const