CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Table Class Reference

#include "Table.h"

Detailed Description

Description: A Table which is a 'structure of arrays'

Usage: A Table provides a 'structure of arrays' using a spreadsheet metaphor. The template arguments of a Table should be edm::soa::Column<> types which declare the type of the column and a label.

constexpr char kEta[] = "eta";
constexpr char kPhi[] = "phi";
using SphereTable = edm::soa::Table<Eta,Phi>;

The same declaration of a column should be shared by different tables in order to allow the functions to be reused across tables. [See TableView]

Accessing data within a Table is done by specifying the column and row to be used. The column is identified by the edm::soa::Column<> type and the row by an integer.

SphereTable sphereTable{...};
...
auto eta1 = sphereTable.get<Eta>(1);

One can iterate over all rows of a Table and get the values of interest

SphereTable sphereTable{...};
...
for(auto const& row: sphereTable) {
std::cout<<row.get<Eta>()<<std::endl;
}
If only some of the columns are of interest, the optimizer of the compiler
is very good at removing code associated with non-used columns and providing
a highly optimized access to just the data of interest.
On can also explicitly iterate over a single column of interest
\code
SphereTable sphereTable{...};
...
for(auto eta: sphereTable.column<Eta>()) {
std::cout<<eta<<std::endl;
}
Usually the optimizer on the compiler is able to make iteration over the entire
row and iterating over just one column compile down to exactly the same machine
instructions.
A Table can be constructed either by
1) passing as many containers as their are columns
\code
std::array<double, 4> eta = {...};
std::array<double, 4> phi = {...};
SphereTable sphereTable{eta,phi};

2) passing a single container of objects where the objects hold the value of interests and where appropriate 'value_for_column' functions are defined [See ColumnFillers.h]

class Vector {
...
double eta() const;
double phi() const;
...
};
double value_for_column(Vector const& iV, Eta*) { return iV.eta(); }
double value_for_column(Vector const& iV, Phi*) { return iV.phi(); }
...
std::vector<Vector> vectors{...};
...
SphereTable sphereTable{ vectors };

Functions which operate over Tables should not take Tables are arguments. Instead, they should take an edm::soa::TableView<>. This will allow the function to operate on any Table that uses the edm::soa::Column<> type needed by the function.

SphereTable sphericalAngles(edm::soa::TableView<X,Y,Z>);

New Table declarations can be created based on existing Table declarations. E.g. say you want a new Table based on an existing Table but with an additional column.

using ATable = edm::soa::Table<...>;
using MyLabel = edm::soa::Column<...>;
using MyATable = AddColumns_t<ATable, MyLabel>;

It is also possible to declare a new Table by removing columns from an existing declaration

using MyBTable = RemoveColumn_t<BTable, Phi>; //Phi is a previously defined Column