CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/Fireworks/Geometry/plugins/DumpFWTGeoRecoGeometry.cc

Go to the documentation of this file.
00001 #include "FWCore/Framework/interface/EDAnalyzer.h"
00002 #include "FWCore/Framework/interface/MakerMacros.h"
00003 #include "FWCore/Framework/interface/ESTransientHandle.h"
00004 #include "FWCore/Framework/interface/ESHandle.h"
00005 #include "FWCore/Framework/interface/EventSetup.h"
00006 #include "Fireworks/Geometry/interface/FWTGeoRecoGeometry.h"
00007 #include "Fireworks/Geometry/interface/FWTGeoRecoGeometryRecord.h"
00008 
00009 #include "TGeoManager.h"
00010 #include "TFile.h"
00011 #include "TTree.h"
00012 #include "TError.h"
00013 
00014 class DumpFWTGeoRecoGeometry : public edm::EDAnalyzer
00015 {
00016 public:
00017   explicit DumpFWTGeoRecoGeometry( const edm::ParameterSet& config );
00018   virtual ~DumpFWTGeoRecoGeometry( void ) {}
00019 
00020 private:
00021   virtual void analyze( const edm::Event& event, const edm::EventSetup& eventSetup );
00022   virtual void beginJob( void );
00023   virtual void endJob( void );
00024 
00025   int m_level;
00026 };
00027 
00028 DumpFWTGeoRecoGeometry::DumpFWTGeoRecoGeometry( const edm::ParameterSet& config )
00029   : m_level( config.getUntrackedParameter<int>( "level", 1 ))
00030 {}
00031 
00032 void
00033 DumpFWTGeoRecoGeometry::analyze( const edm::Event& event, const edm::EventSetup& eventSetup )
00034 {
00035   using namespace edm;
00036 
00037   ESTransientHandle<FWTGeoRecoGeometry> geoh;
00038   eventSetup.get<FWTGeoRecoGeometryRecord>().get( geoh );
00039   TGeoManager *geom = const_cast<TGeoManager*>( geoh.product()->manager());
00040 
00041   std::stringstream s;
00042   s << "cmsTGeoRecoGeom" << m_level << ".root";
00043   TFile file( s.str().c_str(), "RECREATE" );
00044    
00045   TTree *tree = new TTree( "idToGeo", "Raw detector id association with geometry" );
00046   UInt_t v_id;
00047   TString *v_path( new TString );
00048   char v_name[1000];
00049   Float_t v_vertex[24];
00050   Float_t v_params[9];
00051 
00052   tree->SetBranchStyle( 0 );
00053   tree->Branch( "id", &v_id, "id/i" );
00054   tree->Branch( "path", &v_name, "path/C" );
00055   tree->Branch( "points", &v_vertex, "points[24]/F" );
00056   tree->Branch( "topology", &v_params, "topology[9]/F" );
00057 
00058   for( std::map<unsigned int, FWTGeoRecoGeometry::Info>::const_iterator it = geoh.product()->idToName.begin(),
00059                                                                        end = geoh.product()->idToName.end();
00060        it != end; ++it )
00061   {
00062     v_id = it->first;
00063     *v_path = it->second.name.c_str();
00064     for( unsigned int i = 0; i < 24; ++i )
00065       v_vertex[i] = it->second.points[i];
00066     for( unsigned int i = 0; i < 9; ++i )
00067       v_params[i] = it->second.topology[i];
00068     assert( it->second.name.size() < 1000 );
00069     strncpy( v_name, it->second.name.c_str(), 1000 );
00070     tree->Fill();
00071   }
00072   file.WriteTObject( &*geom );
00073   file.WriteTObject( tree );
00074   file.Close();
00075 }
00076 
00077 void 
00078 DumpFWTGeoRecoGeometry::beginJob( void )
00079 {}
00080 
00081 void 
00082 DumpFWTGeoRecoGeometry::endJob( void )
00083 {}
00084 
00085 DEFINE_FWK_MODULE( DumpFWTGeoRecoGeometry );