CMS 3D CMS Logo

DDLPosPart.cc
Go to the documentation of this file.
2 
3 #include <map>
4 #include <utility>
5 
16 
18  : DDXMLElement( myreg )
19 {}
20 
21 // Upon encountering a PosPart, store the label, simple.
22 // Just in case some left-over Rotation has not been cleared, make sure
23 // that it is cleared.
24 // I commented out the others because the last element
25 // that made use of them should have cleared them.
26 void
28 {
29  // Clear out child elements.
30  myRegistry_->getElement("Rotation")->clear();
31  myRegistry_->getElement("ReflectionRotation")->clear();
32 }
33 
34 // Upon encountering the end tag of the PosPart we should have in the meantime
35 // hit two rLogicalPart calls and one of Rotation or rRotation and a Translation.
36 // So, retrieve them and make the call to DDCore.
37 void
39 {
40  // get all internal elements.
41  auto myParent = myRegistry_->getElement("rParent");
42  auto myChild = myRegistry_->getElement("rChild");
43  auto myTranslation= myRegistry_->getElement("Translation");
44  auto myDDLRotation= myRegistry_->getElement("Rotation");
45  auto myrRotation = myRegistry_->getElement("rRotation");
46  auto myDDLRefl = myRegistry_->getElement("ReflectionRotation");
47  auto myrRefl = myRegistry_->getElement("rReflectionRotation");
48  // FIXME!!! add in the new RotationByAxis element...
49 
50  // At this time, PosPart is becoming the most complex of the elements.
51  // For simply reflections/rotations we have 4 possible internal "components"
52  // to the PosPart. We take them in the following order of priority
53  // rRotation, Rotation, rReflectionRotation, ReflectionRotation.
54  //
55  // The idea in the following if-else-if is that no matter
56  // what was used inside the PosPart element, the order in which we
57  // will look for and use an internal element is:
58  // rRotation, Rotation, ReflectionRotation, rReflectionRotation.
59  // If it falls through here, a default call will result in a nameless
60  // "identity" rotation being passed to DDCore.
61  DDName rotn;
62  if (myrRotation->size() > 0){
63  rotn = myrRotation->getDDName(nmspace);
64  }
65  else if (myDDLRotation->size() > 0) {
66  // The assumption here is that the Rotation element created
67  // a DDRotation already, and so we can use this as an rRotation
68  // just provide DDCore with the name of the one just added...
69  // How to handle name conflicts? OVERWRITTEN by DDCore for now.
70  rotn = myDDLRotation->getDDName(nmspace);
71  }
72  else if (myDDLRefl->size() > 0) {
73  // The assumption is that a ReflectionRotation has been created and therefore
74  // we can refer to it as the rotation associated with this PosPart.
75  // we can further assume that the namespace is the same as this PosPart.
76  rotn = myDDLRefl->getDDName(nmspace);
77  }
78  else if (myrRefl->size() > 0) {
79  rotn = myrRefl->getDDName(nmspace);
80  }
81 
83 
84  double x = 0.0, y = 0.0, z = 0.0;
85  if (myTranslation->size() > 0)
86  {
87  const DDXMLAttribute & atts = myTranslation->getAttributeSet();
88  x = ev.eval(nmspace, atts.find("x")->second);
89  y = ev.eval(nmspace, atts.find("y")->second);
90  z = ev.eval(nmspace, atts.find("z")->second);
91  }
92 
93  DDRotation* myDDRotation;
94  // if rotation is named ...
95  if ( rotn.name() != "" && rotn.ns() != "" ) {
96  DDRotation temp(rotn);
97  myDDRotation = &temp;
98  } else {
99  // rotn is not assigned a name anywhere therefore the DDPos assumes the identity matrix.
100  DDRotation temp(DDName(std::string("identity"),std::string("generatedForDDD")));
101  myDDRotation = &temp;
102  // if the identity is not yet defined, then...
103  if ( !myDDRotation->isValid() ) {
105  temp = DDrot(DDName(std::string("identity"),std::string("generatedForDDD")), dmr );
106  myDDRotation = &temp;
107  }
108  }
109 
110 
111  DDTranslation myDDTranslation(x, y, z);
112 
113  const DDXMLAttribute & atts = getAttributeSet();
114  std::string copyno = "";
115  if (atts.find("copyNumber") != atts.end())
116  copyno = atts.find("copyNumber")->second;
117 
118  cpv.position(DDLogicalPart(myChild->getDDName(nmspace))
119  , DDLogicalPart(myParent->getDDName(nmspace))
120  , copyno
121  , myDDTranslation
122  , *myDDRotation);
123 
124  // clear all "children" and attributes
125  myParent->clear();
126  myChild->clear();
127  myTranslation->clear();
128  myDDLRotation->clear();
129  myrRotation->clear();
130  myDDLRefl->clear();
131  myrRefl->clear();
132 
133  // after a pos part is done, we know we can clear it.
134  clear();
135 }
void preProcessElement(const std::string &name, const std::string &nmspace, DDCompactView &cpv) override
Called by loadAttributes AFTER attributes are loaded.
Definition: DDLPosPart.cc:27
DDLElementRegistry * myRegistry_
Definition: DDXMLElement.h:172
virtual const DDXMLAttribute & getAttributeSet(size_t aIndex=0) const
Get a "row" of attributes, i.e. one attribute set.
Definition: DDXMLElement.cc:73
void position(const DDLogicalPart &self, const DDLogicalPart &parent, std::string copyno, const DDTranslation &trans, const DDRotation &rot, const DDDivision *div=NULL)
const std::string & ns() const
Returns the namespace.
Definition: DDName.cc:104
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:16
bool ev
type of data representation of DDCompactView
Definition: DDCompactView.h:90
std::map< std::string, std::string > DDXMLAttribute
Definition: DDXMLElement.h:45
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
Represents a uniquely identifyable rotation matrix.
Definition: DDTransform.h:64
bool isValid() const
true, if the wrapped pointer is valid
Definition: DDBase.h:119
ClhepEvaluator & evaluator()
void processElement(const std::string &name, const std::string &nmspace, DDCompactView &cpv) override
Processing the element.
Definition: DDLPosPart.cc:38
DDLPosPart(DDLElementRegistry *myreg)
Definition: DDLPosPart.cc:17
std::shared_ptr< DDXMLElement > getElement(const std::string &name)
THE most important part. Getting the pointer to a given element type.
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:92
DDRotation DDrot(const DDName &name, DDRotationMatrix *rot)
Definition of a uniquely identifiable rotation matrix named by DDName name.
Definition: DDRotation.cc:90
This is a base class for processing XML elements in the DDD.
Definition: DDXMLElement.h:48
double eval(const std::string &ns, const std::string &expr)
The main class for processing parsed elements.
virtual void clear(void)
clear this element&#39;s contents.
Definition: DDXMLElement.cc:55
ROOT::Math::Rotation3D DDRotationMatrix
A DDRotationMatrix is currently implemented with a ROOT Rotation3D.
const std::string & name() const
Returns the name.
Definition: DDName.cc:90