CMS 3D CMS Logo

SolidsForOnline.cc

Go to the documentation of this file.
00001 #include <memory>
00002 
00003 #include <FWCore/Framework/interface/EDAnalyzer.h>
00004 #include <FWCore/Framework/interface/EventSetup.h>
00005 #include <FWCore/Framework/interface/ESHandle.h>
00006 #include <FWCore/Framework/interface/MakerMacros.h>
00007 
00008 #include <DetectorDescription/Core/interface/DDCompactView.h>
00009 #include <DetectorDescription/Core/interface/DDValue.h>
00010 #include "DetectorDescription/Core/interface/DDName.h"
00011 #include "DetectorDescription/Core/interface/DDSolid.h"
00012 
00013 #include <Geometry/Records/interface/IdealGeometryRecord.h>
00014 
00015 #include <iostream>
00016 #include <istream>
00017 #include <fstream>
00018 #include <string>
00019 
00020 
00021 class SolidsForOnline : public edm::EDAnalyzer {
00022 
00023 public:
00024  
00025   explicit SolidsForOnline( const edm::ParameterSet& );
00026   ~SolidsForOnline();
00027   
00028   virtual void analyze( const edm::Event&, const edm::EventSetup& );
00029   virtual void beginJob( const edm::EventSetup& );
00030   
00031 private: 
00032 
00033   std::string filename_;  
00034 };
00035 
00036 SolidsForOnline::SolidsForOnline( const edm::ParameterSet& iConfig ) { }
00037 
00038 
00039 SolidsForOnline::~SolidsForOnline() { }
00040 
00041 void SolidsForOnline::analyze( const edm::Event& iEvent, const edm::EventSetup& iSetup ) { 
00042   std::cout << "analyze does nothing" << std::endl;
00043 }
00044 
00045 void SolidsForOnline::beginJob( const edm::EventSetup& iSetup ) {
00046 
00047 // TRD1 and Trapezoid can be in the same files.
00048 
00049   std::string solidsFileName("SOLIDS.dat"); //added by Jie Chen
00050   std::string boxFileName("BOXES.dat");
00051 
00052   std::string tubesFileName("TUBES.dat");
00053   std::string polyHedraFileName("POLYHEDRAS.dat");
00054   std::string polyConeFileName("POLYCONES.dat");
00055   std::string conesFileName("CONES.dat");
00056   std::string pseudoTrapFileName("PSEUDOTRAPEZOIDS.dat");
00057   std::string trapFileName("TRAPEZOIDS.dat");
00058   std::string boolSolidsFileName("BOOLEANSOLIDS.dat");
00059   std::string reflectionSolidsFileName("REFLECTIONSOLIDS.dat");
00060   std::string torusFileName("TORUS.dat");
00061 
00062   std::ofstream solidsOS(solidsFileName.c_str());
00063   std::ofstream boxOS(boxFileName.c_str());
00064   std::ofstream tubeOS(tubesFileName.c_str());
00065   std::ofstream polyHOS(polyHedraFileName.c_str());
00066   std::ofstream polyCOS(polyConeFileName.c_str());
00067   std::ofstream coneOS(conesFileName.c_str());
00068   std::ofstream ptrapOS(pseudoTrapFileName.c_str());
00069   std::ofstream trapOS(trapFileName.c_str());
00070   std::ofstream boolOS(boolSolidsFileName.c_str());
00071   std::ofstream reflectionOS(reflectionSolidsFileName.c_str());
00072   std::ofstream torusOS(torusFileName.c_str());
00073 
00074   std::cout << "SolidsForOnline Analyzer..." << std::endl;
00075 
00076   edm::ESHandle<DDCompactView> pDD;
00077 
00078   iSetup.get<IdealGeometryRecord>().get( "", pDD );
00079 
00080   const DDCompactView & cpv = *pDD;
00081   DDCompactView::graph_type gra = cpv.graph();
00082 
00083   DDSolid::iterator<DDSolid> sit(DDSolid::begin()), sed(DDSolid::end());
00084   for (; sit != sed; ++sit) {
00085     if (! sit->isDefined().second) continue;  
00086     const DDSolid& solid = *sit;
00088     solidsOS<<solid.name()<<","<<DDSolidShapesName::name(solid.shape())
00089             << std::endl;
00090     
00091 
00092     switch (solid.shape()) 
00093       {
00094       case ddunion:
00095         {
00096           //for bool solid
00097           DDBooleanSolid boolSolid(solid);
00098           boolOS << boolSolid.name() << "," ;
00099           boolOS << "U";
00100           boolOS << "," << boolSolid.translation().x()
00101                  << "," << boolSolid.translation().y()
00102                  << "," << boolSolid.translation().z()
00103                  << "," << boolSolid.solidA().name() 
00104                  << "," << boolSolid.solidB().name()
00105                  << "," << boolSolid.rotation().name()
00106                  << std::endl;
00107 
00108           break;
00109         }
00110       case ddsubtraction:
00111         {
00112           DDBooleanSolid boolSolid(solid);
00113           boolOS << boolSolid.name() << "," ;
00114           boolOS << "S";
00115           boolOS << "," << boolSolid.translation().x()
00116                  << "," << boolSolid.translation().y()
00117                  << "," << boolSolid.translation().z()
00118                  << "," << boolSolid.solidA().name() 
00119                  << "," << boolSolid.solidB().name()
00120                  << "," << boolSolid.rotation().name()
00121                  << std::endl;
00122           break;
00123         }
00124       case ddintersection: 
00125         {         
00126 
00127           //for bool solid
00128           DDBooleanSolid boolSolid(solid);
00129           // if translation is == identity there are no parameters.
00130           // if there is no rotation the name will be ":"
00131           //std::string rotName = boolSolid.rotation().toString();
00132           //if (rotName == ":") {
00133           //  rotName = "rotations:UNIT";
00134           //}
00135           boolOS << boolSolid.name() << "," ;
00136           boolOS << "I";
00137           boolOS << "," << boolSolid.translation().x()
00138                  << "," << boolSolid.translation().y()
00139                  << "," << boolSolid.translation().z()
00140                  << "," << boolSolid.solidA().name() 
00141                  << "," << boolSolid.solidB().name()
00142                  << "," << boolSolid.rotation().name()
00143                  << std::endl;
00144           
00145           break;
00146           
00147         }
00148       case ddreflected:
00149         { 
00150           DDReflectionSolid reflection(solid);
00151           reflectionOS<<reflection.name()<<","
00152                       <<reflection.unreflected().name()
00153                       <<std::endl;
00154           break;
00155         }
00156       case ddbox:
00157         {
00158           DDBox box(solid);
00159           //std::cout<<"box shape is"<<solid.shape()<<std::endl;
00160           boxOS<<box.name()<<",";
00161           boxOS<<2.0*box.halfX()<<","<<2.0*box.halfY()<<","<<2.0*box.halfZ()<<std::endl;
00162           break;
00163         }
00164         
00165       case ddpseudotrap:
00166         {
00167           DDPseudoTrap pseudoTrap(solid);
00168           
00169           ptrapOS<<pseudoTrap.name() <<",";
00170           ptrapOS<<pseudoTrap.x1() <<","<<pseudoTrap.x2() <<","
00171                  <<pseudoTrap.halfZ()*2. <<","<<pseudoTrap.y1() <<","
00172                  <<pseudoTrap.y2() <<","<<pseudoTrap.radius()<<","
00173                  <<pseudoTrap.atMinusZ()
00174                  << std::endl;
00175           
00176           break;
00177         }
00178         
00179       case ddtubs:
00180         {
00181           //same as ddtrunctubs, Tube element is simply a Tube Section 
00182           //with the angle going from zero to 360 degrees. 
00183           //cutAtStart, cutAtDelta,  and  cutInside. are all zero 
00184           //then they are tubes
00185           DDTubs tubs(solid);
00186           tubeOS<<tubs.name()<<","<<tubs.rIn()<<","
00187                 <<tubs.rOut()<<","<<tubs.zhalf()*2.0<<","
00188                 <<tubs.startPhi()<<","<<tubs.deltaPhi()<<"," 
00189                 <<"0"<<","<<"0"<<","
00190                 <<"0"
00191                 <<std::endl;
00192 
00193           break;
00194         }
00195       case ddtrap: // trd1s is included into this case
00196         {    
00197           DDTrap trap(solid);     
00198           trapOS<<trap.name()<<",";
00199           trapOS<<trap.alpha1()<<","<<trap.alpha2()<<","
00200                 <<trap.x1()<<","<<trap.x2()<<","
00201                 <<trap.halfZ()*2.0<<","<<trap.y1()<<","
00202                 <<trap.y2()<<","
00203                 <<trap.phi()<<","<<trap.theta()<<","
00204                 <<trap.x3()<<","<<trap.x4()
00205                 <<std::endl;
00206           break;
00207         }
00208       case ddcons:
00209         {
00210           DDCons cons(solid);
00211           coneOS<<cons.name()<<","<<cons.zhalf()*2.0<<","
00212                 <<cons.rInMinusZ()<<","
00213                 <<cons.rOutMinusZ()<<","<<cons.rInPlusZ()<<","
00214                 <<cons.rOutPlusZ()<<","<<cons.phiFrom()<<","
00215                 <<cons.deltaPhi()
00216                 <<std::endl;
00217           
00218           break;
00219         }
00220 
00221       case ddpolycone_rz:
00222         {
00223           //rz_zs=rz if it's ddpolycone_rz
00224           DDPolycone polyCone(solid);
00225           polyCOS<<polyCone.name()<<","<<polyCone.startPhi()
00226                  <<","<<polyCone.deltaPhi()<<","<<"RZ"
00227                  <<std::endl;
00228           break;
00229         }
00230       case ddpolyhedra_rz:
00231         {
00232           DDPolyhedra  polyHedra(solid);
00233           polyHOS<<polyHedra.name()<<",";
00234           polyHOS<<polyHedra.sides()<<","<<polyHedra.startPhi()
00235                  <<","<<polyHedra.deltaPhi()<<","<<"RZ"
00236                  <<std::endl;
00237           break;
00238         }
00239       case ddpolycone_rrz:{
00240           //rz_zs=zs if it's ddpolycone_rrz
00241           DDPolycone polyCone(solid);
00242           polyCOS<<polyCone.name()<<","<<polyCone.startPhi()
00243                  <<","<<polyCone.deltaPhi()<<","<<"ZS"
00244                  <<std::endl;   
00245         break;
00246       }
00247       case ddpolyhedra_rrz:
00248         {
00249 
00250           DDPolyhedra  polyHedra(solid);
00251           polyHOS<<polyHedra.name()<<",";
00252           polyHOS<<polyHedra.sides()<<","<<polyHedra.startPhi()
00253                  <<","<<polyHedra.deltaPhi()<<","<<"ZS"
00254                  <<std::endl;
00255           break;
00256         }
00257        
00258       case ddtrunctubs:{
00259 
00260           DDTruncTubs tubs(solid);
00261           tubeOS<<tubs.name()<<","<<tubs.rIn()<<","
00262                 <<tubs.rOut()<<","<<tubs.zHalf()*2.0<<","
00263                 <<tubs.startPhi()<<","<<tubs.deltaPhi()<<"," 
00264                 <<tubs.cutAtStart()<<","<<tubs.cutAtDelta()<<","
00265                 <<tubs.cutInside()
00266                 <<std::endl;
00267           break;
00268       }
00269 
00270       case ddtorus: {
00271         DDTorus torus(solid);
00272         torusOS<<torus.name()<<","<<torus.rMin()<<","
00273                <<torus.rMax()<<","<<torus.rTorus()<<","
00274                <<torus.startPhi()<<","<<torus.deltaPhi()
00275                <<std::endl;
00276         break;
00277       }
00278 
00279       case ddshapeless:{
00280         //      DDShapelessSolid shapeless(solid);
00281         //shapelessOS<<shapeless.name()
00282         // <<std::endl;
00283 
00284 //      return new PSolid( solid.toString(), solid.parameters()
00285 //                         , solid.shape() );
00286         break;
00287       }      
00288       case dd_not_init:
00289       default:
00290         throw DDException("DDDToPersFactory::solid(...) either not inited or no such solid.");
00291         break;
00292       }
00293   
00294 
00295   }
00296   solidsOS.close();
00297   boxOS.close();
00298 
00299   tubeOS.close();
00300   polyHOS.close();
00301   polyCOS.close();
00302   coneOS.close();
00303   ptrapOS.close();
00304   trapOS.close();
00305   boolOS.close();
00306   reflectionOS.close();
00307 }
00308 
00309 //define this as a plug-in
00310 DEFINE_FWK_MODULE(SolidsForOnline);

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