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
BaseDocStringExtensions
EecTopMass.BranchViews.BranchView Type
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.
EecTopMass.BranchViews.HasBranchSchema Type
struct HasBranchSchema{B}Holy trait for events which have B branches for ad-hoc structural subtyping.
EecTopMass.BranchViews.MissingBranchError Type
struct MissingBranchError <: ExceptionException from MissingBranchSchemas.
Usage
Single error.
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.
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)EecTopMass.BranchViews.MissingBranchError Method
MissingBranchError(
_::EecTopMass.BranchViews.MissingBranchSchema{N, M}
) -> EecTopMass.BranchViews.MissingBranchErrorSingle MissingBranchSchema error.
EecTopMass.BranchViews.MissingBranchError Method
MissingBranchError(
_::EecTopMass.BranchViews.MissingBranchSchema{N, M},
rest...
) -> EecTopMass.BranchViews.MissingBranchErrorMultiple MissingBranchSchemas error.
EecTopMass.BranchViews.MissingBranchSchema Type
struct MissingBranchSchema{N, M}Holy trait for events which doesn't have all required branches for N (name). Missing fields are stored in M.
EecTopMass.BranchViews.branchview_schema_trait Method
branchview_schema_trait(
_::Type{NT<:NamedTuple},
_::Val{P},
fields::Type{B<:NamedTuple}
) -> AnyGet a Holy-Trait for BranchView. Returns either HasBranchSchema or MissingBranchSchema. Requiring fields described in fields::Type{B} with prefix P to NT.
Error example
Single error.
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> 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)
trueProcessor
EecTopMass.Processor Module
Process Tables.jl-compatible data row-by-row and collect into Tables-compatible table (typically DataFrame).
EecTopMass.Processor.batch_process_events Method
batch_process_events(
process_local,
merge_results,
events,
batch_size;
info...
) -> AnyProcess batched events in multi threads.
Arguments
process_local: function to run on each taskmerge_results: (merged, new) -> merged: function to merge new results.events: iterator of events to process
EecTopMass.Processor.process_table_single Method
process_table_single(
f::Function,
table
) -> DataFrames.DataFrameProcess all rows in table table and collect results into a DataFrames.DataFrame with a local single thread.
EecTopMass.Processor.process_tables_multithread Method
process_tables_multithread(
f::Function,
tables
) -> DataFrames.DataFrameProcess all tables tables and collect results into a DataFrames.DataFrame with local multi threads.
EecTopMass.Processor.process_tables_single Method
process_tables_single(
f::Function,
tables
) -> DataFrames.DataFrameProcess all tables tables and collect results into a DataFrames.DataFrame with local single thread.
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.
EecTopMass.Processor.read_events Method
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.
EecTopMass.Processor.read_events Method
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.