IODA Bundle
CategorySplit.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2020 NOAA/NWS/NCEP/EMC
3  *
4  * This software is licensed under the terms of the Apache Licence Version 2.0
5  * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6  */
7 
8 #pragma once
9 
10 #include "Split.h"
11 
12 #include <string>
13 #include <vector>
14 #include <map>
15 
16 
17 namespace Ingester
18 {
19  /// \brief Data splitter class that splits data according to a predefined categories.
20  /// \details This class sub-divides data into sub-categories depending on the value of a
21  /// mnemonic. It is assumed that the mnemonic values are integers which represent
22  /// separate categories of data. An example is Satellite ID (mnemonic: SAID) where each
23  /// possible satellite has its own unique integer ID.
24  /// The subcategories this Split divides into can either be manually specified by a
25  /// NameMap (map<integer, string>) or be automatically determined (if the given NameMap
26  /// is found to be empty). An example NameMap might look like this:
27  /// { 257 : GEOS-13,
28  /// 259 : GEOS-15 }
29  /// This NameMap tells the splitter to divide by the values of the given mnemonic
30  /// (SAID for this example) into two named groups (GEOS-13 and GEOS-15). Data
31  /// associated with mnemonic values not specified in the map are discarded. If the
32  /// NameMap were empty (unspecified) then this splitter will use the data to to
33  /// determine all all the possible values to split on automatically. Each split would
34  /// then be named according to its integer value (ex: 257, 259, 270, 271, ....).
35  class CategorySplit : public Split
36  {
37  public:
38  /// \brief Map of integers to strings where the key represents the split mnemonics integer
39  /// value and the value is a human readable name for the key.
40  typedef std::map<int, std::string> NameMap;
41 
42  /// \brief constructor
43  /// \param mnemonic BUFR mnemonic to base the split on.
44  /// \param map Name of the created categories from the integer BUFR values. May be an
45  /// empty map in which case subcategories are automatically determined from the
46  /// data.
47  CategorySplit(const std::string& mnemonic, const NameMap& map);
48 
49  /// \brief Get list of sub categories this split will create
50  /// \result Set of unique strings.
51  std::vector<std::string> subCategories(const BufrDataMap& dataMap) final;
52 
53  /// \brief Split the data according to internal rules
54  /// \param dataMap Data to be split
55  /// \result map of split data where the category is the key
56  std::map<std::string, BufrDataMap> split(const BufrDataMap& dataMap) final;
57 
58  // Getters
59  inline std::string getMnemonic() { return mnemonic_; }
60 
61  private:
63  const std::string mnemonic_;
64 
65  /// \brief Adds values to nameMap_ using the data if nameMap_ is empty.
66  /// \param dataMap Data to be split
67  void updateNameMap(const BufrDataMap& dataMap);
68  };
69 } // namespace Ingester
70 
71 
Data splitter class that splits data according to a predefined categories.
Definition: CategorySplit.h:36
std::map< int, std::string > NameMap
Map of integers to strings where the key represents the split mnemonics integer value and the value i...
Definition: CategorySplit.h:40
CategorySplit(const std::string &mnemonic, const NameMap &map)
constructor
std::map< std::string, BufrDataMap > split(const BufrDataMap &dataMap) final
Split the data according to internal rules.
std::vector< std::string > subCategories(const BufrDataMap &dataMap) final
Get list of sub categories this split will create.
const std::string mnemonic_
Definition: CategorySplit.h:63
std::string getMnemonic()
Definition: CategorySplit.h:59
void updateNameMap(const BufrDataMap &dataMap)
Adds values to nameMap_ using the data if nameMap_ is empty.
Base class for all Split objects that split data into sub-parts.
Definition: Split.h:19
IngesterArrayMap BufrDataMap
Definition: BufrTypes.h:21