QtCut.cxx

Go to the documentation of this file.
00001 
00012 // For truncation warning
00013 #ifdef _MSC_VER
00014 #include "msdevstudio/MSconfig.h"
00015 #endif
00016 
00017 #ifdef HAVE_CONFIG_H
00018 #include "config.h"
00019 #endif
00020 
00021 // include first to avoid _POSIX_C_SOURCE warning.
00022 #include <boost/python.hpp>
00023 
00024 #include "QtCut.h"
00025 
00026 #include "PyApp.h"
00027 #include "PyDataSource.h"
00028 
00029 #include "controllers/CutController.h"
00030 #include "datasrcs/TupleCut.h"
00031 #include "datasrcs/NTupleController.h"
00032 #include "fits/FitsController.h"
00033 #include "plotters/CutPlotter.h"
00034 
00035 using std::string;
00036 using std::vector;
00037 
00038 using namespace hippodraw;
00039 
00040 void
00041 QtCut::
00042 createCut ( const DataSource & nt,
00043             const std::vector < std::string > & binding )
00044 {
00045   CutController * controller = CutController::instance ();
00046   const Color yellow ( Color::yellow );
00047   m_plotter = controller -> createCut ( std::string(), &nt, binding, yellow );
00048 }
00049 
00050 QtCut::
00051 QtCut ( const DataSource & nt, 
00052         const std::vector< std::string > & binding,
00053         QtDisplay * target, double low, double high  )
00054    : QtDisplay ( )
00055 {
00056   PyApp::lock ();
00057   createCut ( nt, binding );
00058 
00059   addTarget ( target );
00060   setCutRange ( low, high, "x" );
00061   PyApp::unlock ();
00062 }
00063 
00064 QtCut::
00065 QtCut ( const PyDataSource & ds, 
00066         const std::vector< std::string > & binding,
00067         QtDisplay * target, double low, double high  )
00068    : QtDisplay ( )
00069 {
00070   PyApp::lock ();
00071   createCut ( ds.dataSource(), binding );
00072 
00073   addTarget ( target );
00074   setCutRange ( low, high, "x" );
00075   PyApp::unlock ();
00076 }
00077 
00078 QtCut::
00079 QtCut ( PyDataSource & source,
00080         const std::string & label,
00081         boost::python::numeric::array array,
00082         QtDisplay * target )
00083 {
00084 #ifdef HAVE_NUMARRAY
00085   PyApp::lock ();
00086 
00087   source.saveColumnFromNumArray ( label, array );
00088   vector < string > binding;
00089   binding.push_back ( label );
00090   createCut ( source.dataSource (), binding );
00091   addTarget ( target );
00092   setCutRange ( 0.9, 1.1, "x" );
00093 
00094   PyApp::unlock ();
00095 #else
00096   std::runtime_error e ( "HippoDraw was not built with "
00097                        "numeric Python support" );
00098   throw e;
00099 
00100 #endif // HAVE_NUMARRAY
00101 }
00102 
00103 QtCut::
00104 QtCut ( const DataSource & nt, 
00105         const std::vector< std::string > & binding )
00106    : QtDisplay ( )
00107 {
00108   PyApp::lock ();
00109   createCut ( nt, binding );
00110   PyApp::unlock ();
00111 }
00112 
00113 QtCut::
00114 QtCut ( const PyDataSource & nt, 
00115         const std::vector< std::string > & binding )
00116    : QtDisplay ( )
00117 {
00118   PyApp::lock ();
00119   createCut ( nt.dataSource (), binding );
00120   PyApp::unlock ();
00121 }
00122 
00123 QtCut::QtCut ( PlotterBase * plotter ) 
00124    : QtDisplay()
00125 {
00126   PyApp::lock ();
00127   CutPlotter * cut_plotter = dynamic_cast < CutPlotter * > ( plotter );
00128   assert ( cut_plotter != 0 );
00129 
00130   m_plotter = plotter;
00131   PyApp::unlock ();
00132 }
00133 
00134 void
00135 QtCut::
00136 addTarget ( QtDisplay * target )
00137 {
00138   PyApp::lock();
00139 
00140   CutController * controller = CutController::instance ();
00141   CutPlotter * cp = dynamic_cast < CutPlotter * > ( m_plotter );
00142   controller -> addCut ( cp, target -> display () );
00143   
00144   PyApp::unlock ();
00145 }
00146 
00147 void QtCut::addTargets ( const std::vector < QtDisplay * > & targets )
00148 {
00149   PyApp::lock();
00150 
00151   CutController * controller = CutController::instance ();
00152   unsigned int size = targets.size ();
00153   CutPlotter * cp = dynamic_cast < CutPlotter * > ( m_plotter );
00154   for ( unsigned int i = 0; i < size; i++ ) {
00155     QtDisplay * target = targets [ i ];
00156     controller -> addCut ( cp, target -> display () );
00157   }
00158   
00159   PyApp::unlock ();
00160 }
00161 
00162 void
00163 QtCut::
00164 setCutRange ( double low, double high, const std::string & axis )
00165 {
00166   hippodraw::Axes::Type type = hippodraw::Axes::convert( axis );
00167 
00168   PyApp::lock();
00169   
00170   CutPlotter * cut_plotter = dynamic_cast < CutPlotter * > ( m_plotter );
00171   assert ( cut_plotter != 0 );
00172 
00173   const Range range ( low, high );
00174   try {
00175     cut_plotter -> setCutRangeAt ( range, type );    
00176   PyApp::unlock ();
00177   }
00178   catch ( const std::out_of_range &  ) { // if axis is wrong
00179     PyApp::unlock ();
00180     string what ( "Cut range axis `" );
00181     what += axis;
00182     what += "' is invalid";
00183     throw std::runtime_error ( what );
00184   }
00185 }
00186 
00187 
00188 std::vector<double> QtCut::cutRange ()
00189 {
00190   PyApp::lock();
00191 
00192   std::vector<double> myCutRange;
00193   vector < const TupleCut * > cuts;
00194   m_plotter -> fillCutList ( cuts );
00195 
00196   for ( unsigned int i = 0; i < cuts.size(); i++ ) {
00197     const TupleCut * cut = cuts [ i ];
00198     const Range & range = cut -> getRange ();
00199     myCutRange.push_back ( range.low () );
00200     myCutRange.push_back ( range.high () );
00201   }
00202   PyApp::unlock ();
00203 
00204   return myCutRange;
00205 }
00206 
00207 void
00208 QtCut::
00209 setEnabled ( bool yes )
00210 {
00211   PyApp::lock();
00212   CutPlotter * plotter = dynamic_cast < CutPlotter * > ( m_plotter );
00213   plotter -> setEnabled ( yes );
00214   PyApp::unlock ();
00215 }
00216 
00217 void
00218 QtCut::
00219 toggleInverted ()
00220 {
00221   PyApp::lock();
00222   CutPlotter * plotter = dynamic_cast < CutPlotter * > ( m_plotter );
00223   plotter -> toggleInverted ();
00224   PyApp::unlock ();
00225 }
00226 
00227 NTuple *
00228 QtCut::
00229 createNTuple ( const std::vector < std::string > & column_list,
00230                const std::vector < QtCut * > & cut_list, 
00231                DataSource * ds )
00232 {
00233 
00234   PyApp::lock();
00235 
00236   std::vector < const TupleCut * > tuple_cut_list;
00237   std::vector < QtCut * >::const_iterator it = cut_list.begin();
00238   
00239   // QtCut list to TupleCut list.
00240   for ( ; it !=cut_list.end(); ++it )
00241     {
00242       QtCut * cut = *it;
00243       cut->m_plotter-> fillCutList ( tuple_cut_list );
00244     }
00245 
00246   NTupleController * ntc = NTupleController::instance();
00247   NTuple * nt = ntc->createNTuple ( column_list, tuple_cut_list, ds );
00248 
00249   PyApp::unlock();
00250 
00251   return nt;
00252 
00253 }
00254 
00255 void
00256 QtCut::
00257 createTnt ( const std::vector < std::string > & column_list,
00258             const std::vector < QtCut * > & cut_list, 
00259             DataSource * ds,
00260             const std::string & filename,
00261             const std::string & dsname )
00262 {
00263 
00264   PyApp::lock();
00265 
00266   std::vector < const TupleCut * > tuple_cut_list;
00267   std::vector < QtCut * >::const_iterator it = cut_list.begin();
00268   
00269   // QtCut list to TupleCut list.
00270   for ( ; it !=cut_list.end(); ++it )
00271     {
00272       QtCut * cut = *it;
00273       cut->m_plotter-> fillCutList ( tuple_cut_list );
00274     }
00275 
00276   NTupleController * ntc = NTupleController::instance();
00277   
00278   // Need to do something with retval.
00279   // int retval =
00280   ntc->createNTupleToFile(column_list, tuple_cut_list, ds, filename, dsname);
00281 
00282   PyApp::unlock();
00283 
00284 }
00285 
00286 void
00287 QtCut::
00288 createFits ( const std::vector < std::string > & column_list,
00289             const std::vector < QtCut * > & cut_list, 
00290             DataSource * ds,
00291             const std::string & filename,
00292             const std::string & dsname )
00293 {
00294 #ifdef HAVE_CFITSIO
00295   PyApp::lock();
00296 
00297   std::vector < const TupleCut * > tuple_cut_list;
00298   std::vector < QtCut * >::const_iterator it = cut_list.begin();
00299   
00300   // QtCut list to TupleCut list.
00301   for ( ; it !=cut_list.end(); ++it )
00302     {
00303       QtCut * cut = *it;
00304       cut->m_plotter-> fillCutList ( tuple_cut_list );
00305     }
00306 
00307   FitsController * fc = FitsController::instance();
00308   
00309   // Need to do something with retval.
00310   // int retval =
00311   fc -> writeNTupleToFile(ds, filename, dsname, column_list, tuple_cut_list );
00312 
00313   PyApp::unlock();
00314 #else
00315   std::string what ( "Sorry, can not create FITS file.  hippo module was not "
00316                 "built with optional FITS support" );
00317   throw std::runtime_error ( what );
00318 #endif
00319 
00320 }
00321 
00322 void
00323 QtCut::
00324 fillCutList ( std::vector <  const TupleCut *> & tuple_cut_list,
00325               const std::vector < QtCut * > & cut_list )
00326 {
00327   std::vector < QtCut * >::const_iterator it = cut_list.begin();
00328   for ( ; it !=cut_list.end(); ++it )
00329     {
00330       QtCut * cut = *it;
00331       cut -> m_plotter-> fillCutList ( tuple_cut_list );
00332     }
00333 }

Generated for HippoDraw Class Library by doxygen