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