File indexing completed on 2024-04-06 12:05:32
0001 #include "DetectorDescription/Parser/src/DDLPgonGenerator.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 DDLPgonGenerator::DDLPgonGenerator(DDLElementRegistry* myreg) : DDLSolid(myreg) {}
0016
0017 void DDLPgonGenerator::preProcessElement(const std::string& name, const std::string& nmspace, DDCompactView& cpv) {
0018 myRegistry_->getElement("XYPoint")->clear();
0019 myRegistry_->getElement("ZXYSection")->clear();
0020 }
0021
0022
0023
0024
0025 void DDLPgonGenerator::processElement(const std::string& name, const std::string& nmspace, DDCompactView& cpv) {
0026 auto myXYPoints = myRegistry_->getElement("XYPoint");
0027 auto myZXYSection = myRegistry_->getElement("ZXYSection");
0028
0029 ClhepEvaluator& ev = myRegistry_->evaluator();
0030 DDXMLAttribute atts;
0031
0032
0033 std::vector<double> x, y;
0034 for (size_t i = 0; i < myXYPoints->size(); ++i) {
0035 atts = myXYPoints->getAttributeSet(i);
0036 auto xit = atts.find("x");
0037 if (xit != atts.end())
0038 x.emplace_back(ev.eval(nmspace, xit->second));
0039 auto yit = atts.find("y");
0040 if (yit != atts.end())
0041 y.emplace_back(ev.eval(nmspace, yit->second));
0042 }
0043 assert(x.size() == y.size());
0044
0045
0046 std::vector<double> z, zx, zy, zscale;
0047
0048 for (size_t i = 0; i < myZXYSection->size(); ++i) {
0049 atts = myZXYSection->getAttributeSet(i);
0050 auto zit = atts.find("z");
0051 if (zit != atts.end())
0052 z.emplace_back(ev.eval(nmspace, zit->second));
0053 auto xit = atts.find("x");
0054 if (xit != atts.end())
0055 zx.emplace_back(ev.eval(nmspace, xit->second));
0056 auto yit = atts.find("y");
0057 if (yit != atts.end())
0058 zy.emplace_back(ev.eval(nmspace, yit->second));
0059 auto sit = atts.find("scale");
0060 if (sit != atts.end())
0061 zscale.emplace_back(std::stod(sit->second));
0062 }
0063 assert(z.size() == zx.size());
0064 assert(z.size() == zy.size());
0065 assert(z.size() == zscale.size());
0066
0067 atts = getAttributeSet();
0068 if (name == "ExtrudedPolygon") {
0069 DDSolid extrudedpolygon = DDSolidFactory::extrudedpolygon(getDDName(nmspace), x, y, z, zx, zy, zscale);
0070 } else {
0071 std::string msg = "\nDDLPgonGenerator::processElement was called with incorrect name of solid: " + name;
0072 throwError(msg);
0073 }
0074 DDLSolid::setReference(nmspace, cpv);
0075
0076
0077 myXYPoints->clear();
0078 myZXYSection->clear();
0079 clear();
0080 }