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 // $Id: FWTableViewManager.cc,v 1.27 2013/02/10 22:12:04 wmtan Exp $
12 //
13 
14 // system include files
15 #include <iostream>
16 #include <boost/bind.hpp>
17 #include <algorithm>
18 
19 #include "TEveManager.h"
20 #include "TClass.h"
24 
25 // user include files
31 
34 
35 
36 //
37 // constants, enums and typedefs
38 //
39 
40 //
41 // static data member definitions
42 //
43 
44 //
45 // constructors and destructor
46 //
49 {
51  f=boost::bind(&FWTableViewManager::buildView,
52  this, _1, _2);
54 
55  // ---------- for some object types, we have default table contents ----------
56  table("reco::GenParticle").
57  column("pT", 1, "pt").
58  column("eta", 3).
59  column("phi", 3).
60  column("status", TableEntry::INT).
61  column("pdgId", TableEntry::INT);
62 
63  table("reco::Muon").
64  column("q", TableEntry::INT, "charge").
65  column("pT", 1, "pt").
66  column("global", TableEntry::BOOL, "isGlobalMuon").
67  column("tracker", TableEntry::BOOL, "isTrackerMuon").
68  column("SA", TableEntry::BOOL, "isStandAloneMuon").
69  column("calo", TableEntry::BOOL, "isCaloMuon").
70  column("tr pt", 1, "track().pt()").
71  column("eta", 3).
72  column("phi", 3).
73  column("matches", TableEntry::INT, "numberOfMatches('SegmentArbitration')").
74  column("d0", 3, "track().d0()").
75  column("d0 / d0Err", 3, "track().d0() / track().d0Error()");
76 
77  table("reco::GsfElectron").
78  column("q", TableEntry::INT, "charge").
79  column("pT", 1, "pt").
80  column("eta", 3).
81  column("phi", 3).
82  column("E/p", 3, "eSuperClusterOverP").
83  column("H/E", 3, "hadronicOverEm").
84  column("fbrem", 3, "(trackMomentumAtVtx().R() - trackMomentumOut().R()) / trackMomentumAtVtx().R()").
85  column("dei", 3, "deltaEtaSuperClusterTrackAtVtx()").
86  column("dpi", 3, "deltaPhiSuperClusterTrackAtVtx()");
87 
88  table("reco::Photon").
89  column("pT", 1, "pt").
90  column("eta", 3).
91  column("phi", 3).
92  column("H/E", 3, "hadronicOverEm");
93 
94  table("reco::CaloJet").
95  column("pT", 1, "pt").
96  column("eta", 3).
97  column("phi", 3).
98  column("ECAL", 1, "p4().E() * emEnergyFraction()").
99  column("HCAL", 1, "p4().E() * energyFractionHadronic()").
100  column("emf", 3, "emEnergyFraction()");
101 
102  table("reco::Jet").
103  column("pT", 1, "pt").
104  column("eta", 3).
105  column("phi", 3);
106 
107  table("reco::MET").
108  column("et", 1).
109  column("phi", 3).
110  column("sumEt", 1).
111  column("mEtSig", 3);
112 
113  table("reco::Track").
114  column("q", TableEntry::INT, "charge").
115  column("pT", 1, "pt").
116  column("eta", 3).
117  column("phi", 3).
118  column("d0", 5).
119  column("d0Err", 5, "d0Error").
120  column("dz", 5).
121  column("dzErr", 5, "dzError").
122  column("vx", 5).
123  column("vy", 5).
124  column("vz", 5).
125  column("pixel hits", TableEntry::INT, "hitPattern().numberOfValidPixelHits()").
126  column("strip hits", TableEntry::INT, "hitPattern().numberOfValidStripHits()").
127  column("chi2", 3).
128  column("ndof", TableEntry::INT);
129 
130  table("reco::Vertex").
131  column("x", 5).
132  column("xError", 5).
133  column("y", 5).
134  column("yError", 5).
135  column("z", 5).
136  column("zError", 5).
137  column("tracks", TableEntry::INT, "tracksSize").
138  column("chi2", 3).
139  column("ndof", 3);
140 
141  table("CaloTower").
142  column("emEt", 1).
143  column("hadEt", 1).
144  column("et", 1, "Et").
145  column("eta", 3).
146  column("phi", 3);
147 
148  table("CaloRecHit").
149  column("id", TableEntry::INT,"detid.rawId").
150  column("energy",3).
151  column("time",3).
152  column("flags",TableEntry::INT,"flags");
153 }
154 
156 {
157 }
158 
159 //
160 // member functions
161 //
162 
177 {
179  return handle;
180 }
181 
191 FWTableViewManager::TableHandle::column(const char *name, int precision, const char *expression)
192 {
193  TableEntry columnEntry;
194  columnEntry.name = name;
195  columnEntry.precision = precision;
196  columnEntry.expression = expression;
197 
198  m_specs[m_name].push_back(columnEntry);
199  return *this;
200 }
201 
205 FWTableViewManager::TableSpecs::iterator
207 {
208  TableSpecs::iterator ret = m_tableFormats.find(key.name());
209  if (ret != m_tableFormats.end())
210  return ret;
211 
212  // if there is no exact match for the type, try the base classes
213  edm::TypeBases bases(key);
214  for (auto const& base : bases)
215  {
216  ret = tableFormatsImpl(edm::BaseWithDict(base).typeOf());
217  if (ret != m_tableFormats.end())
218  return ret;
219  }
220 
221  return m_tableFormats.end();
222 }
223 
237 FWTableViewManager::TableSpecs::iterator
239 {
240  static const std::string isint("int");
241  static const std::string isbool("bool");
242  static const std::string isdouble("double");
243  static const std::string isfloat("float");
244 
245  std::string keyType = key.name();
246 
247  TableSpecs::iterator ret = m_tableFormats.find(keyType);
248 
249  if (ret != m_tableFormats.end())
250  return ret;
251 
252  ret = tableFormatsImpl(key); // recursive search for base classes
253 
254  if (ret != m_tableFormats.end())
255  return ret;
256 
257  TableHandle handle = table(keyType.c_str());
258  edm::TypeFunctionMembers functionMembers(key);
259  for (auto const& member : functionMembers)
260  {
261  edm::FunctionWithDict m(member);
262  if (m.functionParameterSize())
263  continue;
264  if (!m.isPublic())
265  continue;
266  if (!m.isConst())
267  continue;
268  if (m.returnType().name() == isint)
269  handle.column(m.name().c_str(), TableEntry::INT);
270  else if (m.returnType().name() == isbool)
271  handle.column(m.name().c_str(), TableEntry::BOOL);
272  else if (m.returnType().name() == isdouble)
273  handle.column(m.name().c_str(), 5);
274  else if (m.returnType().name() == isfloat)
275  handle.column(m.name().c_str(), 3);
276  }
277  edm::TypeDataMembers dataMembers(key);
278  for (auto const& member : dataMembers)
279  {
280  edm::MemberWithDict m(member);
281  if (!m.isPublic())
282  continue;
283  if (!m.isConst())
284  continue;
285  if (m.typeOf().name() == isint)
286  handle.column(m.name().c_str(), TableEntry::INT);
287  else if (m.typeOf().name() == isbool)
288  handle.column(m.name().c_str(), TableEntry::BOOL);
289  else if (m.typeOf().name() == isdouble)
290  handle.column(m.name().c_str(), 5);
291  else if (m.typeOf().name() == isfloat)
292  handle.column(m.name().c_str(), 3);
293  }
294  return m_tableFormats.find(keyType);
295 }
296 
302 FWTableViewManager::TableSpecs::iterator
304 {
305  return tableFormats(edm::TypeWithDict::byName(key.GetName()));
306 }
307 
308 class FWViewBase*
309 FWTableViewManager::buildView(TEveWindowSlot* iParent, const std::string& /*type*/)
310 {
311  TEveManager::TRedrawDisabler disableRedraw(gEve);
312  boost::shared_ptr<FWTableView> view(new FWTableView(iParent, this));
313  view->setBackgroundColor(colorManager().background());
314  m_views.push_back(view);
315  view->beingDestroyed_.connect(boost::bind(&FWTableViewManager::beingDestroyed,
316  this, _1));
317  return view.get();
318 }
319 
320 void
322 {
323  for(Views::iterator it = m_views.begin(), itEnd = m_views.end();
324  it != itEnd;
325  ++it)
326  {
327  if(it->get() == iView)
328  {
329  m_views.erase(it);
330  return;
331  }
332  }
333 }
334 
335 void
337 {
338  m_items.push_back(iItem);
339  iItem->goingToBeDestroyed_.connect(boost::bind(&FWTableViewManager::destroyItem,
340  this, _1));
341  notifyViews();
342 }
343 
345 void
347 {
348  for(size_t i = 0, e = m_views.size(); i != e; ++i)
349  {
350  FWTableView *view = m_views[i].get();
351  view->updateItems();
352  view->dataChanged();
353  }
354 }
355 
361 void
363 {
364  // remove the item from the list
365  // FIXME: why doesn't it use erase?? Boh...
366  for (size_t i = 0, e = m_items.size(); i != e; ++i)
367  {
368  if (m_items[i] != iItem)
369  continue;
370  m_items[i] = 0;
371  }
372 
373  notifyViews();
374 }
375 
380 void
382 {
383  m_items.clear();
384  notifyViews();
385 }
386 
387 void
389 {
390  gEve->DisableRedraw();
391 }
392 
393 void
395 {
396  gEve->EnableRedraw();
397  // tell the views to update their item lists
398  // FIXME: doesn't this need to call updateItems as well
399  // and hence notifyViews would be more appropriate?? Boh...
400  dataChanged();
401 }
402 
404 void
406 {
407  for(size_t i = 0, e = m_views.size(); i != e; ++i)
408  m_views[i].get()->resetColors(colorManager());
409 }
410 
411 void
413 {
414  for(size_t i = 0, e = m_views.size(); i != e; ++i)
415  m_views[i].get()->dataChanged();
416 }
417 
420 {
421  FWTypeToRepresentations returnValue;
422  return returnValue;
423 }
424 
426 
427 void
429 {
430  // if there are views, it's the job of the first view to store
431  // the configuration (this is to avoid ordering problems in the
432  // case of multiple views)
433  if (!m_views.empty())
434  return;
435  // if there are no views, then it's up to us to store the column
436  // formats. This is done in addToImpl, which can be called by
437  // FWTableView as well
438  addToImpl(iTo);
439 }
440 
441 void
443 {
444  FWConfiguration typeNames(1);
445  char prec[100];
446 
447  for (TableSpecs::const_iterator
448  iType = m_tableFormats.begin(),
449  iType_end = m_tableFormats.end();
450  iType != iType_end; ++iType)
451  {
452  const std::string &typeName = iType->first;
453  typeNames.addValue(typeName);
454  FWConfiguration columns(1);
455  const TableEntries &entries = iType->second;
456  for (size_t ei = 0, ee = entries.size(); ei != ee; ++ei)
457  {
458  const TableEntry &entry = entries[ei];
459  columns.addValue(entry.name);
460  columns.addValue(entry.expression);
461  columns.addValue((snprintf(prec, 100, "%d", entry.precision), prec));
462  }
463  iTo.addKeyValue(typeName, columns);
464  }
465  iTo.addKeyValue(kConfigTypeNames, typeNames);
466 }
467 
468 void
470 {
471  try
472  {
473  const FWConfiguration *typeNames = iFrom.valueForKey(kConfigTypeNames);
474  if (typeNames == 0)
475  {
476  fwLog(fwlog::kWarning) << "no table column configuration stored, using defaults\n";
477  return;
478  }
479 
480  //NOTE: FWTableViewTableManagers hold pointers into m_tableFormats so if we
481  // clear it those pointers would be invalid
482  // instead we will just clear the lists and fill them with their new values
483  //m_tableFormats.clear();
485  iType = typeNames->stringValues()->begin(),
486  iTypeEnd = typeNames->stringValues()->end();
487  iType != iTypeEnd; ++iType)
488  {
489  //std::cout << "reading type " << *iType << std::endl;
490  const FWConfiguration *columns = iFrom.valueForKey(*iType);
491  assert(columns != 0);
492  TableHandle handle = table(iType->c_str());
494  it = columns->stringValues()->begin(),
495  itEnd = columns->stringValues()->end();
496  it != itEnd; ++it)
497  {
498  const std::string &name = *it++;
499  const std::string &expr = *it++;
500  int prec = atoi(it->c_str());
501  handle.column(name.c_str(), prec, expr.c_str());
502  }
503  }
504  }
505  catch (...)
506  {
507  // No info about types in the configuration; this is not an
508  // error, it merely means that the types are handled by the
509  // first FWTableView.
510  }
511 }
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:121
FWItemChangeSignal goingToBeDestroyed_
Definition: FWEventItem.h:215
std::string name() const
FWColorManager & colorManager() const
boost::function2< FWViewBase *, TEveWindowSlot *, const std::string & > ViewBuildFunctor
Definition: FWGUIManager.h:100
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
TypeWithDict returnType() const
TableSpecs::iterator tableFormatsImpl(const edm::TypeWithDict &key)
std::pair< std::string, MonitorElement * > entry
Definition: ME_MAP.h:8
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 fwLog(_level_)
Definition: fwLog.h:51
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:90
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)