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.22 2012/06/26 22:13: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"
21 #include "Reflex/Base.h"
22 
23 // user include files
29 
32 
33 
34 //
35 // constants, enums and typedefs
36 //
37 
38 //
39 // static data member definitions
40 //
41 
42 //
43 // constructors and destructor
44 //
47 {
49  f=boost::bind(&FWTableViewManager::buildView,
50  this, _1, _2);
52 
53  // ---------- for some object types, we have default table contents ----------
54  table("reco::GenParticle").
55  column("pT", 1, "pt").
56  column("eta", 3).
57  column("phi", 3).
58  column("status", TableEntry::INT).
59  column("pdgId", TableEntry::INT);
60 
61  table("reco::Muon").
62  column("q", TableEntry::INT, "charge").
63  column("pT", 1, "pt").
64  column("global", TableEntry::BOOL, "isGlobalMuon").
65  column("tracker", TableEntry::BOOL, "isTrackerMuon").
66  column("SA", TableEntry::BOOL, "isStandAloneMuon").
67  column("calo", TableEntry::BOOL, "isCaloMuon").
68  column("tr pt", 1, "track().pt()").
69  column("eta", 3).
70  column("phi", 3).
71  column("matches", TableEntry::INT, "numberOfMatches('SegmentArbitration')").
72  column("d0", 3, "track().d0()").
73  column("d0 / d0Err", 3, "track().d0() / track().d0Error()");
74 
75  table("reco::GsfElectron").
76  column("q", TableEntry::INT, "charge").
77  column("pT", 1, "pt").
78  column("eta", 3).
79  column("phi", 3).
80  column("E/p", 3, "eSuperClusterOverP").
81  column("H/E", 3, "hadronicOverEm").
82  column("fbrem", 3, "(trackMomentumAtVtx().R() - trackMomentumOut().R()) / trackMomentumAtVtx().R()").
83  column("dei", 3, "deltaEtaSuperClusterTrackAtVtx()").
84  column("dpi", 3, "deltaPhiSuperClusterTrackAtVtx()");
85 
86  table("reco::Photon").
87  column("pT", 1, "pt").
88  column("eta", 3).
89  column("phi", 3).
90  column("H/E", 3, "hadronicOverEm");
91 
92  table("reco::CaloJet").
93  column("pT", 1, "pt").
94  column("eta", 3).
95  column("phi", 3).
96  column("ECAL", 1, "p4().E() * emEnergyFraction()").
97  column("HCAL", 1, "p4().E() * energyFractionHadronic()").
98  column("emf", 3, "emEnergyFraction()");
99 
100  table("reco::Jet").
101  column("pT", 1, "pt").
102  column("eta", 3).
103  column("phi", 3);
104 
105  table("reco::MET").
106  column("et", 1).
107  column("phi", 3).
108  column("sumEt", 1).
109  column("mEtSig", 3);
110 
111  table("reco::Track").
112  column("q", TableEntry::INT, "charge").
113  column("pT", 1, "pt").
114  column("eta", 3).
115  column("phi", 3).
116  column("d0", 5).
117  column("d0Err", 5, "d0Error").
118  column("dz", 5).
119  column("dzErr", 5, "dzError").
120  column("vx", 5).
121  column("vy", 5).
122  column("vz", 5).
123  column("pixel hits", TableEntry::INT, "hitPattern().numberOfValidPixelHits()").
124  column("strip hits", TableEntry::INT, "hitPattern().numberOfValidStripHits()").
125  column("chi2", 3).
126  column("ndof", TableEntry::INT);
127 
128  table("reco::Vertex").
129  column("x", 5).
130  column("xError", 5).
131  column("y", 5).
132  column("yError", 5).
133  column("z", 5).
134  column("zError", 5).
135  column("tracks", TableEntry::INT, "tracksSize").
136  column("chi2", 3).
137  column("ndof", 3);
138 
139  table("CaloTower").
140  column("emEt", 1).
141  column("hadEt", 1).
142  column("et", 1, "Et").
143  column("eta", 3).
144  column("phi", 3);
145 
146  table("CaloRecHit").
147  column("id", TableEntry::INT,"detid.rawId").
148  column("energy",3).
149  column("time",3).
150  column("flags",TableEntry::INT,"flags");
151 }
152 
154 {
155 }
156 
157 //
158 // member functions
159 //
160 
175 {
177  return handle;
178 }
179 
189 FWTableViewManager::TableHandle::column(const char *name, int precision, const char *expression)
190 {
191  TableEntry columnEntry;
192  columnEntry.name = name;
193  columnEntry.precision = precision;
194  columnEntry.expression = expression;
195 
196  m_specs[m_name].push_back(columnEntry);
197  return *this;
198 }
199 
203 FWTableViewManager::TableSpecs::iterator
205 {
206  TableSpecs::iterator ret = m_tableFormats.find(key.Name(Reflex::SCOPED));
207  if (ret != m_tableFormats.end())
208  return ret;
209 
210  // if there is no exact match for the type, try the base classes
211  for (Reflex::Base_Iterator it = key.Base_Begin(); it != key.Base_End(); ++it)
212  {
213  ret = tableFormatsImpl(it->ToType());
214  if (ret != m_tableFormats.end())
215  return ret;
216  }
217 
218  return m_tableFormats.end();
219 }
220 
234 FWTableViewManager::TableSpecs::iterator
236 {
237  std::string keyType = key.Name(Reflex::SCOPED);
238 
239  TableSpecs::iterator ret = m_tableFormats.find(keyType);
240 
241  if (ret != m_tableFormats.end())
242  return ret;
243 
244  ret = tableFormatsImpl(key); // recursive search for base classes
245 
246  if (ret != m_tableFormats.end())
247  return ret;
248 
249  TableHandle handle = table(keyType.c_str());
250  for (Reflex::Member_Iterator mi = key.Member_Begin(),
251  me = key.Member_End();
252  mi != me; ++mi)
253  {
254  if (mi->FunctionParameterSize())
255  continue;
256  if (!mi->IsPublic())
257  continue;
258  if (!mi->IsConst())
259  continue;
260  if (mi->TypeOf().ReturnType().Name() == "int")
261  handle.column(mi->Name().c_str(), TableEntry::INT);
262  else if (mi->TypeOf().ReturnType().Name() == "bool")
263  handle.column(mi->Name().c_str(), TableEntry::BOOL);
264  else if (mi->TypeOf().ReturnType().Name() == "double")
265  handle.column(mi->Name().c_str(), 5);
266  else if (mi->TypeOf().ReturnType().Name() == "float")
267  handle.column(mi->Name().c_str(), 3);
268  }
269  return m_tableFormats.find(keyType);
270 }
271 
277 FWTableViewManager::TableSpecs::iterator
279 {
280  return tableFormats(Reflex::Type::ByName(key.GetName()));
281 }
282 
283 class FWViewBase*
284 FWTableViewManager::buildView(TEveWindowSlot* iParent, const std::string& /*type*/)
285 {
286  TEveManager::TRedrawDisabler disableRedraw(gEve);
287  boost::shared_ptr<FWTableView> view(new FWTableView(iParent, this));
288  view->setBackgroundColor(colorManager().background());
289  m_views.push_back(view);
290  view->beingDestroyed_.connect(boost::bind(&FWTableViewManager::beingDestroyed,
291  this, _1));
292  return view.get();
293 }
294 
295 void
297 {
298  for(Views::iterator it = m_views.begin(), itEnd = m_views.end();
299  it != itEnd;
300  ++it)
301  {
302  if(it->get() == iView)
303  {
304  m_views.erase(it);
305  return;
306  }
307  }
308 }
309 
310 void
312 {
313  m_items.push_back(iItem);
314  iItem->goingToBeDestroyed_.connect(boost::bind(&FWTableViewManager::destroyItem,
315  this, _1));
316  notifyViews();
317 }
318 
320 void
322 {
323  for(size_t i = 0, e = m_views.size(); i != e; ++i)
324  {
325  FWTableView *view = m_views[i].get();
326  view->updateItems();
327  view->dataChanged();
328  }
329 }
330 
336 void
338 {
339  // remove the item from the list
340  // FIXME: why doesn't it use erase?? Boh...
341  for (size_t i = 0, e = m_items.size(); i != e; ++i)
342  {
343  if (m_items[i] != iItem)
344  continue;
345  m_items[i] = 0;
346  }
347 
348  notifyViews();
349 }
350 
355 void
357 {
358  m_items.clear();
359  notifyViews();
360 }
361 
362 void
364 {
365  gEve->DisableRedraw();
366 }
367 
368 void
370 {
371  gEve->EnableRedraw();
372  // tell the views to update their item lists
373  // FIXME: doesn't this need to call updateItems as well
374  // and hence notifyViews would be more appropriate?? Boh...
375  dataChanged();
376 }
377 
379 void
381 {
382  for(size_t i = 0, e = m_views.size(); i != e; ++i)
383  m_views[i].get()->resetColors(colorManager());
384 }
385 
386 void
388 {
389  for(size_t i = 0, e = m_views.size(); i != e; ++i)
390  m_views[i].get()->dataChanged();
391 }
392 
395 {
396  FWTypeToRepresentations returnValue;
397  return returnValue;
398 }
399 
400 const std::string FWTableViewManager::kConfigTypeNames = "typeNames";
401 
402 void
404 {
405  // if there are views, it's the job of the first view to store
406  // the configuration (this is to avoid ordering problems in the
407  // case of multiple views)
408  if (!m_views.empty())
409  return;
410  // if there are no views, then it's up to us to store the column
411  // formats. This is done in addToImpl, which can be called by
412  // FWTableView as well
413  addToImpl(iTo);
414 }
415 
416 void
418 {
419  FWConfiguration typeNames(1);
420  char prec[100];
421 
422  for (TableSpecs::const_iterator
423  iType = m_tableFormats.begin(),
424  iType_end = m_tableFormats.end();
425  iType != iType_end; ++iType)
426  {
427  const std::string &typeName = iType->first;
428  typeNames.addValue(typeName);
429  FWConfiguration columns(1);
430  const TableEntries &entries = iType->second;
431  for (size_t ei = 0, ee = entries.size(); ei != ee; ++ei)
432  {
433  const TableEntry &entry = entries[ei];
434  columns.addValue(entry.name);
435  columns.addValue(entry.expression);
436  columns.addValue((snprintf(prec, 100, "%d", entry.precision), prec));
437  }
438  iTo.addKeyValue(typeName, columns);
439  }
440  iTo.addKeyValue(kConfigTypeNames, typeNames);
441 }
442 
443 void
445 {
446  try
447  {
448  const FWConfiguration *typeNames = iFrom.valueForKey(kConfigTypeNames);
449  if (typeNames == 0)
450  {
451  fwLog(fwlog::kWarning) << "no table column configuration stored, using defaults\n";
452  return;
453  }
454 
455  //NOTE: FWTableViewTableManagers hold pointers into m_tableFormats so if we
456  // clear it those pointers would be invalid
457  // instead we will just clear the lists and fill them with their new values
458  //m_tableFormats.clear();
460  iType = typeNames->stringValues()->begin(),
461  iTypeEnd = typeNames->stringValues()->end();
462  iType != iTypeEnd; ++iType)
463  {
464  //std::cout << "reading type " << *iType << std::endl;
465  const FWConfiguration *columns = iFrom.valueForKey(*iType);
466  assert(columns != 0);
467  TableHandle handle = table(iType->c_str());
469  it = columns->stringValues()->begin(),
470  itEnd = columns->stringValues()->end();
471  it != itEnd; ++it)
472  {
473  const std::string &name = *it++;
474  const std::string &expr = *it++;
475  int prec = atoi(it->c_str());
476  handle.column(name.c_str(), prec, expr.c_str());
477  }
478  }
479  }
480  catch (...)
481  {
482  // No info about types in the configuration; this is not an
483  // error, it merely means that the types are handled by the
484  // first FWTableView.
485  }
486 }
const StringValues * stringValues() const
int i
Definition: DBlmapReader.cc:9
void addToImpl(FWConfiguration &) const
TableHandle table(const char *collection)
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
FWColorManager & colorManager() const
boost::function2< FWViewBase *, TEveWindowSlot *, const std::string & > ViewBuildFunctor
Definition: FWGUIManager.h:100
void registerViewBuilder(const std::string &iName, ViewBuildFunctor &iBuilder)
void updateItems()
Definition: FWTableView.cc:546
std::pair< std::string, MonitorElement * > entry
Definition: ME_MAP.h:8
friend class FWTableView
tuple handle
Definition: patZpeak.py:22
TableSpecs::iterator tableFormatsImpl(const Reflex::Type &key)
double f[11][100]
std::vector< TableEntry > TableEntries
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)
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:585
static const std::string kConfigTypeNames
TableSpecs::iterator tableFormats(const Reflex::Type &key)
void beingDestroyed(const FWViewBase *)
FWViewBase * buildView(TEveWindowSlot *iParent, const std::string &type)