PyFitsController.cxx
Go to the documentation of this file.
1 
12 #ifdef HAVE_CONFIG_H
13 #include "config.h"
14 #endif
15 
16 #include "PyFitsController.h"
17 
18 #include "PyApp.h"
19 #include "PyDataSource.h"
20 #include "QtCut.h"
21 
22 #include "fits/FitsController.h"
23 #include "fits/FitsNTuple.h"
24 
25 #include <stdexcept>
26 
27 using std::runtime_error;
28 using std::vector;
29 
30 using namespace hippodraw;
31 
34 
35 
38 {
39 }
40 
47 {
48  if ( s_instance == 0 ) {
51  }
52 
53  return s_instance;
54 }
55 
56 FitsNTuple *
58 createNTuple ( const std::string & filename, const std::string & hduname )
59 {
60  FitsNTuple * ftuple = 0;
61 
62  try {
63  DataSource * ntuple = m_instance -> createNTuple ( filename, hduname );
64  ftuple = dynamic_cast < FitsNTuple * > ( ntuple );
65  }
66  catch ( const runtime_error & e ) {
67  throw e;
68  }
69  return ftuple;
70 }
71 
74 createDataArray ( const std::string & filename, const std::string & hduname )
75 {
76 #ifdef HAVE_NUMARRAY
77  FitsNTuple * tuple = createNTuple ( filename, hduname );
78  PyDataSource * ds = new PyDataSource ( "FitsNTuple", tuple );
79  return ds;
80 #else
81  runtime_error e ( "HippoDraw was not built with numeric Python support" );
82  throw e;
83 #endif
84 }
85 
86 void
88 writeToFile ( const DataSource * source, const std::string & filename )
89 {
90  // Need lock because on multi-cpu machine, GUI thread maybe trying
91  // to display something based on this source.
92  PyApp::lock();
93  m_instance -> writeNTupleToFile ( source, filename );
94  PyApp::unlock ();
95 }
96 
97 void
99 writeToFile ( const PyDataSource * source, const std::string & filename )
100 {
101  const DataSource & data = source -> dataSource ();
102  writeToFile ( & data, filename );
103 }
104 
105 void
107 writeToFile ( const DataSource * source,
108  const std::string & filename,
109  const std::vector < QtCut * > & cut_list,
110  const std::vector < std::string > & column_list )
111 {
112  // Need lock because on multi-cpu machine, GUI thread maybe trying
113  // to display something based on this source.
114  PyApp::lock ();
115  vector < const TupleCut * > tuple_cut_list;
116  QtCut::fillCutList ( tuple_cut_list, cut_list );
117 
118  // Need to do something with retval.
119  // int retval =
120  const std::string & title = source -> title ();
121 
122  m_instance -> writeNTupleToFile ( source, filename, title,
123  column_list, tuple_cut_list );
124  PyApp::unlock ();
125 }
126 
127 void
129 writeToFile ( const PyDataSource * array,
130  const std::string & filename,
131  const std::vector < QtCut * > & cut_list,
132  const std::vector < std::string > & column_list )
133 {
134  const DataSource & source = array -> dataSource ();
135  writeToFile ( & source, filename, cut_list, column_list );
136 }
137 
138 const std::vector < std::string > &
140 getNTupleNames ( const std::string & filename )
141 {
142  try {
143  const std::vector< std::string > & names
144  = m_instance -> getNTupleNames ( filename );
145  return names;
146  }
147  catch ( const runtime_error & e ) {
148  throw e;
149  }
150  static const std::vector < std::string > names;
151 
152  return names;
153 }

Generated for HippoDraw Class Library by doxygen