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.53 2010/09/07 15:46:46 yana 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"
33 
34 //
35 // static data member definitions
36 //
37 static
38 const std::vector<std::pair<std::string,std::string> >&
40 {
41  static std::vector<std::pair<std::string,std::string> > s_names;
42  if(s_names.empty()){
43  s_names.push_back(std::pair<std::string,std::string>("pt","GeV"));
44  s_names.push_back(std::pair<std::string,std::string>("et","GeV"));
45  s_names.push_back(std::pair<std::string,std::string>("energy","GeV"));
46  }
47  return s_names;
48 }
49 
51 {
52  return -100;
53 }
54 
56 {
57  return 100;
58 }
59 
60 
61 //
62 // constructors and destructor
63 //
65  unsigned int iId,
66  boost::shared_ptr<FWItemAccessorBase> iAccessor,
67  const FWPhysicsObjectDesc& iDesc) :
68  m_context(iContext),
69  m_id(iId),
70  m_name(iDesc.name()),
71  m_type(iDesc.type()),
72  m_purpose(iDesc.purpose()),
73  m_accessor(iAccessor),
74  m_displayProperties(iDesc.displayProperties()),
75  m_layer(iDesc.layer()),
76  m_moduleLabel(iDesc.moduleLabel()),
77  m_productInstanceLabel(iDesc.productInstanceLabel()),
78  m_processName(iDesc.processName()),
79  m_event(0),
80  m_interestingValueGetter(ROOT::Reflex::Type::ByTypeInfo(*(m_accessor->modelType()->GetTypeInfo())),
82  m_filter(iDesc.filterExpression(),""),
83  m_printedErrorThisEvent(false),
84  m_isSelected(false)
85 {
86  //assert(m_type->GetTypeInfo());
87  //ROOT::Reflex::Type dataType( ROOT::Reflex::Type::ByTypeInfo(*(m_type->GetTypeInfo())));
88  //assert(dataType != ROOT::Reflex::Type() );
89  //
90  //std::string dataTypeName = dataType.Name(ROOT::Reflex::SCOPED);
91  //if (dataTypeName[dataTypeName.size() -1] == '>')
92  // dataTypeName += " ";
93  //std::string wrapperName = "edm::Wrapper<" + dataTypeName + ">";
94  //
95  //fwLog(fwlog::kDebug) << "Looking for the wrapper name"
96  // << wrapperName << std::endl;
97  //m_wrapperType = ROOT::Reflex::Type::ByName(wrapperName);
98  //
99  //assert(m_wrapperType != ROOT::Reflex::Type());
100  if(!m_accessor->isCollection()) {
101  m_itemInfos.reserve(1);
102  }
103  m_filter.setClassName(modelType()->GetName());
104 }
105 // FWEventItem::FWEventItem(const FWEventItem& rhs)
106 // {
107 // // do actual copying here;
108 // }
109 /*
110  FWEventItem::~FWEventItem()
111  {
112  }
113  */
114 //
115 // assignment operators
116 //
117 // const FWEventItem& FWEventItem::operator=(const FWEventItem& rhs)
118 // {
119 // //An exception safe implementation is
120 // FWEventItem temp(rhs);
121 // swap(rhs);
122 //
123 // return *this;
124 // }
125 
126 //
127 // member functions
128 //
129 void
131 {
132  m_printedErrorThisEvent = false;
133  m_event = iEvent;
134  m_accessor->reset();
135  m_itemInfos.clear();
136  handleChange();
137 }
138 
139 void
140 FWEventItem::setLabels(const std::string& iModule,
141  const std::string& iProductInstance,
142  const std::string& iProcess)
143 {
144  m_moduleLabel = iModule;
145  m_productInstanceLabel = iProductInstance;
146  m_processName = iProcess;
147  m_accessor->reset();
148  m_itemInfos.clear();
149  handleChange();
150 }
151 
152 void
153 FWEventItem::setName(const std::string& iName)
154 {
155  m_name = iName;
156 }
157 
164 void
166 {
167  bool visChange = m_displayProperties.isVisible() != iProp.isVisible();
168  bool colorChanged = m_displayProperties.color() != iProp.color();
169  bool transparencyChanged = m_displayProperties.transparency() != iProp.transparency();
170 
171  if(!visChange && !colorChanged && !transparencyChanged) {
172  return;
173  }
174  //If the default visibility is changed, we want to also change the the visibility of the children
175  // BUT we want to remember the old visibility so if the visibility is changed again we return
176  // to the previous state.
177  // only the visible ones need to be marked as 'changed'
178  FWChangeSentry sentry(*(changeManager()));
179 
180  for(int index=0; index <static_cast<int>(size()); ++index) {
181  FWDisplayProperties prp = m_itemInfos[index].displayProperties();
182  bool vis=prp.isVisible();
183  bool changed = false;
184  changed = visChange && vis;
185 
186  if(colorChanged) {
187  if(m_displayProperties.color()==prp.color()) {
188  prp.setColor(iProp.color());
189  changed = true;
190  }
191  }
192  if (transparencyChanged) {
194  prp.setTransparency(iProp.transparency());
195  changed = true;
196  }
197  }
198  if(changed) {
199  m_itemInfos[index].m_displayProperties=prp;
200  FWModelId id(this,index);
201  changeManager()->changed(id);
202  }
203  }
204  m_displayProperties= iProp;
206 }
207 
208 void
209 FWEventItem::setFilterExpression(const std::string& iExpression)
210 {
211  m_filter.setExpression(iExpression);
212  filterChanged_(this);
213  runFilter();
214 }
215 
216 void
218 {
219  if(m_accessor->isCollection() && m_accessor->data()) {
220  //std::cout <<"runFilter"<<std::endl;
221  FWChangeSentry sentry(*(this->changeManager()));
222  int size = m_accessor->size();
223  std::vector<ModelInfo>::iterator itInfo = m_itemInfos.begin();
224  try {
225  for(int index = 0; index != size; ++index,++itInfo) {
226  bool changed = false;
227  bool wasVisible = itInfo->m_displayProperties.isVisible();
228  if(not m_filter.passesFilter(m_accessor->modelData(index))) {
229  itInfo->m_displayProperties.setIsVisible(false);
230  changed = wasVisible==true;
231  } else {
232  itInfo->m_displayProperties.setIsVisible(true);
233  changed = wasVisible==false;
234  }
235  if(changed) {
236  FWModelId id(this,index);
237  changeManager()->changed(id);
238  }
239  }
240  } catch( const std::exception& iException) {
241  //Should log this error
242  std::cerr <<"Exception occurred while running filter on "<<name()<<"\n"
243  <<iException.what()<<std::endl;
244  }
245  }
246 }
247 
248 void
249 FWEventItem::unselect(int iIndex) const
250 {
251  //check if this is a change
252  if(bool& sel = m_itemInfos.at(iIndex).m_isSelected) {
253  sel=false;
254  FWModelId id(this,iIndex);
255  selectionManager()->unselect(id);
256  changeManager()->changed(id);
257  }
258 }
259 void
260 FWEventItem::select(int iIndex) const
261 {
262  bool& sel = m_itemInfos.at(iIndex).m_isSelected;
263  if(not sel) {
264  sel = true;
265  FWModelId id(this,iIndex);
266  selectionManager()->select(id);
267  //want to make it obvious what type of object was selected
268  // therefore we also select the item
269  const_cast<FWEventItem*>(this)->selectItem();
270  changeManager()->changed(id);
271  }
272 }
273 void
274 FWEventItem::toggleSelect(int iIndex) const
275 {
276  bool& sel = m_itemInfos.at(iIndex).m_isSelected;
277  sel = not sel;
278  FWModelId id(this,iIndex);
279  if (sel)
280  selectionManager()->select(id);
281  else selectionManager()->unselect(id);
282  changeManager()->changed(id);
283 }
284 
285 void
287 {
288  FWDisplayProperties& prop = m_itemInfos.at(iIndex).m_displayProperties;
290  if( prop
291  != iProps ) {
292  prop = iProps;
293  FWModelId id(this,iIndex);
294  //selectionManager()->select(id);
295  changeManager()->changed(id);
296  }
297  } else {
298  if(iProps.isVisible()) {
299  FWChangeSentry sentry(*(this->changeManager()));
300  int size = m_accessor->size();
301  std::vector<ModelInfo>::iterator itInfo = m_itemInfos.begin();
302  for(int index = 0; index != size; ++index,++itInfo) {
303  if( itInfo->m_displayProperties.isVisible() ) {
304  itInfo->m_displayProperties.setIsVisible(false);
305  FWModelId id(this,index);
306  changeManager()->changed(id);
307  }
308  }
309  m_itemInfos.at(iIndex).m_displayProperties.setIsVisible(true);
310  FWModelId id(this,iIndex);
311  changeManager()->changed(id);
312  const_cast<FWEventItem*>(this)->m_displayProperties.setIsVisible(true);
313  //NOTE: need to send out a signal here
315  }
316  }
317 }
318 
319 void
321 {
322  assert(0!=m_context->eventItemsManager());
323  int largest = layer();
325  itEnd = m_context->eventItemsManager()->end();
326  it != itEnd;
327  ++it) {
328  if ((*it) && (*it != this) && (*it)->layer() > largest) {
329  largest= (*it)->layer();
330  }
331  }
332 
333  if(largest >= layer()) {
334  m_layer = std::min(largest+1, maxLayerValue());
335  }
336 
337  m_itemInfos.clear();
338  m_accessor->reset();
339  handleChange();
340 }
341 
342 void
344 {
345  assert(0!=m_context->eventItemsManager());
346  int smallest = layer();
348  itEnd = m_context->eventItemsManager()->end();
349  it != itEnd;
350  ++it) {
351  if((*it) && (*it != this) && (*it)->layer() < smallest) {
352  smallest= (*it)->layer();
353  }
354  }
355 
356  if(smallest <= layer()) {
357  m_layer = std::max(smallest-1, minLayerValue());
358  }
359 
360  m_itemInfos.clear();
361  m_accessor->reset();
362  handleChange();
363 }
364 
365 void
367 {
368  assert(0!=m_context->eventItemsManager());
369 
371 
372  m_itemInfos.clear();
373  m_accessor->reset();
374  handleChange();
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  using namespace Reflex;
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 {
590 }
591 
592 double
594 {
595  getPrimaryData();
596  return m_interestingValueGetter.valueFor(m_accessor->modelData(iIndex));
597 }
598 
599 const std::string&
601 {
602  getPrimaryData();
603  return m_interestingValueGetter.stringValueFor(m_accessor->modelData(iIndex));
604 }
605 
606 
607 const std::string&
609 {
610  return m_filter.expression();
611 }
612 
613 void
615 {
616  //NOTE: need to unselect first before announcing destruction
617  // because some items are listening to the display change and may
618  // not properly release their connection to that signal after they
619  // are destroyed via a connection to goingToBeDestroyed_
620  const_cast<FWEventItem*>(this)->unselectItem();
621  {
622  FWChangeSentry sentry(*(changeManager()));
623 
624  for(int index=0; index <static_cast<int>(size()); ++index) {
625  if(m_itemInfos.at(index).m_isSelected) {
626  FWModelId id(this,index);
627  selectionManager()->unselect(id);
628  changeManager()->changed(id);
629  }
630  }
631  }
632  goingToBeDestroyed_(this);
633  delete this;
634 }
635 
636 
637 void
639 {
640  if(!m_isSelected) {
641  m_isSelected=true;
642  selectionManager()->selectItem(this);
644  }
645 }
646 void
648 {
649  if(m_isSelected) {
650  m_isSelected=false;
653  }
654 }
655 void
657 {
659  if(m_isSelected) {
660  selectionManager()->selectItem(this);
661  }else {
663  }
665 }
666 bool
668 {
669  return m_isSelected;
670 }
671 
672 bool
674  return !errorMessage().empty();
675 }
676 
677 const std::string&
679 {
680  if(m_errorMessage.empty()) {
681  getPrimaryData();
682  }
683  return m_errorMessage;
684 }
685 
686 const FWGeometry*
688  return m_context->getGeom();
689 }
690 //
691 // static member functions
692 //
const TClass * m_type
Definition: FWEventItem.h:225
type
Definition: HCALResponse.h:22
bool passesFilter(const void *) const
FWItemChangeSignal preItemChanged_
Definition: FWEventItem.h:200
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:614
void moveToBack()
Definition: FWEventItem.cc:343
void select(const FWModelId &iId)
void moveToFront()
Definition: FWEventItem.cc:320
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:366
std::string modelName(int iIndex) const
Definition: FWEventItem.cc:574
void setEvent(const edm::EventBase *iEvent)
Definition: FWEventItem.cc:130
const std::string & name() const
Definition: FWEventItem.cc:500
FWItemValueGetter m_interestingValueGetter
Definition: FWEventItem.h:238
FWEventItem(fireworks::Context *iContext, unsigned int iItemId, boost::shared_ptr< FWItemAccessorBase > iAccessor, const FWPhysicsObjectDesc &iDesc)
Definition: FWEventItem.cc:64
const FWGeometry * getGeom() const
Definition: Context.h:84
void setDisplayProperties(int iIndex, const FWDisplayProperties &) const
Definition: FWEventItem.cc:286
const std::string & filterExpression() const
Definition: FWEventItem.cc:608
FWItemChangeSignal defaultDisplayPropertiesChanged_
Definition: FWEventItem.h:204
bool haveInterestingValue() const
one value from the model which is normally used for the popup
Definition: FWEventItem.cc:587
void getPrimaryData() const
Definition: FWEventItem.cc:443
void unselect(int iIndex) const
Definition: FWEventItem.cc:249
FWItemChangeSignal goingToBeDestroyed_
Definition: FWEventItem.h:211
#define min(a, b)
Definition: mlp_lapack.h:161
boost::shared_ptr< FWItemAccessorBase > m_accessor
Definition: FWEventItem.h:227
const fireworks::Context * m_context
Definition: FWEventItem.h:222
const std::string & expression() const
bool itemIsSelected() const
Definition: FWEventItem.cc:667
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:140
std::string m_moduleLabel
Definition: FWEventItem.h:233
static int maxLayerValue()
Definition: FWEventItem.cc:55
const void * data(const std::type_info &) const
Definition: FWEventItem.cc:392
Color_t color() const
int layer() const
Definition: FWEventItem.cc:457
bool getByLabel(const InputTag &, Handle< T > &) const
Definition: EventBase.h:86
unsigned int m_id
Definition: FWEventItem.h:223
FWModelFilter m_filter
Definition: FWEventItem.h:240
Char_t transparency() const
int iEvent
Definition: GenABIO.cc:243
void setDefaultDisplayProperties(const FWDisplayProperties &)
Definition: FWEventItem.cc:165
const std::string & productInstanceLabel() const
Definition: FWEventItem.cc:523
std::string m_processName
Definition: FWEventItem.h:235
const T & max(const T &a, const T &b)
const std::string & stringValueFor(const void *) const
void setClassName(const std::string &)
const TClass * type() const
Definition: FWEventItem.cc:506
void unselectItem(FWEventItem *)
tuple handle
Definition: patZpeak.py:22
unsigned int id() const
Definition: FWEventItem.cc:494
void unselect(const FWModelId &iId)
double modelInterestingValue(int iIndex) const
Definition: FWEventItem.cc:593
const std::string & modelInterestingValueAsString(int iIndex) const
Definition: FWEventItem.cc:600
static int minLayerValue()
Definition: FWEventItem.cc:50
bool m_printedErrorThisEvent
Definition: FWEventItem.h:241
bool hasError() const
returns true if failed to get data for this event
Definition: FWEventItem.cc:673
FWSelectionManager * selectionManager() const
Definition: FWEventItem.h:133
void toggleSelect(int iIndex) const
Definition: FWEventItem.cc:274
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:228
void selectItem()
Definition: FWEventItem.cc:638
void handleChange()
Definition: FWEventItem.cc:378
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:209
void unselectItem()
Definition: FWEventItem.cc:647
void setTransparency(Char_t transparency)
static const std::vector< std::pair< std::string, std::string > > & defaultMemberFunctionNames()
Definition: FWEventItem.cc:39
const edm::EventBase * m_event
Definition: FWEventItem.h:236
double valueFor(const void *) const
std::string m_errorMessage
Definition: FWEventItem.h:242
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:678
std::vector< ModelInfo > m_itemInfos
Definition: FWEventItem.h:230
void toggleSelectItem()
Definition: FWEventItem.cc:656
void select(int iIndex) const
Definition: FWEventItem.cc:260
bool m_isSelected
Definition: FWEventItem.h:244
string s
Definition: asciidump.py:422
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:153
std::vector< FWEventItem * >::const_iterator const_iterator
void runFilter()
Definition: FWEventItem.cc:217
std::string m_purpose
Definition: FWEventItem.h:226
std::string m_productInstanceLabel
Definition: FWEventItem.h:234
std::string m_name
Definition: FWEventItem.h:224
const FWGeometry * getGeom() const
Definition: FWEventItem.cc:687
const std::string & moduleLabel() const
Definition: FWEventItem.cc:518
void selectItem(FWEventItem *)
const_iterator end() const
const std::string * moduleLabel() const
Definition: HLTadd.h:40
FWItemChangeSignal filterChanged_
Definition: FWEventItem.h:207