CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FWCaloDataProxyBuilderBase.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Calo
4 // Class : FWCaloDataProxyBuilderBase
5 //
6 // Implementation:
7 // [Notes on implementation]
8 //
9 // Original Author:
10 // Created: Mon May 31 15:09:39 CEST 2010
11 // $Id: FWCaloDataProxyBuilderBase.cc,v 1.5 2010/11/09 16:56:23 amraktad Exp $
12 //
13 
14 // system include files
15 
16 #include <math.h>
17 
18 // user includes
19 #include "TEveCaloData.h"
20 #include "TEveCalo.h"
21 #include "TH2F.h"
22 #include "TEveManager.h"
23 #include "TEveSelection.h"
24 
27 
30 
32 
33 
34 //
35 // constants, enums and typedefs
36 //
37 
38 //
39 // static data member definitions
40 //
41 
42 //
43 // constructors and destructor
44 //
46  m_caloData(0),
47  m_sliceIndex(-1)
48 {
49 }
50 
51 // FWCaloDataProxyBuilderBase::FWCaloDataProxyBuilderBase(const FWCaloDataProxyBuilderBase& rhs)
52 // {
53 // // do actual copying here;
54 // }
55 
57 {
58 }
59 
60 //
61 // assignment operators
62 //
63 // const FWCaloDataProxyBuilderBase& FWCaloDataProxyBuilderBase::operator=(const FWCaloDataProxyBuilderBase& rhs)
64 // {
65 // //An exception safe implementation is
66 // FWCaloDataProxyBuilderBase temp(rhs);
67 // swap(rhs);
68 //
69 // return *this;
70 // }
71 
72 //
73 // member functions
74 //
75 
76 void
78  TEveElementList*, const FWViewContext*)
79 {
80  setCaloData(iItem->context());
81 
83  fillCaloData();
84 
85  m_caloData->SetSliceColor(m_sliceIndex,item()->defaultDisplayProperties().color());
86  m_caloData->SetSliceTransparency(m_sliceIndex,item()->defaultDisplayProperties().transparency());
87  m_caloData->DataChanged();
88  m_caloData->CellSelectionChanged();
89 }
90 
91 //______________________________________________________________________________
92 
93 void
95 {
96  if(m_caloData && item())
97  {
99  fillCaloData();
100 
101  TEveCaloData::vCellId_t& selected = m_caloData->GetCellsSelected();
102  if(!selected.empty()) {
103  if(0==m_caloData->GetSelectedLevel()) {
104  gEve->GetSelection()->AddElement(m_caloData);
105  }
106  } else {
107  if(1==m_caloData->GetSelectedLevel()||2==m_caloData->GetSelectedLevel()) {
108  gEve->GetSelection()->RemoveElement(m_caloData);
109  }
110  }
111 
112  m_caloData->SetSliceColor(m_sliceIndex,item()->defaultDisplayProperties().color());
113  m_caloData->SetSliceTransparency(m_sliceIndex,item()->defaultDisplayProperties().transparency());
114  m_caloData->DataChanged();
115  m_caloData->CellSelectionChanged();
116  }
117 }
118 //______________________________________________________________________________
119 
120 void
122 {
124  if (m_caloData)
125  {
127  FWFromTEveCaloDataSelector* sel = reinterpret_cast<FWFromTEveCaloDataSelector*>(m_caloData->GetUserData());
129  m_caloData->DataChanged();
130  }
131 }
132 
133 
134 
135 void
137 {
138  //find all selected cell ids which are not from this FWEventItem and preserve only them
139  // do this by moving them to the end of the list and then clearing only the end of the list
140  // this avoids needing any additional memory
141 
142  TEveCaloData::vCellId_t& selected = m_caloData->GetCellsSelected();
143 
144  TEveCaloData::vCellId_t::iterator itEnd = selected.end();
145  for(TEveCaloData::vCellId_t::iterator it = selected.begin();
146  it != itEnd;
147  ++it) {
148  if(it->fSlice ==m_sliceIndex) {
149  //we have found one we want to get rid of, so we swap it with the
150  // one closest to the end which is not of this slice
151  do {
152  TEveCaloData::vCellId_t::iterator itLast = itEnd-1;
153  itEnd = itLast;
154  } while (itEnd != it && itEnd->fSlice==m_sliceIndex);
155 
156  if(itEnd != it) {
157  std::swap(*it,*itEnd);
158  } else {
159  //shouldn't go on since advancing 'it' will put us past itEnd
160  break;
161  }
162  //std::cout <<"keeping "<<it->fTower<<" "<<it->fSlice<<std::endl;
163  }
164  }
165  selected.erase(itEnd,selected.end());
166 
167 
168  // reset higlight
169  m_caloData->GetCellsHighlighted().clear();
170 }
virtual void itemBeingDestroyed(const FWEventItem *)
std::set< FWModelId > FWModelIds
const FWEventItem * item() const
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
const fireworks::Context & context() const
Definition: FWEventItem.h:127
virtual bool assertCaloDataSlice()=0
virtual void setCaloData(const fireworks::Context &)=0
virtual void modelChanges(const FWModelIds &, Product *)
virtual void itemBeingDestroyed(const FWEventItem *)
virtual void fillCaloData()=0