@@ -41,6 +41,14 @@ addDataEntry!(x...) = addBigDataEntry!(x...)
41
41
$(SIGNATURES)
42
42
Add Big Data Entry to distributed factor graph.
43
43
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
44
52
"""
45
53
function addDataEntry! (dfg:: AbstractDFG ,
46
54
lbl:: Symbol ,
@@ -51,12 +59,13 @@ function addDataEntry!(dfg::AbstractDFG,
51
59
#
52
60
node = isVariable (dfg, lbl) ? getVariable (dfg, lbl) : getFactor (dfg, lbl)
53
61
# 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)
55
63
# Set it in the store
56
- addBigData! (datastore, element , data)
64
+ addBigData! (datastore, entry , data)
57
65
# Add the entry to the graph
58
- addBigDataEntry! (node, element )
66
+ addBigDataEntry! (node, entry )
59
67
end
68
+ const addData! = addDataEntry!
60
69
61
70
"""
62
71
$SIGNATURES
@@ -79,9 +88,68 @@ function getBigDataEntry(dfg::AbstractDFG, label::Symbol, key::Symbol)
79
88
return getBigDataEntry (getVariable (dfg, label), key)
80
89
end
81
90
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
+ entry, rawData = fetchData(fg, :x0, datastore, :SOUND_DATA)
118
+
119
+ # unpack data to original format (this must be done by the user)
120
+ @show entry.mimeType # "applicatio/json"
121
+ userFormat = JSON2.read(IOBuffer(rawData))
122
+ ```
123
+
124
+ Related
125
+
126
+ addDataEntry!, addData!, fetchData, fetchDataEntryElement
127
+ """
128
+ function getDataEntryElement (dfg:: AbstractDFG ,
129
+ dfglabel:: Symbol ,
130
+ datastore:: Union{FileDataStore, InMemoryDataStore} ,
131
+ datalabel:: Symbol )
132
+ #
133
+ vari = getVariable (dfg, dfglabel)
134
+ if ! hasDataEntry (vari, datalabel)
135
+ @error " missing data entry $datalabel in $dfglabel "
136
+ return nothing , nothing
137
+ end
138
+ entry = getBigDataEntry (vari, datalabel)
139
+ element = getBigData (datastore, entry)
140
+ return entry, element
141
+ end
142
+ const fetchDataEntryElement = getDataEntryElement
143
+ const fetchData = getDataEntryElement
144
+
145
+
146
+
82
147
"""
83
148
$(SIGNATURES)
84
149
Update big data entry
150
+
151
+ DevNote
152
+ - DF, unclear if `update` verb is applicable in this case, see #404
85
153
"""
86
154
function updateBigDataEntry! (var:: AbstractDFGVariable , bde:: AbstractBigDataEntry )
87
155
! haskey (var. bigData,bde. key) && (@warn " $(bde. key) does not exist in variable, adding" )
0 commit comments