CutPlotter.cxx
Go to the documentation of this file.
1 
13 // for bind2 defect
14 #ifdef HAVE_CONFIG_H
15 #include "config.h"
16 #endif
17 
18 // for truncation warning
19 #ifdef _MSC_VER
20 #include "msdevstudio/MSconfig.h"
21 #endif
22 
23 #include "CutPlotter.h"
24 
25 #include "CompositePlotter.h"
26 
27 #include "datareps/DataRep.h"
28 
29 #include "datasrcs/DataSource.h"
30 #include "datasrcs/TupleCut.h"
31 
33 
34 #include "reps/CutRangeRep.h"
35 #include "reps/ColorBoxPointRep.h"
36 
37 #include <algorithm>
38 #include <functional>
39 
40 #include <cassert>
41 
42 using std::list;
43 using std::mem_fun;
44 using std::swap;
45 using std::string;
46 using std::vector;
47 
48 using namespace hippodraw;
49 
51 CutPlotter ( const std::string & name )
52  : XyPlotter( name )//,
53 {
54 }
55 
57  : XyPlotter ( plotter )
58 {
59 }
60 
62 {
64 }
65 
70 void
72 setAxisBinding ( const std::vector < std::string > & bindings )
73 {
74  DataRep * datarep = selectedDataRep ();
75  ProjectorBase * pbase = datarep->getProjector ();
76  NTupleProjector * projector = dynamic_cast < NTupleProjector * > ( pbase );
77 
78  projector->setAxisBindings ( bindings );
79 
80  autoScale ();
81 
82  const vector < TupleCut > & cuts = m_datarep -> getCuts ();
83  vector < TupleCut > & cut_list
84  = const_cast < vector < TupleCut > & > ( cuts );
85 
86  unsigned int size = bindings.size ();
87  for ( unsigned int i = 0; i < size; i++ ) {
88  const string & label = bindings[i];
89  unsigned int index = projector -> indexOf ( label );
90  TupleCut & cut = cut_list[i]; // so Doxygen can find it
91  cut.setColumn ( index );
92  cut.setLabel ( label );
93  }
94 
95  updateTargets();
96 }
97 
98 void
100 setCutRangeAt ( const Range & range, unsigned int index )
101 {
102  m_datarep -> setCutRangeAt ( range, index );
103 
104  updateTargets ();
105 }
106 
107 void
109 setCutRange ( double low, double high )
110 {
111  const Range range ( low, high );
112  setCutRangeAt ( range, 0 );
113 }
114 
115 void
118 {
119  // Does not remove rep from m_targets because that would invalidate
120  // iterators in the function removeFromTargets().
121  ProjectorBase * proj = rep->getProjector ();
122  NTupleProjector * projector =
123  dynamic_cast < NTupleProjector * > ( proj );
124  assert( projector );
125 
126  const vector < TupleCut > & cuts = m_datarep -> getCuts ();
127  for ( unsigned int i = 0; i < cuts.size(); i++ ) {
128  projector -> removeCut( & cuts[i] );
129  }
130  rep -> removeObserver( this );
131 
132  TargetList_t::iterator first
133  = find ( m_targets.begin(), m_targets.end(), rep );
134  assert ( first != m_targets.end() );
135  m_targets.erase ( first );
136 
137  rep -> setDirty();
138 }
139 
140 void
143 {
144  TargetList_t::const_iterator first = m_targets.begin();
145  while ( first != m_targets.end() ) {
146  DataRep * rep = *first++;
147  removeFromTarget ( rep );
148  }
149 
150  assert ( m_targets.empty () );
151 }
152 
153 void
155 willDelete ( const Observable * obs )
156 {
157  const DataRep * rep = dynamic_cast < const DataRep * > ( obs );
158  assert ( rep ); // only observes DataRep objects
159 
160  TargetList_t::iterator first
161  = find ( m_targets.begin(), m_targets.end(), rep );
162 
163  if ( first == m_targets.end () ) return; // not a target
164 
165  m_targets.erase ( first );
166 }
167 
169 {
170 #ifdef BIND2ND_DEFECT
171  TargetList_t::iterator first = m_targets.begin();
172  while ( first != m_targets.end() )
173  {
174  DataRep * rep = *first++;
175  rep->setDirty ( true );
176  }
177 #else
178 #ifdef MEMFUN1_DEFECT
179  for_each ( m_targets.begin(), m_targets.end(),
180  bind2nd ( mem_fun1 ( &DataRep::setDirty ), true ) );
181 #else
182  for_each ( m_targets.begin(), m_targets.end(),
183  bind2nd ( mem_fun ( &DataRep::setDirty ), true ) );
184 #endif
185 #endif
186  notifyObservers ();
187 }
188 
189 const vector < TupleCut > &
191 getCuts () const
192 {
193  return m_datarep -> getCuts ();
194 }
195 
196 void
197 CutPlotter::setCuts ( const std::vector < const TupleCut * > & new_cuts )
198 {
199  unsigned int size = new_cuts.size ();
200 
201  if ( m_datarep ) {
202  const vector < TupleCut > & cuts = m_datarep -> getCuts ();
203  vector < TupleCut > & cut_list
204  = const_cast < vector < TupleCut > & > ( cuts );
205  cut_list.resize ( size, TupleCut () );
206  for ( unsigned int i = 0; i < cut_list.size (); i++ ) {
207  cut_list[i] = *new_cuts[i];
208  }
209  }
210 }
211 
212 /* virtual */
214 {
215  return true;
216 }
217 
219 {
220  m_targets.clear();
221 }
222 
224 {
225  if ( rep != m_datarep ) {
226  m_targets.push_back ( rep );
227  rep->addObserver ( this );
228  }
229 }
230 
231 const list < DataRep * > & CutPlotter::getCutTargets () const
232 {
233  return m_targets;
234 }
235 
236 bool CutPlotter::
237 isTarget ( DataRep * rep ) const
238 {
239  return find ( m_targets.begin(), m_targets.end(), rep ) != m_targets.end();
240 }
241 
242 void CutPlotter::setCutColor ( const Color & color )
243 {
244  RepBase * rep = m_datarep -> getCutRep ();
245  rep -> setColor ( color );
246 
248 
249  notifyObservers ();
250 }
251 
253 {
254  RepBase * rep = m_datarep -> getCutRep ();
255 
256  return rep -> getColor ();
257 }
258 
259 void CutPlotter::setNTuple ( const DataSource * ntuple )
260 {
261  DataRep * datarep = selectedDataRep ();
262  ProjectorBase * pbase = datarep->getProjector ();
263  NTupleProjector * projector = dynamic_cast < NTupleProjector * > ( pbase );
264 
265  projector->setNTuple ( ntuple );
266  DataSource * nt = const_cast < DataSource * > ( ntuple );
267  nt->addObserver ( projector );
268 }
269 
270 void
272 setEnabled ( bool yes )
273 {
274  bool no = false;
275 
276  const vector < TupleCut > & cuts = m_datarep -> getCuts ();
277  for ( unsigned int i = 0; i < cuts.size(); i++ ) {
278  no |= cuts[i].isEnabled ();
279  m_datarep -> setEnabled ( i, yes );
280  }
281 
282  if ( yes != no ) {
283  updateTargets ();
284  }
285 }
286 
287 void
289 update ( const Observable * object )
290 {
291  TargetList_t::const_iterator first
292  = find ( m_targets.begin(), m_targets.end(), object );
293 
294  if ( first == m_targets.end () ) {
295  notifyObservers ();
296  }
297 }
298 
299 void
301 setActive ( bool yes )
302 {
303  RepBase * rep = m_datarep -> getCutRep ();
304  rep -> setSelected ( yes );
305  notifyObservers ();
306 }
307 
308 void
311 {
312 }
313 
314 bool
317 {
318  return false;
319 }

Generated for HippoDraw Class Library by doxygen