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 }
PyNTuple * createNTuple() const
Creates and returns an PyNTuple representing the display.
Definition: QtDisplay.cxx:1147
unsigned int i
static FitsController * instance()
Returns the singleton instance of the FitsController.
double high() const
Returns the maximum of the range object.
Definition: Range.cxx:100
Qt Displays wraps a derived class of Cut1DPlotter.
Definition: QtCut.h:42
static CutController * instance()
Returns the pointer to the singleton instance.
hippodraw::QtCut class interface
int createNTupleToFile(const std::vector< std::string > &column_list, const std::vector< const TupleCut * > &cut_list, DataSource *ds, const std::string &filename, const std::string &dsname)
Create NTuple with column list and cut list and save to a file.
static void lock()
Obtains a lock on the application&#39;s mutex.
Definition: PyApp.cxx:331
void setEnabled(bool yes)
Sets the enabled status.
Definition: QtCut.cxx:209
DataSource * createNTuple(const std::string &filename)
Creates and registers an NTuple from data in file filename.
The class expresses a cut on a DataSource, i.e.
Definition: TupleCut.h:43
return yes
Definition: CanvasView.cxx:883
std::vector< double > cutRange()
Return the range of the cut.
Definition: QtCut.cxx:188
A Color class for creating the color object following the standard RGB color space.
Definition: Color.h:37
QtCut(const DataSource &nt, const std::vector< std::string > &binding)
Create a cut.
Definition: QtCut.cxx:104
hippodraw::PyDataSource class interface
The base class for the PlotterBase hierarchy.
Definition: PlotterBase.h:55
PyArray_TYPES type(numeric::array arr)
Definition: num_util.cpp:249
hippodraw::PyApp class interface.
void saveColumnFromNumArray(const std::string &label, boost::python::numeric::array array)
Replace or add a column from a numarray object, indexing by column label.
A PlotterBase derived class that serves a base class for cut plotters.
Definition: CutPlotter.h:43
hippodraw::FitsController class interface.
A singleton class that is the interface between GUI and the NTuple objects.
PlotterBase * m_plotter
The contained PlotterBase object.
Definition: QtDisplay.h:97
static void createFits(const std::vector< std::string > &column_list, const std::vector< QtCut * > &cut_list, DataSource *ds, const std::string &filename, const std::string &dsname)
Static method.
Definition: QtCut.cxx:288
intp size(numeric::array arr)
Definition: num_util.cpp:296
static void fillCutList(std::vector< const TupleCut * > &tuple_cut_list, const std::vector< QtCut * > &cut_list)
Definition: QtCut.cxx:324
void createCut(const DataSource &ds, const std::vector< std::string > &binding)
Creates an uninitialized cut.
Definition: QtCut.cxx:42
This class is the public interface to a DataSource object that the user sees as the DataArray object ...
Definition: PyDataSource.h:43
static NTupleController * instance()
Returns the pointer to the singleton instance.
PlotterBase * display()
Returns the wrapped display object.
Definition: QtDisplay.cxx:724
A DataSource class implemented with std::vector&lt;double&gt; to store the column data. ...
Definition: NTuple.h:33
hippodraw::TupleCut class interface
hippodraw::CutController class interface
Qt Displays wraps a derived class of PlotterBase.
Definition: QtDisplay.h:71
A Controller class for FITS files.
void addTarget(QtDisplay *)
Adds a display as a target of the cut.
Definition: QtCut.cxx:136
static void createTnt(const std::vector< std::string > &column_list, const std::vector< QtCut * > &cut_list, DataSource *ds, const std::string &filename, const std::string &dsname)
Static method.
Definition: QtCut.cxx:257
static void unlock()
Releases the lock on the application&#39;s mutex.
Definition: PyApp.cxx:357
const DataSource & dataSource() const
Return a reference to the underlying DataSource.
Definition: PyDataSource.h:89
void setCutRange(double low, double high, const std::string &axis="x")
Sets the range of the cut on the chosen axis.
Definition: QtCut.cxx:164
double low() const
Returns the minimum of the range object.
Definition: Range.cxx:87
Expresses a range of values.
Definition: Range.h:33
std::vector< double > getRange(const std::string &axis)
Get the Range of the specified axis.
Definition: QtDisplay.cxx:829
hippodraw::NTupleController class interface
void toggleInverted()
Toggles the inversion status.
Definition: QtCut.cxx:219
Type convert(const std::string &axis)
Converts from string representation ot Axes::Type representation.
Definition: AxesType.cxx:32
A singleton class that handles the application logic for cuts.
Definition: CutController.h:38
list< QAction * >::iterator it
Type
Axes constants.
Definition: AxesType.h:31
void addTargets(const std::vector< QtDisplay * > &targets)
Adds the displays as targets of the cut.
Definition: QtCut.cxx:147
Base class for DataSource.
Definition: DataSource.h:55
hippodraw::CutPlotter class interface

Generated for HippoDraw Class Library by doxygen