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, 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_printedErrorThisEvent(false),
71  m_isSelected(false),
72  m_proxyBuilderConfig(0)
73 {
74  //assert(m_type->GetTypeInfo());
75  //edm::TypeWithDict dataType(*(m_type->GetTypeInfo()));
76  //assert(dataType != edm::TypeWithDict() );
77  //
78  //std::string dataTypeName = dataType.name();
79  //if (dataTypeName[dataTypeName.size() -1] == '>')
80  // dataTypeName += " ";
81  //std::string wrapperName = "edm::Wrapper<" + dataTypeName + ">";
82  //
83  //fwLog(fwlog::kDebug) << "Looking for the wrapper name"
84  // << wrapperName << std::endl;
85  //m_wrapperType = edm::TypeWithDict::byName(wrapperName);
86  //
87  //assert(m_wrapperType != edm::TypeWithDict());
88  if(!m_accessor->isCollection()) {
89  m_itemInfos.reserve(1);
90  }
91  m_filter.setClassName(modelType()->GetName());
93 }
94 // FWEventItem::FWEventItem(const FWEventItem& rhs)
95 // {
96 // // do actual copying here;
97 // }
98 
100 {
101  delete m_proxyBuilderConfig;
102 }
103 
104 //
105 // assignment operators
106 //
107 // const FWEventItem& FWEventItem::operator=(const FWEventItem& rhs)
108 // {
109 // //An exception safe implementation is
110 // FWEventItem temp(rhs);
111 // swap(rhs);
112 //
113 // return *this;
114 // }
115 
116 //
117 // member functions
118 //
119 void
121 {
122  m_printedErrorThisEvent = false;
123  m_event = iEvent;
124  m_accessor->reset();
125  m_itemInfos.clear();
126  handleChange();
127 }
128 
129 void
131  const std::string& iProductInstance,
132  const std::string& iProcess)
133 {
134  m_moduleLabel = iModule;
135  m_productInstanceLabel = iProductInstance;
136  m_processName = iProcess;
137  m_accessor->reset();
138  m_itemInfos.clear();
139  handleChange();
140 }
141 
142 void
144 {
145  m_name = iName;
146 }
147 
154 void
156 {
157  bool visChange = m_displayProperties.isVisible() != iProp.isVisible();
158  bool colorChanged = m_displayProperties.color() != iProp.color();
159  bool transparencyChanged = m_displayProperties.transparency() != iProp.transparency();
160 
161  if(!visChange && !colorChanged && !transparencyChanged) {
162  return;
163  }
164  //If the default visibility is changed, we want to also change the the visibility of the children
165  // BUT we want to remember the old visibility so if the visibility is changed again we return
166  // to the previous state.
167  // only the visible ones need to be marked as 'changed'
168  FWChangeSentry sentry(*(changeManager()));
169 
170  for(int index=0; index <static_cast<int>(size()); ++index) {
171  FWDisplayProperties prp = m_itemInfos[index].displayProperties();
172  bool vis=prp.isVisible();
173  bool changed = false;
174  changed = visChange && vis;
175 
176  if(colorChanged) {
177  if(m_displayProperties.color()==prp.color()) {
178  prp.setColor(iProp.color());
179  changed = true;
180  }
181  }
182  if (transparencyChanged) {
184  prp.setTransparency(iProp.transparency());
185  changed = true;
186  }
187  }
188  if(changed) {
189  m_itemInfos[index].m_displayProperties=prp;
190  FWModelId id(this,index);
191  changeManager()->changed(id);
192  }
193  }
194  m_displayProperties= iProp;
196 }
197 
198 void
200 {
201  m_filter.setExpression(iExpression);
202  filterChanged_(this);
203  runFilter();
204 }
205 
206 void
208 {
209  if(m_accessor->isCollection() && m_accessor->data()) {
210  //std::cout <<"runFilter"<<std::endl;
211  FWChangeSentry sentry(*(this->changeManager()));
212  int size = m_accessor->size();
213  std::vector<ModelInfo>::iterator itInfo = m_itemInfos.begin();
214  try {
215  for(int index = 0; index != size; ++index,++itInfo) {
216  bool changed = false;
217  bool wasVisible = itInfo->m_displayProperties.isVisible();
218  if(not m_filter.passesFilter(m_accessor->modelData(index))) {
219  itInfo->m_displayProperties.setIsVisible(false);
220  changed = wasVisible==true;
221  } else {
222  itInfo->m_displayProperties.setIsVisible(true);
223  changed = wasVisible==false;
224  }
225  if(changed) {
226  FWModelId id(this,index);
227  changeManager()->changed(id);
228  }
229  }
230  } catch( const std::exception& iException) {
231  //Should log this error
232  std::cerr <<"Exception occurred while running filter on "<<name()<<"\n"
233  <<iException.what()<<std::endl;
234  }
235  }
236 }
237 
238 void
239 FWEventItem::unselect(int iIndex) const
240 {
241  //check if this is a change
242  if(bool& sel = m_itemInfos.at(iIndex).m_isSelected) {
243  sel=false;
244  FWModelId id(this,iIndex);
245  selectionManager()->unselect(id);
246  changeManager()->changed(id);
247  }
248 }
249 void
250 FWEventItem::select(int iIndex) const
251 {
252  bool& sel = m_itemInfos.at(iIndex).m_isSelected;
253  if(not sel) {
254  sel = true;
255  FWModelId id(this,iIndex);
256  selectionManager()->select(id);
257  //want to make it obvious what type of object was selected
258  // therefore we also select the item
259  const_cast<FWEventItem*>(this)->selectItem();
260  changeManager()->changed(id);
261  }
262 }
263 void
264 FWEventItem::toggleSelect(int iIndex) const
265 {
266  bool& sel = m_itemInfos.at(iIndex).m_isSelected;
267  sel = not sel;
268  FWModelId id(this,iIndex);
269  if (sel)
270  selectionManager()->select(id);
271  else selectionManager()->unselect(id);
272  changeManager()->changed(id);
273 }
274 
275 void
277 {
278  FWDisplayProperties& prop = m_itemInfos.at(iIndex).m_displayProperties;
280  if( prop
281  != iProps ) {
282  prop = iProps;
283  FWModelId id(this,iIndex);
284  //selectionManager()->select(id);
285  changeManager()->changed(id);
286  }
287  } else {
288  if(iProps.isVisible()) {
289  FWChangeSentry sentry(*(this->changeManager()));
290  int size = m_accessor->size();
291  std::vector<ModelInfo>::iterator itInfo = m_itemInfos.begin();
292  for(int index = 0; index != size; ++index,++itInfo) {
293  if( itInfo->m_displayProperties.isVisible() ) {
294  itInfo->m_displayProperties.setIsVisible(false);
295  FWModelId id(this,index);
296  changeManager()->changed(id);
297  }
298  }
299  m_itemInfos.at(iIndex).m_displayProperties.setIsVisible(true);
300  FWModelId id(this,iIndex);
301  changeManager()->changed(id);
302  const_cast<FWEventItem*>(this)->m_displayProperties.setIsVisible(true);
303  //NOTE: need to send out a signal here
305  }
306  }
307 }
308 
309 void
311 {
313  int largest = layer();
315  itEnd = m_context->eventItemsManager()->end();
316  it != itEnd;
317  ++it) {
318  if ((*it) && (*it != this) && (*it)->layer() > largest) {
319  largest= (*it)->layer();
320  }
321  }
322 
323  if(largest >= layer()) {
324  m_layer = std::min(largest+1, maxLayerValue());
325  }
326 
327  m_itemInfos.clear();
328  m_accessor->reset();
329  handleChange();
330 }
331 
332 void
334 {
336  int smallest = layer();
338  itEnd = m_context->eventItemsManager()->end();
339  it != itEnd;
340  ++it) {
341  if((*it) && (*it != this) && (*it)->layer() < smallest) {
342  smallest= (*it)->layer();
343  }
344  }
345 
346  if(smallest <= layer()) {
347  m_layer = std::max(smallest-1, minLayerValue());
348  }
349 
350  m_itemInfos.clear();
351  m_accessor->reset();
352  handleChange();
353 }
354 
355 void
357 {
359 
361 
362  m_itemInfos.clear();
363  m_accessor->reset();
364  handleChange();
365 }
366 
367 void
369 {
370  m_itemInfos.clear();
371  m_accessor->reset();
373  handleChange();
374 
375 }
376 
377 void
379 {
380  preItemChanged_(this);
381  FWChangeSentry sentry(*(this->changeManager()));
382  //want filter to rerun after all changes have been made
383  changeManager()->changed(this);
384  getPrimaryData();
385  runFilter();
386 }
387 
388 //
389 // const member functions
390 //
391 const void*
392 FWEventItem::data(const std::type_info& iInfo) const
393 {
394  //At the moment this is a programming error
395  assert(iInfo == *(m_type->GetTypeInfo()));
396 
397  //lookup data if we don't already have it
398  if (m_accessor->data())
399  return m_accessor->data();
400 
401  m_errorMessage.clear();
402  if (!m_event)
403  return m_accessor->data();
404 
405  // Retrieve the data from the event.
407  edm::TypeWithDict type(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
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 {
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 {
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 
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:21
bool passesFilter(const void *) const
FWItemChangeSignal preItemChanged_
Definition: FWEventItem.h:206
const FWDisplayProperties & defaultDisplayProperties() const
Definition: FWEventItem.cc:451
void setColor(Color_t iColor)
FWModelChangeManager * changeManager() const
Definition: FWEventItem.h:130
void destroy() const
Definition: FWEventItem.cc:608
void moveToBack()
Definition: FWEventItem.cc:333
void select(const FWModelId &iId)
void moveToFront()
Definition: FWEventItem.cc:310
const FWEventItemsManager * eventItemsManager() const
Definition: Context.h:61
void moveToLayer(int layer)
Definition: FWEventItem.cc:356
std::string modelName(int iIndex) const
Definition: FWEventItem.cc:574
void setEvent(const edm::EventBase *iEvent)
Definition: FWEventItem.cc:120
const std::string & name() const
Definition: FWEventItem.cc:500
FWItemValueGetter m_interestingValueGetter
Definition: FWEventItem.h:242
const FWGeometry * getGeom() const
Definition: Context.h:83
void proxyConfigChanged()
Definition: FWEventItem.cc:368
assert(m_qm.get())
void setDisplayProperties(int iIndex, const FWDisplayProperties &) const
Definition: FWEventItem.cc:276
const std::string & filterExpression() const
Definition: FWEventItem.cc:602
FWItemChangeSignal defaultDisplayPropertiesChanged_
Definition: FWEventItem.h:210
bool haveInterestingValue() const
Definition: FWEventItem.cc:587
void getPrimaryData() const
Definition: FWEventItem.cc:443
void unselect(int iIndex) const
Definition: FWEventItem.cc:239
FWItemChangeSignal goingToBeDestroyed_
Definition: FWEventItem.h:217
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:130
std::string m_moduleLabel
Definition: FWEventItem.h:237
static int maxLayerValue()
Definition: FWEventItem.cc:43
const void * data(const std::type_info &) const
Definition: FWEventItem.cc:392
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:230
void setDefaultDisplayProperties(const FWDisplayProperties &)
Definition: FWEventItem.cc:155
const std::string & productInstanceLabel() const
Definition: FWEventItem.cc:523
std::string m_processName
Definition: FWEventItem.h:239
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)
T min(T a, T b)
Definition: MathUtil.h:58
void setData(const edm::ObjectWithDict &) const
Definition: FWEventItem.cc:430
const std::string & modelInterestingValueAsString(int iIndex) const
Definition: FWEventItem.cc:594
static int minLayerValue()
Definition: FWEventItem.cc:38
bool m_printedErrorThisEvent
Definition: FWEventItem.h:245
m_id("(unknown)")
bool hasError() const
returns true if failed to get data for this event
Definition: FWEventItem.cc:667
FWSelectionManager * selectionManager() const
Definition: FWEventItem.h:133
void toggleSelect(int iIndex) const
Definition: FWEventItem.cc:264
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:378
virtual ~FWEventItem()
Definition: FWEventItem.cc:99
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:199
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:52
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:92
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:250
bool m_isSelected
Definition: FWEventItem.h:248
volatile std::atomic< bool > shutdown_flag false
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:143
std::vector< FWEventItem * >::const_iterator const_iterator
void runFilter()
Definition: FWEventItem.cc:207
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:213