CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FWEventItem.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Core
4 // Class : FWEventItem
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author:
10 // Created: Thu Jan 3 14:59:23 EST 2008
11 //
12 
13 // system include files
14 #include <iostream>
15 #include <algorithm>
16 #include <exception>
17 #include <TClass.h>
18 
19 // user include files
22 // Needed to test edm::Event access
23 // #include "FWCore/Framework/interface/Event.h"
33 
34 //
35 // static data member definitions
36 //
37 
39 {
40  return -100;
41 }
42 
44 {
45  return 100;
46 }
47 
48 
49 //
50 // constructors and destructor
51 //
53  unsigned int iId,
54  boost::shared_ptr<FWItemAccessorBase> iAccessor,
55  const FWPhysicsObjectDesc& iDesc, bool showFiltered, const FWConfiguration* pbc) :
56  m_context(iContext),
57  m_id(iId),
58  m_name(iDesc.name()),
59  m_type(iDesc.type()),
60  m_purpose(iDesc.purpose()),
61  m_accessor(iAccessor),
62  m_displayProperties(iDesc.displayProperties()),
63  m_layer(iDesc.layer()),
64  m_moduleLabel(iDesc.moduleLabel()),
65  m_productInstanceLabel(iDesc.productInstanceLabel()),
66  m_processName(iDesc.processName()),
67  m_event(0),
68  m_interestingValueGetter(edm::TypeWithDict(*(m_accessor->modelType()->GetTypeInfo())), m_purpose),
69  m_filter(iDesc.filterExpression(),""),
70  m_showFilteredEntries(showFiltered),
71  m_printedErrorThisEvent(false),
72  m_isSelected(false),
73  m_proxyBuilderConfig(0)
74 {
75  //assert(m_type->GetTypeInfo());
76  //edm::TypeWithDict dataType(*(m_type->GetTypeInfo()));
77  //assert(dataType != edm::TypeWithDict() );
78  //
79  //std::string dataTypeName = dataType.name();
80  //if (dataTypeName[dataTypeName.size() -1] == '>')
81  // dataTypeName += " ";
82  //std::string wrapperName = "edm::Wrapper<" + dataTypeName + ">";
83  //
84  //fwLog(fwlog::kDebug) << "Looking for the wrapper name"
85  // << wrapperName << std::endl;
86  //m_wrapperType = edm::TypeWithDict::byName(wrapperName);
87  //
88  //assert(m_wrapperType != edm::TypeWithDict());
89  if(!m_accessor->isCollection()) {
90  m_itemInfos.reserve(1);
91  }
92  m_filter.setClassName(modelType()->GetName());
94 }
95 // FWEventItem::FWEventItem(const FWEventItem& rhs)
96 // {
97 // // do actual copying here;
98 // }
99 
101 {
102  delete m_proxyBuilderConfig;
103 }
104 
105 //
106 // assignment operators
107 //
108 // const FWEventItem& FWEventItem::operator=(const FWEventItem& rhs)
109 // {
110 // //An exception safe implementation is
111 // FWEventItem temp(rhs);
112 // swap(rhs);
113 //
114 // return *this;
115 // }
116 
117 //
118 // member functions
119 //
120 void
122 {
123  m_printedErrorThisEvent = false;
124  m_event = iEvent;
125  m_accessor->reset();
126  m_itemInfos.clear();
127  handleChange();
128 }
129 
130 void
132  const std::string& iProductInstance,
133  const std::string& iProcess)
134 {
135  m_moduleLabel = iModule;
136  m_productInstanceLabel = iProductInstance;
137  m_processName = iProcess;
138  m_accessor->reset();
139  m_itemInfos.clear();
140  handleChange();
141 }
142 
143 void
145 {
146  m_name = iName;
147 }
148 
155 void
157 {
158  bool visChange = m_displayProperties.isVisible() != iProp.isVisible();
159  bool colorChanged = m_displayProperties.color() != iProp.color();
160  bool transparencyChanged = m_displayProperties.transparency() != iProp.transparency();
161 
162  if(!visChange && !colorChanged && !transparencyChanged) {
163  return;
164  }
165  //If the default visibility is changed, we want to also change the the visibility of the children
166  // BUT we want to remember the old visibility so if the visibility is changed again we return
167  // to the previous state.
168  // only the visible ones need to be marked as 'changed'
169  FWChangeSentry sentry(*(changeManager()));
170 
171  for(int index=0; index <static_cast<int>(size()); ++index) {
172  FWDisplayProperties prp = m_itemInfos[index].displayProperties();
173  bool vis=prp.isVisible();
174  bool changed = false;
175  changed = visChange && vis;
176 
177  if(colorChanged) {
178  if(m_displayProperties.color()==prp.color()) {
179  prp.setColor(iProp.color());
180  changed = true;
181  }
182  }
183  if (transparencyChanged) {
185  prp.setTransparency(iProp.transparency());
186  changed = true;
187  }
188  }
189  if(changed) {
190  m_itemInfos[index].m_displayProperties=prp;
191  FWModelId id(this,index);
192  changeManager()->changed(id);
193  }
194  }
195  m_displayProperties= iProp;
197 }
198 
199 void
201 {
202  m_filter.setExpression(iExpression);
203  filterChanged_(this);
204  runFilter();
205 }
206 
207 void
209 {
211  handleChange(false);
212 }
213 
214 void
216 {
217  if(m_accessor->isCollection() && m_accessor->data()) {
218  //std::cout <<"runFilter"<<std::endl;
219  FWChangeSentry sentry(*(this->changeManager()));
220  int size = m_accessor->size();
221  std::vector<ModelInfo>::iterator itInfo = m_itemInfos.begin();
222  try {
223  for(int index = 0; index != size; ++index,++itInfo) {
224  bool changed = false;
225  bool wasVisible = itInfo->m_displayProperties.isVisible();
226  if(not m_filter.passesFilter(m_accessor->modelData(index))) {
227  itInfo->m_displayProperties.setIsVisible(false);
228  itInfo->m_displayProperties.setFilterPassed(false);
229  changed = wasVisible==true;
230 
231  } else {
232  itInfo->m_displayProperties.setIsVisible(true);
233  itInfo->m_displayProperties.setFilterPassed(true);
234  changed = wasVisible==false;
235  }
236  if(changed) {
237  FWModelId id(this,index);
238  changeManager()->changed(id);
239  }
240  }
241  } catch( const std::exception& iException) {
242  //Should log this error
243  std::cerr <<"Exception occurred while running filter on "<<name()<<"\n"
244  <<iException.what()<<std::endl;
245  }
246  }
247 }
248 
249 void
250 FWEventItem::unselect(int iIndex) const
251 {
252  //check if this is a change
253  if(bool& sel = m_itemInfos.at(iIndex).m_isSelected) {
254  sel=false;
255  FWModelId id(this,iIndex);
256  selectionManager()->unselect(id);
257  changeManager()->changed(id);
258  }
259 }
260 void
261 FWEventItem::select(int iIndex) const
262 {
263  bool& sel = m_itemInfos.at(iIndex).m_isSelected;
264  if(not sel) {
265  sel = true;
266  FWModelId id(this,iIndex);
267  selectionManager()->select(id);
268  //want to make it obvious what type of object was selected
269  // therefore we also select the item
270  const_cast<FWEventItem*>(this)->selectItem();
271  changeManager()->changed(id);
272  }
273 }
274 void
275 FWEventItem::toggleSelect(int iIndex) const
276 {
277  bool& sel = m_itemInfos.at(iIndex).m_isSelected;
278  sel = not sel;
279  FWModelId id(this,iIndex);
280  if (sel)
281  selectionManager()->select(id);
282  else selectionManager()->unselect(id);
283  changeManager()->changed(id);
284 }
285 
286 void
288 {
289  FWDisplayProperties& prop = m_itemInfos.at(iIndex).m_displayProperties;
291  if( prop
292  != iProps ) {
293  prop = iProps;
294  FWModelId id(this,iIndex);
295  //selectionManager()->select(id);
296  changeManager()->changed(id);
297  }
298  } else {
299  if(iProps.isVisible()) {
300  FWChangeSentry sentry(*(this->changeManager()));
301  int size = m_accessor->size();
302  std::vector<ModelInfo>::iterator itInfo = m_itemInfos.begin();
303  for(int index = 0; index != size; ++index,++itInfo) {
304  if( itInfo->m_displayProperties.isVisible() ) {
305  itInfo->m_displayProperties.setIsVisible(false);
306  FWModelId id(this,index);
307  changeManager()->changed(id);
308  }
309  }
310  m_itemInfos.at(iIndex).m_displayProperties.setIsVisible(true);
311  FWModelId id(this,iIndex);
312  changeManager()->changed(id);
313  const_cast<FWEventItem*>(this)->m_displayProperties.setIsVisible(true);
314  //NOTE: need to send out a signal here
316  }
317  }
318 }
319 
320 void
322 {
324  int largest = layer();
326  itEnd = m_context->eventItemsManager()->end();
327  it != itEnd;
328  ++it) {
329  if ((*it) && (*it != this) && (*it)->layer() > largest) {
330  largest= (*it)->layer();
331  }
332  }
333 
334  if(largest >= layer()) {
335  m_layer = std::min(largest+1, maxLayerValue());
336  }
337 
338  m_itemInfos.clear();
339  m_accessor->reset();
340  handleChange(false);
341 }
342 
343 void
345 {
347  int smallest = layer();
349  itEnd = m_context->eventItemsManager()->end();
350  it != itEnd;
351  ++it) {
352  if((*it) && (*it != this) && (*it)->layer() < smallest) {
353  smallest= (*it)->layer();
354  }
355  }
356 
357  if(smallest <= layer()) {
358  m_layer = std::max(smallest-1, minLayerValue());
359  }
360 
361  m_itemInfos.clear();
362  m_accessor->reset();
363  handleChange(false);
364 }
365 
366 void
368 {
370 
372 
373  m_itemInfos.clear();
374  m_accessor->reset();
375  handleChange(false);
376 }
377 
378 void
380 {
381  m_itemInfos.clear();
382  m_accessor->reset();
384  handleChange();
385 
386 }
387 
388 void
389 FWEventItem::handleChange(bool filterUpdate)
390 {
391  preItemChanged_(this);
392  FWChangeSentry sentry(*(this->changeManager()));
393  //want filter to rerun after all changes have been made
394  changeManager()->changed(this);
395  if (filterUpdate) {
396  getPrimaryData();
397  runFilter();
398  }
399 }
400 
401 //
402 // const member functions
403 //
404 const void*
405 FWEventItem::data(const std::type_info& iInfo) const
406 {
407  //At the moment this is a programming error
408  assert(iInfo == *(m_type->GetTypeInfo()));
409 
410  //lookup data if we don't already have it
411  if (m_accessor->data())
412  return m_accessor->data();
413 
414  m_errorMessage.clear();
415  if (!m_event)
416  return m_accessor->data();
417 
418  // Retrieve the data from the event.
420  edm::TypeWithDict type(iInfo);
422  try
423  {
424  m_event->getByLabel(tag, handle);
425  setData(*handle);
426  }
427  catch (std::exception& iException)
428  {
430  {
431  std::ostringstream s;
432  s << "Failed to get " << name() << " because \n" <<iException.what();
433  m_errorMessage=s.str();
435  }
436  return 0;
437  }
438 
439  return m_accessor->data();
440 }
441 
442 void
444 {
445  m_accessor->setData(iData);
446  //std::cout <<"size "<<m_accessor->size()<<std::endl;
447  if(m_accessor->isCollection()) {
448  m_itemInfos.reserve(m_accessor->size());
449  m_itemInfos.resize(m_accessor->size(),ModelInfo(m_displayProperties,false));
450  } else {
451  m_itemInfos.push_back(ModelInfo(m_displayProperties,false));
452  }
453 }
454 
455 void
457 {
458  //if(0!=m_data) return;
459  if(0!=m_accessor->data()) return;
460  this->data(*(m_type->GetTypeInfo()));
461 }
462 
463 const FWDisplayProperties&
465 {
466  return m_displayProperties;
467 }
468 
469 int
471 {
472  return m_layer;
473 }
474 
475 bool
477 {
480  itEnd = m_context->eventItemsManager()->end();
481  it != itEnd;
482  ++it) {
483  if((*it) && (*it != this) && (*it)->layer() >= layer()) {
484  return false;
485  }
486  }
487  return true;
488 }
489 
490 bool
492 {
495  itEnd = m_context->eventItemsManager()->end();
496  it != itEnd;
497  ++it) {
498  if((*it) && (*it != this) && (*it)->layer() <= layer()) {
499  return false;
500  }
501  }
502  return true;
503 }
504 
505 
506 unsigned int
508 {
509  return m_id;
510 }
511 
512 const std::string&
514 {
515  return m_name;
516 }
517 
518 const TClass*
520 {
521  return m_type;
522 }
523 
524 const std::string&
526 {
527  return m_purpose;
528 }
529 
530 const std::string&
532 {
533  return m_moduleLabel;
534 }
535 const std::string&
537 {
538  return m_productInstanceLabel;
539 }
540 
541 const std::string&
543 {
544  return m_processName;
545 }
546 
548 FWEventItem::modelInfo(int iIndex) const
549 {
550  getPrimaryData();
552  return m_itemInfos.at(iIndex);
553  }
554 
555  FWDisplayProperties dp(m_itemInfos.at(iIndex).displayProperties());
556  dp.setIsVisible(false);
557  ModelInfo t(dp,m_itemInfos.at(iIndex).isSelected());
558  return t;
559 }
560 
561 size_t
563 {
564  getPrimaryData();
565  return m_itemInfos.size();
566 }
567 
568 bool
570 {
571  return m_accessor->isCollection();
572 }
573 
574 const TClass*
576 {
577  return m_accessor->modelType();
578 }
579 
580 const void*
581 FWEventItem::modelData(int iIndex) const
582 {
583  getPrimaryData();
584  return m_accessor->modelData(iIndex);
585 }
586 
588 FWEventItem::modelName(int iIndex) const
589 {
590  std::ostringstream s;
591  size_t lastChar = name().size();
592  //if name ends in 's' assume it is plural and remove the s for the individual object
593  if(name()[lastChar-1]=='s') {
594  --lastChar;
595  }
596  s<<name().substr(0,lastChar)<<" "<<iIndex;
597  return s.str();
598 }
599 
600 bool
602 {
603  return true; //m_interestingValueGetter.isValid();
604 }
605 
606 
607 const std::string&
609 {
610  getPrimaryData();
611  return m_interestingValueGetter.getToolTip(m_accessor->modelData(iIndex));
612 }
613 
614 
615 const std::string&
617 {
618  return m_filter.expression();
619 }
620 
621 void
623 {
624  //NOTE: need to unselect first before announcing destruction
625  // because some items are listening to the display change and may
626  // not properly release their connection to that signal after they
627  // are destroyed via a connection to goingToBeDestroyed_
628  const_cast<FWEventItem*>(this)->unselectItem();
629  {
630  FWChangeSentry sentry(*(changeManager()));
631 
632  for(int index=0; index <static_cast<int>(size()); ++index) {
633  if(m_itemInfos.at(index).m_isSelected) {
634  FWModelId id(this,index);
635  selectionManager()->unselect(id);
636  changeManager()->changed(id);
637  }
638  }
639  }
640  goingToBeDestroyed_(this);
641  delete this;
642 }
643 
644 
645 void
647 {
648  if(!m_isSelected) {
649  m_isSelected=true;
650  selectionManager()->selectItem(this);
652  }
653 }
654 void
656 {
657  if(m_isSelected) {
658  m_isSelected=false;
661  }
662 }
663 void
665 {
667  if(m_isSelected) {
668  selectionManager()->selectItem(this);
669  }else {
671  }
673 }
674 bool
676 {
677  return m_isSelected;
678 }
679 
680 bool
682  return !errorMessage().empty();
683 }
684 
685 const std::string&
687 {
688  if(m_errorMessage.empty()) {
689  getPrimaryData();
690  }
691  return m_errorMessage;
692 }
693 
694 const FWGeometry*
696  return m_context->getGeom();
697 }
698 //
699 // static member functions
700 //
const TClass * m_type
Definition: FWEventItem.h:233
type
Definition: HCALResponse.h:21
tuple t
Definition: tree.py:139
bool passesFilter(const void *) const
FWItemChangeSignal preItemChanged_
Definition: FWEventItem.h:208
const FWDisplayProperties & defaultDisplayProperties() const
Definition: FWEventItem.cc:464
void setColor(Color_t iColor)
FWModelChangeManager * changeManager() const
Definition: FWEventItem.h:133
void destroy() const
Definition: FWEventItem.cc:622
void moveToBack()
Definition: FWEventItem.cc:344
void select(const FWModelId &iId)
void moveToFront()
Definition: FWEventItem.cc:321
const FWEventItemsManager * eventItemsManager() const
Definition: Context.h:61
void moveToLayer(int layer)
Definition: FWEventItem.cc:367
std::string modelName(int iIndex) const
Definition: FWEventItem.cc:588
void setEvent(const edm::EventBase *iEvent)
Definition: FWEventItem.cc:121
const std::string & name() const
Definition: FWEventItem.cc:513
FWEventItem(fireworks::Context *iContext, unsigned int iItemId, boost::shared_ptr< FWItemAccessorBase > iAccessor, const FWPhysicsObjectDesc &iDesc, bool showFiltered=true, const FWConfiguration *pbConf=0)
Definition: FWEventItem.cc:52
FWItemValueGetter m_interestingValueGetter
Definition: FWEventItem.h:246
const FWGeometry * getGeom() const
Definition: Context.h:83
void proxyConfigChanged()
Definition: FWEventItem.cc:379
assert(m_qm.get())
void setDisplayProperties(int iIndex, const FWDisplayProperties &) const
Definition: FWEventItem.cc:287
const std::string & filterExpression() const
Definition: FWEventItem.cc:616
FWItemChangeSignal defaultDisplayPropertiesChanged_
Definition: FWEventItem.h:212
bool haveInterestingValue() const
Definition: FWEventItem.cc:601
void getPrimaryData() const
Definition: FWEventItem.cc:456
void unselect(int iIndex) const
Definition: FWEventItem.cc:250
FWItemChangeSignal goingToBeDestroyed_
Definition: FWEventItem.h:219
boost::shared_ptr< FWItemAccessorBase > m_accessor
Definition: FWEventItem.h:235
const fireworks::Context * m_context
Definition: FWEventItem.h:230
const std::string & expression() const
bool itemIsSelected() const
Definition: FWEventItem.cc:675
const std::string & processName() const
Definition: FWEventItem.cc:542
void setLabels(const std::string &iModule, const std::string &iProductInstance, const std::string &iProcess)
Definition: FWEventItem.cc:131
std::string m_moduleLabel
Definition: FWEventItem.h:241
static int maxLayerValue()
Definition: FWEventItem.cc:43
const void * data(const std::type_info &) const
Definition: FWEventItem.cc:405
Color_t color() const
int layer() const
Definition: FWEventItem.cc:470
bool m_showFilteredEntries
Definition: FWEventItem.h:249
unsigned int m_id
Definition: FWEventItem.h:231
void setShowFilteredEntries(bool x)
Definition: FWEventItem.cc:208
FWModelFilter m_filter
Definition: FWEventItem.h:248
Char_t transparency() const
int iEvent
Definition: GenABIO.cc:230
void setDefaultDisplayProperties(const FWDisplayProperties &)
Definition: FWEventItem.cc:156
const std::string & productInstanceLabel() const
Definition: FWEventItem.cc:536
void handleChange(bool filterUpdate=true)
Definition: FWEventItem.cc:389
std::string m_processName
Definition: FWEventItem.h:243
void setClassName(const std::string &)
const TClass * type() const
Definition: FWEventItem.cc:519
FWProxyBuilderConfiguration * m_proxyBuilderConfig
Definition: FWEventItem.h:256
void unselectItem(FWEventItem *)
tuple handle
Definition: patZpeak.py:22
unsigned int id() const
Definition: FWEventItem.cc:507
void unselect(const FWModelId &iId)
T min(T a, T b)
Definition: MathUtil.h:58
void setData(const edm::ObjectWithDict &) const
Definition: FWEventItem.cc:443
const std::string & modelInterestingValueAsString(int iIndex) const
Definition: FWEventItem.cc:608
static int minLayerValue()
Definition: FWEventItem.cc:38
bool m_printedErrorThisEvent
Definition: FWEventItem.h:250
m_id("(unknown)")
bool hasError() const
returns true if failed to get data for this event
Definition: FWEventItem.cc:681
FWSelectionManager * selectionManager() const
Definition: FWEventItem.h:136
void toggleSelect(int iIndex) const
Definition: FWEventItem.cc:275
void changed(const FWModelId &)
const_iterator begin() const
NOTE: iterator is allowed to return a null object for items that have been removed.
bool isInBack() const
returns true if item is behind all other items
Definition: FWEventItem.cc:491
size_t size() const
Definition: FWEventItem.cc:562
void setExpression(const std::string &)
FWDisplayProperties m_displayProperties
Definition: FWEventItem.h:236
void selectItem()
Definition: FWEventItem.cc:646
virtual ~FWEventItem()
Definition: FWEventItem.cc:100
bool isInFront() const
returns true if item is in front of all other items
Definition: FWEventItem.cc:476
void setFilterExpression(const std::string &)
Definition: FWEventItem.cc:200
void unselectItem()
Definition: FWEventItem.cc:655
void setTransparency(Char_t transparency)
const edm::EventBase * m_event
Definition: FWEventItem.h:244
std::string m_errorMessage
Definition: FWEventItem.h:251
bool getByLabel(InputTag const &, Handle< T > &) const
Definition: EventBase.h:92
bool isCollection() const
Definition: FWEventItem.cc:569
const TClass * modelType() const
Definition: FWEventItem.cc:575
const std::string & errorMessage() const
returns error string if there was a problem this event
Definition: FWEventItem.cc:686
std::vector< ModelInfo > m_itemInfos
Definition: FWEventItem.h:238
const std::string & getToolTip(const void *iObject) const
void toggleSelectItem()
Definition: FWEventItem.cc:664
void select(int iIndex) const
Definition: FWEventItem.cc:261
bool m_isSelected
Definition: FWEventItem.h:253
volatile std::atomic< bool > shutdown_flag false
const void * modelData(int iIndex) const
Definition: FWEventItem.cc:581
ModelInfo modelInfo(int iIndex) const
Definition: FWEventItem.cc:548
void setIsVisible(bool iSet)
const std::string & purpose() const
Definition: FWEventItem.cc:525
void setName(const std::string &iName)
Definition: FWEventItem.cc:144
std::vector< FWEventItem * >::const_iterator const_iterator
void runFilter()
Definition: FWEventItem.cc:215
std::string m_purpose
Definition: FWEventItem.h:234
std::string m_productInstanceLabel
Definition: FWEventItem.h:242
std::string m_name
Definition: FWEventItem.h:232
const FWGeometry * getGeom() const
Definition: FWEventItem.cc:695
const std::string & moduleLabel() const
Definition: FWEventItem.cc:531
void selectItem(FWEventItem *)
const_iterator end() const
FWItemChangeSignal filterChanged_
Definition: FWEventItem.h:215