WeatherStore.h
Go to the documentation of this file.
1 #ifndef _anal_WeatherStore_h_
2 #define _anal_WeatherStore_h_
3 
4 #include <LineStringTo.h>
5 #include <set>
6 #include <iostream>
7 #include <fstream>
8 #include <iterator>
9 #include <exception>
10 
11 
12 namespace anal {
13 
14  template<class Data, class RawRow = Data>
15  struct WeatherStore {
16  template<class Iterator>
17  WeatherStore(const Iterator& begin, const Iterator& end) :
18  fSet(begin, end)
19  {
20  Check();
21  }
22 
23  WeatherStore(const std::string& filename)
24  {
25  std::ifstream file(filename);
26  if (!file.is_open()) {
27  std::cerr << "file " << filename << " missing!" << std::endl;
28  return;
29  }
30  typedef std::istream_iterator<LineStringTo<RawRow>> Iterator;
31  fSet.insert(Iterator(file), Iterator());
32  Check();
33  }
34 
35  const Data&
36  GetData(const unsigned long int gps)
37  {
38  fFound.fGPSSecond = gps;
39  const auto it = fSet.lower_bound(fFound);
40  if (it == fSet.begin()) {
41  std::cerr << "Warning: GPS second " << gps << " is before the earliest available weather data!" << std::endl;
42  fFound = *it;
43  } else if (it == fSet.end()) {
44  std::cerr << "Warning: GPS second " << gps << " is after the last available weather data!" << std::endl;
45  fFound = *fSet.rbegin();
46  } else {
47  if (it->fGPSSecond == gps)
48  fFound = *it;
49  else {
50  auto pit = it;
51  --pit;
52  fFound.Interpolate(*pit, *it, gps);
53  }
54  }
55  return fFound;
56  }
57 
58  std::size_t GetNEntries() const { return fSet.size(); }
59 
60  friend
61  std::ostream&
62  operator<<(std::ostream& os, const WeatherStore<Data>& s)
63  {
64  for (const auto& w : s.fSet)
65  os << w << '\n';
66  return os;
67  }
68 
69  private:
70  void
72  {
73  if (fSet.size() < 3)
74  throw std::logic_error("not enough weather data!");
75  }
76 
78  std::set<Data> fSet;
79  };
80 
81 }
82 
83 
84 #endif
WeatherStore(const std::string &filename)
Definition: WeatherStore.h:23
constexpr double s
Definition: AugerUnits.h:163
std::set< Data > fSet
Definition: WeatherStore.h:78
const string file
WeatherStore(const Iterator &begin, const Iterator &end)
Definition: WeatherStore.h:17
std::size_t GetNEntries() const
Definition: WeatherStore.h:58
char * filename
Definition: dump1090.h:266
const Data & GetData(const unsigned long int gps)
Definition: WeatherStore.h:36

, generated on Tue Sep 26 2023.