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()),
67  m_event(0),
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(0!=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(0!=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(0!=m_context->eventItemsManager());
361 
363 
364  m_itemInfos.clear();
365  m_accessor->reset();
366  handleChange();
367 }
368 
369 void
371 {
372  m_itemInfos.clear();
373  m_accessor->reset();
375  handleChange();
376 
377 }
378 
379 void
381 {
382  preItemChanged_(this);
383  FWChangeSentry sentry(*(this->changeManager()));
384  //want filter to rerun after all changes have been made
385  changeManager()->changed(this);
386  getPrimaryData();
387  runFilter();
388 }
389 
390 //
391 // const member functions
392 //
393 const void*
394 FWEventItem::data(const std::type_info& iInfo) const
395 {
396  //At the moment this is a programming error
397  assert(iInfo == *(m_type->GetTypeInfo()));
398 
399  //lookup data if we don't already have it
400  if (m_accessor->data())
401  return m_accessor->data();
402 
403  m_errorMessage.clear();
404  if (!m_event)
405  return m_accessor->data();
406 
407  // Retrieve the data from the event.
409  edm::TypeWithDict type(iInfo);
411  try
412  {
413  m_event->getByLabel(tag, handle);
414  setData(*handle);
415  }
416  catch (std::exception& iException)
417  {
419  {
420  std::ostringstream s;
421  s << "Failed to get " << name() << " because \n" <<iException.what();
422  m_errorMessage=s.str();
424  }
425  return 0;
426  }
427 
428  return m_accessor->data();
429 }
430 
431 void
433 {
434  m_accessor->setData(iData);
435  //std::cout <<"size "<<m_accessor->size()<<std::endl;
436  if(m_accessor->isCollection()) {
437  m_itemInfos.reserve(m_accessor->size());
438  m_itemInfos.resize(m_accessor->size(),ModelInfo(m_displayProperties,false));
439  } else {
440  m_itemInfos.push_back(ModelInfo(m_displayProperties,false));
441  }
442 }
443 
444 void
446 {
447  //if(0!=m_data) return;
448  if(0!=m_accessor->data()) return;
449  this->data(*(m_type->GetTypeInfo()));
450 }
451 
452 const FWDisplayProperties&
454 {
455  return m_displayProperties;
456 }
457 
458 int
460 {
461  return m_layer;
462 }
463 
464 bool
466 {
467  assert(0!=m_context->eventItemsManager());
469  itEnd = m_context->eventItemsManager()->end();
470  it != itEnd;
471  ++it) {
472  if((*it) && (*it != this) && (*it)->layer() >= layer()) {
473  return false;
474  }
475  }
476  return true;
477 }
478 
479 bool
481 {
482  assert(0!=m_context->eventItemsManager());
484  itEnd = m_context->eventItemsManager()->end();
485  it != itEnd;
486  ++it) {
487  if((*it) && (*it != this) && (*it)->layer() <= layer()) {
488  return false;
489  }
490  }
491  return true;
492 }
493 
494 
495 unsigned int
497 {
498  return m_id;
499 }
500 
501 const std::string&
503 {
504  return m_name;
505 }
506 
507 const TClass*
509 {
510  return m_type;
511 }
512 
513 const std::string&
515 {
516  return m_purpose;
517 }
518 
519 const std::string&
521 {
522  return m_moduleLabel;
523 }
524 const std::string&
526 {
527  return m_productInstanceLabel;
528 }
529 
530 const std::string&
532 {
533  return m_processName;
534 }
535 
537 FWEventItem::modelInfo(int iIndex) const
538 {
539  getPrimaryData();
541  return m_itemInfos.at(iIndex);
542  }
543  FWDisplayProperties dp(m_itemInfos.at(iIndex).displayProperties());
544  dp.setIsVisible(false);
545  ModelInfo t(dp,m_itemInfos.at(iIndex).isSelected());
546  return t;
547 }
548 
549 size_t
551 {
552  getPrimaryData();
553  return m_itemInfos.size();
554 }
555 
556 bool
558 {
559  return m_accessor->isCollection();
560 }
561 
562 const TClass*
564 {
565  return m_accessor->modelType();
566 }
567 
568 const void*
569 FWEventItem::modelData(int iIndex) const
570 {
571  getPrimaryData();
572  return m_accessor->modelData(iIndex);
573 }
574 
576 FWEventItem::modelName(int iIndex) const
577 {
578  std::ostringstream s;
579  size_t lastChar = name().size();
580  //if name ends in 's' assume it is plural and remove the s for the individual object
581  if(name()[lastChar-1]=='s') {
582  --lastChar;
583  }
584  s<<name().substr(0,lastChar)<<" "<<iIndex;
585  return s.str();
586 }
587 
588 bool
590 {
591  return true; //m_interestingValueGetter.isValid();
592 }
593 
594 
595 const std::string&
597 {
598  getPrimaryData();
599  return m_interestingValueGetter.getToolTip(m_accessor->modelData(iIndex));
600 }
601 
602 
603 const std::string&
605 {
606  return m_filter.expression();
607 }
608 
609 void
611 {
612  //NOTE: need to unselect first before announcing destruction
613  // because some items are listening to the display change and may
614  // not properly release their connection to that signal after they
615  // are destroyed via a connection to goingToBeDestroyed_
616  const_cast<FWEventItem*>(this)->unselectItem();
617  {
618  FWChangeSentry sentry(*(changeManager()));
619 
620  for(int index=0; index <static_cast<int>(size()); ++index) {
621  if(m_itemInfos.at(index).m_isSelected) {
622  FWModelId id(this,index);
623  selectionManager()->unselect(id);
624  changeManager()->changed(id);
625  }
626  }
627  }
628  goingToBeDestroyed_(this);
629  delete this;
630 }
631 
632 
633 void
635 {
636  if(!m_isSelected) {
637  m_isSelected=true;
638  selectionManager()->selectItem(this);
640  }
641 }
642 void
644 {
645  if(m_isSelected) {
646  m_isSelected=false;
649  }
650 }
651 void
653 {
655  if(m_isSelected) {
656  selectionManager()->selectItem(this);
657  }else {
659  }
661 }
662 bool
664 {
665  return m_isSelected;
666 }
667 
668 bool
670  return !errorMessage().empty();
671 }
672 
673 const std::string&
675 {
676  if(m_errorMessage.empty()) {
677  getPrimaryData();
678  }
679  return m_errorMessage;
680 }
681 
682 const FWGeometry*
684  return m_context->getGeom();
685 }
686 
688 {
690 
691  FWChangeSentry sentry(*(this->changeManager()));
692  for(int index=0; index <static_cast<int>(size()); ++index) {
693  m_itemInfos.at(index).m_displayProperties.setColor(m_origColor);
694  FWModelId id(this,index);
695  changeManager()->changed(id);
696  }
697 
699 }
700 //
701 // static member functions
702 //
const TClass * m_type
Definition: FWEventItem.h:231
type
Definition: HCALResponse.h:21
bool passesFilter(const void *) const
FWItemChangeSignal preItemChanged_
Definition: FWEventItem.h:207
const FWDisplayProperties & defaultDisplayProperties() const
Definition: FWEventItem.cc:453
void setColor(Color_t iColor)
FWModelChangeManager * changeManager() const
Definition: FWEventItem.h:132
void destroy() const
Definition: FWEventItem.cc:610
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:576
void setEvent(const edm::EventBase *iEvent)
Definition: FWEventItem.cc:122
const std::string & name() const
Definition: FWEventItem.cc:502
FWItemValueGetter m_interestingValueGetter
Definition: FWEventItem.h:244
const FWGeometry * getGeom() const
Definition: Context.h:83
void proxyConfigChanged()
Definition: FWEventItem.cc:370
void setDisplayProperties(int iIndex, const FWDisplayProperties &) const
Definition: FWEventItem.cc:278
const std::string & filterExpression() const
Definition: FWEventItem.cc:604
FWItemChangeSignal defaultDisplayPropertiesChanged_
Definition: FWEventItem.h:211
bool haveInterestingValue() const
Definition: FWEventItem.cc:589
void getPrimaryData() const
Definition: FWEventItem.cc:445
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:663
const std::string & processName() const
Definition: FWEventItem.cc:531
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:394
Color_t color() const
int layer() const
Definition: FWEventItem.cc:459
unsigned int m_id
Definition: FWEventItem.h:229
FWModelFilter m_filter
Definition: FWEventItem.h:246
Char_t transparency() const
int iEvent
Definition: GenABIO.cc:230
void setDefaultDisplayProperties(const FWDisplayProperties &)
Definition: FWEventItem.cc:157
void resetColor()
Definition: FWEventItem.cc:687
const std::string & productInstanceLabel() const
Definition: FWEventItem.cc:525
std::string m_processName
Definition: FWEventItem.h:241
void setClassName(const std::string &)
const TClass * type() const
Definition: FWEventItem.cc:508
FWProxyBuilderConfiguration * m_proxyBuilderConfig
Definition: FWEventItem.h:253
void unselectItem(FWEventItem *)
unsigned int id() const
Definition: FWEventItem.cc:496
void unselect(const FWModelId &iId)
T min(T a, T b)
Definition: MathUtil.h:58
void setData(const edm::ObjectWithDict &) const
Definition: FWEventItem.cc:432
const std::string & modelInterestingValueAsString(int iIndex) const
Definition: FWEventItem.cc:596
static int minLayerValue()
Definition: FWEventItem.cc:38
bool m_printedErrorThisEvent
Definition: FWEventItem.h:247
bool hasError() const
returns true if failed to get data for this event
Definition: FWEventItem.cc:669
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:480
size_t size() const
Definition: FWEventItem.cc:550
void setExpression(const std::string &)
FWDisplayProperties m_displayProperties
Definition: FWEventItem.h:234
void selectItem()
Definition: FWEventItem.cc:634
void handleChange()
Definition: FWEventItem.cc:380
auto dp
Definition: deltaR.h:22
virtual ~FWEventItem()
Definition: FWEventItem.cc:101
bool isInFront() const
returns true if item is in front of all other items
Definition: FWEventItem.cc:465
void setFilterExpression(const std::string &)
Definition: FWEventItem.cc:201
void unselectItem()
Definition: FWEventItem.cc:643
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:94
HLT enums.
bool isCollection() const
Definition: FWEventItem.cc:557
const TClass * modelType() const
Definition: FWEventItem.cc:563
const std::string & errorMessage() const
returns error string if there was a problem this event
Definition: FWEventItem.cc:674
std::vector< ModelInfo > m_itemInfos
Definition: FWEventItem.h:236
const std::string & getToolTip(const void *iObject) const
void toggleSelectItem()
Definition: FWEventItem.cc:652
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:569
ModelInfo modelInfo(int iIndex) const
Definition: FWEventItem.cc:537
void setIsVisible(bool iSet)
const std::string & purpose() const
Definition: FWEventItem.cc:514
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:683
const std::string & moduleLabel() const
Definition: FWEventItem.cc:520
void selectItem(FWEventItem *)
const_iterator end() const
FWItemChangeSignal filterChanged_
Definition: FWEventItem.h:214