IODA Bundle
BufrAccumulator.cpp
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 #include "BufrAccumulator.h"
9 
10 
11 #include "eckit/exception/Exceptions.h"
12 
13 
14 namespace Ingester
15 {
16  BufrAccumulator::BufrAccumulator(Eigen::Index numColumns, Eigen::Index blockSize) :
17  dataArray_(blockSize, numColumns),
18  numColumns_(numColumns),
19  numDataRows_(0),
20  blockSize_(blockSize)
21  {
22  }
23 
24  void BufrAccumulator::addRow(std::vector<FloatType>& newRow)
25  {
26  if (numDataRows_ + 1 > dataArray_.rows())
27  {
28  dataArray_.conservativeResize(dataArray_.rows() + blockSize_, numColumns_);
29  }
30 
31  dataArray_.row(numDataRows_) = Eigen::Map<IngesterArray>(newRow.data(), 1, numColumns_);
32  numDataRows_++;
33  }
34 
35  IngesterArray BufrAccumulator::getData(Eigen::Index elementPos,
36  Eigen::Index numElementsPerSet,
37  const Channels& indices)
38  {
39  if (std::find_if(indices.begin(), indices.end(),
40  [](const auto x){ return x < 1; }) != indices.end())
41  {
42  throw eckit::BadParameter("All channel numbers must be >= 1.");
43  }
44 
45  IngesterArray resultArr(numDataRows_, indices.size());
46  unsigned int colIdx = 0;
47  for (auto col : indices)
48  {
49  unsigned int offset = elementPos + numElementsPerSet * (col - 1);
50  resultArr.block(0, colIdx, numDataRows_, 1) =
51  dataArray_.block(0, offset, numDataRows_, 1);
52 
53  colIdx++;
54  }
55 
56  return resultArr;
57  }
58 
60  {
61  numDataRows_ = 0;
62  }
63 } // namespace Ingester
void addRow(std::vector< FloatType > &newRow)
Add row of data to the internal data structure.
BufrAccumulator(Eigen::Index numColumns, Eigen::Index blockSize=50000)
Eigen::Index numColumns_
Total number of columns (width of data structure)
IngesterArray dataArray_
Eigen Array that holds the accumulated data.
IngesterArray getData(Eigen::Index elementPos, Eigen::Index numElementsPerSet, const Channels &indices={1})
Get an Eigen Array that contains a slice of the collected data.
Eigen::Index blockSize_
Amount to allocate when we need to extend the Eigen Array.
Eigen::Index numDataRows_
Number of data rows of collected data.
Eigen::Array< FloatType, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > IngesterArray
Definition: IngesterTypes.h:19
std::set< size_t > Channels
Definition: BufrTypes.h:18