Browse code

Shorten two pathnames with 103 chars to <= 100 chars by renaming fusion_sdk/ folder to fusion/ (fixes #35)

Henrik Bengtsson authored on 22/09/2021 16:19:01
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,379 @@
1
+////////////////////////////////////////////////////////////////
2
+//
3
+// Copyright (C) 2005 Affymetrix, Inc.
4
+//
5
+// This library is free software; you can redistribute it and/or modify
6
+// it under the terms of the GNU Lesser General Public License 
7
+// (version 2.1) as published by the Free Software Foundation.
8
+// 
9
+// This library is distributed in the hope that it will be useful, but
10
+// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11
+// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
12
+// for more details.
13
+// 
14
+// You should have received a copy of the GNU Lesser General Public License
15
+// along with this library; if not, write to the Free Software Foundation, Inc.,
16
+// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
17
+//
18
+////////////////////////////////////////////////////////////////
19
+
20
+
21
+#ifndef _DataSet_HEADER_
22
+#define _DataSet_HEADER_
23
+
24
+#ifdef _MSC_VER
25
+#include <windows.h>
26
+#endif
27
+
28
+#include "calvin_files/data/src/DataException.h"
29
+#include "calvin_files/data/src/DataSetHeader.h"
30
+#include "calvin_files/portability/src/AffymetrixBaseTypes.h"
31
+#include "calvin_files/utils/src/AffyStlCollectionTypes.h"
32
+//
33
+#include <cstring>
34
+#include <fstream>
35
+#include <string>
36
+//
37
+
38
+
39
+namespace affymetrix_calvin_io
40
+{
41
+
42
+// forward declare
43
+class GenericData;
44
+
45
+/*! This class provides methods to access the data of a DataSet. */
46
+class DataSet
47
+{
48
+public:
49
+	/*! Constructor. Use this constructor do access the data using memory-mapping.
50
+	 *	On Windows, memory-mapping will be restricted to 200MB view of the DataSet data.
51
+	 *	@param fileName The name of the generic file to access.
52
+	 *	@param header The DataSetHeader of the DataSet to access.
53
+	 *	@param handle A handle to the file mapping object
54
+	 *	@param loadEntireDataSetHint Indicate if DataSet will attempt to read the entire DataSet data into a memory buffer.
55
+	 */
56
+	DataSet(const std::string& fileName, const affymetrix_calvin_io::DataSetHeader& header, void* handle, bool loadEntireDataSetHint=false);
57
+
58
+
59
+	/*! Constructor. Use this constructor do access the data using std::ifstream.
60
+	 *	With fstream access the entire DataSet data will be read into memory.
61
+	 *	@param fileName The name of the generic file to access.
62
+	 *	@param header The DataSetHeader of the DataSet to access.
63
+	 *	@param ifs A reference to an open ifstream.
64
+	 *	@param loadEntireDataSetHint Indicate if DataSet will attempt to read the entire DataSet data into a memory buffer.
65
+	 */
66
+	DataSet(const std::string& fileName, const affymetrix_calvin_io::DataSetHeader& header, std::ifstream& ifs, bool loadEntireDataSetHint=false);
67
+
68
+public:
69
+	/*! Method to release memory held by this object.  Closes object before deleting. */
70
+	void Delete();
71
+
72
+	/*! Method to open the DataSet to access the data.
73
+	 *	@return true if successful
74
+	 */
75
+	bool Open();
76
+
77
+	/*! Method to close the DataSet. */
78
+	void Close();
79
+
80
+	/*! Method to get a reference to the DataSetHeader
81
+	 *	@return A reference to the DataSetHeader.
82
+	 */
83
+	const affymetrix_calvin_io::DataSetHeader& Header() { return header; }
84
+
85
+	/*! Return the number of rows in the DataSet. */
86
+	int32_t Rows() { return header.GetRowCnt(); }
87
+
88
+	/*! Return the number of columns in the DataSet. */
89
+	int32_t Cols() { return header.GetColumnCnt(); }
90
+
91
+	/*! Determines if the DataSet is open
92
+	 *	@return true if the DataSet is open
93
+	 */
94
+	bool IsOpen() { return (isOpen); }
95
+
96
+	/*! Provides access to single data elements
97
+	 *	@param row Row index.
98
+	 *	@param col Column index.
99
+	 *	@param value Reference to the data type to fill with the data.
100
+	 *	@exception affymetrix_calvin_exceptions::DataSetNotOpenException The file is not memory-mapped.
101
+	 */
102
+	void GetData(int32_t row, int32_t col, u_int8_t& value);
103
+
104
+	void GetData(int32_t row, int32_t col, int8_t& value);
105
+
106
+	void GetData(int32_t row, int32_t col, u_int16_t& value);
107
+
108
+	void GetData(int32_t row, int32_t col, int16_t& value);
109
+
110
+	void GetData(int32_t row, int32_t col, u_int32_t& value);
111
+
112
+	void GetData(int32_t row, int32_t col, int32_t& value);
113
+
114
+	void GetData(int32_t row, int32_t col, float& value);
115
+
116
+	void GetData(int32_t row, int32_t col, std::string& value);
117
+
118
+	void GetData(int32_t row, int32_t col, std::wstring& value);
119
+
120
+	/*! Provides access to multiple data elements in the same column.
121
+	 *	If count elements could not be read, it is not considered an error.  The vector
122
+	 *	is filled with only the data that could be read.
123
+	 *	@param col Column index.
124
+	 *	@param startRow Row index of the data to be inserted into the vector at [0].
125
+	 *	@param count Number of elements to retrieve. -1 indicates to read all
126
+	 *	@param values Reference to the data type to fill with the data.
127
+	 *	@exception affymetrix_calvin_exceptions::DataSetNotOpenException The file is not memory-mapped.
128
+	 */
129
+
130
+	void GetData(int32_t col, int32_t startRow, int32_t count, Uint8Vector& values);
131
+
132
+	void GetData(int32_t col, int32_t startRow, int32_t count, Int8Vector& values);
133
+
134
+	void GetData(int32_t col, int32_t startRow, int32_t count, Uint16Vector& values);
135
+
136
+	void GetData(int32_t col, int32_t startRow, int32_t count, Int16Vector& values);
137
+
138
+	void GetData(int32_t col, int32_t startRow, int32_t count, Uint32Vector& values);
139
+
140
+	void GetData(int32_t col, int32_t startRow, int32_t count, Int32Vector& values);
141
+
142
+	void GetData(int32_t col, int32_t startRow, int32_t count, FloatVector& values);
143
+
144
+	void GetData(int32_t col, int32_t startRow, int32_t count, std::vector<std::string>& values);
145
+
146
+	void GetData(int32_t col, int32_t startRow, int32_t count, WStringVector& values);
147
+
148
+	/*! Provides access to multiple data elements in the same column.
149
+	 *	The caller is responsible for allocating the storage to which count element values can be written.
150
+	 *	If count elements could not be read, it is not considered an error.  The array
151
+	 *	is filled with only the data that could be read.
152
+	 *	@param col Column index.
153
+	 *	@param startRow Row index of the data to be inserted into the vector at [0].
154
+	 *	@param count Number of elements to retrieve. -1 indicates to read all
155
+	 *	@param values Reference to the data type to fill with the data.
156
+	 *	@return Number of elements read.
157
+	 *	@exception affymetrix_calvin_exceptions::DataSetNotOpenException The file is not memory-mapped.
158
+	*/
159
+
160
+	int32_t GetDataRaw(int32_t col, int32_t startRow, int32_t count, u_int8_t* values);
161
+
162
+	int32_t GetDataRaw(int32_t col, int32_t startRow, int32_t count, int8_t* values);
163
+
164
+	int32_t GetDataRaw(int32_t col, int32_t startRow, int32_t count, u_int16_t* values);
165
+
166
+	int32_t GetDataRaw(int32_t col, int32_t startRow, int32_t count, int16_t* values);
167
+
168
+	int32_t GetDataRaw(int32_t col, int32_t startRow, int32_t count, u_int32_t* values);
169
+
170
+	int32_t GetDataRaw(int32_t col, int32_t startRow, int32_t count, int32_t* values);
171
+
172
+	int32_t GetDataRaw(int32_t col, int32_t startRow, int32_t count, float* values);
173
+
174
+	int32_t GetDataRaw(int32_t col, int32_t startRow, int32_t count, std::string* values);
175
+
176
+	int32_t GetDataRaw(int32_t col, int32_t startRow, int32_t count, std::wstring* values);
177
+
178
+	/*! Check that the requested data matches the type of data in the column and that row and column are in bounds.
179
+	 *	@param row Row index to check.
180
+	 *	@param col Column index to check.
181
+	 *	@param type Column type to check.
182
+	 *	@exception affymetrix_calvin_exceptions::DataSetNotOpenException The file is not memory-mapped.
183
+	 *	@exception affymetrix_calvin_exceptions::ColumnIndexOutOfBoundsException The column index is out-of-bounds.
184
+	 *	@exception affymetrix_calvin_exceptions::RowIndexOutOfBoundsException The row index is out-of-bounds.
185
+	 *	@exception affymetrix_calvin_exceptions::UnexpectedColumnTypeException The column type does not match the type requested.
186
+	 */
187
+	void CheckRowColumnAndType(int32_t row, int32_t col, affymetrix_calvin_io::DataSetColumnTypes type);
188
+
189
+//protected:
190
+
191
+	/*! Return the bytes per row.
192
+	 *	@return Bytes in a row.
193
+	 */
194
+	int32_t BytesPerRow() { return columnByteOffsets[header.GetColumnCnt()]; }
195
+
196
+//protected:
197
+	/*! Destructor. */
198
+	~DataSet();
199
+
200
+protected:
201
+	/*! Open the DataSet using memory-mapping
202
+	 *	@return True if the DataSet was successully mapped.
203
+	 */
204
+	bool OpenMM();
205
+
206
+	/*! Read the DataSet data into a buffer using ifstream::read.
207
+	 */
208
+	void ReadDataSetUsingStream();
209
+
210
+	/*! Close the memory mapped file. */
211
+	void UnmapFile();
212
+
213
+	/*! Delete the DataSet data read in by ifstream::read */
214
+	void ClearStreamData();
215
+
216
+	/*! Returns the address of a data element given a row and column.  Ensures that data from rowStart
217
+	 *	to rowCount+rowStart are mapped unless that is larger than the mapped window.
218
+	 *	@param rowStart Row index
219
+	 *	@param col Column index
220
+	 *	@param rowCount The number of rows to ensure are mapped starting at rowStart
221
+	 *	@return Pointer to the data element at rowStart
222
+	 *	@exception affymetrix_calvin_exceptions::DataSetNotOpenException The file is not open.
223
+	 *	@exception affymetrix_calvin_exceptions::DataSetRemapException There was an error during a remap.
224
+	 */
225
+	char* FilePosition(int32_t rowStart, int32_t col, int32_t rowCount=1);
226
+
227
+	/*! Returns the address of a data element given a row and column.  Ensures that data from rowStart
228
+	 *	to rowCount+rowStart are copied from the file into a memory buffer.  The memory buffer will
229
+	 *	remain intact until the next call to LoadDataAndReturnFilePosition.
230
+	 *	@param rowStart Row index
231
+	 *	@param col Column index
232
+	 *	@param rowCount The number of rows to ensure are mapped starting at rowStart
233
+	 *	@return Pointer to the data element at rowStart
234
+	 *	@exception affymetrix_calvin_exceptions::DataSetNotOpenException The file is not open.
235
+	 */
236
+	char* LoadDataAndReturnFilePosition(int32_t rowStart, int32_t col, int32_t rowCount);
237
+
238
+	/*! Updates the columnByteOffsets member. */
239
+	void UpdateColumnByteOffsets();
240
+
241
+	/*! Computes the index of the row after last to read.
242
+	 *	@param startRow Row index of the data to be inserted into the vector at [0].
243
+	 *	@param count Number of elements to be retrieved. -1 indicates read to the last element.
244
+	 *	@return Index of row after the last row to read.
245
+	 */
246
+	int32_t ComputeEndRow(int32_t startRow, int32_t count);
247
+
248
+	/*!	Clears and resizes the vector
249
+	 *	@param values Reference to a vector to clear and resize.
250
+	 *	@param size Target size of the vector
251
+	 */
252
+	template<typename T> void ClearAndSizeVector(std::vector<T>& values, u_int32_t size);
253
+
254
+	/*! Template method to get data into a vector
255
+	 *	@param col Column index.
256
+	 *	@param startRow Row index of the data to be inserted into the vector at [0].
257
+	 *	@param count Number of elements to retrieve. -1 indicates to read all
258
+	 *	@param values Reference to the data type to fill with the data.
259
+	 *	@exception affymetrix_calvin_exceptions::DataSetNotOpenException The file is not memory-mapped.
260
+	 */
261
+	template<typename T> void GetDataT(int32_t col, int32_t startRow, int32_t count, T& values);
262
+
263
+	/*! Template method to get data into an array
264
+	 *	@param col Column index.
265
+	 *	@param startRow Row index of the data to be inserted into the vector at [0].
266
+	 *	@param count Number of elements to retrieve. -1 indicates to read all
267
+	 *	@param values Reference to the data type to fill with the data.
268
+	 *	@return Number of elements read.
269
+	 *	@exception affymetrix_calvin_exceptions::DataSetNotOpenException The file is not memory-mapped.
270
+	 */
271
+	template<typename T> int32_t GetDataRawT(int32_t col, int32_t startRow, int32_t count, T* values);
272
+
273
+
274
+	/*! Returns the index of the last row mapped.
275
+	 *	@return Index of the last row mapped.
276
+	 */
277
+	int32_t LastRowMapped();
278
+
279
+	/*! Platform specific memory-mapping method */
280
+#ifdef _MSC_VER
281
+
282
+	bool MapDataWin32(u_int32_t start, u_int32_t bytes);
283
+
284
+#else
285
+
286
+	bool MapDataPosix(u_int32_t start, u_int32_t bytes);
287
+
288
+#endif
289
+
290
+	/*! Reads from the instr pointer into the vector at the index indicated.
291
+	 *	@param index Index to the vector where to write the value.
292
+	 *	@param values The vector into which to write the value.
293
+	 *	@param instr A pointer to the data in the memory buffer.  The pointer is advanced by the method.
294
+	 */
295
+	void AssignValue(int32_t index, Uint8Vector& values, char*& instr);
296
+
297
+	void AssignValue(int32_t index, Int8Vector& values, char*& instr);
298
+
299
+	void AssignValue(int32_t index, Uint16Vector& values, char*& instr);
300
+
301
+	void AssignValue(int32_t index, Int16Vector& values, char*& instr);
302
+
303
+	void AssignValue(int32_t index, Uint32Vector& values, char*& instr);
304
+
305
+	void AssignValue(int32_t index, Int32Vector& values, char*& instr);
306
+
307
+	void AssignValue(int32_t index, FloatVector& values, char*& instr);
308
+
309
+	void AssignValue(int32_t index, StringVector& values, char*& instr);
310
+
311
+	void AssignValue(int32_t index, WStringVector& values, char*& instr);
312
+
313
+	void AssignValue(int32_t index, u_int8_t* values, char*& instr);
314
+
315
+	void AssignValue(int32_t index, int8_t* values, char*& instr);
316
+
317
+	void AssignValue(int32_t index, u_int16_t* values, char*& instr);
318
+
319
+	void AssignValue(int32_t index, int16_t* values, char*& instr);
320
+
321
+	void AssignValue(int32_t index, u_int32_t* values, char*& instr);
322
+
323
+	void AssignValue(int32_t index, int32_t* values, char*& instr);
324
+
325
+	void AssignValue(int32_t index, float* values, char*& instr);
326
+
327
+	void AssignValue(int32_t index, std::string* values, char*& instr);
328
+
329
+	void AssignValue(int32_t index, std::wstring* values, char*& instr);
330
+
331
+protected:
332
+	/*! name of the file containing the data data set*.  */
333
+	std::string fileName;
334
+
335
+	/*! copy of the DataSetHeader */
336
+	affymetrix_calvin_io::DataSetHeader header;
337
+
338
+	/*! pointer to the mapped data, doesn't account for allocation granularity. */
339
+	void*	mappedData;
340
+
341
+	/*! pointer to the data.  In memory-mapping mode, the pointer has been adjusted for the allocation granularity. */
342
+	char*	data;
343
+
344
+	/*! Array of column byte offsets.  Updated when the file is opened.
345
+	 *  There are columns + 1 elements
346
+	 */
347
+	Int32Vector columnByteOffsets;
348
+
349
+#ifdef _MSC_VER
350
+
351
+	/*! Handle returned by CreateFileMapping */
352
+	HANDLE fileMapHandle;
353
+	/*! Maximum size of the view to map */
354
+	static const u_int32_t MaxViewSize = 200*1024*1024;	// 200MB
355
+
356
+#else
357
+
358
+	FILE *fp;
359
+
360
+#endif
361
+
362
+	/*! Indicates if the DataSet is open*/
363
+	bool isOpen;
364
+	/*! Byte offset to the start of the view */
365
+	u_int32_t mapStart;
366
+	/*! Number of bytes mapped to the view */
367
+	u_int32_t mapLen;
368
+	/*! A flag the indicates the data access mode.  True = access the data using memory-mapping.  False = access the data using std::ifstream */
369
+	bool useMemoryMapping;
370
+	/*! An open ifstream object */
371
+	std::ifstream* fileStream;
372
+	/*! Indicates whether to attempt to read all data into a memory buffer. */
373
+	bool loadEntireDataSetHint;
374
+
375
+};
376
+
377
+}
378
+
379
+#endif // _DataSet_HEADER_