CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/DetectorDescription/Parser/src/DDLAlgoPosPart.cc

Go to the documentation of this file.
00001 /***************************************************************************
00002                           DDLAlgoPosPart.cc  -  description
00003                              -------------------
00004     begin                : Wed Apr 17 2002
00005     email                : case@ucdhep.ucdavis.edu
00006  ***************************************************************************/
00007 
00008 /***************************************************************************
00009  *                                                                         *
00010  *           DDDParser sub-component of DDD                                *
00011  *                                                                         *
00012  ***************************************************************************/
00013 
00014 #include "DetectorDescription/Parser/src/DDLAlgoPosPart.h"
00015 
00016 #include "DetectorDescription/Core/interface/DDName.h"
00017 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
00018 #include "DetectorDescription/Core/interface/DDAlgo.h"
00019 #include "DetectorDescription/Base/interface/DDAlgoPar.h"
00020 #include "DetectorDescription/Base/interface/DDdebug.h"
00021 
00022 #include "DetectorDescription/ExprAlgo/interface/ExprEvalSingleton.h"
00023 
00024 #include <iostream>
00025 
00026 DDLAlgoPosPart::DDLAlgoPosPart( DDLElementRegistry* myreg )
00027   : DDXMLElement( myreg )
00028 {}
00029 
00030 DDLAlgoPosPart::~DDLAlgoPosPart( void )
00031 {}
00032 
00033 // Upon encountering the end tag of the AlgoPosPart we should have in the meantime
00034 // hit rParent, rChild, ParS and ParE.
00035 void
00036 DDLAlgoPosPart::processElement( const std::string& name, const std::string& nmspace, DDCompactView& cpv )
00037 {
00038   DCOUT_V('P', "DDLAlgoPosPart::processElement started");
00039   
00040   // get all internal elements.
00041   DDXMLElement* myParent  = myRegistry_->getElement("rParent");
00042   DDXMLElement* myChild   = myRegistry_->getElement("rChild");
00043   DDXMLElement* myParS    = myRegistry_->getElement("ParS");
00044   DDXMLElement* myParE    = myRegistry_->getElement("ParE");
00045 
00046   ExprEvalInterface & ev = ExprEvalSingleton::instance();
00047   
00048   DDXMLAttribute atts = getAttributeSet();
00049 
00050   // these were doubles
00051   int st = static_cast<int> ((atts.find("start") == atts.end() ? 0.0 : ev.eval(nmspace, atts.find("start")->second)));
00052   int ic = static_cast<int> ((atts.find("incr") == atts.end() ? 0.0 : ev.eval(nmspace, atts.find("incr")->second)));
00053   int ed = static_cast<int> ((atts.find("end") == atts.end() ? 0.0 : ev.eval(nmspace, atts.find("end")->second)));
00054   
00055   // get actual DDLogicalPart objects.
00056   DDLogicalPart parent(DDName(myParent->getDDName(nmspace)));
00057   DDLogicalPart self(DDName(myChild->getDDName(nmspace)));
00058 
00059   // get the algorithm
00060   DDAlgo algo( getDDName(nmspace, "algo" ));
00061   if (!(algo.isDefined().second)) 
00062   {
00063     std::string  msg = std::string("\n\tDDLParser, algo requested is not defined.  Either AlgoInit() or check algo spelling.\n ")
00064                        + "\n\t\talgo=" + std::string(getDDName(nmspace, "algo" ))
00065                        + "\n\t\tparent=" + std::string(myParent->getDDName(nmspace))
00066                        + "\n\t\tself=" + std::string(myChild->getDDName(nmspace));
00067     throwError(msg);
00068   }
00069 
00070   // set the parameters for the algorithm
00071 
00072   // First for ParE type
00073   parE_type parE;
00074   for (size_t i = 0; i < myParE->size(); ++i)
00075   {
00076     atts = myParE->getAttributeSet(i);
00077     // find vname in ParE.
00078     parE_type::iterator existingName=parE.find(atts.find("name")->second);
00079       
00080     // if found, get std::vector, then add this value to it.
00081     // if not found, add this var, then add a value to it.
00082     if (existingName != parE.end())
00083       existingName->second.push_back(ev.eval(nmspace,atts.find("value")->second));
00084     //  tvect = existingName->second;
00085     else
00086     {
00087       std::vector<double> tvect;
00088       tvect.push_back(ev.eval(nmspace,atts.find("value")->second));
00089       parE[atts.find("name")->second] = tvect;
00090     }
00091   }
00092 
00093   // Now for ParS type
00094   parS_type parS;
00095 
00096   for (size_t i = 0; i < myParS->size(); ++i)
00097   {
00098     atts = myParS->getAttributeSet(i);
00099 
00100     // find vname in ParS.
00101     parS_type::iterator existingName=parS.find(atts.find("name")->second);
00102       
00103     // if found, get std::vector, then add this value to it.
00104     // if not found, add this var, then add a value to it.
00105 
00106     if (existingName != parS.end())
00107       existingName->second.push_back(atts.find("value")->second);
00108     else
00109     {
00110       std::vector<std::string> tvect;
00111       tvect.push_back(atts.find("value")->second);
00112       parS[atts.find("name")->second] = tvect;
00113     }
00114   }
00115   
00116   algo.setParameters(st,ed,ic,parS,parE);
00117   // for efficiency, I do not want to make a DDAlgoPositioner every time this is called.
00118   // so DDCompactView must have a way to position inside itself as well.
00119   cpv.algoPosPart(self, parent, algo);
00120   //  ap_(self, parent, algo);
00121   // clear all "children" and attributes
00122   myChild->clear();
00123   myParent->clear();
00124   myParS->clear();
00125   myParE->clear();
00126   // after an AlgoPosPart, we are sure it can be cleared.
00127   clear();
00128   
00129   DCOUT_V('P', "DDLAlgoPosPart::processElement completed");
00130 }
00131