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.59 2012/06/26 22:09:35 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(Reflex::Type::ByTypeInfo(*(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  //Reflex::Type dataType( Reflex::Type::ByTypeInfo(*(m_type->GetTypeInfo())));
77  //assert(dataType != Reflex::Type() );
78  //
79  //std::string dataTypeName = dataType.Name(Reflex::SCOPED);
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 = Reflex::Type::ByName(wrapperName);
87  //
88  //assert(m_wrapperType != Reflex::Type());
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
131 FWEventItem::setLabels(const std::string& iModule,
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
144 FWEventItem::setName(const std::string& iName)
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
200 FWEventItem::setFilterExpression(const std::string& iExpression)
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::FWGenericHandle handle(Reflex::Type::ByTypeInfo(iInfo));
409  try
410  {
411  m_event->getByLabel(tag, handle);
412  setData(*handle);
413  }
414  catch (std::exception& iException)
415  {
417  {
418  std::ostringstream s;
419  s << "Failed to get " << name() << " because \n" <<iException.what();
420  m_errorMessage=s.str();
422  }
423  return 0;
424  }
425 
426  return m_accessor->data();
427 }
428 
429 void
430 FWEventItem::setData(const Reflex::Object& iData) const
431 {
432  m_accessor->setData(iData);
433  //std::cout <<"size "<<m_accessor->size()<<std::endl;
434  if(m_accessor->isCollection()) {
435  m_itemInfos.reserve(m_accessor->size());
436  m_itemInfos.resize(m_accessor->size(),ModelInfo(m_displayProperties,false));
437  } else {
438  m_itemInfos.push_back(ModelInfo(m_displayProperties,false));
439  }
440 }
441 
442 void
444 {
445  //if(0!=m_data) return;
446  if(0!=m_accessor->data()) return;
447  this->data(*(m_type->GetTypeInfo()));
448 }
449 
450 const FWDisplayProperties&
452 {
453  return m_displayProperties;
454 }
455 
456 int
458 {
459  return m_layer;
460 }
461 
462 bool
464 {
465  assert(0!=m_context->eventItemsManager());
467  itEnd = m_context->eventItemsManager()->end();
468  it != itEnd;
469  ++it) {
470  if((*it) && (*it != this) && (*it)->layer() >= layer()) {
471  return false;
472  }
473  }
474  return true;
475 }
476 
477 bool
479 {
480  assert(0!=m_context->eventItemsManager());
482  itEnd = m_context->eventItemsManager()->end();
483  it != itEnd;
484  ++it) {
485  if((*it) && (*it != this) && (*it)->layer() <= layer()) {
486  return false;
487  }
488  }
489  return true;
490 }
491 
492 
493 unsigned int
495 {
496  return m_id;
497 }
498 
499 const std::string&
501 {
502  return m_name;
503 }
504 
505 const TClass*
507 {
508  return m_type;
509 }
510 
511 const std::string&
513 {
514  return m_purpose;
515 }
516 
517 const std::string&
519 {
520  return m_moduleLabel;
521 }
522 const std::string&
524 {
525  return m_productInstanceLabel;
526 }
527 
528 const std::string&
530 {
531  return m_processName;
532 }
533 
535 FWEventItem::modelInfo(int iIndex) const
536 {
537  getPrimaryData();
539  return m_itemInfos.at(iIndex);
540  }
541  FWDisplayProperties dp(m_itemInfos.at(iIndex).displayProperties());
542  dp.setIsVisible(false);
543  ModelInfo t(dp,m_itemInfos.at(iIndex).isSelected());
544  return t;
545 }
546 
547 size_t
549 {
550  getPrimaryData();
551  return m_itemInfos.size();
552 }
553 
554 bool
556 {
557  return m_accessor->isCollection();
558 }
559 
560 const TClass*
562 {
563  return m_accessor->modelType();
564 }
565 
566 const void*
567 FWEventItem::modelData(int iIndex) const
568 {
569  getPrimaryData();
570  return m_accessor->modelData(iIndex);
571 }
572 
573 std::string
574 FWEventItem::modelName(int iIndex) const
575 {
576  std::ostringstream s;
577  size_t lastChar = name().size();
578  //if name ends in 's' assume it is plural and remove the s for the individual object
579  if(name()[lastChar-1]=='s') {
580  --lastChar;
581  }
582  s<<name().substr(0,lastChar)<<" "<<iIndex;
583  return s.str();
584 }
585 
586 bool
588 {
589  return true; //m_interestingValueGetter.isValid();
590 }
591 
592 
593 const std::string&
595 {
596  getPrimaryData();
597  return m_interestingValueGetter.getToolTip(m_accessor->modelData(iIndex));
598 }
599 
600 
601 const std::string&
603 {
604  return m_filter.expression();
605 }
606 
607 void
609 {
610  //NOTE: need to unselect first before announcing destruction
611  // because some items are listening to the display change and may
612  // not properly release their connection to that signal after they
613  // are destroyed via a connection to goingToBeDestroyed_
614  const_cast<FWEventItem*>(this)->unselectItem();
615  {
616  FWChangeSentry sentry(*(changeManager()));
617 
618  for(int index=0; index <static_cast<int>(size()); ++index) {
619  if(m_itemInfos.at(index).m_isSelected) {
620  FWModelId id(this,index);
621  selectionManager()->unselect(id);
622  changeManager()->changed(id);
623  }
624  }
625  }
626  goingToBeDestroyed_(this);
627  delete this;
628 }
629 
630 
631 void
633 {
634  if(!m_isSelected) {
635  m_isSelected=true;
636  selectionManager()->selectItem(this);
638  }
639 }
640 void
642 {
643  if(m_isSelected) {
644  m_isSelected=false;
647  }
648 }
649 void
651 {
653  if(m_isSelected) {
654  selectionManager()->selectItem(this);
655  }else {
657  }
659 }
660 bool
662 {
663  return m_isSelected;
664 }
665 
666 bool
668  return !errorMessage().empty();
669 }
670 
671 const std::string&
673 {
674  if(m_errorMessage.empty()) {
675  getPrimaryData();
676  }
677  return m_errorMessage;
678 }
679 
680 const FWGeometry*
682  return m_context->getGeom();
683 }
684 //
685 // static member functions
686 //
const TClass * m_type
Definition: FWEventItem.h:229
type
Definition: HCALResponse.h:22
bool passesFilter(const void *) const
FWItemChangeSignal preItemChanged_
Definition: FWEventItem.h:204
const FWDisplayProperties & defaultDisplayProperties() const
Definition: FWEventItem.cc:451
void setColor(Color_t iColor)
FWModelChangeManager * changeManager() const
Definition: FWEventItem.h:131
void destroy() const
Definition: FWEventItem.cc:608
void moveToBack()
Definition: FWEventItem.cc:334
void select(const FWModelId &iId)
void moveToFront()
Definition: FWEventItem.cc:311
void setData(const Reflex::Object &) const
Definition: FWEventItem.cc:430
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:574
void setEvent(const edm::EventBase *iEvent)
Definition: FWEventItem.cc:121
const std::string & name() const
Definition: FWEventItem.cc:500
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:602
FWItemChangeSignal defaultDisplayPropertiesChanged_
Definition: FWEventItem.h:208
bool haveInterestingValue() const
Definition: FWEventItem.cc:587
void getPrimaryData() const
Definition: FWEventItem.cc:443
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:661
const std::string & processName() const
Definition: FWEventItem.cc:529
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:457
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:523
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:506
FWProxyBuilderConfiguration * m_proxyBuilderConfig
Definition: FWEventItem.h:251
void unselectItem(FWEventItem *)
tuple handle
Definition: patZpeak.py:22
unsigned int id() const
Definition: FWEventItem.cc:494
void unselect(const FWModelId &iId)
const std::string & modelInterestingValueAsString(int iIndex) const
Definition: FWEventItem.cc:594
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:667
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:478
size_t size() const
Definition: FWEventItem.cc:548
void setExpression(const std::string &)
FWDisplayProperties m_displayProperties
Definition: FWEventItem.h:232
void selectItem()
Definition: FWEventItem.cc:632
void handleChange()
Definition: FWEventItem.cc:379
virtual ~FWEventItem()
Definition: FWEventItem.cc:100
bool isInFront() const
returns true if item is in front of all other items
Definition: FWEventItem.cc:463
void setFilterExpression(const std::string &)
Definition: FWEventItem.cc:200
void unselectItem()
Definition: FWEventItem.cc:641
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:555
const TClass * modelType() const
Definition: FWEventItem.cc:561
const std::string & errorMessage() const
returns error string if there was a problem this event
Definition: FWEventItem.cc:672
std::vector< ModelInfo > m_itemInfos
Definition: FWEventItem.h:234
const std::string & getToolTip(const void *iObject) const
void toggleSelectItem()
Definition: FWEventItem.cc:650
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:567
ModelInfo modelInfo(int iIndex) const
Definition: FWEventItem.cc:535
void setIsVisible(bool iSet)
const std::string & purpose() const
Definition: FWEventItem.cc:512
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:681
const std::string & moduleLabel() const
Definition: FWEventItem.cc:518
void selectItem(FWEventItem *)
const_iterator end() const
FWItemChangeSignal filterChanged_
Definition: FWEventItem.h:211