CMS 3D CMS Logo

FWTableViewManager.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Core
4 // Class : FWTableViewManager
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author:
10 // Created: Sun Jan 6 22:01:27 EST 2008
11 //
12 
13 // system include files
14 #include <iostream>
15 #include <boost/bind.hpp>
16 #include <algorithm>
17 
18 #include "TEveManager.h"
19 #include "TClass.h"
23 
24 // user include files
30 
33 
34 
35 //
36 // constants, enums and typedefs
37 //
38 
39 //
40 // static data member definitions
41 //
42 
43 //
44 // constructors and destructor
45 //
48 {
50  f=boost::bind(&FWTableViewManager::buildView,
51  this, _1, _2);
53 
54  // ---------- for some object types, we have default table contents ----------
55  table("reco::GenParticle").
56  column("pT", 1, "pt").
57  column("eta", 3).
58  column("phi", 3).
59  column("status", TableEntry::INT).
60  column("pdgId", TableEntry::INT);
61 
62  table("reco::Muon").
63  column("q", TableEntry::INT, "charge").
64  column("pT", 1, "pt").
65  column("global", TableEntry::BOOL, "isGlobalMuon").
66  column("tracker", TableEntry::BOOL, "isTrackerMuon").
67  column("SA", TableEntry::BOOL, "isStandAloneMuon").
68  column("calo", TableEntry::BOOL, "isCaloMuon").
69  column("tr pt", 1, "track().pt()").
70  column("eta", 3).
71  column("phi", 3).
72  column("matches", TableEntry::INT, "numberOfMatches('SegmentArbitration')").
73  column("d0", 3, "track().d0()").
74  column("d0 / d0Err", 3, "track().d0() / track().d0Error()");
75 
76  table("reco::GsfElectron").
77  column("q", TableEntry::INT, "charge").
78  column("pT", 1, "pt").
79  column("eta", 3).
80  column("phi", 3).
81  column("E/p", 3, "eSuperClusterOverP").
82  column("H/E", 3, "hadronicOverEm").
83  column("fbrem", 3, "(trackMomentumAtVtx().R() - trackMomentumOut().R()) / trackMomentumAtVtx().R()").
84  column("dei", 3, "deltaEtaSuperClusterTrackAtVtx()").
85  column("dpi", 3, "deltaPhiSuperClusterTrackAtVtx()");
86 
87  table("reco::Photon").
88  column("pT", 1, "pt").
89  column("eta", 3).
90  column("phi", 3).
91  column("H/E", 3, "hadronicOverEm");
92 
93  table("reco::CaloJet").
94  column("pT", 1, "pt").
95  column("eta", 3).
96  column("phi", 3).
97  column("ECAL", 1, "p4().E() * emEnergyFraction()").
98  column("HCAL", 1, "p4().E() * energyFractionHadronic()").
99  column("emf", 3, "emEnergyFraction()");
100 
101  table("reco::Jet").
102  column("pT", 1, "pt").
103  column("eta", 3).
104  column("phi", 3).
105  column("electronEnergyFraction", 3, "electronEnergyFraction()").
106  column("muonEnergyFraction", 3, "muonEnergyFraction()").
107  column("photonEnergyFraction", 3, "photonEnergyFraction()");
108 
109  table("reco::MET").
110  column("et", 1).
111  column("phi", 3).
112  column("sumEt", 1).
113  column("mEtSig", 3);
114 
115  table("reco::Track").
116  column("q", TableEntry::INT, "charge").
117  column("pT", 1, "pt").
118  column("eta", 3).
119  column("phi", 3).
120  column("d0", 5).
121  column("d0Err", 5, "d0Error").
122  column("dz", 5).
123  column("dzErr", 5, "dzError").
124  column("vx", 5).
125  column("vy", 5).
126  column("vz", 5).
127  column("pixel hits", TableEntry::INT, "hitPattern().numberOfValidPixelHits()").
128  column("strip hits", TableEntry::INT, "hitPattern().numberOfValidStripHits()").
129  column("chi2", 3).
130  column("ndof", TableEntry::INT);
131 
132  table("DTRecSegment4D").
133  column("wheel", 0, "chamberId.wheel").
134  column("station", 0, "chamberId.station").
135  column("sector", 0, "chamberId.sector").
136  column("t0phi", 2, "phiSegment.t0").
137  column("t0theta", 2, "zSegment.t0").
138  column("hasPhi", -2, "hasPhi").
139  column("hasZed", -2, "hasZed").
140  column("chi2", 2, "chi2").
141  column("dof", 0, "degreesOfFreedom");
142 
143  table("DTRecHit1DPair").
144  column("wheel", 0, "wireId.wheel").
145  column("station", 0, "wireId.station").
146  column("sector", 0, "wireId.sector").
147  column("SL", 0, "wireId.superlayer").
148  column("layer", 0, "wireId.layer").
149  column("wire", 0, "wireId.wire").
150  column("digiTime", 2, "digiTime");
151 
152  table("CSCSegment").
153  column("endcap", 0, "cscDetId.endcap").
154  column("station", 0, "cscDetId.station").
155  column("ring", 0, "cscDetId.ring").
156  column("chamber", 0, "cscDetId.chamber");
157 
158  table("reco::Vertex").
159  column("x", 5).
160  column("xError", 5).
161  column("y", 5).
162  column("yError", 5).
163  column("z", 5).
164  column("zError", 5).
165  column("tracks", TableEntry::INT, "tracksSize").
166  column("chi2", 3).
167  column("ndof", 3);
168 
169  table("CaloTower").
170  column("emEt", 1).
171  column("hadEt", 1).
172  column("et", 1, "Et").
173  column("eta", 3).
174  column("phi", 3);
175 
176  table("CaloRecHit").
177  column("id", TableEntry::INT,"detid.rawId").
178  column("energy",3).
179  column("time",3).
180  column("flags",TableEntry::INT,"flags");
181 
182  table("reco::PFCandidate").
183  column("et", 1, "Et").
184  column("eta", 3).
185  column("phi", 3).
186  column("ecalEnergy", 3,"ecalEnergy()").
187  column("hcalEnergy", 3,"hcalEnergy()").
188  column("track pt", 3,"trackRef().pt()");
189 
190  table("reco::Electron").
191  column("pT", 1, "pt").
192  column("eta", 3).
193  column("phi", 3).
194  column("E/p", 3, "eSuperClusterOverP").
195  column("H/E", 3, "hadronicOverEm").
196  column("fbrem", 3,"(trackMomentumAtVtx().R() - trackMomentumOut().R()) / trackMomentumAtVtx().R()" ).
197  column("dei",3, "deltaEtaSuperClusterTrackAtVtx" ).
198  column("dpi", 3, "deltaPhiSuperClusterTrackAtVtx()").
199  column("charge", 0, "charge").
200  column("isPF", 0, "isPF()").
201  column("sieie", 3, "sigmaIetaIeta").
202  column("isNotConv", 1, "passConversionVeto");
203 
204  table("pat::PackedCandidate").
205  column("pT", 1, "pt").
206  column("eta", 3).
207  column("phi", 3).
208  column("pdgId", 0).
209  column("charge", 0).
210  column("dxy", 3).
211  column("dzAssociatedPV", 3, "dzAssociatedPV()");
212 }
213 
215 {
216 }
217 
218 //
219 // member functions
220 //
221 
236 {
238  return handle;
239 }
240 
250 FWTableViewManager::TableHandle::column(const char *name, int precision, const char *expression)
251 {
252  TableEntry columnEntry;
253  columnEntry.name = name;
254  columnEntry.precision = precision;
255  columnEntry.expression = expression;
256 
257  m_specs[m_name].push_back(columnEntry);
258  return *this;
259 }
260 
264 FWTableViewManager::TableSpecs::iterator
266 {
267  TableSpecs::iterator ret = m_tableFormats.find(key.name());
268  if (ret != m_tableFormats.end())
269  return ret;
270 
271  // if there is no exact match for the type, try the base classes
272  edm::TypeBases bases(key);
273  for (auto const& base : bases)
274  {
275  ret = tableFormatsImpl(edm::BaseWithDict(base).typeOf());
276  if (ret != m_tableFormats.end())
277  return ret;
278  }
279 
280  return m_tableFormats.end();
281 }
282 
296 FWTableViewManager::TableSpecs::iterator
298 {
299  static const std::string isint("int");
300  static const std::string isbool("bool");
301  static const std::string isdouble("double");
302  static const std::string isfloat("float");
303 
304  std::string keyType = key.name();
305 
306  TableSpecs::iterator ret = m_tableFormats.find(keyType);
307 
308  if (ret != m_tableFormats.end())
309  return ret;
310 
311  ret = tableFormatsImpl(key); // recursive search for base classes
312 
313  if (ret != m_tableFormats.end())
314  return ret;
315 
316  TableHandle handle = table(keyType.c_str());
317  edm::TypeFunctionMembers functionMembers(key);
318  for (auto const& member : functionMembers)
319  {
320  edm::FunctionWithDict m(member);
321  if (m.functionParameterSize())
322  continue;
323  if (!m.isPublic())
324  continue;
325  if (!m.isConst())
326  continue;
327  if (m.finalReturnType().name() == isint)
328  handle.column(m.name().c_str(), TableEntry::INT);
329  else if (m.finalReturnType().name() == isbool)
330  handle.column(m.name().c_str(), TableEntry::BOOL);
331  else if (m.finalReturnType().name() == isdouble)
332  handle.column(m.name().c_str(), 5);
333  else if (m.finalReturnType().name() == isfloat)
334  handle.column(m.name().c_str(), 3);
335  }
336  edm::TypeDataMembers dataMembers(key);
337  for (auto const& member : dataMembers)
338  {
339  edm::MemberWithDict m(member);
340  if (!m.isPublic())
341  continue;
342  if (!m.isConst())
343  continue;
344  if (m.typeOf().name() == isint)
345  handle.column(m.name().c_str(), TableEntry::INT);
346  else if (m.typeOf().name() == isbool)
347  handle.column(m.name().c_str(), TableEntry::BOOL);
348  else if (m.typeOf().name() == isdouble)
349  handle.column(m.name().c_str(), 5);
350  else if (m.typeOf().name() == isfloat)
351  handle.column(m.name().c_str(), 3);
352  }
353  return m_tableFormats.find(keyType);
354 }
355 
361 FWTableViewManager::TableSpecs::iterator
363 {
364  return tableFormats(edm::TypeWithDict::byName(key.GetName()));
365 }
366 
367 class FWViewBase*
368 FWTableViewManager::buildView(TEveWindowSlot* iParent, const std::string& /*type*/)
369 {
370  TEveManager::TRedrawDisabler disableRedraw(gEve);
371  auto view = std::make_shared<FWTableView>(iParent, this);
372  view->setBackgroundColor(colorManager().background());
373  m_views.push_back(view);
374  view->beingDestroyed_.connect(boost::bind(&FWTableViewManager::beingDestroyed,
375  this, _1));
376  return view.get();
377 }
378 
379 void
381 {
382  for(Views::iterator it = m_views.begin(), itEnd = m_views.end();
383  it != itEnd;
384  ++it)
385  {
386  if(it->get() == iView)
387  {
388  m_views.erase(it);
389  return;
390  }
391  }
392 }
393 
394 void
396 {
397  m_items.push_back(iItem);
398  iItem->goingToBeDestroyed_.connect(boost::bind(&FWTableViewManager::destroyItem,
399  this, _1));
400  notifyViews();
401 }
402 
404 void
406 {
407  for(size_t i = 0, e = m_views.size(); i != e; ++i)
408  {
409  FWTableView *view = m_views[i].get();
410  view->updateItems();
411  view->dataChanged();
412  }
413 }
414 
420 void
422 {
423  // remove the item from the list
424  // FIXME: why doesn't it use erase?? Boh...
425  for (size_t i = 0, e = m_items.size(); i != e; ++i)
426  {
427  if (m_items[i] != iItem)
428  continue;
429  m_items[i] = nullptr;
430  }
431 
432  notifyViews();
433 }
434 
439 void
441 {
442  m_items.clear();
443  notifyViews();
444 }
445 
446 void
448 {
449  gEve->DisableRedraw();
450 }
451 
452 void
454 {
455  gEve->EnableRedraw();
456  // tell the views to update their item lists
457  // FIXME: doesn't this need to call updateItems as well
458  // and hence notifyViews would be more appropriate?? Boh...
459  dataChanged();
460 }
461 
463 void
465 {
466  for(size_t i = 0, e = m_views.size(); i != e; ++i)
467  m_views[i].get()->resetColors(colorManager());
468 }
469 
470 void
472 {
473  for(size_t i = 0, e = m_views.size(); i != e; ++i)
474  m_views[i].get()->dataChanged();
475 }
476 
479 {
480  FWTypeToRepresentations returnValue;
481  return returnValue;
482 }
483 
485 
486 void
488 {
489  // if there are views, it's the job of the first view to store
490  // the configuration (this is to avoid ordering problems in the
491  // case of multiple views)
492  if (!m_views.empty())
493  return;
494  // if there are no views, then it's up to us to store the column
495  // formats. This is done in addToImpl, which can be called by
496  // FWTableView as well
497  addToImpl(iTo);
498 }
499 
500 void
502 {
503  FWConfiguration typeNames(1);
504  char prec[100];
505 
506  for (TableSpecs::const_iterator
507  iType = m_tableFormats.begin(),
508  iType_end = m_tableFormats.end();
509  iType != iType_end; ++iType)
510  {
511  const std::string &typeName = iType->first;
512  typeNames.addValue(typeName);
514  const TableEntries &entries = iType->second;
515  for (size_t ei = 0, ee = entries.size(); ei != ee; ++ei)
516  {
517  const TableEntry &entry = entries[ei];
518  columns.addValue(entry.name);
519  columns.addValue(entry.expression);
520  columns.addValue((snprintf(prec, 100, "%d", entry.precision), prec));
521  }
522  iTo.addKeyValue(typeName, columns);
523  }
524  iTo.addKeyValue(kConfigTypeNames, typeNames);
525 }
526 
527 void
529 {
530  try
531  {
532  const FWConfiguration *typeNames = iFrom.valueForKey(kConfigTypeNames);
533  if (typeNames == nullptr)
534  {
535  fwLog(fwlog::kWarning) << "no table column configuration stored, using defaults\n";
536  return;
537  }
538 
539  //NOTE: FWTableViewTableManagers hold pointers into m_tableFormats so if we
540  // clear it those pointers would be invalid
541  // instead we will just clear the lists and fill them with their new values
542  //m_tableFormats.clear();
544  iType = typeNames->stringValues()->begin(),
545  iTypeEnd = typeNames->stringValues()->end();
546  iType != iTypeEnd; ++iType)
547  {
548  //std::cout << "reading type " << *iType << std::endl;
549  const FWConfiguration *columns = iFrom.valueForKey(*iType);
550  assert(columns != nullptr);
551  TableHandle handle = table(iType->c_str());
553  it = columns->stringValues()->begin(),
554  itEnd = columns->stringValues()->end();
555  it != itEnd; ++it)
556  {
557  const std::string &name = *it++;
558  const std::string &expr = *it++;
559  int prec = atoi(it->c_str());
560  handle.column(name.c_str(), prec, expr.c_str());
561  }
562  }
563  }
564  catch (...)
565  {
566  // No info about types in the configuration; this is not an
567  // error, it merely means that the types are handled by the
568  // first FWTableView.
569  }
570 }
const StringValues * stringValues() const
void addToImpl(FWConfiguration &) const
TableHandle table(const char *collection)
void addTo(FWConfiguration &) const override
TableHandle & column(const char *formula, int precision, const char *name)
const std::string & typeName() const
Definition: FWViewBase.cc:120
FWItemChangeSignal goingToBeDestroyed_
Definition: FWEventItem.h:218
std::string name() const
FWColorManager & colorManager() const
boost::function2< FWViewBase *, TEveWindowSlot *, const std::string & > ViewBuildFunctor
Definition: FWGUIManager.h:98
static TypeWithDict byName(std::string const &name)
Definition: TypeWithDict.cc:59
void registerViewBuilder(const std::string &iName, ViewBuildFunctor &iBuilder)
bool isPublic() const
TableSpecs::iterator tableFormats(const edm::TypeWithDict &key)
void updateItems()
Definition: FWTableView.cc:547
std::string name() const
TableSpecs::iterator tableFormatsImpl(const edm::TypeWithDict &key)
std::string name() const
double f[11][100]
TypeWithDict typeOf() const
void modelChangesComing() override
base
Make Sure CMSSW is Setup ##.
TypeWithDict finalReturnType() const
void setFrom(const FWConfiguration &) override
std::vector< TableEntry > TableEntries
bool isConst() const
FWConfiguration & addKeyValue(const std::string &, const FWConfiguration &)
FWConfiguration & addValue(const std::string &)
#define fwLog(_level_)
Definition: fwLog.h:50
void modelChangesDone() override
void colorsChanged() override
void destroyItem(const FWEventItem *item)
size_t functionParameterSize(bool required=false) const
static const std::string & idToName(int)
Definition: FWViewType.cc:89
FWTypeToRepresentations supportedTypesAndRepresentations() const override
const FWConfiguration * valueForKey(const std::string &iKey) const
StringValues::const_iterator StringValuesIt
void dataChanged()
Definition: FWTableView.cc:586
static const std::string kConfigTypeNames
void beingDestroyed(const FWViewBase *)
FWViewBase * buildView(TEveWindowSlot *iParent, const std::string &type)
void newItem(const FWEventItem *) override