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 // constants, enums and typedefs
36 //
37 
38 //
39 // static data member definitions
40 //
41 
42 //
43 // constructors and destructor
44 //
47  f = boost::bind(&FWTableViewManager::buildView, this, _1, _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) {
255  ret = tableFormatsImpl(edm::BaseWithDict(base).typeOf());
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(boost::bind(&FWTableViewManager::beingDestroyed, this, _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(boost::bind(&FWTableViewManager::destroyItem, this, _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  }
456  iTo.addKeyValue(typeName, columns);
457  }
458  iTo.addKeyValue(kConfigTypeNames, typeNames);
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 }
const StringValues * stringValues() const
void addToImpl(FWConfiguration &) const
TableHandle table(const char *collection)
void addTo(FWConfiguration &) const override
ret
prodAgent to be discontinued
base
Main Program
Definition: newFWLiteAna.py:92
TableHandle & column(const char *formula, int precision, const char *name)
FWItemChangeSignal goingToBeDestroyed_
Definition: FWEventItem.h:197
std::map< l1t::HGCalMulticluster::EnergyInterpretation, double > ei
Definition: classes.h:67
std::string name() const
FWColorManager & colorManager() const
static TypeWithDict byName(std::string const &name)
Definition: TypeWithDict.cc:74
void registerViewBuilder(const std::string &iName, ViewBuildFunctor &iBuilder)
bool isPublic() const
TableSpecs::iterator tableFormats(const edm::TypeWithDict &key)
void updateItems()
Definition: FWTableView.cc:518
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
TypeWithDict finalReturnType() const
void setFrom(const FWConfiguration &) override
std::vector< TableEntry > TableEntries
bool isConst() const
FWConfiguration & addKeyValue(const std::string &, const FWConfiguration &)
boost::function2< FWViewBase *, TEveWindowSlot *, const std::string & > ViewBuildFunctor
Definition: FWGUIManager.h:97
FWConfiguration & addValue(const std::string &)
#define fwLog(_level_)
Definition: fwLog.h:45
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:72
FWTypeToRepresentations supportedTypesAndRepresentations() const override
const FWConfiguration * valueForKey(const std::string &iKey) const
StringValues::const_iterator StringValuesIt
void dataChanged()
Definition: FWTableView.cc:550
static const std::string kConfigTypeNames
void beingDestroyed(const FWViewBase *)
FWViewBase * buildView(TEveWindowSlot *iParent, const std::string &type)
void newItem(const FWEventItem *) override