Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "DetectorDescription/Parser/src/DDLPolyGenerator.h"
0002 #include "DetectorDescription/Core/interface/DDSolid.h"
0003 #include "DetectorDescription/Core/interface/ClhepEvaluator.h"
0004 #include "DetectorDescription/Parser/interface/DDLElementRegistry.h"
0005 #include "DetectorDescription/Parser/src/DDLSolid.h"
0006 #include "DetectorDescription/Parser/src/DDXMLElement.h"
0007 
0008 #include <cstddef>
0009 #include <map>
0010 #include <utility>
0011 #include <vector>
0012 
0013 class DDCompactView;
0014 
0015 DDLPolyGenerator::DDLPolyGenerator(DDLElementRegistry* myreg) : DDLSolid(myreg) {}
0016 
0017 void DDLPolyGenerator::preProcessElement(const std::string& name, const std::string& nmspace, DDCompactView& cpv) {
0018   myRegistry_->getElement("RZPoint")->clear();
0019   myRegistry_->getElement("ZSection")->clear();
0020 }
0021 
0022 // Upon encountering an end Polycone or Polyhedra tag, process the RZPoints
0023 // element and extract the r and z std::vectors to feed into DDCore.  Then, clear
0024 // the RZPoints and clear this element.
0025 void DDLPolyGenerator::processElement(const std::string& name, const std::string& nmspace, DDCompactView& cpv) {
0026   auto myRZPoints = myRegistry_->getElement("RZPoint");
0027   auto myZSection = myRegistry_->getElement("ZSection");
0028 
0029   ClhepEvaluator& ev = myRegistry_->evaluator();
0030   DDXMLAttribute atts;
0031 
0032   // get z and r
0033   std::vector<double> z, r, x, y;
0034   for (size_t i = 0; i < myRZPoints->size(); ++i) {
0035     atts = myRZPoints->getAttributeSet(i);
0036     z.emplace_back(ev.eval(nmspace, atts.find("z")->second));
0037     r.emplace_back(ev.eval(nmspace, atts.find("r")->second));
0038   }
0039 
0040   // if z is empty, then it better not have been a polycone defined
0041   // by RZPoints, instead, it must be a ZSection defined polycone.
0042   if (z.empty()) {
0043     // get zSection information, note, we already have a z declared above
0044     // and we will use r for rmin.  In this case, no use "trying" because
0045     // it better be there!
0046     std::vector<double> rMax;
0047 
0048     for (size_t i = 0; i < myZSection->size(); ++i) {
0049       atts = myZSection->getAttributeSet(i);
0050       z.emplace_back(ev.eval(nmspace, atts.find("z")->second));
0051       r.emplace_back(ev.eval(nmspace, atts.find("rMin")->second));
0052       rMax.emplace_back(ev.eval(nmspace, atts.find("rMax")->second));
0053     }
0054     atts = getAttributeSet();
0055     if (name == "Polycone")  // defined with ZSections
0056     {
0057       DDSolid ddpolycone = DDSolidFactory::polycone(getDDName(nmspace),
0058                                                     ev.eval(nmspace, atts.find("startPhi")->second),
0059                                                     ev.eval(nmspace, atts.find("deltaPhi")->second),
0060                                                     z,
0061                                                     r,
0062                                                     rMax);
0063     } else if (name == "Polyhedra")  // defined with ZSections
0064     {
0065       DDSolid ddpolyhedra = DDSolidFactory::polyhedra(getDDName(nmspace),
0066                                                       int(ev.eval(nmspace, atts.find("numSide")->second)),
0067                                                       ev.eval(nmspace, atts.find("startPhi")->second),
0068                                                       ev.eval(nmspace, atts.find("deltaPhi")->second),
0069                                                       z,
0070                                                       r,
0071                                                       rMax);
0072     }
0073 
0074   } else if (name == "Polycone")  // defined with RZPoints
0075   {
0076     atts = getAttributeSet();
0077     DDSolid ddpolycone = DDSolidFactory::polycone(getDDName(nmspace),
0078                                                   ev.eval(nmspace, atts.find("startPhi")->second),
0079                                                   ev.eval(nmspace, atts.find("deltaPhi")->second),
0080                                                   z,
0081                                                   r);
0082   } else if (name == "Polyhedra")  // defined with RZPoints
0083   {
0084     atts = getAttributeSet();
0085     DDSolid ddpolyhedra = DDSolidFactory::polyhedra(getDDName(nmspace),
0086                                                     int(ev.eval(nmspace, atts.find("numSide")->second)),
0087                                                     ev.eval(nmspace, atts.find("startPhi")->second),
0088                                                     ev.eval(nmspace, atts.find("deltaPhi")->second),
0089                                                     z,
0090                                                     r);
0091   } else {
0092     std::string msg = "\nDDLPolyGenerator::processElement was called with incorrect name of solid: " + name;
0093     throwError(msg);
0094   }
0095   DDLSolid::setReference(nmspace, cpv);
0096 
0097   // clear out RZPoint element accumulator and ZSections
0098   myRZPoints->clear();
0099   myZSection->clear();
0100   clear();
0101 }