CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
106  table("reco::MET").
107  column("et", 1).
108  column("phi", 3).
109  column("sumEt", 1).
110  column("mEtSig", 3);
111 
112  table("reco::Track").
113  column("q", TableEntry::INT, "charge").
114  column("pT", 1, "pt").
115  column("eta", 3).
116  column("phi", 3).
117  column("d0", 5).
118  column("d0Err", 5, "d0Error").
119  column("dz", 5).
120  column("dzErr", 5, "dzError").
121  column("vx", 5).
122  column("vy", 5).
123  column("vz", 5).
124  column("pixel hits", TableEntry::INT, "hitPattern().numberOfValidPixelHits()").
125  column("strip hits", TableEntry::INT, "hitPattern().numberOfValidStripHits()").
126  column("chi2", 3).
127  column("ndof", TableEntry::INT);
128 
129  table("DTRecSegment4D").
130  column("wheel", 0, "chamberId.wheel").
131  column("station", 0, "chamberId.station").
132  column("sector", 0, "chamberId.sector").
133  column("t0phi", 2, "phiSegment.t0").
134  column("t0theta", 2, "zSegment.t0").
135  column("hasPhi", -2, "hasPhi").
136  column("hasZed", -2, "hasZed").
137  column("chi2", 2, "chi2").
138  column("dof", 0, "degreesOfFreedom");
139 
140  table("DTRecHit1DPair").
141  column("wheel", 0, "wireId.wheel").
142  column("station", 0, "wireId.station").
143  column("sector", 0, "wireId.sector").
144  column("SL", 0, "wireId.superlayer").
145  column("layer", 0, "wireId.layer").
146  column("wire", 0, "wireId.wire").
147  column("digiTime", 2, "digiTime");
148 
149  table("CSCSegment").
150  column("endcap", 0, "cscDetId.endcap").
151  column("station", 0, "cscDetId.station").
152  column("ring", 0, "cscDetId.ring").
153  column("chamber", 0, "cscDetId.chamber");
154 
155  table("reco::Vertex").
156  column("x", 5).
157  column("xError", 5).
158  column("y", 5).
159  column("yError", 5).
160  column("z", 5).
161  column("zError", 5).
162  column("tracks", TableEntry::INT, "tracksSize").
163  column("chi2", 3).
164  column("ndof", 3);
165 
166  table("CaloTower").
167  column("emEt", 1).
168  column("hadEt", 1).
169  column("et", 1, "Et").
170  column("eta", 3).
171  column("phi", 3);
172 
173  table("CaloRecHit").
174  column("id", TableEntry::INT,"detid.rawId").
175  column("energy",3).
176  column("time",3).
177  column("flags",TableEntry::INT,"flags");
178 }
179 
181 {
182 }
183 
184 //
185 // member functions
186 //
187 
202 {
204  return handle;
205 }
206 
216 FWTableViewManager::TableHandle::column(const char *name, int precision, const char *expression)
217 {
218  TableEntry columnEntry;
219  columnEntry.name = name;
220  columnEntry.precision = precision;
221  columnEntry.expression = expression;
222 
223  m_specs[m_name].push_back(columnEntry);
224  return *this;
225 }
226 
230 FWTableViewManager::TableSpecs::iterator
232 {
233  TableSpecs::iterator ret = m_tableFormats.find(key.name());
234  if (ret != m_tableFormats.end())
235  return ret;
236 
237  // if there is no exact match for the type, try the base classes
238  edm::TypeBases bases(key);
239  for (auto const& base : bases)
240  {
241  ret = tableFormatsImpl(edm::BaseWithDict(base).typeOf());
242  if (ret != m_tableFormats.end())
243  return ret;
244  }
245 
246  return m_tableFormats.end();
247 }
248 
262 FWTableViewManager::TableSpecs::iterator
264 {
265  static const std::string isint("int");
266  static const std::string isbool("bool");
267  static const std::string isdouble("double");
268  static const std::string isfloat("float");
269 
270  std::string keyType = key.name();
271 
272  TableSpecs::iterator ret = m_tableFormats.find(keyType);
273 
274  if (ret != m_tableFormats.end())
275  return ret;
276 
277  ret = tableFormatsImpl(key); // recursive search for base classes
278 
279  if (ret != m_tableFormats.end())
280  return ret;
281 
282  TableHandle handle = table(keyType.c_str());
283  edm::TypeFunctionMembers functionMembers(key);
284  for (auto const& member : functionMembers)
285  {
286  edm::FunctionWithDict m(member);
287  if (m.functionParameterSize())
288  continue;
289  if (!m.isPublic())
290  continue;
291  if (!m.isConst())
292  continue;
293  if (m.returnType().name() == isint)
294  handle.column(m.name().c_str(), TableEntry::INT);
295  else if (m.returnType().name() == isbool)
296  handle.column(m.name().c_str(), TableEntry::BOOL);
297  else if (m.returnType().name() == isdouble)
298  handle.column(m.name().c_str(), 5);
299  else if (m.returnType().name() == isfloat)
300  handle.column(m.name().c_str(), 3);
301  }
302  edm::TypeDataMembers dataMembers(key);
303  for (auto const& member : dataMembers)
304  {
305  edm::MemberWithDict m(member);
306  if (!m.isPublic())
307  continue;
308  if (!m.isConst())
309  continue;
310  if (m.typeOf().name() == isint)
311  handle.column(m.name().c_str(), TableEntry::INT);
312  else if (m.typeOf().name() == isbool)
313  handle.column(m.name().c_str(), TableEntry::BOOL);
314  else if (m.typeOf().name() == isdouble)
315  handle.column(m.name().c_str(), 5);
316  else if (m.typeOf().name() == isfloat)
317  handle.column(m.name().c_str(), 3);
318  }
319  return m_tableFormats.find(keyType);
320 }
321 
327 FWTableViewManager::TableSpecs::iterator
329 {
330  return tableFormats(edm::TypeWithDict::byName(key.GetName()));
331 }
332 
333 class FWViewBase*
334 FWTableViewManager::buildView(TEveWindowSlot* iParent, const std::string& /*type*/)
335 {
336  TEveManager::TRedrawDisabler disableRedraw(gEve);
337  boost::shared_ptr<FWTableView> view(new FWTableView(iParent, this));
338  view->setBackgroundColor(colorManager().background());
339  m_views.push_back(view);
340  view->beingDestroyed_.connect(boost::bind(&FWTableViewManager::beingDestroyed,
341  this, _1));
342  return view.get();
343 }
344 
345 void
347 {
348  for(Views::iterator it = m_views.begin(), itEnd = m_views.end();
349  it != itEnd;
350  ++it)
351  {
352  if(it->get() == iView)
353  {
354  m_views.erase(it);
355  return;
356  }
357  }
358 }
359 
360 void
362 {
363  m_items.push_back(iItem);
364  iItem->goingToBeDestroyed_.connect(boost::bind(&FWTableViewManager::destroyItem,
365  this, _1));
366  notifyViews();
367 }
368 
370 void
372 {
373  for(size_t i = 0, e = m_views.size(); i != e; ++i)
374  {
375  FWTableView *view = m_views[i].get();
376  view->updateItems();
377  view->dataChanged();
378  }
379 }
380 
386 void
388 {
389  // remove the item from the list
390  // FIXME: why doesn't it use erase?? Boh...
391  for (size_t i = 0, e = m_items.size(); i != e; ++i)
392  {
393  if (m_items[i] != iItem)
394  continue;
395  m_items[i] = 0;
396  }
397 
398  notifyViews();
399 }
400 
405 void
407 {
408  m_items.clear();
409  notifyViews();
410 }
411 
412 void
414 {
415  gEve->DisableRedraw();
416 }
417 
418 void
420 {
421  gEve->EnableRedraw();
422  // tell the views to update their item lists
423  // FIXME: doesn't this need to call updateItems as well
424  // and hence notifyViews would be more appropriate?? Boh...
425  dataChanged();
426 }
427 
429 void
431 {
432  for(size_t i = 0, e = m_views.size(); i != e; ++i)
433  m_views[i].get()->resetColors(colorManager());
434 }
435 
436 void
438 {
439  for(size_t i = 0, e = m_views.size(); i != e; ++i)
440  m_views[i].get()->dataChanged();
441 }
442 
445 {
446  FWTypeToRepresentations returnValue;
447  return returnValue;
448 }
449 
451 
452 void
454 {
455  // if there are views, it's the job of the first view to store
456  // the configuration (this is to avoid ordering problems in the
457  // case of multiple views)
458  if (!m_views.empty())
459  return;
460  // if there are no views, then it's up to us to store the column
461  // formats. This is done in addToImpl, which can be called by
462  // FWTableView as well
463  addToImpl(iTo);
464 }
465 
466 void
468 {
469  FWConfiguration typeNames(1);
470  char prec[100];
471 
472  for (TableSpecs::const_iterator
473  iType = m_tableFormats.begin(),
474  iType_end = m_tableFormats.end();
475  iType != iType_end; ++iType)
476  {
477  const std::string &typeName = iType->first;
478  typeNames.addValue(typeName);
479  FWConfiguration columns(1);
480  const TableEntries &entries = iType->second;
481  for (size_t ei = 0, ee = entries.size(); ei != ee; ++ei)
482  {
483  const TableEntry &entry = entries[ei];
484  columns.addValue(entry.name);
485  columns.addValue(entry.expression);
486  columns.addValue((snprintf(prec, 100, "%d", entry.precision), prec));
487  }
488  iTo.addKeyValue(typeName, columns);
489  }
490  iTo.addKeyValue(kConfigTypeNames, typeNames);
491 }
492 
493 void
495 {
496  try
497  {
498  const FWConfiguration *typeNames = iFrom.valueForKey(kConfigTypeNames);
499  if (typeNames == 0)
500  {
501  fwLog(fwlog::kWarning) << "no table column configuration stored, using defaults\n";
502  return;
503  }
504 
505  //NOTE: FWTableViewTableManagers hold pointers into m_tableFormats so if we
506  // clear it those pointers would be invalid
507  // instead we will just clear the lists and fill them with their new values
508  //m_tableFormats.clear();
510  iType = typeNames->stringValues()->begin(),
511  iTypeEnd = typeNames->stringValues()->end();
512  iType != iTypeEnd; ++iType)
513  {
514  //std::cout << "reading type " << *iType << std::endl;
515  const FWConfiguration *columns = iFrom.valueForKey(*iType);
516  assert(columns != 0);
517  TableHandle handle = table(iType->c_str());
519  it = columns->stringValues()->begin(),
520  itEnd = columns->stringValues()->end();
521  it != itEnd; ++it)
522  {
523  const std::string &name = *it++;
524  const std::string &expr = *it++;
525  int prec = atoi(it->c_str());
526  handle.column(name.c_str(), prec, expr.c_str());
527  }
528  }
529  }
530  catch (...)
531  {
532  // No info about types in the configuration; this is not an
533  // error, it merely means that the types are handled by the
534  // first FWTableView.
535  }
536 }
tuple base
Main Program
Definition: newFWLiteAna.py:92
const StringValues * stringValues() const
int i
Definition: DBlmapReader.cc:9
void addToImpl(FWConfiguration &) const
TableHandle table(const char *collection)
static TypeWithDict byName(std::string const &className)
virtual FWTypeToRepresentations supportedTypesAndRepresentations() const
void setFrom(const FWConfiguration &)
virtual void newItem(const FWEventItem *)
TableHandle & column(const char *formula, int precision, const char *name)
const std::string & typeName() const
Definition: FWViewBase.cc:120
FWItemChangeSignal goingToBeDestroyed_
Definition: FWEventItem.h:214
std::string name() const
FWColorManager & colorManager() const
boost::function2< FWViewBase *, TEveWindowSlot *, const std::string & > ViewBuildFunctor
Definition: FWGUIManager.h:99
void registerViewBuilder(const std::string &iName, ViewBuildFunctor &iBuilder)
bool isPublic() const
TableSpecs::iterator tableFormats(const edm::TypeWithDict &key)
void updateItems()
Definition: FWTableView.cc:546
std::string name() const
TypeWithDict returnType() const
TableSpecs::iterator tableFormatsImpl(const edm::TypeWithDict &key)
friend class FWTableView
tuple handle
Definition: patZpeak.py:22
std::string name() const
double f[11][100]
TypeWithDict typeOf() const
std::vector< TableEntry > TableEntries
bool isConst() const
FWConfiguration & addKeyValue(const std::string &, const FWConfiguration &)
void addTo(FWConfiguration &) const
FWConfiguration & addValue(const std::string &)
#define column(...)
Definition: DbCore.h:74
#define fwLog(_level_)
Definition: fwLog.h:50
virtual void modelChangesDone()
virtual void colorsChanged()
void destroyItem(const FWEventItem *item)
size_t functionParameterSize(bool required=false) const
list key
Definition: combine.py:13
virtual void modelChangesComing()
static const std::string & idToName(int)
Definition: FWViewType.cc:89
const FWConfiguration * valueForKey(const std::string &iKey) const
StringValues::const_iterator StringValuesIt
void dataChanged()
Definition: FWTableView.cc:585
static const std::string kConfigTypeNames
void beingDestroyed(const FWViewBase *)
FWViewBase * buildView(TEveWindowSlot *iParent, const std::string &type)