Skip to content

General Utilities ​

This package comes with general utilities which should be also useful for other projects.

BranchViews ​

EecTopMass.BranchViews Module

Ad-hoc structural subtyping using Holy-Trait design pattern

Exports

Imports

  • Base

  • DocStringExtensions

source
EecTopMass.BranchViews.BranchView Type
julia
struct BranchView{P, F, E}

Lazy view of event's Prefixed_name branches under the non-prefixed names of F, a NamedTuple type giving each allowed name and its return type. If P is Nothing, then nothing is prefixed before name. Otherwise, P must be a Symbol. Like UnROOT.LazyEvent, only field access does I/O.

source
EecTopMass.BranchViews.BranchView Methodsource
EecTopMass.BranchViews.HasBranchSchema Type
julia
struct HasBranchSchema{B}

Holy trait for events which have B branches for ad-hoc structural subtyping.

source
EecTopMass.BranchViews.MissingBranchError Type
julia
struct MissingBranchError <: Exception

Exception from MissingBranchSchemas.

Usage

Single error.

julia
Required = @NamedTuple{a::Int64, b::Float64, c::UInt32}
Has = @NamedTuple{x_b::Float64, x_c::UInt32, y_a::Int64, y_c::UInt32, z_a::Int64, z_b::Float64, z_c::UInt32}
trait_missing = branchview_schema_trait(Has, Val(:x), Required)
@assert trait_missing isa MissingBranchSchema
MissingBranchError(trait_missing)

Multiple errors, including HasBranchSchema. This is applicative functor style error.

julia
Required = @NamedTuple{a::Int64, b::Float64, c::UInt32}
Has = @NamedTuple{x_b::Float64, x_c::UInt32, y_a::Int64, y_c::UInt32, z_a::Int64, z_b::Float64, z_c::UInt32}
trait_missing_1 = branchview_schema_trait(Has, Val(:x), Required)
trait_missing_2 = branchview_schema_trait(Has, Val(:y), Required)
trait_has_1 = branchview_schema_trait(Has, Val(:z), Required)
@assert trait_missing_1 isa MissingBranchSchema
@assert trait_missing_2 isa MissingBranchSchema
@assert trait_has_1 isa HasBranchSchema
MissingBranchError(trait_missing_1, trait_missing_2) == MissingBranchError(trait_missing_1, trait_missing_2, trait_has_1)
source
EecTopMass.BranchViews.MissingBranchError Method
julia
MissingBranchError(
    _::EecTopMass.BranchViews.MissingBranchSchema{N, M}
) -> EecTopMass.BranchViews.MissingBranchError

Single MissingBranchSchema error.

source
EecTopMass.BranchViews.MissingBranchError Method
julia
MissingBranchError(
    _::EecTopMass.BranchViews.MissingBranchSchema{N, M},
    rest...
) -> EecTopMass.BranchViews.MissingBranchError

Multiple MissingBranchSchemas error.

source
EecTopMass.BranchViews.MissingBranchSchema Type
julia
struct MissingBranchSchema{N, M}

Holy trait for events which doesn't have all required branches for N (name). Missing fields are stored in M.

source
EecTopMass.BranchViews.branchview_schema_trait Method
julia
branchview_schema_trait(
    _::Type{NT<:NamedTuple},
    _::Val{P},
    fields::Type{B<:NamedTuple}
) -> Any

Get a Holy-Trait for BranchView. Returns either HasBranchSchema or MissingBranchSchema. Requiring fields described in fields::Type{B} with prefix P to NT.

source

Error example ​

Single error.

julia
julia> using EecTopMass: branchview_schema_trait, MissingBranchSchema, MissingBranchError

julia> Required = @NamedTuple{a::Int64, b::Float64, c::UInt32};

julia> Has = @NamedTuple{x_b::Float64, x_c::UInt32, y_a::Int64, y_c::UInt32, z_a::Int64, z_b::Float64, z_c::UInt32};

julia> trait_missing = branchview_schema_trait(Has, Val(:x), Required)
EecTopMass.BranchViews.MissingBranchSchema{Type{@NamedTuple{a::Int64, b::Float64, c::UInt32}}, (:x_a,)}()

julia> @assert trait_missing isa MissingBranchSchema

julia> MissingBranchError(trait_missing)
EecTopMass.BranchViews.MissingBranchError((Symbol("Type{@NamedTuple{a::Int64, b::Float64, c::UInt32}}"),), ((:x_a,),))

Multiple errors, including HasBranchSchema. This is applicative functor style error.

julia
julia> using EecTopMass: branchview_schema_trait, MissingBranchSchema, MissingBranchError, HasBranchSchema

julia> Required = @NamedTuple{a::Int64, b::Float64, c::UInt32};

julia> Has = @NamedTuple{x_b::Float64, x_c::UInt32, y_a::Int64, y_c::UInt32, z_a::Int64, z_b::Float64, z_c::UInt32};

julia> trait_missing_1 = branchview_schema_trait(Has, Val(:x), Required)
EecTopMass.BranchViews.MissingBranchSchema{Type{@NamedTuple{a::Int64, b::Float64, c::UInt32}}, (:x_a,)}()

julia> trait_missing_2 = branchview_schema_trait(Has, Val(:y), Required)
EecTopMass.BranchViews.MissingBranchSchema{Type{@NamedTuple{a::Int64, b::Float64, c::UInt32}}, (:y_b,)}()

julia> trait_has_1 = branchview_schema_trait(Has, Val(:z), Required)
EecTopMass.BranchViews.HasBranchSchema{@NamedTuple{a::Int64, b::Float64, c::UInt32}}()

julia> @assert trait_missing_1 isa MissingBranchSchema

julia> @assert trait_missing_2 isa MissingBranchSchema

julia> @assert trait_has_1 isa HasBranchSchema

julia> MissingBranchError(trait_missing_1, trait_missing_2) == MissingBranchError(trait_missing_1, trait_missing_2, trait_has_1)
true

Processor ​

EecTopMass.Processor Module

Process Tables.jl-compatible data row-by-row and collect into Tables-compatible table (typically DataFrame).

source
EecTopMass.Processor.batch_process_events Method
julia
batch_process_events(
    process_local,
    merge_results,
    events,
    batch_size;
    info...
) -> Any

Process batched events in multi threads.

Arguments

  • process_local: function to run on each task

  • merge_results: (merged, new) -> merged: function to merge new results.

  • events: iterator of events to process

source
EecTopMass.Processor.process_table_single Method
julia
process_table_single(
    f::Function,
    table
) -> DataFrames.DataFrame

Process all rows in table table and collect results into a DataFrames.DataFrame with a local single thread.

source
EecTopMass.Processor.process_tables_multithread Method
julia
process_tables_multithread(
    f::Function,
    tables
) -> DataFrames.DataFrame

Process all tables tables and collect results into a DataFrames.DataFrame with local multi threads.

source
EecTopMass.Processor.process_tables_single Method
julia
process_tables_single(
    f::Function,
    tables
) -> DataFrames.DataFrame

Process all tables tables and collect results into a DataFrames.DataFrame with local single thread.

source
EecTopMass.Processor.read_events Function

Read events from multiple root files and returns Tables.partitions, which is basically an iterator of LazyTree. Argument branches is passed to Tables.LazyTree.

source
EecTopMass.Processor.read_events Method
julia
read_events(
    data_dir::AbstractString,
    tree_name,
    branches
) -> Tables.Partitioner{T} where T<:(Base.Generator{Vector{String}, F} where F<:(Tables.var"#partitioner##0#partitioner##1"{EecTopMass.Processor.var"#read_events##0#read_events##1"{tree_name, branches}} where {tree_name, branches}))

Read root files under data_dir.

source
EecTopMass.Processor.read_events Method
julia
read_events(
    data_files::AbstractVector{<:AbstractString},
    tree_name,
    branches
) -> Tables.Partitioner{T} where T<:(Base.Generator{I, F} where {I<:(AbstractVector{<:AbstractString}), F<:(Tables.var"#partitioner##0#partitioner##1"{EecTopMass.Processor.var"#read_events##0#read_events##1"{tree_name, branches}} where {tree_name, branches})})

Read root files at data_files.

source