[pypy-commit] pypy reflex-support: bench02 code cleanup and test of bench
wlav
noreply at buildbot.pypy.org
Thu Jul 21 14:15:30 CEST 2011
Author: Wim Lavrijsen <WLavrijsen at lbl.gov>
Branch: reflex-support
Changeset: r45813:41aebf1d8db1
Date: 2011-07-21 05:15 -0700
http://bitbucket.org/pypy/pypy/changeset/41aebf1d8db1/
Log: bench02 code cleanup and test of bench
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
@@ -1,4 +1,5 @@
#include "bench02.h"
+
#include "TROOT.h"
#include "TApplication.h"
#include "TDirectory.h"
@@ -10,92 +11,64 @@
#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 );
-
+ 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
- {
+ const char* acn, int* argc, char** argv, bool do_load) : TApplication(acn, argc, argv) {
+ if (do_load) {
// 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
+ 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
+ // save current interpreter context
gInterpreter->SaveContext();
gInterpreter->SaveGlobalsContext();
-// prevent crashes on accessing histor
- Gl_histinit( (char*)"-" );
+ // prevent crashes on accessing history
+ Gl_histinit((char*)"-");
-// prevent ROOT from exiting python
- SetReturnFromRun( kTRUE );
+ // 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
+Bench02RootApp::Bench02RootApp() {
+ if (!gApplication) {
int argc = 1;
char* argv[1]; argv[0] = (char*)appname;
- gApplication = new TTestApplication( appname, &argc, argv, kTRUE );
+ gApplication = new TTestApplication(appname, &argc, argv, kTRUE);
}
-
- std::cout << "gApplication is: " << gApplication << std::endl;
}
-void CloserHack::report() {
+Bench02RootApp::~Bench02RootApp() {
+ // TODO: ROOT globals cleanup ... (?)
+}
+
+void Bench02RootApp::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();
- gDirectory->Close();
- }
+void Bench02RootApp::close_file(TFile* f) {
+ std::cout << "closing file " << f->GetName() << " ... " << std::endl;
+ f->Write();
+ f->Close();
+ std::cout << "... file closed" << std::endl;
}
-
-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
@@ -4,18 +4,45 @@
#include "TNtuple.h"
#include "TH1F.h"
#include "TH2F.h"
+#include "TRandom.h"
#include "TROOT.h"
#include "TApplication.h"
+#include "TBox.h"
+#include "TClassGenerator.h"
+#include "TF1.h"
+#include "TFileMergeInfo.h"
+#include "TFolder.h"
+#include "TFunction.h"
+#include "TFrame.h"
+#include "TGlobal.h"
+#include "TInetAddress.h"
+#include "TInterpreter.h"
+#include "TKey.h"
+#include "TLegend.h"
+#include "TPluginManager.h"
+#include "TProcessUUID.h"
+#include "TStyle.h"
+#include "TSysEvtHandler.h"
+#include "TTimer.h"
+#include "TView.h"
+#include "TVirtualFFT.h"
+#include "TVirtualHistPainter.h"
+#include "TVirtualPadPainter.h"
+#include "TVirtualViewer3D.h"
-class CloserHack {
+#include <typeinfo>
+#include <ostream>
+
+
+class Bench02RootApp {
public:
- CloserHack();
- ~CloserHack();
+ Bench02RootApp();
+ ~Bench02RootApp();
void report();
- void close();
+ void close_file(TFile* f);
};
/*
diff --git a/pypy/module/cppyy/bench/bench02.xml b/pypy/module/cppyy/bench/bench02.xml
--- a/pypy/module/cppyy/bench/bench02.xml
+++ b/pypy/module/cppyy/bench/bench02.xml
@@ -1,42 +1,31 @@
<lcgdict>
- <!-- base classes -->
- <class name="TROOT" />
- <class name="TApplication" />
+ <selection>
- <class name="TObject" />
- <class name="TNamed" />
+ <!-- ROOT classes -->
+ <class pattern="T[A-Z]*" />
- <class name="TQObject" />
- <class name="TAttPad" />
- <class name="TAttFill" />
- <class name="TAttLine" />
- <class name="TAttMarker" />
- <class name="TVirtualPad" />
- <class name="TPad" />
-
- <class name="TDirectory" />
- <class name="TDirectoryFile" />
-
- <class name="TH1" />
- <class name="TH2" />
- <class name="TH1D" />
-
- <class name="TArray" />
- <class name="TArrayD" />
- <class name="TArrayF" />
-
- <class name="TTree" /> -->
-
- <!-- desired classes -->
- <class name="TCanvas" />
- <class name="TFile" />
- <class name="TProfile" />
- <class name="TNtuple" />
- <class name="TH1F" />
- <class name="TH2F" />
+ <!-- STL classes actually used -->
+ <class name="std::ostream" />
+ <class name="std::type_info" />
+ <class pattern="std::_Vector_base<*> >" />
<!-- helper -->
- <class name="CloserHack" />
+ <class name="Bench02RootApp" />
+
+ </selection>
+
+ <exclusion>
+
+ <class name="TString" >
+ <field name="fRep" transient="true"/>
+ </class>
+
+ <class pattern="TString::*" />
+
+ <class name="TClass::TNameMapNode" />
+ <class name="TFileOpenHandle" />
+
+ </exclusion>
</lcgdict>
diff --git a/pypy/module/cppyy/bench/hsimple.C b/pypy/module/cppyy/bench/hsimple.C
--- a/pypy/module/cppyy/bench/hsimple.C
+++ b/pypy/module/cppyy/bench/hsimple.C
@@ -10,6 +10,8 @@
#include <TBenchmark.h>
#include <TInterpreter.h>
+#include <math.h>
+
TFile *hsimple(Int_t get=0)
{
// This program creates :
@@ -80,13 +82,13 @@
*/
// Fill histograms randomly
gRandom->SetSeed();
- Float_t px, py, pz;
+ Float_t px, py, pt;
const Int_t kUPDATE = 1000;
for (Int_t i = 0; i < 2500000; i++) {
gRandom->Rannor(px,py);
- pz = px*px + py*py;
+ pt = sqrt(px*px + py*py);
// Float_t random = gRandom->Rndm(1);
- hpx->Fill(px);
+ hpx->Fill(pt);
/*
hpxpy->Fill(px,py);
hprof->Fill(px,pz);
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
@@ -14,18 +14,19 @@
import cppyy, random
cppyy.load_lib('bench02Dict_reflex.so')
+ app = cppyy.gbl.Bench02RootApp()
TCanvas = cppyy.gbl.TCanvas
TFile = cppyy.gbl.TFile
TProfile = cppyy.gbl.TProfile
TNtuple = cppyy.gbl.TNtuple
TH1F = cppyy.gbl.TH1F
TH2F = cppyy.gbl.TH2F
- CH = cppyy.gbl.CloserHack()
- CH.report()
+ TRandom = cppyy.gbl.TRandom
except ImportError:
- from ROOT import TCanvas, TFile, TProfile, TNtuple, TH1F, TH2F
+ from ROOT import TCanvas, TFile, TProfile, TNtuple, TH1F, TH2F, TRandom
import random
+import math
#gROOT = cppyy.gbl.gROOT
#gBenchmark = cppyy.gbl.gBenchmark
#gRandom = cppyy.gbl.gRandom
@@ -34,7 +35,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 )
@@ -65,14 +66,18 @@
#gRandom.SetSeed()
#rannor, rndm = gRandom.Rannor, gRandom.Rndm
+#random = TRandom()
+
# Fill histograms randomly.
#px, py = Double(), Double()
kUPDATE = 1000
for i in xrange( 2500000 ):
# Generate random values.
px, py = random.gauss(0, 1), random.gauss(0, 1)
+# px, py = random.Gaus(0, 1), random.Gaus(0, 1)
# pt = (px*px + py*py)**0.5
- pt = (px*px + py*py)
+ pt = math.sqrt(px*px + py*py)
+# pt = (px*px + py*py)
# random = rndm(1)
# Fill histograms.
@@ -82,9 +87,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()
@@ -100,8 +105,8 @@
hfile.Close()
#hpx.SetFillColor( 48 )
#c1.Modified()
-c1.Update()
-c1.Draw()
+#c1.Update()
+#c1.Draw()
#import gc
#gc.collect()
More information about the pypy-commit
mailing list