LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Classes | Public Member Functions | Static Public Member Functions | Private Types | Private Attributes | List of all members
lsst::afw::table::SchemaMapper Class Reference

A mapping between the keys of two Schemas, used to copy data between them. More...

#include <SchemaMapper.h>

Classes

struct  AddMappingsWhere
 

Public Member Functions

Schema const getInputSchema () const
 Return the input schema (copy-on-write). More...
 
Schema const getOutputSchema () const
 Return the output schema (copy-on-write). More...
 
SchemaeditOutputSchema ()
 Return a reference to the output schema that allows it to be modified in place. More...
 
template<typename T >
Key< T > addOutputField (Field< T > const &newField, bool doReplace=false)
 Add a new field to the output Schema that is not connected to the input Schema. More...
 
template<typename T >
Key< T > addMapping (Key< T > const &inputKey, bool doReplace=false)
 Add a new field to the output Schema that is a copy of a field in the input Schema. More...
 
template<typename T >
Key< T > addMapping (Key< T > const &inputKey, Field< T > const &outputField, bool doReplace=false)
 Add a new mapped field to the output Schema with new descriptions. More...
 
template<typename T >
Key< T > addMapping (Key< T > const &inputKey, std::string const &outputName, bool doReplace=true)
 Add a new mapped field to the output Schema with a new name. More...
 
template<typename Predicate >
void addMappingsWhere (Predicate predicate, bool doReplace=true)
 Add mappings for all fields that match criteria defined by a predicate. More...
 
void addMinimalSchema (Schema const &minimal, bool doMap=true)
 Add the given minimal schema to the output schema. More...
 
void invert ()
 Swap the input and output schemas in-place. More...
 
template<typename T >
bool isMapped (Key< T > const &inputKey) const
 Return true if the given input Key is mapped to an output Key. More...
 
template<typename T >
Key< T > getMapping (Key< T > const &inputKey) const
 Return the output Key corresponding to the given input Key, or raise NotFoundError. More...
 
template<typename F >
void forEach (F func) const
 Call the given functor for each key pair in the mapper. More...
 
 SchemaMapper ()
 Construct an empty mapper; useless unless you assign a fully-constructed one to it. More...
 
 SchemaMapper (Schema const &input, Schema const &output)
 Construct a mapper from the given input Schema and initial output Schema. More...
 
 SchemaMapper (Schema const &input, bool shareAliasMap=false)
 Construct a mapper from the given input Schema. More...
 
 SchemaMapper (SchemaMapper const &other)
 Copy construct (copy-on-write). More...
 
SchemaMapperoperator= (SchemaMapper const &other)
 Assignement (copy-on-write). More...
 

Static Public Member Functions

static SchemaMapper removeMinimalSchema (Schema const &input, Schema const &minimal)
 Create a mapper by removing fields from the front of a schema. More...
 
static std::vector< SchemaMapperjoin (std::vector< Schema > const &inputs, std::vector< std::string > const &prefixes=std::vector< std::string >())
 Combine a sequence of schemas into one, creating a SchemaMapper for each. More...
 

Private Types

typedef detail::SchemaMapperImpl Impl
 

Private Attributes

boost::scoped_ptr< Impl_impl
 

Detailed Description

A mapping between the keys of two Schemas, used to copy data between them.

SchemaMapper is initialized with its input Schema, and contains member functions to add mapped or unmapped fields to the output Schema.

Definition at line 19 of file SchemaMapper.h.

Member Typedef Documentation

Definition at line 223 of file SchemaMapper.h.

Constructor & Destructor Documentation

lsst::afw::table::SchemaMapper::SchemaMapper ( )
explicit

Construct an empty mapper; useless unless you assign a fully-constructed one to it.

lsst::afw::table::SchemaMapper::SchemaMapper ( Schema const &  input,
Schema const &  output 
)
explicit

Construct a mapper from the given input Schema and initial output Schema.

Parameters
[in]inputThe Schema that fields will be mapped from.
[in]outputThe starting point for the Schema that fields will be mapped to (no mappings will be created automaticaly). Use addMapping() with doReplace=true to connect input fields to preexisting fields in the output schema.

Note that the addMapping() methods will not connect input schema fields to existing output schema fields unless doReplace=true; instead, these will by default append new fields to the output schema. So most often you'll want to start with an empty output schema and construct it as fields are mapped from the input schema, or be sure to always pass doReplace=true to addMapping.

lsst::afw::table::SchemaMapper::SchemaMapper ( Schema const &  input,
bool  shareAliasMap = false 
)
explicit

Construct a mapper from the given input Schema.

Parameters
[in]inputThe Schema that fields will be mapped from.
[in]shareAliasMapIf true, install the input Schema's AliasMap in the output Schema.

Note that the addMapping() methods will not connect input schema fields to existing output schema fields unless doReplace=true; instead, these will by default append new fields to the output schema. So most often you'll want to start with an empty output schema and construct it as fields are mapped from the input schema, or be sure to always pass doReplace=true to addMapping.

The initial (empty) output schema will have the same version as the input schema, and they will share the same AliasMap (use editOutputSchema().disconnectAliases() to use a copy of the AliasMap).

lsst::afw::table::SchemaMapper::SchemaMapper ( SchemaMapper const &  other)

Copy construct (copy-on-write).

Member Function Documentation

template<typename T >
Key<T> lsst::afw::table::SchemaMapper::addMapping ( Key< T > const &  inputKey,
bool  doReplace = false 
)

Add a new field to the output Schema that is a copy of a field in the input Schema.

If the input Key has already been mapped, the existing output Key will be reused but the associated Field in the output Schema will be reset to a copy of the input Field.

If doReplace=True and a field with same name already exists in the output schema, that field will be mapped instead of adding a new field to the output schema. If doReplace=false and a name conflict occurs, an exception will be thrown.

template<typename T >
Key<T> lsst::afw::table::SchemaMapper::addMapping ( Key< T > const &  inputKey,
Field< T > const &  outputField,
bool  doReplace = false 
)

Add a new mapped field to the output Schema with new descriptions.

If the input Key has already been mapped, the existing output Key will be reused but the associated Field will be replaced with the given one.

If doReplace=True and a field with same name already exists in the output schema, that field will be mapped instead of adding a new field to the output schema. If doReplace=false and a name conflict occurs, an exception will be thrown.

template<typename T >
Key<T> lsst::afw::table::SchemaMapper::addMapping ( Key< T > const &  inputKey,
std::string const &  outputName,
bool  doReplace = true 
)

Add a new mapped field to the output Schema with a new name.

If the input Key has already been mapped, the existing output Key will be reused but the associated Field will be replaced with one with the given name.

If doReplace=True and a field with same name already exists in the output schema, that field will be mapped instead of adding a new field to the output schema. If doReplace=false and a name conflict occurs, an exception will be thrown.

template<typename Predicate >
void lsst::afw::table::SchemaMapper::addMappingsWhere ( Predicate  predicate,
bool  doReplace = true 
)

Add mappings for all fields that match criteria defined by a predicate.

A mapping in the output Schema will be created for each SchemaItem 'i' in the input Schema such that 'predicate(i)' is true. Note that the predicate must have a templated and/or sufficiently overloaded operator() to match all supported field types, not just those present in the input Schema.

If doReplace=True and a field with same name already exists in the output schema, that field will be mapped instead of adding a new field to the output schema. If doReplace=false and a name conflict occurs, an exception will be thrown.

Definition at line 229 of file SchemaMapper.h.

229  {
230  _impl->_input.forEach(AddMappingsWhere<Predicate>(this, predicate, doReplace));
231 }
boost::scoped_ptr< Impl > _impl
Definition: SchemaMapper.h:225
void lsst::afw::table::SchemaMapper::addMinimalSchema ( Schema const &  minimal,
bool  doMap = true 
)

Add the given minimal schema to the output schema.

This is intended to be used to ensure the output schema starts with some minimal schema. It must be called before any other fields are added to the output schema.

Parameters
[in]minimalMinimal schema to be added to the beginning of the output schema.
[in]doMapWhether to map minimal schema fields that are also present in the input schema.
template<typename T >
Key<T> lsst::afw::table::SchemaMapper::addOutputField ( Field< T > const &  newField,
bool  doReplace = false 
)
inline

Add a new field to the output Schema that is not connected to the input Schema.

Definition at line 33 of file SchemaMapper.h.

33  {
34  return _impl->_output.addField(newField, doReplace);
35  }
boost::scoped_ptr< Impl > _impl
Definition: SchemaMapper.h:225
Schema& lsst::afw::table::SchemaMapper::editOutputSchema ( )
inline

Return a reference to the output schema that allows it to be modified in place.

Definition at line 29 of file SchemaMapper.h.

29 { return _impl->_output; }
boost::scoped_ptr< Impl > _impl
Definition: SchemaMapper.h:225
template<typename F >
void lsst::afw::table::SchemaMapper::forEach ( func) const
inline

Call the given functor for each key pair in the mapper.

Function objects should have a template and/or overloaded operator() that takes two Key objects with the same type:

* struct Functor {
* template <typename T>
* void operator()(Key<T> const & input, Key<T> const & output) const;
* };
*

The order of iteration is the same as the order in which mappings were added.

Definition at line 141 of file SchemaMapper.h.

141  {
142  Impl::VisitorWrapper<typename boost::unwrap_reference<F>::type &> visitor(func);
143  std::for_each(_impl->_map.begin(), _impl->_map.end(), visitor);
144  }
boost::scoped_ptr< Impl > _impl
Definition: SchemaMapper.h:225
Schema const lsst::afw::table::SchemaMapper::getInputSchema ( ) const
inline

Return the input schema (copy-on-write).

Definition at line 23 of file SchemaMapper.h.

23 { return _impl->_input; }
boost::scoped_ptr< Impl > _impl
Definition: SchemaMapper.h:225
template<typename T >
Key<T> lsst::afw::table::SchemaMapper::getMapping ( Key< T > const &  inputKey) const

Return the output Key corresponding to the given input Key, or raise NotFoundError.

Schema const lsst::afw::table::SchemaMapper::getOutputSchema ( ) const
inline

Return the output schema (copy-on-write).

Definition at line 26 of file SchemaMapper.h.

26 { return _impl->_output; }
boost::scoped_ptr< Impl > _impl
Definition: SchemaMapper.h:225
void lsst::afw::table::SchemaMapper::invert ( )

Swap the input and output schemas in-place.

template<typename T >
bool lsst::afw::table::SchemaMapper::isMapped ( Key< T > const &  inputKey) const

Return true if the given input Key is mapped to an output Key.

static std::vector<SchemaMapper> lsst::afw::table::SchemaMapper::join ( std::vector< Schema > const &  inputs,
std::vector< std::string > const &  prefixes = std::vector< std::string >() 
)
static

Combine a sequence of schemas into one, creating a SchemaMapper for each.

Parameters
[in]inputsA vector of input schemas to merge.
[in]prefixesAn optional vector of prefixes for the output field names, either empty or of the same size as the inputs vector.

Each of the returned SchemaMappers has the same output schema.

SchemaMapper& lsst::afw::table::SchemaMapper::operator= ( SchemaMapper const &  other)

Assignement (copy-on-write).

static SchemaMapper lsst::afw::table::SchemaMapper::removeMinimalSchema ( Schema const &  input,
Schema const &  minimal 
)
static

Create a mapper by removing fields from the front of a schema.

The returned mapper maps all fields in the input schema to all fields that are not in the minimal schema (compared by keys, so the overlap must appear at the beginning of the input schema).

Parameters
[in]inputInput schema for the mapper.
[in]minimalThe minimal schema the input schema starts with.

Member Data Documentation

boost::scoped_ptr<Impl> lsst::afw::table::SchemaMapper::_impl
private

Definition at line 225 of file SchemaMapper.h.


The documentation for this class was generated from the following file: