diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2f12c646..b6c26fa2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,10 +2,10 @@ name: CI on: pull_request: branches: - - master + - main push: branches: - - master + - main tags: '*' jobs: test: @@ -29,20 +29,11 @@ jobs: with: version: ${{ matrix.version }} arch: ${{ matrix.arch }} - - uses: actions/cache@v1 - env: - cache-name: cache-artifacts - with: - path: ~/.julia/artifacts - key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }} - restore-keys: | - ${{ runner.os }}-test-${{ env.cache-name }}- - ${{ runner.os }}-test- - ${{ runner.os }}- + - uses: julia-actions/cache@v1 - uses: julia-actions/julia-buildpkg@v1 - uses: julia-actions/julia-runtest@v1 env: - JULIA_NUM_THREADS: "3" + JULIA_NUM_THREADS: 4,1 - uses: julia-actions/julia-processcoverage@v1 - uses: codecov/codecov-action@v1 with: @@ -52,23 +43,10 @@ jobs: name: Documentation runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: julia-actions/setup-julia@v1 - with: - version: '1.6' - - run: | - julia --project=docs -e ' - using Pkg - Pkg.develop(PackageSpec(path=pwd())) - Pkg.instantiate()' - - run: | - julia --color=yes --project=docs/ -e ' - using UnROOT - # using Pkg; Pkg.activate("docs") - using Documenter: DocMeta, doctest - DocMeta.setdocmeta!(UnROOT, :DocTestSetup, :(using UnROOT); recursive=true) - doctest(UnROOT)' - - run: julia --project=docs docs/make.jl + - uses: actions/checkout@v2 + - uses: julia-actions/cache@v1 + - uses: julia-actions/julia-buildpkg@latest + - uses: julia-actions/julia-docdeploy@latest env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }} diff --git a/Project.toml b/Project.toml index 419a5516..56b55132 100644 --- a/Project.toml +++ b/Project.toml @@ -31,9 +31,9 @@ AbstractTrees = "^0.3.0, 0.4" ArraysOfArrays = "^0.5.3, ^0.6" Arrow = "2 - 2.5" BitIntegers = "^0.2.6, ^0.3" -CodecLz4 = "^0.3.0, ^0.4.0" -CodecXz = "^0.6.0, ^0.7.0" -CodecZstd = "^0.6.0, ^0.7.0" +CodecLz4 = "^0.3, ^0.4" +CodecXz = "^0.6, ^0.7" +CodecZstd = "^0.6, ^0.7, ^0.8" HTTP = "^0.9.7, 1" IterTools = "^1" LRUCache = "^1.3.0" diff --git a/src/RNTuple/highlevel.jl b/src/RNTuple/highlevel.jl index a1b95594..41848e24 100644 --- a/src/RNTuple/highlevel.jl +++ b/src/RNTuple/highlevel.jl @@ -19,9 +19,10 @@ struct RNTupleField{R, F, O, E} <: AbstractVector{E} function RNTupleField(rn::R, field::F) where {R, F} O = _field_output_type(F) E = eltype(O) - buffers = Vector{O}(undef, Threads.nthreads()) - thread_locks = [ReentrantLock() for _ in 1:Threads.nthreads()] - buffer_ranges = [0:-1 for _ in 1:Threads.nthreads()] + Nthreads = _maxthreadid() + buffers = Vector{O}(undef, Nthreads) + thread_locks = [ReentrantLock() for _ in 1:Nthreads] + buffer_ranges = [0:-1 for _ in 1:Nthreads] new{R, F, O, E}(rn, field, buffers, thread_locks, buffer_ranges) end end diff --git a/src/UnROOT.jl b/src/UnROOT.jl index 3b6b5dbd..14236ec5 100644 --- a/src/UnROOT.jl +++ b/src/UnROOT.jl @@ -64,6 +64,13 @@ include("RNTuple/displays.jl") # show(devnull, df) # show(devnull, df[1]) # end +# + +_maxthreadid() = @static if VERSION < v"1.9" + Threads.nthreads() +else + Threads.maxthreadid() +end if VERSION >= v"1.9" let diff --git a/src/bootstrap.jl b/src/bootstrap.jl index 3091b930..1c5498e0 100644 --- a/src/bootstrap.jl +++ b/src/bootstrap.jl @@ -930,6 +930,12 @@ TH2F(io, tkey::TKey, refs) = TH(io, tkey, refs) TH1D(io, tkey::TKey, refs) = TH(io, tkey, refs) TH2D(io, tkey::TKey, refs) = TH(io, tkey, refs) +""" + TH(io, tkey::TKey, refs) + +Internal function used to form a `fields = Dict{Symbol, Any}()` that represents the fields of a +`TH` (histogram) in C++ ROOT. +""" function TH(io, tkey::TKey, refs) fields = Dict{Symbol, Any}() diff --git a/src/iteration.jl b/src/iteration.jl index b4714e9b..b6f8832b 100644 --- a/src/iteration.jl +++ b/src/iteration.jl @@ -123,11 +123,12 @@ mutable struct LazyBranch{T,J,B} <: AbstractVector{T} _buffer = VectorOfVectors(T(), Int32[1]) T = SubArray{eltype(T), 1, T, Tuple{UnitRange{Int64}}, true} end + Nthreads = _maxthreadid() return new{T,J,typeof(_buffer)}(f, b, length(b), b.fBasketEntry, - [_buffer for _ in 1:Threads.nthreads()], - [ReentrantLock() for _ in 1:Threads.nthreads()], - [0:-1 for _ in 1:Threads.nthreads()]) + [_buffer for _ in 1:Nthreads], + [ReentrantLock() for _ in 1:Nthreads], + [0:-1 for _ in 1:Nthreads]) end end LazyBranch(f::ROOTFile, s::AbstractString) = LazyBranch(f, f[s]) diff --git a/src/root.jl b/src/root.jl index eadce273..fdd1ede2 100644 --- a/src/root.jl +++ b/src/root.jl @@ -38,6 +38,7 @@ function Base.hash(rf::ROOTFile, h::UInt) return hash(rf.fobj, h) end +const HEAD_BUFFER_SIZE = 2048 """ ROOTFile(filename::AbstractString; customstructs = Dict("TLorentzVector" => LorentzVector{Float64})) @@ -61,7 +62,6 @@ test/samples/NanoAODv5_sample.root └─ "⋮" ``` """ -const HEAD_BUFFER_SIZE = 2048 function ROOTFile(filename::AbstractString; customstructs = Dict("TLorentzVector" => LorentzVector{Float64})) fobj = if startswith(filename, r"https?://") HTTPStream(filename) diff --git a/test/rntuple_tests.jl b/test/rntuple_tests.jl index 1506b0f7..9b3d9b6b 100644 --- a/test/rntuple_tests.jl +++ b/test/rntuple_tests.jl @@ -157,8 +157,17 @@ end Threads.@threads for i in eachindex(field) @inbounds accumulator[Threads.threadid()] += field[i] end + # test we've hit each thread's buffer - @test all(!isempty, field.buffers) + @test all( + map(eachindex(field.buffers)) do b + if !isassigned(field.buffers, b) + return true + else + return !isempty(field.buffers[b]) + end + + end) @test sum(accumulator) == sum(1:5e4) accumulator .= 0 diff --git a/test/runtests.jl b/test/runtests.jl index b2b66771..babb8fc2 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -4,7 +4,7 @@ using StaticArrays using InteractiveUtils using MD5 -const nthreads = Threads.nthreads() +const nthreads = UnROOT._maxthreadid() nthreads == 1 && @warn "Running on a single thread. Please re-run the test suite with at least two threads (`julia --threads 2 ...`)" const SAMPLES_DIR = joinpath(@__DIR__, "samples") @@ -766,13 +766,13 @@ end if get(ENV, "CI", "false") == "true" - if nthreads >= 1 - @test Threads.nthreads()>1 - else - @warn "CI wasn't run with multi thread" + if nthreads == 1 + @warn "CI wasn't run with multiple threads" end end - nmus = zeros(Int, Threads.nthreads()) + + nmus = zeros(Int, nthreads) + Threads.@threads for i in 1:length(t) nmus[Threads.threadid()] += length(t.Muon_pt[i]) end