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 // $Id: FWEventItem.cc,v 1.60 2012/08/03 18:20:28 wmtan Exp $
12 //
13 
14 // system include files
15 #include <iostream>
16 #include <algorithm>
17 #include <exception>
18 #include <TClass.h>
19 
20 // user include files
23 // Needed to test edm::Event access
24 // #include "FWCore/Framework/interface/Event.h"
34 
35 //
36 // static data member definitions
37 //
38 
40 {
41  return -100;
42 }
43 
45 {
46  return 100;
47 }
48 
49 
50 //
51 // constructors and destructor
52 //
54  unsigned int iId,
55  boost::shared_ptr<FWItemAccessorBase> iAccessor,
56  const FWPhysicsObjectDesc& iDesc, const FWConfiguration* pbc) :
57  m_context(iContext),
58  m_id(iId),
59  m_name(iDesc.name()),
60  m_type(iDesc.type()),
61  m_purpose(iDesc.purpose()),
62  m_accessor(iAccessor),
63  m_displayProperties(iDesc.displayProperties()),
64  m_layer(iDesc.layer()),
65  m_moduleLabel(iDesc.moduleLabel()),
66  m_productInstanceLabel(iDesc.productInstanceLabel()),
67  m_processName(iDesc.processName()),
68  m_event(0),
69  m_interestingValueGetter(edm::TypeWithDict(*(m_accessor->modelType()->GetTypeInfo())), m_purpose),
70  m_filter(iDesc.filterExpression(),""),
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 {
210  if(m_accessor->isCollection() && m_accessor->data()) {
211  //std::cout <<"runFilter"<<std::endl;
212  FWChangeSentry sentry(*(this->changeManager()));
213  int size = m_accessor->size();
214  std::vector<ModelInfo>::iterator itInfo = m_itemInfos.begin();
215  try {
216  for(int index = 0; index != size; ++index,++itInfo) {
217  bool changed = false;
218  bool wasVisible = itInfo->m_displayProperties.isVisible();
219  if(not m_filter.passesFilter(m_accessor->modelData(index))) {
220  itInfo->m_displayProperties.setIsVisible(false);
221  changed = wasVisible==true;
222  } else {
223  itInfo->m_displayProperties.setIsVisible(true);
224  changed = wasVisible==false;
225  }
226  if(changed) {
227  FWModelId id(this,index);
228  changeManager()->changed(id);
229  }
230  }
231  } catch( const std::exception& iException) {
232  //Should log this error
233  std::cerr <<"Exception occurred while running filter on "<<name()<<"\n"
234  <<iException.what()<<std::endl;
235  }
236  }
237 }
238 
239 void
240 FWEventItem::unselect(int iIndex) const
241 {
242  //check if this is a change
243  if(bool& sel = m_itemInfos.at(iIndex).m_isSelected) {
244  sel=false;
245  FWModelId id(this,iIndex);
246  selectionManager()->unselect(id);
247  changeManager()->changed(id);
248  }
249 }
250 void
251 FWEventItem::select(int iIndex) const
252 {
253  bool& sel = m_itemInfos.at(iIndex).m_isSelected;
254  if(not sel) {
255  sel = true;
256  FWModelId id(this,iIndex);
257  selectionManager()->select(id);
258  //want to make it obvious what type of object was selected
259  // therefore we also select the item
260  const_cast<FWEventItem*>(this)->selectItem();
261  changeManager()->changed(id);
262  }
263 }
264 void
265 FWEventItem::toggleSelect(int iIndex) const
266 {
267  bool& sel = m_itemInfos.at(iIndex).m_isSelected;
268  sel = not sel;
269  FWModelId id(this,iIndex);
270  if (sel)
271  selectionManager()->select(id);
272  else selectionManager()->unselect(id);
273  changeManager()->changed(id);
274 }
275 
276 void
278 {
279  FWDisplayProperties& prop = m_itemInfos.at(iIndex).m_displayProperties;
281  if( prop
282  != iProps ) {
283  prop = iProps;
284  FWModelId id(this,iIndex);
285  //selectionManager()->select(id);
286  changeManager()->changed(id);
287  }
288  } else {
289  if(iProps.isVisible()) {
290  FWChangeSentry sentry(*(this->changeManager()));
291  int size = m_accessor->size();
292  std::vector<ModelInfo>::iterator itInfo = m_itemInfos.begin();
293  for(int index = 0; index != size; ++index,++itInfo) {
294  if( itInfo->m_displayProperties.isVisible() ) {
295  itInfo->m_displayProperties.setIsVisible(false);
296  FWModelId id(this,index);
297  changeManager()->changed(id);
298  }
299  }
300  m_itemInfos.at(iIndex).m_displayProperties.setIsVisible(true);
301  FWModelId id(this,iIndex);
302  changeManager()->changed(id);
303  const_cast<FWEventItem*>(this)->m_displayProperties.setIsVisible(true);
304  //NOTE: need to send out a signal here
306  }
307  }
308 }
309 
310 void
312 {
313  assert(0!=m_context->eventItemsManager());
314  int largest = layer();
316  itEnd = m_context->eventItemsManager()->end();
317  it != itEnd;
318  ++it) {
319  if ((*it) && (*it != this) && (*it)->layer() > largest) {
320  largest= (*it)->layer();
321  }
322  }
323 
324  if(largest >= layer()) {
325  m_layer = std::min(largest+1, maxLayerValue());
326  }
327 
328  m_itemInfos.clear();
329  m_accessor->reset();
330  handleChange();
331 }
332 
333 void
335 {
336  assert(0!=m_context->eventItemsManager());
337  int smallest = layer();
339  itEnd = m_context->eventItemsManager()->end();
340  it != itEnd;
341  ++it) {
342  if((*it) && (*it != this) && (*it)->layer() < smallest) {
343  smallest= (*it)->layer();
344  }
345  }
346 
347  if(smallest <= layer()) {
348  m_layer = std::max(smallest-1, minLayerValue());
349  }
350 
351  m_itemInfos.clear();
352  m_accessor->reset();
353  handleChange();
354 }
355 
356 void
358 {
359  assert(0!=m_context->eventItemsManager());
360 
362 
363  m_itemInfos.clear();
364  m_accessor->reset();
365  handleChange();
366 }
367 
368 void
370 {
371  m_itemInfos.clear();
372  m_accessor->reset();
374  handleChange();
375 
376 }
377 
378 void
380 {
381  preItemChanged_(this);
382  FWChangeSentry sentry(*(this->changeManager()));
383  //want filter to rerun after all changes have been made
384  changeManager()->changed(this);
385  getPrimaryData();
386  runFilter();
387 }
388 
389 //
390 // const member functions
391 //
392 const void*
393 FWEventItem::data(const std::type_info& iInfo) const
394 {
395  //At the moment this is a programming error
396  assert(iInfo == *(m_type->GetTypeInfo()));
397 
398  //lookup data if we don't already have it
399  if (m_accessor->data())
400  return m_accessor->data();
401 
402  m_errorMessage.clear();
403  if (!m_event)
404  return m_accessor->data();
405 
406  // Retrieve the data from the event.
408  edm::TypeWithDict type(iInfo);
410  try
411  {
412  m_event->getByLabel(tag, handle);
413  setData(*handle);
414  }
415  catch (std::exception& iException)
416  {
418  {
419  std::ostringstream s;
420  s << "Failed to get " << name() << " because \n" <<iException.what();
421  m_errorMessage=s.str();
423  }
424  return 0;
425  }
426 
427  return m_accessor->data();
428 }
429 
430 void
432 {
433  m_accessor->setData(iData);
434  //std::cout <<"size "<<m_accessor->size()<<std::endl;
435  if(m_accessor->isCollection()) {
436  m_itemInfos.reserve(m_accessor->size());
437  m_itemInfos.resize(m_accessor->size(),ModelInfo(m_displayProperties,false));
438  } else {
439  m_itemInfos.push_back(ModelInfo(m_displayProperties,false));
440  }
441 }
442 
443 void
445 {
446  //if(0!=m_data) return;
447  if(0!=m_accessor->data()) return;
448  this->data(*(m_type->GetTypeInfo()));
449 }
450 
451 const FWDisplayProperties&
453 {
454  return m_displayProperties;
455 }
456 
457 int
459 {
460  return m_layer;
461 }
462 
463 bool
465 {
466  assert(0!=m_context->eventItemsManager());
468  itEnd = m_context->eventItemsManager()->end();
469  it != itEnd;
470  ++it) {
471  if((*it) && (*it != this) && (*it)->layer() >= layer()) {
472  return false;
473  }
474  }
475  return true;
476 }
477 
478 bool
480 {
481  assert(0!=m_context->eventItemsManager());
483  itEnd = m_context->eventItemsManager()->end();
484  it != itEnd;
485  ++it) {
486  if((*it) && (*it != this) && (*it)->layer() <= layer()) {
487  return false;
488  }
489  }
490  return true;
491 }
492 
493 
494 unsigned int
496 {
497  return m_id;
498 }
499 
500 const std::string&
502 {
503  return m_name;
504 }
505 
506 const TClass*
508 {
509  return m_type;
510 }
511 
512 const std::string&
514 {
515  return m_purpose;
516 }
517 
518 const std::string&
520 {
521  return m_moduleLabel;
522 }
523 const std::string&
525 {
526  return m_productInstanceLabel;
527 }
528 
529 const std::string&
531 {
532  return m_processName;
533 }
534 
536 FWEventItem::modelInfo(int iIndex) const
537 {
538  getPrimaryData();
540  return m_itemInfos.at(iIndex);
541  }
542  FWDisplayProperties dp(m_itemInfos.at(iIndex).displayProperties());
543  dp.setIsVisible(false);
544  ModelInfo t(dp,m_itemInfos.at(iIndex).isSelected());
545  return t;
546 }
547 
548 size_t
550 {
551  getPrimaryData();
552  return m_itemInfos.size();
553 }
554 
555 bool
557 {
558  return m_accessor->isCollection();
559 }
560 
561 const TClass*
563 {
564  return m_accessor->modelType();
565 }
566 
567 const void*
568 FWEventItem::modelData(int iIndex) const
569 {
570  getPrimaryData();
571  return m_accessor->modelData(iIndex);
572 }
573 
575 FWEventItem::modelName(int iIndex) const
576 {
577  std::ostringstream s;
578  size_t lastChar = name().size();
579  //if name ends in 's' assume it is plural and remove the s for the individual object
580  if(name()[lastChar-1]=='s') {
581  --lastChar;
582  }
583  s<<name().substr(0,lastChar)<<" "<<iIndex;
584  return s.str();
585 }
586 
587 bool
589 {
590  return true; //m_interestingValueGetter.isValid();
591 }
592 
593 
594 const std::string&
596 {
597  getPrimaryData();
598  return m_interestingValueGetter.getToolTip(m_accessor->modelData(iIndex));
599 }
600 
601 
602 const std::string&
604 {
605  return m_filter.expression();
606 }
607 
608 void
610 {
611  //NOTE: need to unselect first before announcing destruction
612  // because some items are listening to the display change and may
613  // not properly release their connection to that signal after they
614  // are destroyed via a connection to goingToBeDestroyed_
615  const_cast<FWEventItem*>(this)->unselectItem();
616  {
617  FWChangeSentry sentry(*(changeManager()));
618 
619  for(int index=0; index <static_cast<int>(size()); ++index) {
620  if(m_itemInfos.at(index).m_isSelected) {
621  FWModelId id(this,index);
622  selectionManager()->unselect(id);
623  changeManager()->changed(id);
624  }
625  }
626  }
627  goingToBeDestroyed_(this);
628  delete this;
629 }
630 
631 
632 void
634 {
635  if(!m_isSelected) {
636  m_isSelected=true;
637  selectionManager()->selectItem(this);
639  }
640 }
641 void
643 {
644  if(m_isSelected) {
645  m_isSelected=false;
648  }
649 }
650 void
652 {
654  if(m_isSelected) {
655  selectionManager()->selectItem(this);
656  }else {
658  }
660 }
661 bool
663 {
664  return m_isSelected;
665 }
666 
667 bool
669  return !errorMessage().empty();
670 }
671 
672 const std::string&
674 {
675  if(m_errorMessage.empty()) {
676  getPrimaryData();
677  }
678  return m_errorMessage;
679 }
680 
681 const FWGeometry*
683  return m_context->getGeom();
684 }
685 //
686 // static member functions
687 //
const TClass * m_type
Definition: FWEventItem.h:229
type
Definition: HCALResponse.h:21
bool passesFilter(const void *) const
FWItemChangeSignal preItemChanged_
Definition: FWEventItem.h:204
const FWDisplayProperties & defaultDisplayProperties() const
Definition: FWEventItem.cc:452
void setColor(Color_t iColor)
FWModelChangeManager * changeManager() const
Definition: FWEventItem.h:131
void destroy() const
Definition: FWEventItem.cc:609
void moveToBack()
Definition: FWEventItem.cc:334
void select(const FWModelId &iId)
void moveToFront()
Definition: FWEventItem.cc:311
const FWEventItemsManager * eventItemsManager() const
Definition: Context.h:62
void moveToLayer(int layer)
Definition: FWEventItem.cc:357
std::string modelName(int iIndex) const
Definition: FWEventItem.cc:575
void setEvent(const edm::EventBase *iEvent)
Definition: FWEventItem.cc:121
const std::string & name() const
Definition: FWEventItem.cc:501
FWItemValueGetter m_interestingValueGetter
Definition: FWEventItem.h:242
const FWGeometry * getGeom() const
Definition: Context.h:84
void proxyConfigChanged()
Definition: FWEventItem.cc:369
void setDisplayProperties(int iIndex, const FWDisplayProperties &) const
Definition: FWEventItem.cc:277
const std::string & filterExpression() const
Definition: FWEventItem.cc:603
FWItemChangeSignal defaultDisplayPropertiesChanged_
Definition: FWEventItem.h:208
bool haveInterestingValue() const
Definition: FWEventItem.cc:588
void getPrimaryData() const
Definition: FWEventItem.cc:444
void unselect(int iIndex) const
Definition: FWEventItem.cc:240
FWItemChangeSignal goingToBeDestroyed_
Definition: FWEventItem.h:215
#define min(a, b)
Definition: mlp_lapack.h:161
boost::shared_ptr< FWItemAccessorBase > m_accessor
Definition: FWEventItem.h:231
const fireworks::Context * m_context
Definition: FWEventItem.h:226
const std::string & expression() const
bool itemIsSelected() const
Definition: FWEventItem.cc:662
const std::string & processName() const
Definition: FWEventItem.cc:530
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:237
static int maxLayerValue()
Definition: FWEventItem.cc:44
const void * data(const std::type_info &) const
Definition: FWEventItem.cc:393
Color_t color() const
int layer() const
Definition: FWEventItem.cc:458
unsigned int m_id
Definition: FWEventItem.h:227
FWModelFilter m_filter
Definition: FWEventItem.h:244
Char_t transparency() const
int iEvent
Definition: GenABIO.cc:243
void setDefaultDisplayProperties(const FWDisplayProperties &)
Definition: FWEventItem.cc:156
const std::string & productInstanceLabel() const
Definition: FWEventItem.cc:524
std::string m_processName
Definition: FWEventItem.h:239
const T & max(const T &a, const T &b)
void setClassName(const std::string &)
const TClass * type() const
Definition: FWEventItem.cc:507
FWProxyBuilderConfiguration * m_proxyBuilderConfig
Definition: FWEventItem.h:251
void unselectItem(FWEventItem *)
tuple handle
Definition: patZpeak.py:22
unsigned int id() const
Definition: FWEventItem.cc:495
void unselect(const FWModelId &iId)
void setData(const edm::ObjectWithDict &) const
Definition: FWEventItem.cc:431
const std::string & modelInterestingValueAsString(int iIndex) const
Definition: FWEventItem.cc:595
static int minLayerValue()
Definition: FWEventItem.cc:39
bool m_printedErrorThisEvent
Definition: FWEventItem.h:245
bool hasError() const
returns true if failed to get data for this event
Definition: FWEventItem.cc:668
FWSelectionManager * selectionManager() const
Definition: FWEventItem.h:134
void toggleSelect(int iIndex) const
Definition: FWEventItem.cc:265
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:479
size_t size() const
Definition: FWEventItem.cc:549
void setExpression(const std::string &)
FWDisplayProperties m_displayProperties
Definition: FWEventItem.h:232
void selectItem()
Definition: FWEventItem.cc:633
void handleChange()
Definition: FWEventItem.cc:379
auto dp
Definition: deltaR.h:24
virtual ~FWEventItem()
Definition: FWEventItem.cc:100
bool isInFront() const
returns true if item is in front of all other items
Definition: FWEventItem.cc:464
void setFilterExpression(const std::string &)
Definition: FWEventItem.cc:200
void unselectItem()
Definition: FWEventItem.cc:642
void setTransparency(Char_t transparency)
FWEventItem(fireworks::Context *iContext, unsigned int iItemId, boost::shared_ptr< FWItemAccessorBase > iAccessor, const FWPhysicsObjectDesc &iDesc, const FWConfiguration *pbConf=0)
Definition: FWEventItem.cc:53
const edm::EventBase * m_event
Definition: FWEventItem.h:240
std::string m_errorMessage
Definition: FWEventItem.h:246
bool getByLabel(InputTag const &, Handle< T > &) const
Definition: EventBase.h:86
bool isCollection() const
Definition: FWEventItem.cc:556
const TClass * modelType() const
Definition: FWEventItem.cc:562
const std::string & errorMessage() const
returns error string if there was a problem this event
Definition: FWEventItem.cc:673
std::vector< ModelInfo > m_itemInfos
Definition: FWEventItem.h:234
const std::string & getToolTip(const void *iObject) const
void toggleSelectItem()
Definition: FWEventItem.cc:651
void select(int iIndex) const
Definition: FWEventItem.cc:251
bool m_isSelected
Definition: FWEventItem.h:248
const void * modelData(int iIndex) const
Definition: FWEventItem.cc:568
ModelInfo modelInfo(int iIndex) const
Definition: FWEventItem.cc:536
void setIsVisible(bool iSet)
const std::string & purpose() const
Definition: FWEventItem.cc:513
void setName(const std::string &iName)
Definition: FWEventItem.cc:144
std::vector< FWEventItem * >::const_iterator const_iterator
void runFilter()
Definition: FWEventItem.cc:208
std::string m_purpose
Definition: FWEventItem.h:230
std::string m_productInstanceLabel
Definition: FWEventItem.h:238
std::string m_name
Definition: FWEventItem.h:228
const FWGeometry * getGeom() const
Definition: FWEventItem.cc:682
const std::string & moduleLabel() const
Definition: FWEventItem.cc:519
void selectItem(FWEventItem *)
const_iterator end() const
FWItemChangeSignal filterChanged_
Definition: FWEventItem.h:211