CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/DetectorDescription/Parser/src/DDLSpecPar.cc

Go to the documentation of this file.
00001 /***************************************************************************
00002                           DDLSpecPar.cc  -  description
00003                              -------------------
00004     begin                : Tue Nov 21 2001
00005     email                : case@ucdhep.ucdavis.edu
00006  ***************************************************************************/
00007 
00008 /***************************************************************************
00009  *                                                                         *
00010  *           DDDParser sub-component of DDD                                *
00011  *                                                                         *
00012  ***************************************************************************/
00013 
00014 #include "DetectorDescription/Parser/src/DDLSpecPar.h"
00015 
00016 #include "DetectorDescription/Core/interface/DDName.h"
00017 #include "DetectorDescription/Core/interface/DDSpecifics.h"
00018 #include "DetectorDescription/Base/interface/DDdebug.h"
00019 #include "DetectorDescription/Core/interface/DDValue.h"
00020 #include "DetectorDescription/Core/interface/DDValuePair.h"
00021 
00022 #include "DetectorDescription/ExprAlgo/interface/ExprEvalSingleton.h"
00023 
00024 #include <sstream>
00025 
00026 DDLSpecPar::DDLSpecPar( DDLElementRegistry* myreg )
00027   : DDXMLElement( myreg )
00028 {}
00029 
00030 DDLSpecPar::~DDLSpecPar( void )
00031 {}
00032 
00033 // Process a SpecPar element.  We have to assume that 
00034 // certain things have happened.
00035 void
00036 DDLSpecPar::processElement( const std::string& name, const std::string& nmspace, DDCompactView& cpv )
00037 {
00038   DCOUT_V('P',"DDLSpecPar::processElement started");
00039 
00040   // sends the call to the DDD Core OR does nothing if it is a sub-element
00041 
00042   // What I want to do here is the following:
00043   // 1.  output PartSelector information.
00044   // 2.  pass the Path and parameters to DDSpecifics
00045   // for each of the above, use the name of the SpecPar, since DDL does not
00046   // provide a name for a PartSelector.
00047 
00048   DDXMLElement* myParameter      = myRegistry_->getElement("Parameter");
00049   DDXMLElement* myNumeric        = myRegistry_->getElement("Numeric");
00050   DDXMLElement* myString         = myRegistry_->getElement("String");
00051   DDXMLElement* myPartSelector   = myRegistry_->getElement("PartSelector");
00052   DDXMLElement* mySpecParSection = myRegistry_->getElement("SpecParSection");
00053 
00054   // Because of namespace magic "!" means namespaces should be provided
00055   // in the names of the XML elements for the DDD.  So if this is
00056   // the state/case then we need to force the expression evaluator to 
00057   // use the namespace of the SpecPar element being processed.
00058   // --  Michael Case 2008-11-06
00059   std::string ns(nmspace);
00060   DDXMLAttribute spatts = getAttributeSet();
00061   std::string rn = spatts.find("name")->second;
00062   if ( ns == "!" ) {
00063     size_t foundColon= rn.find(':');
00064     if (foundColon != std::string::npos) {
00065       ns = rn.substr(0,foundColon);
00066       //       rn = rn.substr(foundColon+1);
00067     }
00068   }
00069 
00070   // DDPartSelector name comes from DDLSpecPar (this class, there is no analogue to 
00071   // DDLSpecPar in DDCore)
00072   std::vector <std::string> partsels;
00073   size_t i;
00074 
00075   //    if (getName("name") == "")
00076   //      {
00077   //        std::cout << "ERROR: no name for SpecPar" << std::endl;
00078   //        partsels = myPartSelector->getVectorAttribute("path");
00079   //        snames = myParameter->getVectorAttribute("name");
00080   //        std::cout << "\tParameter Names" << std::endl;
00081   //        size_t i;
00082   //        for (i = 0; i < snames.size(); ++i)
00083   //    {
00084   //      std::cout << "\t\t" << snames[i] << std::endl;
00085   //    }
00086   //        std::cout << "\tPart Selectors:" << std::endl;
00087   //        for (i = 0; i < partsels.size(); ++i)
00088   //    {
00089   //      std::cout << "\t\t" << partsels[i] << std::endl;
00090   //    }
00091   //      }
00092   //    else 
00093   //      {
00094 
00095   //should i keep this? partsels = myPartSelector->getVectorAttribute("path");
00096   //otherise I have to do this block...
00097   for (i = 0; i < myPartSelector->size(); ++i)
00098     partsels.push_back((myPartSelector->getAttributeSet(i).find("path"))->second);
00099   DDsvalues_type svt;
00100 
00101   // boolean flag to indicate whether the std::vector<DDValuePair> has been evaluated 
00102   // using the Evaluator
00103   typedef std::map<std::string, std::pair<bool,std::vector<DDValuePair> > > vvvpType;
00104 
00105   vvvpType vvvp;
00106 
00112   bool doNotEval = true;
00113   bool doRegex = true;
00114   {
00115     // check parent level  
00116     const DDXMLAttribute & atts = mySpecParSection->getAttributeSet();
00117     
00118     if (atts.find("eval") != atts.end() && atts.find("eval")->second == "true")
00119       doNotEval = false;
00120     
00121     if (atts.find("regex") != atts.end() && atts.find("regex")->second == "false")
00122       doRegex = false;
00123   }
00124   {
00125     // check this level
00126     const DDXMLAttribute & atts = getAttributeSet();
00127     
00128     if (atts.find("eval") != atts.end() && atts.find("eval")->second == "true")
00129       doNotEval = false;
00130     else if (atts.find("eval") != atts.end())
00131       doNotEval = true;
00132     
00133     if (atts.find("regex") != atts.end() && atts.find("regex")->second == "false")
00134       doRegex = false;
00135     else if (atts.find("regex") != atts.end())
00136       doRegex = true;
00137   }
00138   for (i = 0; i < myParameter->size(); ++i)
00139   {
00140     const DDXMLAttribute & atts = myParameter->getAttributeSet(i);
00141     std::vector <DDValuePair> vvp;
00142     vvvpType::iterator itv = vvvp.find((atts.find("name")->second));
00143     if (itv != vvvp.end())
00144       vvp = itv->second.second;
00145     double tval = 0.0;
00146     bool isEvaluated = false;
00147 
00155     // bool notThis =  doNotEval  myParameter->get(std::string("eval"), i) != "true";
00156 
00157     // since eval is an optional attribute, we need to check if it exists for
00158     // the debug statement.  Unfortunately, I see no way to do this internal
00159     // to the DCOUT_V statement... ts is a "wasted" variable.
00160     std::string ts = "** no eval attribute **";
00161     if (atts.find("eval") != atts.end()) 
00162       ts = atts.find("eval")->second;
00163     DCOUT_V('P', std::string("about to process ") << atts.find("value")->second << std::string(" eval = ") << ts);
00164     if ((atts.find("eval") != atts.end() && atts.find("eval")->second !="false")
00165         || (atts.find("eval") == atts.end() && !doNotEval))
00166     { 
00167       tval = ExprEvalSingleton::instance().eval(ns, atts.find("value")->second);
00168       isEvaluated=true;
00169       DCOUT_V('P', std::string("EVALUATED"));
00170     }
00171     else
00172     {
00173       DCOUT_V('P', std::string("NOT Evaluated"));
00174     }
00175       
00176     DDValuePair vp(atts.find("value")->second, tval);
00177     vvp.push_back(vp);
00178     vvvp[atts.find("name")->second] = make_pair(isEvaluated,vvp);
00179   }
00180 
00181   // Process the String names and values.
00182   for (i = 0; i < myString->size(); ++i)
00183   {
00184     const DDXMLAttribute & atts = myString->getAttributeSet(i);
00185     std::vector <DDValuePair> vvp;
00186     vvvpType::iterator itv = vvvp.find(atts.find("name")->second);
00187     if (itv != vvvp.end())
00188       vvp = itv->second.second;
00189     DCOUT_V('P', std::string("about to process String ") << (atts.find("name")->second) << " = " << (atts.find("value")->second));
00190     DDValuePair vp(atts.find("value")->second, 0.0);
00191     vvp.push_back(vp);
00192     vvvp[atts.find("name")->second] = make_pair(false,vvp);
00193   }
00194   
00195   // Process the Numeric names and values.
00196   for (i = 0; i < myNumeric->size(); ++i)
00197   {
00198     const DDXMLAttribute & atts = myNumeric->getAttributeSet(i);
00199     std::vector <DDValuePair> vvp;
00200     vvvpType::iterator itv = vvvp.find(atts.find("name")->second);
00201     if (itv != vvvp.end())
00202       vvp = itv->second.second;
00203     DCOUT_V('P', std::string("about to process String ") << (atts.find("name")->second) << " = " << (atts.find("value")->second));
00204     double tval = ExprEvalSingleton::instance().eval(ns, atts.find("value")->second);
00205     DCOUT_V('P', std::string("EVALUATED"));
00206     DDValuePair vp(atts.find("value")->second, tval);
00207     vvp.push_back(vp);
00208     vvvp[atts.find("name")->second] = make_pair(true,vvp);
00209   }
00210   
00211   svt.reserve(vvvp.size());
00212   for (vvvpType::const_iterator it = vvvp.begin(); it != vvvp.end(); ++it)
00213   {
00214     DDValue val(it->first, it->second.second);
00215     bool isEvaluated = it->second.first;
00216     val.setEvalState(isEvaluated);
00217     svt.push_back(DDsvalues_Content_type(val,val));      
00218   }
00219   std::sort(svt.begin(),svt.end());
00220 
00221 
00222   DCOUT_V('p', "DDLSpecPar::processElement\n\tname " << getDDName(nmspace) << "\n\tpartsels.size() = " << myPartSelector->size() << "\n\tsvt " << svt);
00223 
00224   DDSpecifics ds(getDDName(nmspace), 
00225                  partsels,
00226                  svt,
00227                  doRegex);
00228 
00229   myParameter->clear();
00230   myPartSelector->clear();
00231   
00232   // after a SpecPar is done, we can clear
00233   clear();
00234   
00235   DCOUT_V('P',"DDLSpecPar::processElement(...)");
00236 }
00237