CMS 3D CMS Logo

CocoaToDDLMgr.cc

Go to the documentation of this file.
00001 //   COCOA class implementation file
00002 //Id:  CocoaToDDLMgr.cc
00003 //
00004 //   History: v1.0 
00005 //   Pedro Arce
00006 
00007 #include "Alignment/CocoaToDDL/interface/CocoaToDDLMgr.h"
00008 #include "Alignment/CocoaToDDL/interface/UnitConverter.h"
00009 #define UC(val,category) UnitConverter(val,category).ucstring()
00010 
00011 #include "Alignment/CocoaDDLObjects/interface/CocoaMaterialElementary.h"
00012 #include "Alignment/CocoaDDLObjects/interface/CocoaSolidShapeBox.h"
00013 #include "Alignment/CocoaDDLObjects/interface/CocoaSolidShapeTubs.h"
00014 
00015 #include "Alignment/CocoaModel/interface/Model.h"
00016 #include "Alignment/CocoaModel/interface/OpticalObject.h"
00017 #include "Alignment/CocoaModel/interface/Entry.h"
00018 #include "Alignment/CocoaModel/interface/Measurement.h"
00019 
00020 #include "CLHEP/Units/SystemOfUnits.h"
00021 
00022 
00023 CocoaToDDLMgr* CocoaToDDLMgr::instance = 0;
00024 
00025 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00026 CocoaToDDLMgr* CocoaToDDLMgr::getInstance()
00027 {
00028   if(!instance) {
00029     instance = new CocoaToDDLMgr;
00030   }
00031   return instance;
00032 }
00033 
00034 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00035 void CocoaToDDLMgr::writeDDDFile( ALIstring filename) 
00036 {
00037   //---- Write header
00038   writeHeader( filename );
00039 
00040   //---- Write materials
00041   writeMaterials();
00042 
00043   //---- Write solids
00044   writeSolids();
00045 
00046   //---- Write logical volumes
00047   writeLogicalVolumes();
00048 
00049   //---- Write physical volumes
00050   writePhysicalVolumes();
00051 
00052   //---- Write rotations
00053   writeRotations();
00054 
00055   //---- Write SpecPar's
00056   writeSpecPars();
00057 
00058   newPartPost( filename, "" ); 
00059 
00060 
00061 }
00062 
00063 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00064 void CocoaToDDLMgr::writeHeader( ALIstring filename)
00065 {
00066   newPartPre( filename ); 
00067 }
00068 
00069 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00070 void CocoaToDDLMgr::writeMaterials()
00071 {
00072   newSectPre_ma("");
00073   static std::vector< OpticalObject* > optolist = Model::OptOList();
00074   static std::vector< OpticalObject* >::const_iterator ite;
00075   for(ite = optolist.begin(); ite != optolist.end(); ite++ ){
00076     if( (*ite)->type() == "system" ) continue;
00077     CocoaMaterialElementary* mat = (*ite)->getMaterial();
00078     //-    std::cout << " mat of opto " << (*ite)->name() << " = " << mat->getName() << std::endl;
00079     if( mat ) {
00080       if( !materialIsRepeated( mat ) ) ma( mat );
00081     }
00082   }
00083 
00084   newSectPost_ma("");
00085 }
00086 
00087 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00088 void CocoaToDDLMgr::writeSolids()
00089 {
00090   newSectPre_so("");
00091   
00092   static std::vector< OpticalObject* > optolist = Model::OptOList();
00093   static std::vector< OpticalObject* >::const_iterator ite,ite2;
00094   for(ite = optolist.begin(); ite != optolist.end(); ite++ ){
00095     bool alreadyWritten = false;
00096     for(ite2 = optolist.begin(); ite2 != ite; ite2++ ){
00097       if( (*ite)->shortName() == (*ite2)->shortName() ) {
00098         alreadyWritten = true;
00099       }
00100     }
00101 std::cout << " CocoaToDDLMgr::writeSolids() " << alreadyWritten << *ite;
00102 std::cout << (*ite)->name() << std::endl;
00103     if( !alreadyWritten ) so( *ite );
00104   }
00105   
00106   newSectPost_so("");
00107 
00108 }
00109 
00110 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00111 void CocoaToDDLMgr::writeLogicalVolumes()
00112 {
00113   newSectPre_lv("");
00114   
00115   static std::vector< OpticalObject* > optolist = Model::OptOList();
00116   static std::vector< OpticalObject* >::const_iterator ite,ite2;
00117   for(ite = optolist.begin(); ite != optolist.end(); ite++ ){
00118     bool alreadyWritten = false;
00119     for(ite2 = optolist.begin(); ite2 != ite; ite2++ ){
00120       if( (*ite)->shortName() == (*ite2)->shortName() ) {
00121         alreadyWritten = true;
00122       }
00123     }
00124     if( !alreadyWritten ) lv( *ite );
00125   }
00126   
00127   newSectPost_lv("");
00128 
00129 }
00130 
00131 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00132 void CocoaToDDLMgr::writePhysicalVolumes()
00133 {
00134   newSectPre_pv("");
00135   
00136   static std::vector< OpticalObject* > optolist = Model::OptOList();
00137   static std::vector< OpticalObject* >::const_iterator ite;
00138   for(ite = optolist.begin(); ite != optolist.end(); ite++ ){
00139     if( (*ite)->type() == "system" ) continue;
00140     pv( *ite );
00141   }
00142   
00143   newSectPost_pv("");
00144 
00145 }
00146 
00147 
00148 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00149 void CocoaToDDLMgr::writeRotations()
00150 {
00151   newSectPre_ro("");
00152   std::vector<HepRotation>::const_iterator ite;
00153   int nc = 0;
00154   for( ite = theRotationList.begin(); ite != theRotationList.end(); ite++) {
00155     //-  std::cout << nc << " rot size " <<  theRotationList.size() << std::endl;
00156     ro( *ite, nc );
00157     nc++;
00158   }    
00159   newSectPost_ro("");
00160 
00161 }
00162 
00163 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00164 void CocoaToDDLMgr::writeSpecPars()
00165 {
00166   newSectPre_specPar("");
00167   
00168   static std::vector< OpticalObject* > optolist = Model::OptOList();
00169   static std::vector< OpticalObject* >::const_iterator ite;
00170   for(ite = optolist.begin(); ite != optolist.end(); ite++ ){
00171     if( (*ite)->type() == "system" ) continue;
00172     specPar( *ite );
00173   }
00174   
00175   writeSpecParsCocoa();
00176 
00177   //---- Write Measurements's
00178   measurementsAsSpecPars();
00179 
00180 
00181   newSectPost_specPar("");
00182 
00183 
00184 }
00185 
00186 
00187 
00188 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00189 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00190 void CocoaToDDLMgr::newPartPre(std::string name)
00191 {
00192    filename_=name;
00193    file_.open(filename_.c_str()); 
00194    file_.precision(8);
00195    file_ << "<?xml version=\"1.0\"?>" << std::endl;
00196 
00197    // all files get schema references and namespaces.
00198    file_ << "<DDDefinition xmlns=\"https://www.cern.ch/cms/DDL\""
00199          << " xmlns:xsi=\"https://www.w3.org/2001/XMLSchema-instance\""
00200          << " xsi:schemaLocation=\"https://www.cern.ch/cms/DDL ../../DDLSchema/DDLSchema.xsd\">"
00201          << std::endl << std::endl;
00202 
00203    #ifdef gdebug
00204      cout << "part-pre:" << name << std::endl;
00205    #endif  
00206 }
00207 
00208 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00209 void CocoaToDDLMgr::newPartPost(std::string name, std::string extension)
00210 {
00211    file_ << std::endl << "</DDDefinition>" << std::endl;
00212    file_.close();
00213 }
00214 
00215 
00216 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00217 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00218 void CocoaToDDLMgr::newSectPre_ma(std::string name)
00219 {
00220 #ifdef gdebug
00221   std::cout << " sect-mat-pre:" << name << '-' << std::endl;
00222 #endif
00223    newSectPre(filename_,std::string("MaterialSection"));
00224 }    
00225 
00226 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00227 void CocoaToDDLMgr::ma(CocoaMaterialElementary* ma)
00228 {
00229   theMaterialList.push_back( ma );
00230 
00231 #ifdef gdebug
00232   cout << "  ma:" << ma->getName() << std::endl;
00233 #endif
00234   
00235   ALIfloat density       = ma->getDensity();
00236   
00237   // start tag
00238   file_ << "  <ElementaryMaterial";
00239   ALIstring cSymbol = ma->getSymbol();
00240   
00241   // name attribute
00242   file_ << " name=\"" << ma->getName() << "\"";
00243   
00244   // put out common attributes
00245   //  file_ << " density=\"" << UnitConverter(density,"Volumic Mass") << "\"";
00246   file_ << " density=\"" << UC(density,"Volumic Mass") << "\"";
00247   file_ << " symbol=\"" << ma->getSymbol() << "\"";
00248   
00249   
00250   // finish last two attributes and end material element
00251   file_ << " atomicWeight=\"" << (ma->getA()) << "*g/mole\""
00252         << " atomicNumber=\"" << ma->getZ() << "\""
00253         << "/>" << std::endl;
00254   
00255 } 
00256 
00257 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00258 void CocoaToDDLMgr::newSectPost_ma(std::string name)
00259 {
00260    #ifdef gdebug
00261     cout << " sect-mat-post:" << name << '-' << std::endl;
00262    #endif
00263    newSectPost("MaterialSection");
00264 }    
00265 
00266 
00267 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00268 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00269 void CocoaToDDLMgr::newSectPre_so(std::string name)
00270 {
00271    #ifdef gdebug
00272     cout << " sect-so-pre:" << name << '-' << std::endl;
00273    #endif
00274    newSectPre(filename_,std::string("SolidSection"));
00275 }    
00276 
00277 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00278 void CocoaToDDLMgr::so(OpticalObject * opto) 
00279 {
00280  std::cout << " CocoaToDDLMgr::so( " << opto;
00281 std::cout << " " << opto->shortName() << std::endl;
00282 
00283   std::string name = opto->shortName();
00284 
00285   if( opto->type() == "system" ){
00286     //    file_ << " <Box name=\"" << name << "\"";
00287     file_ << " <Box name=\"" << opto->name() << "\"";
00288     file_ << " dx=\"10.*m" 
00289           << "\" dy=\"10.*m" 
00290           << "\" dz=\"10.*m" 
00291           << "\"/>" << std::endl;
00292     return;
00293   }
00294 
00295   CocoaSolidShape* so = opto->getSolidShape();
00296 
00297  std::cout << " CocoaToDDLMgr::so( so " << so << std::endl;  
00298 std::string solidType = so->getType();
00299 
00300   if (solidType == "Box")
00301     {
00302       file_ << " <" << solidType << " name=\"" << name << "\"";
00303       CocoaSolidShapeBox * sb = dynamic_cast<CocoaSolidShapeBox*>(so);
00304       file_ << " dx=\"" << UC(sb->getXHalfLength(),"Length")
00305             << "\" dy=\"" << UC(sb->getYHalfLength(),"Length") 
00306             << "\" dz=\"" << UC(sb->getZHalfLength(),"Length")
00307             << "\"/>" << std::endl;
00308     }
00309   else if (solidType == "Tubs")
00310     {
00311       CocoaSolidShapeTubs * tu = dynamic_cast < CocoaSolidShapeTubs * > (so);
00312       file_ << " <" << solidType 
00313             << " name=\""     << name                                                    << "\""
00314             << " rMin=\""     << UC(tu->getInnerRadius(),"Length")   << "\""
00315             << " rMax=\""     << UC(tu->getOuterRadius(),"Length")   << "\""
00316             << " dz=\""       << UC(tu->getZHalfLength(),"Length")   << "\""
00317             << " startPhi=\"" << UC(tu->getStartPhiAngle(),"Angle") << "\""
00318             << " deltaPhi=\"" << UC(tu->getDeltaPhiAngle(),"Angle") << "\""
00319             << "/>" << std::endl;
00320     }
00321   /*  else if (solidType == "Cons")
00322     {
00323       G4Cons * cn = dynamic_cast < G4Cons * > (so);
00324       file_ << " <" << solidType 
00325             << " name=\""     << name                                              << "\""
00326             << " dz=\""       << UC(cn->getZHalfLength(),"Length")       << "\""
00327             << " rMin1=\""    << UC(cn->getInnerRadiusMinusZ(),"Length") << "\"" 
00328             << " rMax1=\""    << UC(cn->getOuterRadiusMinusZ(),"Length") << "\""
00329             << " rMin2=\""    << UC(cn->getInnerRadiusPlusZ(),"Length")  << "\""            
00330             << " rMax2=\""    << UC(cn->getOuterRadiusPlusZ(),"Length")  << "\""
00331             << " startPhi=\"" << UC(cn->getStartPhiAngle(),"Angle")     << "\""
00332             << " deltaPhi=\"" << UC(cn->getDeltaPhiAngle(),"Angle")    << "\""
00333           //<< " lengthUnit=\"mm\" angleUnit=\"degree\"/>" 
00334             << " />" << std::endl;
00335     }
00336   else if (solidType == "Polycone")
00337     {
00338       G4Polycone * pc = dynamic_cast < G4Polycone * > (so);
00339       file_ << " <Polycone name=\"" << name<< "\"";
00340       bool isOpen = pc->IsOpen();
00341       G4int numRZCorner = (dynamic_cast < G4Polycone * > (so))->getNumRZCorner();
00342       
00343       file_ << " startPhi=\"" << UC(pc->getStartPhi(),"Angle") << "\""
00344             //<< " deltaPhi=\"" << UC(fabs((pc->getEndPhi()/deg - pc->getStartPhi()/deg))*deg,"Angle")   << "\"" 
00345             //<< " deltaPhi=\"" << UC(pc->getEndPhi(),"Angle")   << "\"" 
00346             << " deltaPhi=\"" << UC(pc->original_parameters->Opening_angle,"Angle")   << "\""
00347             //<< " angleUnit=\"degree\">" 
00348             << " >" << std::endl;
00349 
00350       G4PolyconeSideRZ rz;
00351       
00352       //liendl: FIXME put a switch which decides whether RZ or Rmin,Rmax,Z types should
00353       //              by generated ....
00354       //outPolyZSections(rz, (dynamic_cast < G4Polycone * > (so)), numRZCorner);
00355       G4double * zVal;
00356       G4double * rmin;
00357       G4double * rmax;
00358       G4int zPlanes;
00359       zPlanes = pc->original_parameters->Num_z_planes;
00360       zVal = pc->original_parameters->Z_values;
00361       rmin = pc->original_parameters->Rmin;
00362       rmax = pc->original_parameters->Rmax;
00363       outPolySections(zPlanes, zVal, rmin, rmax);
00364       file_ << " </Polycone> " << std::endl;
00365     }
00366   else if (solidType == "Polyhedra")
00367     {
00368       //      bool isOpen = (dynamic_cast < G4Polyhedra * > (so))->IsOpen();
00369       G4Polyhedra * ph = (dynamic_cast < G4Polyhedra * > (so));
00370       G4int numRZCorner = ph->getNumRZCorner();
00371  
00372       file_ << " <Polyhedra name=\"" << name<< "\""
00373             << " numSide=\"" << ph->getNumSide() << "\""
00374             << " startPhi=\"" << UC(ph->getStartPhi(),"Angle") << "\""
00375             //<< " deltaPhi=\""   <<  UC(fabs((ph->getEndPhi()/deg - ph->getStartPhi()/deg))*deg,"Angle")   << "\""
00376             << " deltaPhi=\"" << UC(ph->original_parameters->Opening_angle,"Angle")   << "\"" 
00377             << " >" << std::endl;
00378 
00379       G4PolyhedraSideRZ rz;
00380       //liendl: FIXME put a switch which decides whether RZ or Rmin,Rmax,Z types should
00381       //              by generated ....
00382       // outPolyZSections(rz, (dynamic_cast < G4Polyhedra * > (so)), numRZCorner);
00383       G4double * zVal;
00384       G4double * rmin;
00385       G4double * rmax;
00386       // convertRad of ctor of G4Polyhedra(..) ....
00387       G4double strangeG3G4Factor = cos(0.5*ph->original_parameters->Opening_angle/G4double(ph->getNumSide()));
00388       G4int zPlanes;
00389       zPlanes = ph->original_parameters->Num_z_planes;
00390       zVal = ph->original_parameters->Z_values;
00391       rmin = ph->original_parameters->Rmin;
00392       rmax = ph->original_parameters->Rmax;
00393       for (int i=0; i<zPlanes;++i) {
00394        *(rmin+i) = *(rmin+i) * strangeG3G4Factor;
00395        *(rmax+i) = *(rmax+i) * strangeG3G4Factor;
00396       }
00397       outPolySections(zPlanes, zVal, rmin, rmax);
00398 
00399       file_ << " </Polyhedra>" << std::endl;
00400     }
00401   else if (solidType == "Trapezoid")
00402     {
00403       // DDL fields
00404       // ALP1, ALP2, Bl1, Bl2, Dz, H1, H2, Phi, Thet, TL1, TL2, lengthUnit, angleUnit    
00405       // Phi and Theta are !NOT!optional.
00406        G4Trap * trp = dynamic_cast < G4Trap * > (so);
00407        G4ThreeVector symAxis(trp->getSymAxis());
00408        double theta, phi;
00409        theta = symAxis.theta();
00410        phi = symAxis.phi();
00411 
00412       file_ << " <" << solidType 
00413             << " name=\"" << name                                                       << "\""
00414             << " dz=\""   << UC(trp->getZHalfLength(),"Length")      << "\""
00415             << " alp1=\"" << UC(atan(trp->getTanAlpha1()/rad),"Angle") << "\"" 
00416             << " bl1=\""  << UC(trp->getXHalfLength1(),"Length")     << "\""
00417             << " tl1=\""  << UC(trp->getXHalfLength2(),"Length")     << "\""        
00418             << " h1=\""   << UC(trp->getYHalfLength1(),"Length")    << "\""
00419             << " alp2=\"" << UC(atan(trp->getTanAlpha2()/rad),"Angle") << "\""
00420             << " bl2=\""  << UC(trp->getXHalfLength3(),"Length")     << "\""
00421             << " tl2=\""  << UC(trp->getXHalfLength4(),"Length")    << "\""         
00422             << " h2=\""   << UC(trp->getYHalfLength2(),"Length")     << "\""
00423             << " phi=\""  << UC(phi,"Angle") << "\""
00424             << " theta=\"" << UC(theta,"Angle") << "\"" 
00425             << " />" << std::endl ;
00426     }
00427   else if (solidType == "Trd1")
00428     {
00429       G4Trd * tr = dynamic_cast < G4Trd * > (so);
00430       file_ << " <" << solidType  
00431             << " name=\"" << name                                                  << "\""
00432             << " dz=\""   << UC(tr->getZHalfLength(),"Length")  << "\""
00433             << " dy1=\""  << UC(tr->getYHalfLength1(),"Length") << "\""
00434             << " dy2=\""  << UC(tr->getYHalfLength2(),"Length")<< "\"" 
00435             << " dx1=\""  << UC(tr->getXHalfLength1(),"Length") << "\""
00436             << " dx2=\""  << UC(tr->getXHalfLength2(),"Length") << "\""
00437             //<< " lengthUnit=\"mm\"/>" 
00438             << " />" << std::endl;
00439     }
00440   */  
00441   else
00442     {
00443      std::cerr << " <!-- NOT HANDLED: " << solidType << " name=\"" << name<< "\""
00444             << ">" << std::endl
00445             << " </" << solidType << "> -->" << std::endl;
00446     std::exception();
00447     }
00448     
00449 }      
00450 
00451 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00452 void CocoaToDDLMgr::newSectPost_so(std::string name)
00453 {
00454    #ifdef gdebug
00455     cout << " sect-so-post:" << name << '-' << std::endl;
00456    #endif
00457    newSectPost("SolidSection");
00458 }
00459 
00460 
00461 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00462 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00463 void CocoaToDDLMgr::newSectPre_lv(std::string name)
00464 {
00465    #ifdef gdebug
00466     cout << " sect-lv-pre:" << name << '-'  << std::endl;
00467    #endif
00468    newSectPre(filename_,std::string("LogicalPartSection"));
00469 }    
00470 
00471 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00472 void CocoaToDDLMgr::lv(OpticalObject * opto)
00473 { 
00474   std::string name = opto->shortName();
00475   std::string rSolid = opto->shortName();
00476   std::string sensitive = "unspecified";
00477 
00478   if( opto->type() == "system" ){
00479     file_ << " <LogicalPart name=\"" 
00480           <<  name << "\" category=\"" << sensitive << "\">" << std::endl
00481           << "  <rSolid name=\"" << rSolid << "\"/>" << std::endl
00482           << "  <rMaterial name=\"Hydrogen\"" 
00483           << "/>" << std::endl
00484           << " </LogicalPart>" << std::endl;                    
00485     return;
00486   }
00487 
00488 #ifdef gdebug_v
00489   cout << "xml:lv " << opto->name() << std::endl;
00490 #endif 
00491   file_ << " <LogicalPart name=\"" 
00492         <<  name << "\" category=\"" << sensitive << "\">" << std::endl
00493         << "  <rSolid name=\"" << rSolid << "\"/>" << std::endl
00494         << "  <rMaterial name=\"" << opto->getMaterial()->getName() << "\"" 
00495         << "/>" << std::endl
00496         << " </LogicalPart>" << std::endl;                      
00497 }
00498 
00499 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00500 void CocoaToDDLMgr::newSectPost_lv(std::string name)
00501 {
00502    #ifdef gdebug
00503     cout << " sect-lv-post:" << name << '-'<< std::endl;
00504    #endif 
00505    newSectPost("LogicalPartSection");
00506 }    
00507 
00508 
00509 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00510 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00511 void CocoaToDDLMgr::newSectPre_pv(std::string name)
00512 {
00513    #ifdef gdebug
00514      cout << " sect-pv-pre:" << name << '-' << std::endl;
00515    #endif
00516    newSectPre(filename_,std::string("PosPartSection"));
00517 }    
00518 
00519 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00520 void CocoaToDDLMgr::pv(OpticalObject * opto)
00521 {
00522    #ifdef gdebug_v
00523     cout << "  pv:" << opto->name() 
00524          << ':' << opto->parent()->name() << std::endl;
00525    #endif
00526 
00527     //   file_ << " <PosPart copyNumber=\"" << pv->GetCopyNo() << "\">" << std::endl; 
00528    file_ << " <PosPart copyNumber=\"" << "1" << "\">" << std::endl; 
00529    file_ << "   <rParent name=\"";
00530 
00531    //t   if (file!=filename_) file_ << file << ":";
00532    
00533    file_ << opto->parent()->shortName() << "\"/>" << std::endl;
00534 
00535    file_ << "   <rChild name=\""; 
00536    //t  if (file_d != filename_)  file_<<  file_d << ":";       
00537    file_ << opto->shortName();  
00538    file_ << "\"/>" << std::endl;
00539    
00540    int rotNumber = buildRotationNumber( opto );
00541    //CocoaDDLRotation* rot = buildRotationNotRepeated( opto );
00542    
00543    if( rotNumber != -1 ) file_ << "  <rRotation name=\"R" << rotNumber << "\"/>" << std::endl;
00544 
00545    Hep3Vector t =  opto->centreLocal();
00546    if(t != Hep3Vector()) { //if (0,0,0) write nothing
00547      const Hep3Vector t = opto->centreLocal();
00548 
00549      file_ << "  <Translation x=\"" <<  UC(t[0],"Length") << "\""
00550            <<               " y=\"" << UC(t[1],"Length") << "\""
00551            <<               " z=\"" << UC(t[2],"Length")<< "\" />"
00552            << std::endl;
00553    }                     
00554     
00555    file_ << " </PosPart>" << std::endl;  
00556                          
00557 }   
00558 
00559 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00560 void CocoaToDDLMgr::newSectPost_pv(std::string name)
00561 {
00562    #ifdef gdebug
00563     cout << " sect-pv-post:" << name << '-' << std::endl;
00564    #endif
00565    newSectPost("PosPartSection");
00566 }
00567 
00568 
00569 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00570 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00571 void CocoaToDDLMgr::newSectPre_ro(std::string name)
00572 {
00573    newSectPre(filename_,std::string("RotationSection"));
00574 }
00575 
00576 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00577 // handlers reflections and rotations ...
00578 void CocoaToDDLMgr::ro(const HepRotation& ro, int n)
00579 {
00580    
00581    HepRotation roinv = inverseOf(ro);
00582   //-    G4ThreeVector v(1.,1.,1.);
00583   //-     G4ThreeVector a;
00584   //-   a = (*ro)*v;
00585   bool identity = false;
00586   ALIstring tag = " <Rotation name=\"R";
00587   identity=roinv.isIdentity();  
00588   
00589   //---- DDD convention is to use the inverse matrix, COCOA is the direct one!!!
00590   if (! identity) {     
00591     file_ << tag << n << "\"";
00592     file_ << " phiX=\""   << UC(roinv.phiX(),"Angle")   << "\""
00593           << " thetaX=\"" << UC(roinv.thetaX(),"Angle") << "\""
00594           << " phiY=\""   << UC(roinv.phiY(),"Angle")   << "\""
00595           << " thetaY=\"" << UC(roinv.thetaY(),"Angle") << "\""
00596           << " phiZ=\""   << UC(roinv.phiZ(),"Angle")   << "\""
00597           << " thetaZ=\"" << UC(roinv.thetaZ(),"Angle") << "\""
00598       //<< " angleUnit=\"degree\"/>" 
00599           << " />" << std::endl;
00600   }          
00601 }
00602 
00603 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00604 void CocoaToDDLMgr::newSectPost_ro(std::string name)
00605 {
00606    newSectPost("RotationSection");
00607 }
00608 
00609 
00610 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00611 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00612 void CocoaToDDLMgr::newSectPre_specPar(std::string name)
00613 {
00614    #ifdef gdebug
00615     cout << " sect-lv-pre:" << name << '-'  << std::endl;
00616    #endif
00617     //-   newSectPre(filename_,std::string("SpecParSection"));
00618    file_ << "<SpecParSection label=\"" << filename_ << "\" eval=\"true\">" << std::endl;
00619 
00620 }    
00621 
00622 
00623 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00624 void CocoaToDDLMgr::specPar(OpticalObject * opto)
00625 {
00626   file_ << " <SpecPar name=\"" << opto->name() << "_PARAMS\">" << std::endl;
00627   file_ << "    <PartSelector path=\"/" << opto->name() << "\"/> " << std::endl;
00628   file_ << "   <Parameter name=\"cocoa_type\""  << " value=\"" << opto->type() << "\"   eval=\"false\" /> " << std::endl;
00629 
00630   const std::vector< Entry* > coord = opto->CoordinateEntryList();
00631   for( int ii=3; ii<6; ii++ ){
00632     Entry* ent = coord[ii];
00633     file_ << "   <Parameter name=\"" << ent->name()+std::string("_value") << "\" value=\"";
00634     file_ << UC(ent->value(),"Angle");
00635     file_ << "\" /> " << std::endl;
00636   }
00637   for( int ii=0; ii<6; ii++ ){
00638     Entry* ent = coord[ii];
00639     file_ << "   <Parameter name=\"" << ent->name()+std::string("_sigma") << "\" value=\"";
00640     if( ii < 3 ){
00641       file_ << UC(ent->sigma(),"Length");
00642     }else {
00643       file_ << UC(ent->sigma(),"Angle");
00644     }
00645     file_ << "\" /> " << std::endl;
00646     file_ << "   <Parameter name=\"" << ent->name()+std::string("_quality") << "\" value=\"" << ent->quality() << "\" /> " << std::endl;
00647   }
00648   
00649   const std::vector< Entry* > extraEnt = opto->ExtraEntryList();
00650   for( uint ii=0; ii<extraEnt.size(); ii++ ){
00651     Entry* ent = extraEnt[ii]; 
00652     file_ << "   <Parameter name=\"extra_entry\" value=\"" << ent->name() << "\"  eval=\"false\" /> " << std::endl;
00653     file_ << "   <Parameter name=\"dimType\" value=\"" << ent->type() << "\"  eval=\"false\" /> " << std::endl;
00654     file_ << "   <Parameter name=\"value\" value=\"";
00655     if( ent->type() == "nodim" ) {
00656       file_ << ent->value();
00657     }else if( ent->type() == "length" ) {
00658       file_ << UC(ent->value(),"Length");
00659     }else if( ent->type() == "angle" ) {
00660       file_ << UC(ent->value(),"Angle");
00661     }
00662     file_ << "\"  eval=\"true\" /> " << std::endl;
00663 
00664     file_ << "   <Parameter name=\"sigma\" value=\"";
00665     if( ent->type() == "nodim" ) {
00666       file_ << ent->sigma();
00667     }else if( ent->type() == "length" ) {
00668       file_ << UC(ent->sigma(),"Length");
00669     }else if( ent->type() == "angle" ) {
00670       file_ << UC(ent->sigma(),"Angle");
00671     }
00672     file_ << "\"  eval=\"true\" /> " << std::endl;
00673 
00674     file_ << "   <Parameter name=\"quality\" value=\"" << ent->quality() << "\"  eval=\"true\" /> " << std::endl;
00675   }
00676 
00677   file_ << " </SpecPar>" << std::endl;
00678   
00679 }
00680 
00681 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00682 void CocoaToDDLMgr::measurementsAsSpecPars()
00683 {
00684   
00685   std::vector< Measurement* > measlist = Model::MeasurementList();
00686   std::vector< Measurement* >::iterator mite;
00687   std::vector<ALIstring>::iterator site;
00688   std::multimap<OpticalObject*,Measurement*> optoMeasMap;
00689   for( mite = measlist.begin(); mite != measlist.end(); mite++ ) {
00690     std::vector<OpticalObject*> optolist = (*mite)->OptOList();
00691     OpticalObject* opto = optolist[optolist.size()-1];
00692     optoMeasMap.insert( std::multimap<OpticalObject*,Measurement*>::value_type(opto, *mite) );
00693   }
00694 
00695   typedef std::multimap<OpticalObject*,Measurement*>::const_iterator itemom;
00696   itemom omite;
00697   std::pair<itemom, itemom > omitep;
00698   itemom omite2, omite3;
00699 
00700   for( omite = optoMeasMap.begin(); omite != optoMeasMap.end(); omite++ ){
00701     omitep = optoMeasMap.equal_range( (*omite).first );
00702     if( omite != optoMeasMap.begin() && (*omite).first == (*omite3).first ) continue; // check that it is not the same OptO than previous one
00703     omite3 = omite;
00704     for( omite2 = omitep.first; omite2 != omitep.second; omite2++ ){
00705       OpticalObject* opto = (*(omite2)).first;
00706       Measurement* meas = (*(omite2)).second;
00707       std::vector<ALIstring> namelist = meas->OptONameList();
00708       if( omite2 == omitep.first ){
00709         file_ << " <SpecPar name=\"" << meas->name() << "_MEASUREMENT\">" << std::endl;
00710         file_ << "   <PartSelector path=\"/" << opto->name() << "\"/> " << std::endl;
00711       }
00712 
00713       file_ << "   <Parameter name=\"" << std::string("meas_name") << "\" value=\"" << meas->name() << "\"  eval=\"false\" /> " << std::endl;
00714       file_ << "   <Parameter name=\"" << std::string("meas_type") << "\" value=\"" << meas->type() << "\"  eval=\"false\" /> " << std::endl;
00715       for( site = namelist.begin(); site != namelist.end(); site++ ){     
00716         file_ << "   <Parameter name=\"" << std::string("meas_object_name_")+meas->name() << "\" value=\"" << (*site) << "\"  eval=\"false\" /> " << std::endl;
00717       }
00718       for( uint ii = 0; ii < meas->dim(); ii++ ){
00719         file_ << "   <Parameter name=\"" << std::string("meas_value_name_")+meas->name() << "\" value=\"" << meas->valueType(ii) << "\"  eval=\"false\" /> " << std::endl;
00720         file_ << "   <Parameter name=\"" << std::string("meas_value_")+meas->name() << "\" value=\"" << meas->value(ii) << "\"  eval=\"true\" /> " << std::endl;
00721         file_ << "   <Parameter name=\"" << std::string("meas_sigma_")+meas->name() << "\" value=\"" << meas->sigma(ii) << "\"  eval=\"true\" /> " << std::endl;
00722         file_ << "   <Parameter name=\"" << std::string("meas_is_simulated_value_")+meas->name() << "\" value=\"" << meas->valueIsSimulated(ii) << "\"  eval=\"true\" /> " << std::endl;
00723       }
00724       
00725     }
00726     file_ << " </SpecPar>" << std::endl;
00727   }
00728 }
00729 
00730 
00731 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00732 void CocoaToDDLMgr::writeSpecParsCocoa()
00733 {
00734   file_ << "<!--    Define volumes as COCOA objects --> " << std::endl
00735         << "  <SpecPar name=\"COCOA\"> " << std::endl;
00736 
00737   static std::vector< OpticalObject* > optolist = Model::OptOList();
00738   static std::vector< OpticalObject* >::const_iterator ite;
00739   for(ite = optolist.begin(); ite != optolist.end(); ite++ ){
00740     if( (*ite)->type() == "system" ) continue;
00741     file_ << "    <PartSelector path=\"/" << (*ite)->name() << "\"/> " << std::endl;
00742   }
00743    
00744   file_ << "   <String name=\"COCOA\" value=\"COCOA\"/> " << std::endl
00745         << "  </SpecPar> " << std::endl;
00746 
00747 }
00748 
00749 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00750 void CocoaToDDLMgr::newSectPost_specPar(std::string name)
00751 {
00752    newSectPost("SpecParSection");
00753 }
00754 
00755 
00756 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00757 
00758 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00759 void CocoaToDDLMgr::newSectPre(std::string name, std::string type)
00760 {
00761    file_ << "<" << type << " label=\"" << name << "\">" << std::endl;
00762 }
00763 
00764 
00765 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00766 void CocoaToDDLMgr::newSectPost(std::string name)
00767 {
00768    file_ << "</" << name << ">" << std::endl << std::endl;
00769 }
00770 
00771 
00772 
00773 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00774 ALIbool CocoaToDDLMgr::materialIsRepeated( CocoaMaterialElementary* ma )
00775 {
00776   ALIbool isRepeated = false;
00777   std::vector<CocoaMaterialElementary*>::const_iterator ite;
00778 
00779   for(ite = theMaterialList.begin(); ite != theMaterialList.end(); ite++ ){
00780     if( *(*ite) == *ma ){
00781       isRepeated = true;
00782       break;
00783     }
00784   }
00785 
00786   return isRepeated;
00787 }
00788 
00789 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00790 std::string CocoaToDDLMgr::scrubString(const std::string& s)
00791 {
00792   std::string::const_iterator ampat;
00793   static const std::string amp = "_"; //"&amp;";
00794   std::string ret = "";
00795   for (ampat = s.begin(); ampat !=  s.end(); ampat++)
00796     {
00797      if (*ampat == '&')
00798        ret = ret + amp;
00799      else if (*ampat == '/')
00800        ret = ret + ";";
00801      else if (*ampat == ':')
00802        ret = ret + '_';
00803      else
00804        ret = ret + *ampat;
00805     }
00806   // this works when used alone.  when in this file it fails.  i don't know why.
00807   //for (ampat = s.begin(); ampat != s.end(); ampat++)
00808   //  {
00809   //    if (*ampat == '&'){
00810   //    s.insert(ampat+1, amp.begin(), amp.end());
00811   //    }
00812   //  }
00813   //  replace(s.begin(), s.end(), '/', ';');
00814   //return s;
00815   //cout << "AMP: " << ret << endl;
00816   return ret;
00817 }
00818 
00819 
00820 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00821 ALIint CocoaToDDLMgr::buildRotationNumber( OpticalObject* opto )
00822 {
00823   ALIint rotnum = -1;
00824 
00825   if(opto->rmLocal().isIdentity() ) return rotnum;
00826 
00827   std::vector<HepRotation>::const_iterator ite;
00828 
00829   int nc = 0;
00830   for( ite = theRotationList.begin(); ite != theRotationList.end(); ite++) {
00831     if( (*ite) == opto->rmLocal() ) {
00832       rotnum = nc;
00833       break;
00834     }
00835     nc++;
00836   }
00837 
00838   if( rotnum == -1 ) {
00839     theRotationList.push_back( opto->rmLocal() );
00840     rotnum = theRotationList.size()-1;
00841   }
00842 
00843   return rotnum;
00844 
00845 }
00846 

Generated on Tue Jun 9 17:23:40 2009 for CMSSW by  doxygen 1.5.4