CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DDLAlgoPosPart.cc
Go to the documentation of this 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 
15 
21 
23 
24 #include <iostream>
25 
27  : DDXMLElement( myreg )
28 {}
29 
31 {}
32 
33 // Upon encountering the end tag of the AlgoPosPart we should have in the meantime
34 // hit rParent, rChild, ParS and ParE.
35 void
36 DDLAlgoPosPart::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 
47 
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 
int i
Definition: DBlmapReader.cc:9
def_type isDefined() const
Definition: DDBase.h:115
DDLElementRegistry * myRegistry_
Definition: DDXMLElement.h:186
void algoPosPart(const DDLogicalPart &self, const DDLogicalPart &parent, DDAlgo &algo)
positioning...
virtual const DDXMLAttribute & getAttributeSet(size_t aIndex=0) const
Get a &quot;row&quot; of attributes, i.e. one attribute set.
Definition: DDXMLElement.cc:79
void throwError(const std::string &keyMessage) const
format std::string for throw an error.
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:18
Definition: DDAlgo.h:21
const std::string & parent(void) const
access to parent element name
type of data representation of DDCompactView
Definition: DDCompactView.h:77
std::map< std::string, std::string > DDXMLAttribute
Definition: DDXMLElement.h:55
DDXMLElement * getElement(const std::string &name)
THE most important part. Getting the pointer to a given element type.
static value_type & instance()
DDLAlgoPosPart(DDLElementRegistry *myreg)
Constructor.
~DDLAlgoPosPart()
Destructor.
virtual size_t size(void) const
Number of elements accumulated.
std::map< std::string, std::vector< std::string > > parS_type
Definition: DDAlgoPar.h:9
Interface of an Expression Evaluator.
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:88
void processElement(const std::string &name, const std::string &nmspace, DDCompactView &cpv)
Processing the element.
#define DCOUT_V(M_v_Y, M_v_S)
Definition: DDdebug.h:54
virtual double eval(const std::string &ns, const std::string &expr)=0
evaluate an expression expr inside the local namespace
This is a base class for processing XML elements in the DDD.
Definition: DDXMLElement.h:58
The main class for processing parsed elements.
virtual void clear(void)
clear this element&#39;s contents.
Definition: DDXMLElement.cc:61
void setParameters(int start, int end, int incr, const parS_type &, const parE_type &)
Definition: DDAlgo.cc:42
LimitAlgo * algo
Definition: Combine.cc:60
virtual const DDName getDDName(const std::string &defaultNS, const std::string &attname=std::string("name"), size_t aIndex=0)
Definition: DDXMLElement.cc:86
std::map< std::string, std::vector< double > > parE_type
Definition: DDAlgoPar.h:12