/DetectorDescription/Parser/src/DDLAlgoPosPart.cc

https://github.com/aivanov-cern/cmssw · C++ · 131 lines · 74 code · 25 blank · 32 comment · 10 complexity · dab905ce3ce577b9674e41f24aee3ce3 MD5 · raw file

  1. /***************************************************************************
  2. DDLAlgoPosPart.cc - description
  3. -------------------
  4. begin : Wed Apr 17 2002
  5. email : case@ucdhep.ucdavis.edu
  6. ***************************************************************************/
  7. /***************************************************************************
  8. * *
  9. * DDDParser sub-component of DDD *
  10. * *
  11. ***************************************************************************/
  12. #include "DetectorDescription/Parser/src/DDLAlgoPosPart.h"
  13. #include "DetectorDescription/Core/interface/DDName.h"
  14. #include "DetectorDescription/Core/interface/DDLogicalPart.h"
  15. #include "DetectorDescription/Core/interface/DDAlgo.h"
  16. #include "DetectorDescription/Base/interface/DDAlgoPar.h"
  17. #include "DetectorDescription/Base/interface/DDdebug.h"
  18. #include "DetectorDescription/ExprAlgo/interface/ClhepEvaluator.h"
  19. #include <iostream>
  20. DDLAlgoPosPart::DDLAlgoPosPart( DDLElementRegistry* myreg )
  21. : DDXMLElement( myreg )
  22. {}
  23. DDLAlgoPosPart::~DDLAlgoPosPart( void )
  24. {}
  25. // Upon encountering the end tag of the AlgoPosPart we should have in the meantime
  26. // hit rParent, rChild, ParS and ParE.
  27. void
  28. DDLAlgoPosPart::processElement( const std::string& name, const std::string& nmspace, DDCompactView& cpv )
  29. {
  30. DCOUT_V('P', "DDLAlgoPosPart::processElement started");
  31. // get all internal elements.
  32. DDXMLElement* myParent = myRegistry_->getElement("rParent");
  33. DDXMLElement* myChild = myRegistry_->getElement("rChild");
  34. DDXMLElement* myParS = myRegistry_->getElement("ParS");
  35. DDXMLElement* myParE = myRegistry_->getElement("ParE");
  36. ClhepEvaluator & ev = myRegistry_->evaluator();
  37. DDXMLAttribute atts = getAttributeSet();
  38. // these were doubles
  39. int st = static_cast<int> ((atts.find("start") == atts.end() ? 0.0 : ev.eval(nmspace, atts.find("start")->second)));
  40. int ic = static_cast<int> ((atts.find("incr") == atts.end() ? 0.0 : ev.eval(nmspace, atts.find("incr")->second)));
  41. int ed = static_cast<int> ((atts.find("end") == atts.end() ? 0.0 : ev.eval(nmspace, atts.find("end")->second)));
  42. // get actual DDLogicalPart objects.
  43. DDLogicalPart parent(DDName(myParent->getDDName(nmspace)));
  44. DDLogicalPart self(DDName(myChild->getDDName(nmspace)));
  45. // get the algorithm
  46. DDAlgo algo( getDDName(nmspace, "algo" ));
  47. if (!(algo.isDefined().second))
  48. {
  49. std::string msg = std::string("\n\tDDLParser, algo requested is not defined. Either AlgoInit() or check algo spelling.\n ")
  50. + "\n\t\talgo=" + std::string(getDDName(nmspace, "algo" ))
  51. + "\n\t\tparent=" + std::string(myParent->getDDName(nmspace))
  52. + "\n\t\tself=" + std::string(myChild->getDDName(nmspace));
  53. throwError(msg);
  54. }
  55. // set the parameters for the algorithm
  56. // First for ParE type
  57. parE_type parE;
  58. for (size_t i = 0; i < myParE->size(); ++i)
  59. {
  60. atts = myParE->getAttributeSet(i);
  61. // find vname in ParE.
  62. parE_type::iterator existingName=parE.find(atts.find("name")->second);
  63. // if found, get std::vector, then add this value to it.
  64. // if not found, add this var, then add a value to it.
  65. if (existingName != parE.end())
  66. existingName->second.push_back(ev.eval(nmspace,atts.find("value")->second));
  67. // tvect = existingName->second;
  68. else
  69. {
  70. std::vector<double> tvect;
  71. tvect.push_back(ev.eval(nmspace,atts.find("value")->second));
  72. parE[atts.find("name")->second] = tvect;
  73. }
  74. }
  75. // Now for ParS type
  76. parS_type parS;
  77. for (size_t i = 0; i < myParS->size(); ++i)
  78. {
  79. atts = myParS->getAttributeSet(i);
  80. // find vname in ParS.
  81. parS_type::iterator existingName=parS.find(atts.find("name")->second);
  82. // if found, get std::vector, then add this value to it.
  83. // if not found, add this var, then add a value to it.
  84. if (existingName != parS.end())
  85. existingName->second.push_back(atts.find("value")->second);
  86. else
  87. {
  88. std::vector<std::string> tvect;
  89. tvect.push_back(atts.find("value")->second);
  90. parS[atts.find("name")->second] = tvect;
  91. }
  92. }
  93. algo.setParameters(st,ed,ic,parS,parE);
  94. // for efficiency, I do not want to make a DDAlgoPositioner every time this is called.
  95. // so DDCompactView must have a way to position inside itself as well.
  96. cpv.algoPosPart(self, parent, algo);
  97. // ap_(self, parent, algo);
  98. // clear all "children" and attributes
  99. myChild->clear();
  100. myParent->clear();
  101. myParS->clear();
  102. myParE->clear();
  103. // after an AlgoPosPart, we are sure it can be cleared.
  104. clear();
  105. DCOUT_V('P', "DDLAlgoPosPart::processElement completed");
  106. }