Skip to content

Commit

Permalink
Legacy reader fix
Browse files Browse the repository at this point in the history
  • Loading branch information
peremato committed Mar 26, 2024
1 parent 6997159 commit 7aa610f
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "EDM4hep"
uuid = "eb32b910-dde9-4347-8fce-cd6be3498f0c"
authors = ["Pere Mato <[email protected]>"]
version = "0.3.0"
version = "0.3.1"

[deps]
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
Expand Down
4 changes: 4 additions & 0 deletions docs/src/release_notes.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@

# Release Notes

## 0.3.1
### Bug Fixes
- Legacy podio test fixed

## 0.3.0
### New Functionality
- Optimisations by explicitly generation of StructArrays
Expand Down
4 changes: 2 additions & 2 deletions examples/FCC/analysis_MT.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ end
function myanalysis!(data::MyData, reader, events)
for evt in events
data.pevts += 1 # count process events
μIDs = RootIO.get(reader, evt, "Muon_objIdx") # get the ids of muons
μIDs = RootIO.get(reader, evt, "Muon_objIdx"; register=false) # get the ids of muons
length(μIDs) < 2 && continue # skip if less than 2

recps = RootIO.get(reader, evt, "ReconstructedParticles")
recps = RootIO.get(reader, evt, "ReconstructedParticles"; register=false)
muons = recps[μIDs] # use the ids to subset the reco particles

sel_muons = filter(x -> pₜ(x) > 10GeV, muons) # select the the Pt of muons
Expand Down
18 changes: 15 additions & 3 deletions src/RootIO.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,23 @@ module RootIO
vmembers = []
fnames = fieldnames(T)
ftypes = fieldtypes(T)
n_rels = 0 # number of one-to-one or one-to-many Relations
n_pvecs = 0 # number of vector member
for (fn,ft) in zip(fnames, ftypes)
if ft <: Relation
push!(relations, ("_$(branch)_$(fn)", eltype(ft))) # add a tuple with (relation_branchname, target_type)
if reader.podioversion >= newpodio
push!(relations, ("_$(branch)_$(fn)", eltype(ft))) # add a tuple with (relation_branchname, target_type)
else
push!(relations, ("$(branch)#$(n_rels)", eltype(ft)))
n_rels += 1
end
elseif ft <: PVector
push!(vmembers, ("_$(branch)_$(fn)", eltype(ft))) # add a tuple with (relation_branchname, target_type)
if reader.podioversion >= newpodio
push!(vmembers, ("_$(branch)_$(fn)", eltype(ft))) # add a tuple with (vector_branchname, target_type)
else
push!(vmembers, ("$(branch)_$(n_pvecs)", eltype(ft))) # add a tuple with (vector_branchname, target_type)
n_pvecs += 1
end
end
end
(T, (), Tuple(relations), Tuple(vmembers))
Expand Down Expand Up @@ -293,7 +305,7 @@ module RootIO
type known in the ROOT file (C++ class name). The optonal key parameter `register` indicates is the collection
needs to be registered to the `EDStore`.
"""
function get(reader::Reader, evt::UnROOT.LazyEvent, bname::String; btype::Type=Any, register=false)
function get(reader::Reader, evt::UnROOT.LazyEvent, bname::String; btype::Type=Any, register=true)
btype = btype === Any ? reader.btypes[bname] : btype # Allow the user to force the actual type
_get(reader, evt, bname, btype, register)
end
Expand Down
14 changes: 9 additions & 5 deletions test/testRootReaderLegacy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ using EDM4hep.RootIO
events = RootIO.get(reader, "events")
@test length(events) == 100000

# Loop over MC particles
# Loop over MC events
for evt in Iterators.take(events, 100)
recps = RootIO.get(reader, evt, "ReconstructedParticles");
tracks = RootIO.get(reader, evt, "EFlowTrack")
pids = RootIO.get(reader, evt, "ParticleIDs")
muons = recps[RootIO.get(reader, evt, "Muon#0")]
recps = RootIO.get(reader, evt, "ReconstructedParticles"; register=true);
tracks = RootIO.get(reader, evt, "EFlowTrack"; register=true)
pids = RootIO.get(reader, evt, "ParticleIDs"; register=true)
μids = RootIO.get(reader, evt, "Muon#0")
@test eltype(μids) == ObjectID
muons = recps[μids]
@test length(muons) == length(μids)
@test eltype(muons) == ReconstructedParticle
if length(muons) == 2
@test abs(sum(muons.charge)) <= 2.0f0
end
Expand Down

2 comments on commit 7aa610f

@peremato
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

Release notes:

Fixes

  • Legacy reader fix

@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/103630

Tagging

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.3.1 -m "<description of version>" 7aa610f0c591ae7d236bf1c593e29b26192ddabe
git push origin v0.3.1

Please sign in to comment.