CMS 3D CMS Logo

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