casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DataRecord.h
Go to the documentation of this file.
1 /*
2  * DataRecord.h
3  *
4  * Created on: Jan 27, 2016
5  * Author: nakazato
6  */
7 
8 #ifndef SINGLEDISH_FILLER_DATARECORD_H_
9 #define SINGLEDISH_FILLER_DATARECORD_H_
10 
11 #include <memory>
12 #include <stdlib.h>
13 
19 
20 namespace {
21 template<class T>
22 void copyStorage(size_t n, T const *src, T *dst) {
23  for (size_t i = n; i < n; ++i) {
24  dst[i] = src[i];
25  }
26 }
27 
28 template<class T>
29 void copyStorage(size_t n, size_t m, size_t stride, T const *src, T *dst) {
30  for (size_t i = 0; i < m; ++i) {
31  copyStorage(n, src + stride * m, dst + stride * m);
32  }
33 }
34 
35 }
36 
37 namespace casa { //# NAMESPACE CASA - BEGIN
38 namespace sdfiller { //# NAMESPACE SDFILLER - BEGIN
39 
40 using casacore::SHARE;
41 
42 struct DataRecord {
46  data_shape_(1, 0), tsys_shape_(1, 0), tcal_shape_(1, 0),
52  direction_vector(direction.column(0)), scan_rate(direction.column(1)),
57 // std::cout << "DataRecord::DataRecord()" << std::endl;
58  clear();
59  }
60 
62  }
63 
64  // method
65  void clear() {
66 // std::cout << "clear" << std::endl;
67  time = -1.0;
68  interval = -1.0;
69  antenna_id = -1;
70  field_id = -1;
71  spw_id = -1;
72  feed_id = -1;
73  scan = -1;
74  subscan = -1;
76  intent = "";
77  pol_type = "";
78  direction = 0.0;
79  setDataSize(0);
80  setTsysSize(0);
81  setTcalSize(0);
82  flag_row = true;
83 
84  temperature = 0.0f;
85  pressure = 0.0f;
86  rel_humidity = 0.0f;
87  wind_speed = 0.0f;
88  wind_direction = 0.0f;
89  }
90 
91  void setDataSize(size_t n) {
92  casacore::Bool redirect = false;
93  if (data_shape_[0] != (ssize_t) n) {
94 // std::cout << "resize data to " << n << std::endl;
95  data_shape_[0] = n;
96  redirect = true;
97  }
98  if (num_data_storage_ < n) {
99  size_t new_num_storage = num_data_storage_ + block_size_;
100  while (new_num_storage < n) {
101  new_num_storage += block_size_;
102  }
103 // std::cout << "resize data storage to " << new_num_storage << std::endl;
104  casacore::Float *new_data_storage = new casacore::Float[new_num_storage];
105  copyStorage(data_shape_[0], data_storage_.get(), new_data_storage);
106  data_storage_.reset(new_data_storage);
107  casacore::Bool *new_flag_storage = new casacore::Bool[new_num_storage];
108  copyStorage(data_shape_[0], flag_storage_.get(), new_flag_storage);
109  flag_storage_.reset(new_flag_storage);
110  num_data_storage_ = new_num_storage;
111  redirect = true;
112  }
113  if (redirect) {
116  }
117  }
118 
119  void setTsysSize(size_t n) {
120  casacore::Bool redirect = false;
121  if (tsys_shape_[0] != (ssize_t) n) {
122 // std::cout << "resize tsys to " << n << std::endl;
123  tsys_shape_[0] = n;
124  redirect = true;
125  }
126  if (num_tsys_storage_ < n) {
127  size_t new_num_storage = num_tsys_storage_ + block_size_;
128  while (new_num_storage < n) {
129  new_num_storage += block_size_;
130  }
131 // std::cout << "resize tsys storage to " << new_num_storage << std::endl;
132  casacore::Float *new_tsys_storage = new casacore::Float[new_num_storage];
133  copyStorage(tsys_shape_[0], tsys_storage_.get(), new_tsys_storage);
134  tsys_storage_.reset(new_tsys_storage);
135  num_tsys_storage_ = new_num_storage;
136  redirect = true;
137  }
138  if (redirect) {
140  }
141  }
142 
143  void setTcalSize(size_t n) {
144  casacore::Bool redirect = false;
145  if (tcal_shape_[0] != (ssize_t) n) {
146 // std::cout << "resize tcal to " << n << std::endl;
147  tcal_shape_[0] = n;
148  redirect = true;
149  }
150  if (num_tcal_storage_ < n) {
151  size_t new_num_storage = num_tcal_storage_ + block_size_;
152  while (new_num_storage < n) {
153  new_num_storage += block_size_;
154  }
155 // std::cout << "resize tcal storage to " << new_num_storage << std::endl;
156  casacore::Float *new_tcal_storage = new casacore::Float[new_num_storage];
157  copyStorage(tcal_shape_[0], tcal_storage_.get(), new_tcal_storage);
158  tcal_storage_.reset(new_tcal_storage);
159  num_tcal_storage_ = new_num_storage;
160  redirect = true;
161  }
162  if (redirect) {
164  }
165  }
166 
167  DataRecord(DataRecord const &other) :
168  DataRecord() {
169  *this = other;
170  }
171  DataRecord &operator=(DataRecord const &other) {
172  time = other.time;
173  interval = other.interval;
174  antenna_id = other.antenna_id;
175  field_id = other.field_id;
176  spw_id = other.spw_id;
177  feed_id = other.feed_id;
178  scan = other.scan;
179  subscan = other.subscan;
180  pol = other.pol;
181  intent = other.intent;
182  pol_type = other.pol_type;
183  direction = other.direction;
185  SHARE);
188  flag_row = other.flag_row;
189  setDataSize(other.data_shape_[0]);
190  data = other.data;
191  flag = other.flag;
192  setTsysSize(other.tsys_shape_[0]);
193  tsys = other.tsys;
194  setTcalSize(other.tcal_shape_[0]);
195  tcal = other.tcal;
196 
197  temperature = other.temperature;
198  pressure = other.pressure;
199  rel_humidity = other.rel_humidity;
200  wind_speed = other.wind_speed;
202 
203  return *this;
204  }
205 
206 private:
207  size_t const block_size_;
214  std::unique_ptr<casacore::Float[]> data_storage_;
215  std::unique_ptr<casacore::Bool[]> flag_storage_;
216  std::unique_ptr<casacore::Float[]> tsys_storage_;
217  std::unique_ptr<casacore::Float[]> tcal_storage_;
218 
219 public:
220  // mandatory
239 
240  // optional
243 
249 };
250 
251 struct MSDataRecord {
253  block_size_(131072u),
257  data_shape_(2, 0, 0),
258  tsys_shape_(2, 0, 0),
259  tcal_shape_(2, 0, 0),
260  corr_type_shape_(1, 0),
262  data_storage_(malloc(num_data_storage_ * sizeof(casacore::Complex))),
263  flag_storage_(malloc(num_data_storage_ * sizeof(casacore::Bool))),
264  tsys_storage_(malloc(num_tsys_storage_ * sizeof(casacore::Float))),
265  tcal_storage_(malloc(num_tcal_storage_ * sizeof(casacore::Float))),
266  sigma_storage_(new casacore::Float[4]),
267  is_float_(false),
269  direction(2, 2, 0.0),
271  float_data(data_shape_, reinterpret_cast<casacore::Float *>(data_storage_.get()),
272  SHARE),
274  reinterpret_cast<casacore::Complex *>(data_storage_.get()), SHARE),
275  flag(data_shape_, reinterpret_cast<casacore::Bool *>(flag_storage_.get()), SHARE),
277  tsys(tsys_shape_, reinterpret_cast<casacore::Float *>(tsys_storage_.get()), SHARE),
278  tcal(tcal_shape_, reinterpret_cast<casacore::Float *>(tcal_storage_.get()), SHARE) {
280  throw casacore::AipsError("Failed to allocate memory.");
281  }
282  for (size_t i = 0; i < 4; ++i) {
283  sigma_storage_[i] = 1.0f;
284  }
285  clear();
286  }
287 
289  }
290 
291  // method
292  void clear() {
293  time = -1.0;
294  interval = -1.0;
295  antenna_id = -1;
296  field_id = -1;
297  spw_id = -1;
298  feed_id = -1;
299  scan = -1;
300  subscan = -1;
301  intent = "";
302  pol_type = "";
303  num_pol = 0;
304  direction = 0.0;
305  setDataSize(0, 0);
306  setTsysSize(0, 0);
307  setTcalSize(0, 0);
308  flag_row = true;
309  is_float_ = false;
310 
311  temperature = 0.0f;
312  pressure = 0.0f;
313  rel_humidity = 0.0f;
314  wind_speed = 0.0f;
315  wind_direction = 0.0f;
316  }
317 
319  return is_float_;
320  }
321 
322  void setFloat() {
323  is_float_ = true;
324  }
325 
326  void setComplex() {
327  is_float_ = false;
328  }
329 
330  void setDataSize(size_t n, size_t m) {
331  casacore::Bool redirect = false;
332  if (data_shape_[0] != (ssize_t) n) {
333 // std::cout << "resize data to " << n << std::endl;
334  data_shape_[0] = n;
335  redirect = true;
336  }
337  if (data_shape_[1] != (ssize_t) m) {
338  data_shape_[1] = m;
339  redirect = true;
340  }
341  if (num_data_storage_ < n * m) {
342  size_t new_num_storage = num_data_storage_ + block_size_;
343  while (new_num_storage < n * m) {
344  new_num_storage += block_size_;
345  }
346 // std::cout << "resize data storage to " << new_num_storage << std::endl;
347  void *new_data_storage = malloc(new_num_storage * sizeof(casacore::Complex));
348  if (!new_data_storage) {
349  throw casacore::AipsError("Failed to allocate memory.");
350  }
351  if (is_float_) {
352  copyStorage(data_shape_[0], data_shape_[1], 4,
353  reinterpret_cast<casacore::Float *>(data_storage_.get()),
354  reinterpret_cast<casacore::Float *>(new_data_storage));
355  } else {
356  copyStorage(data_shape_[0], data_shape_[1], 4,
357  reinterpret_cast<casacore::Complex *>(data_storage_.get()),
358  reinterpret_cast<casacore::Complex *>(new_data_storage));
359  }
360  data_storage_.reset(new_data_storage);
361  void *new_flag_storage = malloc(new_num_storage * sizeof(casacore::Bool));
362  if (!new_flag_storage) {
363  throw casacore::AipsError("Failed to allocate memory.");
364  }
365  copyStorage(data_shape_[0], data_shape_[1], 4,
366  reinterpret_cast<casacore::Bool *>(flag_storage_.get()),
367  reinterpret_cast<casacore::Bool *>(new_flag_storage));
368  flag_storage_.reset(new_flag_storage);
369  num_data_storage_ = new_num_storage;
370  redirect = true;
371  }
372  if (redirect) {
375  SHARE);
378  reinterpret_cast<casacore::Float *>(data_storage_.get()), SHARE);
380  reinterpret_cast<casacore::Complex *>(data_storage_.get()), SHARE);
382  reinterpret_cast<casacore::Bool *>(flag_storage_.get()), SHARE);
383  }
384  }
385 
386  void setTsysSize(size_t n, size_t m) {
387  casacore::Bool redirect = false;
388  if (tsys_shape_[0] != (ssize_t) n) {
389 // std::cout << "resize tsys to " << n << std::endl;
390  tsys_shape_[0] = n;
391  redirect = true;
392  }
393  if (tsys_shape_[1] != (ssize_t) m) {
394 // std::cout << "resize tsys to " << n << std::endl;
395  tsys_shape_[1] = m;
396  redirect = true;
397  }
398  if (num_tsys_storage_ < n * m) {
399  size_t new_num_storage = num_tsys_storage_ + block_size_;
400  while (new_num_storage < n * m) {
401  new_num_storage += block_size_;
402  }
403 // std::cout << "resize tsys storage to " << new_num_storage << std::endl;
404  void *new_tsys_storage = malloc(new_num_storage * sizeof(casacore::Float));
405  copyStorage(tsys_shape_[0], tsys_shape_[1], 4,
406  reinterpret_cast<casacore::Float *>(tsys_storage_.get()),
407  reinterpret_cast<casacore::Float *>(new_tsys_storage));
408  tsys_storage_.reset(new_tsys_storage);
409  num_tsys_storage_ = new_num_storage;
410  redirect = true;
411  }
412  if (redirect) {
414  reinterpret_cast<casacore::Float *>(tsys_storage_.get()), SHARE);
415  }
416  }
417 
418  void setTcalSize(size_t n, size_t m) {
419  casacore::Bool redirect = false;
420  if (tcal_shape_[0] != (ssize_t) n) {
421 // std::cout << "resize tcal to " << n << std::endl;
422  tcal_shape_[0] = n;
423  redirect = true;
424  }
425  if (tcal_shape_[1] != (ssize_t) m) {
426 // std::cout << "resize tcal to " << n << std::endl;
427  tcal_shape_[1] = m;
428  redirect = true;
429  }
430  if (num_tcal_storage_ < n * m) {
431  size_t new_num_storage = num_tcal_storage_ + block_size_;
432  while (new_num_storage < n * m) {
433  new_num_storage += block_size_;
434  }
435 // std::cout << "resize tcal storage to " << new_num_storage << std::endl;
436  void *new_tcal_storage = malloc(new_num_storage * sizeof(casacore::Float));
437  copyStorage(tcal_shape_[0], tcal_shape_[1], 4,
438  reinterpret_cast<casacore::Float *>(tcal_storage_.get()),
439  reinterpret_cast<casacore::Float *>(new_tcal_storage));
440  tcal_storage_.reset(new_tcal_storage);
441  num_tcal_storage_ = new_num_storage;
442  redirect = true;
443  }
444  if (redirect) {
446  reinterpret_cast<casacore::Float *>(tcal_storage_.get()), SHARE);
447  }
448  }
449 
450  MSDataRecord(MSDataRecord const &other) :
451  MSDataRecord() {
452  *this = other;
453  }
455  time = other.time;
456  interval = other.interval;
457  antenna_id = other.antenna_id;
458  field_id = other.field_id;
459  spw_id = other.spw_id;
460  feed_id = other.feed_id;
461  scan = other.scan;
462  subscan = other.subscan;
463  intent = other.intent;
464  pol_type = other.pol_type;
465  num_pol = other.num_pol;
466  direction = other.direction;
468  SHARE);
469  flag_row = other.flag_row;
470  setDataSize(other.data_shape_[0], other.data_shape_[1]);
471  corr_type = other.corr_type;
472  if (other.is_float_) {
473  float_data = other.float_data;
474  } else {
475  complex_data = other.complex_data;
476  }
477  flag = other.flag;
478  setTsysSize(other.tsys_shape_[0], other.tsys_shape_[1]);
479  tsys = other.tsys;
480  setTcalSize(other.tcal_shape_[0], other.tcal_shape_[1]);
481  tcal = other.tcal;
482 
483  temperature = other.temperature;
484  pressure = other.pressure;
485  rel_humidity = other.rel_humidity;
486  wind_speed = other.wind_speed;
488 
489  return *this;
490  }
491 
492 private:
493  size_t const block_size_;
502  std::unique_ptr<void, sdfiller::Deleter> data_storage_;
503  std::unique_ptr<void, sdfiller::Deleter> flag_storage_;
504  std::unique_ptr<void, sdfiller::Deleter> tsys_storage_;
505  std::unique_ptr<void, sdfiller::Deleter> tcal_storage_;
506  std::unique_ptr<casacore::Float[]> sigma_storage_;
508 
509 public:
510 // mandatory
531 
532  // optional
535 
541 
542 };
543 
544 } //# NAMESPACE SDFILLER - END
545 } //# NAMESPACE CASA - END
546 
547 #endif /* SINGLEDISH_FILLER_DATARECORD_H_ */
A Vector of integers, for indexing into Array&lt;T&gt; objects.
Definition: IPosition.h:119
casacore::Matrix< casacore::Float > tsys
optional
Definition: DataRecord.h:533
void setTsysSize(size_t n, size_t m)
Definition: DataRecord.h:386
int Int
Definition: aipstype.h:50
Vector< T > column(size_t j)
Returns a reference to the j&#39;th column.
std::unique_ptr< casacore::Float[]> tcal_storage_
Definition: DataRecord.h:217
Share means that the Array will just use the pointer (no copy), however the Array will NOT delete it ...
Definition: ArrayBase.h:64
casacore::Double time
mandatory
Definition: DataRecord.h:511
void setTcalSize(size_t n)
Definition: DataRecord.h:143
std::unique_ptr< void, sdfiller::Deleter > tsys_storage_
Definition: DataRecord.h:504
casacore::Float wind_speed
Definition: DataRecord.h:247
const IPosition & shape() const
The length of each axis of the Matrix.
Definition: Matrix.h:295
casacore::Float temperature
Definition: DataRecord.h:536
casacore::Float wind_speed
Definition: DataRecord.h:539
DataRecord(DataRecord const &other)
Definition: DataRecord.h:167
casacore::Vector< casacore::Float > & weight
Definition: DataRecord.h:530
casacore::Vector< casacore::Float > data
Definition: DataRecord.h:236
casacore::String pol_type
Definition: DataRecord.h:231
void setDataSize(size_t n, size_t m)
Definition: DataRecord.h:330
casacore::Stokes::StokesTypes pol
Definition: DataRecord.h:229
casacore::Float wind_direction
Definition: DataRecord.h:540
casacore::Int antenna_id
Definition: DataRecord.h:223
MSDataRecord & operator=(MSDataRecord const &other)
Definition: DataRecord.h:454
casacore::Matrix< casacore::Double > direction_slice
Definition: DataRecord.h:233
casacore::Matrix< casacore::Float > float_data
Definition: DataRecord.h:525
casacore::Matrix< casacore::Bool > flag
Definition: DataRecord.h:527
casacore::Vector< casacore::Double > direction_vector
Definition: DataRecord.h:234
casacore::Bool isFloat() const
Definition: DataRecord.h:318
casacore::Vector< casacore::Float > sigma
Definition: DataRecord.h:529
casacore::IPosition tcal_shape_
Definition: DataRecord.h:499
casacore::Block< casacore::Int > corr_type_storage_
Definition: DataRecord.h:501
casacore::IPosition tsys_shape_
Definition: DataRecord.h:212
casacore::Vector< casacore::Double > scan_rate
Definition: DataRecord.h:235
MSDataRecord(MSDataRecord const &other)
Definition: DataRecord.h:450
casacore::Vector< casacore::Float > tsys
optional
Definition: DataRecord.h:241
StokesTypes
The Stokes types are defined by this enum.
Definition: Stokes.h:66
std::unique_ptr< casacore::Bool[]> flag_storage_
Definition: DataRecord.h:215
ABSTRACT CLASSES Deliberately vague to be general enough to allow for many different types of data
Definition: PlotData.h:48
T * data()
Get a pointer to the beginning of the array.
Definition: Array.h:597
std::unique_ptr< casacore::Float[]> sigma_storage_
Definition: DataRecord.h:506
casacore::Vector< casacore::Bool > flag
Definition: DataRecord.h:237
casacore::IPosition data_shape_
Definition: DataRecord.h:211
void setTcalSize(size_t n, size_t m)
Definition: DataRecord.h:418
casacore::Vector< casacore::Int > corr_type
Definition: DataRecord.h:522
void setDataSize(size_t n)
Definition: DataRecord.h:91
std::unique_ptr< void, sdfiller::Deleter > tcal_storage_
Definition: DataRecord.h:505
std::unique_ptr< void, sdfiller::Deleter > flag_storage_
Definition: DataRecord.h:503
casacore::Vector< casacore::Float > tcal
Definition: DataRecord.h:242
std::unique_ptr< void, sdfiller::Deleter > data_storage_
Definition: DataRecord.h:502
casacore::Float rel_humidity
Definition: DataRecord.h:246
double Double
Definition: aipstype.h:55
casacore::IPosition tcal_shape_
Definition: DataRecord.h:213
casacore::IPosition tsys_shape_
Definition: DataRecord.h:498
casacore::Matrix< casacore::Complex > complex_data
Definition: DataRecord.h:526
casacore::Double interval
Definition: DataRecord.h:512
casacore::Double time
mandatory
Definition: DataRecord.h:221
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
casacore::Float pressure
Definition: DataRecord.h:245
casacore::Matrix< casacore::Double > direction
Definition: DataRecord.h:523
float Float
Definition: aipstype.h:54
casacore::String pol_type
Definition: DataRecord.h:521
casacore::Float temperature
Definition: DataRecord.h:244
std::unique_ptr< casacore::Float[]> data_storage_
Definition: DataRecord.h:214
casacore::Matrix< casacore::Float > tcal
Definition: DataRecord.h:534
casacore::Float wind_direction
Definition: DataRecord.h:248
casacore::String intent
Definition: DataRecord.h:520
casacore::Matrix< casacore::Double > direction
Definition: DataRecord.h:232
casacore::Float rel_humidity
Definition: DataRecord.h:538
virtual void takeStorage(const IPosition &shape, T *storage, StorageInitPolicy policy=COPY)
Replace the data values with those in the pointer storage.
Base class for all Casacore library errors.
Definition: Error.h:134
std::unique_ptr< casacore::Float[]> tsys_storage_
Definition: DataRecord.h:216
DataRecord & operator=(DataRecord const &other)
Definition: DataRecord.h:171
casacore::String intent
Definition: DataRecord.h:230
String: the storage and methods of handling collections of characters.
Definition: String.h:223
T * storage()
If you really, really, need a &quot;raw&quot; pointer to the beginning of the storage area this will give it to...
Definition: Block.h:605
casacore::Float pressure
Definition: DataRecord.h:537
casacore::IPosition data_shape_
Definition: DataRecord.h:497
virtual void reference(const Array< T > &other)
Create a reference to &quot;other&quot;, which must be of dimension one.
casacore::Double interval
Definition: DataRecord.h:222
void setTsysSize(size_t n)
Definition: DataRecord.h:119
casacore::Matrix< casacore::Double > direction_slice
Definition: DataRecord.h:524
undefined value = 0
Definition: Stokes.h:68
casacore::IPosition corr_type_shape_
Definition: DataRecord.h:500
casacore::Bool flag_row
Definition: DataRecord.h:238
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42