CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DDLElementRegistry.cc
Go to the documentation of this file.
1 /***************************************************************************
2  DDLElementRegistry.cc - description
3  -------------------
4  begin : Wed Oct 24 2001
5  email : case@ucdhep.ucdavis.edu
6  ***************************************************************************/
7 
8 /***************************************************************************
9  * *
10  * DDDParser sub-component of DDD *
11  * Nov 25, 2003 : note that comments on DDLRotation are for future *
12  * changes which break backward compatibility. *
13  * *
14  ***************************************************************************/
15 
46 
49 
50 #include <iostream>
51 
53 {}
54 
56 {
57  // Complicated cleanup. I keep track of DDXMLElements that have
58  // already been deleted using this vector. Then delete them one-by-one.
59  std::vector<DDXMLElement*> toDelete;
60  for( RegistryMap::const_iterator it = registry_.begin(), end = registry_.end(); it != end; ++it )
61  {
62  std::vector<DDXMLElement*>::const_iterator deleteIt = std::find( toDelete.begin(), toDelete.end(), it->second );
63  if( deleteIt == toDelete.end())
64  {
65  toDelete.push_back( it->second );
66  delete it->second;
67  }
68  }
69 }
70 
71 // -------------------------------------------------------------------------
72 // Implementation
73 // -------------------------------------------------------------------------
76 {
77  DCOUT_V('P',"myRegistry_->getElementRegistry(" << name << ")");
78 
79  // DDXMLElement* myret = instance()->DDXMLElementRegistry::getElement(name);
80  RegistryMap::iterator it = registry_.find(name);
81  // std::cout << "it found name? "<< name << " " ;
82  // if (it != registry_.end() ) std::cout << "yes"; else std::cout << "no";
83  // std::cout << std::endl;
84  // std::cout << "there are " << registry_.size() << " elements-types so far." << std::endl;
85  DDXMLElement* myret = NULL;
86  if( it != registry_.end())
87  {
88  myret = it->second;
89  } else {
90  // std::cout << " making first and only " << name << std::endl;
91  // Make the Solid handlers and register them.
92  if (name == "Box")
93  {
94  myret = new DDLBox(this);
95  }
96  else if (name == "Cone")
97  {
98  myret = new DDLCone(this);
99  }
100  else if (name == "Polyhedra" || name == "Polycone")
101  {
102  myret = new DDLPolyGenerator(this);
103  }
104  else if (name == "Trapezoid" || name == "Trd1")
105  {
106  myret = new DDLTrapezoid(this);
107  }
108  else if (name == "PseudoTrap")
109  {
110  myret = new DDLPseudoTrap(this);
111  }
112  else if (name == "Tubs" || name == "Tube" || name == "TruncTubs")
113  {
114  myret = new DDLTubs(this);
115  }
116  else if (name == "Torus")
117  {
118  myret = new DDLTorus(this);
119  }
120  else if (name == "ReflectionSolid")
121  {
122  myret = new DDLReflectionSolid(this);
123  }
124  else if (name == "UnionSolid" || name == "SubtractionSolid"
125  || name == "IntersectionSolid")
126  {
127  myret = new DDLBooleanSolid(this);
128  }
129  else if (name == "ShapelessSolid")
130  {
131  myret = new DDLShapelessSolid(this);
132  }
133  else if (name == "Sphere")
134  {
135  myret = new DDLSphere(this);
136  }
137  else if (name == "Orb")
138  {
139  myret = new DDLOrb(this);
140  }
141  else if (name == "EllipticalTube")
142  {
143  myret = new DDLEllipticalTube(this);
144  }
145  else if (name == "Ellipsoid")
146  {
147  myret = new DDLEllipsoid(this);
148  }
149  else if (name == "Sphere")
150  {
151  myret = new DDLParallelepiped(this);
152  }
153 
154  // LogicalParts, Positioners, Materials, Rotations, Reflections
155  // and Specific (Specified?) Parameters
156  else if (name == "PosPart")
157  {
158  myret = new DDLPosPart(this);
159  }
160  else if (name == "AlgoPosPart")
161  {
162  myret = new DDLAlgoPosPart(this);
163  }
164  else if (name == "CompositeMaterial")
165  {
166  myret = new DDLCompositeMaterial(this);
167  }
168  else if (name == "ElementaryMaterial")
169  {
170  myret = new DDLElementaryMaterial(this);
171  }
172  else if (name == "LogicalPart")
173  {
174  myret = new DDLLogicalPart(this);
175  }
176  else if (name == "ReflectionRotation" || name == "Rotation" )
177  {
178  myret = new DDLRotationAndReflection(this);
179  }
180  else if (name == "SpecPar")
181  {
182  myret = new DDLSpecPar(this);
183  }
184  else if (name == "RotationSequence")
185  {
186  myret = new DDLRotationSequence(this);
187  }
188  else if (name == "RotationByAxis")
189  {
190  myret = new DDLRotationByAxis(this);
191  }
192  // Special, need them around.
193  else if (name == "SpecParSection") {
194  myret = new DDXMLElement(this, true);
195  }
196  else if (name == "Vector") {
197  myret = new DDLVector(this);
198  }
199  else if (name == "Map") {
200  myret = new DDLMap(this);
201  }
202  else if (name == "String") {
203  myret = new DDLString(this);
204  }
205  else if (name == "Numeric") {
206  myret = new DDLNumeric(this);
207  }
208  else if (name == "Algorithm") {
209  myret = new DDLAlgorithm(this);
210  }
211  else if (name == "Division") {
212  myret = new DDLDivision(this);
213  }
214 
215  // Supporting Cast of elements.
216  // All elements which simply accumulate attributes which are then used
217  // by one of the above elements.
218  else if (name == "MaterialFraction" || name == "ParE" || name == "ParS"
219  || name == "RZPoint" || name == "PartSelector"
220  || name == "Parameter" || name == "ZSection"
221  || name == "Translation"
222  || name == "rSolid" || name == "rMaterial"
223  || name == "rParent" || name == "rChild"
224  || name == "rRotation" || name == "rReflectionRotation"
225  || name == "DDDefinition" )
226  {
227  myret = new DDXMLElement(this);
228  }
229 
230  // IF it is a new element return a default XMLElement which processes nothing.
231  // Since there are elements in the XML which require no processing, they
232  // can all use the same DDXMLElement which defaults to anything. A validated
233  // XML document (i.e. validated with XML Schema) will work properly.
234  // As of 8/16/2002: Elements like LogicalPartSection and any other *Section
235  // XML elements of the DDLSchema are taken care of by this.
236  else
237  {
238  // myret = instance()->DDXMLElementRegistry::getElement("***");
239 
240  myret = new DDXMLElement(this);
241  // std::cout << "about to register a " << "***" << std::endl;
242  // registry_["***"] = myret;
243  // DCOUT_V('P', "WARNING: The default (DDLElementRegistry) was used for "
244  // << name << " since there was no specific handler." << std::endl);
245  // return myret;
246  }
247 
248  // Actually register the thing
249  // instance()->registerElement(name, myret);
250  // std::cout << "about to register a " << name << std::endl;
251  registry_[name] = myret;
252  }
253  return myret;
254 }
255 
256 const std::string&
258 {
259  for( RegistryMap::const_iterator it = registry_.begin(), end = registry_.end(); it != end; ++it )
260  if( it->second == theElement )
261  return it->first;
262  return registry_.find( "***" )->first;
263 }
264 
266 
DDLPosPart handles PosPart elements.
Definition: DDLPosPart.h:24
This class takes care of processing all BooleanSolid type elements.
DDLElementRegistry()
Constructor.
DDLSphere processes all Sphere elements.
Definition: DDLSphere.h:24
DDLDivision processes Division elements.
Definition: DDLDivision.h:23
DDLOrb processes all Orb elements.
Definition: DDLOrb.h:24
~DDLElementRegistry()
Destructor.
DDLString handles String Elements.
Definition: DDLString.h:26
DDLVector handles Rotation and ReflectionRotation elements.
Definition: DDLVector.h:31
DDLReflectionSolid processes ReflectionSolid elements.
DDLAlgoPosPart handles AlgoPosPart elements.
#define NULL
Definition: scimark2.h:8
DDLSpecPar processes SpecPar elements.
Definition: DDLSpecPar.h:23
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:22
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:24
DDLElementaryMaterial processes ElementaryMaterial elements.
DDLCone processes all Cone elements.
Definition: DDLCone.h:24
#define end
Definition: vmac.h:38
DDLEllipsoid processes all Ellipsoid elements.
Definition: DDLEllipsoid.h:24
DDLTubs processes Tubs elements.
Definition: DDLTubs.h:22
DDLPolyGenerator processes DDL XML Polycone and DDL XML Polyhedra elements.
#define DCOUT_V(M_v_Y, M_v_S)
Definition: DDdebug.h:54
DDLMap handles Map container.
Definition: DDLMap.h:58
DDLLogicalPart processes LogicalPart elements.
This is a base class for processing XML elements in the DDD.
Definition: DDXMLElement.h:58
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:26
DDLRotationSequence handles a set of Rotations.
DDLShapelessSolid processes ShapelessSolid elements.