[pypy-commit] pypy reflex-support: update benchmark to have a TApplication as per ROOT rules
wlav
noreply at buildbot.pypy.org
Fri Jul 15 17:07:43 CEST 2011
Author: Wim Lavrijsen <WLavrijsen at lbl.gov>
Branch: reflex-support
Changeset: r45636:bacc1bb43dca
Date: 2011-07-15 08:07 -0700
http://bitbucket.org/pypy/pypy/changeset/bacc1bb43dca/
Log: update benchmark to have a TApplication as per ROOT rules
diff --git a/pypy/module/cppyy/bench/Makefile b/pypy/module/cppyy/bench/Makefile
--- a/pypy/module/cppyy/bench/Makefile
+++ b/pypy/module/cppyy/bench/Makefile
@@ -26,4 +26,4 @@
bench02Dict_reflex.so: bench02.h bench02.xml
$(genreflex) bench02.h $(genreflexflags) --selection=bench02.xml -I$(ROOTSYS)/include
- g++ -o $@ bench02.cxx bench02_rflx.cpp -I$(ROOTSYS)/include -shared -lReflex `root-config --libs` $(cppflags) $(cppflags2)
+ g++ -o $@ bench02.cxx bench02_rflx.cpp -I$(ROOTSYS)/include -shared -lReflex -lHistPainter `root-config --libs` $(cppflags) $(cppflags2)
diff --git a/pypy/module/cppyy/bench/bench02.cxx b/pypy/module/cppyy/bench/bench02.cxx
--- a/pypy/module/cppyy/bench/bench02.cxx
+++ b/pypy/module/cppyy/bench/bench02.cxx
@@ -2,15 +2,93 @@
#include "TROOT.h"
#include "TApplication.h"
#include "TDirectory.h"
+#include "TInterpreter.h"
+#include "TSystem.h"
+#include "TBenchmark.h"
+#include "TStyle.h"
+#include "TError.h"
+#include "Getline.h"
+#include "TVirtualX.h"
+
+// CINT
+#include "Api.h"
#include <iostream>
+class TTestApplication : public TApplication {
+public:
+ TTestApplication(
+ const char* acn, Int_t* argc, char** argv, Bool_t bLoadLibs = kTRUE );
+
+ virtual ~TTestApplication();
+};
+
+
+//- constructors/destructor --------------------------------------------------
+TTestApplication::TTestApplication(
+ const char* acn, int* argc, char** argv, bool bLoadLibs ) :
+ TApplication( acn, argc, argv )
+{
+// Create a TApplication derived for use with interactive ROOT from python. A
+// set of standard, often used libs is loaded if bLoadLibs is true (default).
+
+ if ( bLoadLibs ) // note that this section could be programmed in python
+ {
+ // follow TRint to minimize differences with CINT
+ ProcessLine( "#include <iostream>", kTRUE );
+ ProcessLine( "#include <_string>", kTRUE ); // for std::string iostream.
+ ProcessLine( "#include <vector>", kTRUE ); // needed because they're used within the
+ ProcessLine( "#include <pair>", kTRUE ); // core ROOT dicts and CINT won't be able
+ // to properly unload these files
+
+ // following RINT, these are now commented out (rely on auto-loading)
+ // // the following libs are also useful to have, make sure they are loaded...
+ // gROOT->LoadClass("TMinuit", "Minuit");
+ // gROOT->LoadClass("TPostScript", "Postscript");
+ // gROOT->LoadClass("THtml", "Html");
+ }
+
+#ifdef WIN32
+ // switch win32 proxy main thread id
+ if (gVirtualX)
+ ProcessLine("((TGWin32 *)gVirtualX)->SetUserThreadId(0);", kTRUE);
+#endif
+
+// save current interpreter context
+ gInterpreter->SaveContext();
+ gInterpreter->SaveGlobalsContext();
+
+// prevent crashes on accessing histor
+ Gl_histinit( (char*)"-" );
+
+// prevent ROOT from exiting python
+ SetReturnFromRun( kTRUE );
+}
+
+TTestApplication::~TTestApplication() {}
+
+static const char* appname = "pypy-cppyy";
+
CloserHack::CloserHack() {
std::cout << "gROOT is: " << gROOT << std::endl;
std::cout << "gApplication is: " << gApplication << std::endl;
+
+ if ( ! gApplication ) {
+ // retrieve arg list from python, translate to raw C, pass on
+ int argc = 1;
+ char* argv[1]; argv[0] = (char*)appname;
+ gApplication = new TTestApplication( appname, &argc, argv, kTRUE );
+ }
+
+ std::cout << "gApplication is: " << gApplication << std::endl;
}
-CloserHack::~CloserHack() {
+void CloserHack::report() {
+ std::cout << "gROOT is: " << gROOT << std::endl;
+ std::cout << "gApplication is: " << gApplication << std::endl;
+}
+
+void CloserHack::close() {
std::cout << "closing file ... " << std::endl;
if (gDirectory && gDirectory != gROOT) {
gDirectory->Write();
@@ -18,3 +96,6 @@
}
}
+CloserHack::~CloserHack() {
+}
+
diff --git a/pypy/module/cppyy/bench/bench02.h b/pypy/module/cppyy/bench/bench02.h
--- a/pypy/module/cppyy/bench/bench02.h
+++ b/pypy/module/cppyy/bench/bench02.h
@@ -13,6 +13,9 @@
public:
CloserHack();
~CloserHack();
+
+ void report();
+ void close();
};
/*
diff --git a/pypy/module/cppyy/bench/hsimple.py b/pypy/module/cppyy/bench/hsimple.py
--- a/pypy/module/cppyy/bench/hsimple.py
+++ b/pypy/module/cppyy/bench/hsimple.py
@@ -20,6 +20,8 @@
TNtuple = cppyy.gbl.TNtuple
TH1F = cppyy.gbl.TH1F
TH2F = cppyy.gbl.TH2F
+ CH = cppyy.gbl.CloserHack()
+ CH.report()
except ImportError:
from ROOT import TCanvas, TFile, TProfile, TNtuple, TH1F, TH2F
import random
@@ -32,7 +34,7 @@
#gROOT.Reset()
# Create a new canvas, and customize it.
-#c1 = TCanvas( 'c1', 'Dynamic Filling Example', 200, 10, 700, 500 )
+c1 = TCanvas( 'c1', 'Dynamic Filling Example', 200, 10, 700, 500 )
#c1.SetFillColor( 42 )
#c1.GetFrame().SetFillColor( 21 )
#c1.GetFrame().SetBorderSize( 6 )
@@ -80,9 +82,9 @@
# ntupleFill( px, py, pz, random, i )
# Update display every kUPDATE events.
-# if i and i%kUPDATE == 0:
-# if i == kUPDATE:
-# hpx.Draw()
+ if i and i%kUPDATE == 0:
+ if i == kUPDATE:
+ hpx.Draw()
# c1.Modified()
# c1.Update()
@@ -98,7 +100,8 @@
hfile.Close()
#hpx.SetFillColor( 48 )
#c1.Modified()
-#c1.Update()
+c1.Update()
+c1.Draw()
#import gc
#gc.collect()
More information about the pypy-commit
mailing list