PageRenderTime 75ms CodeModel.GetById 15ms app.highlight 57ms RepoModel.GetById 1ms app.codeStats 0ms

/DetectorDescription/Parser/src/DDLDivision.cc

https://github.com/aivanov-cern/cmssw
C++ | 262 lines | 226 code | 25 blank | 11 comment | 77 complexity | 977ab3360199ece7d08b27e04cbc5edd MD5 | raw file
  1/***************************************************************************
  2                          DDLDivision.cc  -  description
  3                             -------------------
  4    begin                : Friday, April 23, 2004
  5    email                : case@ucdhep.ucdavis.edu
  6 ***************************************************************************/
  7
  8/***************************************************************************
  9 *                                                                         *
 10 *           DDDParser sub-component of DDD                                *
 11 *                                                                         *
 12 ***************************************************************************/
 13
 14#include "DetectorDescription/Parser/src/DDLDivision.h"
 15#include "DetectorDescription/Parser/src/DDDividedBox.h"
 16#include "DetectorDescription/Parser/src/DDDividedTubs.h"
 17#include "DetectorDescription/Parser/src/DDDividedTrd.h"
 18#include "DetectorDescription/Parser/src/DDDividedCons.h"
 19#include "DetectorDescription/Parser/src/DDDividedPolycone.h"
 20#include "DetectorDescription/Parser/src/DDDividedPolyhedra.h"
 21
 22#include "DetectorDescription/Core/interface/DDName.h"
 23#include "DetectorDescription/Core/interface/DDAxes.h"
 24#include "DetectorDescription/Core/interface/DDSolid.h"
 25#include "DetectorDescription/Core/interface/DDSolidShapes.h"
 26#include "DetectorDescription/Core/interface/DDLogicalPart.h"
 27#include "DetectorDescription/Base/interface/DDdebug.h"
 28
 29#include "DetectorDescription/ExprAlgo/interface/ClhepEvaluator.h"
 30
 31DDLDivision::DDLDivision( DDLElementRegistry* myreg )
 32  : DDXMLElement( myreg )
 33{}
 34
 35DDLDivision::~DDLDivision( void )
 36{}
 37
 38void
 39DDLDivision::preProcessElement( const std::string& name, const std::string& nmspace, DDCompactView& cpv )
 40{}
 41
 42void
 43DDLDivision::processElement( const std::string& name, const std::string& nmspace, DDCompactView& cpv )
 44{
 45  DCOUT_V('P', "DDLDivision::processElement started");
 46
 47  DDXMLAttribute atts = getAttributeSet();
 48
 49  DDName parent = getDDName(nmspace, "parent");
 50  ClhepEvaluator & ev = myRegistry_->evaluator();
 51  size_t ax = 0;
 52  while (DDAxesNames::name(DDAxes(ax)) != atts.find("axis")->second &&
 53	 DDAxesNames::name(DDAxes(ax)) != "undefined")
 54    ++ax;
 55
 56  DDLogicalPart lp(parent);
 57  if ( !lp.isDefined().second || !lp.solid().isDefined().second ) {
 58    std::string em("DetectorDescription Parser DDLDivision::processElement(...) failed.");
 59    em += "  The solid of the parent logical part MUST be defined before the Division is made.";
 60    em += "\n    name= " + getDDName(nmspace).ns() + ":" + getDDName(nmspace).name() ;
 61    em += "\n    parent= " + parent.ns() + ":" + parent.name();
 62    throwError (em);
 63  }
 64
 65  DDDivision div;
 66
 67  if (atts.find("nReplicas") != atts.end() 
 68      && atts.find("width")  != atts.end()
 69      && atts.find("offset") != atts.end())
 70  {
 71    div = DDDivision(getDDName(nmspace)
 72		     , parent
 73		     , DDAxes(ax)
 74		     , int(ev.eval(nmspace, atts.find("nReplicas")->second))
 75		     , ev.eval(nmspace, atts.find("width")->second)
 76		     , ev.eval(nmspace, atts.find("offset")->second));
 77  }
 78  else if (atts.find("nReplicas")  != atts.end()
 79	   && atts.find("offset") != atts.end())
 80  {
 81    div = DDDivision(getDDName(nmspace)
 82		     , parent
 83		     , DDAxes(ax)
 84		     , int(ev.eval(nmspace, atts.find("nReplicas")->second))
 85		     , ev.eval(nmspace, atts.find("offset")->second));
 86  }
 87  else if (atts.find("width")     != atts.end()
 88	   && atts.find("offset") != atts.end())
 89  {
 90    DCOUT_V ('D', " width = " << ev.eval(nmspace, atts.find("width")->second) << std::endl);
 91    DCOUT_V ('D', " offset = " << ev.eval(nmspace, atts.find("offset")->second) << std::endl);
 92    div = DDDivision(getDDName(nmspace)
 93		     , parent
 94		     , DDAxes(ax)
 95		     , ev.eval(nmspace, atts.find("width")->second)
 96		     , ev.eval(nmspace, atts.find("offset")->second));
 97  } else {
 98    std::string em("DetectorDescription Parser DDLDivision::processElement(...) failed.");
 99    em += "  Allowed combinations are attributes width&offset OR nReplicas&offset OR nReplicas&width&offset.";
100    em += "\n    name= " + getDDName(nmspace).ns() + ":" + getDDName(nmspace).name() ;
101    em += "\n    parent= " + parent.ns() + ":" + parent.name();
102    throwError (em);
103  }
104  DDDividedGeometryObject* dg = makeDivider(div, &cpv);
105  dg->execute();
106  delete dg;
107
108  clear();
109
110  DCOUT_V('P', "DDLDivision::processElement completed");
111}
112
113DDDividedGeometryObject*
114DDLDivision::makeDivider( const DDDivision& div, DDCompactView* cpv )
115{
116  DDDividedGeometryObject* dg = NULL;
117
118  switch (div.parent().solid().shape()) 
119  {
120  case ddbox:
121    if (div.axis() == x)
122      dg = new DDDividedBoxX(div,cpv);
123    else if (div.axis() == y)
124      dg = new DDDividedBoxY(div,cpv);
125    else if (div.axis() == z)
126      dg = new DDDividedBoxZ(div,cpv);
127    else {
128      std::string s = "DDLDivision can not divide a ";
129      s += DDSolidShapesName::name(div.parent().solid().shape());
130      s += " along axis " + DDAxesNames::name(div.axis());
131      s += ".";
132      s += "\n    name= " + div.name().ns() + ":" + div.name().name() ;
133      s += "\n    parent= " + div.parent().name().ns() + ":" + div.parent().name().name();
134      throwError(s);
135    }
136    break;
137
138  case ddtubs:
139    if (div.axis() == rho)
140      dg = new DDDividedTubsRho(div,cpv);
141    else if (div.axis() == phi)
142      dg = new DDDividedTubsPhi(div,cpv);
143    else if (div.axis() == z)
144      dg = new DDDividedTubsZ(div,cpv);
145    else {
146      std::string s = "DDLDivision can not divide a ";
147      s += DDSolidShapesName::name(div.parent().solid().shape());
148      s += " along axis " + DDAxesNames::name(div.axis());
149      s += ".";
150      s += "\n    name= " + div.name().ns() + ":" + div.name().name() ;
151      s += "\n    parent= " + div.parent().name().ns() + ":" + div.parent().name().name();
152      throwError(s);
153    }
154    break;
155
156  case ddtrap:
157    if (div.axis() == x)
158      dg = new DDDividedTrdX(div,cpv);
159    else if (div.axis() == y )
160      dg = new DDDividedTrdY(div,cpv);
161    else if (div.axis() == z )
162      dg = new DDDividedTrdZ(div,cpv);
163    else {
164      std::string s = "DDLDivision can not divide a ";
165      s += DDSolidShapesName::name(div.parent().solid().shape());
166      s += " along axis ";
167      s += DDAxesNames::name(div.axis());
168      s += ".";
169      s += "\n    name= " + div.name().ns() + ":" + div.name().name() ;
170      s += "\n    parent= " + div.parent().name().ns() + ":" + div.parent().name().name();
171      throwError(s);
172    }
173    break;
174
175  case ddcons:
176    if (div.axis() == rho)
177      dg = new DDDividedConsRho(div,cpv);
178    else if (div.axis() == phi)
179      dg = new DDDividedConsPhi(div,cpv);
180    else if (div.axis() == z)
181      dg = new DDDividedConsZ(div,cpv);
182    else {
183      std::string s = "DDLDivision can not divide a ";
184      s += DDSolidShapesName::name(div.parent().solid().shape());
185      s += " along axis " + DDAxesNames::name(div.axis());
186      s += ".";
187      s += "\n    name= " + div.name().ns() + ":" + div.name().name() ;
188      s += "\n    parent= " + div.parent().name().ns() + ":" + div.parent().name().name();
189      throwError(s);
190    }
191    break;
192
193  case ddpolycone_rrz:
194    if (div.axis() == rho)
195      dg = new DDDividedPolyconeRho(div,cpv);
196    else if (div.axis() == phi)
197      dg = new DDDividedPolyconePhi(div,cpv);
198    else if (div.axis() == z)
199      dg = new DDDividedPolyconeZ(div,cpv);
200    else {
201      std::string s = "DDLDivision can not divide a ";
202      s += DDSolidShapesName::name(div.parent().solid().shape());
203      s += " along axis ";
204      s += DDAxesNames::name(div.axis());
205      s += ".";
206      s += "\n    name= " + div.name().ns() + ":" + div.name().name() ;
207      s += "\n    parent= " + div.parent().name().ns() + ":" + div.parent().name().name();
208      throwError(s);
209    }
210    break;
211
212  case ddpolyhedra_rrz:
213    if (div.axis() == rho)
214      dg = new DDDividedPolyhedraRho(div,cpv);
215    else if (div.axis() == phi)
216      dg = new DDDividedPolyhedraPhi(div,cpv);
217    else if (div.axis() == z)
218      dg = new DDDividedPolyhedraZ(div,cpv);
219    else {
220      std::string s = "DDLDivision can not divide a ";
221      s += DDSolidShapesName::name(div.parent().solid().shape());
222      s += " along axis ";
223      s += DDAxesNames::name(div.axis());
224      s += ".";
225      s += "\n    name= " + div.name().ns() + ":" + div.name().name() ;
226      s += "\n    parent= " + div.parent().name().ns() + ":" + div.parent().name().name();
227      throwError(s);
228    }
229    break;
230
231  case ddpolycone_rz:
232  case ddpolyhedra_rz: {
233    std::string s = "ERROR:  A Polycone or Polyhedra can not be divided on any axis if it's\n";
234    s += "original definition used r and z instead of ZSections. This has\n";
235    s += "not (yet) been implemented.";
236    s += "\n    name= " + div.name().ns() + ":" + div.name().name() ;
237    s += "\n    parent= " + div.parent().name().ns() + ":" + div.parent().name().name();
238  }
239    break;
240
241  case ddunion: 
242  case ddsubtraction: 
243  case ddintersection: 
244  case ddreflected: 
245  case ddshapeless: 
246  case ddpseudotrap: 
247  case ddtrunctubs:
248  case dd_not_init: {
249    std::string s = "DDLDivision can not divide a ";
250    s += DDSolidShapesName::name(div.parent().solid().shape());
251    s += " at all (yet?).  Requested axis was ";
252    s += DDAxesNames::name(div.axis());
253    s += ".\n";
254    throwError(s);
255  }
256    break;
257  default:
258    break;
259  }
260  return dg;
261
262}