CMS 3D CMS Logo

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

Generated on Tue Jun 9 17:32:24 2009 for CMSSW by  doxygen 1.5.4