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 <functional>
16 #include <algorithm>
17 
18 #include "TEveManager.h"
19 #include "TClass.h"
23 
24 // user include files
30 
33 
34 //
35 // constants, enums and typedefs
36 //
37 
38 //
39 // static data member definitions
40 //
41 
42 //
43 // constructors and destructor
44 //
47  f = std::bind(&FWTableViewManager::buildView, this, std::placeholders::_1, std::placeholders::_2);
49 
50  // ---------- for some object types, we have default table contents ----------
51  table("reco::GenParticle")
52  .column("pT", 1, "pt")
53  .column("eta", 3)
54  .column("phi", 3)
55  .column("status", TableEntry::INT)
56  .column("pdgId", TableEntry::INT);
57 
58  table("reco::Muon")
59  .column("q", TableEntry::INT, "charge")
60  .column("pT", 1, "pt")
61  .column("global", TableEntry::BOOL, "isGlobalMuon")
62  .column("tracker", TableEntry::BOOL, "isTrackerMuon")
63  .column("SA", TableEntry::BOOL, "isStandAloneMuon")
64  .column("calo", TableEntry::BOOL, "isCaloMuon")
65  .column("tr pt", 1, "track().pt()")
66  .column("eta", 3)
67  .column("phi", 3)
68  .column("matches", TableEntry::INT, "numberOfMatches('SegmentArbitration')")
69  .column("d0", 3, "track().d0()")
70  .column("d0 / d0Err", 3, "track().d0() / track().d0Error()");
71 
72  table("reco::GsfElectron")
73  .column("q", TableEntry::INT, "charge")
74  .column("pT", 1, "pt")
75  .column("eta", 3)
76  .column("phi", 3)
77  .column("E/p", 3, "eSuperClusterOverP")
78  .column("H/E", 3, "hadronicOverEm")
79  .column("fbrem", 3, "(trackMomentumAtVtx().R() - trackMomentumOut().R()) / trackMomentumAtVtx().R()")
80  .column("dei", 3, "deltaEtaSuperClusterTrackAtVtx()")
81  .column("dpi", 3, "deltaPhiSuperClusterTrackAtVtx()");
82 
83  table("reco::Photon").column("pT", 1, "pt").column("eta", 3).column("phi", 3).column("H/E", 3, "hadronicOverEm");
84 
85  table("reco::CaloJet")
86  .column("pT", 1, "pt")
87  .column("eta", 3)
88  .column("phi", 3)
89  .column("ECAL", 1, "p4().E() * emEnergyFraction()")
90  .column("HCAL", 1, "p4().E() * energyFractionHadronic()")
91  .column("emf", 3, "emEnergyFraction()");
92 
93  table("reco::Jet")
94  .column("pT", 1, "pt")
95  .column("eta", 3)
96  .column("phi", 3)
97  .column("electronEnergyFraction", 3, "electronEnergyFraction()")
98  .column("muonEnergyFraction", 3, "muonEnergyFraction()")
99  .column("photonEnergyFraction", 3, "photonEnergyFraction()");
100 
101  table("reco::MET").column("et", 1).column("phi", 3).column("sumEt", 1).column("mEtSig", 3);
102 
103  table("reco::Track")
104  .column("q", TableEntry::INT, "charge")
105  .column("pT", 1, "pt")
106  .column("eta", 3)
107  .column("phi", 3)
108  .column("d0", 5)
109  .column("d0Err", 5, "d0Error")
110  .column("dz", 5)
111  .column("dzErr", 5, "dzError")
112  .column("vx", 5)
113  .column("vy", 5)
114  .column("vz", 5)
115  .column("pixel hits", TableEntry::INT, "hitPattern().numberOfValidPixelHits()")
116  .column("strip hits", TableEntry::INT, "hitPattern().numberOfValidStripHits()")
117  .column("chi2", 3)
118  .column("ndof", TableEntry::INT);
119 
120  table("DTRecSegment4D")
121  .column("wheel", 0, "chamberId.wheel")
122  .column("station", 0, "chamberId.station")
123  .column("sector", 0, "chamberId.sector")
124  .column("t0phi", 2, "phiSegment.t0")
125  .column("t0theta", 2, "zSegment.t0")
126  .column("hasPhi", -2, "hasPhi")
127  .column("hasZed", -2, "hasZed")
128  .column("chi2", 2, "chi2")
129  .column("dof", 0, "degreesOfFreedom");
130 
131  table("DTRecHit1DPair")
132  .column("wheel", 0, "wireId.wheel")
133  .column("station", 0, "wireId.station")
134  .column("sector", 0, "wireId.sector")
135  .column("SL", 0, "wireId.superlayer")
136  .column("layer", 0, "wireId.layer")
137  .column("wire", 0, "wireId.wire")
138  .column("digiTime", 2, "digiTime");
139 
140  table("CSCSegment")
141  .column("endcap", 0, "cscDetId.endcap")
142  .column("station", 0, "cscDetId.station")
143  .column("ring", 0, "cscDetId.ring")
144  .column("chamber", 0, "cscDetId.chamber");
145 
146  table("reco::Vertex")
147  .column("x", 5)
148  .column("xError", 5)
149  .column("y", 5)
150  .column("yError", 5)
151  .column("z", 5)
152  .column("zError", 5)
153  .column("tracks", TableEntry::INT, "tracksSize")
154  .column("chi2", 3)
155  .column("ndof", 3);
156 
157  table("CaloTower").column("emEt", 1).column("hadEt", 1).column("et", 1, "Et").column("eta", 3).column("phi", 3);
158 
159  table("CaloRecHit")
160  .column("id", TableEntry::INT, "detid.rawId")
161  .column("energy", 3)
162  .column("time", 3)
163  .column("flags", TableEntry::INT, "flags");
164 
165  table("reco::PFCandidate")
166  .column("et", 1, "Et")
167  .column("eta", 3)
168  .column("phi", 3)
169  .column("ecalEnergy", 3, "ecalEnergy()")
170  .column("hcalEnergy", 3, "hcalEnergy()")
171  .column("track pt", 3, "trackRef().pt()");
172 
173  table("reco::Electron")
174  .column("pT", 1, "pt")
175  .column("eta", 3)
176  .column("phi", 3)
177  .column("E/p", 3, "eSuperClusterOverP")
178  .column("H/E", 3, "hadronicOverEm")
179  .column("fbrem", 3, "(trackMomentumAtVtx().R() - trackMomentumOut().R()) / trackMomentumAtVtx().R()")
180  .column("dei", 3, "deltaEtaSuperClusterTrackAtVtx")
181  .column("dpi", 3, "deltaPhiSuperClusterTrackAtVtx()")
182  .column("charge", 0, "charge")
183  .column("isPF", 0, "isPF()")
184  .column("sieie", 3, "sigmaIetaIeta")
185  .column("isNotConv", 1, "passConversionVeto");
186 
187  table("pat::PackedCandidate")
188  .column("pT", 1, "pt")
189  .column("eta", 3)
190  .column("phi", 3)
191  .column("pdgId", 0)
192  .column("charge", 0)
193  .column("dxy", 3)
194  .column("dzAssociatedPV", 3, "dzAssociatedPV()");
195 
196  table("l1t::HGCalTriggerCell").column("pT", 1, "pt").column("eta", 3).column("phi", 3).column("detId", 0);
197 
198  table("CaloParticle").column("eta", 3).column("phi", 3).column("energy", 3);
199 }
200 
202 
203 //
204 // member functions
205 //
206 
221  return handle;
222 }
223 
233  int precision,
234  const char *expression) {
235  TableEntry columnEntry;
236  columnEntry.name = name;
237  columnEntry.precision = precision;
238  columnEntry.expression = expression;
239 
240  m_specs[m_name].push_back(columnEntry);
241  return *this;
242 }
243 
247 FWTableViewManager::TableSpecs::iterator FWTableViewManager::tableFormatsImpl(const edm::TypeWithDict &key) {
248  TableSpecs::iterator ret = m_tableFormats.find(key.name());
249  if (ret != m_tableFormats.end())
250  return ret;
251 
252  // if there is no exact match for the type, try the base classes
253  edm::TypeBases bases(key);
254  for (auto const &base : bases) {
256  if (ret != m_tableFormats.end())
257  return ret;
258  }
259 
260  return m_tableFormats.end();
261 }
262 
276 FWTableViewManager::TableSpecs::iterator FWTableViewManager::tableFormats(const edm::TypeWithDict &key) {
277  static const std::string isint("int");
278  static const std::string isbool("bool");
279  static const std::string isdouble("double");
280  static const std::string isfloat("float");
281 
282  std::string keyType = key.name();
283 
284  TableSpecs::iterator ret = m_tableFormats.find(keyType);
285 
286  if (ret != m_tableFormats.end())
287  return ret;
288 
289  ret = tableFormatsImpl(key); // recursive search for base classes
290 
291  if (ret != m_tableFormats.end())
292  return ret;
293 
294  TableHandle handle = table(keyType.c_str());
295  edm::TypeFunctionMembers functionMembers(key);
296  for (auto const &member : functionMembers) {
297  edm::FunctionWithDict m(member);
298  if (m.functionParameterSize())
299  continue;
300  if (!m.isPublic())
301  continue;
302  if (!m.isConst())
303  continue;
304  if (m.finalReturnType().name() == isint)
305  handle.column(m.name().c_str(), TableEntry::INT);
306  else if (m.finalReturnType().name() == isbool)
307  handle.column(m.name().c_str(), TableEntry::BOOL);
308  else if (m.finalReturnType().name() == isdouble)
309  handle.column(m.name().c_str(), 5);
310  else if (m.finalReturnType().name() == isfloat)
311  handle.column(m.name().c_str(), 3);
312  }
313  edm::TypeDataMembers dataMembers(key);
314  for (auto const &member : dataMembers) {
315  edm::MemberWithDict m(member);
316  if (!m.isPublic())
317  continue;
318  if (!m.isConst())
319  continue;
320  if (m.typeOf().name() == isint)
321  handle.column(m.name().c_str(), TableEntry::INT);
322  else if (m.typeOf().name() == isbool)
323  handle.column(m.name().c_str(), TableEntry::BOOL);
324  else if (m.typeOf().name() == isdouble)
325  handle.column(m.name().c_str(), 5);
326  else if (m.typeOf().name() == isfloat)
327  handle.column(m.name().c_str(), 3);
328  }
329  return m_tableFormats.find(keyType);
330 }
331 
337 FWTableViewManager::TableSpecs::iterator FWTableViewManager::tableFormats(const TClass &key) {
338  return tableFormats(edm::TypeWithDict::byName(key.GetName()));
339 }
340 
341 class FWViewBase *FWTableViewManager::buildView(TEveWindowSlot *iParent, const std::string & /*type*/) {
342  TEveManager::TRedrawDisabler disableRedraw(gEve);
343  auto view = std::make_shared<FWTableView>(iParent, this);
344  view->setBackgroundColor(colorManager().background());
345  m_views.push_back(view);
346  view->beingDestroyed_.connect(std::bind(&FWTableViewManager::beingDestroyed, this, std::placeholders::_1));
347  return view.get();
348 }
349 
351  for (Views::iterator it = m_views.begin(), itEnd = m_views.end(); it != itEnd; ++it) {
352  if (it->get() == iView) {
353  m_views.erase(it);
354  return;
355  }
356  }
357 }
358 
360  m_items.push_back(iItem);
361  iItem->goingToBeDestroyed_.connect(std::bind(&FWTableViewManager::destroyItem, this, std::placeholders::_1));
362  notifyViews();
363 }
364 
367  for (size_t i = 0, e = m_views.size(); i != e; ++i) {
368  FWTableView *view = m_views[i].get();
369  view->updateItems();
370  view->dataChanged();
371  }
372 }
373 
380  // remove the item from the list
381  // FIXME: why doesn't it use erase?? Boh...
382  for (size_t i = 0, e = m_items.size(); i != e; ++i) {
383  if (m_items[i] != iItem)
384  continue;
385  m_items[i] = nullptr;
386  }
387 
388  notifyViews();
389 }
390 
396  m_items.clear();
397  notifyViews();
398 }
399 
400 void FWTableViewManager::modelChangesComing() { gEve->DisableRedraw(); }
401 
403  gEve->EnableRedraw();
404  // tell the views to update their item lists
405  // FIXME: doesn't this need to call updateItems as well
406  // and hence notifyViews would be more appropriate?? Boh...
407  dataChanged();
408 }
409 
412  for (size_t i = 0, e = m_views.size(); i != e; ++i)
413  m_views[i].get()->resetColors(colorManager());
414 }
415 
417  for (size_t i = 0, e = m_views.size(); i != e; ++i)
418  m_views[i].get()->dataChanged();
419 }
420 
422  FWTypeToRepresentations returnValue;
423  return returnValue;
424 }
425 
427 
429  // if there are views, it's the job of the first view to store
430  // the configuration (this is to avoid ordering problems in the
431  // case of multiple views)
432  if (!m_views.empty())
433  return;
434  // if there are no views, then it's up to us to store the column
435  // formats. This is done in addToImpl, which can be called by
436  // FWTableView as well
437  addToImpl(iTo);
438 }
439 
442  char prec[100];
443 
444  for (TableSpecs::const_iterator iType = m_tableFormats.begin(), iType_end = m_tableFormats.end(); iType != iType_end;
445  ++iType) {
446  const std::string &typeName = iType->first;
447  typeNames.addValue(typeName);
449  const TableEntries &entries = iType->second;
450  for (size_t ei = 0, ee = entries.size(); ei != ee; ++ei) {
451  const TableEntry &entry = entries[ei];
452  columns.addValue(entry.name);
453  columns.addValue(entry.expression);
454  columns.addValue((snprintf(prec, 100, "%d", entry.precision), prec));
455  }
457  }
459 }
460 
462  try {
464  if (typeNames == nullptr) {
465  fwLog(fwlog::kWarning) << "no table column configuration stored, using defaults\n";
466  return;
467  }
468 
469  //NOTE: FWTableViewTableManagers hold pointers into m_tableFormats so if we
470  // clear it those pointers would be invalid
471  // instead we will just clear the lists and fill them with their new values
472  //m_tableFormats.clear();
473  for (FWConfiguration::StringValuesIt iType = typeNames->stringValues()->begin(),
474  iTypeEnd = typeNames->stringValues()->end();
475  iType != iTypeEnd;
476  ++iType) {
477  //std::cout << "reading type " << *iType << std::endl;
478  const FWConfiguration *columns = iFrom.valueForKey(*iType);
479  assert(columns != nullptr);
480  TableHandle handle = table(iType->c_str());
481  for (FWConfiguration::StringValuesIt it = columns->stringValues()->begin(),
482  itEnd = columns->stringValues()->end();
483  it != itEnd;
484  ++it) {
485  const std::string &name = *it++;
486  const std::string &expr = *it++;
487  int prec = atoi(it->c_str());
488  handle.column(name.c_str(), prec, expr.c_str());
489  }
490  }
491  } catch (...) {
492  // No info about types in the configuration; this is not an
493  // error, it merely means that the types are handled by the
494  // first FWTableView.
495  }
496 }
runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:542
edm::TypeWithDict::byName
static TypeWithDict byName(std::string const &name)
Definition: TypeWithDict.cc:74
fwLog
#define fwLog(_level_)
Definition: fwLog.h:45
mps_fire.i
i
Definition: mps_fire.py:428
FWTableViewManager::buildView
FWViewBase * buildView(TEveWindowSlot *iParent, const std::string &type)
Definition: FWTableViewManager.cc:341
FWGUIManager
Definition: FWGUIManager.h:95
FWTableViewManager::newItem
void newItem(const FWEventItem *) override
Definition: FWTableViewManager.cc:359
FWViewType::idToName
static const std::string & idToName(int)
Definition: FWViewType.cc:72
FWViewManagerBase
Definition: FWViewManagerBase.h:45
FWTableViewManager::TableEntries
std::vector< TableEntry > TableEntries
Definition: FWTableViewManager.h:53
FWGUIManager::registerViewBuilder
void registerViewBuilder(const std::string &iName, ViewBuildFunctor &iBuilder)
Definition: FWGUIManager.cc:273
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
FWTableViewManager::addToImpl
void addToImpl(FWConfiguration &) const
Definition: FWTableViewManager.cc:440
patZpeak.handle
handle
Definition: patZpeak.py:23
FWViewManagerBase::colorManager
FWColorManager & colorManager() const
Definition: FWViewManagerBase.cc:123
BaseWithDict.h
mps_splice.entry
entry
Definition: mps_splice.py:68
FWEventItem::goingToBeDestroyed_
FWItemChangeSignal goingToBeDestroyed_
Definition: FWEventItem.h:197
cms::cuda::assert
assert(be >=bs)
FWTableView
Definition: FWTableView.h:50
FWTableViewManager::TableHandle::column
TableHandle & column(const char *formula, int precision, const char *name)
Definition: FWTableViewManager.cc:232
FWTableViewManager::colorsChanged
void colorsChanged() override
Definition: FWTableViewManager.cc:411
edm::BaseWithDict
Definition: BaseWithDict.h:18
FWTableViewManager::TableEntry::expression
std::string expression
Definition: FWTableViewManager.h:45
FWTableViewManager::supportedTypesAndRepresentations
FWTypeToRepresentations supportedTypesAndRepresentations() const override
Definition: FWTableViewManager.cc:421
FWColorManager.h
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:72
FWTableViewManager::TableHandle::m_specs
TableSpecs & m_specs
Definition: FWTableViewManager.h:113
FWConfiguration::valueForKey
const FWConfiguration * valueForKey(const std::string &iKey) const
Definition: FWConfiguration.cc:122
FWTableViewManager::TableEntry::BOOL
Definition: FWTableViewManager.h:44
FWTableViewManager::TableEntry::INT
Definition: FWTableViewManager.h:44
FWTableViewManager::TableHandle::m_name
std::string m_name
Definition: FWTableViewManager.h:112
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
FWTableViewManager::kConfigTypeNames
static const std::string kConfigTypeNames
Definition: FWTableViewManager.h:79
FWTableViewManager::removeAllItems
void removeAllItems(void)
Definition: FWTableViewManager.cc:395
dqmiodumpindices.typeName
typeName
Definition: dqmiodumpindices.py:33
FWTableViewManager.h
FWGUIManager::ViewBuildFunctor
std::function< FWViewBase *(TEveWindowSlot *, const std::string &)> ViewBuildFunctor
Definition: FWGUIManager.h:98
edm::TypeWithDict
Definition: TypeWithDict.h:38
common_cff.precision
precision
Definition: common_cff.py:44
dqmiodumpindices.typeNames
typeNames
Definition: dqmiodumpindices.py:16
FWConfiguration::StringValuesIt
StringValues::const_iterator StringValuesIt
Definition: FWConfiguration.h:44
FWTableViewManager::tableFormatsImpl
TableSpecs::iterator tableFormatsImpl(const edm::TypeWithDict &key)
Definition: FWTableViewManager.cc:247
edm::TypeDataMembers
Definition: TypeWithDict.h:164
FWTableView::updateItems
void updateItems()
Definition: FWTableView.cc:519
FWTableViewManager::modelChangesDone
void modelChangesDone() override
Definition: FWTableViewManager.cc:402
FWTableViewManager::setFrom
void setFrom(const FWConfiguration &) override
Definition: FWTableViewManager.cc:461
FWTableViewManager::m_tableFormats
TableSpecs m_tableFormats
Definition: FWTableViewManager.h:95
edm::MemberWithDict
Definition: MemberWithDict.h:19
fwlog::kWarning
Definition: fwLog.h:35
fwLog.h
FWTableViewManager::notifyViews
void notifyViews()
Definition: FWTableViewManager.cc:366
FWTableViewManager::TableHandle
Definition: FWTableViewManager.h:104
FWTableViewManager::TableEntry::precision
int precision
Definition: FWTableViewManager.h:47
get
#define get
FWEventItem.h
FWTableViewManager::m_items
Items m_items
Definition: FWTableViewManager.h:94
FWTableViewManager::TableEntry
Definition: FWTableViewManager.h:43
FWTableViewManager::modelChangesComing
void modelChangesComing() override
Definition: FWTableViewManager.cc:400
FWTableViewManager::~FWTableViewManager
~FWTableViewManager() override
Definition: FWTableViewManager.cc:201
FWConfiguration::addKeyValue
FWConfiguration & addKeyValue(const std::string &, const FWConfiguration &)
Definition: FWConfiguration.cc:58
FWTableView::dataChanged
void dataChanged()
Definition: FWTableView.cc:551
FWEventItem
Definition: FWEventItem.h:56
FWTableViewManager::TableEntry::name
std::string name
Definition: FWTableViewManager.h:46
FWTableViewManager::destroyItem
void destroyItem(const FWEventItem *item)
Definition: FWTableViewManager.cc:379
edm::FunctionWithDict
Definition: FunctionWithDict.h:27
jets_cff.expr
expr
Definition: jets_cff.py:489
FWTableViewManager::tableFormats
TableSpecs::iterator tableFormats(const edm::TypeWithDict &key)
Definition: FWTableViewManager.cc:276
FWTypeToRepresentations
Definition: FWTypeToRepresentations.h:33
mps_check.columns
columns
Definition: mps_check.py:244
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
FWTableViewManager::FWTableViewManager
FWTableViewManager()
FWTypeToRepresentations.h
FWConfiguration
Definition: FWConfiguration.h:31
FWTableViewManager::dataChanged
void dataChanged()
Definition: FWTableViewManager.cc:416
FWViewBase
Definition: FWViewBase.h:36
FWTableViewManager::beingDestroyed
void beingDestroyed(const FWViewBase *)
Definition: FWTableViewManager.cc:350
edm::TypeBases
Definition: TypeWithDict.h:153
FWTableViewManager::table
TableHandle table(const char *collection)
Definition: FWTableViewManager.cc:219
crabWrapper.key
key
Definition: crabWrapper.py:19
newFWLiteAna.base
base
Definition: newFWLiteAna.py:92
MemberWithDict.h
FWTableViewManager::addTo
void addTo(FWConfiguration &) const override
Definition: FWTableViewManager.cc:428
FunctionWithDict.h
FWGUIManager.h
FWTableViewManager::m_views
Views m_views
Definition: FWTableViewManager.h:93
FWConfiguration.h
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
edm::TypeFunctionMembers
Definition: TypeWithDict.h:175
FWViewType::kTable
Definition: FWViewType.h:39