CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/DetectorDescription/Parser/src/DDLPolyGenerator.cc

Go to the documentation of this file.
00001 /***************************************************************************
00002                           DDLPolyGenerator.cpp  -  description
00003                              -------------------
00004     begin                : Thu Oct 25 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/DDLPolyGenerator.h"
00015 
00016 #include "DetectorDescription/Core/interface/DDName.h"
00017 #include "DetectorDescription/Core/interface/DDSolid.h"
00018 #include "DetectorDescription/Base/interface/DDdebug.h"
00019 
00020 #include "DetectorDescription/ExprAlgo/interface/ExprEvalSingleton.h"
00021 
00022 DDLPolyGenerator::DDLPolyGenerator( DDLElementRegistry* myreg )
00023   : DDLSolid( myreg )
00024 {}
00025 
00026 DDLPolyGenerator::~DDLPolyGenerator( void )
00027 {}
00028 
00029 void
00030 DDLPolyGenerator::preProcessElement( const std::string& name, const std::string& nmspace, DDCompactView& cpv )
00031 {
00032   myRegistry_->getElement("RZPoint")->clear();
00033   myRegistry_->getElement("ZSection")->clear();
00034 }
00035 
00036 // Upon encountering an end Polycone or Polyhedra tag, process the RZPoints
00037 // element and extract the r and z std::vectors to feed into DDCore.  Then, clear
00038 // the RZPoints and clear this element.
00039 void
00040 DDLPolyGenerator::processElement( const std::string& name, const std::string& nmspace, DDCompactView& cpv )
00041 {
00042   DCOUT_V('P', "DDLPolyGenerator::processElement started");
00043 
00044   DDXMLElement* myRZPoints = myRegistry_->getElement("RZPoint");
00045   DDXMLElement* myZSection = myRegistry_->getElement("ZSection");
00046 
00047   ExprEvalInterface & ev = ExprEvalSingleton::instance();
00048   DDXMLAttribute atts;
00049 
00050   // get z and r
00051   std::vector<double> z, r;
00052   for (size_t i = 0; i < myRZPoints->size(); ++i)
00053   {
00054     atts = myRZPoints->getAttributeSet(i);
00055     z.push_back(ev.eval(nmspace, atts.find("z")->second));
00056     r.push_back(ev.eval(nmspace, atts.find("r")->second));
00057   }
00058 
00059   // if z is empty, then it better not have been a polycone defined
00060   // by RZPoints, instead, it must be a ZSection defined polycone.
00061   if (z.size() == 0 )
00062   {
00063     // get zSection information, note, we already have a z declared above
00064     // and we will use r for rmin.  In this case, no use "trying" because
00065     // it better be there!
00066     std::vector<double> rMax;
00067 
00068     for (size_t i = 0; i < myZSection->size(); ++i)
00069     {
00070       atts = myZSection->getAttributeSet(i);
00071       z.push_back(ev.eval(nmspace, atts.find("z")->second));
00072       r.push_back(ev.eval(nmspace, atts.find("rMin")->second));
00073       rMax.push_back(ev.eval(nmspace, atts.find("rMax")->second));
00074     }
00075     atts = getAttributeSet();
00076     if (name == "Polycone") // defined with ZSections 
00077     {
00078       DDSolid ddpolycone = 
00079         DDSolidFactory::polycone(getDDName(nmspace)
00080                                  , ev.eval(nmspace, atts.find("startPhi")->second)
00081                                  , ev.eval(nmspace, atts.find("deltaPhi")->second)
00082                                  , z
00083                                  , r
00084                                  , rMax);
00085     }
00086     else if (name == "Polyhedra")  // defined with ZSections
00087     {
00088       DDSolid ddpolyhedra = 
00089         DDSolidFactory::polyhedra(getDDName(nmspace)
00090                                   , int (ev.eval(nmspace, atts.find("numSide")->second))
00091                                   , ev.eval(nmspace, atts.find("startPhi")->second)
00092                                   , ev.eval(nmspace, atts.find("deltaPhi")->second)
00093                                   , z
00094                                   , r
00095                                   , rMax);
00096     }
00097 
00098   }
00099   else if (name == "Polycone") // defined with RZPoints
00100   {
00101     atts = getAttributeSet();
00102     DDSolid ddpolycone = 
00103       DDSolidFactory::polycone(getDDName(nmspace)
00104                                , ev.eval(nmspace, atts.find("startPhi")->second)
00105                                , ev.eval(nmspace, atts.find("deltaPhi")->second)
00106                                , z
00107                                , r);
00108   }
00109   else if (name == "Polyhedra") // defined with RZPoints
00110   {
00111     atts = getAttributeSet();
00112     DDSolid ddpolyhedra = 
00113       DDSolidFactory::polyhedra(getDDName(nmspace)
00114                                 , int (ev.eval(nmspace, atts.find("numSide")->second))
00115                                 , ev.eval(nmspace, atts.find("startPhi")->second)
00116                                 , ev.eval(nmspace, atts.find("deltaPhi")->second)
00117                                 , z
00118                                 , r);
00119   }
00120   else
00121   {
00122     std::string msg = "\nDDLPolyGenerator::processElement was called with incorrect name of solid: " + name;
00123     throwError(msg);
00124   }
00125   DDLSolid::setReference(nmspace, cpv);
00126 
00127   // clear out RZPoint element accumulator and ZSections
00128   myRZPoints->clear();
00129   myZSection->clear();
00130   clear();
00131 
00132   DCOUT_V('P', "DDLPolyGenerator::processElement completed");
00133 }