00001 #include <DetectorDescription/PersistentDDDObjects/interface/DDDToPersFactory.h>
00002
00003 #include <DetectorDescription/Core/interface/DDSolid.h>
00004 #include <DetectorDescription/Core/interface/DDMaterial.h>
00005
00006 #include <DetectorDescription/Core/interface/DDSpecifics.h>
00007 #include <DetectorDescription/Core/interface/DDPartSelection.h>
00008
00009 #include <sstream>
00010
00011
00012 PSolid* DDDToPersFactory::solid ( const DDSolid& solid ) {
00013
00014 switch (solid.shape())
00015 {
00016 case ddunion:
00017 case ddsubtraction:
00018 case ddintersection:
00019 {
00020 DDBooleanSolid boolSolid(solid);
00021
00022
00023 std::string rotName = boolSolid.rotation().toString();
00024 if (rotName == ":") {
00025 rotName = "generatedForDB:IDENTITYDB";
00026 }
00027 return new PSolid( pstrs(boolSolid.toString())
00028 , boolSolid.parameters()
00029 , boolSolid.shape()
00030 , pstrs(boolSolid.solidA().toString())
00031 , pstrs(boolSolid.solidB().toString())
00032 , pstrs(rotName) );
00033 break;
00034 }
00035 case ddreflected:
00036 {
00037 DDReflectionSolid ref(solid);
00038 return new PSolid( pstrs(ref.unreflected().toString()), solid.parameters()
00039 , solid.shape(), pstrs(""), pstrs(""), pstrs(""), true);
00040 break;
00041 }
00042 case ddbox:
00043 case ddtubs:
00044 case ddtrap:
00045 case ddcons:
00046 case ddpolycone_rz:
00047 case ddpolyhedra_rz:
00048 case ddpolycone_rrz:
00049 case ddpolyhedra_rrz:
00050 case ddpseudotrap:
00051 case ddtrunctubs:
00052 case ddshapeless:
00053 case ddtorus:
00054 return new PSolid( pstrs(solid.toString()), solid.parameters()
00055 , solid.shape(), pstrs(""), pstrs(""), pstrs("") );
00056 break;
00057
00058 case dd_not_init:
00059 default:
00060 throw DDException("DDDToPersFactory::solid(...) either not inited or no such solid.");
00061 break;
00062 }
00063 return 0;
00064 }
00065
00066 PMaterial* DDDToPersFactory::material ( const DDMaterial& material ) {
00067
00068 PMaterial* temp = new PMaterial( pstrs(material.toString()), material.density()
00069 , material.z(), material.a() );
00070 int noc = material.noOfConstituents();
00071 int j=0;
00072 for (; j<noc; ++j) {
00073 temp->addConstituent ( pstrs(material.constituent(j).first.toString())
00074 , material.constituent(j).second );
00075
00076
00077
00078
00079 }
00080
00081
00082 return temp;
00083 }
00084
00085 PRotation* DDDToPersFactory::rotation ( DDRotation& rotation ) {
00086 double tol = 1.0e-3;
00087 DD3Vector x,y,z;
00088 rotation.matrix()->GetComponents(x,y,z);
00089 double check = (x.Cross(y)).Dot(z);
00090
00091 bool reflection((1.-check)>tol);
00092 std::string rotName=rotation.toString();
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107 return new PRotation( pstrs(rotName)
00108 , x.theta(), x.phi()
00109 , y.theta(), y.phi()
00110 , z.theta(), z.phi()
00111 , reflection );
00112 }
00113
00114 PLogicalPart* DDDToPersFactory::logicalPart ( const DDLogicalPart& lp ) {
00115 return new PLogicalPart( pstrs(lp.toString())
00116 , pstrs(lp.solid().toString())
00117 , pstrs(lp.material().toString()) );
00118 }
00119
00120
00121
00122 PPosPart* DDDToPersFactory::position ( const DDLogicalPart& parent
00123 , const DDLogicalPart& child
00124 , DDPosData* edgeToChild
00125 , PIdealGeometry& geom
00126 , int& rotNameSeed ) {
00127 std::string rotName = edgeToChild->rot_.toString();
00128 DDRotationMatrix myIDENT;
00129 if ( *(edgeToChild->rot_.matrix()) == myIDENT ) {
00130 rotName = "generatedForDB:IDENTITYDB";
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141 } else if ( rotName == ":" ) {
00142 std::ostringstream namestr;
00143 namestr << "rotName" << rotNameSeed;
00144 ++rotNameSeed;
00145 rotName = namestr.str();
00146 DDRotationMatrix* dmr = new DDRotationMatrix( *edgeToChild->rot_.matrix() );
00147 DDRotation frot = DDrot ( DDName ( rotName, "generatedForDB" ), dmr );
00148 PRotation* pr;
00149
00150
00151
00152 pr = rotation( frot );
00153 geom.pRotations.push_back( *pr );
00154 rotName = frot.toString();
00155 }
00156
00157
00158
00159
00160
00161
00162
00163 return new PPosPart( pstrs(parent.toString())
00164 , pstrs(child.toString())
00165 , pstrs(rotName)
00166 , edgeToChild->translation().x()
00167 , edgeToChild->translation().y()
00168 , edgeToChild->translation().z()
00169 , edgeToChild->copyno_
00170 );
00171 }
00172
00173
00174 PSpecPar* DDDToPersFactory::specpar ( const DDSpecifics& sp ) {
00175
00176
00177 PSpecPar* psp = new PSpecPar();
00178 psp->pName = pstrs(sp.toString());
00179
00180 std::vector<DDPartSelection>::const_iterator sit(sp.selection().begin()), sed(sp.selection().end());
00181
00182
00183 for (; sit != sed; ++sit) {
00184 std::ostringstream selStringStream;
00185 selStringStream << *sit;
00186 psp->pSpecSelections.push_back ( selStringStream.str() );
00187
00188 }
00189
00190
00191 DDsvalues_type::const_iterator vit(sp.specifics().begin()), ved(sp.specifics().end());
00192 for (; vit != ved; ++vit) {
00193 const DDValue & v = vit->second;
00194
00195 psp->newSpecParEntry ( pstrs(v.name()), v.isEvaluated() );
00196 size_t s=v.size();
00197
00198 size_t i=0;
00199
00200 const std::vector<std::string>& strvec = v.strings();
00201 if ( v.isEvaluated() ) {
00202 for (; i<s; ++i) {
00203 psp->addToCurrentSpecPar ( pstrs(strvec[i]), v[i] );
00204 }
00205 } else {
00206 for (; i<s; ++i ) {
00207 psp->addToCurrentSpecPar ( pstrs(strvec[i]) );
00208 }
00209 }
00210
00211
00212 }
00213 return psp;
00214 }
00215