QtCut.cxx
Go to the documentation of this file.
1 
12 // For truncation warning
13 #ifdef _MSC_VER
14 #include "msdevstudio/MSconfig.h"
15 #endif
16 
17 #ifdef HAVE_CONFIG_H
18 #include "config.h"
19 #endif
20 
21 // include first to avoid _POSIX_C_SOURCE warning.
22 #include <boost/python.hpp>
23 
24 #include "QtCut.h"
25 
26 #include "PyApp.h"
27 #include "PyDataSource.h"
28 
30 #include "datasrcs/TupleCut.h"
32 #include "fits/FitsController.h"
33 #include "plotters/CutPlotter.h"
34 
35 using std::string;
36 using std::vector;
37 
38 using namespace hippodraw;
39 
40 void
41 QtCut::
42 createCut ( const DataSource & nt,
43  const std::vector < std::string > & binding )
44 {
45  CutController * controller = CutController::instance ();
46  const Color yellow ( Color::yellow );
47  m_plotter = controller -> createCut ( std::string(), &nt, binding, yellow );
48 }
49 
50 QtCut::
51 QtCut ( const DataSource & nt,
52  const std::vector< std::string > & binding,
53  QtDisplay * target, double low, double high )
54  : QtDisplay ( )
55 {
56  PyApp::lock ();
57  createCut ( nt, binding );
58 
59  addTarget ( target );
60  setCutRange ( low, high, "x" );
61  PyApp::unlock ();
62 }
63 
64 QtCut::
65 QtCut ( const PyDataSource & ds,
66  const std::vector< std::string > & binding,
67  QtDisplay * target, double low, double high )
68  : QtDisplay ( )
69 {
70  PyApp::lock ();
71  createCut ( ds.dataSource(), binding );
72 
73  addTarget ( target );
74  setCutRange ( low, high, "x" );
75  PyApp::unlock ();
76 }
77 
78 QtCut::
79 QtCut ( PyDataSource & source,
80  const std::string & label,
81  boost::python::numeric::array array,
82  QtDisplay * target )
83 {
84 #ifdef HAVE_NUMARRAY
85  PyApp::lock ();
86 
87  source.saveColumnFromNumArray ( label, array );
88  vector < string > binding;
89  binding.push_back ( label );
90  createCut ( source.dataSource (), binding );
91  addTarget ( target );
92  setCutRange ( 0.9, 1.1, "x" );
93 
94  PyApp::unlock ();
95 #else
96  std::runtime_error e ( "HippoDraw was not built with "
97  "numeric Python support" );
98  throw e;
99 
100 #endif // HAVE_NUMARRAY
101 }
102 
103 QtCut::
104 QtCut ( const DataSource & nt,
105  const std::vector< std::string > & binding )
106  : QtDisplay ( )
107 {
108  PyApp::lock ();
109  createCut ( nt, binding );
110  PyApp::unlock ();
111 }
112 
113 QtCut::
114 QtCut ( const PyDataSource & nt,
115  const std::vector< std::string > & binding )
116  : QtDisplay ( )
117 {
118  PyApp::lock ();
119  createCut ( nt.dataSource (), binding );
120  PyApp::unlock ();
121 }
122 
123 QtCut::QtCut ( PlotterBase * plotter )
124  : QtDisplay()
125 {
126  PyApp::lock ();
127  CutPlotter * cut_plotter = dynamic_cast < CutPlotter * > ( plotter );
128  assert ( cut_plotter != 0 );
129 
130  m_plotter = plotter;
131  PyApp::unlock ();
132 }
133 
134 void
135 QtCut::
136 addTarget ( QtDisplay * target )
137 {
138  PyApp::lock();
139 
140  CutController * controller = CutController::instance ();
141  CutPlotter * cp = dynamic_cast < CutPlotter * > ( m_plotter );
142  controller -> addCut ( cp, target -> display () );
143 
144  PyApp::unlock ();
145 }
146 
147 void QtCut::addTargets ( const std::vector < QtDisplay * > & targets )
148 {
149  PyApp::lock();
150 
151  CutController * controller = CutController::instance ();
152  unsigned int size = targets.size ();
153  CutPlotter * cp = dynamic_cast < CutPlotter * > ( m_plotter );
154  for ( unsigned int i = 0; i < size; i++ ) {
155  QtDisplay * target = targets [ i ];
156  controller -> addCut ( cp, target -> display () );
157  }
158 
159  PyApp::unlock ();
160 }
161 
162 void
163 QtCut::
164 setCutRange ( double low, double high, const std::string & axis )
165 {
167 
168  PyApp::lock();
169 
170  CutPlotter * cut_plotter = dynamic_cast < CutPlotter * > ( m_plotter );
171  assert ( cut_plotter != 0 );
172 
173  const Range range ( low, high );
174  try {
175  cut_plotter -> setCutRangeAt ( range, type );
176  PyApp::unlock ();
177  }
178  catch ( const std::out_of_range & ) { // if axis is wrong
179  PyApp::unlock ();
180  string what ( "Cut range axis `" );
181  what += axis;
182  what += "' is invalid";
183  throw std::runtime_error ( what );
184  }
185 }
186 
187 
188 std::vector<double> QtCut::cutRange ()
189 {
190  PyApp::lock();
191 
192  std::vector<double> myCutRange;
193  vector < const TupleCut * > cuts;
194  m_plotter -> fillCutList ( cuts );
195 
196  for ( unsigned int i = 0; i < cuts.size(); i++ ) {
197  const TupleCut * cut = cuts [ i ];
198  const Range & range = cut -> getRange ();
199  myCutRange.push_back ( range.low () );
200  myCutRange.push_back ( range.high () );
201  }
202  PyApp::unlock ();
203 
204  return myCutRange;
205 }
206 
207 void
208 QtCut::
209 setEnabled ( bool yes )
210 {
211  PyApp::lock();
212  CutPlotter * plotter = dynamic_cast < CutPlotter * > ( m_plotter );
213  plotter -> setEnabled ( yes );
214  PyApp::unlock ();
215 }
216 
217 void
218 QtCut::
220 {
221  PyApp::lock();
222  CutPlotter * plotter = dynamic_cast < CutPlotter * > ( m_plotter );
223  plotter -> toggleInverted ();
224  PyApp::unlock ();
225 }
226 
227 NTuple *
228 QtCut::
229 createNTuple ( const std::vector < std::string > & column_list,
230  const std::vector < QtCut * > & cut_list,
231  DataSource * ds )
232 {
233 
234  PyApp::lock();
235 
236  std::vector < const TupleCut * > tuple_cut_list;
237  std::vector < QtCut * >::const_iterator it = cut_list.begin();
238 
239  // QtCut list to TupleCut list.
240  for ( ; it !=cut_list.end(); ++it )
241  {
242  QtCut * cut = *it;
243  cut->m_plotter-> fillCutList ( tuple_cut_list );
244  }
245 
247  NTuple * nt = ntc->createNTuple ( column_list, tuple_cut_list, ds );
248 
249  PyApp::unlock();
250 
251  return nt;
252 
253 }
254 
255 void
256 QtCut::
257 createTnt ( const std::vector < std::string > & column_list,
258  const std::vector < QtCut * > & cut_list,
259  DataSource * ds,
260  const std::string & filename,
261  const std::string & dsname )
262 {
263 
264  PyApp::lock();
265 
266  std::vector < const TupleCut * > tuple_cut_list;
267  std::vector < QtCut * >::const_iterator it = cut_list.begin();
268 
269  // QtCut list to TupleCut list.
270  for ( ; it !=cut_list.end(); ++it )
271  {
272  QtCut * cut = *it;
273  cut->m_plotter-> fillCutList ( tuple_cut_list );
274  }
275 
277 
278  // Need to do something with retval.
279  // int retval =
280  ntc->createNTupleToFile(column_list, tuple_cut_list, ds, filename, dsname);
281 
282  PyApp::unlock();
283 
284 }
285 
286 void
287 QtCut::
288 createFits ( const std::vector < std::string > & column_list,
289  const std::vector < QtCut * > & cut_list,
290  DataSource * ds,
291  const std::string & filename,
292  const std::string & dsname )
293 {
294 #ifdef HAVE_CFITSIO
295  PyApp::lock();
296 
297  std::vector < const TupleCut * > tuple_cut_list;
298  std::vector < QtCut * >::const_iterator it = cut_list.begin();
299 
300  // QtCut list to TupleCut list.
301  for ( ; it !=cut_list.end(); ++it )
302  {
303  QtCut * cut = *it;
304  cut->m_plotter-> fillCutList ( tuple_cut_list );
305  }
306 
308 
309  // Need to do something with retval.
310  // int retval =
311  fc -> writeNTupleToFile(ds, filename, dsname, column_list, tuple_cut_list );
312 
313  PyApp::unlock();
314 #else
315  std::string what ( "Sorry, can not create FITS file. hippo module was not "
316  "built with optional FITS support" );
317  throw std::runtime_error ( what );
318 #endif
319 
320 }
321 
322 void
323 QtCut::
324 fillCutList ( std::vector < const TupleCut *> & tuple_cut_list,
325  const std::vector < QtCut * > & cut_list )
326 {
327  std::vector < QtCut * >::const_iterator it = cut_list.begin();
328  for ( ; it !=cut_list.end(); ++it )
329  {
330  QtCut * cut = *it;
331  cut -> m_plotter-> fillCutList ( tuple_cut_list );
332  }
333 }

Generated for HippoDraw Class Library by doxygen