PageRenderTime 18ms CodeModel.GetById 6ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

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