1-
2- # #==============================================================================
3- # # Blobentry - compare
4- # #==============================================================================
5-
6- import Base: ==
7-
8- @generated function == (x:: T , y:: T ) where {T <: Blobentry }
9- return mapreduce (n -> :(x.$ n == y.$ n), (a, b) -> :($ a && $ b), fieldnames (x))
10- end
11-
121# #==============================================================================
132# # Blobentry - common
143# #==============================================================================
@@ -85,49 +74,26 @@ Finds and returns the first blob entry that matches the filter.
8574
8675Also see: [`getBlobentry`](@ref)
8776"""
88- function getfirstBlobentry (var:: AbstractGraphVariable , blobId:: UUID )
89- for (k, v) in var. dataDict
90- if blobId == v. blobId
91- return v
92- end
93- end
94- throw (KeyError (" No blobEntry with blobId $(blobId) found in variable $(getLabel (var)) " ))
95- end
96-
97- function getfirstBlobentry (dfg:: AbstractDFG , label:: Symbol , blobId:: UUID )
98- return getfirstBlobentry (getVariable (dfg, label), blobId)
99- end
100-
101- function getfirstBlobentry (var:: AbstractGraphVariable , key:: Regex )
102- for (k, v) in var. dataDict
103- if occursin (key, string (v. label))
104- return v
105- end
106- end
107- throw (
108- KeyError (
109- " No blobEntry with label matching regex $(key) found in variable $(getLabel (var)) " ,
110- ),
111- )
112- end
113-
114- function getfirstBlobentry (var:: VariableDFG , key:: Regex )
115- firstIdx = findfirst (x -> contains (string (x. label), key), var. blobEntries)
116- if isnothing (firstIdx)
117- throw (KeyError (" $key " ))
77+ function getfirstBlobentry (
78+ v:: AbstractGraphVariable ;
79+ labelFilter:: Union{Nothing, Function} = nothing ,
80+ blobIdFilter:: Union{Nothing, Function} = nothing ,
81+ )
82+ entries = getBlobentries (v; labelFilter, blobIdFilter)
83+ if isempty (entries)
84+ return nothing
85+ else
86+ return entries[1 ]
11887 end
119- return var. blobEntries[firstIdx]
12088end
12189
122- function getfirstBlobentry (dfg:: AbstractDFG , label:: Symbol , key:: Regex )
123- els = listBlobentries (dfg, label)
124- firstIdx = findfirst (contains (key), string .(els))
125- isnothing (firstIdx) && throw (
126- KeyError (
127- " No blobEntry with label matching regex $(key) found in variable $(label) " ,
128- ),
129- )
130- return getBlobentry (dfg, label, els[firstIdx])
90+ function getfirstBlobentry (
91+ dfg:: AbstractDFG ,
92+ label:: Symbol ;
93+ labelFilter:: Union{Nothing, Function} = nothing ,
94+ blobIdFilter:: Union{Nothing, Function} = nothing ,
95+ )
96+ return getfirstBlobentry (getVariable (dfg, label); labelFilter, blobIdFilter)
13197end
13298
13399# TODO Consider autogenerating all methods of the form:
@@ -140,22 +106,18 @@ end
140106# @eval DistributedFactorGraphs $met(dfg::AbstractDFG, label::Symbol, args...; kwargs...) = $met(getVariable(dfg, label), args...; kwargs...)
141107# end
142108
143- function getBlobentry (dfg:: AbstractDFG , label :: Symbol , key :: Symbol )
144- return getBlobentry (getVariable (dfg, label ), key )
109+ function getBlobentry (dfg:: AbstractDFG , varLabel :: Symbol , label :: Symbol )
110+ return getBlobentry (getVariable (dfg, varLabel ), label )
145111end
146- # getBlobentry(dfg::AbstractDFG, label::Symbol, key::Symbol) = getBlobentry(getVariable(dfg, label), key)
147112
148113"""
149114 $(SIGNATURES)
150- Add Data Entry to a DFG variable
115+ Add a `Blobentry` to a variable
151116Should be extended if DFG variable is not returned by reference.
152117
153- Also see: [`getBlobentry`](@ref), [`addBlob!`](@ref), [`mergeBlobentries !`](@ref)
118+ Also see: [`getBlobentry`](@ref), [`addBlob!`](@ref), [`mergeBlobentry !`](@ref)
154119"""
155- function addBlobentry! (var:: AbstractGraphVariable , entry:: Blobentry )
156- # see https://github.com/JuliaRobotics/DistributedFactorGraphs.jl/issues/985
157- # blobId::Union{UUID,Nothing} = (isnothing(entry.blobId) ? entry.id : entry.blobId),
158- # blobSize::Int = (hasfield(Blobentry, :size) ? entry.size : -1)
120+ function addBlobentry! (var:: VariableCompute , entry:: Blobentry )
159121 haskey (var. dataDict, entry. label) && throw (LabelExistsError (" Blobentry" , entry. label))
160122 var. dataDict[entry. label] = entry
161123 return entry
@@ -197,37 +159,28 @@ end
197159
198160"""
199161 $(SIGNATURES)
200- Delete a blob entry from the factor graph.
201- Note this doesn't remove it from any data stores.
162+ Delete a `Blobentry` from the factor graph variable.
202163
203164Notes:
204- - users responsibility to delete data in db before deleting entry
165+ - This doesn't remove the associated `Blob` from any Blobstores.
205166"""
206- function deleteBlobentry! (var:: AbstractGraphVariable , key:: Symbol )
207- pop! (var. dataDict, key)
167+ function deleteBlobentry! (var:: VariableCompute , key:: Symbol )
168+ ! hasBlobentry (var, key) && throw (LabelNotFoundError (" Blobentry" , key))
169+ delete! (var. dataDict, key)
208170 return 1
209171end
210172
211173function deleteBlobentry! (var:: VariableDFG , key:: Symbol )
212- if ! hasBlobentry (var, key)
213- throw (
214- KeyError (
215- " No dataEntry label $(key) found in variable $(getLabel (var)) . Available keys: $(keys (var. dataDict)) " ,
216- ),
217- )
218- end
174+ ! hasBlobentry (var, key) && throw (LabelNotFoundError (" Blobentry" , key))
219175 deleteat! (var. blobEntries, findfirst (x -> x. label == key, var. blobEntries))
220176 return 1
221177end
222178
223179function deleteBlobentry! (dfg:: AbstractDFG , label:: Symbol , key:: Symbol )
224- # users responsibility to delete data in db before deleting entry
225- # !isVariable(dfg, label) && return nothing
226180 return deleteBlobentry! (getVariable (dfg, label), key)
227181end
228182
229183function deleteBlobentry! (var:: AbstractGraphVariable , entry:: Blobentry )
230- # users responsibility to delete data in db before deleting entry
231184 return deleteBlobentry! (var, entry. label)
232185end
233186
@@ -240,73 +193,66 @@ end
240193
241194Does a blob entry exist with `blobLabel`.
242195"""
243- hasBlobentry (var:: AbstractGraphVariable , blobLabel:: Symbol ) =
244- haskey (var. dataDict, blobLabel)
196+ hasBlobentry (v:: VariableCompute , blobLabel:: Symbol ) = haskey (v. dataDict, blobLabel)
245197
246- function hasBlobentry (var :: VariableDFG , label:: Symbol )
247- return label in getproperty .(var . blobEntries, :label )
198+ function hasBlobentry (v :: VariableDFG , label:: Symbol )
199+ return label in getproperty .(v . blobEntries, :label )
248200end
249201
250202"""
251203 $(SIGNATURES)
252204
253- Get blob entries, Vector{Blobentry}
205+ Get blob entries, returns a ` Vector{Blobentry}`.
254206"""
255- function getBlobentries (var:: AbstractGraphVariable )
256- # or should we return the iterator, Base.ValueIterator{Dict{Symbol,Blobentry}}?
257- return collect (values (var. dataDict))
207+ function getBlobentries (v:: VariableCompute )
208+ return collect (values (v. dataDict))
258209end
259210
260- function getBlobentries (var :: VariableDFG )
261- return var . blobEntries
211+ function getBlobentries (v :: VariableDFG )
212+ return copy (v . blobEntries)
262213end
263214
264- function getBlobentries (dfg:: AbstractDFG , label:: Symbol )
265- # !isVariable(dfg, label) && return nothing
266- # or should we return the iterator, Base.ValueIterator{Dict{Symbol,Blobentry}}?
267- return getBlobentries (getVariable (dfg, label))
268- end
269-
270- function getBlobentries (dfg:: AbstractDFG , label:: Symbol , regex:: Regex )
271- entries = getBlobentries (dfg, label)
272- return filter (entries) do e
273- return occursin (regex, string (e. label))
274- end
215+ function getBlobentries (
216+ v:: AbstractGraphVariable ;
217+ labelFilter:: Union{Nothing, Function} = nothing ,
218+ blobIdFilter:: Union{Nothing, Function} = nothing ,
219+ )
220+ entries = getBlobentries (v)
221+ filterDFG! (entries, labelFilter, x -> string (x. label))
222+ filterDFG! (entries, blobIdFilter, x -> string (x. blobId))
223+ return entries
275224end
276225
277226function getBlobentries (
278227 dfg:: AbstractDFG ,
279- label:: Symbol ,
280- skey:: Union{Symbol, <:AbstractString} ,
228+ variableLabel:: Symbol ;
229+ labelFilter:: Union{Nothing, Function} = nothing ,
230+ blobIdFilter:: Union{Nothing, Function} = nothing ,
281231)
282- return getBlobentries (dfg, label, Regex ( string (skey)) )
232+ return getBlobentries (getVariable ( dfg, variableLabel); labelFilter, blobIdFilter )
283233end
284234
285- """
286- $(SIGNATURES)
287-
288- Get all blob entries matching a Regex pattern over variables
289-
290- Notes
291- - Use `dropEmpties=true` to not include empty lists in result.
292- - Use keyword `varList` for which variables to search through.
293- """
294- function getBlobentriesVariables (
295- dfg:: AbstractDFG ,
296- bLblPattern:: Regex ;
297- varList:: AbstractVector{Symbol} = sort (listVariables (dfg); lt = natural_lt),
298- dropEmpties:: Bool = false ,
235+ function gatherBlobentries (
236+ dfg:: AbstractDFG ;
237+ labelFilter:: Union{Nothing, Function} = nothing ,
238+ blobIdFilter:: Union{Nothing, Function} = nothing ,
239+ solvableFilter:: Union{Nothing, Function} = nothing ,
240+ tagsFilter:: Union{Nothing, Function} = nothing ,
241+ typeFilter:: Union{Nothing, Function} = nothing ,
242+ variableLabelFilter:: Union{Nothing, Function} = nothing ,
299243)
300- RETLIST = Vector {Vector{Blobentry}} ()
301- @showprogress " Get entries matching $bLblPattern " for vl in varList
302- bes = filter (s -> occursin (bLblPattern, string (s. label)), listBlobentries (dfg, vl))
303- # only push to list if there are entries on this variable
304- (! dropEmpties || 0 < length (bes)) ? nothing : continue
305- push! (RETLIST, bes)
244+ vls = listVariables (
245+ dfg;
246+ solvableFilter,
247+ tagsFilter,
248+ typeFilter,
249+ labelFilter = variableLabelFilter,
250+ )
251+ return map (vls) do vl
252+ return vl => getBlobentries (dfg, vl; labelFilter, blobIdFilter)
306253 end
307-
308- return RETLIST
309254end
255+ const collectBlobentries = gatherBlobentries
310256
311257"""
312258 $(SIGNATURES)
@@ -321,7 +267,6 @@ function listBlobentries(var::VariableDFG)
321267end
322268
323269function listBlobentries (dfg:: AbstractDFG , label:: Symbol )
324- # !isVariable(dfg, label) && return nothing
325270 return listBlobentries (getVariable (dfg, label))
326271end
327272
@@ -357,66 +302,6 @@ function listBlobentrySequence(
357302 return ents_[findall (entMsk)] |> _sort
358303end
359304
360- """
361- $SIGNATURES
362-
363- Add a blob entry into the destination variable which already exists
364- in a source variable.
365-
366- See also: [`addBlobentry!`](@ref), [`getBlobentry`](@ref), [`listBlobentries`](@ref), [`getBlob`](@ref)
367- """
368- function mergeBlobentries! (
369- dst:: AbstractDFG ,
370- dlbl:: Symbol ,
371- src:: AbstractDFG ,
372- slbl:: Symbol ,
373- bllb:: Union{Symbol, UUID, <:AbstractString, Regex} ,
374- )
375- #
376- _makevec (s) = [s;]
377- _makevec (s:: AbstractVector ) = s
378- des_ = getBlobentry (src, slbl, bllb)
379- des = _makevec (des_)
380- # don't add data entries that already exist
381- dde = listBlobentries (dst, dlbl)
382- # HACK, verb list should just return vector of Symbol. NCE36
383- _getid (s) = s
384- _getid (s:: Blobentry ) = s. id
385- uids = _getid .(dde) # (s->s.id).(dde)
386- filter! (s -> ! (_getid (s) in uids), des)
387- # add any data entries not already in the destination variable, by uuid
388- return addBlobentry! .(dst, dlbl, des)
389- end
390-
391- function mergeBlobentries! (
392- dst:: AbstractDFG ,
393- dlbl:: Symbol ,
394- src:: AbstractDFG ,
395- slbl:: Symbol ,
396- :: Colon = :,
397- )
398- des = listBlobentries (src, slbl)
399- # don't add data entries that already exist
400- uids = listBlobentries (dst, dlbl)
401- # verb list should just return vector of Symbol. NCE36
402- filter! (s -> ! (s in uids), des)
403- if 0 < length (des)
404- union (((s -> mergeBlobentries! (dst, dlbl, src, slbl, s)). (des)). .. )
405- end
406- end
407-
408- function mergeBlobentries! (
409- dest:: AbstractDFG ,
410- src:: AbstractDFG ,
411- w... ;
412- varList:: AbstractVector = listVariables (dest) |> sortDFG,
413- )
414- @showprogress 1 " merging data entries" for vl in varList
415- mergeBlobentries! (dest, vl, src, vl, w... )
416- end
417- return varList
418- end
419-
420305"""
421306 $SIGNATURES
422307
0 commit comments