Skip to content
This repository has been archived by the owner on Jun 21, 2022. It is now read-only.

addresses issue #168: provide a way to skip speedbump bytes #170

Merged
merged 1 commit into from
Oct 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Binary file added tests/samples/small-evnt-tree-nosplit.root
Binary file not shown.
8 changes: 8 additions & 0 deletions tests/test_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,11 @@ def test_geant4(self):
assert [len(x) for x in f["HitStrips"].arrays().values()] == [4808, 4808, 4808]
assert sum(f["edep_inner"].values), 1547 == 0
assert sum(sum(x) for x in f["recon_orig"].values), 141 == 0

### file is too big to include
# def test_issue168(self):
# t = uproot.open("tests/samples/issue168.root")["Events"]
# a1 = t["MRawEvtData.fHiGainFadcSamples"].array(t["MRawEvtData.fHiGainFadcSamples"].interpretation.speedbump(False), entrystop=4)
# assert a1[0]._fArray.shape == (108400,)
# a2 = t["MRawEvtData.fHiGainPixId"].array(t["MRawEvtData.fHiGainPixId"].interpretation.speedbump(False))
# assert a2[0]._fArray.shape == (1084,)
21 changes: 14 additions & 7 deletions uproot/interp/auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import copy
import re
import ast
from functools import reduce
Expand Down Expand Up @@ -114,18 +115,24 @@ def _leaf2dtype(leaf):
else:
raise _NotNumerical

def _obj_or_genobj(streamerClass, branch, isjagged, cntvers=False, tobject=True):
def _obj_or_genobj(streamerClass, branch, isjagged, cntvers=False, tobject=True, speedbump=True):
if len(branch._fBranches) != 0:
return None

try:
recarray = streamerClass._recarray_dtype(cntvers=cntvers, tobject=tobject)

except (AttributeError, ValueError):
if not speedbump:
context = copy.copy(branch._context)
context.speedbump = False
else:
context = branch._context

if isjagged:
return asgenobj(SimpleArray(streamerClass), branch._context, 0)
return asgenobj(SimpleArray(streamerClass), context, 0)
else:
return asgenobj(streamerClass, branch._context, 0)
return asgenobj(streamerClass, context, 0)

else:
if streamerClass._methods is None:
Expand All @@ -142,7 +149,7 @@ def _obj_or_genobj(streamerClass, branch, isjagged, cntvers=False, tobject=True)
else:
return asobj(astable(asdtype(recarray)), streamerClass._methods)

def interpret(branch, swapbytes=True, cntvers=False, tobject=True):
def interpret(branch, swapbytes=True, cntvers=False, tobject=True, speedbump=True):
dims, isjagged = (), False
if len(branch._fLeaves) == 1:
m = interpret._titlehasdims.match(branch._fLeaves[0]._fTitle)
Expand All @@ -163,7 +170,7 @@ def interpret(branch, swapbytes=True, cntvers=False, tobject=True):
obj = obj[:-1]
obj = uproot.rootio._safename(obj)
if obj in branch._context.classes:
return _obj_or_genobj(branch._context.classes.get(obj), branch, isjagged, cntvers=cntvers, tobject=tobject)
return _obj_or_genobj(branch._context.classes.get(obj), branch, isjagged, cntvers=cntvers, tobject=tobject, speedbump=speedbump)

if branch._fLeaves[0].__class__.__name__ == "TLeafElement" and branch._fLeaves[0]._fType == uproot.const.kDouble32:
def transform(node, tofloat=True):
Expand Down Expand Up @@ -238,14 +245,14 @@ def transform(node, tofloat=True):
if obj == "string":
return asgenobj(STLString(), branch._context, 0)
elif obj in branch._context.classes:
return _obj_or_genobj(branch._context.classes.get(obj), branch, isjagged, cntvers=cntvers, tobject=tobject)
return _obj_or_genobj(branch._context.classes.get(obj), branch, isjagged, cntvers=cntvers, tobject=tobject, speedbump=speedbump)

if isinstance(branch._streamer, uproot.rootio.TStreamerInfo):
obj = uproot.rootio._safename(branch._streamer._fName)
if obj == "string":
return asgenobj(STLString(), branch._context, 0)
elif obj in branch._context.classes:
return _obj_or_genobj(branch._context.classes.get(obj), branch, isjagged, cntvers=cntvers, tobject=tobject)
return _obj_or_genobj(branch._context.classes.get(obj), branch, isjagged, cntvers=cntvers, tobject=tobject, speedbump=speedbump)

if branch._fLeaves[0].__class__.__name__ == "TLeafC":
return asstring(skipbytes=1)
Expand Down
8 changes: 8 additions & 0 deletions uproot/interp/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import copy
import struct

import awkward
Expand Down Expand Up @@ -282,6 +283,13 @@ def __repr__(self):
def __init__(self, cls, context, skipbytes):
super(asgenobj, self).__init__(uproot.interp.jagged.asjagged(uproot.interp.numerical.asdtype(awkward.util.CHARTYPE), skipbytes=skipbytes), asgenobj._Wrapper(cls, context))

def speedbump(self, value):
out = copy.copy(self)
out.generator = copy.copy(self.generator)
out.generator.context = copy.copy(out.generator.context)
out.generator.context.speedbump = value
return out

def __repr__(self):
return "asgenobj({0})".format(self.generator)

Expand Down
3 changes: 2 additions & 1 deletion uproot/rootio.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,8 @@ def _defineclasses(streamerinfos, classes):
bases.append(_safename(element._fName))

elif isinstance(element, TStreamerBasicPointer):
code.append(" cursor.skip(1)")
code.append(" if getattr(context, \"speedbump\", True):")
code.append(" cursor.skip(1)")

assert uproot.const.kOffsetP < element._fType < uproot.const.kOffsetP + 20
fType = element._fType - uproot.const.kOffsetP
Expand Down
1 change: 1 addition & 0 deletions uproot/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ def _attachstreamer(self, branch, streamer, streamerinfosmap):
def _postprocess(self, source, cursor, context, parent):
self._context = context
self._context.treename = self.name
self._context.speedbump = True

for branch in self._fBranches:
self._attachstreamer(branch, context.streamerinfosmap.get(getattr(branch, "_fClassName", None), None), context.streamerinfosmap)
Expand Down
2 changes: 1 addition & 1 deletion uproot/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

import re

__version__ = "3.2.5"
__version__ = "3.2.6"
version = __version__
version_info = tuple(re.split(r"[-\.]", __version__))

Expand Down