00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "DetectorDescription/Parser/src/DDLDivision.h"
00015 #include "DetectorDescription/Parser/src/DDDividedBox.h"
00016 #include "DetectorDescription/Parser/src/DDDividedTubs.h"
00017 #include "DetectorDescription/Parser/src/DDDividedTrd.h"
00018 #include "DetectorDescription/Parser/src/DDDividedCons.h"
00019 #include "DetectorDescription/Parser/src/DDDividedPolycone.h"
00020 #include "DetectorDescription/Parser/src/DDDividedPolyhedra.h"
00021
00022 #include "DetectorDescription/Core/interface/DDName.h"
00023 #include "DetectorDescription/Core/interface/DDAxes.h"
00024 #include "DetectorDescription/Core/interface/DDSolid.h"
00025 #include "DetectorDescription/Core/interface/DDSolidShapes.h"
00026 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
00027 #include "DetectorDescription/Base/interface/DDdebug.h"
00028
00029 #include "DetectorDescription/ExprAlgo/interface/ExprEvalSingleton.h"
00030
00031 DDLDivision::DDLDivision( DDLElementRegistry* myreg )
00032 : DDXMLElement( myreg )
00033 {}
00034
00035 DDLDivision::~DDLDivision( void )
00036 {}
00037
00038 void
00039 DDLDivision::preProcessElement( const std::string& name, const std::string& nmspace, DDCompactView& cpv )
00040 {}
00041
00042 void
00043 DDLDivision::processElement( const std::string& name, const std::string& nmspace, DDCompactView& cpv )
00044 {
00045 DCOUT_V('P', "DDLDivision::processElement started");
00046
00047 DDXMLAttribute atts = getAttributeSet();
00048
00049 DDName parent = getDDName(nmspace, "parent");
00050 ExprEvalInterface & ev = ExprEvalSingleton::instance();
00051 size_t ax = 0;
00052 while (DDAxesNames::name(DDAxes(ax)) != atts.find("axis")->second &&
00053 DDAxesNames::name(DDAxes(ax)) != "undefined")
00054 ++ax;
00055
00056 DDLogicalPart lp(parent);
00057 if ( !lp.isDefined().second || !lp.solid().isDefined().second ) {
00058 std::string em("DetectorDescription Parser DDLDivision::processElement(...) failed.");
00059 em += " The solid of the parent logical part MUST be defined before the Division is made.";
00060 em += "\n name= " + getDDName(nmspace).ns() + ":" + getDDName(nmspace).name() ;
00061 em += "\n parent= " + parent.ns() + ":" + parent.name();
00062 throwError (em);
00063 }
00064
00065 DDDivision div;
00066
00067 if (atts.find("nReplicas") != atts.end()
00068 && atts.find("width") != atts.end()
00069 && atts.find("offset") != atts.end())
00070 {
00071 div = DDDivision(getDDName(nmspace)
00072 , parent
00073 , DDAxes(ax)
00074 , int(ev.eval(nmspace, atts.find("nReplicas")->second))
00075 , ev.eval(nmspace, atts.find("width")->second)
00076 , ev.eval(nmspace, atts.find("offset")->second));
00077 }
00078 else if (atts.find("nReplicas") != atts.end()
00079 && atts.find("offset") != atts.end())
00080 {
00081 div = DDDivision(getDDName(nmspace)
00082 , parent
00083 , DDAxes(ax)
00084 , int(ev.eval(nmspace, atts.find("nReplicas")->second))
00085 , ev.eval(nmspace, atts.find("offset")->second));
00086 }
00087 else if (atts.find("width") != atts.end()
00088 && atts.find("offset") != atts.end())
00089 {
00090 DCOUT_V ('D', " width = " << ev.eval(nmspace, atts.find("width")->second) << std::endl);
00091 DCOUT_V ('D', " offset = " << ev.eval(nmspace, atts.find("offset")->second) << std::endl);
00092 div = DDDivision(getDDName(nmspace)
00093 , parent
00094 , DDAxes(ax)
00095 , ev.eval(nmspace, atts.find("width")->second)
00096 , ev.eval(nmspace, atts.find("offset")->second));
00097 } else {
00098 std::string em("DetectorDescription Parser DDLDivision::processElement(...) failed.");
00099 em += " Allowed combinations are attributes width&offset OR nReplicas&offset OR nReplicas&width&offset.";
00100 em += "\n name= " + getDDName(nmspace).ns() + ":" + getDDName(nmspace).name() ;
00101 em += "\n parent= " + parent.ns() + ":" + parent.name();
00102 throwError (em);
00103 }
00104 DDDividedGeometryObject* dg = makeDivider(div, &cpv);
00105 dg->execute();
00106 delete dg;
00107
00108 clear();
00109
00110 DCOUT_V('P', "DDLDivision::processElement completed");
00111 }
00112
00113 DDDividedGeometryObject*
00114 DDLDivision::makeDivider( const DDDivision& div, DDCompactView* cpv )
00115 {
00116 DDDividedGeometryObject* dg = NULL;
00117
00118 switch (div.parent().solid().shape())
00119 {
00120 case ddbox:
00121 if (div.axis() == x)
00122 dg = new DDDividedBoxX(div,cpv);
00123 else if (div.axis() == y)
00124 dg = new DDDividedBoxY(div,cpv);
00125 else if (div.axis() == z)
00126 dg = new DDDividedBoxZ(div,cpv);
00127 else {
00128 std::string s = "DDLDivision can not divide a ";
00129 s += DDSolidShapesName::name(div.parent().solid().shape());
00130 s += " along axis " + DDAxesNames::name(div.axis());
00131 s += ".";
00132 s += "\n name= " + div.name().ns() + ":" + div.name().name() ;
00133 s += "\n parent= " + div.parent().name().ns() + ":" + div.parent().name().name();
00134 throwError(s);
00135 }
00136 break;
00137
00138 case ddtubs:
00139 if (div.axis() == rho)
00140 dg = new DDDividedTubsRho(div,cpv);
00141 else if (div.axis() == phi)
00142 dg = new DDDividedTubsPhi(div,cpv);
00143 else if (div.axis() == z)
00144 dg = new DDDividedTubsZ(div,cpv);
00145 else {
00146 std::string s = "DDLDivision can not divide a ";
00147 s += DDSolidShapesName::name(div.parent().solid().shape());
00148 s += " along axis " + DDAxesNames::name(div.axis());
00149 s += ".";
00150 s += "\n name= " + div.name().ns() + ":" + div.name().name() ;
00151 s += "\n parent= " + div.parent().name().ns() + ":" + div.parent().name().name();
00152 throwError(s);
00153 }
00154 break;
00155
00156 case ddtrap:
00157 if (div.axis() == x)
00158 dg = new DDDividedTrdX(div,cpv);
00159 else if (div.axis() == y )
00160 dg = new DDDividedTrdY(div,cpv);
00161 else if (div.axis() == z )
00162 dg = new DDDividedTrdZ(div,cpv);
00163 else {
00164 std::string s = "DDLDivision can not divide a ";
00165 s += DDSolidShapesName::name(div.parent().solid().shape());
00166 s += " along axis ";
00167 s += DDAxesNames::name(div.axis());
00168 s += ".";
00169 s += "\n name= " + div.name().ns() + ":" + div.name().name() ;
00170 s += "\n parent= " + div.parent().name().ns() + ":" + div.parent().name().name();
00171 throwError(s);
00172 }
00173 break;
00174
00175 case ddcons:
00176 if (div.axis() == rho)
00177 dg = new DDDividedConsRho(div,cpv);
00178 else if (div.axis() == phi)
00179 dg = new DDDividedConsPhi(div,cpv);
00180 else if (div.axis() == z)
00181 dg = new DDDividedConsZ(div,cpv);
00182 else {
00183 std::string s = "DDLDivision can not divide a ";
00184 s += DDSolidShapesName::name(div.parent().solid().shape());
00185 s += " along axis " + DDAxesNames::name(div.axis());
00186 s += ".";
00187 s += "\n name= " + div.name().ns() + ":" + div.name().name() ;
00188 s += "\n parent= " + div.parent().name().ns() + ":" + div.parent().name().name();
00189 throwError(s);
00190 }
00191 break;
00192
00193 case ddpolycone_rrz:
00194 if (div.axis() == rho)
00195 dg = new DDDividedPolyconeRho(div,cpv);
00196 else if (div.axis() == phi)
00197 dg = new DDDividedPolyconePhi(div,cpv);
00198 else if (div.axis() == z)
00199 dg = new DDDividedPolyconeZ(div,cpv);
00200 else {
00201 std::string s = "DDLDivision can not divide a ";
00202 s += DDSolidShapesName::name(div.parent().solid().shape());
00203 s += " along axis ";
00204 s += DDAxesNames::name(div.axis());
00205 s += ".";
00206 s += "\n name= " + div.name().ns() + ":" + div.name().name() ;
00207 s += "\n parent= " + div.parent().name().ns() + ":" + div.parent().name().name();
00208 throwError(s);
00209 }
00210 break;
00211
00212 case ddpolyhedra_rrz:
00213 if (div.axis() == rho)
00214 dg = new DDDividedPolyhedraRho(div,cpv);
00215 else if (div.axis() == phi)
00216 dg = new DDDividedPolyhedraPhi(div,cpv);
00217 else if (div.axis() == z)
00218 dg = new DDDividedPolyhedraZ(div,cpv);
00219 else {
00220 std::string s = "DDLDivision can not divide a ";
00221 s += DDSolidShapesName::name(div.parent().solid().shape());
00222 s += " along axis ";
00223 s += DDAxesNames::name(div.axis());
00224 s += ".";
00225 s += "\n name= " + div.name().ns() + ":" + div.name().name() ;
00226 s += "\n parent= " + div.parent().name().ns() + ":" + div.parent().name().name();
00227 throwError(s);
00228 }
00229 break;
00230
00231 case ddpolycone_rz:
00232 case ddpolyhedra_rz: {
00233 std::string s = "ERROR: A Polycone or Polyhedra can not be divided on any axis if it's\n";
00234 s += "original definition used r and z instead of ZSections. This has\n";
00235 s += "not (yet) been implemented.";
00236 s += "\n name= " + div.name().ns() + ":" + div.name().name() ;
00237 s += "\n parent= " + div.parent().name().ns() + ":" + div.parent().name().name();
00238 }
00239 break;
00240
00241 case ddunion:
00242 case ddsubtraction:
00243 case ddintersection:
00244 case ddreflected:
00245 case ddshapeless:
00246 case ddpseudotrap:
00247 case ddtrunctubs:
00248 case dd_not_init: {
00249 std::string s = "DDLDivision can not divide a ";
00250 s += DDSolidShapesName::name(div.parent().solid().shape());
00251 s += " at all (yet?). Requested axis was ";
00252 s += DDAxesNames::name(div.axis());
00253 s += ".\n";
00254 throwError(s);
00255 }
00256 break;
00257 default:
00258 break;
00259 }
00260 return dg;
00261
00262 }