CMS 3D CMS Logo

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