Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "DetectorDescription/Parser/src/DDLSpecPar.h"
0002 #include "DetectorDescription/Core/interface/DDName.h"
0003 #include "DetectorDescription/Core/interface/DDSpecifics.h"
0004 #include "DetectorDescription/Core/interface/DDValue.h"
0005 #include "DetectorDescription/Core/interface/DDValuePair.h"
0006 #include "DetectorDescription/Core/interface/DDsvalues.h"
0007 #include "DetectorDescription/Core/interface/ClhepEvaluator.h"
0008 #include "DetectorDescription/Parser/interface/DDLElementRegistry.h"
0009 #include "DetectorDescription/Parser/src/DDXMLElement.h"
0010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0011 
0012 #include <algorithm>
0013 #include <cstddef>
0014 #include <map>
0015 #include <utility>
0016 #include <vector>
0017 
0018 class DDCompactView;
0019 
0020 DDLSpecPar::DDLSpecPar(DDLElementRegistry* myreg) : DDXMLElement(myreg) {}
0021 
0022 // Process a SpecPar element.  We have to assume that
0023 // certain things have happened.
0024 void DDLSpecPar::processElement(const std::string& name, const std::string& nmspace, DDCompactView& cpv) {
0025   // sends the call to the DDD Core OR does nothing if it is a sub-element
0026 
0027   // What I want to do here is the following:
0028   // 1.  output PartSelector information.
0029   // 2.  pass the Path and parameters to DDSpecifics
0030   // for each of the above, use the name of the SpecPar, since DDL does not
0031   // provide a name for a PartSelector.
0032 
0033   auto myParameter = myRegistry_->getElement("Parameter");
0034   auto myNumeric = myRegistry_->getElement("Numeric");
0035   auto myString = myRegistry_->getElement("String");
0036   auto myPartSelector = myRegistry_->getElement("PartSelector");
0037   auto mySpecParSection = myRegistry_->getElement("SpecParSection");
0038 
0039   // Because of namespace magic "!" means namespaces should be provided
0040   // in the names of the XML elements for the DDD.  So if this is
0041   // the state/case then we need to force the expression evaluator to
0042   // use the namespace of the SpecPar element being processed.
0043   // --  Michael Case 2008-11-06
0044   std::string ns(nmspace);
0045   DDXMLAttribute spatts = getAttributeSet();
0046   std::string rn = spatts.find("name")->second;
0047   if (ns == "!") {
0048     size_t foundColon = rn.find(':');
0049     if (foundColon != std::string::npos) {
0050       ns = rn.substr(0, foundColon);
0051       //       rn = rn.substr(foundColon+1);
0052     }
0053   }
0054 
0055   // DDPartSelector name comes from DDLSpecPar (this class, there is no analogue to
0056   // DDLSpecPar in DDCore)
0057   std::vector<std::string> partsels;
0058   size_t i;
0059 
0060   //    if (getName("name") == "")
0061   //      {
0062   //        std::cout << "ERROR: no name for SpecPar" << std::endl;
0063   //        partsels = myPartSelector->getVectorAttribute("path");
0064   //        snames = myParameter->getVectorAttribute("name");
0065   //        std::cout << "\tParameter Names" << std::endl;
0066   //        size_t i;
0067   //        for (i = 0; i < snames.size(); ++i)
0068   //    {
0069   //      std::cout << "\t\t" << snames[i] << std::endl;
0070   //    }
0071   //        std::cout << "\tPart Selectors:" << std::endl;
0072   //        for (i = 0; i < partsels.size(); ++i)
0073   //    {
0074   //      std::cout << "\t\t" << partsels[i] << std::endl;
0075   //    }
0076   //      }
0077   //    else
0078   //      {
0079 
0080   //should i keep this? partsels = myPartSelector->getVectorAttribute("path");
0081   //otherise I have to do this block...
0082   for (i = 0; i < myPartSelector->size(); ++i)
0083     partsels.emplace_back((myPartSelector->getAttributeSet(i).find("path"))->second);
0084   DDsvalues_type svt;
0085 
0086   // boolean flag to indicate whether the std::vector<DDValuePair> has been evaluated
0087   // using the Evaluator
0088   typedef std::map<std::string, std::pair<bool, std::vector<DDValuePair> > > vvvpType;
0089 
0090   vvvpType vvvp;
0091 
0092   /** 08/13/03 doNotEval for Parameter is based on the value of the eval flag.
0093       For String it is always false and for Numeric it is always true.
0094       But for "legacy" Parameter, remember, we need to check eval.
0095       Default is NOT to evaluate.
0096   **/
0097   bool doNotEval = true;
0098   bool doRegex = true;
0099   {
0100     // check parent level
0101     const DDXMLAttribute& atts = mySpecParSection->getAttributeSet();
0102 
0103     if (atts.find("eval") != atts.end() && atts.find("eval")->second == "true")
0104       doNotEval = false;
0105 
0106     if (atts.find("regex") != atts.end() && atts.find("regex")->second == "false")
0107       doRegex = false;
0108   }
0109   {
0110     // check this level
0111     const DDXMLAttribute& atts = getAttributeSet();
0112 
0113     if (atts.find("eval") != atts.end() && atts.find("eval")->second == "true")
0114       doNotEval = false;
0115     else if (atts.find("eval") != atts.end())
0116       doNotEval = true;
0117 
0118     if (atts.find("regex") != atts.end() && atts.find("regex")->second == "false")
0119       doRegex = false;
0120     else if (atts.find("regex") != atts.end())
0121       doRegex = true;
0122   }
0123   for (i = 0; i < myParameter->size(); ++i) {
0124     const DDXMLAttribute& atts = myParameter->getAttributeSet(i);
0125     std::vector<DDValuePair> vvp;
0126     vvvpType::iterator itv = vvvp.find((atts.find("name")->second));
0127     if (itv != vvvp.end())
0128       vvp = itv->second.second;
0129     double tval = 0.0;
0130     bool isEvaluated = false;
0131 
0132     /** 
0133     1.  Check eval flag of each level (SpecParSection, SpecPar
0134     and Parameter).
0135     2.  Default is the closest specified eval attribute
0136     with any value other than "false".
0137     */
0138 
0139     // bool notThis =  doNotEval  myParameter->get(std::string("eval"), i) != "true";
0140 
0141     if ((atts.find("eval") != atts.end() && atts.find("eval")->second != "false") ||
0142         (atts.find("eval") == atts.end() && !doNotEval)) {
0143       tval = myRegistry_->evaluator().eval(ns, atts.find("value")->second);
0144       isEvaluated = true;
0145     }
0146 
0147     DDValuePair vp(atts.find("value")->second, tval);
0148     vvp.emplace_back(vp);
0149     vvvp[atts.find("name")->second] = make_pair(isEvaluated, vvp);
0150   }
0151 
0152   // Process the String names and values.
0153   for (i = 0; i < myString->size(); ++i) {
0154     const DDXMLAttribute& atts = myString->getAttributeSet(i);
0155     std::vector<DDValuePair> vvp;
0156     vvvpType::iterator itv = vvvp.find(atts.find("name")->second);
0157     if (itv != vvvp.end())
0158       vvp = itv->second.second;
0159 
0160     DDValuePair vp(atts.find("value")->second, 0.0);
0161     vvp.emplace_back(vp);
0162     vvvp[atts.find("name")->second] = make_pair(false, vvp);
0163   }
0164 
0165   // Process the Numeric names and values.
0166   for (i = 0; i < myNumeric->size(); ++i) {
0167     const DDXMLAttribute& atts = myNumeric->getAttributeSet(i);
0168     std::vector<DDValuePair> vvp;
0169     vvvpType::iterator itv = vvvp.find(atts.find("name")->second);
0170     if (itv != vvvp.end())
0171       vvp = itv->second.second;
0172     double tval = myRegistry_->evaluator().eval(ns, atts.find("value")->second);
0173     DDValuePair vp(atts.find("value")->second, tval);
0174     vvp.emplace_back(vp);
0175     vvvp[atts.find("name")->second] = make_pair(true, vvp);
0176   }
0177 
0178   svt.reserve(vvvp.size());
0179   for (vvvpType::const_iterator it = vvvp.begin(); it != vvvp.end(); ++it) {
0180     DDValue val(it->first, it->second.second);
0181     bool isEvaluated = it->second.first;
0182     val.setEvalState(isEvaluated);
0183     svt.emplace_back(DDsvalues_Content_type(val, val));
0184   }
0185   std::sort(svt.begin(), svt.end());
0186 
0187   DDSpecifics ds(getDDName(nmspace), partsels, svt, doRegex);
0188 
0189   myParameter->clear();
0190   myPartSelector->clear();
0191 
0192   // after a SpecPar is done, we can clear
0193   clear();
0194 }