Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PyROOT][ROOT-10294] Reuse TEnum to get its underlying type #132

Closed
wants to merge 40 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
e0ecce2
[ntuple] add support for column element creation from type
jblomer Aug 25, 2019
2f3b7b8
[ntuple] add support for printing internals (WIP)
jblomer Aug 26, 2019
977eb0a
[ntuple] fix descriptor printing for empty columns
jblomer Aug 26, 2019
3c44889
[ntuple] increase default cluster size from 8k to 64k entries
jblomer Aug 26, 2019
f902c64
[ntuple] make std::int32 and ClusterSize_t mapped view types
jblomer Aug 26, 2019
3c7af4b
[ntuple] cosmetics in page storage printer
jblomer Aug 26, 2019
8daaa01
[io] update TFile docu about kReproducible bit
linev Aug 27, 2019
6c8baff
[io] add optional mmap() capability to raw file
jblomer Aug 24, 2019
8eb8c0b
[ntuple] verify that raw files support GetSize()
jblomer Aug 24, 2019
a9fc3cf
[ntuple] fix typo preventing build on Windows
jblomer Aug 26, 2019
a7054dd
[ntuple] use R__zipMultipleAlgorithm for raw storage compression
jblomer Aug 26, 2019
6758d6f
[ntuple] use more reasonable size for raw storage compression buffers
jblomer Aug 26, 2019
3eab9d9
[ntuple] show number of pages per cluster in storage details
jblomer Aug 26, 2019
df470db
[xml] use c++11 interface for virtaul functions
linev Aug 23, 2019
435fc82
[xml] check kReproducible bit to save default values for dates and uuid
linev Aug 23, 2019
5f18e1e
[xml] use more c++11 syntax in TKeyXML and TXMLSetup
linev Aug 23, 2019
b633acb
[xml] use c++11 syntax in TBufferXML
linev Aug 23, 2019
b37a66c
[xml] use unique_ptr as holder of stack objects
linev Aug 23, 2019
833f077
[sql] check kReproducible bit in TSQLFile
linev Aug 26, 2019
9ac35af
[sqlio] use actual creation/modification times of TDirectory
linev Aug 26, 2019
bbb66f8
[sqlio] use final specifier for TSQLFile/TKeySQL methods
linev Aug 26, 2019
40a1aec
[xmlio] use c++11 syntax to delclare copy/assign constructors as delete
linev Aug 27, 2019
49c2981
[sqlio] provide more c++11 in TSQLFile classes
linev Aug 27, 2019
bb2f702
[sqlio] use more default initializers in TSQLFile classes
linev Aug 27, 2019
f6fcb4e
[json] fix problem with conversion vector<vector<vector<int>>>
linev Aug 27, 2019
bb3e5e0
[ntuple] Fix linker error in unit test
jblomer Aug 27, 2019
d181dd7
[ntuple] fix compiler warning
jblomer Aug 27, 2019
c888601
In MakeProject avoid dereferencing deleted object.
pcanal Aug 26, 2019
1072b4f
[PyROOT exp] Port TTree.AsMatrix feature
stwunsch Aug 27, 2019
41ffdc7
[Exp PyROOT] Prevent cppyy from filtering ROOT libraries
etejedor Aug 26, 2019
3a12063
[Exp PyROOT] Set memory policy to heuristics
etejedor Aug 26, 2019
960bb0f
[Exp PyROOT] Fix slice assignment when range is longer than assigned val
etejedor Aug 26, 2019
7cc9dd0
[Exp PyROOT] Do not rely on RemoveAt to implement list methods
etejedor Aug 27, 2019
28a0f45
[Exp PyROOT] No need to set ownership, now using kMemoryHeuristics
etejedor Aug 27, 2019
e535b51
[Exp PyROOT] Fix c *= factor operator for TCollection
etejedor Aug 27, 2019
e33452c
[Exp PyROOT] Add plotOn overloads of RooAbsData to RooDataHist
etejedor Aug 27, 2019
6727de8
[Exp PyROOT] Re-enable tests and tutorials fixed by plotOn pythonisation
etejedor Aug 27, 2019
afeda5f
[Exp PyROOT] Re-enable tutorial (all dependencies are re-enabled)
etejedor Aug 27, 2019
10581bd
[PyROOT exp] Assume TTree.AsMatrix tutorial as passing
stwunsch Aug 28, 2019
1c0341f
[PyROOT][ROOT-10294] Reuse TEnum to get its underlying type
etejedor Aug 30, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README/ReleaseNotes/v620/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,17 @@ or in `TBrowser` by opening `Browser Help → About ROOT`.
## I/O Libraries

* TMemFile: Apply customization of minimal block size also to the first block.
* TFile: A new bit `TFile::kReproducible` was introduced. It can be enabled by
specifying the `"reproducible"` url option when creating the file:
```{.cpp}
TFile *f = TFile::Open("name.root?reproducible","RECREATE","File title");
```{.cpp}
Unlike regular `TFile`s, the content of such file has reproducible binary
content when writing exactly same data. This achieved by writing pre-defined
values for creation and modification date of TKey/TDirectory objects and null
value for TUUID objects inside TFile. As drawback, TRef objects stored in such
file cannot be read correctly.


## TTree Libraries

Expand Down
9 changes: 6 additions & 3 deletions bindings/pyroot/src/Cppyy.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "TCollection.h"
#include "TDataMember.h"
#include "TDataType.h"
#include "TEnum.h"
#include "TEnumConstant.h"
#include "TError.h"
#include "TFunction.h"
Expand Down Expand Up @@ -175,9 +174,8 @@ std::string Cppyy::ResolveName( const std::string& cppitem_name )
return TClassEdit::ResolveTypedef( tclean.c_str(), true );
}

std::string Cppyy::ResolveEnum(const std::string& enum_type)
std::string Cppyy::ResolveEnum(const TEnum* en)
{
auto en = TEnum::GetEnum(enum_type.c_str());
if (en) {
auto ut = en->GetUnderlyingType();
if (ut != EDataType::kNumDataTypes)
Expand All @@ -187,6 +185,11 @@ std::string Cppyy::ResolveEnum(const std::string& enum_type)
return "int";
}

std::string Cppyy::ResolveEnum(const std::string& enum_type)
{
return ResolveEnum(TEnum::GetEnum(enum_type.c_str()));
}

Cppyy::TCppScope_t Cppyy::GetScope( const std::string& sname )
{
std::string scope_name;
Expand Down
4 changes: 4 additions & 0 deletions bindings/pyroot/src/Cppyy.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#ifndef PYROOT_CPPYY_H
#define PYROOT_CPPYY_H

// ROOT
#include "TEnum.h"

// Standard
#include <string>
#include <vector>
Expand All @@ -22,6 +25,7 @@ namespace Cppyy {
TCppIndex_t GetNumScopes( TCppScope_t parent );
std::string GetScopeName( TCppScope_t parent, TCppIndex_t iscope );
std::string ResolveName( const std::string& cppitem_name );
std::string ResolveEnum(const TEnum* en);
std::string ResolveEnum(const std::string& enum_type);
TCppScope_t GetScope( const std::string& scope_name );
std::string GetName( const std::string& scope_name );
Expand Down
5 changes: 2 additions & 3 deletions bindings/pyroot/src/PropertyProxy.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,9 @@ void PyROOT::PropertyProxy::Set( Cppyy::TCppScope_t scope, Cppyy::TCppIndex_t id

////////////////////////////////////////////////////////////////////////////////

void PyROOT::PropertyProxy::Set( Cppyy::TCppScope_t scope, const std::string& name, void* address )
void PyROOT::PropertyProxy::Set( Cppyy::TCppScope_t scope, const std::string& name, void* address, TEnum* en )
{
Cppyy::TCppIndex_t idata = Cppyy::GetDatamemberIndex(scope, name);
std::string cppType = Cppyy::ResolveEnum(Cppyy::GetDatamemberType(scope, idata));
std::string cppType = Cppyy::ResolveEnum(en);

fEnclosingScope = scope;
fName = name;
Expand Down
6 changes: 3 additions & 3 deletions bindings/pyroot/src/PropertyProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace PyROOT {
class PropertyProxy {
public:
void Set( Cppyy::TCppScope_t scope, Cppyy::TCppIndex_t idata );
void Set( Cppyy::TCppScope_t scope, const std::string& name, void* address );
void Set( Cppyy::TCppScope_t scope, const std::string& name, void* address, TEnum* en );

std::string GetName() { return fName; }
void* GetAddress( ObjectProxy* pyobj /* owner */ );
Expand Down Expand Up @@ -70,12 +70,12 @@ namespace PyROOT {
}

inline PropertyProxy* PropertyProxy_NewConstant(
Cppyy::TCppScope_t scope, const std::string& name, void* address )
Cppyy::TCppScope_t scope, const std::string& name, void* address, TEnum* en )
{
// Create an initialize a new property descriptor, given the C++ datum.
PropertyProxy* pyprop =
(PropertyProxy*)PropertyProxy_Type.tp_new( &PropertyProxy_Type, 0, 0 );
pyprop->Set( scope, name, address );
pyprop->Set( scope, name, address, en );
return pyprop;
}

Expand Down
8 changes: 4 additions & 4 deletions bindings/pyroot/src/RootWrapper.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ namespace {
Py_DECREF( property );
}

void AddPropertyToClass( PyObject* pyclass,
Cppyy::TCppScope_t scope, const std::string& name, void* address )
void AddConstantPropertyToClass( PyObject* pyclass,
Cppyy::TCppScope_t scope, const std::string& name, void* address, TEnum* en )
{
PyROOT::PropertyProxy* property =
PyROOT::PropertyProxy_NewConstant( scope, name, address );
PyROOT::PropertyProxy_NewConstant( scope, name, address, en );
AddPropertyToClass1( pyclass, property, kTRUE );
Py_DECREF( property );
}
Expand Down Expand Up @@ -366,7 +366,7 @@ static int BuildScopeProxyDict( Cppyy::TCppScope_t scope, PyObject* pyclass ) {
if (isScoped) continue; // scoped enum: do not add constants as properties of the enum's scope
for ( Int_t i = 0; i < seq->GetSize(); i++ ) {
TEnumConstant* ec = (TEnumConstant*)seq->At( i );
AddPropertyToClass( pyclass, scope, ec->GetName(), ec->GetAddress() );
AddConstantPropertyToClass( pyclass, scope, ec->GetName(), ec->GetAddress(), e );
}
}

Expand Down
1 change: 1 addition & 0 deletions bindings/pyroot_experimental/PyROOT/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ set(py_sources
ROOT/pythonization/_drawables.py
ROOT/pythonization/_generic.py
ROOT/pythonization/_rooabscollection.py
ROOT/pythonization/_roodatahist.py
ROOT/pythonization/_rvec.py
ROOT/pythonization/_stl_vector.py
ROOT/pythonization/_tarray.py
Expand Down
3 changes: 3 additions & 0 deletions bindings/pyroot_experimental/PyROOT/python/ROOT/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
# Prevent cppyy's check for extra header directory
environ['CPPYY_API_PATH'] = 'none'

# Prevent cppyy from filtering ROOT libraries
environ['CPPYY_NO_ROOT_FILTER'] = '1'

import cppyy
import ROOT.pythonization as pyz

Expand Down
5 changes: 5 additions & 0 deletions bindings/pyroot_experimental/PyROOT/python/ROOT/_facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ def _finalSetup(self):
if not self.gROOT.IsBatch():
self.app.init_graphics()

# Set memory policy to kUseHeuristics.
# This restores the default in PyROOT which was changed
# by new Cppyy
self.SetMemoryPolicy(self.kMemoryHeuristics)

# Redirect lookups to cppyy's global namespace
self.__dict__['ROOT_ns'] = gbl_namespace.ROOT
self.__class__.__getattr__ = self._fallback_getattr
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Author: Enric Tejedor CERN 08/2019

################################################################################
# Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. #
# All rights reserved. #
# #
# For the licensing terms see $ROOTSYS/LICENSE. #
# For the list of contributors see $ROOTSYS/README/CREDITS. #
################################################################################

from ROOT import pythonization

from libROOTPython import AddUsingToClass


@pythonization()
def pythonize_roodatahist(klass, name):
# Parameters:
# klass: class to be pythonized
# name: string containing the name of the class

if name == 'RooDataHist':
# Add 'using' overloads for plotOn from RooAbsData
AddUsingToClass(klass, 'plotOn')

return True
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@ def _imul_pyz(self, n):
# - n: factor to multiply the collection by
# Returns:
# - self *= n
c = self.__class__()
c.AddAll(self)
for _ in range(n - 1):
_extend_pyz(self, self)
_extend_pyz(self, c)
return self

# Python iteration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ def _getitem_pyz(self, idx):

return res

def _remove_at(self, idx):
# Parameters:
# - self: collection to remove the item from
# - idx: index of the item, always positive
lnk = self.FirstLink()
for i in range(idx):
lnk = lnk.Next()
return self.Remove(lnk)

def _setitem_pyz(self, idx, val):
# Parameters:
# - self: collection where to set item/s
Expand Down Expand Up @@ -97,10 +106,20 @@ def _setitem_pyz(self, idx, val):
except StopIteration:
# No more indices in range, just append
self.append(elem)

# If range is longer than the number of elements in val,
# we need to remove the remaining elements of the range
try:
for i in it:
del self[i]
except StopIteration:
# No more indices in range, we are done
pass

# Number
else:
idx = _check_index(self, idx)
self.RemoveAt(idx)
_remove_at(self, idx)
self.AddAt(val, idx)

def _delitem_pyz(self, idx):
Expand All @@ -119,11 +138,11 @@ def _delitem_pyz(self, idx):
rg = reversed(rg)

for i in rg:
self.RemoveAt(i)
_remove_at(self, i)
# Number
else:
idx = _check_index(self, idx)
self.RemoveAt(idx)
_remove_at(self, idx)

# Python-list-like methods

Expand Down Expand Up @@ -177,7 +196,7 @@ def _pop_pyz(self, *args):
if idx < 0 or idx >= lcol:
raise IndexError('pop index out of range')

return self.RemoveAt(idx)
return _remove_at(self, idx)

def _reverse_pyz(self):
# Parameters:
Expand Down
Loading