/[escript]/branches/arrayview_from_1695_trunk/escript/src/DataTagged.h
ViewVC logotype

Annotation of /branches/arrayview_from_1695_trunk/escript/src/DataTagged.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 535 - (hide annotations)
Fri Feb 17 02:27:06 2006 UTC (13 years, 4 months ago) by jgs
Original Path: trunk/escript/src/DataTagged.h
File MIME type: text/plain
File size: 12213 byte(s)
minor comment changes

1 jgs 82 // $Id$
2 jgs 121
3     /*
4 jgs 82 ******************************************************************************
5     * *
6     * COPYRIGHT ACcESS 2004 - All Rights Reserved *
7     * *
8     * This software is the property of ACcESS. No part of this code *
9     * may be copied in any form or by any means without the expressed written *
10     * consent of ACcESS. Copying, use or modification of this software *
11     * by any unauthorised person is illegal unless that person has a software *
12     * license agreement with ACcESS. *
13     * *
14     ******************************************************************************
15     */
16 jgs 121
17 jgs 82 #if !defined escript_DataTagged_20040615_H
18     #define escript_DataTagged_20040615_H
19    
20 jgs 474 #include "DataAbstract.h"
21     #include "DataArrayView.h"
22 jgs 82
23     #include <vector>
24     #include <map>
25    
26     namespace escript {
27    
28     class DataConstant;
29    
30     /**
31     \brief
32 jgs 496 Simulates a full dataset accessible via sampleNo and dataPointNo.
33 jgs 82
34     Description:
35 jgs 496 Each data-point has an associated tag number, and a given tag can represent a
36     range of dataPointNo and sampleNo. Each tag indexes only a single data-point.
37 jgs 82 Thus only a single data-point needs to be stored for a range of sampleNo and
38     dataPointNo values.
39     */
40    
41     class DataTagged : public DataAbstract {
42    
43     public:
44    
45 jgs 119 //
46 jgs 496 // Types for the lists of tags and values.
47 jgs 121 typedef std::vector<int> TagListType;
48 jgs 82 typedef std::vector<DataArrayView> ValueListType;
49 jgs 121 typedef DataArrayView::ValueType ValueType;
50 jgs 82
51     //
52 jgs 496 // Map from a tag to an offset into the data array.
53 jgs 82 typedef std::map<int, int> DataMapType;
54    
55     /**
56     \brief
57     Default constructor for DataTagged.
58    
59     Description:
60     Default constructor for DataTagged. Creates a DataTagged object for which
61 jgs 509 the default data-point is a scalar data-point with value 0.0, and no other
62     tag values are stored.
63 jgs 507 T
64 jgs 82 */
65     DataTagged();
66    
67     /**
68     \brief
69     Constructor for DataTagged.
70    
71     Description:
72     Constructor for DataTagged.
73 jgs 509 \param tagKeys - Input - A vector of integer tags.
74 jgs 82 \param values - Input - A vector of DataArrayViews. If this is empty
75 jgs 509 all tag values will be assigned a scalar data-point of value
76     0. If it contains one value all tag values will be assigned
77     this value. Otherwise consecutive tags will be assigned
78     consecutive values. If there is a mismatch between the
79     number of keys and the number of values an exception
80 jgs 496 will be generated.
81 jgs 82 \param defaultValue - Input - Value returned if a requested tag doesn't exist.
82     \param what - Input - A description of what this data represents.
83 jgs 507 T
84 jgs 82 */
85     DataTagged(const TagListType& tagKeys,
86     const ValueListType& values,
87     const DataArrayView& defaultValue,
88     const FunctionSpace& what);
89    
90     /**
91     \brief
92 jgs 496 Alternative Constructor for DataTagged.
93 jgs 119
94     Description:
95 jgs 496 Alternative Constructor for DataTagged.
96 jgs 119 \param what - Input - A description of what this data object represents.
97 jgs 496 \param shape - Input - The shape of each data-point.
98     \param tags - Input - An array of tags, one for each sample number.
99     \param data - The data values for each tag.
100 jgs 535 NB: no unit testing yet
101 jgs 119 */
102     DataTagged(const FunctionSpace& what,
103     const DataArrayView::ShapeType &shape,
104     const int tags[],
105 jgs 500 const ValueType& data);
106 jgs 119
107     /**
108     \brief
109 jgs 496 Copy Constructor for DataTagged.
110 jgs 82 Performs a deep copy from the given DataTagged object.
111 jgs 507 T
112 jgs 82 */
113     DataTagged(const DataTagged& other);
114    
115     /**
116     \brief
117 jgs 496 Copy Constructor for DataTagged.
118 jgs 509 Construct a DataTagged object from a DataConstant object.
119     The default value will be the value of the DataConstant object.
120 jgs 507 T
121 jgs 82 */
122     DataTagged(const DataConstant& other);
123    
124     /**
125     \brief
126     getSampleDataByTag
127    
128     Description:
129 jgs 496 Return the data-point for the given tag. All of the data for the
130     sample will be visible via the returned pointer.
131    
132     ** This provides an interface into the data suitable for legacy C code.
133 jgs 507 ** NB: need to do array bounds checking when accessing returned value!
134     T
135 jgs 82 */
136     virtual
137     double*
138     getSampleDataByTag(int tag);
139    
140     /**
141     \brief
142     Write the data as a string.
143     Writes out each tag, including the default, and the data-point which is
144     associated with each tag.
145 jgs 507 T
146 jgs 82 */
147     virtual
148     std::string
149     toString() const;
150    
151     /**
152     \brief
153 jgs 496 Return the tag number associated with the given data-point number
154     according to the associated function space.
155 jgs 507 T
156 jgs 149 */
157     virtual
158     int
159     getTagNumber(int dpno);
160    
161     /**
162     \brief
163 jgs 82 getPointOffset
164    
165     Description:
166 jgs 496 Return the offset to the given data-point value in the underlying
167     data vector.
168 jgs 82
169     \param sampleNo - Input - sample number.
170     \param dataPointNo - Input - data-point number.
171 jgs 507 T
172     */
173 jgs 82 virtual
174 jgs 121 ValueType::size_type
175 jgs 82 getPointOffset(int sampleNo,
176     int dataPointNo) const;
177    
178     /**
179     \brief
180     addTaggedValues
181    
182     Description:
183 jgs 509 Add the given tags and values to this DataTagged object.
184 jgs 507 \param tagKeys - Input - A vector of integer tags.
185 jgs 82 \param values - Input - A vector of DataArrayViews. If this is empty
186 jgs 509 all tag values will be assigned a scalar data-point of value
187     0. If it contains one value all tag values will be assigned
188     this value. Otherwise consecutive tags will be assigned
189     consecutive values. If there is a mismatch between the
190     number of keys and the number of values an exception
191     will be generated.
192 jgs 507 T
193 jgs 82 */
194     void
195     addTaggedValues(const TagListType& tagKeys,
196     const ValueListType& values);
197    
198     /**
199     \brief
200     addTaggedValue
201    
202     Description:
203 jgs 121 Add a single tag and value to this DataTagged object. If this tag already has
204     a value associated with it, setTaggedValue will be used to update this value.
205 jgs 509 \param tagKey - Input - Integer tag.
206 jgs 121 \param value - Input - Single DataArrayView value to be assigned to the tag.
207 jgs 507 T
208 jgs 82 */
209     void
210     addTaggedValue(int tagKey,
211     const DataArrayView& value);
212    
213     /**
214     \brief
215     setTaggedValues
216    
217     Description:
218 jgs 509 Set the given tags to the given values in this DataTagged object.
219     \param tagKeys - Input - A vector of integer tag.
220 jgs 82 \param values - Input - A vector of DataArrayViews. If this is empty
221 jgs 509 all tag values will be assigned a scalar data-point of value
222     0. If it contains one value all tag values will be assigned
223     this value. Otherwise consecutive tags will be assigned
224     consecutive values. If there is a mismatch between the
225     number of keys and the number of values an exception
226     will be generated.
227 jgs 507 T
228 jgs 82 */
229     void
230     setTaggedValues(const TagListType& tagKeys,
231     const ValueListType& values);
232    
233     /**
234     \brief
235     setTaggedValue
236    
237     Description:
238 jgs 509 Assign the given value to the given tag.
239     \param tagKey - Input - Integer tag.
240 jgs 82 \param value - Input - Single DataArrayView value to be assigned to the tag.
241 jgs 507 T
242 jgs 82 */
243     virtual
244     void
245     setTaggedValue(int tagKey,
246     const DataArrayView& value);
247    
248     /**
249     \brief
250     getDataPointByTag
251    
252     Description:
253 jgs 509 Return data-point associated with the given tag as a DataArrayView.
254 jgs 82 \param tag - Input - Integer key.
255 jgs 507 T
256 jgs 82 */
257     DataArrayView
258     getDataPointByTag(int tag) const;
259    
260     /**
261     \brief
262     getDataPoint
263    
264     Description:
265 jgs 509 Return the data-point specified by the given sample and data-point
266     numbers as a DataArrayView.
267 jgs 82 \param sampleNo - Input.
268     \param dataPointNo - Input.
269 jgs 507 T
270 jgs 82 */
271     virtual
272     DataArrayView
273     getDataPoint(int sampleNo,
274     int dataPointNo);
275    
276     /**
277     \brief
278     getTagLookup
279    
280     Description:
281     Return a reference to the tag offset lookup table.
282 jgs 507 T
283 jgs 82 */
284     const DataMapType&
285     getTagLookup() const;
286    
287     /**
288     \brief
289     isCurrentTag
290    
291     Description:
292 jgs 496 Return true if the given tag exists within the DataTagged tag map.
293    
294 jgs 509 *** NB: The DataTagged tag map does not necessarily coincide with the tag
295 jgs 496 keys in the associated function space.
296 jgs 507 T
297     */
298 jgs 82 bool
299     isCurrentTag(int tag) const;
300    
301     /**
302     \brief
303     getDefaultValue
304    
305     Description:
306     Return the default value. This value is associated with any tag which
307 jgs 496 is not explicitly recorded in this DataTagged object's tag map.
308 jgs 507 T
309 jgs 82 */
310     DataArrayView&
311     getDefaultValue();
312    
313     const DataArrayView&
314     getDefaultValue() const;
315    
316     /**
317     \brief
318     getLength
319    
320     Description:
321 jgs 509 Return the total number of doubles stored for this DataTagged object.
322 jgs 507 T
323 jgs 82 */
324     virtual
325     ValueType::size_type
326     getLength() const;
327    
328     /**
329     \brief
330     getSlice
331    
332     Description:
333 jgs 513 Factory method that returns a newly created DataTagged object generated
334     by taking the specified slice from this DataTagged object.
335     The caller is reponsible for managing the returned object.
336 jgs 535 T
337 jgs 82 */
338     virtual
339     DataAbstract*
340     getSlice(const DataArrayView::RegionType& region) const;
341    
342     /**
343     \brief
344 jgs 513 Slice Constructor for DataTagged.
345 jgs 82
346     Description:
347 jgs 513 Creates a DataTagged object which is the specified slice
348 jgs 519 from the given DataTagged object.
349     \param other - Input - DataTagged object to slice from.
350     \param region - Input - Region to slice.
351 jgs 535 T
352 jgs 82 */
353 jgs 513 DataTagged(const DataTagged& other,
354     const DataArrayView::RegionType& region);
355    
356     /**
357     \brief
358     setSlice
359    
360     Description:
361 jgs 519 Copy the given Data object into the specified region in this object.
362 jgs 513 \param other - Input - Data object to copy from.
363 jgs 519 \param region - Input - Region to copy into (NB: must have same shape as other!).
364 jgs 535 T
365 jgs 513 */
366 jgs 82 virtual
367     void
368 jgs 513 setSlice(const DataAbstract* other,
369 jgs 82 const DataArrayView::RegionType& region);
370    
371     /**
372     \brief
373     reshapeDataPoint
374    
375     Description:
376 jgs 509 Reshape each data-point in this object to the given shape, only
377     if current data-points are scalars. An exception is thrown if
378     the current data-points have rank other than 0.
379     The original values of the data-points are used for all values
380     of the new data-points.
381     T
382 jgs 82 */
383     void
384     reshapeDataPoint(const DataArrayView::ShapeType& shape);
385    
386 jgs 123 /**
387 jgs 509 \brief
388     Archive the underlying data values to the file referenced
389     by ofstream. A count of the number of values expected to be written
390     is provided as a cross-check.
391 jgs 123
392 jgs 509 The return value indicates success (0) or otherwise (1).
393 jgs 123 */
394     int
395     archiveData(std::ofstream& archiveFile,
396     const DataArrayView::ValueType::size_type noValues) const;
397    
398     /**
399 jgs 509 \brief
400     Extract the number of values specified by noValues from the file
401     referenced by ifstream to the underlying data structure.
402 jgs 123
403 jgs 509 The return value indicates success (0) or otherwise (1).
404 jgs 123 */
405     int
406     extractData(std::ifstream& archiveFile,
407     const DataArrayView::ValueType::size_type noValues);
408    
409 jgs 82 protected:
410    
411     private:
412    
413     //
414     // The offset lookup table
415     DataMapType m_offsetLookup;
416    
417     //
418 jgs 496 // the offset to the default value
419 jgs 119 static const int m_defaultValueOffset = 0;
420    
421     //
422 jgs 82 // The actual data
423 jgs 121 ValueType m_data;
424 jgs 82
425     };
426    
427     inline
428     bool
429     DataTagged::isCurrentTag(int tag) const
430     {
431     DataMapType::const_iterator pos(m_offsetLookup.find(tag));
432     return (pos!=m_offsetLookup.end());
433     }
434    
435     inline
436     DataArrayView&
437     DataTagged::getDefaultValue()
438     {
439     // The default value is always the first value.
440     return getPointDataView();
441     }
442    
443     inline
444     const DataArrayView&
445     DataTagged::getDefaultValue() const
446     {
447     // The default value is always the first value.
448     return getPointDataView();
449     }
450    
451 jgs 496 inline
452     const DataTagged::DataMapType&
453     DataTagged::getTagLookup() const
454     {
455     return m_offsetLookup;
456     }
457    
458     inline
459     DataArrayView::ValueType::size_type
460     DataTagged::getLength() const
461     {
462     return m_data.size();
463     }
464    
465 jgs 82 } // end of namespace
466    
467     #endif

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26