Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplified data loader #59

Merged
merged 54 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
bb5e990
Remove Requires support
theHenks Aug 8, 2024
8e439ac
Fix error message for DataPeriod
theHenks Aug 8, 2024
badb85a
New `read-ldata` functionality to load tiers across files for single …
theHenks Aug 12, 2024
6f9fa03
deprecate partition and run load function due to new `read_ldata` fun…
theHenks Aug 12, 2024
e001eff
Add LegendHDF5IO extension documentation
theHenks Aug 13, 2024
abd9018
Add section about DetectorIDa as input to `read_ldata`
theHenks Aug 13, 2024
3557f61
Fix _can_convert_to for ChannelId
theHenks Aug 16, 2024
b64e871
Removed calfuncs.jl --> LegendSpecFIts.jl: only ljl_propfuncs
theHenks Aug 16, 2024
d143010
Add in and intervals to allowed expressions
theHenks Aug 20, 2024
c4d79c4
Add _ljlexpr_numbers for Inf, NaN, nothing and missing
theHenks Aug 21, 2024
58418b4
Dynamic selection of AoE pars cat and type
theHenks Aug 23, 2024
f636405
Fix AoE classifier pars access
theHenks Aug 23, 2024
37d841e
Parse nothing :err to be parsed as NaN uncertainty
theHenks Aug 23, 2024
e4b98e9
Bug fix error and debug messages
theHenks Aug 27, 2024
751bb23
Merge apply vectors with existing valdiity entries to prevent partiti…
theHenks Aug 27, 2024
f9a32ed
Allow symbols to be used in ljl_propfuncs
theHenks Aug 31, 2024
4828754
Include SiPM chdata output
theHenks Sep 2, 2024
30a1c67
Add LRU chaching for channelinfo
theHenks Sep 2, 2024
c256818
Include hitchsel propfunc for geds hitchannel propfunc selection
theHenks Sep 2, 2024
d50d2f0
DataCategory can only consist of 3 letters
theHenks Sep 3, 2024
d5a8d30
Allow read_ldata to be used without a channel argument
theHenks Sep 3, 2024
6c1f6d9
Fixed LRU cache for channelinfo with channel --> TODO: Fix bug
theHenks Sep 3, 2024
6c5b3e8
Fix runinfo Sub-Table, allow partitioninfo to also take IdLike inputs
theHenks Sep 5, 2024
7f941ab
partitioninfo can take more IdLike arguments + fixed runinfo Table
theHenks Sep 5, 2024
cb827e2
channelinfo can also take arguments as single arguments instead of on…
theHenks Sep 5, 2024
88c347e
Remove debug messages
theHenks Sep 5, 2024
80e7c8b
partitioninfo can be used to get the partiton for a specific run
theHenks Sep 5, 2024
0e138d6
Include Measurements functions for usage within ljl_profuncs
theHenks Sep 11, 2024
196343b
Merge branch `main` into `dev`
fhagemann Sep 11, 2024
824f6cb
Add functions to calculate active volume (credit to @bene73)
fhagemann Sep 9, 2024
65cd36b
Add option to calculate active volume in `channelinfo`
fhagemann Sep 10, 2024
26bdb96
Add tests for extended `channelinfo`
fhagemann Sep 10, 2024
a745081
Move more columns of `channelinfo` to `detailed`
fhagemann Sep 10, 2024
f5a5fe4
Rename keyword in `channelinfo`: `detailed` --> `extended`
fhagemann Sep 10, 2024
82bc004
Add units to return value of `get_active_volume`
fhagemann Sep 11, 2024
154bc01
Improve tests for `channelinfo` column names
fhagemann Sep 11, 2024
70a4ff4
Add tests to compare `active_volume` output to SSD
fhagemann Sep 11, 2024
f631749
Merge pull request #63 from fhagemann/dev
fhagemann Sep 17, 2024
bede46d
Implement active volume calculation for cracks
apearsonn Sep 18, 2024
39b7827
Create config dicts from LEGEND metadata
bene73 Sep 18, 2024
21618c5
Add handling of `fccd` for crack volume calculations
fhagemann Sep 18, 2024
dd8a76a
Use `fccd` value in active volume calculation
fhagemann Sep 18, 2024
f5e52dc
Add keyword `dicttype` when creating SSD config file from metadata
fhagemann Sep 18, 2024
db4a390
Update tests for SSD extension
fhagemann Sep 18, 2024
8fa3ba8
Add handling of `fccd` for topgroove volume calculations
fhagemann Sep 18, 2024
654e749
Merge branch 'dev' of https://github.com/legend-exp/LegendDataManagem…
theHenks Sep 19, 2024
b948cfc
Add documentation for the SSD extension
fhagemann Sep 19, 2024
abb3159
Fix in parsing p+ contact
fhagemann Sep 19, 2024
7f2a917
Merge pull request #67 from bene73/refactor
fhagemann Sep 19, 2024
d3c7ea5
Merge pull request #66 from apearsonn/dev
fhagemann Sep 19, 2024
f0d2251
Fix typo in docs
fhagemann Sep 19, 2024
664e8fe
Merge branch 'main' into dev
fhagemann Sep 19, 2024
cd78332
Bug fix when parsing borehole tapers
fhagemann Sep 23, 2024
8be0c18
Merge pull request #70 from legend-exp/ssd
fhagemann Sep 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
*.jl.cov
*.jl.*.cov
*.jl.mem
*.lh5
.ipynb_checkpoints
Manifest.toml
7 changes: 3 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"

[weakdeps]
LegendHDF5IO = "c9265ca6-b027-5446-b1a4-febfa8dd10b0"
LegendDataTypes = "99e09c13-5545-5ee2-bfa2-77f358fb75d8"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
SolidStateDetectors = "71e43887-2bd9-5f77-aebd-47f656f0a3f0"

[extensions]
LegendDataManagementLegendHDF5IOExt = "LegendHDF5IO"
LegendDataManagementLegendHDF5IOExt = ["LegendHDF5IO", "LegendDataTypes"]
LegendDataManagementPlotsExt = ["RecipesBase", "Plots"]
LegendDataManagementSolidStateDetectorsExt = "SolidStateDetectors"

Expand All @@ -47,6 +48,7 @@ Format = "1"
Glob = "1"
IntervalSets = "0.6, 0.7"
JSON = "0.21, 1"
LegendDataTypes = "0.1.13"
LRUCache = "1.5"
LegendHDF5IO = "0.1.14"
LinearAlgebra = "1"
Expand All @@ -70,6 +72,3 @@ TypedTables = "1.4"
UUIDs = "1"
Unitful = "1"
julia = "1.10"

[extras]
LegendHDF5IO = "c9265ca6-b027-5446-b1a4-febfa8dd10b0"
51 changes: 50 additions & 1 deletion docs/src/extensions.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,42 @@
# Extensions

## `LegendHDF5IO` extension

LegendDataManagment provides an extension for [LegendHDF5IO](https://github.com/legend-exp/LegendHDF5IO.jl).
This makes it possible to directly load LEGEND data from HDF5 files via the `read_ldata` function. The extension is automatically loaded when both packages are loaded.
Example (requires a `$LEGEND_DATA_CONFIG` environment variable pointing to a legend data-config file):

```julia
using LegendDataManagement, LegendHDF5IO
l200 = LegendData(:l200)
filekeys = search_disk(FileKey, l200.tier[:jldsp, :cal, :p03, :r000])

chinfo = channelinfo(l200, (:p03, :r000, :cal); system=:geds, only_processable=true)

ch = chinfo[1].channel

dsp = read_ldata(l200, :jldsp, first(filekeys), ch)
dsp = read_ldata(l200, :jldsp, :cal, :p03, :r000, ch)
dsp = read_ldata((:e_cusp, :e_trap, :blmean, :blslope), l200, :jldsp, :cal, :p03, :r000, ch)
```
`read_ldata` automitcally loads LEGEND data for a specific `DataTier` and data selection like e.g. a `FileKey` or a run-selection based for a given `ChannelId`. The `search_disk` function allows the user to search for available `DataTier` and `FileKey` on disk. The first argument can be either a selection of keys in form of a `NTuple` of `Symbol` or a [PropertyFunction](https://github.com/oschulz/PropertyFunctions.jl/tree/main) which will be applied during loading.
It is also possible to load whole a `DataPartition` or `DataPeriod` for a given `ChannelId` ch:
```julia
dsp = read_ldata(l200, :jldsp, :cal, DataPartition(1), ch)
dsp = read_ldata(l200, :jldsp, :cal, DataPeriod(3), ch)
```
In additon, it is possible to load a random selection of `n_evts` events randomly selected from each loaded file:
```julia
dsp = read_ldata(l200, :jldsp, :cal, :p03, :r000, ch; n_evts=1000)
```
For simplicity, the ch can also be given as a `DetectorID` which will be converted internally to a `ChannelId`:
```julia
det = chinfo[1].detector
dsp = read_ldata(l200, :jldsp, :cal, :p03, :r000, det)
```
## `SolidStateDetectors` extension

LegendDataManagment provides an extension for [SolidStateDetectors](https://github.com/JuliaPhysics/SolidStateDetectors.jl). This makes it possible to create `SolidStateDetector` instances from LEGEND metadata.
LegendDataManagment provides an extension for [SolidStateDetectors](https://github.com/JuliaPhysics/SolidStateDetectors.jl). This makes it possible to create `SolidStateDetector` and `Simulation` instances from LEGEND metadata.

Example (requires a `$LEGEND_DATA_CONFIG` environment variable pointing to a legend data-config file):

Expand All @@ -18,6 +52,21 @@ A detector can also be constructed using the filename of the LEGEND metadata det
det = SolidStateDetector(LegendData, "V99000A.json")
```

In addition, when creating a `Simulation`, all simulation functions in SolidStateDetectors.jl can be applied. As usual, all fields stored in the `Simulation` can be written and read using `LegendHDF5IO`:

```julia
using LegendDataManagement
using SolidStateDetectors

sim = Simulation(LegendData, "V99000A.json")
simulate!(sim) # calculate electric field and weighting potentials

using LegendHDF5IO
ssd_write("V99000A.lh5", sim)
sim_in = ssd_read("V99000A.lh5", Simulation)
```


The following code will generate an overview plot of every 5th LEGEND detector (requires the actual LEGEND metadata instead of the metadata in legend-testdata):

```julia
Expand Down
185 changes: 182 additions & 3 deletions ext/LegendDataManagementLegendHDF5IOExt.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
module LegendDataManagementLegendHDF5IOExt

using LegendDataManagement
LegendDataManagement._lh5_ext_loaded(::Val{true}) = true

Check warning on line 4 in ext/LegendDataManagementLegendHDF5IOExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/LegendDataManagementLegendHDF5IOExt.jl#L4

Added line #L4 was not covered by tests
using LegendDataManagement.LDMUtils: detector2channel
using LegendDataManagement: RunCategorySelLike
using LegendHDF5IO
using LegendDataTypes: fast_flatten, flatten_by_key
using TypedTables, PropertyFunctions

# using LegendDataManagement: LegendDataManagement.DataSelector
const ChannelOrDetectorIdLike = Union{ChannelIdLike, DetectorIdLike}
const AbstractDataSelectorLike = Union{AbstractString, Symbol, DataTierLike, DataCategoryLike, DataPeriodLike, DataRunLike, DataPartitionLike, ChannelOrDetectorIdLike}
const PossibleDataSelectors = [DataTier, DataCategory, DataPeriod, DataRun, DataPartition, ChannelId, DetectorId]

function _get_channelid(data::LegendData, rsel::Union{AnyValiditySelection, RunCategorySelLike}, det::ChannelOrDetectorIdLike)
if LegendDataManagement._can_convert_to(ChannelId, det)
ChannelId(det)
elseif LegendDataManagement._can_convert_to(DetectorId, det)
detector2channel(data, rsel, det)

Check warning on line 19 in ext/LegendDataManagementLegendHDF5IOExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/LegendDataManagementLegendHDF5IOExt.jl#L15-L19

Added lines #L15 - L19 were not covered by tests
else
throw(ArgumentError("$det is neither a ChannelId nor a DetectorId"))

Check warning on line 21 in ext/LegendDataManagementLegendHDF5IOExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/LegendDataManagementLegendHDF5IOExt.jl#L21

Added line #L21 was not covered by tests
end
end

const dataselector_bytypes = Dict{Type, String}()

Expand Down Expand Up @@ -43,7 +60,7 @@

function LegendHDF5IO.LH5Array(ds::LegendHDF5IO.HDF5.Dataset,
::Type{<:AbstractArray{<:T, N}}) where {T <: LegendDataManagement.DataSelector, N}

s = read(ds)
T.(s)
end
Expand All @@ -68,4 +85,166 @@
(@isdefined DataPartition) && extend_datatype_dict(DataPartition, "datapartition")
end

end
function _lh5_data_open(f::Function, data::LegendData, tier::DataTierLike, filekey::FileKey, ch::ChannelIdLike, mode::AbstractString="r")
ch_filename = data.tier[DataTier(tier), filekey, ch]
filename = data.tier[DataTier(tier), filekey]
if isfile(ch_filename)
@debug "Read from $(basename(ch_filename))"
LegendHDF5IO.lh5open(f, ch_filename, mode)
elseif isfile(filename)
@debug "Read from $(basename(filename))"
LegendHDF5IO.lh5open(f, filename, mode)

Check warning on line 96 in ext/LegendDataManagementLegendHDF5IOExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/LegendDataManagementLegendHDF5IOExt.jl#L88-L96

Added lines #L88 - L96 were not covered by tests
else
throw(ArgumentError("Neither $(basename(filename)) nor $(basename(ch_filename)) found"))

Check warning on line 98 in ext/LegendDataManagementLegendHDF5IOExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/LegendDataManagementLegendHDF5IOExt.jl#L98

Added line #L98 was not covered by tests
end
end

_propfunc_columnnames(f::PropSelFunction{cols}) where cols = cols

Check warning on line 102 in ext/LegendDataManagementLegendHDF5IOExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/LegendDataManagementLegendHDF5IOExt.jl#L102

Added line #L102 was not covered by tests

_load_all_keys(nt::NamedTuple, n_evts::Int=-1) = if length(nt) == 1 _load_all_keys(nt[first(keys(nt))], n_evts) else NamedTuple{keys(nt)}(map(x -> _load_all_keys(nt[x], n_evts), keys(nt))) end
_load_all_keys(arr::AbstractArray, n_evts::Int=-1) = arr[:][if (n_evts < 1 || n_evts > length(arr)) 1:length(arr) else rand(1:length(arr), n_evts) end]
_load_all_keys(t::Table, n_evts::Int=-1) = t[:][if (n_evts < 1 || n_evts > length(t)) 1:length(t) else rand(1:length(t), n_evts) end]
_load_all_keys(x, n_evts::Int=-1) = x

Check warning on line 107 in ext/LegendDataManagementLegendHDF5IOExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/LegendDataManagementLegendHDF5IOExt.jl#L104-L107

Added lines #L104 - L107 were not covered by tests

function LegendDataManagement.read_ldata(f::Base.Callable, data::LegendData, rsel::Tuple{DataTierLike, FileKey, ChannelOrDetectorIdLike}; n_evts::Int=-1)
tier, filekey, ch = DataTier(rsel[1]), rsel[2], if !isempty(string((rsel[3]))) _get_channelid(data, rsel[2], rsel[3]) else rsel[3] end
_lh5_data_open(data, tier, filekey, ch) do h
if !isempty(string((ch))) && !haskey(h, "$ch")
throw(ArgumentError("Channel $ch not found in $(basename(string(h.data_store)))"))

Check warning on line 113 in ext/LegendDataManagementLegendHDF5IOExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/LegendDataManagementLegendHDF5IOExt.jl#L109-L113

Added lines #L109 - L113 were not covered by tests
end
if f == identity
if !isempty(string((ch)))
_load_all_keys(h[ch, tier], n_evts)

Check warning on line 117 in ext/LegendDataManagementLegendHDF5IOExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/LegendDataManagementLegendHDF5IOExt.jl#L115-L117

Added lines #L115 - L117 were not covered by tests
else
_load_all_keys(h[tier], n_evts)

Check warning on line 119 in ext/LegendDataManagementLegendHDF5IOExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/LegendDataManagementLegendHDF5IOExt.jl#L119

Added line #L119 was not covered by tests
end
elseif f isa PropSelFunction
if !isempty(string((ch)))
_load_all_keys(getproperties(_propfunc_columnnames(f)...)(h[ch, tier]), n_evts)

Check warning on line 123 in ext/LegendDataManagementLegendHDF5IOExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/LegendDataManagementLegendHDF5IOExt.jl#L121-L123

Added lines #L121 - L123 were not covered by tests
else
_load_all_keys(getproperties(_propfunc_columnnames(f)...)(h[tier]), n_evts)

Check warning on line 125 in ext/LegendDataManagementLegendHDF5IOExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/LegendDataManagementLegendHDF5IOExt.jl#L125

Added line #L125 was not covered by tests
end
else
result = if !isempty(string((ch)))
f.(_load_all_keys(h[ch, tier], n_evts))

Check warning on line 129 in ext/LegendDataManagementLegendHDF5IOExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/LegendDataManagementLegendHDF5IOExt.jl#L128-L129

Added lines #L128 - L129 were not covered by tests
else
f.(_load_all_keys(h[tier], n_evts))

Check warning on line 131 in ext/LegendDataManagementLegendHDF5IOExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/LegendDataManagementLegendHDF5IOExt.jl#L131

Added line #L131 was not covered by tests
end
if result isa AbstractVector{<:NamedTuple}
Table(result)

Check warning on line 134 in ext/LegendDataManagementLegendHDF5IOExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/LegendDataManagementLegendHDF5IOExt.jl#L133-L134

Added lines #L133 - L134 were not covered by tests
else
result

Check warning on line 136 in ext/LegendDataManagementLegendHDF5IOExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/LegendDataManagementLegendHDF5IOExt.jl#L136

Added line #L136 was not covered by tests
end
end
end
end

function LegendDataManagement.read_ldata(f::Base.Callable, data::LegendData, rsel::Tuple{DataTierLike, FileKey}; kwargs...)
ch_keys = _lh5_data_open(data, rsel[1], rsel[2], "") do h
keys(h)

Check warning on line 144 in ext/LegendDataManagementLegendHDF5IOExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/LegendDataManagementLegendHDF5IOExt.jl#L142-L144

Added lines #L142 - L144 were not covered by tests
end
@debug "Found keys: $ch_keys"
if length(ch_keys) == 1
if string(only(ch_keys)) == string(rsel[1])
LegendDataManagement.read_ldata(f, data, (rsel[1], rsel[2], ""); kwargs...)
elseif LegendDataManagement._can_convert_to(ChannelId, only(ch_keys)) || LegendDataManagement._can_convert_to(DetectorId, only(ch_keys))
LegendDataManagement.read_ldata(f, data, (rsel[1], rsel[2], string(only(ch_keys))); kwargs...)

Check warning on line 151 in ext/LegendDataManagementLegendHDF5IOExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/LegendDataManagementLegendHDF5IOExt.jl#L146-L151

Added lines #L146 - L151 were not covered by tests
else
throw(ArgumentError("No tierm channel or detector found in $(basename(string(h.data_store)))"))

Check warning on line 153 in ext/LegendDataManagementLegendHDF5IOExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/LegendDataManagementLegendHDF5IOExt.jl#L153

Added line #L153 was not covered by tests
end
else
NamedTuple{Tuple(Symbol.(ch_keys))}([LegendDataManagement.read_ldata(f, data, (rsel[1], rsel[2], ch); kwargs...) for ch in ch_keys]...)

Check warning on line 156 in ext/LegendDataManagementLegendHDF5IOExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/LegendDataManagementLegendHDF5IOExt.jl#L156

Added line #L156 was not covered by tests
end
end

lflatten(x) = fast_flatten(x)

Check warning on line 160 in ext/LegendDataManagementLegendHDF5IOExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/LegendDataManagementLegendHDF5IOExt.jl#L160

Added line #L160 was not covered by tests
# lflatten(t::AbstractVector{<:Table}) = append!(t...)
lflatten(nt::AbstractVector{<:NamedTuple}) = flatten_by_key(nt)

Check warning on line 162 in ext/LegendDataManagementLegendHDF5IOExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/LegendDataManagementLegendHDF5IOExt.jl#L162

Added line #L162 was not covered by tests

function LegendDataManagement.read_ldata(f::Base.Callable, data::LegendData, rsel::Tuple{DataTierLike, AbstractVector{FileKey}, ChannelOrDetectorIdLike}; kwargs...)
if !isempty(string(rsel[3]))
lflatten([LegendDataManagement.read_ldata(f, data, (rsel[1], fk, rsel[3]); kwargs...) for fk in rsel[2]])

Check warning on line 166 in ext/LegendDataManagementLegendHDF5IOExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/LegendDataManagementLegendHDF5IOExt.jl#L164-L166

Added lines #L164 - L166 were not covered by tests
else
lflatten([LegendDataManagement.read_ldata(f, data, (rsel[1], fk); kwargs...) for fk in rsel[2]])

Check warning on line 168 in ext/LegendDataManagementLegendHDF5IOExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/LegendDataManagementLegendHDF5IOExt.jl#L168

Added line #L168 was not covered by tests
end
end
LegendDataManagement.read_ldata(f::Base.Callable, data::LegendData, rsel::Tuple{DataTierLike, AbstractVector{FileKey}}; kwargs...) =

Check warning on line 171 in ext/LegendDataManagementLegendHDF5IOExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/LegendDataManagementLegendHDF5IOExt.jl#L171

Added line #L171 was not covered by tests
LegendDataManagement.read_ldata(f, data, (rsel[1], rsel[2], ""); kwargs...)

### Argument distinction for different DataSelector Types
function _convert_rsel2dsel(rsel::NTuple{<:Any, AbstractDataSelectorLike})
selector_types = [PossibleDataSelectors[LegendDataManagement._can_convert_to.(PossibleDataSelectors, Ref(s))] for s in rsel]
if length(selector_types[2]) > 1 && DataCategory in selector_types[2]
selector_types[2] = [DataCategory]

Check warning on line 178 in ext/LegendDataManagementLegendHDF5IOExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/LegendDataManagementLegendHDF5IOExt.jl#L175-L178

Added lines #L175 - L178 were not covered by tests
end
if isempty(last(selector_types))
selector_types[end] = [String]

Check warning on line 181 in ext/LegendDataManagementLegendHDF5IOExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/LegendDataManagementLegendHDF5IOExt.jl#L180-L181

Added lines #L180 - L181 were not covered by tests
end
if !all(length.(selector_types) .<= 1)
throw(ArgumentError("Ambiguous selector types: $selector_types for $rsel"))

Check warning on line 184 in ext/LegendDataManagementLegendHDF5IOExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/LegendDataManagementLegendHDF5IOExt.jl#L183-L184

Added lines #L183 - L184 were not covered by tests
end
Tuple([only(st)(r) for (r, st) in zip(rsel, selector_types)])

Check warning on line 186 in ext/LegendDataManagementLegendHDF5IOExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/LegendDataManagementLegendHDF5IOExt.jl#L186

Added line #L186 was not covered by tests
end

function LegendDataManagement.read_ldata(f::Base.Callable, data::LegendData, rsel::NTuple{<:Any, AbstractDataSelectorLike}; kwargs...)
LegendDataManagement.read_ldata(f, data, _convert_rsel2dsel(rsel); kwargs...)

Check warning on line 190 in ext/LegendDataManagementLegendHDF5IOExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/LegendDataManagementLegendHDF5IOExt.jl#L189-L190

Added lines #L189 - L190 were not covered by tests
end

LegendDataManagement.read_ldata(f::Base.Callable, data::LegendData, rsel::Tuple{DataTier, DataCategory, DataPeriod}; kwargs...) =

Check warning on line 193 in ext/LegendDataManagementLegendHDF5IOExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/LegendDataManagementLegendHDF5IOExt.jl#L193

Added line #L193 was not covered by tests
LegendDataManagement.read_ldata(f, data, (DataTier(rsel[1]), DataCategory(rsel[2]), DataPeriod(rsel[3]), ""))

LegendDataManagement.read_ldata(f::Base.Callable, data::LegendData, rsel::Tuple{DataTier, DataCategory, DataPeriod, DataRun}; kwargs...) =

Check warning on line 196 in ext/LegendDataManagementLegendHDF5IOExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/LegendDataManagementLegendHDF5IOExt.jl#L196

Added line #L196 was not covered by tests
LegendDataManagement.read_ldata(f, data, (rsel[1], rsel[2], rsel[3], rsel[4], ""))


function LegendDataManagement.read_ldata(f::Base.Callable, data::LegendData, rsel::Tuple{DataTier, DataCategory, DataPartition, ChannelOrDetectorIdLike}; kwargs...)
first_run = first(LegendDataManagement._get_partitions(data, :default)[rsel[3]])
ch = _get_channelid(data, (first_run.period, first_run.run, rsel[2]), rsel[4])
pinfo = partitioninfo(data, ch, rsel[3])
@assert ch == _get_channelid(data, (first(pinfo).period, first(pinfo).run, rsel[2]), rsel[4]) "Channel mismatch in partitioninfo"
LegendDataManagement.read_ldata(f, data, (rsel[1], rsel[2], pinfo, ch); kwargs...)

Check warning on line 205 in ext/LegendDataManagementLegendHDF5IOExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/LegendDataManagementLegendHDF5IOExt.jl#L200-L205

Added lines #L200 - L205 were not covered by tests
end

function LegendDataManagement.read_ldata(f::Base.Callable, data::LegendData, rsel::Tuple{DataTier, DataCategory, DataPeriod, ChannelOrDetectorIdLike}; kwargs...)
rinfo = runinfo(data, rsel[3])
first_run = first(rinfo)
ch = if !isempty(string(rsel[4]))
_get_channelid(data, (first_run.period, first_run.run, rsel[2]), rsel[4])

Check warning on line 212 in ext/LegendDataManagementLegendHDF5IOExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/LegendDataManagementLegendHDF5IOExt.jl#L208-L212

Added lines #L208 - L212 were not covered by tests
else
string(rsel[4])

Check warning on line 214 in ext/LegendDataManagementLegendHDF5IOExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/LegendDataManagementLegendHDF5IOExt.jl#L214

Added line #L214 was not covered by tests
end
LegendDataManagement.read_ldata(f, data, (rsel[1], rsel[2], rinfo, ch); kwargs...)

Check warning on line 216 in ext/LegendDataManagementLegendHDF5IOExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/LegendDataManagementLegendHDF5IOExt.jl#L216

Added line #L216 was not covered by tests
end

function LegendDataManagement.read_ldata(f::Base.Callable, data::LegendData, rsel::Tuple{DataTier, DataCategory, DataPeriod, DataRun, ChannelOrDetectorIdLike}; kwargs...)
fks = search_disk(FileKey, data.tier[rsel[1], rsel[2], rsel[3], rsel[4]])
ch = rsel[5]
if isempty(fks) && isfile(data.tier[rsel[1:4]..., ch])
LegendDataManagement.read_ldata(f, data, (rsel[1], start_filekey(data, (rsel[3], rsel[4], rsel[2])), ch); kwargs...)
elseif !isempty(fks)
LegendDataManagement.read_ldata(f, data, (rsel[1], fks, ch); kwargs...)

Check warning on line 225 in ext/LegendDataManagementLegendHDF5IOExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/LegendDataManagementLegendHDF5IOExt.jl#L219-L225

Added lines #L219 - L225 were not covered by tests
else
throw(ArgumentError("No filekeys found for $(rsel[2]) $(rsel[3]) $(rsel[4])"))

Check warning on line 227 in ext/LegendDataManagementLegendHDF5IOExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/LegendDataManagementLegendHDF5IOExt.jl#L227

Added line #L227 was not covered by tests
end
end


### DataPartition
const _partinfo_required_cols = NamedTuple{(:period, :run), Tuple{DataPeriod, DataRun}}

LegendDataManagement.read_ldata(f::Base.Callable, data::LegendData, rsel::Tuple{DataTierLike, DataCategoryLike, Table{_partinfo_required_cols}, ChannelOrDetectorIdLike}; kwargs...) =

Check warning on line 235 in ext/LegendDataManagementLegendHDF5IOExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/LegendDataManagementLegendHDF5IOExt.jl#L235

Added line #L235 was not covered by tests
lflatten([LegendDataManagement.read_ldata(f, data, (rsel[1], rsel[2], r.period, r.run, rsel[4]); kwargs...) for r in rsel[3]])

LegendDataManagement.read_ldata(f::Base.Callable, data::LegendData, rsel::Tuple{DataTierLike, DataCategoryLike, Table{_partinfo_required_cols}}; kwargs...) =

Check warning on line 238 in ext/LegendDataManagementLegendHDF5IOExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/LegendDataManagementLegendHDF5IOExt.jl#L238

Added line #L238 was not covered by tests
LegendDataManagement.read_ldata(f, data, (rsel[1], rsel[2], rsel[3], ""); kwargs...)

function LegendDataManagement.read_ldata(f::Base.Callable, data::LegendData, rsel::Tuple{DataTierLike, DataCategoryLike, Table, ChannelOrDetectorIdLike}; kwargs...)
@assert (hasproperty(rsel[3], :period) && hasproperty(rsel[3], :run)) "Runtable doesn't provide periods and runs"
LegendDataManagement.read_ldata(f, data, (rsel[1], rsel[2], Table(period = rsel[3].period, run = rsel[3].run), rsel[4]); kwargs...)

Check warning on line 243 in ext/LegendDataManagementLegendHDF5IOExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/LegendDataManagementLegendHDF5IOExt.jl#L241-L243

Added lines #L241 - L243 were not covered by tests
end

LegendDataManagement.read_ldata(f::Base.Callable, data::LegendData, rsel::Tuple{DataTierLike, DataCategoryLike, Table}; kwargs...) =

Check warning on line 246 in ext/LegendDataManagementLegendHDF5IOExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/LegendDataManagementLegendHDF5IOExt.jl#L246

Added line #L246 was not covered by tests
LegendDataManagement.read_ldata(f, data, (rsel[1], rsel[2], rsel[3], ""); kwargs...)


end # module
Loading
Loading