CMS 3D CMS Logo

FWDetailViewManager.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Core
4 // Class : FWDetailViewManager
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: Chris Jones
10 // Created: Wed Mar 5 09:13:47 EST 2008
11 //
12 
13 #include <cstdio>
14 #include <boost/bind.hpp>
15 #include <algorithm>
16 #include <sstream>
17 
18 #include "TClass.h"
19 #include "TROOT.h"
20 #include "TGWindow.h"
21 #include "TGFrame.h"
22 #include "TEveManager.h"
23 #include "TEveWindowManager.h"
24 #include "TEveWindow.h"
25 #include "TQObject.h"
26 
38 
42 static std::string viewNameFrom(const std::string& iFull) {
43  std::string::size_type first = iFull.find_first_of('@');
44  std::string::size_type second = iFull.find_first_of('@', first + 1);
45  return iFull.substr(first + 1, second - first - 1);
46 }
47 //
48 // constructors and destructor
49 //
51  // force white background for all embedded canvases
52  gROOT->SetStyle("Plain");
53 
55  gEve->GetWindowManager()->Connect(
56  "WindowDeleted(TEveWindow*)", "FWDetailViewManager", this, "eveWindowDestroyed(TEveWindow*)");
57 }
58 
61  gEve->GetWindowManager()->Disconnect("WindowDeleted(TEveWindow*)", this, "eveWindowDestroyed(TEveWindow*)");
62 }
63 
64 FWDetailViewManager::ViewFrame::ViewFrame(TEveCompositeFrameInMainFrame* f,
65  std::unique_ptr<FWDetailViewBase> v,
66  TEveWindow* w)
67  : m_eveFrame(f), m_detailView(std::move(v)), m_eveWindow(w) {}
69 
71  TEveWindowSlot* slot = TEveWindow::CreateWindowMainFrame();
72  TEveCompositeFrameInMainFrame* eveFrame = (TEveCompositeFrameInMainFrame*)slot->GetEveFrame();
73 
74  // find the right viewer for this item
75  std::string typeName = edm::TypeWithDict(*(id.item()->modelType()->GetTypeInfo())).name();
76  std::vector<std::string> viewerNames = findViewersFor(typeName);
77  if (viewerNames.empty()) {
78  fwLog(fwlog::kError) << "FWDetailViewManager: don't know what detailed view to "
79  "use for object "
80  << id.item()->name() << std::endl;
81  assert(!viewerNames.empty());
82  }
83 
84  //see if one of the names matches iViewName
86  for (std::vector<std::string>::iterator it = viewerNames.begin(), itEnd = viewerNames.end(); it != itEnd; ++it) {
87  std::string t = viewNameFrom(*it);
88  //std::cout <<"'"<<iViewName<< "' '"<<t<<"'"<<std::endl;
89  if (t == iViewName) {
90  match = *it;
91  break;
92  }
93  }
94  assert(!match.empty());
95  std::unique_ptr<FWDetailViewBase> detailView{FWDetailViewFactory::get()->create(match)};
96  assert(nullptr != detailView);
97 
98  TEveWindowSlot* ws = (TEveWindowSlot*)(eveFrame->GetEveWindow());
99  detailView->init(ws);
100  detailView->build(id);
101  detailView->setBackgroundColor(m_context->colorManager()->background());
102 
103  TGMainFrame* mf = (TGMainFrame*)(eveFrame->GetParent());
104  mf->SetWindowName(Form("%s Detail View [%d]", id.item()->name().c_str(), id.index()));
105 
106  m_views.emplace_back(eveFrame, std::move(detailView), eveFrame->GetEveWindow());
107 
108  mf->MapRaised();
109 }
110 
111 std::vector<std::string> FWDetailViewManager::detailViewsFor(const FWModelId& iId) const {
112  std::string typeName = edm::TypeWithDict(*(iId.item()->modelType()->GetTypeInfo())).name();
113  std::vector<std::string> fullNames = findViewersFor(typeName);
114  std::vector<std::string> justViewNames;
115  justViewNames.reserve(fullNames.size());
116  std::transform(fullNames.begin(), fullNames.end(), std::back_inserter(justViewNames), &viewNameFrom);
117  return justViewNames;
118 }
119 namespace {
120  bool pluginComapreFunc(std::string a, std::string b) {
121  std::string::size_type as = a.find_first_of('&');
122  a = a.substr(0, as);
123  std::string::size_type bs = b.find_first_of('&');
124  b = b.substr(0, bs);
125  return a == b;
126  }
127 } // namespace
128 
129 std::vector<std::string> FWDetailViewManager::findViewersFor(const std::string& iType) const {
130  std::vector<std::string> returnValue;
131 
132  std::map<std::string, std::vector<std::string> >::const_iterator itFind = m_typeToViewers.find(iType);
133  if (itFind != m_typeToViewers.end()) {
134  return itFind->second;
135  }
136 
137  std::set<std::string> detailViews;
138 
139  std::vector<edmplugin::PluginInfo> all =
141  std::transform(all.begin(),
142  all.end(),
143  std::inserter(detailViews, detailViews.begin()),
144  boost::bind(&edmplugin::PluginInfo::name_, _1));
145  unsigned int closestMatch = 0xFFFFFFFF;
146 
147  for (std::set<std::string>::iterator it = detailViews.begin(), itEnd = detailViews.end(); it != itEnd; ++it) {
148  if (m_context->getHidePFBuilders()) {
149  std::size_t found = it->find("PF ");
150  if (found != std::string::npos)
151  continue;
152  }
153  std::string::size_type first = it->find_first_of('@');
154  std::string type = it->substr(0, first);
155 
156  //see if we match via inheritance
157  FWSimpleRepresentationChecker checker(type, "", 0, false);
158  FWRepresentationInfo info = checker.infoFor(iType);
159  bool pass = false;
160  if (closestMatch > info.proximity()) {
161  pass = true;
162  std::string::size_type firstD = it->find_first_of('&') + 1;
163  if (firstD != std::string::npos) {
164  std::stringstream ss(it->substr(firstD));
165  std::string ml;
166  while (std::getline(ss, ml, '&')) {
168  fwLog(fwlog::kDebug) << "DetailView " << *it << " requires module label " << ml << std::endl;
169  pass = false;
170  break;
171  }
172  }
173  }
174  if (pass) {
175  returnValue.push_back(*it);
176  } else {
177  std::string::size_type first = (*it).find_first_of('@');
178  std::string vn = *it;
179  vn.insert(++first, "!");
180  returnValue.push_back(vn);
181  }
182  }
183  }
184 
185  std::vector<std::string>::iterator it;
186  it = std::unique(returnValue.begin(), returnValue.end(), pluginComapreFunc);
187  returnValue.resize(std::distance(returnValue.begin(), it));
188 
189  m_typeToViewers[iType] = returnValue;
190  return returnValue;
191 }
192 
194  for (vViews_i i = m_views.begin(); i != m_views.end(); ++i)
195  (*i).m_detailView->setBackgroundColor(m_context->colorManager()->background());
196 }
197 
199  while (!m_views.empty()) {
200  m_views.front().m_eveWindow->DestroyWindowAndSlot();
201  }
202 }
203 
205  for (vViews_i i = m_views.begin(); i != m_views.end(); ++i) {
206  if (ew == i->m_eveWindow) {
207  // printf("========================== delete %s \n", ew->GetElementName());
208  m_views.erase(i);
209  break;
210  }
211  }
212 }
const CategoryToInfos & categoryToInfos() const
Definition: PluginManager.h:83
type
Definition: HCALResponse.h:21
static const TGPicture * info(bool iBackgroundIsBlack)
Color_t background() const
virtual bool hasModuleLabel(std::string &moduleLabel)=0
const double w
Definition: UKUtility.cc:23
FWColorManager * colorManager() const
Definition: Context.h:58
vViews_t::iterator vViews_i
uint16_t size_type
static std::string viewNameFrom(const std::string &iFull)
std::vector< std::string > findViewersFor(const std::string &) const
unsigned int proximity() const
measures how &#39;close&#39; this representation is to the type in question, the large the number the farther...
void eveWindowDestroyed(TEveWindow *)
U second(std::pair< T, U > const &p)
std::string name() const
std::map< std::string, std::vector< std::string > > m_typeToViewers
def unique(seq, keepstr=True)
Definition: tier0.py:24
bool getHidePFBuilders() const
Definition: Context.h:80
double f[11][100]
fireworks::Context * m_context
ViewFrame(TEveCompositeFrameInMainFrame *f, std::unique_ptr< FWDetailViewBase > v, TEveWindow *w)
#define fwLog(_level_)
Definition: fwLog.h:45
FWJobMetadataManager * metadataManager() const
Definition: Context.h:60
double b
Definition: hdecay.h:118
std::vector< std::string > detailViewsFor(const FWModelId &) const
void openDetailViewFor(const FWModelId &, const std::string &)
double a
Definition: hdecay.h:119
std::string name_
Definition: PluginInfo.h:29
const TClass * modelType() const
Definition: FWEventItem.cc:464
FWDetailViewManager(fireworks::Context *)
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
sigc::signal< void > colorsHaveChanged_
static PluginManager * get()
const FWEventItem * item() const
Definition: FWModelId.h:39
def move(src, dest)
Definition: eostools.py:511
FWRepresentationInfo infoFor(const std::string &iTypeName) const override
unsigned transform(const HcalDetId &id, unsigned transformCode)