Skip to content

Commit 7b2360e

Browse files
committed
Support of Measurements and MonteCarloMeasurements
1 parent 9297e33 commit 7b2360e

File tree

1 file changed

+56
-10
lines changed

1 file changed

+56
-10
lines changed

src/SignalTableFunctions.jl

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -260,22 +260,63 @@ end
260260
#TargetElType(::Type{Measurements.Measurement{T}}) where {T} = T
261261
#TargetElType(::Type{MonteCarloMeasurements.Particles{T,N}}) where {T,N} = T
262262
#TargetElType(::Type{MonteCarloMeasurements.StaticParticles{T,N}}) where {T,N} = T
263+
#=
264+
function basetypeWithMeasurements(obj)
265+
if typeof(obj) <: AbstractArray
266+
obj1 = obj[1]
267+
if eltype(obj1) <: Real
268+
println("... is Real")
269+
Tobj1 = typeof(obj1)
270+
if hasfield(Tobj1, :particles) # MonteCarloMeasurements
271+
btype = eltype(obj1.particles)
272+
elseif hasfield(Tobj1, :val) && hasfield(Tobj1, :err) # Measurements
273+
btype = typeof(obj1.val)
274+
else
275+
btype = basetype(obj)
276+
end
277+
end
278+
else
279+
btype = basetype(obj)
280+
end
281+
#catch
282+
# btype = basetype(obj)
283+
#end
284+
return btype
285+
end
263286
264287
function basetypeWithMeasurements(obj)
265-
btype = basetype(obj)
266-
#if typeof(obj) <: AbstractArray
267-
# obj1 = obj[1]
268-
# if eltype(obj1) <: Real
269-
# if hasfield(obj1, :particles) # MonteCarloMeasurements
270-
# btype = eltype(obj1.particles)
271-
# elseif hasfield(obj1, :val) && hasfield(obj1, :err) # Measurements
272-
# btype = typeof(obj1.val)
273-
# end
274-
# end
288+
obj_eltype = eltype(obj)
289+
if obj_eltype <: Real
290+
if hasfield(obj_eltype, :particles) # MonteCarloMeasurements
291+
btype = eltype(obj1.particles)
292+
elseif hasfield(Tobj1, :val) && hasfield(Tobj1, :err) # Measurements
293+
btype = typeof(obj1.val)
294+
else
295+
btype = basetype(obj)
296+
end
297+
end
298+
else
299+
btype = basetype(obj)
300+
end
301+
#catch
302+
# btype = basetype(obj)
275303
#end
276304
return btype
277305
end
306+
=#
278307

308+
function basetypeWithMeasurements(obj)
309+
obj1 = typeof(obj) <: AbstractArray ? obj[1] : obj
310+
Tobj1 = typeof(obj1)
311+
if hasfield(Tobj1, :particles) # MonteCarloMeasurements
312+
btype = eltype(obj1.particles)
313+
elseif hasfield(Tobj1, :val) && hasfield(Tobj1, :err) # Measurements
314+
btype = typeof(obj1.val)
315+
else
316+
btype = basetype(obj)
317+
end
318+
return btype
319+
end
279320

280321
function getValuesFromPar(signal, len::Int)
281322
sigValue = signal[:value]
@@ -323,6 +364,11 @@ Legend is a vector of strings that provides a description for every array column
323364
(e.g. if `"name=a.b.c[2,3:5]", unit="m/s"`, then `legend = ["a.b.c[2,3] [m/s]", "a.b.c[2,3] [m/s]", "a.b.c[2,5] [m/s]"]`.
324365
325366
If the required transformation is not possible, a warning message is printed and `nothing` is returned.
367+
368+
As a special case, if signal[:values] is a vector or signal[:value] is a scalar and
369+
an element of values or value is of type `Measurements{targetFloat}` or
370+
`MonteCarloMeasurements{targetFloat}`, then the signal is not transformed and
371+
flattenedSignal = getValues(signalTable,name) or getValue(signalTable,name).
326372
"""
327373
function getFlattenedSignal(signalTable, name::String;
328374
missingToNaN = true,

0 commit comments

Comments
 (0)