Skip to content

Commit

Permalink
Provide a script to update config files to v0.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
fhagemann committed Jul 29, 2021
1 parent 069b90f commit 0cb843a
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 34 deletions.
12 changes: 0 additions & 12 deletions src/IO/ParseConfigFiles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,6 @@ function parse_config_file(filename::AbstractString)::Dict{Any,Any}
else
error("Currently only .json and .yaml files are supported.")
end
@assert !haskey(dict, "objects") "Configuration file deprecation.\n
The configuration file format was updated in v0.6.0.
However, this configuration file still seems to be in the old format.\n
To update your configuration file to the new format (v0.6.0 and newer),
open a new Julia session and load the following file:\n
\tinclude(\"<path_to_SolidStateDetectors.jl>/test/update_config_files.jl\")\n
Afterwards, run\n
\tupdate_config_file(\"<path_to_configuration_file>\")\n
This method returns the file name of the updated configuration file.
Please close the Julia session after updating the configuration files, as some
parsing methods are overridden with old methods."

dict
end

Expand Down
2 changes: 1 addition & 1 deletion src/IO/Update.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function restructure_config_file_dict!(config_file_dict::AbstractDict, T::DataTy
delete!(contact, "type")
if "channel" in keys(contact)
contact["id"] = contact["channel"]
delete!(contact, "id")
delete!(contact, "channel")
end
update_geometry!(contact, T, update_units)
contact
Expand Down
55 changes: 38 additions & 17 deletions src/SolidStateDetector/SolidStateDetector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,26 +92,47 @@ function get_world_limits_from_objects(::Type{Cartesian}, det::SolidStateDetecto
end

function SolidStateDetector{T}(config_file::Dict, input_units::NamedTuple) where {T <: SSDFloat}
if haskey(config_file, "detectors")
config_detector = config_file["detectors"][1] # still only one detector

transformations = parse_CSG_transformation(T, config_detector, input_units)

@assert !haskey(config_file, "objects") "Configuration file deprecation.\n
The configuration file format was updated in v0.6.0.
However, this configuration file still seems to be in the old format.\n
To update your configuration file to the new format (v0.6.0 and newer),
open a new Julia session and load the following file:\n
\tinclude(\"<path_to_SolidStateDetectors.jl>/test/update_config_files.jl\")\n
Afterwards, run\n
\tupdate_config_file(\"<path_to_configuration_file>\")\n
This method returns the file name of the updated configuration file.
Please close the Julia session after updating the configuration files, as some
parsing methods are overridden with old methods.\n
Note that if your old geometries were defined using `difference`, you might
need to increase the dimensions of the subtracted geometry as it is now treated as
open primitive. Please have a look at the documentation:\n
\thttps://juliaphysics.github.io/SolidStateDetectors.jl/stable/\n"

@assert haskey(config_detector, "semiconductor") "Each detector needs an entry `semiconductor`. Please define the semiconductor."
semiconductor = Semiconductor{T}(config_detector["semiconductor"], input_units, transformations)
@assert haskey(config_file, "detectors") "Config file needs an entry `detectors` that defines the detector(s)."
config_detector = config_file["detectors"][1] # still only one detector

@assert haskey(config_detector, "contacts") "Each detector needs at least two contacts. Please define the them in the configuration file."
contacts = broadcast(c -> Contact{T}(c, input_units, transformations), config_detector["contacts"])

virtual_drift_volumes = if haskey(config_detector, "virtual_drift_volumes")
broadcast(v -> construct_virtual_volume(T, v, input_units, transformations), config_detector["virtual_drift_volumes"])
else
missing
end
transformations = parse_CSG_transformation(T, config_detector, input_units)

@assert haskey(config_detector, "semiconductor") "Each detector needs an entry `semiconductor`. Please define the semiconductor."
semiconductor = Semiconductor{T}(config_detector["semiconductor"], input_units, transformations)

@assert haskey(config_detector, "contacts") "Each detector needs at least two contacts. Please define the them in the configuration file."
contacts = broadcast(c -> Contact{T}(c, input_units, transformations), config_detector["contacts"])

passives = []
if haskey(config_detector, "passives") # "passives" as entry of "detectors"
append!(passives, broadcast(p -> Passive{T}(p, input_units, transformations), config_detector["passives"]))
end
if haskey(config_file, "surroundings") # "surroundings" as entry in the configuration file
append!(passives, broadcast(p -> Passive{T}(p, input_units, parse_CSG_transformation(T, p, input_units)), config_file["surroundings"]))
end
passives = if haskey(config_file, "surroundings")
config_surroundings = config_file["surroundings"]
broadcast(p -> Passive{T}(p, input_units, parse_CSG_transformation(T, p, input_units)), config_file["surroundings"])
if isempty(passives)
passives = missing
end

virtual_drift_volumes = if haskey(config_detector, "virtual_drift_volumes")
broadcast(v -> construct_virtual_volume(T, v, input_units, transformations), config_detector["virtual_drift_volumes"])
else
missing
end
Expand Down
8 changes: 4 additions & 4 deletions src/SolidStateDetector/VirtualVolumes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ function modulate_driftvector(sv::CartesianVector{T}, pt::CartesianPoint{T}, tl:
return CartesianVector{T}(0,0,0)
end

function DeadVolume{T}(dict::Dict, input_units::NamedTuple, transformations = missing) where T <: SSDFloat
function DeadVolume{T}(dict::Dict, input_units::NamedTuple, transformations::Transformations) where T <: SSDFloat
n = haskey(dict, "name") ? dict["name"] : "external part"
g = transform(Geometry(T, dict["geometry"], input_units), transformations)
g = Geometry(T, dict["geometry"], input_units, transformations)
return DeadVolume{T, typeof(g)}(n, g)
end

Expand All @@ -73,9 +73,9 @@ function modulate_driftvector(sv::CartesianVector{T}, pt::CartesianPoint{T}, tl:
end


function ArbitraryDriftModificationVolume{T}(dict::Dict, input_units::NamedTuple, transformations = missing) where T <: SSDFloat
function ArbitraryDriftModificationVolume{T}(dict::Dict, input_units::NamedTuple, transformations::Transformations) where T <: SSDFloat
n = haskey(dict, "name") ? dict["name"] : "external part"
g = transform(Geometry(T, dict["geometry"], input_units), transformations)
g = Geometry(T, dict["geometry"], input_units, transformations)
id = Int(dict["id"])
return ArbitraryDriftModificationVolume{T}(n, id, g)
end
Expand Down

2 comments on commit 0cb843a

@fhagemann
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/41784

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.6.0 -m "<description of version>" 0cb843a24012ea83d0dff03965ff83787e4166d4
git push origin v0.6.0

Please sign in to comment.