LSSTApplications  11.0-13-gbb96280,12.1+18,12.1+7,12.1-1-g14f38d3+72,12.1-1-g16c0db7+5,12.1-1-g5961e7a+84,12.1-1-ge22e12b+23,12.1-11-g06625e2+4,12.1-11-g0d7f63b+4,12.1-19-gd507bfc,12.1-2-g7dda0ab+38,12.1-2-gc0bc6ab+81,12.1-21-g6ffe579+2,12.1-21-gbdb6c2a+4,12.1-24-g941c398+5,12.1-3-g57f6835+7,12.1-3-gf0736f3,12.1-37-g3ddd237,12.1-4-gf46015e+5,12.1-5-g06c326c+20,12.1-5-g648ee80+3,12.1-5-gc2189d7+4,12.1-6-ga608fc0+1,12.1-7-g3349e2a+5,12.1-7-gfd75620+9,12.1-9-g577b946+5,12.1-9-gc4df26a+10
LSSTDataManagementBasePackage
arrays.h
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 /*
3  * LSST Data Management System
4  * Copyright 2008-2014 LSST Corporation.
5  *
6  * This product includes software developed by the
7  * LSST Project (http://www.lsst.org/).
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the LSST License Statement and
20  * the GNU General Public License along with this program. If not,
21  * see <http://www.lsstcorp.org/LegalNotices/>.
22  */
23 #ifndef AFW_TABLE_arrays_h_INCLUDED
24 #define AFW_TABLE_arrays_h_INCLUDED
25 
27 #include "lsst/afw/table/Schema.h"
28 
29 namespace lsst { namespace afw { namespace table {
30 
38 template <typename T>
39 class ArrayKey : public FunctorKey< ndarray::Array<T const,1,1> >,
40  public ReferenceFunctorKey< ndarray::ArrayRef<T,1,1> >,
41  public ConstReferenceFunctorKey< ndarray::ArrayRef<T const,1,1> >
42 {
43 public:
44 
59  static ArrayKey addFields(
60  Schema & schema,
61  std::string const & name,
62  std::string const & doc,
63  std::string const & unit,
64  std::vector<T> const & docData
65  );
66 
77  static ArrayKey addFields(
78  Schema & schema,
79  std::string const & name,
80  std::string const & doc,
81  std::string const & unit,
82  int size
83  );
84 
86  ArrayKey() : _begin() {}
87 
89  explicit ArrayKey(std::vector< Key<T> > const & keys);
90 
97  explicit ArrayKey(Key< Array<T> > const & other);
98 
108  ArrayKey(SubSchema const & s);
109 
111  int getSize() const { return _size; }
112 
114  virtual ndarray::Array<T const,1,1> get(BaseRecord const & record) const;
115 
117  virtual void set(BaseRecord & record, ndarray::Array<T const,1,1> const & value) const;
118 
119 #ifndef SWIG
120  virtual ndarray::ArrayRef<T,1,1> getReference(BaseRecord & record) const;
122 
124  virtual ndarray::ArrayRef<T const,1,1> getConstReference(BaseRecord const & record) const;
125 #endif
126 
128  bool operator==(ArrayKey<T> const & other) const {
130  return other._begin == _begin && other._size == _size;
131  }
132  bool operator!=(ArrayKey<T> const & other) const { return !operator==(other); }
134 
136  bool isValid() const { return _begin.isValid(); }
137 
139  Key<T> operator[](int i) const;
140 
142  ArrayKey slice(int begin, int end) const;
143 
144 private:
145 
146  ArrayKey(Key<T> const & begin, int size) : _begin(begin), _size(size) {}
147 
149  int _size;
150 };
151 
152 }}} // namespace lsst::afw::table
153 
154 #endif // !AFW_TABLE_arrays_h_INCLUDED
Defines the fields and offsets for a table.
Definition: Schema.h:44
A FunctorKey used to get or set a ndarray::Array from a sequence of scalar Keys.
Definition: arrays.h:39
A proxy type for name lookups in a Schema.
Definition: Schema.h:340
table::Key< std::string > name
Definition: ApCorrMap.cc:71
virtual ndarray::ArrayRef< T, 1, 1 > getReference(BaseRecord &record) const
Get non-const reference array from the given record.
afw::table::Schema schema
Definition: GaussianPsf.cc:41
ArrayKey()
Default constructor; instance will not be usuable unless subsequently assigned to.
Definition: arrays.h:86
ArrayKey(Key< T > const &begin, int size)
Definition: arrays.h:146
bool operator==(ArrayKey< T > const &other) const
Compare the FunctorKey for equality with another, using the underlying scalar Keys.
Definition: arrays.h:129
virtual ndarray::ArrayRef< T const, 1, 1 > getConstReference(BaseRecord const &record) const
Get const reference array from the given record.
Base class for objects that can return a const reference to part of a record, but are not a true Key...
Definition: FunctorKey.h:105
Tag types used to declare specialized field types.
Definition: misc.h:34
virtual void set(BaseRecord &record, ndarray::Array< T const, 1, 1 > const &value) const
Set an array in the given record.
Base class for objects that can return a non-const reference to part of a record, but are not a true ...
Definition: FunctorKey.h:83
ArrayKey slice(int begin, int end) const
Return a FunctorKey corresponding to a range of elements.
Base class for all records.
Definition: BaseRecord.h:27
A class used as a handle to a particular field in a table.
Definition: fwd.h:44
Key< T > operator[](int i) const
Return a scalar Key for an element of the array.
bool operator!=(ArrayKey< T > const &other) const
Compare the FunctorKey for equality with another, using the underlying scalar Keys.
Definition: arrays.h:132
bool isValid() const
Return True if the FunctorKey contains valid scalar keys.
Definition: arrays.h:136
Convenience base class that combines the OutputFunctorKey and InputFunctorKey.
Definition: FunctorKey.h:70
static ArrayKey addFields(Schema &schema, std::string const &name, std::string const &doc, std::string const &unit, std::vector< T > const &docData)
Add an array of fields to a Schema, and return an ArrayKey that points to them.
int getSize() const
Return the number of elements in the array.
Definition: arrays.h:111