00001
00012 #ifdef HAVE_CONFIG_H
00013 #include "config.h"
00014 #endif
00015
00016 #include "PyFitsController.h"
00017
00018 #include "PyApp.h"
00019 #include "PyDataSource.h"
00020 #include "QtCut.h"
00021
00022 #include "fits/FitsController.h"
00023 #include "fits/FitsNTuple.h"
00024
00025 #include <stdexcept>
00026
00027 using std::runtime_error;
00028 using std::vector;
00029
00030 using namespace hippodraw;
00031
00032 FitsController * PyFitsController::m_instance = 0;
00033 PyFitsController * PyFitsController::s_instance = 0;
00034
00035
00036 PyFitsController::
00037 PyFitsController()
00038 {
00039 }
00040
00044 PyFitsController *
00045 PyFitsController::
00046 instance ()
00047 {
00048 if ( s_instance == 0 ) {
00049 s_instance = new PyFitsController ();
00050 m_instance = FitsController::instance ();
00051 }
00052
00053 return s_instance;
00054 }
00055
00056 FitsNTuple *
00057 PyFitsController::
00058 createNTuple ( const std::string & filename, const std::string & hduname )
00059 {
00060 FitsNTuple * ftuple = 0;
00061
00062 try {
00063 DataSource * ntuple = m_instance -> createNTuple ( filename, hduname );
00064 ftuple = dynamic_cast < FitsNTuple * > ( ntuple );
00065 }
00066 catch ( const runtime_error & e ) {
00067 throw e;
00068 }
00069 return ftuple;
00070 }
00071
00072 PyDataSource *
00073 PyFitsController::
00074 createDataArray ( const std::string & filename, const std::string & hduname )
00075 {
00076 #ifdef HAVE_NUMARRAY
00077 FitsNTuple * tuple = createNTuple ( filename, hduname );
00078 PyDataSource * ds = new PyDataSource ( "FitsNTuple", tuple );
00079 return ds;
00080 #else
00081 runtime_error e ( "HippoDraw was not built with numeric Python support" );
00082 throw e;
00083 #endif
00084 }
00085
00086 void
00087 PyFitsController::
00088 writeToFile ( const DataSource * source, const std::string & filename )
00089 {
00090
00091
00092 PyApp::lock();
00093 m_instance -> writeNTupleToFile ( source, filename );
00094 PyApp::unlock ();
00095 }
00096
00097 void
00098 PyFitsController::
00099 writeToFile ( const PyDataSource * source, const std::string & filename )
00100 {
00101 const DataSource & data = source -> dataSource ();
00102 writeToFile ( & data, filename );
00103 }
00104
00105 void
00106 PyFitsController::
00107 writeToFile ( const DataSource * source,
00108 const std::string & filename,
00109 const std::vector < QtCut * > & cut_list,
00110 const std::vector < std::string > & column_list )
00111 {
00112
00113
00114 PyApp::lock ();
00115 vector < const TupleCut * > tuple_cut_list;
00116 QtCut::fillCutList ( tuple_cut_list, cut_list );
00117
00118
00119
00120 const std::string & title = source -> title ();
00121
00122 m_instance -> writeNTupleToFile ( source, filename, title,
00123 column_list, tuple_cut_list );
00124 PyApp::unlock ();
00125 }
00126
00127 void
00128 PyFitsController::
00129 writeToFile ( const PyDataSource * array,
00130 const std::string & filename,
00131 const std::vector < QtCut * > & cut_list,
00132 const std::vector < std::string > & column_list )
00133 {
00134 const DataSource & source = array -> dataSource ();
00135 writeToFile ( & source, filename, cut_list, column_list );
00136 }
00137
00138 const std::vector < std::string > &
00139 PyFitsController::
00140 getNTupleNames ( const std::string & filename )
00141 {
00142 try {
00143 const std::vector< std::string > & names
00144 = m_instance -> getNTupleNames ( filename );
00145 return names;
00146 }
00147 catch ( const runtime_error & e ) {
00148 throw e;
00149 }
00150 static const std::vector < std::string > names;
00151
00152 return names;
00153 }