This file is indexed.

/usr/include/casacore/measures/TableMeasures/ArrayQuantColumn.tcc is in casacore-dev 2.2.0-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
//# ArrayQuantColumn.cc: Access to an Array Quantum Column in a table.
//# Copyright (C) 1997,1998,1999,2000,2001
//# Associated Universities, Inc. Washington DC, USA.
//#
//# This library is free software; you can redistribute it and/or modify it
//# under the terms of the GNU Library General Public License as published by
//# the Free Software Foundation; either version 2 of the License, or (at your
//# option) any later version.
//#
//# This library is distributed in the hope that it will be useful, but WITHOUT
//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
//# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
//# License for more details.
//#
//# You should have received a copy of the GNU Library General Public License
//# along with this library; if not, write to the Free Software Foundation,
//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
//#
//# Correspondence concerning AIPS++ should be addressed as follows:
//#        Internet email: aips2-request@nrao.edu.
//#        Postal address: AIPS++ Project Office
//#                        National Radio Astronomy Observatory
//#                        520 Edgemont Road
//#                        Charlottesville, VA 22903-2475 USA
//#
//# $Id$

#ifndef MEASURES_ARRAYQUANTCOLUMN_TCC
#define MEASURES_ARRAYQUANTCOLUMN_TCC

//# Includes
#include <casacore/measures/TableMeasures/ArrayQuantColumn.h>
#include <casacore/measures/TableMeasures/TableQuantumDesc.h>
#include <casacore/casa/Quanta/Quantum.h>
#include <casacore/casa/Quanta/Unit.h>
#include <casacore/tables/Tables/ArrayColumn.h>
#include <casacore/tables/Tables/ScalarColumn.h>
#include <casacore/tables/Tables/Table.h>
#include <casacore/tables/Tables/TableDesc.h>
#include <casacore/tables/Tables/ColumnDesc.h>
#include <casacore/tables/Tables/TableError.h>
#include <casacore/casa/BasicSL/String.h>


namespace casacore { //# NAMESPACE CASACORE - BEGIN

template<class T>
ArrayQuantColumn<T>::ArrayQuantColumn()
: itsDataCol    (0),
  itsArrUnitsCol(0),
  itsScaUnitsCol(0),
  itsConvOut    (False)
{}

template<class T>
ArrayQuantColumn<T>::ArrayQuantColumn (const Table& tab,
                                       const String& columnName)
: itsDataCol    (0),
  itsArrUnitsCol(0),
  itsScaUnitsCol(0),
  itsConvOut    (False)
{
  init (tab, columnName);
  itsUnitOut = itsUnit;
}

template<class T>
ArrayQuantColumn<T>::ArrayQuantColumn (const Table& tab,
                                       const String& columnName,
                                       const Unit& u)
: itsDataCol    (0),
  itsArrUnitsCol(0),
  itsScaUnitsCol(0)
{
  init (tab, columnName);
  itsUnitOut.resize(1);
  itsUnitOut(0) = u;
  itsConvOut = (! itsUnitOut(0).getName().empty());
}

template<class T>
ArrayQuantColumn<T>::ArrayQuantColumn (const Table& tab,
                                       const String& columnName,
                                       const Vector<Unit>& u)
: itsDataCol    (0),
  itsArrUnitsCol(0),
  itsScaUnitsCol(0)
{
  init (tab, columnName);
  itsUnitOut.resize(u.nelements());
  itsUnitOut = u;
  itsConvOut = False;
  for (uInt i=0; i<itsUnitOut.nelements(); i++) {
    if (! itsUnitOut(i).getName().empty()) {
      itsConvOut = True;
      break;
    }
  }
}

template<class T>
ArrayQuantColumn<T>::ArrayQuantColumn (const ArrayQuantColumn<T>& that)
: itsDataCol    (0),
  itsArrUnitsCol(0),
  itsScaUnitsCol(0)
{
  reference (that);
}

template<class T>
ArrayQuantColumn<T>::~ArrayQuantColumn()
{
  cleanUp();
}

template<class T>
void ArrayQuantColumn<T>::cleanUp()
{
  delete itsDataCol;
  itsDataCol = 0;
  delete itsArrUnitsCol;
  itsArrUnitsCol = 0;
  delete itsScaUnitsCol;
  itsScaUnitsCol = 0;
}

template<class T>
void ArrayQuantColumn<T>::init (const Table& tab, const String& columnName)
{
  TableQuantumDesc* tqDesc =
    	TableQuantumDesc::reconstruct(tab.tableDesc(), columnName);
  if (tqDesc->isUnitVariable()) {
    // the variable units column could be either an Array or a Scalar
    String varColName = tqDesc->unitColumnName();
    if (tab.tableDesc().columnDesc(varColName).isScalar()) {
      itsScaUnitsCol = new ScalarColumn<String>(tab, varColName);	
    } else {
      itsArrUnitsCol = new ArrayColumn<String>(tab, varColName);
    }
  } else {
    Vector<String> units = tqDesc->getUnits();
    itsUnit.resize (units.nelements());
    for (uInt i=0; i<units.nelements(); i++) {
      itsUnit(i) = units(i);
    }
  }
  itsDataCol = new ArrayColumn<T>(tab, columnName);
  delete tqDesc;
}

template<class T>
void ArrayQuantColumn<T>::reference (const ArrayQuantColumn<T>& that)
{
  cleanUp();
  itsUnit.resize (that.itsUnit.nelements());
  itsUnitOut.resize (that.itsUnitOut.nelements());
  itsUnit    = that.itsUnit;
  itsUnitOut = that.itsUnitOut;
  itsConvOut = that.itsConvOut;
  if (that.itsDataCol != 0) {
    itsDataCol = new ArrayColumn<T>(*that.itsDataCol);
  }
  if (that.itsArrUnitsCol != 0) {
    itsArrUnitsCol = new ArrayColumn<String>(*that.itsArrUnitsCol);
  }
  if (that.itsScaUnitsCol != 0) {
    itsScaUnitsCol = new ScalarColumn<String>(*that.itsScaUnitsCol);
  }
}

template<class T>
void ArrayQuantColumn<T>::attach (const Table& tab, 
                                  const String& columnName)
{
  reference(ArrayQuantColumn<T> (tab, columnName)); 
}
 
template<class T>
void ArrayQuantColumn<T>::attach (const Table& tab, 
                                  const String& columnName,
                                  const Unit& u)
{
  reference(ArrayQuantColumn<T> (tab, columnName, u)); 
}
 
template<class T>
void ArrayQuantColumn<T>::attach (const Table& tab, 
                                  const String& columnName,
                                  const Vector<Unit>& u)
{
  reference(ArrayQuantColumn<T> (tab, columnName, u)); 
}
 
template<class T>
Vector<String> ArrayQuantColumn<T>::getUnits() const
{
  Vector<String> names(itsUnit.nelements());
  for (uInt i=0; i<itsUnit.nelements(); i++) {
    names(i) = itsUnit(i).getName();
  }
  return names;
}

template<class T>
void ArrayQuantColumn<T>::getData (uInt rownr, Array<Quantum<T> >& q, 
                                   Bool resize) const
{ 
  // Quantums are created and put into q by taking T data from 
  // itsDataCol and Quantum units from one of itsArrUnitsCol (if units
  // are in a ArrayColumn) or itsScaUnitsCol (if units are in a
  // ScalarColumn) or from itsUnit (if units are static).
  // getStorage() is used on each array to return pointers which are 
  // used to iterate through the respective arrays.
  Bool deleteData;
  Array<T> tmpDataCol = (*itsDataCol)(rownr);
  const T* d_p = tmpDataCol.getStorage(deleteData);
  // Ensure q is the correct size. Resize if needed.
  IPosition shp = tmpDataCol.shape();
  if (!shp.isEqual(q.shape())) {
    if (resize || q.nelements() == 0) {
      q.resize(shp);
    } else {
      throw(TableArrayConformanceError("ArrayQuantColumn::get"));
    }
  }
  Bool deleteQuant;
  Quantum<T>* q_p = q.getStorage(deleteQuant);
  
  const String* u_p=0;
  Bool deleteUnits;
  Array<String> tmpUnitsCol;
  Vector<Unit> localUnit(itsUnit);
  if (itsArrUnitsCol != 0) {
    Array<String> tmp = (*itsArrUnitsCol)(rownr);
    tmpUnitsCol.reference (tmp);
    u_p = tmpUnitsCol.getStorage(deleteUnits);
  } else if (itsScaUnitsCol != 0) {
    localUnit.resize(1);
    localUnit(0) = (*itsScaUnitsCol)(rownr);
  }
  uInt nrun = localUnit.nelements();
  
  uInt n = tmpDataCol.nelements();
  for (uInt i=0; i<n; i++) {
    q_p[i].setValue (d_p[i]);
    if (itsArrUnitsCol != 0) {
      q_p[i].setUnit (u_p[i]);
    } else {
      q_p[i].setUnit (localUnit(i%nrun));
    }
  }
  
  tmpDataCol.freeStorage (d_p, deleteData);
  q.putStorage (q_p, deleteQuant);
  if (itsArrUnitsCol != 0) {
    tmpUnitsCol.freeStorage (u_p, deleteUnits);
  }
}

template<class T>
void ArrayQuantColumn<T>::get (uInt rownr, Array<Quantum<T> >& q,
                               Bool resize) const
{        
  if (itsConvOut) {
    get (rownr, q, itsUnitOut, resize);
  } else {
    getData (rownr, q, resize);
  }
}

template<class T>
void ArrayQuantColumn<T>::get (uInt rownr, Array<Quantum<T> >& q,
                               const Unit& u, Bool resize) const
{        
  getData (rownr, q, resize);
  if (! u.getName().empty()) {
    Bool deleteIt;
    Quantum<T>* q_p = q.getStorage(deleteIt);
    uInt n = q.nelements();
    for (uInt i=0; i<n; i++) {
      q_p[i].convert (u);
    }
    q.putStorage(q_p, deleteIt);
  }
}

template<class T>
void ArrayQuantColumn<T>::get (uInt rownr, Array<Quantum<T> >& q,
                               const Vector<Unit>& u, Bool resize) const
{        
  getData (rownr, q, resize);
  Bool hasUnits = False;
  uInt nrun = u.nelements();
  Vector<Bool> hasUnit(nrun, False);
  for (uInt i=0; i<nrun; i++) {
    if (!u(i).getName().empty()) {
      hasUnits = True;
      hasUnit(i) = True;
    }
  }
  if (hasUnits) {
    Bool deleteIt;
    Quantum<T>* q_p = q.getStorage(deleteIt);
    uInt n = q.nelements();
    for (uInt i=0; i<n; i++) {
      uInt inx = i%nrun;
      if (hasUnit(inx)) {
	q_p[i].convert (u(inx));
      }
    }
    q.putStorage(q_p, deleteIt);
  }
}

template<class T>
void ArrayQuantColumn<T>::get (uInt rownr, Array<Quantum<T> >& q,
                               const Quantum<T>& other, 
                               Bool resize) const
{
  get (rownr, q, other.getFullUnit(), resize);
}

template<class T> 
Array<Quantum<T> > ArrayQuantColumn<T>::operator() (uInt rownr) const
{
  Array<Quantum<T> > q;
  get (rownr, q);
  return q;
}

template<class T> 
Array<Quantum<T> > ArrayQuantColumn<T>::operator() (uInt rownr,
                                                    const Unit& u) const
{
  Array<Quantum<T> > q;
  get (rownr, q, u);
  return q;
}

template<class T> 
Array<Quantum<T> > ArrayQuantColumn<T>::operator() (uInt rownr,
                                                    const Vector<Unit>& u) const
{
  Array<Quantum<T> > q;
  get (rownr, q, u);
  return q;
}

template<class T> 
Array<Quantum<T> > ArrayQuantColumn<T>::operator()
                               (uInt rownr, const Quantum<T>& other) const
{
  Array<Quantum<T> > q;
  get (rownr, q, other);
  return q;
}

template<class T>
void ArrayQuantColumn<T>::throwIfNull() const
{
  if (isNull()) {
    throw (TableInvOper("Quantum table column is null"));
  }
}
 
template<class T>
void ArrayQuantColumn<T>::put (uInt rownr, const Array<Quantum<T> >& q)
{
  // Each quantum in q is separated out into its T component and
  // Unit component which are stored in itsDataCol and, if Units are
  // variable, itsArrUnitsCol repsectively.  If units are not variable
  // each quantum is first converted into local units before it is
  // saved.  
  
  // If q is empty, write empty arrays.
  const uInt n = q.nelements();
  if (n == 0) {
    Array<T> arr;
    itsDataCol->put (rownr, arr);
    if (itsArrUnitsCol != 0) {
      Array<String> arru;
      itsArrUnitsCol->put (rownr, arru);
    } else if (itsScaUnitsCol != 0) {
      itsScaUnitsCol->put (rownr, String());
    }
    return;
  }
  
  Array<T> dataArr(q.shape());
  Bool deleteData;
  T* d_p = dataArr.getStorage(deleteData);
  
  Bool deleteQuant;
  const Quantum<T>* q_p = q.getStorage(deleteQuant);
  
  // If units are variable they could vary per element of the quantum
  // array (i.e., the units column is also an array) or they could vary
  // by row (i.e., the units column is a Scalar Column where each row 
  // contains a single unit entry).  When variable by row, the unit of the
  // first quantum in q is used.
  Bool deleteUnits;
  String* u_p;
  Array<String> unitsArr;
  Vector<Unit> localUnit(itsUnit);
  if (itsArrUnitsCol != 0) {
    unitsArr.resize(q.shape());
    u_p = unitsArr.getStorage(deleteUnits);
  } else if (itsScaUnitsCol != 0) {
    // Take the value for unit from the first entry in q.  This
    // is safe because we know here that q contains at least 1 entry.
    localUnit.resize(1);
    localUnit(0) = q_p[0].getFullUnit();
    itsScaUnitsCol->put (rownr, localUnit(0).getName());
  }
  uInt nrun = localUnit.nelements();
  
  // Copy the value component of each quantum into the local data array.
  // If using an array to store units, copy quantum unit to local unit array
  for (uInt i=0; i<n; i++) {
    if (itsArrUnitsCol != 0) {
      u_p[i] = q_p[i].getFullUnit().getName();
      d_p[i] = q_p[i].getValue();
    } else {
      // Convert to fixed unit.
      d_p[i] = q_p[i].getValue (localUnit(i%nrun));
    }
  }
  
  // update the real columns.
  dataArr.putStorage (d_p, deleteData);
  itsDataCol->put (rownr, dataArr);
  if (itsArrUnitsCol != 0) {
    unitsArr.putStorage (u_p, deleteUnits);
    itsArrUnitsCol->put (rownr, unitsArr);
  }
  
  q.freeStorage(q_p, deleteQuant);
}

//# Declare extern templates for often used types.
#ifdef AIPS_CXX11
  extern template class Array<Quantum<Double> >;
#endif

} //# NAMESPACE CASACORE - END


#endif