1 |
mojays |
2 |
package appl.parallel.data.xulugridfile; |
2 |
|
|
|
3 |
|
|
import java.awt.Rectangle; |
4 |
|
|
import java.io.File; |
5 |
|
|
import java.io.FileNotFoundException; |
6 |
|
|
|
7 |
|
|
import schmitzm.data.WritableGrid; |
8 |
|
|
import appl.data.DataLoader; |
9 |
|
|
import appl.data.WritableGridLLProxy; |
10 |
|
|
import appl.parallel.spmd.split.DataPartition; |
11 |
|
|
import appl.parallel.spmd.split.SplittableGrid; |
12 |
|
|
import appl.parallel.spmd.split.SplittableResource; |
13 |
|
|
import appl.util.RasterMetaData; |
14 |
|
|
|
15 |
|
|
/** |
16 |
|
|
* An implementation of a WritableGrid based on a {@link XuluGridFile}. |
17 |
|
|
* |
18 |
|
|
* @author Dominik Appl |
19 |
|
|
*/ |
20 |
|
|
public class XuluWritableGridFile extends WritableGridLLProxy implements SplittableGrid{ |
21 |
|
|
|
22 |
|
|
private XuluGridFile gridFile; |
23 |
|
|
private boolean wasWriteAccessed = false; |
24 |
|
|
private final String directory; |
25 |
|
|
private int rootID = this.hashCode(); |
26 |
|
|
private final File baseFile; |
27 |
|
|
|
28 |
|
|
/** |
29 |
|
|
* Opens the GridFile at the given destination |
30 |
|
|
* @param gridfileName the filename of the XuluGridfile |
31 |
|
|
* |
32 |
|
|
*/ |
33 |
|
|
public XuluWritableGridFile(File gridfileName) { |
34 |
|
|
super(null); |
35 |
|
|
this.baseFile = gridfileName; |
36 |
|
|
try { |
37 |
|
|
gridFile = new XuluGridFile(gridfileName); |
38 |
|
|
} catch (FileNotFoundException e) { |
39 |
|
|
// TODO Auto-generated catch block |
40 |
|
|
e.printStackTrace(); |
41 |
|
|
} catch (XuluGridFileException e) { |
42 |
|
|
// TODO Auto-generated catch block |
43 |
|
|
e.printStackTrace(); |
44 |
|
|
} |
45 |
|
|
this.metaData = gridFile.metaData; |
46 |
|
|
this.intialDataLoader = new GridFileDataLoader(gridFile); |
47 |
|
|
this.dataLoader = new GridFileDataLoader(gridFile); |
48 |
|
|
directory = null; |
49 |
|
|
} |
50 |
|
|
|
51 |
|
|
|
52 |
|
|
/** |
53 |
|
|
* Creates NEW a GridFile in the given directory with the given metadata-sample |
54 |
|
|
* |
55 |
|
|
* @param metaData the metadata |
56 |
|
|
*/ |
57 |
|
|
public XuluWritableGridFile(RasterMetaData metaData, String directory) { |
58 |
|
|
super(metaData); |
59 |
|
|
this.directory = directory; |
60 |
|
|
baseFile = new File(directory + File.separatorChar + "xulugridFile"+ this.hashCode() + ".xgrid"); |
61 |
|
|
try { |
62 |
|
|
gridFile = new XuluGridFile(baseFile,metaData); |
63 |
|
|
this.intialDataLoader = new GridFileDataLoader(gridFile); |
64 |
|
|
this.dataLoader = new GridFileDataLoader(gridFile); |
65 |
|
|
} catch (XuluGridFileException e) { |
66 |
|
|
// TODO Auto-generated catch block |
67 |
|
|
e.printStackTrace(); |
68 |
|
|
LOG.error(e); |
69 |
|
|
|
70 |
|
|
} |
71 |
|
|
|
72 |
|
|
} |
73 |
|
|
|
74 |
|
|
/** creates a instance out of a {@link XuluGridFile} */ |
75 |
|
|
public XuluWritableGridFile(XuluGridFile xuluGridFile) { |
76 |
|
|
super(xuluGridFile.getMetaData()); |
77 |
|
|
baseFile = xuluGridFile.getOutputFile(); |
78 |
|
|
gridFile = xuluGridFile; |
79 |
|
|
this.metaData = xuluGridFile.getMetaData(); |
80 |
|
|
this.intialDataLoader = new GridFileDataLoader(gridFile); |
81 |
|
|
this.dataLoader = new GridFileDataLoader(gridFile); |
82 |
|
|
// TODO Auto-generated constructor stub |
83 |
|
|
this.directory=null; |
84 |
|
|
} |
85 |
|
|
|
86 |
|
|
|
87 |
|
|
/** |
88 |
|
|
* Creates a new XuluWritableGridFile in the specified directory, with the given metadata. |
89 |
|
|
* The ID given in this constuctor will be the RootID of this Grid (used e.g. for |
90 |
|
|
* identification in remoteComputing) |
91 |
|
|
* |
92 |
|
|
* @param newID the to be set as the new RootID (permanent) |
93 |
|
|
* @param metaData the metadata is used for creation of the bounds and the type of the new {@link XuluGridFile} |
94 |
|
|
* @param directory the directory in which the file should be created |
95 |
|
|
* @see SplittableResource#getRootID() |
96 |
|
|
*/ |
97 |
|
|
public XuluWritableGridFile(int newID, RasterMetaData metaData, String directory) { |
98 |
|
|
this(metaData,directory); |
99 |
|
|
this.rootID = newID; |
100 |
|
|
} |
101 |
|
|
|
102 |
|
|
|
103 |
|
|
/* (non-Javadoc) |
104 |
|
|
* @see appl.parallel.spmd.split.SplittableResource#getLocalLoader() |
105 |
|
|
*/ |
106 |
|
|
public DataLoader getLocalLoader() { |
107 |
|
|
throw new UnsupportedOperationException("Feature not yet supported!"); |
108 |
|
|
} |
109 |
|
|
|
110 |
|
|
/* (non-Javadoc) |
111 |
|
|
* @see appl.parallel.spmd.split.SplittableResource#getRootID() |
112 |
|
|
*/ |
113 |
|
|
public int getRootID() { |
114 |
|
|
return rootID; |
115 |
|
|
} |
116 |
|
|
|
117 |
|
|
/* (non-Javadoc) |
118 |
|
|
* @see appl.parallel.spmd.split.SplittableResource#getSplitHeight() |
119 |
|
|
*/ |
120 |
|
|
public int getSplitHeight() { |
121 |
|
|
return metaData.getHeight(); |
122 |
|
|
} |
123 |
|
|
|
124 |
|
|
/* (non-Javadoc) |
125 |
|
|
* @see appl.parallel.spmd.split.SplittableResource#getSplitWidth() |
126 |
|
|
*/ |
127 |
|
|
public int getSplitWidth() { |
128 |
|
|
return metaData.getWidth(); |
129 |
|
|
} |
130 |
|
|
|
131 |
|
|
/* (non-Javadoc) |
132 |
|
|
* @see appl.parallel.spmd.split.DataPartition#getEmpty(int) |
133 |
|
|
*/ |
134 |
|
|
public DataPartition getEmpty(int newID) { |
135 |
|
|
if(directory==null) |
136 |
|
|
throw new UnsupportedOperationException("Directory == null. Cant create a empty grid!"); |
137 |
|
|
return new XuluWritableGridFile(newID,this.metaData,this.directory); |
138 |
|
|
} |
139 |
|
|
|
140 |
|
|
/* (non-Javadoc) |
141 |
|
|
* @see appl.parallel.spmd.split.DataPartition#getPartition(java.awt.Rectangle) |
142 |
|
|
*/ |
143 |
|
|
public DataPartition getPartition(Rectangle partitionBounds) { |
144 |
|
|
try { |
145 |
|
|
return gridFile.getPartitialGrid2D(partitionBounds); |
146 |
|
|
} catch (XuluGridFileException e) { |
147 |
|
|
e.printStackTrace(); |
148 |
|
|
LOG.error("Could not retrieve partition from underlaying gridfile"); |
149 |
|
|
} |
150 |
|
|
return null; |
151 |
|
|
} |
152 |
|
|
|
153 |
|
|
/* (non-Javadoc) |
154 |
|
|
* @see appl.parallel.spmd.split.DataPartition#getPartitionBounds() |
155 |
|
|
*/ |
156 |
|
|
public Rectangle getPartitionBounds() { |
157 |
|
|
return new Rectangle(0,0,getWidth(),getHeight()); |
158 |
|
|
} |
159 |
|
|
|
160 |
|
|
/* (non-Javadoc) |
161 |
|
|
* @see appl.parallel.spmd.split.DataPartition#setPartition(appl.parallel.spmd.split.DataPartition, java.awt.Rectangle) |
162 |
|
|
*/ |
163 |
|
|
public void setPartition(DataPartition partition, Rectangle partitionBounds) { |
164 |
|
|
try { |
165 |
|
|
gridFile.setPartition((WritableGrid) partition, partitionBounds); |
166 |
|
|
} catch (XuluGridFileException e) { |
167 |
|
|
// TODO Auto-generated catch block |
168 |
|
|
e.printStackTrace(); |
169 |
|
|
} |
170 |
|
|
|
171 |
|
|
} |
172 |
|
|
|
173 |
|
|
/* (non-Javadoc) |
174 |
|
|
* @see appl.data.WritableGridLLProxy#setGridSample(java.lang.Object, double[]) |
175 |
|
|
*/ |
176 |
|
|
@Override |
177 |
|
|
public void setGridSample(Object value, double... coord) { |
178 |
|
|
throw new UnsupportedOperationException("Writing on cell level is not yet supported. Use setPartition(..) to write to the Grid"); |
179 |
|
|
//wasWriteAccessed =true; |
180 |
|
|
// super.setGridSample(value, coord); |
181 |
|
|
} |
182 |
|
|
|
183 |
|
|
/* (non-Javadoc) |
184 |
|
|
* @see appl.data.WritableGridLLProxy#setRasterSample(java.lang.Object, int[]) |
185 |
|
|
*/ |
186 |
|
|
public void setRasterSample(Object value, int... cell) { |
187 |
|
|
throw new UnsupportedOperationException("Writing on cell level is not yet supported. Use setPartition(..) to write to the Grid"); |
188 |
|
|
|
189 |
|
|
} |
190 |
|
|
|
191 |
|
|
|
192 |
|
|
/* (non-Javadoc) |
193 |
|
|
* @see appl.data.WritableGridLLProxy#getGridSample(double[]) |
194 |
|
|
*/ |
195 |
|
|
@Override |
196 |
|
|
public Object getGridSample(double... coord) { |
197 |
|
|
throw new UnsupportedOperationException("Reading on cell level is not yet supported. Use getPartition(..) to read from the to the Grid"); |
198 |
|
|
} |
199 |
|
|
|
200 |
|
|
|
201 |
|
|
/* (non-Javadoc) |
202 |
|
|
* @see appl.data.WritableGridLLProxy#getGridSampleAsByte(double[]) |
203 |
|
|
*/ |
204 |
|
|
@Override |
205 |
|
|
public byte getGridSampleAsByte(double... coord) { |
206 |
|
|
throw new UnsupportedOperationException("Reading on cell level is not yet supported. Use getPartition(..) to read from the to the Grid"); |
207 |
|
|
} |
208 |
|
|
|
209 |
|
|
|
210 |
|
|
/* (non-Javadoc) |
211 |
|
|
* @see appl.data.WritableGridLLProxy#getGridSampleAsDouble(double[]) |
212 |
|
|
*/ |
213 |
|
|
@Override |
214 |
|
|
public double getGridSampleAsDouble(double... coord) { |
215 |
|
|
throw new UnsupportedOperationException("Reading on cell level is not yet supported. Use getPartition(..) to read from the to the Grid"); |
216 |
|
|
} |
217 |
|
|
|
218 |
|
|
|
219 |
|
|
/* (non-Javadoc) |
220 |
|
|
* @see appl.data.WritableGridLLProxy#getGridSampleAsFloat(double[]) |
221 |
|
|
*/ |
222 |
|
|
@Override |
223 |
|
|
public float getGridSampleAsFloat(double... coord) { |
224 |
|
|
throw new UnsupportedOperationException("Reading on cell level is not yet supported. Use getPartition(..) to read from the to the Grid"); |
225 |
|
|
} |
226 |
|
|
|
227 |
|
|
|
228 |
|
|
/* (non-Javadoc) |
229 |
|
|
* @see appl.data.WritableGridLLProxy#getGridSampleAsInt(double[]) |
230 |
|
|
*/ |
231 |
|
|
@Override |
232 |
|
|
public int getGridSampleAsInt(double... coord) { |
233 |
|
|
throw new UnsupportedOperationException("Reading on cell level is not yet supported. Use getPartition(..) to read from the to the Grid"); |
234 |
|
|
} |
235 |
|
|
|
236 |
|
|
|
237 |
|
|
/* (non-Javadoc) |
238 |
|
|
* @see appl.data.WritableGridLLProxy#getGridSampleAsLong(double[]) |
239 |
|
|
*/ |
240 |
|
|
@Override |
241 |
|
|
public long getGridSampleAsLong(double... coord) { |
242 |
|
|
throw new UnsupportedOperationException("Reading on cell level is not yet supported. Use getPartition(..) to read from the to the Grid"); |
243 |
|
|
} |
244 |
|
|
|
245 |
|
|
|
246 |
|
|
/* (non-Javadoc) |
247 |
|
|
* @see appl.data.WritableGridLLProxy#getGridSampleAsShort(double[]) |
248 |
|
|
*/ |
249 |
|
|
@Override |
250 |
|
|
public short getGridSampleAsShort(double... coord) { |
251 |
|
|
throw new UnsupportedOperationException("Reading on cell level is not yet supported. Use getPartition(..) to read from the to the Grid"); |
252 |
|
|
} |
253 |
|
|
/** |
254 |
|
|
* unloading is not necessary (method does nothing |
255 |
|
|
* |
256 |
|
|
* @see appl.data.LateLoadingProxy#unloadData() |
257 |
|
|
*/ |
258 |
|
|
@Override |
259 |
|
|
public synchronized void unloadData() { |
260 |
|
|
} |
261 |
|
|
|
262 |
|
|
|
263 |
|
|
public String getGridFileName() { |
264 |
|
|
return baseFile.getPath(); |
265 |
|
|
} |
266 |
|
|
} |