Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:05:25

0001 #include "DetectorDescription/Core/interface/DDFilter.h"
0002 
0003 #include <cstddef>
0004 #include <iterator>
0005 #include <string>
0006 #include <utility>
0007 
0008 #include "DetectorDescription/Core/interface/DDExpandedView.h"
0009 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
0010 #include "DetectorDescription/Core/interface/DDsvalues.h"
0011 #include "DetectorDescription/Core/interface/DDComparator.h"
0012 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0013 
0014 DDFilter::DDFilter() {}
0015 
0016 DDFilter::~DDFilter() {}
0017 
0018 // =======================================================================
0019 // =======================================================================
0020 
0021 /** Mike Case 2007x12x18
0022  * Important note:  The removal of throwing and catchine a DDException is
0023  * based more on "what is" rather than the ideal.  We have managed to force
0024  * users to put all SpecPar types and filters at the end of the set of XML
0025  * files.  Therefore a DDValue of the XML syntax "[myvar]-2*[myothervar]"
0026  * will have a correctly evaluated number and valid doubles by the time this
0027  * code is ever run.  What will happen now, is possibly a crash if someone mis-
0028  * identifies their variables to the DD.  I use edm::LogWarning to attempt to catch
0029  * one type of such problems.
0030  **/
0031 
0032 // ================================================================================================
0033 DDSpecificsFilter::DDSpecificsFilter() : DDFilter() {}
0034 
0035 DDSpecificsFilter::~DDSpecificsFilter() {}
0036 
0037 void DDSpecificsFilter::setCriteria(const DDValue& nameVal,  // name & value of a variable
0038                                     DDCompOp op) {
0039   criteria_.emplace_back(SpecificCriterion(nameVal, op));
0040 }
0041 
0042 bool DDSpecificsFilter::accept(const DDExpandedView& node) const { return accept_impl(node); }
0043 
0044 bool DDSpecificsFilter::accept_impl(const DDExpandedView& node) const {
0045   bool result = true;
0046   const DDLogicalPart& logp = node.logicalPart();
0047 
0048   for (auto it = begin(criteria_); it != end(criteria_); ++it) {
0049     bool locres = false;
0050     if (logp.hasDDValue(it->nameVal_)) {
0051       const auto& specs = logp.attachedSpecifics();
0052 
0053       const auto& hist = node.geoHistory();
0054       bool decided = false;
0055       for (auto const& spec : specs) {
0056         if (DDCompareEqual(hist, *spec.first)()) {
0057           for (auto const& v : *(spec.second)) {
0058             if (it->nameVal_.id() == v.first) {
0059               switch (it->comp_) {
0060                 case DDCompOp::equals: {
0061                   locres = (it->nameVal_.strings() == v.second.strings());
0062                   break;
0063                 }
0064                 case DDCompOp::not_equals: {
0065                   locres = (it->nameVal_.strings() != v.second.strings());
0066                   break;
0067                 }
0068                 default:
0069                   return false;
0070               }
0071               decided = true;
0072               break;
0073             }
0074           }
0075           if (decided) {
0076             break;
0077           }
0078         }
0079       }
0080     }
0081     result &= locres;
0082     // avoid useless evaluations
0083     if (!result) {
0084       break;
0085     }
0086   }
0087   return result;
0088 }
0089 
0090 bool DDSpecificsHasNamedValueFilter::accept(const DDExpandedView& node) const {
0091   const DDLogicalPart& logp = node.logicalPart();
0092 
0093   if (logp.hasDDValue(attribute_)) {
0094     const auto& specs = logp.attachedSpecifics();
0095 
0096     const auto& hist = node.geoHistory();
0097     for (auto const& spec : specs) {
0098       for (auto const& v : *(spec.second)) {
0099         if (attribute_.id() == v.first) {
0100           //DDCompareEqual is slow so only call
0101           // when needed
0102           if (DDCompareEqual(hist, *spec.first)()) {
0103             return true;
0104           } else {
0105             //since we know this isn't in the correct
0106             // geometry path we do not have to check
0107             // anymore attributes
0108             break;
0109           }
0110         }
0111       }
0112     }
0113   }
0114   return false;
0115 }
0116 
0117 bool DDSpecificsMatchesValueFilter::accept(const DDExpandedView& node) const {
0118   const DDLogicalPart& logp = node.logicalPart();
0119 
0120   if (logp.hasDDValue(value_)) {
0121     const auto& specs = logp.attachedSpecifics();
0122 
0123     const auto& hist = node.geoHistory();
0124     for (auto const& spec : specs) {
0125       for (auto const& v : *(spec.second)) {
0126         if (value_.id() == v.first) {
0127           if (DDCompareEqual(hist, *spec.first)()) {
0128             return (value_.strings() == v.second.strings());
0129           } else {
0130             //since we know this isn't in the correct
0131             // geometry path we do not have to check
0132             // anymore attributes
0133             break;
0134           }
0135         }
0136       }
0137     }
0138   }
0139   return false;
0140 }