CMS 3D CMS Logo

DDDToPersFactory.cc

Go to the documentation of this file.
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 //#include <iostream>
00011 
00012 PSolid* DDDToPersFactory::solid ( const DDSolid& solid ) {
00013   //  std::cout << solid.name() << std::endl;
00014   switch (solid.shape()) 
00015     {
00016     case ddunion:
00017     case ddsubtraction:
00018     case ddintersection: 
00019       {      
00020         DDBooleanSolid boolSolid(solid);
00021         // if translation is == identity there are no parameters.
00022         // if there is no rotation the name will be ":"
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   //  std::cout << "got here!" << std::endl;
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       //    DCOUT('y', "  write-const-material=" << m.constituent(j).first.name());
00076       //      os << ' ';
00077       //      nameout(os,m.constituent(j).first.name());
00078       //      os << ' ' << m.constituent(j).second;
00079     }
00080     //    os << std::endl;
00081 
00082   return temp;
00083 }
00084 
00085 PRotation* DDDToPersFactory::rotation ( DDRotation& rotation ) {
00086   double tol = 1.0e-3; // Geant4 compatible
00087   DD3Vector x,y,z; 
00088   rotation.matrix()->GetComponents(x,y,z); 
00089   double check = (x.Cross(y)).Dot(z); // in case of a LEFT-handed orthogonal system 
00090   // this must be -1
00091   bool reflection((1.-check)>tol);
00092   std::string rotName=rotation.toString();
00093 //   DDRotation rotn(DDName("IDENTITYDB","generatedForDB"));
00094 //   if ( rotName == ":" ) {
00095 //     // build a name somehow this only happens once and IS the identity!
00096 //     std::cout << "DDDToPersFactory::rotation( ... ) with no name!" << std::endl;
00097 //   std::cout << "rotation named: " << rotName;
00098 //   std::cout << "          theta -------------- phi " << std::endl;
00099 //   std::cout << "x  " << (rotation.matrix()->thetaX())/deg << ", " << (rotation.matrix()->phiX())/deg << std::endl;
00100 //   std::cout << "y  " << (rotation.matrix()->thetaY())/deg << ", " << (rotation.matrix()->phiY())/deg << std::endl;
00101 //   std::cout << "z  " << (rotation.matrix()->thetaZ())/deg << ", " << (rotation.matrix()->phiZ())/deg << std::endl;
00102      //     rotName = rotn.toString();
00103 //   } else {
00104 //     //    std::cout << "Rotation name: " << rotName << std::endl;
00105 //   }
00106 //  std::cout << "okay, about to return a PRotation..." << std::endl;
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 // What is bad about this implementation is that the factory 
00121 // actually needs to know about the default Identity matrix :-(.
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     //    std::cout << "USING " << rotName << " for " << parent << " to " << child << std::endl;
00132 //   }  else if ( rotName != ":" ) {
00133 //     DDRotation rotn( DDName(edgeToChild->rot_.name().name(), edgeToChild->rot_.name().ns()) );
00134 //     if ( rotn.isValid() ) {
00135 //       //      rotName = rotn.toString();
00136 //       // rotName STAYS AS IS!
00137 //     } else {
00138 //       // MIKE: if I got no ELSE then get rid of this whole thing and ONLY keep the
00139 //       // next else as else if ( rotName == ":" );
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 //       std::cout << "generated... " << rotName << std::endl;
00150 //       std::cout << frot << std::endl;
00151 //       std::cout << "done displaying frot" << std::endl;
00152       pr = rotation( frot );
00153       geom.pRotations.push_back( *pr );
00154       rotName = frot.toString();
00155   }
00156 //   std::cout << parent.toString() << " " << child.toString() << " " << rotName << std::endl;
00157 //   std::cout << "about to write edgeToChild..." << std::endl;
00158 //   std::cout << edgeToChild->translation().x() << std::endl;
00159 //   std::cout << edgeToChild->translation().y() << std::endl;
00160 //   std::cout << edgeToChild->translation().z() << std::endl;
00161 //   std::cout << edgeToChild->copyno_ << std::endl;
00162 //   std::cout << "done writing edgeToChild..." << std::endl;
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   //  std::cout << "Entering  DDDToPersFactory::specpar " << sp.toString() << std::endl;
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   // ========... copy all the selection strings out as strings by using the DDPartSelection's ostream function...
00183   for (; sit != sed; ++sit) {
00184     std::ostringstream selStringStream;
00185     selStringStream << *sit;
00186     psp->pSpecSelections.push_back ( selStringStream.str() );
00187     //    std::cout << "selection " << selStringStream.str() << std::endl;
00188   }
00189   // =========  ... and iterate over all DDValues...
00190   //  std::cout << "About to iterate over DDValues " << std::endl;
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     //    std::cout << " make entry with name " << v.name();
00195     psp->newSpecParEntry ( pstrs(v.name()), v.isEvaluated() );
00196     size_t s=v.size();
00197     //    std::cout << " and size " << v.size() << std::endl;
00198     size_t i=0;
00199     // ============  ... and copy all actual values with the same name
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     //std::cout << sp.toString() << " variable name " << v.name() << " set evaluated to 0 (false) " << std::endl;
00212   }
00213   return psp;
00214 }
00215 

Generated on Tue Jun 9 17:32:25 2009 for CMSSW by  doxygen 1.5.4