00001
00012 #ifdef HAVE_CONFIG_H
00013 #include "config.h"
00014 #endif
00015
00016
00017 #ifdef _MSC_VER
00018 #include "msdevstudio/MSconfig.h"
00019 #endif
00020
00021 #include "QtRootNTuple.h"
00022
00023 #include "RootDataType.h"
00024
00025 #include "datasrcs/DataSourceException.h"
00026
00027 #ifdef HAVE_NUMARRAY
00028 #include "numarray/num_util.h"
00029 #endif
00030
00031 #include "qapplication.h"
00032
00033 #include <utility>
00034
00035 using std::string;
00036 using std::vector;
00037
00038
00039 QtRootNTuple::
00040 QtRootNTuple ( TTree * tree )
00041 : RootNTuple ( tree )
00042 {
00043 }
00044
00045 QtRootNTuple::
00046 QtRootNTuple ( )
00047 : RootNTuple ( )
00048 {
00049 }
00050
00051 unsigned int
00052 QtRootNTuple::
00053 rows ()
00054 {
00055 if ( qApp ) qApp -> lock ();
00056 unsigned int rows = RootNTuple::rows ();
00057 if ( qApp ) qApp -> unlock ();
00058
00059 return rows;
00060 }
00061
00062 unsigned int
00063 QtRootNTuple::
00064 columns ()
00065 {
00066
00067 return RootNTuple::columns ();
00068 }
00069
00070 const vector < double > &
00071 QtRootNTuple::
00072 getColumn ( const std::string & name ) const
00073 {
00074 static vector < double > temp;
00075 if ( qApp ) qApp -> lock ();
00076 try {
00077 const vector < double > & column = RootNTuple::getColumn ( name );
00078 if ( qApp ) qApp -> unlock ();
00079
00080 return column;
00081 }
00082 catch ( const DataSourceException e ) {
00083 if ( qApp ) qApp -> unlock ();
00084 throw e;
00085 }
00086 return temp;
00087 }
00088
00089 const vector < double > &
00090 QtRootNTuple::
00091 getColumn ( const std::string & name,
00092 const std::vector < int > & indexes ) const
00093 {
00094 static vector < double > temp;
00095 if ( qApp ) qApp -> lock ();
00096 try {
00097 const vector < double > & column
00098 = RootNTuple::getColumn ( name, indexes );
00099 if ( qApp ) qApp -> unlock ();
00100
00101 return column;
00102 }
00103 catch ( const DataSourceException e ) {
00104 if ( qApp ) qApp -> unlock ();
00105 throw e;
00106 }
00107 return temp;
00108 }
00109
00110 const vector < double > &
00111 QtRootNTuple::
00112 getColumn ( unsigned int index ) const
00113 {
00114 static vector < double > temp;
00115 if ( qApp ) qApp -> lock ();
00116 try {
00117 const vector < double > & column = RootNTuple::getColumn ( index );
00118 if ( qApp ) qApp -> unlock ();
00119 return column;
00120 }
00121 catch ( const DataSourceException & e ) {
00122 if ( qApp ) qApp -> unlock ();
00123 throw e;
00124 }
00125
00126 return temp;
00127 }
00128
00129 int
00130 QtRootNTuple::
00131 addColumn ( const std::string & label,
00132 const std::vector < double > & column )
00133 {
00134 return RootNTuple::addColumn ( label, column );
00135 }
00136
00137 const std::vector < std::string > &
00138 QtRootNTuple::
00139 getLabels () const
00140 {
00141
00142 return RootNTuple::getLabels ();
00143 }
00144
00145 bool
00146 QtRootNTuple::
00147 isMultiDimensional ( const std::string & column ) const
00148 {
00149 if ( qApp ) qApp -> lock ();
00150 try {
00151 bool yes = RootNTuple::isMultiDimensional ( column );
00152 if ( qApp ) qApp -> unlock ();
00153 return yes;
00154 }
00155 catch ( const DataSourceException & e ) {
00156 if ( qApp ) qApp -> unlock ();
00157 throw e;
00158 }
00159 }
00160
00161 const std::vector < int > &
00162 QtRootNTuple::
00163 rowDataDimSize ( const std::string & column ) {
00164 if ( qApp ) qApp -> lock ();
00165 try {
00166 const vector < int > & dims = RootNTuple::rowDataDimSize ( column );
00167 if ( qApp ) qApp -> unlock ();
00168 return dims;
00169 }
00170 catch ( const DataSourceException & e ) {
00171 if ( qApp ) qApp -> unlock ();
00172 throw e;
00173 }
00174 }
00175
00176 void
00177 QtRootNTuple::
00178 expandIfNeeded ( const std::vector < std::string > & labels ) const
00179 {
00180 RootNTuple::expandIfNeeded ( labels );
00181 }
00182
00183 std::string
00184 QtRootNTuple::
00185 createBinding ( const std::string & name,
00186 const std::vector < int > & indices ) const
00187 {
00188 return RootNTuple::createBinding ( name, indices );
00189 }
00190
00191
00192 using namespace hippodraw;
00193
00194 #ifdef HAVE_NUMARRAY
00195 using namespace boost::python;
00196
00197 numeric::array
00198 QtRootNTuple::
00199 valueAt ( unsigned int row, const std::string & variable )
00200 {
00201 RootNTuple::throwIfInvalidLabel ( variable );
00202 int column = RootNTuple::indexOf ( variable );
00203 vector < int > shape = RootNTuple::getColumnShape ( column );
00204
00205 RootData::Type type = RootNTuple::getType ( column );
00206 switch ( type ) {
00207 case RootData::Double:
00208 {
00209 double * array =RootNTuple::doubleArrayAt ( row, column );
00210 numeric::array na = num_util::makeNum ( array, shape );
00211 return na;
00212 }
00213 break;
00214 case RootData::Float:
00215 {
00216 float * array = RootNTuple::floatArrayAt ( row, column );
00217 numeric::array na = num_util::makeNum ( array, shape );
00218 return na;
00219 }
00220 break;
00221 case RootData::Int:
00222 {
00223 int * array = RootNTuple::intArrayAt ( row, column );
00224 numeric::array na = num_util::makeNum ( array, shape );
00225 return na;
00226 }
00227 break;
00228 default:
00229 assert ( false );
00230 break;
00231 }
00232 return num_util::makeNum ( 1, PyArray_DOUBLE );
00233 }
00234 #endif