Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
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
00021 #include "Fireworks/Core/interface/FWGeometryTableViewManager.h"
00022 #include "Fireworks/Core/interface/FWGeometryTableView.h"
00023 #include "Fireworks/Core/interface/FWGUIManager.h"
00024 #include "Fireworks/Core/interface/FWColorManager.h"
00025 #include "Fireworks/Core/interface/fwLog.h"
00026
00027 TGeoManager* FWGeometryTableViewManager::s_geoManager = 0;
00028
00029 FWGeometryTableViewManager::FWGeometryTableViewManager(FWGUIManager* iGUIMgr, std::string fileName):
00030 FWViewManagerBase(),
00031 m_fileName(fileName)
00032 {
00033 FWGUIManager::ViewBuildFunctor f;
00034 f=boost::bind(&FWGeometryTableViewManager::buildView, this, _1, _2);
00035 iGUIMgr->registerViewBuilder(FWViewType::idToName(FWViewType::kGeometryTable), f);
00036 }
00037
00038 FWGeometryTableViewManager::~FWGeometryTableViewManager()
00039 {
00040 }
00041
00042
00043 class FWViewBase*
00044 FWGeometryTableViewManager::buildView(TEveWindowSlot* iParent, const std::string& )
00045 {
00046 boost::shared_ptr<FWGeometryTableView> view;
00047 if (!s_geoManager) initGeoManager();
00048 view.reset( new FWGeometryTableView(iParent, &colorManager(), s_geoManager->GetTopNode(), s_geoManager->GetListOfVolumes()));
00049
00050 view->setBackgroundColor();
00051 m_views.push_back(boost::shared_ptr<FWGeometryTableView> (view));
00052 view->beingDestroyed_.connect(boost::bind(&FWGeometryTableViewManager::beingDestroyed, this,_1));
00053
00054 return view.get();
00055 }
00056
00057
00058 void
00059 FWGeometryTableViewManager::beingDestroyed(const FWViewBase* iView)
00060 {
00061 for(std::vector<boost::shared_ptr<FWGeometryTableView> >::iterator it=m_views.begin(); it != m_views.end(); ++it) {
00062 if(it->get() == iView) {
00063 m_views.erase(it);
00064 return;
00065 }
00066 }
00067 }
00068
00069 void
00070 FWGeometryTableViewManager::colorsChanged()
00071 {
00072 for(std::vector<boost::shared_ptr<FWGeometryTableView> >::iterator it=m_views.begin(); it != m_views.end(); ++it)
00073 (*it)->setBackgroundColor();
00074 }
00075
00076
00077
00078
00079 void
00080 FWGeometryTableViewManager::initGeoManager()
00081 {
00082 TGeoManager *old = gGeoManager;
00083 TGeoIdentity *old_id = gGeoIdentity;
00084 gGeoManager = 0;
00085
00086
00087 TString filePath = m_fileName;
00088
00089 if (gSystem->AccessPathName(filePath.Data()))
00090 {
00091 if( m_fileName[0] == '.' && m_fileName[1] == '/' )
00092 {
00093 filePath = Form("%s/%s", gSystem->Getenv( "PWD" ), &m_fileName.c_str()[1]);
00094 }
00095 else
00096 {
00097
00098
00099 filePath = Form("%s/%s", gSystem->Getenv( "PWD" ),m_fileName.c_str() );
00100
00101 if(gSystem->AccessPathName(filePath.Data())) {
00102
00103 filePath = Form("%s/%s", gSystem->Getenv( "CMSSW_BASE" ),m_fileName.c_str() );
00104 }
00105 }
00106 }
00107
00108
00109 if( !gSystem->AccessPathName(filePath.Data()))
00110 {
00111 TFile* file = new TFile( filePath.Data(), "READ");
00112 try {
00113 if ( ! file )
00114 throw std::runtime_error("No root file.");
00115
00116 file->ls();
00117
00118 if ( !file->Get("cmsGeo;1"))
00119 throw std::runtime_error("Can't find TGeoManager object in selected file.");
00120 s_geoManager = (TGeoManager*) file->Get("cmsGeo;1");
00121
00122 }
00123 catch (std::runtime_error &e)
00124 {
00125 fwLog(fwlog::kError) << "Failed to load simulation geomtery.\n";
00126 }
00127 }
00128
00129 gGeoManager = old;
00130 gGeoIdentity = old_id;
00131 }