Skip to content
Snippets Groups Projects
Verified Commit 3983e0fc authored by Tamas Gal's avatar Tamas Gal :speech_balloon:
Browse files

Improve error reporting on getindex of Detector

parent 0d7ed108
Branches
Tags
1 merge request!45Improve detector api
...@@ -298,8 +298,16 @@ function Base.iterate(d::Detector, state=(Int[], 1)) ...@@ -298,8 +298,16 @@ function Base.iterate(d::Detector, state=(Int[], 1))
end end
(d.modules[module_ids[count]], (module_ids, count + 1)) (d.modules[module_ids[count]], (module_ids, count + 1))
end end
Base.getindex(d::Detector, module_id::Integer) = d.modules[module_id] function Base.getindex(d::Detector, module_id::Integer)
Base.getindex(d::Detector, string::Integer, floor::Integer) = d.locations[string, floor] haskey(d.modules, module_id) && return d.modules[module_id]
error("Module with ID $(module_id) not found.")
end
function Base.getindex(d::Detector, string::Integer, floor::Integer)
haskey(d.locations, (string, floor)) && return d.locations[string, floor]
available_strings = join(d.strings, ", ", " and ")
!(hasstring(d, string)) && error("String $(string) not found. Available strings: $(available_strings).")
error("String $(string) has no module at floor $(floor).")
end
""" """
Return the detector module for a given module ID. Return the detector module for a given module ID.
""" """
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment