13 #include "Eigen/Dense"
14 #include "eckit/exception/Exceptions.h"
28 categoryMap_(categoryMap)
34 const std::shared_ptr<DataObject> data,
37 if (
hasKey(fieldName, categoryId))
39 std::ostringstream errorStr;
40 errorStr <<
"ERROR: Field called " << fieldName <<
" already exists ";
42 throw eckit::BadParameter(errorStr.str());
45 dataSets_.at(categoryId).insert({fieldName, data});
51 if (!
hasKey(fieldName, categoryId))
53 std::ostringstream errStr;
54 errStr <<
"ERROR: Either field called " << fieldName;
56 errStr <<
" does not exist.";
58 throw eckit::BadParameter(errStr.str());
61 return dataSets_.at(categoryId).at(fieldName);
81 std::ostringstream errStr;
83 errStr <<
" does not exist.";
85 throw eckit::BadParameter(errStr.str());
88 return dataSets_.at(categoryId).begin()->second->nrows();
93 std::vector<SubCategory> allCategories;
97 allCategories.push_back(dataSetPair.first);
100 return allCategories;
105 std::function<void(std::vector<size_t>&,
const std::vector<size_t>&,
size_t)> incIdx;
106 incIdx = [&incIdx](std::vector<size_t>& indicies,
107 const std::vector<size_t>& lengths,
110 if (indicies[idx] + 1 >= lengths[idx])
112 if (idx + 1 < indicies.size())
115 incIdx(indicies, lengths, idx + 1);
124 size_t numCombos = 1;
125 std::vector<size_t> indicies;
126 std::vector<size_t> lengths;
129 indicies.push_back(0);
130 lengths.push_back(category.second.size());
131 numCombos = numCombos * category.second.size();
134 if (!indicies.empty())
136 for (
size_t idx = 0; idx < numCombos; idx++) {
138 std::vector<std::string> subsets;
140 subsets.push_back(category.second[indicies[catIdx]]);
145 incIdx(indicies, lengths, 0);
156 std::ostringstream catStr;
158 if (!categoryId.empty())
160 for (
const auto &subCategory : categoryId)
162 catStr << subCategory <<
"_";
167 catStr <<
"__MAIN__";
DataSets dataSets_
Map of data for each possible subcategory.
std::shared_ptr< DataObject > get(const std::string &fieldName, const SubCategory &categoryId={}) const
Get a DataObject from the collection.
bool hasKey(const std::string &fieldName, const SubCategory &categoryId={}) const
Check if DataObject with name is available.
void makeDataSets()
Uses category map to generate listings of all possible subcategories.
size_t size(const SubCategory &categoryId={}) const
Get the number of rows of the specified sub category.
DataContainer()
Simple constructor.
void add(const std::string &fieldName, std::shared_ptr< DataObject > data, const SubCategory &categoryId={})
Add a DataObject to the collection.
std::vector< SubCategory > allSubCategories() const
Get the number of rows of the specified sub category.
static std::string makeSubCategoryStr(const SubCategory &categoryId)
Convenience function used to make a string out of a subcategory listing.
const CategoryMap categoryMap_
Category map given (see constructor).
std::map< std::string, std::shared_ptr< DataObject > > DataSetMap
Map string paths (ex: variable/radiance) to DataObject.
std::map< std::string, SubCategory > CategoryMap
Map of data set id's to vector of possible value strings.
std::vector< std::string > SubCategory
List of possible category strings (for splitting data)