CMS 3D CMS Logo

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