00001 00012 #include "QtRootController.h" 00013 00014 #include "RootController.h" 00015 #include "QtRootNTuple.h" 00016 00017 #include "datasrcs/DataSourceController.h" 00018 #include "datasrcs/DataSourceException.h" 00019 #include "python/PyDataSource.h" 00020 00021 #include <qapplication.h> 00022 00023 RootController * QtRootController::m_instance = 0; 00024 QtRootController * QtRootController::s_instance = 0; 00025 00026 QtRootController:: 00027 QtRootController() 00028 { 00029 } 00030 00031 QtRootController * 00032 QtRootController:: 00033 instance () 00034 { 00035 if ( s_instance == 0 ) { 00036 s_instance = new QtRootController (); 00037 m_instance = RootController::instance (); 00038 } 00039 00040 return s_instance; 00041 } 00042 00043 DataSource * 00044 QtRootController:: 00045 createNTuple ( const std::string & filename, const std::string & treename ) 00046 { 00047 if ( qApp ) qApp -> lock (); 00048 00049 std::string ds_name = filename; 00050 ds_name += ": "; 00051 ds_name += treename; 00052 00053 DataSourceController * controller = DataSourceController::instance(); 00054 DataSource * ntuple = controller -> getDataSource ( ds_name ); 00055 00056 if ( ntuple == 0 ) { 00057 TTree * tree = m_instance -> getTree ( filename, treename ); 00058 QtRootNTuple * rtuple = new QtRootNTuple ( tree ); 00059 ntuple = rtuple; 00060 ntuple -> setTitle ( treename ); 00061 00062 ntuple -> setName ( ds_name ); 00063 controller -> registerNTuple ( ntuple ); 00064 controller -> registerDataSourceFile ( ntuple ); 00065 } 00066 00067 if ( qApp ) qApp -> unlock (); 00068 00069 return ntuple; 00070 } 00071 00072 #ifdef HAVE_NUMARRAY 00073 PyDataSource * 00074 QtRootController:: 00075 createDataArray ( const std::string & filename, const std::string & treename ) 00076 { 00077 DataSource * rtuple = createNTuple ( filename, treename ); 00078 PyDataSource * ds = new PyDataSource ( "RootNTuple", rtuple ); 00079 00080 return ds; 00081 } 00082 #endif 00083 00084 const std::vector < std::string > & 00085 QtRootController:: 00086 getNTupleNames ( const std::string & filename ) 00087 { 00088 if ( qApp ) qApp -> lock (); 00089 try { 00090 const std::vector< std::string > & names 00091 = m_instance -> getNTupleNames ( filename ); 00092 if ( qApp ) qApp -> unlock (); 00093 00094 return names; 00095 } 00096 catch ( const DataSourceException & e ) { 00097 if ( qApp ) qApp -> unlock (); 00098 throw e; 00099 } 00100 static const std::vector < std::string > names; 00101 00102 return names; 00103 }