Skip to content

Commit bd5a9a3

Browse files
committed
fetchData and docs
1 parent 37bb5f4 commit bd5a9a3

File tree

2 files changed

+71
-4
lines changed

2 files changed

+71
-4
lines changed

src/BigData/services/AbstractBigDataEntries.jl

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ addDataEntry!(x...) = addBigDataEntry!(x...)
4141
$(SIGNATURES)
4242
Add Big Data Entry to distributed factor graph.
4343
Should be extended if DFG variable is not returned by reference.
44+
45+
Example
46+
47+
See docs for `getDataEntryElement`.
48+
49+
Related
50+
51+
addData!, getDataEntryElement, fetchData
4452
"""
4553
function addDataEntry!(dfg::AbstractDFG,
4654
lbl::Symbol,
@@ -51,12 +59,13 @@ function addDataEntry!(dfg::AbstractDFG,
5159
#
5260
node = isVariable(dfg, lbl) ? getVariable(dfg, lbl) : getFactor(dfg, lbl)
5361
# Make a big data entry in the graph - use JSON2 to just write this
54-
element = GeneralBigDataEntry(dfg, node, descr, mimeType=mimeType)
62+
entry = GeneralBigDataEntry(dfg, node, descr, mimeType=mimeType)
5563
# Set it in the store
56-
addBigData!(datastore, element, data)
64+
addBigData!(datastore, entry, data)
5765
# Add the entry to the graph
58-
addBigDataEntry!(node, element)
66+
addBigDataEntry!(node, entry)
5967
end
68+
const addData! = addDataEntry!
6069

6170
"""
6271
$SIGNATURES
@@ -79,9 +88,63 @@ function getBigDataEntry(dfg::AbstractDFG, label::Symbol, key::Symbol)
7988
return getBigDataEntry(getVariable(dfg, label), key)
8089
end
8190

91+
"""
92+
$SIGNATURES
93+
Get both the entry and raw data element from datastore returning as a tuple.
94+
95+
Notes:
96+
- This is the counterpart to `addDataEntry!`.
97+
- Data is identified by the node in the DFG object `dfglabel::Symbol` as well as `datalabel::Symbol`.
98+
- The data should have been stored along with a `entry.mimeType::String` which describes the format of the data.
99+
- ImageMagick.jl is useful for storing images in png or jpg compressed format.
100+
101+
Example
102+
103+
```julia
104+
# some dfg object
105+
fg = initfg()
106+
addVariable!(fg, :x0, IIF.ContinuousScalar) # using IncrementalInference
107+
# FileDataStore (as example)
108+
datastore = FileDataStore(joinLogPath(fg,"datastore"))
109+
110+
# now some data comes in
111+
mydata = Dict(:soundBite => randn(Float32, 10000), :meta => "something about lazy foxes and fences.")
112+
113+
# store the data
114+
addDataEntry!( fg, :x0, datastore, :SOUND_DATA, "application/json", Vector{UInt8}(JSON2.write( mydata )) )
115+
116+
# get/fetch the data
117+
118+
# unpack data to original format (this must be done by the user)
119+
@show entry.mimeType # "applicatio/json"
120+
userFormat = JSON2.read(IOBuffer(rawData))
121+
```
122+
123+
Related
124+
125+
addDataEntry!, addData!, fetchData, fetchDataEntryElement
126+
"""
127+
function getDataEntryElement(dfg::AbstractDFG, dfglabel::Symbol, datastore::DataStore, datalabel::Symbol)
128+
vari = getVariable(dfg, dfglabel)
129+
if !hasDataEntry(vari, datalabel)
130+
@error "missing data entry $datalabel in $dfglabel"
131+
return nothing, nothing
132+
end
133+
entry = getBigDataEntry(vari, datalabel)
134+
element = getBigData(datastore, entry)
135+
return entry, element
136+
end
137+
const fetchDataEntryElement = getDataEntryElement
138+
const fetchData = getDataEntryElement
139+
140+
141+
82142
"""
83143
$(SIGNATURES)
84144
Update big data entry
145+
146+
DevNote
147+
- DF, unclear if `update` verb is applicable in this case, see #404
85148
"""
86149
function updateBigDataEntry!(var::AbstractDFGVariable, bde::AbstractBigDataEntry)
87150
!haskey(var.bigData,bde.key) && (@warn "$(bde.key) does not exist in variable, adding")

src/DistributedFactorGraphs.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,11 @@ export getNeighborhood, getNeighbors, _getDuplicatedEmptyDFG
165165
export copyGraph!, deepcopyGraph, deepcopyGraph!, buildSubgraph, mergeGraph!
166166
# Big Data
167167
##------------------------------------------------------------------------------
168-
export addBigDataEntry!, addDataEntry!, getBigDataEntry, updateBigDataEntry!, deleteBigDataEntry!, getBigDataEntries, getBigDataKeys, hasDataEntry, hasBigDataEntry
168+
export addBigDataEntry!, getBigDataEntry, updateBigDataEntry!, deleteBigDataEntry!, getBigDataEntries, getBigDataKeys, hasDataEntry, hasBigDataEntry
169+
# convenience wrappers
170+
export addDataEntry!, getDataEntryElement
171+
# aliases
172+
export addData!, fetchData, fetchDataEntryElement
169173

170174

171175
##------------------------------------------------------------------------------

0 commit comments

Comments
 (0)