00001 /*************************************************************************** 00002 DDLElementRegistry.cc - description 00003 ------------------- 00004 begin : Wed Oct 24 2001 00005 email : case@ucdhep.ucdavis.edu 00006 ***************************************************************************/ 00007 00008 /*************************************************************************** 00009 * * 00010 * DDDParser sub-component of DDD * 00011 * Nov 25, 2003 : note that comments on DDLRotation are for future * 00012 * changes which break backward compatibility. * 00013 * * 00014 ***************************************************************************/ 00015 00016 00017 00018 // ------------------------------------------------------------------------- 00019 // Includes 00020 // ------------------------------------------------------------------------- 00021 // DDL parts 00022 #include "DDLAlgorithm.h" 00023 #include "DDLAlgoPosPart.h" 00024 #include "DDLBooleanSolid.h" 00025 #include "DDLBox.h" 00026 #include "DDLCompositeMaterial.h" 00027 #include "DDLCone.h" 00028 #include "DDLDivision.h" 00029 #include "DDLElementRegistry.h" 00030 #include "DDLElementaryMaterial.h" 00031 #include "DDLLogicalPart.h" 00032 #include "DDLMap.h" 00033 #include "DDLNumeric.h" 00034 #include "DDLPolyGenerator.h" 00035 #include "DDLPosPart.h" 00036 #include "DDLPseudoTrap.h" 00037 #include "DDLReflectionSolid.h" 00038 #include "DDLRotationByAxis.h" 00039 #include "DDLRotationAndReflection.h" 00040 #include "DDLRotationSequence.h" 00041 #include "DDLShapelessSolid.h" 00042 #include "DDLSpecPar.h" 00043 #include "DDLString.h" 00044 #include "DDLTorus.h" 00045 #include "DDLTrapezoid.h" 00046 #include "DDLTubs.h" 00047 #include "DDLVector.h" 00048 #include "DDXMLElementRegistry.h" 00049 #include "DDXMLElement.h" 00050 00051 // DDCore dependencies 00052 #include "DetectorDescription/Base/interface/DDdebug.h" 00053 00054 #include <string> 00055 #include <iostream> 00056 00057 // ------------------------------------------------------------------------- 00058 // Static member initialization 00059 // ------------------------------------------------------------------------- 00060 //DDLElementRegistry* DDLElementRegistry::instance_ = 0; 00061 00062 // Note that an XML element can not be all spaces or all asterisks, etc. :-) 00063 // so we are safe to use this. 00064 //std::string DDLElementRegistry::defaultElement_ = "*****"; 00065 00066 // ------------------------------------------------------------------------- 00067 // Constructor/Destructor 00068 // ------------------------------------------------------------------------- 00069 00070 DDLElementRegistry::DDLElementRegistry() 00071 { } 00072 00073 DDLElementRegistry::~DDLElementRegistry() { 00074 00075 } 00076 00077 // ------------------------------------------------------------------------- 00078 // Implementation 00079 // ------------------------------------------------------------------------- 00080 00081 // This initializes and acts as the singleton instance of DDLElementRegistry. 00082 DDLElementRegistry* DDLElementRegistry::instance() 00083 { 00084 static DDLElementRegistry reg; 00085 static bool isInit=false; 00086 if (!isInit) { 00087 isInit=true; 00088 instance()->registerElement("***", new DDXMLElement); 00089 } 00090 return ® 00091 /* 00092 if (instance_ == 0) 00093 { 00094 instance_ = new DDLElementRegistry; 00095 00096 DDXMLElement* defaultElement = new DDXMLElement; 00097 instance()->registerElement(defaultElement_, defaultElement); 00098 } 00099 return instance_; 00100 */ 00101 } 00102 00103 DDXMLElement* DDLElementRegistry::getElement(const std::string& name) 00104 { 00105 DCOUT_V('P',"DDLElementRegistry::getElementRegistry(" << name << ")"); 00106 00107 DDXMLElement* myret = instance()->DDXMLElementRegistry::getElement(name); 00108 00109 if (myret == NULL) 00110 { 00111 00112 // Make the Solid handlers and register them. 00113 if (name == "Box") 00114 { 00115 myret = new DDLBox; 00116 } 00117 else if (name == "Cone") 00118 { 00119 myret = new DDLCone; 00120 } 00121 else if (name == "Polyhedra" || name == "Polycone") 00122 { 00123 myret = new DDLPolyGenerator; 00124 } 00125 else if (name == "Trapezoid" || name == "Trd1") 00126 { 00127 myret = new DDLTrapezoid; 00128 } 00129 else if (name == "PseudoTrap") 00130 { 00131 myret = new DDLPseudoTrap; 00132 } 00133 else if (name == "Tubs" || name == "Tube" || name == "TruncTubs") 00134 { 00135 myret = new DDLTubs; 00136 } 00137 else if (name == "Torus") 00138 { 00139 myret = new DDLTorus; 00140 } 00141 else if (name == "ReflectionSolid") 00142 { 00143 myret = new DDLReflectionSolid; 00144 } 00145 else if (name == "UnionSolid" || name == "SubtractionSolid" 00146 || name == "IntersectionSolid") 00147 { 00148 myret = new DDLBooleanSolid; 00149 } 00150 else if (name == "ShapelessSolid") 00151 { 00152 myret = new DDLShapelessSolid; 00153 } 00154 00155 // LogicalParts, Positioners, Materials, Rotations, Reflections 00156 // and Specific (Specified?) Parameters 00157 else if (name == "PosPart") 00158 { 00159 myret = new DDLPosPart; 00160 } 00161 else if (name == "AlgoPosPart") 00162 { 00163 myret = new DDLAlgoPosPart; 00164 } 00165 else if (name == "CompositeMaterial") 00166 { 00167 myret = new DDLCompositeMaterial; 00168 } 00169 else if (name == "ElementaryMaterial") 00170 { 00171 myret = new DDLElementaryMaterial; 00172 } 00173 else if (name == "LogicalPart") 00174 { 00175 myret = new DDLLogicalPart; 00176 } 00177 else if (name == "ReflectionRotation" || name == "Rotation" ) 00178 { 00179 myret = new DDLRotationAndReflection; 00180 } 00181 else if (name == "SpecPar") 00182 { 00183 myret = new DDLSpecPar; 00184 } 00185 else if (name == "RotationSequence") 00186 { 00187 myret = new DDLRotationSequence; 00188 } 00189 else if (name == "RotationByAxis") 00190 { 00191 myret = new DDLRotationByAxis; 00192 } 00193 // Special, need them around. 00194 else if (name == "SpecParSection") { 00195 myret = new DDXMLElement(true); 00196 } 00197 else if (name == "Vector") { 00198 myret = new DDLVector; 00199 } 00200 else if (name == "Map") { 00201 myret = new DDLMap; 00202 } 00203 else if (name == "String") { 00204 myret = new DDLString; 00205 } 00206 else if (name == "Numeric") { 00207 myret = new DDLNumeric; 00208 } 00209 else if (name == "Algorithm") { 00210 myret = new DDLAlgorithm; 00211 } 00212 else if (name == "Division") { 00213 myret = new DDLDivision; 00214 } 00215 00216 // Supporting Cast of elements. 00217 // All elements which simply accumulate attributes which are then used 00218 // by one of the above elements. 00219 else if (name == "MaterialFraction" || name == "ParE" || name == "ParS" 00220 || name == "RZPoint" || name == "PartSelector" 00221 || name == "Parameter" || name == "ZSection" 00222 || name == "Translation" 00223 || name == "rSolid" || name == "rMaterial" 00224 || name == "rParent" || name == "rChild" 00225 || name == "rRotation" || name == "rReflectionRotation" 00226 || name == "DDDefinition" ) 00227 { 00228 myret = new DDXMLElement; 00229 } 00230 00231 00232 // IF it is a new element return a default XMLElement which processes nothing. 00233 // Since there are elements in the XML which require no processing, they 00234 // can all use the same DDXMLElement which defaults to anything. A validated 00235 // XML document (i.e. validated with XML Schema) will work properly. 00236 // As of 8/16/2002: Elements like LogicalPartSection and any other *Section 00237 // XML elements of the DDLSchema are taken care of by this. 00238 else 00239 { 00240 myret = instance()->DDXMLElementRegistry::getElement("***"); 00241 DCOUT_V('P', "WARNING: The default (DDLElementRegistry) was used for " 00242 << name << " since there was no specific handler." << std::endl); 00243 } 00244 00245 // Actually register the thing 00246 instance()->registerElement(name, myret); 00247 } 00248 00249 return myret; 00250 }