CMS 3D CMS Logo

DDLElementRegistry.cc
Go to the documentation of this file.
1 #include <stddef.h>
2 #include <algorithm>
3 #include <map>
4 #include <string>
5 #include <utility>
6 #include <vector>
7 
41 
43 {}
44 
46 {
47  // Complicated cleanup. I keep track of DDXMLElements that have
48  // already been deleted using this vector. Then delete them one-by-one.
49  std::vector<DDXMLElement*> toDelete;
50  for( RegistryMap::const_iterator it = registry_.begin(), end = registry_.end(); it != end; ++it )
51  {
52  std::vector<DDXMLElement*>::const_iterator deleteIt = std::find( toDelete.begin(), toDelete.end(), it->second );
53  if( deleteIt == toDelete.end())
54  {
55  toDelete.push_back( it->second );
56  delete it->second;
57  }
58  }
59 }
60 
61 // -------------------------------------------------------------------------
62 // Implementation
63 // -------------------------------------------------------------------------
66 {
67  RegistryMap::iterator it = registry_.find(name);
68  DDXMLElement* myret = NULL;
69  if( it != registry_.end())
70  {
71  myret = it->second;
72  } else {
73  // Make the Solid handlers and register them.
74  if (name == "Box")
75  {
76  myret = new DDLBox(this);
77  }
78  else if (name == "Cone")
79  {
80  myret = new DDLCone(this);
81  }
82  else if (name == "Polyhedra" || name == "Polycone")
83  {
84  myret = new DDLPolyGenerator(this);
85  }
86  else if (name == "Trapezoid" || name == "Trd1")
87  {
88  myret = new DDLTrapezoid(this);
89  }
90  else if (name == "PseudoTrap")
91  {
92  myret = new DDLPseudoTrap(this);
93  }
94  else if (name == "Tubs" || name == "CutTubs" || name == "Tube" || name == "TruncTubs")
95  {
96  myret = new DDLTubs(this);
97  }
98  else if (name == "Torus")
99  {
100  myret = new DDLTorus(this);
101  }
102  else if (name == "ReflectionSolid")
103  {
104  myret = new DDLReflectionSolid(this);
105  }
106  else if (name == "UnionSolid" || name == "SubtractionSolid"
107  || name == "IntersectionSolid")
108  {
109  myret = new DDLBooleanSolid(this);
110  }
111  else if (name == "ShapelessSolid")
112  {
113  myret = new DDLShapelessSolid(this);
114  }
115  else if (name == "Sphere")
116  {
117  myret = new DDLSphere(this);
118  }
119  else if (name == "Orb")
120  {
121  myret = new DDLOrb(this);
122  }
123  else if (name == "EllipticalTube")
124  {
125  myret = new DDLEllipticalTube(this);
126  }
127  else if (name == "Ellipsoid")
128  {
129  myret = new DDLEllipsoid(this);
130  }
131  else if (name == "Sphere")
132  {
133  myret = new DDLParallelepiped(this);
134  }
135 
136  // LogicalParts, Positioners, Materials, Rotations, Reflections
137  // and Specific (Specified?) Parameters
138  else if (name == "PosPart")
139  {
140  myret = new DDLPosPart(this);
141  }
142  else if (name == "CompositeMaterial")
143  {
144  myret = new DDLCompositeMaterial(this);
145  }
146  else if (name == "ElementaryMaterial")
147  {
148  myret = new DDLElementaryMaterial(this);
149  }
150  else if (name == "LogicalPart")
151  {
152  myret = new DDLLogicalPart(this);
153  }
154  else if (name == "ReflectionRotation" || name == "Rotation" )
155  {
156  myret = new DDLRotationAndReflection(this);
157  }
158  else if (name == "SpecPar")
159  {
160  myret = new DDLSpecPar(this);
161  }
162  else if (name == "RotationSequence")
163  {
164  myret = new DDLRotationSequence(this);
165  }
166  else if (name == "RotationByAxis")
167  {
168  myret = new DDLRotationByAxis(this);
169  }
170  // Special, need them around.
171  else if (name == "SpecParSection") {
172  myret = new DDXMLElement(this, true);
173  }
174  else if (name == "Vector") {
175  myret = new DDLVector(this);
176  }
177  else if (name == "Map") {
178  myret = new DDLMap(this);
179  }
180  else if (name == "String") {
181  myret = new DDLString(this);
182  }
183  else if (name == "Numeric") {
184  myret = new DDLNumeric(this);
185  }
186  else if (name == "Algorithm") {
187  myret = new DDLAlgorithm(this);
188  }
189  else if (name == "Division") {
190  myret = new DDLDivision(this);
191  }
192 
193  // Supporting Cast of elements.
194  // All elements which simply accumulate attributes which are then used
195  // by one of the above elements.
196  else if (name == "MaterialFraction"
197  || name == "RZPoint" || name == "PartSelector"
198  || name == "Parameter" || name == "ZSection"
199  || name == "Translation"
200  || name == "rSolid" || name == "rMaterial"
201  || name == "rParent" || name == "rChild"
202  || name == "rRotation" || name == "rReflectionRotation"
203  || name == "DDDefinition" )
204  {
205  myret = new DDXMLElement(this);
206  }
207 
208  // IF it is a new element return a default XMLElement which processes nothing.
209  // Since there are elements in the XML which require no processing, they
210  // can all use the same DDXMLElement which defaults to anything. A validated
211  // XML document (i.e. validated with XML Schema) will work properly.
212  // As of 8/16/2002: Elements like LogicalPartSection and any other *Section
213  // XML elements of the DDLSchema are taken care of by this.
214  else
215  {
216  myret = new DDXMLElement(this);
217  }
218 
219  // Actually register the thing
220  registry_[name] = myret;
221  }
222  return myret;
223 }
224 
225 const std::string&
227 {
228  for( RegistryMap::const_iterator it = registry_.begin(), end = registry_.end(); it != end; ++it )
229  if( it->second == theElement )
230  return it->first;
231  return registry_.find( "***" )->first;
232 }
233 
235 
DDLPosPart handles PosPart elements.
Definition: DDLPosPart.h:27
This class takes care of processing all BooleanSolid type elements.
DDLSphere processes all Sphere elements.
Definition: DDLSphere.h:24
DDLDivision processes Division elements.
Definition: DDLDivision.h:27
DDLOrb processes all Orb elements.
Definition: DDLOrb.h:23
DDLString handles String Elements.
Definition: DDLString.h:26
DDLVector handles Rotation and ReflectionRotation elements.
Definition: DDLVector.h:31
DDLReflectionSolid processes ReflectionSolid elements.
#define NULL
Definition: scimark2.h:8
DDLSpecPar processes SpecPar elements.
Definition: DDLSpecPar.h:26
DDLRotationAndReflection handles RotationCMSIM and ReflectionRotation elements.
DDLEllipticalTube processes all EllipticalTube elements.
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
DDLAlgorithm processes Algorithm elements.
Definition: DDLAlgorithm.h:25
DDLParallelepiped processes all Parallelepiped elements.
DDXMLElement * getElement(const std::string &name)
THE most important part. Getting the pointer to a given element type.
DDLBox processes Box elements.
Definition: DDLBox.h:27
DDLElementaryMaterial processes ElementaryMaterial elements.
DDLCone processes all Cone elements.
Definition: DDLCone.h:27
#define end
Definition: vmac.h:37
DDLEllipsoid processes all Ellipsoid elements.
Definition: DDLEllipsoid.h:24
DDLTubs processes Tubs elements.
Definition: DDLTubs.h:21
DDLPolyGenerator processes DDL XML Polycone and DDL XML Polyhedra elements.
DDLMap handles Map container.
Definition: DDLMap.h:63
DDLLogicalPart processes LogicalPart elements.
This is a base class for processing XML elements in the DDD.
Definition: DDXMLElement.h:48
DDLRotationByAxis handles RotationByAxis elements.
const std::string & getElementName(DDXMLElement *theElement) const
Get the name given a pointer. This may not be needed...
DDLCompositeMaterial processes all CompositeMaterial elements.
DDLNumeric handles Numeric Elements.
Definition: DDLNumeric.h:29
DDLRotationSequence handles a set of Rotations.
DDLShapelessSolid processes ShapelessSolid elements.