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 
38 int FWEventItem::minLayerValue() { return -100; }
39 
40 int FWEventItem::maxLayerValue() { return 100; }
41 
42 //
43 // constructors and destructor
44 //
46  unsigned int iId,
47  std::shared_ptr<FWItemAccessorBase> iAccessor,
48  const FWPhysicsObjectDesc& iDesc,
49  const FWConfiguration* pbc)
50  : m_context(iContext),
51  m_id(iId),
52  m_name(iDesc.name()),
53  m_type(iDesc.type()),
54  m_purpose(iDesc.purpose()),
55  m_accessor(iAccessor),
56  m_displayProperties(iDesc.displayProperties()),
57  m_layer(iDesc.layer()),
58  m_moduleLabel(iDesc.moduleLabel()),
59  m_productInstanceLabel(iDesc.productInstanceLabel()),
60  m_processName(iDesc.processName()),
61  m_event(nullptr),
62  m_interestingValueGetter(edm::TypeWithDict(*(m_accessor->modelType()->GetTypeInfo())), m_purpose),
63  m_filter(iDesc.filterExpression(), ""),
64  m_printedErrorThisEvent(false),
65  m_isSelected(false),
66  m_origColor(0),
67  m_proxyBuilderConfig(nullptr) {
68  //assert(m_type->GetTypeInfo());
69  //edm::TypeWithDict dataType(*(m_type->GetTypeInfo()));
70  //assert(dataType != edm::TypeWithDict() );
71  //
72  //std::string dataTypeName = dataType.name();
73  //if (dataTypeName[dataTypeName.size() -1] == '>')
74  // dataTypeName += " ";
75  //std::string wrapperName = "edm::Wrapper<" + dataTypeName + ">";
76  //
77  //fwLog(fwlog::kDebug) << "Looking for the wrapper name"
78  // << wrapperName << std::endl;
79  //m_wrapperType = edm::TypeWithDict::byName(wrapperName);
80  //
81  //assert(m_wrapperType != edm::TypeWithDict());
82  if (!m_accessor->isCollection()) {
83  m_itemInfos.reserve(1);
84  }
85  m_filter.setClassName(modelType()->GetName());
88 }
89 // FWEventItem::FWEventItem(const FWEventItem& rhs)
90 // {
91 // // do actual copying here;
92 // }
93 
95 
96 //
97 // assignment operators
98 //
99 // const FWEventItem& FWEventItem::operator=(const FWEventItem& rhs)
100 // {
101 // //An exception safe implementation is
102 // FWEventItem temp(rhs);
103 // swap(rhs);
104 //
105 // return *this;
106 // }
107 
108 //
109 // member functions
110 //
112  m_printedErrorThisEvent = false;
113  m_event = iEvent;
114  m_accessor->reset();
115  m_itemInfos.clear();
116  handleChange();
117 }
118 
120  const std::string& iProductInstance,
121  const std::string& iProcess) {
122  m_moduleLabel = iModule;
123  m_productInstanceLabel = iProductInstance;
124  m_processName = iProcess;
125  m_accessor->reset();
126  m_itemInfos.clear();
127  handleChange();
128 }
129 
130 void FWEventItem::setName(const std::string& iName) { m_name = iName; }
131 
139  bool visChange = m_displayProperties.isVisible() != iProp.isVisible();
140  bool colorChanged = m_displayProperties.color() != iProp.color();
141  bool transparencyChanged = m_displayProperties.transparency() != iProp.transparency();
142 
143  if (!visChange && !colorChanged && !transparencyChanged) {
144  return;
145  }
146  //If the default visibility is changed, we want to also change the the visibility of the children
147  // BUT we want to remember the old visibility so if the visibility is changed again we return
148  // to the previous state.
149  // only the visible ones need to be marked as 'changed'
150  FWChangeSentry sentry(*(changeManager()));
151 
152  for (int index = 0; index < static_cast<int>(size()); ++index) {
153  FWDisplayProperties prp = m_itemInfos[index].displayProperties();
154  bool vis = prp.isVisible();
155  bool changed = false;
156  changed = visChange && vis;
157 
158  if (colorChanged) {
159  if (m_displayProperties.color() == prp.color()) {
160  prp.setColor(iProp.color());
161  changed = true;
162  }
163  }
164  if (transparencyChanged) {
166  prp.setTransparency(iProp.transparency());
167  changed = true;
168  }
169  }
170  if (changed) {
171  m_itemInfos[index].m_displayProperties = prp;
172  FWModelId id(this, index);
173  changeManager()->changed(id);
174  }
175  }
176  m_displayProperties = iProp;
178 }
179 
181  m_filter.setExpression(iExpression);
182  filterChanged_(this);
183  runFilter();
184 }
185 
187  if (m_accessor->isCollection() && m_accessor->data()) {
188  //std::cout <<"runFilter"<<std::endl;
189  FWChangeSentry sentry(*(this->changeManager()));
190  int size = m_accessor->size();
191  std::vector<ModelInfo>::iterator itInfo = m_itemInfos.begin();
192  try {
193  for (int index = 0; index != size; ++index, ++itInfo) {
194  bool changed = false;
195  bool wasVisible = itInfo->m_displayProperties.isVisible();
196  if (not m_filter.passesFilter(m_accessor->modelData(index))) {
197  itInfo->m_displayProperties.setIsVisible(false);
198  changed = wasVisible == true;
199  } else {
200  itInfo->m_displayProperties.setIsVisible(true);
201  changed = wasVisible == false;
202  }
203  if (changed) {
204  FWModelId id(this, index);
205  changeManager()->changed(id);
206  }
207  }
208  } catch (const std::exception& iException) {
209  //Should log this error
210  std::cerr << "Exception occurred while running filter on " << name() << "\n" << iException.what() << std::endl;
211  }
212  }
213 }
214 
215 void FWEventItem::unselect(int iIndex) const {
216  //check if this is a change
217  if (bool& sel = m_itemInfos.at(iIndex).m_isSelected) {
218  sel = false;
219  FWModelId id(this, iIndex);
220  selectionManager()->unselect(id);
221  changeManager()->changed(id);
222  }
223 }
224 void FWEventItem::select(int iIndex) const {
225  bool& sel = m_itemInfos.at(iIndex).m_isSelected;
226  if (not sel) {
227  sel = true;
228  FWModelId id(this, iIndex);
229  selectionManager()->select(id);
230  //want to make it obvious what type of object was selected
231  // therefore we also select the item
232  const_cast<FWEventItem*>(this)->selectItem();
233  changeManager()->changed(id);
234  }
235 }
236 void FWEventItem::toggleSelect(int iIndex) const {
237  bool& sel = m_itemInfos.at(iIndex).m_isSelected;
238  sel = not sel;
239  FWModelId id(this, iIndex);
240  if (sel)
241  selectionManager()->select(id);
242  else
243  selectionManager()->unselect(id);
244  changeManager()->changed(id);
245 }
246 
247 void FWEventItem::setDisplayProperties(int iIndex, const FWDisplayProperties& iProps) const {
248  FWDisplayProperties& prop = m_itemInfos.at(iIndex).m_displayProperties;
250  if (prop != iProps) {
251  prop = iProps;
252  FWModelId id(this, iIndex);
253  //selectionManager()->select(id);
254  changeManager()->changed(id);
255  }
256  } else {
257  if (iProps.isVisible()) {
258  FWChangeSentry sentry(*(this->changeManager()));
259  int size = m_accessor->size();
260  std::vector<ModelInfo>::iterator itInfo = m_itemInfos.begin();
261  for (int index = 0; index != size; ++index, ++itInfo) {
262  if (itInfo->m_displayProperties.isVisible()) {
263  itInfo->m_displayProperties.setIsVisible(false);
264  FWModelId id(this, index);
265  changeManager()->changed(id);
266  }
267  }
268  m_itemInfos.at(iIndex).m_displayProperties.setIsVisible(true);
269  FWModelId id(this, iIndex);
270  changeManager()->changed(id);
271  const_cast<FWEventItem*>(this)->m_displayProperties.setIsVisible(true);
272  //NOTE: need to send out a signal here
274  }
275  }
276 }
277 
279  assert(nullptr != m_context->eventItemsManager());
280  int largest = layer();
282  itEnd = m_context->eventItemsManager()->end();
283  it != itEnd;
284  ++it) {
285  if ((*it) && (*it != this) && (*it)->layer() > largest) {
286  largest = (*it)->layer();
287  }
288  }
289 
290  if (largest >= layer()) {
291  m_layer = std::min(largest + 1, maxLayerValue());
292  }
293 
294  m_itemInfos.clear();
295  m_accessor->reset();
296  handleChange();
297 }
298 
300  assert(nullptr != m_context->eventItemsManager());
301  int smallest = layer();
303  itEnd = m_context->eventItemsManager()->end();
304  it != itEnd;
305  ++it) {
306  if ((*it) && (*it != this) && (*it)->layer() < smallest) {
307  smallest = (*it)->layer();
308  }
309  }
310 
311  if (smallest <= layer()) {
312  m_layer = std::max(smallest - 1, minLayerValue());
313  }
314 
315  m_itemInfos.clear();
316  m_accessor->reset();
317  handleChange();
318 }
319 
321  assert(nullptr != m_context->eventItemsManager());
322 
324 
325  m_itemInfos.clear();
326  m_accessor->reset();
327  handleChange();
328 }
329 
331  if (!k) {
332  m_itemInfos.clear();
333  m_accessor->reset();
335  handleChange();
336  } else {
337  changeManager()->changed(this);
338  }
339 }
340 
342  preItemChanged_(this);
343  FWChangeSentry sentry(*(this->changeManager()));
344  //want filter to rerun after all changes have been made
345  changeManager()->changed(this);
346  getPrimaryData();
347  runFilter();
348 }
349 
350 //
351 // const member functions
352 //
353 const void* FWEventItem::data(const std::type_info& iInfo) const {
354  //At the moment this is a programming error
355  assert(iInfo == *(m_type->GetTypeInfo()));
356 
357  //lookup data if we don't already have it
358  if (m_accessor->data())
359  return m_accessor->data();
360 
361  m_errorMessage.clear();
362  if (!m_event)
363  return m_accessor->data();
364 
365  // Retrieve the data from the event.
367  edm::TypeWithDict type(iInfo);
369  try {
371  setData(*handle);
372  } catch (std::exception& iException) {
374  std::ostringstream s;
375  s << "Failed to get " << name() << " because \n" << iException.what();
376  m_errorMessage = s.str();
378  }
379  return nullptr;
380  }
381 
382  return m_accessor->data();
383 }
384 
385 void FWEventItem::setData(const edm::ObjectWithDict& iData) const {
386  m_accessor->setData(iData);
387  //std::cout <<"size "<<m_accessor->size()<<std::endl;
388  if (m_accessor->isCollection()) {
389  m_itemInfos.reserve(m_accessor->size());
390  m_itemInfos.resize(m_accessor->size(), ModelInfo(m_displayProperties, false));
391  } else {
392  m_itemInfos.push_back(ModelInfo(m_displayProperties, false));
393  }
394 }
395 
397  //if(0!=m_data) return;
398  if (nullptr != m_accessor->data())
399  return;
400  this->data(*(m_type->GetTypeInfo()));
401 }
402 
404 
405 int FWEventItem::layer() const { return m_layer; }
406 
408  assert(nullptr != m_context->eventItemsManager());
410  itEnd = m_context->eventItemsManager()->end();
411  it != itEnd;
412  ++it) {
413  if ((*it) && (*it != this) && (*it)->layer() >= layer()) {
414  return false;
415  }
416  }
417  return true;
418 }
419 
420 bool FWEventItem::isInBack() const {
421  assert(nullptr != m_context->eventItemsManager());
423  itEnd = m_context->eventItemsManager()->end();
424  it != itEnd;
425  ++it) {
426  if ((*it) && (*it != this) && (*it)->layer() <= layer()) {
427  return false;
428  }
429  }
430  return true;
431 }
432 
433 unsigned int FWEventItem::id() const { return m_id; }
434 
435 const std::string& FWEventItem::name() const { return m_name; }
436 
437 const TClass* FWEventItem::type() const { return m_type; }
438 
439 const std::string& FWEventItem::purpose() const { return m_purpose; }
440 
443 
445 
447  getPrimaryData();
449  return m_itemInfos.at(iIndex);
450  }
451  FWDisplayProperties dp(m_itemInfos.at(iIndex).displayProperties());
452  dp.setIsVisible(false);
453  ModelInfo t(dp, m_itemInfos.at(iIndex).isSelected());
454  return t;
455 }
456 
457 size_t FWEventItem::size() const {
458  getPrimaryData();
459  return m_itemInfos.size();
460 }
461 
462 bool FWEventItem::isCollection() const { return m_accessor->isCollection(); }
463 
464 const TClass* FWEventItem::modelType() const { return m_accessor->modelType(); }
465 
466 const void* FWEventItem::modelData(int iIndex) const {
467  getPrimaryData();
468  return m_accessor->modelData(iIndex);
469 }
470 
472  std::ostringstream s;
473  size_t lastChar = name().size();
474  //if name ends in 's' assume it is plural and remove the s for the individual object
475  if (name()[lastChar - 1] == 's') {
476  --lastChar;
477  }
478  s << name().substr(0, lastChar) << " " << iIndex;
479  return s.str();
480 }
481 
483  return true; //m_interestingValueGetter.isValid();
484 }
485 
487  getPrimaryData();
488  return m_interestingValueGetter.getToolTip(m_accessor->modelData(iIndex));
489 }
490 
492 
493 void FWEventItem::destroy() const {
494  //NOTE: need to unselect first before announcing destruction
495  // because some items are listening to the display change and may
496  // not properly release their connection to that signal after they
497  // are destroyed via a connection to goingToBeDestroyed_
498  const_cast<FWEventItem*>(this)->unselectItem();
499  {
500  FWChangeSentry sentry(*(changeManager()));
501 
502  for (int index = 0; index < static_cast<int>(size()); ++index) {
503  if (m_itemInfos.at(index).m_isSelected) {
504  FWModelId id(this, index);
505  selectionManager()->unselect(id);
506  changeManager()->changed(id);
507  }
508  }
509  }
510  goingToBeDestroyed_(this);
511  delete this;
512 }
513 
515  if (!m_isSelected) {
516  m_isSelected = true;
517  selectionManager()->selectItem(this);
519  }
520 }
522  if (m_isSelected) {
523  m_isSelected = false;
526  }
527 }
530  if (m_isSelected) {
531  selectionManager()->selectItem(this);
532  } else {
534  }
536 }
538 
539 bool FWEventItem::hasError() const { return !errorMessage().empty(); }
540 
542  if (m_errorMessage.empty()) {
543  getPrimaryData();
544  }
545  return m_errorMessage;
546 }
547 
548 const FWGeometry* FWEventItem::getGeom() const { return m_context->getGeom(); }
549 
552 
553  FWChangeSentry sentry(*(this->changeManager()));
554  for (int index = 0; index < static_cast<int>(size()); ++index) {
555  m_itemInfos.at(index).m_displayProperties.setColor(m_origColor);
556  FWModelId id(this, index);
557  changeManager()->changed(id);
558  }
559 
561 }
562 //
563 // static member functions
564 //
const TClass * m_type
Definition: FWEventItem.h:210
bool isCollection() const
Definition: FWEventItem.cc:462
void proxyConfigChanged(bool k=false)
Definition: FWEventItem.cc:330
size_t size() const
Definition: FWEventItem.cc:457
FWItemChangeSignal preItemChanged_
Definition: FWEventItem.h:186
const std::string & expression() const
const void * modelData(int iIndex) const
Definition: FWEventItem.cc:466
void setColor(Color_t iColor)
void moveToBack()
Definition: FWEventItem.cc:299
void select(const FWModelId &iId)
Color_t m_origColor
Definition: FWEventItem.h:230
void moveToFront()
Definition: FWEventItem.cc:278
void setData(const edm::ObjectWithDict &) const
Definition: FWEventItem.cc:385
void moveToLayer(int layer)
Definition: FWEventItem.cc:320
const FWEventItemsManager * eventItemsManager() const
Definition: Context.h:56
void setEvent(const edm::EventBase *iEvent)
Definition: FWEventItem.cc:111
bool itemIsSelected() const
Definition: FWEventItem.cc:537
FWItemValueGetter m_interestingValueGetter
Definition: FWEventItem.h:223
unsigned int id() const
Definition: FWEventItem.cc:433
Char_t transparency() const
FWItemChangeSignal defaultDisplayPropertiesChanged_
Definition: FWEventItem.h:190
bool isInBack() const
returns true if item is behind all other items
Definition: FWEventItem.cc:420
bool passesFilter(const void *) const
FWItemChangeSignal goingToBeDestroyed_
Definition: FWEventItem.h:197
FWModelChangeManager * changeManager() const
Definition: FWEventItem.h:123
const std::string & processName() const
Definition: FWEventItem.cc:444
const std::string & errorMessage() const
returns error string if there was a problem this event
Definition: FWEventItem.cc:541
bool getByLabel(InputTag const &, Handle< T > &) const
Definition: EventBase.h:92
const fireworks::Context * m_context
Definition: FWEventItem.h:207
bool isInFront() const
returns true if item is in front of all other items
Definition: FWEventItem.cc:407
const std::string & moduleLabel() const
Definition: FWEventItem.cc:441
void setLabels(const std::string &iModule, const std::string &iProductInstance, const std::string &iProcess)
Definition: FWEventItem.cc:119
assert(be >=bs)
std::string m_moduleLabel
Definition: FWEventItem.h:218
std::shared_ptr< FWItemAccessorBase > m_accessor
Definition: FWEventItem.h:212
const void * data(const std::type_info &) const
Definition: FWEventItem.cc:353
static int maxLayerValue()
Definition: FWEventItem.cc:40
const std::string & modelInterestingValueAsString(int iIndex) const
Definition: FWEventItem.cc:486
void select(int iIndex) const
Definition: FWEventItem.cc:224
constexpr std::array< uint8_t, layerIndexSize > layer
unsigned int m_id
Definition: FWEventItem.h:208
FWSelectionManager * selectionManager() const
Definition: FWEventItem.h:124
const TClass * modelType() const
Definition: FWEventItem.cc:464
FWModelFilter m_filter
Definition: FWEventItem.h:225
void unselect(int iIndex) const
Definition: FWEventItem.cc:215
int iEvent
Definition: GenABIO.cc:224
void setDefaultDisplayProperties(const FWDisplayProperties &)
Definition: FWEventItem.cc:138
void resetColor()
Definition: FWEventItem.cc:550
const FWDisplayProperties & displayProperties() const
FWGeometry * getGeom() const
Definition: Context.h:72
std::string modelName(int iIndex) const
Definition: FWEventItem.cc:471
std::string m_processName
Definition: FWEventItem.h:220
void getPrimaryData() const
Definition: FWEventItem.cc:396
const FWDisplayProperties & defaultDisplayProperties() const
Definition: FWEventItem.cc:403
void setClassName(const std::string &)
FWProxyBuilderConfiguration * m_proxyBuilderConfig
Definition: FWEventItem.h:232
bool hasError() const
returns true if failed to get data for this event
Definition: FWEventItem.cc:539
const std::string & filterExpression() const
Definition: FWEventItem.cc:491
void unselectItem(FWEventItem *)
void unselect(const FWModelId &iId)
static int minLayerValue()
Definition: FWEventItem.cc:38
bool m_printedErrorThisEvent
Definition: FWEventItem.h:226
const std::string & getToolTip(const void *iObject) const
void changed(const FWModelId &)
const FWGeometry * getGeom() const
Definition: FWEventItem.cc:548
int layer() const
Definition: FWEventItem.cc:405
void setExpression(const std::string &)
FWDisplayProperties m_displayProperties
Definition: FWEventItem.h:213
void selectItem()
Definition: FWEventItem.cc:514
void handleChange()
Definition: FWEventItem.cc:341
const TClass * type() const
Definition: FWEventItem.cc:437
virtual ~FWEventItem()
Definition: FWEventItem.cc:94
const std::string & name() const
Definition: FWEventItem.cc:435
void setFilterExpression(const std::string &)
Definition: FWEventItem.cc:180
void unselectItem()
Definition: FWEventItem.cc:521
void setTransparency(Char_t transparency)
const edm::EventBase * m_event
Definition: FWEventItem.h:221
FWEventItem(fireworks::Context *iContext, unsigned int iItemId, std::shared_ptr< FWItemAccessorBase > iAccessor, const FWPhysicsObjectDesc &iDesc, const FWConfiguration *pbConf=nullptr)
Definition: FWEventItem.cc:45
std::string m_errorMessage
Definition: FWEventItem.h:227
HLT enums.
std::vector< ModelInfo > m_itemInfos
Definition: FWEventItem.h:215
void toggleSelectItem()
Definition: FWEventItem.cc:528
void setDisplayProperties(int iIndex, const FWDisplayProperties &) const
Definition: FWEventItem.cc:247
bool haveInterestingValue() const
Definition: FWEventItem.cc:482
const std::string & purpose() const
Definition: FWEventItem.cc:439
const_iterator begin() const
NOTE: iterator is allowed to return a null object for items that have been removed.
bool m_isSelected
Definition: FWEventItem.h:229
const_iterator end() const
void setIsVisible(bool iSet)
ModelInfo modelInfo(int iIndex) const
Definition: FWEventItem.cc:446
void destroy() const
Definition: FWEventItem.cc:493
const std::string & productInstanceLabel() const
Definition: FWEventItem.cc:442
void setName(const std::string &iName)
Definition: FWEventItem.cc:130
std::vector< FWEventItem * >::const_iterator const_iterator
void runFilter()
Definition: FWEventItem.cc:186
std::string m_purpose
Definition: FWEventItem.h:211
std::string m_productInstanceLabel
Definition: FWEventItem.h:219
std::string m_name
Definition: FWEventItem.h:209
void toggleSelect(int iIndex) const
Definition: FWEventItem.cc:236
void selectItem(FWEventItem *)
FWItemChangeSignal filterChanged_
Definition: FWEventItem.h:193