CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/src/Fireworks/Core/src/FWGeometryTableViewManager.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Core
00004 // Class  :     FWGeometryTableViewManager
00005 // 
00006 // Implementation:
00007 //     [Notes on implementation]
00008 //
00009 // Original Author:  Alja Mrak-Tadel
00010 //         Created:  Fri Jul  8 00:40:37 CEST 2011
00011 // $Id: FWGeometryTableViewManager.cc,v 1.10 2012/04/28 01:11:02 amraktad Exp $
00012 //
00013 
00014 #include <boost/bind.hpp>
00015 
00016 #include "TFile.h"
00017 #include "TSystem.h"
00018 #include "TGeoManager.h"
00019 #include "TGeoMatrix.h"
00020 #include "TEveManager.h"
00021 
00022 #include "Fireworks/Core/interface/FWGeometryTableViewManager.h"
00023 #include "Fireworks/Core/src/FWGeometryTableView.h"
00024 #include "Fireworks/Core/src/FWOverlapTableView.h"
00025 #include "Fireworks/Core/interface/FWGeometry.h"
00026 #include "Fireworks/Core/interface/FWGUIManager.h"
00027 #include "Fireworks/Core/interface/FWColorManager.h"
00028 #include "Fireworks/Core/interface/fwLog.h"
00029 
00030 TGeoManager* FWGeometryTableViewManager::s_geoManager = 0;
00031 
00032 TGeoManager* FWGeometryTableViewManager_GetGeoManager() { return FWGeometryTableViewManager::getGeoMangeur(); }
00033 
00034 FWGeometryTableViewManager::FWGeometryTableViewManager(FWGUIManager* iGUIMgr, std::string fileName):
00035    FWViewManagerBase(),
00036    m_fileName(fileName)
00037 {
00038    FWGUIManager::ViewBuildFunctor f;
00039    f=boost::bind(&FWGeometryTableViewManager::buildView, this, _1, _2);                
00040    iGUIMgr->registerViewBuilder(FWViewType::idToName(FWViewType::kGeometryTable), f);
00041    iGUIMgr->registerViewBuilder(FWViewType::idToName(FWViewType::kOverlapTable), f);
00042 }
00043 
00044 FWGeometryTableViewManager::~FWGeometryTableViewManager()
00045 { 
00046 }
00047 
00048 
00049 FWViewBase*
00050 FWGeometryTableViewManager::buildView(TEveWindowSlot* iParent, const std::string& type)
00051 {
00052    if (!s_geoManager) setGeoManagerFromFile();
00053    boost::shared_ptr<FWGeometryTableViewBase> view;
00054 
00055    FWViewType::EType typeId = (type == FWViewType::sName[FWViewType::kGeometryTable]) ?  FWViewType::kGeometryTable : FWViewType::kOverlapTable;
00056    if (typeId == FWViewType::kGeometryTable)
00057       view.reset( new FWGeometryTableView(iParent, &colorManager()));
00058    else
00059       view.reset( new FWOverlapTableView(iParent, &colorManager()));
00060 
00061    view->setBackgroundColor();
00062    m_views.push_back(boost::shared_ptr<FWGeometryTableViewBase> (view));
00063    view->beingDestroyed_.connect(boost::bind(&FWGeometryTableViewManager::beingDestroyed, this,_1));
00064                                             
00065    return view.get();
00066 }
00067 
00068 
00069 void
00070 FWGeometryTableViewManager::beingDestroyed(const FWViewBase* iView)
00071 {
00072    for(std::vector<boost::shared_ptr<FWGeometryTableViewBase> >::iterator it=m_views.begin(); it != m_views.end(); ++it) {
00073       if(it->get() == iView) {
00074          m_views.erase(it);
00075          return;
00076       }
00077    }
00078 }
00079 
00080 void
00081 FWGeometryTableViewManager::colorsChanged()
00082 {
00083   for(std::vector<boost::shared_ptr<FWGeometryTableViewBase> >::iterator it=m_views.begin(); it != m_views.end(); ++it)
00084       (*it)->setBackgroundColor();
00085 }
00086 
00087 //______________________________________________________________________________
00088 TGeoManager*
00089 FWGeometryTableViewManager::getGeoMangeur()
00090 {
00091    // Function used in geomtery table views.
00092 
00093    assert( s_geoManager);
00094    return s_geoManager;
00095 }
00096 
00097 //______________________________________________________________________________
00098 void
00099 FWGeometryTableViewManager::setGeoManagerRuntime(TGeoManager* x)
00100 {
00101    // Function called from FWFFLooper to set geometry created in runtime.
00102 
00103    s_geoManager = x;
00104 }
00105 
00106 //______________________________________________________________________________
00107 void
00108 FWGeometryTableViewManager::setGeoManagerFromFile()
00109 { 
00110    TFile* file = FWGeometry::findFile( m_fileName.c_str() );
00111    try 
00112    {
00113       if ( ! file )
00114          throw std::runtime_error("No root file.");
00115       
00116       file->ls();
00117       
00118       s_geoManager = (TGeoManager*) file->Get("cmsGeo;1");      
00119       if ( ! s_geoManager)
00120          throw std::runtime_error("Can't find TGeoManager object in selected file.");
00121 
00122    }
00123    catch (std::runtime_error &e)
00124    {
00125       fwLog(fwlog::kError) << "Failed to find simulation geomtery file. Please set the file path with --sim-geom-file option.\n";
00126       exit(0);
00127    }
00128 }