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/FWGeometry.h"
00024 #include "Fireworks/Core/interface/FWGUIManager.h"
00025 #include "Fireworks/Core/interface/FWColorManager.h"
00026 #include "Fireworks/Core/interface/fwLog.h"
00027
00028 TGeoManager* FWGeometryTableViewManager::s_geoManager = 0;
00029
00030 FWGeometryTableViewManager::FWGeometryTableViewManager(FWGUIManager* iGUIMgr, std::string fileName):
00031 FWViewManagerBase(),
00032 m_fileName(fileName)
00033 {
00034 FWGUIManager::ViewBuildFunctor f;
00035 f=boost::bind(&FWGeometryTableViewManager::buildView, this, _1, _2);
00036 iGUIMgr->registerViewBuilder(FWViewType::idToName(FWViewType::kGeometryTable), f);
00037 }
00038
00039 FWGeometryTableViewManager::~FWGeometryTableViewManager()
00040 {
00041 }
00042
00043
00044 FWViewBase*
00045 FWGeometryTableViewManager::buildView(TEveWindowSlot* iParent, const std::string& )
00046 {
00047 boost::shared_ptr<FWGeometryTableView> view;
00048 if (!s_geoManager) initGeoManager();
00049 view.reset( new FWGeometryTableView(iParent, &colorManager(), (!s_geoManager) ? 0 : s_geoManager->GetTopNode(), (!s_geoManager) ? 0 : s_geoManager->GetListOfVolumes()));
00050
00051 view->setBackgroundColor();
00052 m_views.push_back(boost::shared_ptr<FWGeometryTableView> (view));
00053 view->beingDestroyed_.connect(boost::bind(&FWGeometryTableViewManager::beingDestroyed, this,_1));
00054
00055 return view.get();
00056 }
00057
00058
00059 void
00060 FWGeometryTableViewManager::beingDestroyed(const FWViewBase* iView)
00061 {
00062 for(std::vector<boost::shared_ptr<FWGeometryTableView> >::iterator it=m_views.begin(); it != m_views.end(); ++it) {
00063 if(it->get() == iView) {
00064 m_views.erase(it);
00065 return;
00066 }
00067 }
00068 }
00069
00070 void
00071 FWGeometryTableViewManager::colorsChanged()
00072 {
00073 for(std::vector<boost::shared_ptr<FWGeometryTableView> >::iterator it=m_views.begin(); it != m_views.end(); ++it)
00074 (*it)->setBackgroundColor();
00075 }
00076
00077
00078 void
00079 FWGeometryTableViewManager::initGeoManager()
00080 {
00081 TGeoManager *old = gGeoManager;
00082 TGeoIdentity *old_id = gGeoIdentity;
00083 gGeoManager = 0;
00084
00085 TFile* file = FWGeometry::findFile( m_fileName.c_str() );
00086
00087 try
00088 {
00089 if ( ! file )
00090 throw std::runtime_error("No root file.");
00091
00092 file->ls();
00093
00094 if ( !file->Get("cmsGeo;1"))
00095 throw std::runtime_error("Can't find TGeoManager object in selected file.");
00096 s_geoManager = (TGeoManager*) file->Get("cmsGeo;1");
00097 }
00098 catch (std::runtime_error &e)
00099 {
00100 fwLog(fwlog::kError) << "Failed to find simulation geomtery file. Please set the file path with --sim-geom-file option.\n";
00101 exit(0);
00102 }
00103 gGeoManager = old;
00104 gGeoIdentity = old_id;
00105 }