File indexing completed on 2024-04-06 12:11:39
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #include <functional>
0014
0015 #include "TFile.h"
0016 #include "TSystem.h"
0017 #include "TGeoManager.h"
0018 #include "TGeoMatrix.h"
0019 #include "TEveManager.h"
0020
0021 #include "Fireworks/Core/interface/FWGeometryTableViewManager.h"
0022 #include "Fireworks/Core/src/FWGeometryTableView.h"
0023 #include "Fireworks/Core/src/FWOverlapTableView.h"
0024 #include "Fireworks/Core/interface/FWGeometry.h"
0025 #include "Fireworks/Core/interface/FWGUIManager.h"
0026 #include "Fireworks/Core/interface/FWColorManager.h"
0027 #include "Fireworks/Core/interface/fwLog.h"
0028
0029 TGeoManager* FWGeometryTableViewManager::s_geoManager = nullptr;
0030
0031 TGeoManager* FWGeometryTableViewManager_GetGeoManager() { return FWGeometryTableViewManager::getGeoMangeur(); }
0032
0033 FWGeometryTableViewManager::FWGeometryTableViewManager(FWGUIManager* iGUIMgr, std::string fileName, std::string geoName)
0034 : FWViewManagerBase(), m_fileName(fileName), m_TGeoName(geoName) {
0035 FWGUIManager::ViewBuildFunctor f;
0036 f = std::bind(&FWGeometryTableViewManager::buildView, this, std::placeholders::_1, std::placeholders::_2);
0037 iGUIMgr->registerViewBuilder(FWViewType::idToName(FWViewType::kGeometryTable), f);
0038 iGUIMgr->registerViewBuilder(FWViewType::idToName(FWViewType::kOverlapTable), f);
0039 }
0040
0041 FWGeometryTableViewManager::~FWGeometryTableViewManager() {}
0042
0043 FWViewBase* FWGeometryTableViewManager::buildView(TEveWindowSlot* iParent, const std::string& type) {
0044 if (!s_geoManager)
0045 setGeoManagerFromFile();
0046 std::shared_ptr<FWGeometryTableViewBase> view;
0047
0048 FWViewType::EType typeId =
0049 (type == FWViewType::sName[FWViewType::kGeometryTable]) ? FWViewType::kGeometryTable : FWViewType::kOverlapTable;
0050 if (typeId == FWViewType::kGeometryTable)
0051 view.reset(new FWGeometryTableView(iParent, &colorManager()));
0052 else
0053 view.reset(new FWOverlapTableView(iParent, &colorManager()));
0054
0055 view->setBackgroundColor();
0056 m_views.push_back(std::shared_ptr<FWGeometryTableViewBase>(view));
0057 view->beingDestroyed_.connect(std::bind(&FWGeometryTableViewManager::beingDestroyed, this, std::placeholders::_1));
0058
0059 return view.get();
0060 }
0061
0062 void FWGeometryTableViewManager::beingDestroyed(const FWViewBase* iView) {
0063 for (std::vector<std::shared_ptr<FWGeometryTableViewBase> >::iterator it = m_views.begin(); it != m_views.end();
0064 ++it) {
0065 if (it->get() == iView) {
0066 m_views.erase(it);
0067 return;
0068 }
0069 }
0070 }
0071
0072 void FWGeometryTableViewManager::colorsChanged() {
0073 for (std::vector<std::shared_ptr<FWGeometryTableViewBase> >::iterator it = m_views.begin(); it != m_views.end(); ++it)
0074 (*it)->setBackgroundColor();
0075 }
0076
0077
0078 TGeoManager* FWGeometryTableViewManager::getGeoMangeur() {
0079
0080
0081 assert(s_geoManager);
0082 return s_geoManager;
0083 }
0084
0085
0086 void FWGeometryTableViewManager::setGeoManagerRuntime(TGeoManager* x) {
0087
0088
0089 s_geoManager = x;
0090 }
0091
0092
0093 void FWGeometryTableViewManager::setGeoManagerFromFile() {
0094 TFile* file = FWGeometry::findFile(m_fileName.c_str());
0095 fwLog(fwlog::kInfo) << "Geometry table file: " << m_fileName.c_str() << std::endl;
0096 try {
0097 if (!file) {
0098
0099 s_geoManager = TGeoManager::Import(m_fileName.c_str(), m_TGeoName.c_str());
0100 } else {
0101 file->ls();
0102 s_geoManager = (TGeoManager*)file->Get(m_TGeoName.c_str());
0103 }
0104 if (!s_geoManager)
0105 throw std::runtime_error("Can't find TGeoManager object in selected file.");
0106
0107 } catch (std::runtime_error& e) {
0108 fwLog(fwlog::kError) << e.what();
0109 exit(0);
0110 }
0111 }