CMS 3D CMS Logo

FWGeometryTableViewManager.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Core
4 // Class : FWGeometryTableViewManager
5 //
6 // Implementation:
7 // [Notes on implementation]
8 //
9 // Original Author: Alja Mrak-Tadel
10 // Created: Fri Jul 8 00:40:37 CEST 2011
11 //
12 
13 #include <functional>
14 
15 #include "TFile.h"
16 #include "TSystem.h"
17 #include "TGeoManager.h"
18 #include "TGeoMatrix.h"
19 #include "TEveManager.h"
20 
28 
29 TGeoManager* FWGeometryTableViewManager::s_geoManager = nullptr;
30 
32 
34  : FWViewManagerBase(), m_fileName(fileName), m_TGeoName(geoName) {
36  f = std::bind(&FWGeometryTableViewManager::buildView, this, std::placeholders::_1, std::placeholders::_2);
39 }
40 
42 
44  if (!s_geoManager)
46  std::shared_ptr<FWGeometryTableViewBase> view;
47 
48  FWViewType::EType typeId =
50  if (typeId == FWViewType::kGeometryTable)
51  view.reset(new FWGeometryTableView(iParent, &colorManager()));
52  else
53  view.reset(new FWOverlapTableView(iParent, &colorManager()));
54 
55  view->setBackgroundColor();
56  m_views.push_back(std::shared_ptr<FWGeometryTableViewBase>(view));
57  view->beingDestroyed_.connect(std::bind(&FWGeometryTableViewManager::beingDestroyed, this, std::placeholders::_1));
58 
59  return view.get();
60 }
61 
63  for (std::vector<std::shared_ptr<FWGeometryTableViewBase> >::iterator it = m_views.begin(); it != m_views.end();
64  ++it) {
65  if (it->get() == iView) {
66  m_views.erase(it);
67  return;
68  }
69  }
70 }
71 
73  for (std::vector<std::shared_ptr<FWGeometryTableViewBase> >::iterator it = m_views.begin(); it != m_views.end(); ++it)
74  (*it)->setBackgroundColor();
75 }
76 
77 //______________________________________________________________________________
79  // Function used in geometry table views.
80 
82  return s_geoManager;
83 }
84 
85 //______________________________________________________________________________
87  // Function called from FWFFLooper to set geometry created in runtime.
88 
89  s_geoManager = x;
90 }
91 
92 //______________________________________________________________________________
94  TFile* file = FWGeometry::findFile(m_fileName.c_str());
95  fwLog(fwlog::kInfo) << "Geometry table file: " << m_fileName.c_str() << std::endl;
96  try {
97  if (!file) {
98  // Try it as a GDML file
99  s_geoManager = TGeoManager::Import(m_fileName.c_str(), m_TGeoName.c_str());
100  } else {
101  file->ls();
102  s_geoManager = (TGeoManager*)file->Get(m_TGeoName.c_str());
103  }
104  if (!s_geoManager)
105  throw std::runtime_error("Can't find TGeoManager object in selected file.");
106 
107  } catch (std::runtime_error& e) {
108  fwLog(fwlog::kError) << e.what();
109  exit(0);
110  }
111 }
static TFile * findFile(const char *fileName)
Definition: FWGeometry.cc:38
TGeoManager * FWGeometryTableViewManager_GetGeoManager()
FWColorManager & colorManager() const
std::vector< std::shared_ptr< FWGeometryTableViewBase > > m_views
assert(be >=bs)
void registerViewBuilder(const std::string &iName, ViewBuildFunctor &iBuilder)
static std::string sName[kTypeSize]
Definition: FWViewType.h:61
void beingDestroyed(const FWViewBase *iView)
double f[11][100]
std::function< FWViewBase *(TEveWindowSlot *, const std::string &)> ViewBuildFunctor
Definition: FWGUIManager.h:98
#define fwLog(_level_)
Definition: fwLog.h:45
FWGeometryTableViewManager(FWGUIManager *, std::string fileName, std::string geoName)
static const std::string & idToName(int)
Definition: FWViewType.cc:72
static void setGeoManagerRuntime(TGeoManager *)
float x
FWViewBase * buildView(TEveWindowSlot *iParent, const std::string &type)
def exit(msg="")