Skip to content

Commit

Permalink
TVectorT<double> support (#240)
Browse files Browse the repository at this point in the history
* Add support for TVectorT<double>

* Bump version

* Add test for TVectorT<double> on top-level
  • Loading branch information
tamasgal authored Apr 20, 2023
1 parent 9d47b40 commit db2b306
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "UnROOT"
uuid = "3cd96dde-e98d-4713-81e9-a4a1b0235ce9"
authors = ["Tamas Gal", "Jerry Ling", "Johannes Schumann", "Nick Amin"]
version = "0.10.6"
version = "0.10.7"

[deps]
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
Expand Down
18 changes: 16 additions & 2 deletions src/bootstrap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1011,8 +1011,12 @@ function TNtuple(io, tkey::TKey, refs)
tree = TTree(io, tkey, refs; top=false) #embeded tree
end


"""
Direct parsing of streamed objects which are not sitting on branches.
Direct parsing of streamed objects which are not sitting on branches. This function needs to be
rewritten, so that it can create proper types of TObject inherited data (like `TVectorT<*>`).
"""
function parsetobject(io, tkey::TKey, streamer)
# pass the correct parser from f!
Expand All @@ -1024,7 +1028,7 @@ function parsetobject(io, tkey::TKey, streamer)
# the first entry in the streamer is a TOBject
parsefields!(io, fields, TObject)

# the second (and last) entry is the actual data streamer (we think)
# FIXME: this is just a hack, for TObject-derivatives which are subclassing map<string,string>
s = streamer.streamer.fElements.elements[2]
if s.fTypeName == "map<string,string>"
skip(io, 3*4) # unclear what the first 12 bytes are
Expand All @@ -1036,9 +1040,19 @@ function parsetobject(io, tkey::TKey, streamer)
values = [readtype(io, String) for i 1:n]
return Dict(zip(keys, values))
end

# FIXME: generalise this! We also need a hook-in mechanism for this function
# so that the user can provide custom parsing logic
if tkey.fClassName == "TVectorT<double>"
n = readtype(io, UInt32)
row_lwb = readtype(io, Int32) # index of the starting element of the vector itself
skip(io, 1)
return [readtype(io, Float64) for _ row_lwb+1:n]
end
error("Unable to parse '$(s.fTypeName)' of '$(tkey.fClassName)'")
end


# FIXME preliminary TTree implementation
function TTree(io, tkey::TKey, refs; top=true)
# if embeded in a Ntuple, don't run datastream again
Expand Down
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -925,5 +925,9 @@ end
@test alloc1 > 1.9*alloc2
end

@testset "Objects on top level" begin
rootfile = UnROOT.samplefile("TVectorT-double_on_top_level.root")
@test [1.1, 2.2, 3.3] == rootfile["vector_double"]
end

include("rntuple_tests.jl")
17 changes: 17 additions & 0 deletions test/samples/TVectorT-double_on_top_level.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <TFile.h>
#include <TVectorT.h>

int main() {
TFile* file = new TFile("example.root", "RECREATE");
TVectorT<double>* vec = new TVectorT<double>(3);
(*vec)[0] = 1.1;
(*vec)[1] = 2.2;
(*vec)[2] = 3.3;

TDirectory* dir = file->GetDirectory("/");
dir->WriteObject(vec, "vector_double");

file->Close();

return 0;
}
Binary file added test/samples/TVectorT-double_on_top_level.root
Binary file not shown.

2 comments on commit db2b306

@tamasgal
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register

@8me 0.10.7 can read your files now

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/82019

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.10.7 -m "<description of version>" db2b306bbda9ea8c4ada8a045e5e1be360cd5099
git push origin v0.10.7

Please sign in to comment.