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 #include "TObjString.h"
27 
39 
43 static std::string viewNameFrom(const std::string& iFull) {
44  std::string::size_type first = iFull.find_first_of('@');
45  std::string::size_type second = iFull.find_first_of('@', first + 1);
46  return iFull.substr(first + 1, second - first - 1);
47 }
48 //
49 // constructors and destructor
50 //
52  // force white background for all embedded canvases
53  gROOT->SetStyle("Plain");
54 
56  gEve->GetWindowManager()->Connect(
57  "WindowDeleted(TEveWindow*)", "FWDetailViewManager", this, "eveWindowDestroyed(TEveWindow*)");
58 }
59 
62  gEve->GetWindowManager()->Disconnect("WindowDeleted(TEveWindow*)", this, "eveWindowDestroyed(TEveWindow*)");
63 }
64 
65 FWDetailViewManager::ViewFrame::ViewFrame(TEveCompositeFrameInMainFrame* f,
66  std::unique_ptr<FWDetailViewBase> v,
67  TEveWindow* w)
68  : m_eveFrame(f), m_detailView(std::move(v)), m_eveWindow(w) {}
70 
72  TEveWindowSlot* slot = TEveWindow::CreateWindowMainFrame();
73  TEveCompositeFrameInMainFrame* eveFrame = (TEveCompositeFrameInMainFrame*)slot->GetEveFrame();
74 
75  // find the right viewer for this item
76  std::string typeName = edm::TypeWithDict(*(id.item()->modelType()->GetTypeInfo())).name();
77  std::vector<std::string> viewerNames = findViewersFor(typeName);
78  if (viewerNames.empty()) {
79  fwLog(fwlog::kError) << "FWDetailViewManager: don't know what detailed view to "
80  "use for object "
81  << id.item()->name() << std::endl;
82  assert(!viewerNames.empty());
83  }
84 
85  //see if one of the names matches iViewName
87  for (std::vector<std::string>::iterator it = viewerNames.begin(), itEnd = viewerNames.end(); it != itEnd; ++it) {
88  std::string t = viewNameFrom(*it);
89  //std::cout <<"'"<<iViewName<< "' '"<<t<<"'"<<std::endl;
90  if (t == iViewName) {
91  match = *it;
92  break;
93  }
94  }
95  assert(!match.empty());
96  std::unique_ptr<FWDetailViewBase> detailView{FWDetailViewFactory::get()->create(match)};
97  assert(nullptr != detailView);
98 
99  TEveWindowSlot* ws = (TEveWindowSlot*)(eveFrame->GetEveWindow());
100  detailView->init(ws);
101  detailView->build(id);
102  detailView->setBackgroundColor(m_context->colorManager()->background());
103 
104  TGMainFrame* mf = (TGMainFrame*)(eveFrame->GetParent());
105  mf->SetWindowName(Form("%s Detail View [%d]", id.item()->name().c_str(), id.index()));
106 
107  m_views.emplace_back(eveFrame, std::move(detailView), eveFrame->GetEveWindow());
108 
109  mf->MapRaised();
110 }
111 
112 std::vector<std::string> FWDetailViewManager::detailViewsFor(const FWModelId& iId) const {
113  std::string typeName = edm::TypeWithDict(*(iId.item()->modelType()->GetTypeInfo())).name();
114  std::vector<std::string> fullNames = findViewersFor(typeName);
115  std::vector<std::string> justViewNames;
116  justViewNames.reserve(fullNames.size());
117  std::transform(fullNames.begin(), fullNames.end(), std::back_inserter(justViewNames), &viewNameFrom);
118  return justViewNames;
119 }
120 namespace {
121  bool pluginComapreFunc(std::string a, std::string b) {
122  std::string::size_type as = a.find_first_of('&');
123  a = a.substr(0, as);
124  std::string::size_type bs = b.find_first_of('&');
125  b = b.substr(0, bs);
126  return a == b;
127  }
128 } // namespace
129 
130 std::vector<std::string> FWDetailViewManager::findViewersFor(const std::string& iType) const {
131  std::vector<std::string> returnValue;
132 
133  std::map<std::string, std::vector<std::string> >::const_iterator itFind = m_typeToViewers.find(iType);
134  if (itFind != m_typeToViewers.end()) {
135  return itFind->second;
136  }
137 
138  std::set<std::string> detailViews;
139 
140  std::vector<edmplugin::PluginInfo> all =
142  std::transform(all.begin(),
143  all.end(),
144  std::inserter(detailViews, detailViews.begin()),
145  boost::bind(&edmplugin::PluginInfo::name_, _1));
146  unsigned int closestMatch = 0xFFFFFFFF;
147 
148  for (std::set<std::string>::iterator it = detailViews.begin(), itEnd = detailViews.end(); it != itEnd; ++it) {
149  if (m_context->getHidePFBuilders()) {
150  std::size_t found = it->find("PF ");
151  if (found != std::string::npos)
152  continue;
153  }
154  std::string::size_type first = it->find_first_of('@');
155  std::string type = it->substr(0, first);
156 
157  //see if we match via inheritance
158  FWSimpleRepresentationChecker checker(type, "", 0, false);
159  FWRepresentationInfo info = checker.infoFor(iType);
160  bool pass = false;
161  if (closestMatch > info.proximity()) {
162  pass = true;
163  std::string::size_type firstD = it->find_first_of('&') + 1;
164  if (firstD != std::string::npos) {
165  std::stringstream ss(it->substr(firstD));
166  std::string ml;
167  while (std::getline(ss, ml, '&')) {
169  fwLog(fwlog::kDebug) << "DetailView " << *it << " requires module label " << ml << std::endl;
170  pass = false;
171  break;
172  }
173  }
174  }
175  if (pass) {
176  returnValue.push_back(*it);
177  } else {
178  std::string::size_type first = (*it).find_first_of('@');
179  std::string vn = *it;
180  vn.insert(++first, "!");
181  returnValue.push_back(vn);
182  }
183  }
184  }
185 
186  std::vector<std::string>::iterator it;
187  it = std::unique(returnValue.begin(), returnValue.end(), pluginComapreFunc);
188  returnValue.resize(std::distance(returnValue.begin(), it));
189 
190  m_typeToViewers[iType] = returnValue;
191  return returnValue;
192 }
193 
195  for (vViews_i i = m_views.begin(); i != m_views.end(); ++i)
196  (*i).m_detailView->setBackgroundColor(m_context->colorManager()->background());
197 }
198 
200  while (!m_views.empty()) {
201  m_views.front().m_eveWindow->DestroyWindowAndSlot();
202  }
203 }
204 
206  for (vViews_i i = m_views.begin(); i != m_views.end(); ++i) {
207  if (ew == i->m_eveWindow) {
208  // printf("========================== delete %s \n", ew->GetElementName());
209  m_views.erase(i);
210  break;
211  }
212  }
213 }
taus_updatedMVAIds_cff.category
category
Definition: taus_updatedMVAIds_cff.py:30
FWSimpleRepresentationChecker
Definition: FWSimpleRepresentationChecker.h:29
fwLog
#define fwLog(_level_)
Definition: fwLog.h:45
mps_fire.i
i
Definition: mps_fire.py:355
fireworks::Context
Definition: Context.h:41
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
FWDetailViewManager::colorsChanged
void colorsChanged()
Definition: FWDetailViewManager.cc:194
fireworks::Context::colorManager
FWColorManager * colorManager() const
Definition: Context.h:58
FWModelId
Definition: FWModelId.h:28
FWColorManager::colorsHaveChanged_
sigc::signal< void > colorsHaveChanged_
Definition: FWColorManager.h:101
FWModelId.h
FWRepresentationInfo.h
FWDetailViewManager::openDetailViewFor
void openDetailViewFor(const FWModelId &, const std::string &)
Definition: FWDetailViewManager.cc:71
cms::cuda::assert
assert(be >=bs)
HLT_2018_cff.distance
distance
Definition: HLT_2018_cff.py:6417
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:215
info
static const TGPicture * info(bool iBackgroundIsBlack)
Definition: FWCollectionSummaryWidget.cc:152
FWModelId::item
const FWEventItem * item() const
Definition: FWModelId.h:39
findQualityFiles.v
v
Definition: findQualityFiles.py:179
FWDetailViewFactory.h
fireworks::Context::metadataManager
FWJobMetadataManager * metadataManager() const
Definition: Context.h:60
EventBase.h
newFWLiteAna.found
found
Definition: newFWLiteAna.py:118
dqmdumpme.first
first
Definition: dqmdumpme.py:55
edmplugin::PluginManager::get
static PluginManager * get()
Definition: PluginManager.cc:307
python.cmstools.all
def all(container)
workaround iterator generators for ROOT classes
Definition: cmstools.py:26
edmplugin::PluginManager::categoryToInfos
const CategoryToInfos & categoryToInfos() const
Definition: PluginManager.h:80
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
FWJobMetadataManager.h
cms::cuda::bs
bs
Definition: HistoContainer.h:127
trigger::size_type
uint16_t size_type
Definition: TriggerTypeDefs.h:18
FWDetailViewManager::ViewFrame::~ViewFrame
~ViewFrame()
FWColorManager.h
w
const double w
Definition: UKUtility.cc:23
FWDetailViewManager::vViews_i
vViews_t::iterator vViews_i
Definition: FWDetailViewManager.h:70
FWEventItem::modelType
const TClass * modelType() const
Definition: FWEventItem.cc:464
HcalDetIdTransform::transform
unsigned transform(const HcalDetId &id, unsigned transformCode)
Definition: HcalDetIdTransform.cc:7
FWDetailViewManager::m_typeToViewers
std::map< std::string, std::vector< std::string > > m_typeToViewers
Definition: FWDetailViewManager.h:73
OrderedSet.t
t
Definition: OrderedSet.py:90
edmplugin::PluginInfo::name_
std::string name_
Definition: PluginInfo.h:29
b
double b
Definition: hdecay.h:118
FWDetailViewBase.h
FWDetailViewManager::detailViewsFor
std::vector< std::string > detailViewsFor(const FWModelId &) const
Definition: FWDetailViewManager.cc:112
FWDetailViewManager::~FWDetailViewManager
virtual ~FWDetailViewManager()
Definition: FWDetailViewManager.cc:60
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
viewNameFrom
static std::string viewNameFrom(const std::string &iFull)
Definition: FWDetailViewManager.cc:43
dqmiodumpindices.typeName
typeName
Definition: dqmiodumpindices.py:33
BranchDescription.h
edm::TypeWithDict
Definition: TypeWithDict.h:38
a
double a
Definition: hdecay.h:119
FWDetailViewManager::m_context
fireworks::Context * m_context
Definition: FWDetailViewManager.h:61
FWDetailViewManager::m_views
vViews_t m_views
Definition: FWDetailViewManager.h:71
match
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
fireworks::Context::getHidePFBuilders
bool getHidePFBuilders() const
Definition: Context.h:80
B2GTnPMonitor_cfi.item
item
Definition: B2GTnPMonitor_cfi.py:147
fwLog.h
get
#define get
FWEventItem.h
FWRepresentationInfo
Definition: FWRepresentationInfo.h:28
type
type
Definition: HCALResponse.h:21
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
FWDetailViewManager.h
tier0.unique
def unique(seq, keepstr=True)
Definition: tier0.py:24
FWSimpleRepresentationChecker.h
FWJobMetadataManager::hasModuleLabel
virtual bool hasModuleLabel(std::string &moduleLabel)=0
fwlog::kDebug
Definition: fwLog.h:35
Event.h
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
fwlog::kError
Definition: fwLog.h:35
FWDetailViewManager::newEventCallback
void newEventCallback()
Definition: FWDetailViewManager.cc:199
FWDetailViewManager::eveWindowDestroyed
void eveWindowDestroyed(TEveWindow *)
Definition: FWDetailViewManager.cc:205
FWDetailViewManager::findViewersFor
std::vector< std::string > findViewersFor(const std::string &) const
Definition: FWDetailViewManager.cc:130
FWColorManager::background
Color_t background() const
Definition: FWColorManager.h:55
edm::TypeWithDict::name
std::string name() const
Definition: TypeWithDict.cc:456
FWDetailViewManager::ViewFrame::ViewFrame
ViewFrame(TEveCompositeFrameInMainFrame *f, std::unique_ptr< FWDetailViewBase > v, TEveWindow *w)
Definition: FWDetailViewManager.cc:65
FWGUIManager.h
FWSimpleRepresentationChecker::infoFor
FWRepresentationInfo infoFor(const std::string &iTypeName) const override
Definition: FWSimpleRepresentationChecker.cc:97
FWDetailViewManager::FWDetailViewManager
FWDetailViewManager(fireworks::Context *)
Definition: FWDetailViewManager.cc:51