PageRenderTime 31ms CodeModel.GetById 19ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/DetectorDescription/Parser/src/DDLPosPart.cc

https://github.com/aivanov-cern/cmssw
C++ | 161 lines | 91 code | 25 blank | 45 comment | 16 complexity | c99653f4783db505a87869fc39dd1749 MD5 | raw file
  1/***************************************************************************
  2                          DDLPosPart.cc  -  description
  3                             -------------------
  4    begin                : Tue Oct 30 2001
  5    email                : case@ucdhep.ucdavis.edu
  6 ***************************************************************************/
  7
  8/***************************************************************************
  9 *                                                                         *
 10 *           DDDParser sub-component of DDD                                *
 11 *                                                                         *
 12 ***************************************************************************/
 13
 14#include "DetectorDescription/Parser/src/DDLPosPart.h"
 15
 16#include "DetectorDescription/Core/interface/DDLogicalPart.h"
 17#include "DetectorDescription/Core/interface/DDName.h"
 18#include "DetectorDescription/Base/interface/DDdebug.h"
 19
 20#include "DetectorDescription/ExprAlgo/interface/ClhepEvaluator.h"
 21
 22DDLPosPart::DDLPosPart( DDLElementRegistry* myreg )
 23  : DDXMLElement( myreg )
 24{}
 25
 26DDLPosPart::~DDLPosPart( void )
 27{}
 28
 29// Upon encountering a PosPart, store the label, simple.
 30// Just in case some left-over Rotation has not been cleared, make sure
 31// that it is cleared.  
 32// I commented out the others because the last element
 33// that made use of them should have cleared them.
 34void
 35DDLPosPart::preProcessElement( const std::string& name, const std::string& nmspace, DDCompactView& cpv )
 36{
 37  DCOUT_V('P', "DDLPosPart::preProcessElement started");
 38
 39  // Clear out child elements.
 40  myRegistry_->getElement("Rotation")->clear();
 41  myRegistry_->getElement("ReflectionRotation")->clear();
 42
 43  DCOUT_V('P', "DDLPosPart::preProcessElement completed");
 44}
 45
 46// Upon encountering the end tag of the PosPart we should have in the meantime
 47// hit two rLogicalPart calls and one of Rotation or rRotation and a Translation.
 48// So, retrieve them and make the call to DDCore.
 49void
 50DDLPosPart::processElement( const std::string& name, const std::string& nmspace, DDCompactView& cpv )
 51{
 52  DCOUT_V('P', "DDLPosPart::processElement started");
 53  
 54  // get all internal elements.
 55  DDXMLElement* myParent     = myRegistry_->getElement("rParent");
 56  DDXMLElement* myChild      = myRegistry_->getElement("rChild");
 57  DDXMLElement* myTranslation= myRegistry_->getElement("Translation");
 58  DDXMLElement* myDDLRotation= myRegistry_->getElement("Rotation");
 59  DDXMLElement* myrRotation  = myRegistry_->getElement("rRotation");
 60  DDXMLElement* myDDLRefl    = myRegistry_->getElement("ReflectionRotation");
 61  DDXMLElement* myrRefl      = myRegistry_->getElement("rReflectionRotation");
 62  // FIXME!!! add in the new RotationByAxis element...
 63
 64  // At this time, PosPart is becoming the most complex of the elements.
 65  // For simply reflections/rotations we have 4 possible internal "components"
 66  // to the PosPart.  We take them in the following order of priority
 67  //     rRotation, Rotation, rReflectionRotation, ReflectionRotation.
 68  //
 69  // The idea in the following if-else-if is that no matter
 70  // what was used inside the PosPart element, the order in which we
 71  // will look for and use an internal element is:
 72  // rRotation, Rotation, ReflectionRotation, rReflectionRotation.
 73  // If it falls through here, a default call will result in a nameless 
 74  // "identity" rotation being passed to DDCore.
 75  DDName rotn;
 76  if (myrRotation->size() > 0){
 77    rotn = myrRotation->getDDName(nmspace);
 78  }
 79  else if (myDDLRotation->size() > 0) {
 80    // The assumption here is that the Rotation element created 
 81    // a DDRotation already, and so we can use this as an rRotation
 82    // just provide DDCore with the name of the one just added... 
 83    // How to handle name conflicts? OVERWRITTEN by DDCore for now.
 84    rotn = myDDLRotation->getDDName(nmspace);
 85  }
 86  else if (myDDLRefl->size() > 0) {
 87    // The assumption is that a ReflectionRotation has been created and therefore 
 88    // we can refer to it as the rotation associated with this PosPart.
 89    // we can further assume that the namespace is the same as this PosPart.
 90    rotn = myDDLRefl->getDDName(nmspace);
 91  }
 92  else if (myrRefl->size() > 0) {
 93    rotn = myrRefl->getDDName(nmspace);
 94  }
 95
 96  DCOUT_V('P', "DDLPosPart::processElement:  Final Rotation info: " << rotn);
 97
 98  ClhepEvaluator & ev = myRegistry_->evaluator();
 99
100  double x = 0.0, y = 0.0, z = 0.0;
101  if (myTranslation->size() > 0)
102  {
103    const DDXMLAttribute & atts = myTranslation->getAttributeSet();
104    x = ev.eval(nmspace, atts.find("x")->second);
105    y = ev.eval(nmspace, atts.find("y")->second);
106    z = ev.eval(nmspace, atts.find("z")->second);
107  }
108
109  DCOUT_V('P', "DDLPosPart::processElement:  Final Translation info x=" << x << " y=" << y << " z=" << z);
110
111  DDRotation* myDDRotation;
112  // if rotation is named ...
113  if ( rotn.name() != "" && rotn.ns() != "" ) {
114    DDRotation temp(rotn);
115    myDDRotation = &temp;
116  } else { 
117    // rotn is not assigned a name anywhere therefore the DDPos assumes the identity matrix.
118    DDRotation temp(DDName(std::string("identity"),std::string("generatedForDDD")));
119    myDDRotation = &temp;
120    // if the identity is not yet defined, then...
121    if ( !myDDRotation->isValid() ) {
122      DDRotationMatrix* dmr = new DDRotationMatrix;
123      temp = DDrot(DDName(std::string("identity"),std::string("generatedForDDD")), dmr );
124      myDDRotation = &temp;
125    }
126  }
127
128
129  DDTranslation myDDTranslation(x, y, z);
130
131  DCOUT_V('P', "about to make a PosPart ...");
132  DCOUT_V('p', "  myDDRotation    : " << *myDDRotation);
133  DCOUT_V('p', "  myDDTranslation : " << myDDTranslation);
134  DCOUT_V('p', "  parentDDName    : " << myParent->getDDName(nmspace));
135  DCOUT_V('p', "  selfDDName      : " << myChild->getDDName(nmspace));
136
137  const DDXMLAttribute & atts = getAttributeSet();
138  std::string copyno = "";
139  if (atts.find("copyNumber") != atts.end())
140    copyno = atts.find("copyNumber")->second;
141    
142  cpv.position(DDLogicalPart(myChild->getDDName(nmspace))
143	       , DDLogicalPart(myParent->getDDName(nmspace))
144	       , copyno
145	       , myDDTranslation
146	       , *myDDRotation);
147  
148  // clear all "children" and attributes
149  myParent->clear();
150  myChild->clear();
151  myTranslation->clear();
152  myDDLRotation->clear();
153  myrRotation->clear();
154  myDDLRefl->clear();
155  myrRefl->clear();
156
157  // after a pos part is done, we know we can clear it.
158  clear();
159
160  DCOUT_V('P', "DDLPosPart::processElement completed");
161}