/[xulu]/trunk.bakup/src/appl/parallel/data/xulugridfile/XuluWritableGridFile.java
ViewVC logotype

Annotation of /trunk.bakup/src/appl/parallel/data/xulugridfile/XuluWritableGridFile.java

Parent Directory Parent Directory | Revision Log Revision Log


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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26