CMS 3D CMS Logo

DDPersToDDDFactory.cc

Go to the documentation of this file.
00001 #include <DetectorDescription/PersistentDDDObjects/interface/DDPersToDDDFactory.h>
00002 #include <CondFormats/IdealGeometryObjects/interface/PersistentDDDObjects.h>
00003 
00004 #include <DetectorDescription/Base/interface/DDException.h>
00005 #include <DetectorDescription/Core/interface/DDSolid.h>
00006 #include <DetectorDescription/Core/interface/DDSolidShapes.h>
00007 #include <DetectorDescription/Core/interface/DDPosPart.h>
00008 #include <DetectorDescription/Core/interface/DDMaterial.h>
00009 #include <DetectorDescription/Core/interface/DDRoot.h>
00010 #include <DetectorDescription/Core/interface/DDSpecifics.h>
00011 
00012 #include <iostream>
00013 #include <vector>
00014 #include <algorithm>
00015 
00016 namespace std { } using namespace std;
00017   
00018 DDSolid DDPersToDDDFactory::solid ( const PSolid* sol ) {
00019   return solid ( *sol );
00020 }
00021 
00022 DDMaterial DDPersToDDDFactory::material ( const PMaterial* mat ) {
00023   return material ( *mat );
00024 }
00025 
00026 DDRotation DDPersToDDDFactory::rotation ( const PRotation* rot ) {
00027   return rotation ( *rot );
00028 }
00029 
00030 DDLogicalPart DDPersToDDDFactory::logicalPart ( const PLogicalPart* lp ) {
00031   return logicalPart ( *lp );
00032 }
00033 
00034 void DDPersToDDDFactory::position ( const PPosPart*  posPart ) {
00035   position ( *posPart );
00036 }
00037 
00038 DDSolid DDPersToDDDFactory::solid ( const PSolid& sol ) {
00039   //  std::cout << "solid type = " << sol.pShapeType << std::endl;
00040   DDSolid mysol;
00041   //  std::cout << "about to set DDSolidShape s" << std::endl;
00042   DDSolidShape s = DDSolidShapesName::index(sol.pShapeType);
00043   //  std::cout << "about to enter the switch" << std::endl;
00044   //  std::cout << "DDSolidShape is..." << s << std::endl;
00045   switch (s) 
00046     {
00047     case ddbox:
00048     case ddtubs:
00049     case ddcons:
00050     case ddpseudotrap:
00051     case ddtrunctubs:
00052     case ddtrap:
00053     case ddpolyhedra_rz: 
00054     case ddpolyhedra_rrz:
00055     case ddpolycone_rz:
00056     case ddpolycone_rrz:
00057     case ddtorus:
00058       {
00059         mysol = DDSolid( DDName( (*pstrs)[sol.pName] ), s, sol.pPars );
00060         break;
00061       }
00062     case ddshapeless:
00063       mysol = DDSolidFactory::shapeless( DDName( (*pstrs)[sol.pName]) );
00064       break;
00065     case ddunion:
00066       {
00067         DDTranslation t;
00068         if ( sol.pPars.size() != 0 ) {
00069           t = DDTranslation( sol.pPars[0], sol.pPars[1], sol.pPars[2] );
00070         } else {
00071           t = DDTranslation( 0.0, 0.0, 0.0 );
00072         }
00073         
00074         mysol = DDSolidFactory::unionSolid( DDName( (*pstrs)[sol.pName])
00075                                             , DDSolid(DDName( (*pstrs)[sol.pSolid1]) )
00076                                             , DDSolid(DDName( (*pstrs)[sol.pSolid2]) )
00077                                             , t //DDTranslation(sol.pPars[0], sol.pPars[1], sol.pPars[2])
00078                                             , DDRotation(DDName( (*pstrs)[sol.pRotation]) )
00079                                             );
00080         break;
00081       }
00082     case ddsubtraction: 
00083       {
00084         //       std::cout << "got subtraction... make solid1 "; // << std::endl;
00085         //        DDSolid s1(DDName(sol.pSolid1));
00086         //        std::cout << s1 << std::endl << "make solid2 "; // << std::endl;
00087         //        DDSolid s2(DDName(sol.pSolid2));
00088         //        std::cout << s2 << std::endl << "make translation "; // << std::endl;
00089         //        std::cout << "size of pPars = " << sol.pPars.size() << std::endl;
00090         DDTranslation t;
00091         if ( sol.pPars.size() != 0 ) {
00092           t = DDTranslation( sol.pPars[0], sol.pPars[1], sol.pPars[2] );
00093         } else {
00094           t = DDTranslation( 0.0, 0.0, 0.0 );
00095         }
00096         //        std::cout << t << std::endl << "make rotation "; // << std::endl;
00097         //        DDRotation r(DDName(sol.pRotation));
00098         //        std::cout << r << std::endl << "about to make subtraction" << std::endl;
00099         mysol = DDSolidFactory::subtraction( DDName( (*pstrs)[sol.pName] )
00100                                              //, s1, s2, t, r );
00101                                              , DDSolid(DDName( (*pstrs)[sol.pSolid1] ))
00102                                              , DDSolid(DDName( (*pstrs)[sol.pSolid2] ))
00103                                              , t //DDTranslation(sol.pPars[0], sol.pPars[1], sol.pPars[2])
00104                                              , DDRotation(DDName( (*pstrs)[sol.pRotation] ))
00105                                              );
00106         break;
00107       }
00108     case ddintersection:
00109       {
00110         DDTranslation t;
00111         if ( sol.pPars.size() != 0 ) {
00112           t = DDTranslation( sol.pPars[0], sol.pPars[1], sol.pPars[2] );
00113         } else {
00114           t = DDTranslation( 0.0, 0.0, 0.0 );
00115         }
00116         
00117         mysol = DDSolidFactory::intersection( DDName( (*pstrs)[sol.pName] )
00118                                               , DDSolid(DDName( (*pstrs)[sol.pSolid1] ))
00119                                               , DDSolid(DDName( (*pstrs)[sol.pSolid2] ))
00120                                               , t //DDTranslation(sol.pPars[0], sol.pPars[1], sol.pPars[2])
00121                                               , DDRotation(DDName( (*pstrs)[sol.pRotation] ))
00122                                               );
00123         break;
00124       }
00125     case dd_not_init:
00126     default:
00127       throw DDException("DDSolid::DDSolid(DDName,DDSolidShape,vector<double>: wrong shape");   
00128     }
00129   //  std::cout << "solid : " << mysol << std::endl;
00130   return mysol;
00131 }
00132 
00133 DDMaterial DDPersToDDDFactory::material ( const PMaterial& mat ) {
00134  DDMaterial mymat;
00135  // std::cout << "Make a PersMaterial" << std::endl;
00136  mymat = DDMaterial( DDName( (*pstrs)[mat.pName] )
00137                      , mat.pZ
00138                      , mat.pA
00139                      , mat.pDensity );
00140  if ( mat.pNumberOfConstituents != 0 ) {
00141    for ( size_t constituent = 0; constituent < mat.pCN.size(); ++constituent ) {
00142      mymat.addMaterial( DDName( (*pstrs)[mat.pCN[constituent]]), mat.pCF[constituent] );
00143    }
00144  }
00145  // std::cout << "material " << mymat << std::endl;
00146  return mymat;
00147 }
00148 
00149 DDRotation DDPersToDDDFactory::rotation ( const PRotation& rot ) {
00150 //   std::cout << "rotation named: " << rot.pName;
00151 //   std::cout << "  theta -- phi " << std::endl;
00152 //   std::cout << "x  " << rot.pThetaX/deg << ", " << rot.pPhiX/deg << std::endl;
00153 //   std::cout << "y  " << rot.pThetaY/deg << ", " << rot.pPhiY/deg << std::endl;
00154 //   std::cout << "z  " << rot.pThetaZ/deg << ", " << rot.pPhiZ/deg << std::endl;
00155 
00156   DDRotation defrot;
00157   //  std::cout << " reflection? 1=true " << rot.pReflection << std::endl;
00158   //  std::cout << "size of pStrings = " << (*pstrs).size() << std::endl;
00159   //  std::cout << "rotation name index = " << rot.pName << std::endl;
00160   //  std::cout << "so the name is pStrings[" << rot.pName << "] = " << (*pstrs)[rot.pName] << std::endl;
00161   if ( rot.pReflection == 1) {
00162     //    std::cout << "make reflection" << std::endl;
00163     DDRotation myrot = DDrotReflect ( DDName( (*pstrs)[rot.pName] )
00164                                       , rot.pThetaX, rot.pPhiX
00165                                       , rot.pThetaY, rot.pPhiY
00166                                       , rot.pThetaZ, rot.pPhiZ );
00167     return myrot;
00168   } else {
00169     //    std::cout << "make rotation" << std::endl;
00170     DDRotation myrot = DDrot ( DDName( (*pstrs)[rot.pName] )
00171                                , rot.pThetaX, rot.pPhiX
00172                                , rot.pThetaY, rot.pPhiY
00173                                , rot.pThetaZ, rot.pPhiZ );
00174     return myrot;
00175   }
00176   return defrot;
00177 }
00178 
00179 DDLogicalPart DDPersToDDDFactory::logicalPart ( const PLogicalPart& lp ) {
00180   std::string lpn = (*pstrs)[lp.pName];
00181   std::string pmn = (*pstrs)[lp.pMaterial];
00182   std::string psn = (*pstrs)[lp.pSolid];
00183   DDLogicalPart mylp = DDLogicalPart( DDName( lpn )
00184                                       , DDMaterial(DDName( pmn ))
00185                                       , DDSolid(DDName( psn )) );
00186 
00187 //   std::cout << mylp.toString() << " " << mylp.solid().toString() << " "
00188 //        << mylp.material().toString() << std::endl;
00189 
00190   return mylp;
00191 }
00192 
00193 void DDPersToDDDFactory::position ( const PPosPart&  posPart ) {
00194   DDpos( DDLogicalPart(DDName( (*pstrs)[posPart.pChildLP] ))
00195          , DDLogicalPart(DDName( (*pstrs)[posPart.pParentLP] ))
00196          , posPart.pCopyNo
00197          , DDTranslation (posPart.pX, posPart.pY, posPart.pZ)
00198          , DDRotation (DDName( (*pstrs)[posPart.pRotation] )));
00199 }
00200 
00201 
00202 void DDPersToDDDFactory::specPar ( const PSpecPar& specPar ) {
00203 
00204   // first, build DDValue and DDsvalues
00205   DDsvalues_type svt;
00206 
00207   size_t numPars = specPar.pValues.pNames.size();
00208   size_t currPar = 0;
00209   //  std::cout << " rebuilding specpar " << specPar.pName << " with " << numPars << " number of parameters." << std::endl;
00210   for ( ; currPar < numPars ; ++currPar ) {
00211     std::vector <DDValuePair> vvp;
00212 
00213     size_t currVal = specPar.pValues.pOffset[currPar].pOneOffset;
00214     size_t numVals = specPar.pValues.pOffset[currPar].pSize + currVal;
00215     //    std::cout << "numVals = " << numVals << " and currVal = " << currVal << std::endl;
00216     for ( ; currVal < numVals ; ++currVal ) {
00217       vvp.push_back(DDValuePair( (*pstrs)[specPar.pValues.pValuePairs[currVal].pStr], specPar.pValues.pValuePairs[currVal].pDbl));
00218     }
00219     
00220     DDValue val ( (*pstrs)[specPar.pValues.pNames[currPar]], vvp );
00221     val.setEvalState(specPar.pValues.pOffset[currPar].pIsEvaluated);
00222     svt.push_back(DDsvalues_Content_type(val,val));
00223   }
00224   std::sort(svt.begin(),svt.end());
00225 
00226   DDSpecifics ds( (*pstrs)[specPar.pName], specPar.pSpecSelections, svt, false );
00227   //  std::cout << ds << std::endl;
00228 
00229 }
00230 
00231 void DDPersToDDDFactory::setRoot (const std::string& rootName) {
00232   DDRootDef::instance().set(DDName(rootName));
00233 }
00234 

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