MultiFormatNavDataFactory.cpp
Go to the documentation of this file.
1 //==============================================================================
2 //
3 // This file is part of GNSSTk, the ARL:UT GNSS Toolkit.
4 //
5 // The GNSSTk is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published
7 // by the Free Software Foundation; either version 3.0 of the License, or
8 // any later version.
9 //
10 // The GNSSTk is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with GNSSTk; if not, write to the Free Software Foundation,
17 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 //
19 // This software was developed by Applied Research Laboratories at the
20 // University of Texas at Austin.
21 // Copyright 2004-2022, The Board of Regents of The University of Texas System
22 //
23 //==============================================================================
24 
25 
26 //==============================================================================
27 //
28 // This software was developed by Applied Research Laboratories at the
29 // University of Texas at Austin, under contract to an agency or agencies
30 // within the U.S. Department of Defense. The U.S. Government retains all
31 // rights to use, duplicate, distribute, disclose, or release this software.
32 //
33 // Pursuant to DoD Directive 523024
34 //
35 // DISTRIBUTION STATEMENT A: This software has been approved for public
36 // release, distribution is unlimited.
37 //
38 //==============================================================================
41 #include "NDFUniqConstIterator.hpp"
42 
43 namespace gnsstk
44 {
47  {
48  // get our own shared pointer to the factories map.
50  // keys for factories are not unique but that doesn't really matter.
51  for (const auto& i : *myFactories)
52  {
53  supportedSignals.insert(i.first);
54  }
55  }
56 
57 
60  {
61  clear();
62  }
63 
64 
66  find(const NavMessageID& nmid, const CommonTime& when,
67  NavDataPtr& navOut, SVHealth xmitHealth, NavValidityType valid,
68  NavSearchOrder order)
69  {
70  // Don't use factories.equal_range(nmid), as it can result in
71  // range.first and range.second being the same iterator, in
72  // which case the loop won't process anything at all.
73  // Also don't use the unique iterator as it will result in
74  // skipping over valid factories, e.g. looking for CNAV but
75  // LNAV is first in the map, the signals don't match and the
76  // factory won't be looked at again.
77  std::set<NavDataFactory*> uniques;
78  for (auto& fi : *myFactories)
79  {
80  // std::cerr << "fi.first = " << fi.first << " nmid = " << nmid << std::endl;
81  if ((fi.first == nmid) && (uniques.count(fi.second.get()) == 0))
82  {
83  if (fi.second->find(nmid, when, navOut, xmitHealth, valid, order))
84  return true;
85  uniques.insert(fi.second.get());
86  }
87  }
88  return false;
89  }
90 
91 
94  const CommonTime& when, NavDataPtr& offset,
95  SVHealth xmitHealth, NavValidityType valid)
96  {
98  {
99  if (fi.second->getOffset(fromSys, toSys, when, offset, xmitHealth,
100  valid))
101  {
102  return true;
103  }
104  }
105  return false;
106  }
107 
108 
110  edit(const CommonTime& fromTime, const CommonTime& toTime)
111  {
113  {
114  fi.second->edit(fromTime,toTime);
115  }
116  }
117 
118 
120  edit(const CommonTime& fromTime, const CommonTime& toTime,
121  const NavSatelliteID& satID)
122  {
124  {
125  fi.second->edit(fromTime,toTime,satID);
126  }
127  }
128 
129 
131  edit(const CommonTime& fromTime, const CommonTime& toTime,
132  const NavSignalID& signal)
133  {
135  {
136  fi.second->edit(fromTime,toTime,signal);
137  }
138  }
139 
140 
143  {
145  {
146  fi.second->clear();
147  }
148  }
149 
150 
153  {
154  // always use basic time system converter because
155  // 1) We don't need nanosecond precision for getInitialTime
156  // 2) We don't want to spend a lot of time searching nav data
161  {
162  CommonTime t = fi.second->getInitialTime();
163  if ((rv.getTimeSystem() == TimeSystem::Any) ||
164  (t.getTimeSystem() == TimeSystem::Any) ||
165  (t.getTimeSystem() == rv.getTimeSystem()))
166  {
167  rv = std::min(rv,t);
168  }
169  else
170  {
173  rv = std::min(rv,t);
174  }
175  }
176  return rv;
177  }
178 
179 
182  {
183  // always use basic time system converter because
184  // 1) We don't need nanosecond precision for getFinalTime
185  // 2) We don't want to spend a lot of time searching nav data
190  {
191  CommonTime t = fi.second->getFinalTime();
192  if ((rv.getTimeSystem() == TimeSystem::Any) ||
193  (t.getTimeSystem() == TimeSystem::Any) ||
194  (t.getTimeSystem() == rv.getTimeSystem()))
195  {
196  rv = std::max(rv,t);
197  }
198  else
199  {
202  rv = std::max(rv,t);
203  }
204  }
205  return rv;
206  }
207 
208 
210  getAvailableSats(const CommonTime& fromTime, const CommonTime& toTime)
211  const
212  {
213  NavSatelliteIDSet rv, tmp;
215  {
216  tmp = fi.second->getAvailableSats(fromTime, toTime);
217  for (const auto& i : tmp)
218  {
219  rv.insert(i);
220  }
221  }
222  return rv;
223  }
224 
225 
228  const CommonTime& fromTime,
229  const CommonTime& toTime)
230  const
231  {
232  NavSatelliteIDSet rv, tmp;
234  {
235  tmp = fi.second->getAvailableSats(nmt, fromTime, toTime);
236  for (const auto& i : tmp)
237  {
238  rv.insert(i);
239  }
240  }
241  return rv;
242  }
243 
244 
247  const CommonTime& toTime)
248  const
249  {
250  NavMessageIDSet rv, tmp;
252  {
253  tmp = fi.second->getAvailableMsgs(fromTime, toTime);
254  for (const auto& i : tmp)
255  {
256  rv.insert(i);
257  }
258  }
259  return rv;
260  }
261 
262 
265  const CommonTime& fromTime,
266  const CommonTime& toTime)
267  {
269  {
270  if (fi.second->isPresent(nmid, fromTime, toTime))
271  return true;
272  }
273  return false;
274  }
275 
276 
278  size() const
279  {
280  // this one is easy, it's just the sum of each individual
281  // factory's size
282  size_t rv = 0;
284  {
285  NavDataFactory *ndfp = fi.second.get();
287  dynamic_cast<NavDataFactoryWithStore*>(ndfp);
288  if (ndfs != nullptr)
289  {
290  rv += ndfs->size();
291  }
292  }
293  return rv;
294  }
295 
296 
298  count(const NavMessageID& nmid) const
299  {
300  // this one is easy, it's just the sum of each individual
301  // factory's count() results
302  size_t rv = 0;
304  {
305  NavDataFactory *ndfp = fi.second.get();
307  dynamic_cast<NavDataFactoryWithStore*>(ndfp);
308  if (ndfs != nullptr)
309  {
310  rv += ndfs->count(nmid);
311  }
312  }
313  return rv;
314  }
315 
316 
318  numSignals() const
319  {
320  std::set<NavSignalID> uniqueSig;
322  {
323  NavDataFactory *ndfp = fi.second.get();
325  dynamic_cast<NavDataFactoryWithStore*>(ndfp);
326  if (ndfs != nullptr)
327  {
328  for (const auto& mti : ndfs->data)
329  {
330  for (const auto& sigIt : mti.second)
331  {
332  uniqueSig.insert(sigIt.first);
333  }
334  }
335  }
336  }
337  return uniqueSig.size();
338  }
339 
340 
343  {
344  std::set<NavSatelliteID> uniqueSat;
346  {
347  NavDataFactory *ndfp = fi.second.get();
349  dynamic_cast<NavDataFactoryWithStore*>(ndfp);
350  if (ndfs != nullptr)
351  {
352  for (const auto& mti : ndfs->data)
353  {
354  for (const auto& satIt : mti.second)
355  {
356  uniqueSat.insert(satIt.first);
357  }
358  }
359  }
360  }
361  return uniqueSat.size();
362  }
363 
364 
367  {
368  // This will end up setting the validity filter multiple
369  // times for any factory that has multiple supported signals,
370  // but the end result is the same whether we check for
371  // duplicates or not.
373  {
374  i.second->setValidityFilter(nvt);
375  }
376  }
377 
378 
381  {
383  // This will end up setting the type filter multiple times
384  // for any factory that has multiple supported signals, but
385  // the end result is the same whether we check for duplicates
386  // or not.
388  {
389  i.second->setTypeFilter(nmts);
390  }
391  }
392 
393 
396  {
399  {
400  i.second->clearTypeFilter();
401  }
402  }
403 
404 
407  {
410  {
411  i.second->addTypeFilter(nmt);
412  }
413  }
414 
415 
418  {
419  // make sure it's a valid class first
420  NavDataFactory *ndfp = fact.get();
421  // std::cerr << "MultiFormatNavDataFactory::addFactory() ndfp = " << ndfp << std::endl;
422  if (dynamic_cast<NavDataFactoryWithStoreFile*>(ndfp) == nullptr)
423  {
424  return false;
425  }
426  if (dynamic_cast<MultiFormatNavDataFactory*>(ndfp) != nullptr)
427  {
428  return false;
429  }
430  // Yes, we do add multiple copies of the NavDataFactoryPtr to
431  // the map, it's a convenience.
432  for (const auto& si : fact->supportedSignals)
433  {
434  factories()->insert(NavDataFactoryMap::value_type(si,fact));
435  }
436  return true;
437  }
438 
439 
441  addDataSource(const std::string& source)
442  {
444  {
445  NavDataFactory *ptr = fi.second.get();
447  dynamic_cast<NavDataFactoryWithStoreFile*>(ptr);
448  if (fact != nullptr)
449  {
450  if (fact->addDataSource(source))
451  {
452  return true;
453  }
454  }
455  }
456  // none of the existing factories were able to load the data
457  return false;
458  }
459 
460 
462  process(const std::string& filename,
464  {
466  {
467  NavDataFactory *ptr = fi.second.get();
469  dynamic_cast<NavDataFactoryWithStoreFile*>(ptr);
470  if (fact != nullptr)
471  {
472  if (fact->process(filename,cb))
473  {
474  return true;
475  }
476  }
477  }
478  // none of the existing factories were able to load the data
479  return false;
480  }
481 
482 
484  dump(std::ostream& s, DumpDetail dl) const
485  {
487  {
488  NavDataFactory *ptr = fi.second.get();
489  ptr->dump(s,dl);
490  }
491  }
492 
493 
496  {
499  {
500  fi.second->setControl(ctrl);
501  }
502  }
503 
504 
505  std::string MultiFormatNavDataFactory ::
507  {
508  std::string rv;
510  {
511  NavDataFactory *ptr = fi.second.get();
512  std::string ff(ptr->getFactoryFormats());
513  if (!ff.empty())
514  {
515  if (!rv.empty())
516  rv += ", ";
517  rv += ff;
518  }
519  }
520  return rv;
521  }
522 
523 
524  std::shared_ptr<NavDataFactoryMap> MultiFormatNavDataFactory ::
526  {
527  static std::shared_ptr<NavDataFactoryMap> rv =
528  std::make_shared<NavDataFactoryMap>();
529  return rv;
530  }
531 }
gnsstk::NavDataFactoryWithStoreFile::process
virtual bool process(const std::string &filename, NavDataFactoryCallback &cb)=0
gnsstk::MultiFormatNavDataFactory::size
size_t size() const override
Return the number of nav messages in all factories.
Definition: MultiFormatNavDataFactory.cpp:278
gnsstk::NavDataPtr
std::shared_ptr< NavData > NavDataPtr
Factories instantiate these in response to find() requests.
Definition: NavData.hpp:62
gnsstk::NavMessageTypeSet
std::set< NavMessageType > NavMessageTypeSet
Set of message types, used by NavLibrary and NavDataFactory.
Definition: NavMessageType.hpp:76
gnsstk::MultiFormatNavDataFactory::numSatellites
size_t numSatellites() const override
Return the number of distinct signals including PRN, in factories.
Definition: MultiFormatNavDataFactory.cpp:342
gnsstk::NavMessageID
Class used to identify/categorize navigation message data.
Definition: NavMessageID.hpp:52
gnsstk::NavDataFactory::setControl
virtual void setControl(const FactoryControl &ctrl)
Definition: NavDataFactory.hpp:372
gnsstk::MultiFormatNavDataFactory::~MultiFormatNavDataFactory
virtual ~MultiFormatNavDataFactory()
Definition: MultiFormatNavDataFactory.cpp:59
gnsstk::MultiFormatNavDataFactory::myFactories
std::shared_ptr< NavDataFactoryMap > myFactories
Definition: MultiFormatNavDataFactory.hpp:335
gnsstk::MultiFormatNavDataFactory::getInitialTime
CommonTime getInitialTime() const override
Definition: MultiFormatNavDataFactory.cpp:152
gnsstk::MultiFormatNavDataFactory::find
bool find(const NavMessageID &nmid, const CommonTime &when, NavDataPtr &navOut, SVHealth xmitHealth, NavValidityType valid, NavSearchOrder order) override
Definition: MultiFormatNavDataFactory.cpp:66
gnsstk::MultiFormatNavDataFactory::count
size_t count(const NavMessageID &nmid) const override
Definition: MultiFormatNavDataFactory.cpp:298
gnsstk::NavSatelliteID
Definition: NavSatelliteID.hpp:57
gnsstk::max
T max(const SparseMatrix< T > &SM)
Maximum element - return 0 if empty.
Definition: SparseMatrix.hpp:881
gnsstk::MultiFormatNavDataFactory::setTypeFilter
void setTypeFilter(const NavMessageTypeSet &nmts) override
Definition: MultiFormatNavDataFactory.cpp:380
gnsstk::NavSatelliteIDSet
std::set< NavSatelliteID > NavSatelliteIDSet
Definition: NavSatelliteID.hpp:174
gnsstk::MultiFormatNavDataFactory::addFactory
static bool addFactory(NavDataFactoryPtr &fact)
Definition: MultiFormatNavDataFactory.cpp:417
gnsstk::TimeSystem::Any
@ Any
wildcard; allows comparison with any other type
gnsstk::MultiFormatNavDataFactory::numSignals
size_t numSignals() const override
Return the number of distinct signals (ignoring PRN) in factories.
Definition: MultiFormatNavDataFactory.cpp:318
gnsstk::MultiFormatNavDataFactory::getOffset
bool getOffset(TimeSystem fromSys, TimeSystem toSys, const CommonTime &when, NavDataPtr &offset, SVHealth xmitHealth=SVHealth::Any, NavValidityType valid=NavValidityType::ValidOnly) override
Definition: MultiFormatNavDataFactory.cpp:93
gnsstk::CommonTime::setTimeSystem
CommonTime & setTimeSystem(TimeSystem timeSystem)
Definition: CommonTime.hpp:195
gnsstk::CommonTime::BEGINNING_OF_TIME
static const GNSSTK_EXPORT CommonTime BEGINNING_OF_TIME
earliest representable CommonTime
Definition: CommonTime.hpp:102
gnsstk::SVHealth
SVHealth
Identify different types of SV health states.
Definition: SVHealth.hpp:52
gnsstk::NavValidityType
NavValidityType
Definition: NavValidityType.hpp:53
gnsstk::NavSearchOrder
NavSearchOrder
Specify the behavior of nav data searches in NavLibrary/NavDataFactory.
Definition: NavSearchOrder.hpp:51
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
gnsstk::MultiFormatNavDataFactory::getFactoryFormats
std::string getFactoryFormats() const override
Return a comma-separated list of formats supported by the factories.
Definition: MultiFormatNavDataFactory.cpp:506
gnsstk::NavDataFactoryWithStore::count
virtual size_t count(const NavMessageID &nmid) const
Definition: NavDataFactoryWithStore.cpp:1022
gnsstk::NavDataFactoryWithStoreFile
Define an interface for loading nav data from a file.
Definition: NavDataFactoryWithStoreFile.hpp:51
gnsstk::NavDataFactoryPtr
std::shared_ptr< NavDataFactory > NavDataFactoryPtr
Managed pointer to NavDataFactory.
Definition: NavDataFactory.hpp:398
gnsstk::NavDataFactoryCallback
Definition: NavDataFactoryCallback.hpp:54
gnsstk::MultiFormatNavDataFactory::clear
void clear() override
Remove all data from the internal store.
Definition: MultiFormatNavDataFactory.cpp:142
gnsstk::CommonTime::END_OF_TIME
static const GNSSTK_EXPORT CommonTime END_OF_TIME
latest representable CommonTime
Definition: CommonTime.hpp:104
gnsstk::NavDataFactoryWithStoreFile::addDataSource
bool addDataSource(const std::string &source) override
Definition: NavDataFactoryWithStoreFile.hpp:64
gnsstk::MultiFormatNavDataFactory::getAvailableSats
NavSatelliteIDSet getAvailableSats(const CommonTime &fromTime, const CommonTime &toTime) const override
Definition: MultiFormatNavDataFactory.cpp:210
gnsstk::MultiFormatNavDataFactory::dump
void dump(std::ostream &s, DumpDetail dl) const
Definition: MultiFormatNavDataFactory.cpp:484
BasicTimeSystemConverter.hpp
gnsstk::NavDataFactoryWithStore::size
virtual size_t size() const
Return the number of nav messages in data.
Definition: NavDataFactoryWithStore.cpp:1005
gnsstk::MultiFormatNavDataFactory::edit
void edit(const CommonTime &fromTime, const CommonTime &toTime) override
Definition: MultiFormatNavDataFactory.cpp:110
NDFUniqConstIterator.hpp
MultiFormatNavDataFactory.hpp
gnsstk::MultiFormatNavDataFactory::setControl
void setControl(const FactoryControl &ctrl) override
Definition: MultiFormatNavDataFactory.cpp:495
gnsstk::MultiFormatNavDataFactory
Definition: MultiFormatNavDataFactory.hpp:74
gnsstk::CommonTime
Definition: CommonTime.hpp:84
gnsstk::FactoryControl
Definition: FactoryControl.hpp:52
gnsstk::min
T min(const SparseMatrix< T > &SM)
Maximum element - return 0 if empty.
Definition: SparseMatrix.hpp:858
gnsstk::TimeSystem
TimeSystem
Definition of various time systems.
Definition: TimeSystem.hpp:51
gnsstk::NavDataFactory::addTypeFilter
virtual void addTypeFilter(NavMessageType nmt)
Definition: NavDataFactory.hpp:163
example6.valid
valid
Definition: example6.py:20
gnsstk::MultiFormatNavDataFactory::getAvailableMsgs
NavMessageIDSet getAvailableMsgs(const CommonTime &fromTime, const CommonTime &toTime) const override
Definition: MultiFormatNavDataFactory.cpp:246
gnsstk::MultiFormatNavDataFactory::factories
static std::shared_ptr< NavDataFactoryMap > factories()
Definition: MultiFormatNavDataFactory.cpp:525
gnsstk::MultiFormatNavDataFactory::MultiFormatNavDataFactory
MultiFormatNavDataFactory()
Initialize supportedSignals from factories.
Definition: MultiFormatNavDataFactory.cpp:46
gnsstk::TimeSystem::UTC
@ UTC
Coordinated Universal Time (e.g., from NTP)
gnsstk::NavDataFactoryWithStore::data
NavMessageMap data
Internal storage of navigation data for User searches.
Definition: NavDataFactoryWithStore.hpp:456
gnsstk::NavSignalID
Class used to identify navigation data signal types.
Definition: NavSignalID.hpp:54
gnsstk::MultiFormatNavDataFactory::clearTypeFilter
void clearTypeFilter() override
Definition: MultiFormatNavDataFactory.cpp:395
gnsstk::CommonTime::getTimeSystem
TimeSystem getTimeSystem() const
Obtain time system info (enum).
Definition: CommonTime.cpp:288
gnsstk::BasicTimeSystemConverter
Definition: BasicTimeSystemConverter.hpp:51
gnsstk::DumpDetail
DumpDetail
Specify level of detail for dump output.
Definition: DumpDetail.hpp:51
gnsstk::NavMessageType
NavMessageType
Identify different types of navigation message data.
Definition: NavMessageType.hpp:59
gnsstk::NavDataFactory::dump
virtual void dump(std::ostream &s, DumpDetail dl) const
Definition: NavDataFactory.hpp:181
gnsstk::MultiFormatNavDataFactory::process
bool process(const std::string &filename, NavDataFactoryCallback &cb) override
Definition: MultiFormatNavDataFactory.cpp:462
gnsstk::MultiFormatNavDataFactory::isPresent
bool isPresent(const NavMessageID &nmid, const CommonTime &fromTime, const CommonTime &toTime) override
Definition: MultiFormatNavDataFactory.cpp:264
gnsstk::NavDataFactory
Definition: NavDataFactory.hpp:60
gnsstk::NavDataFactory::clearTypeFilter
virtual void clearTypeFilter()
Definition: NavDataFactory.hpp:155
gnsstk::NDFUniqIterator
Definition: NDFUniqIterator.hpp:60
gnsstk::NavDataFactory::supportedSignals
NavSignalSet supportedSignals
Definition: NavDataFactory.hpp:379
gnsstk::MultiFormatNavDataFactory::setValidityFilter
void setValidityFilter(NavValidityType nvt) override
Definition: MultiFormatNavDataFactory.cpp:366
gnsstk::CommonTime::changeTimeSystem
bool changeTimeSystem(TimeSystem timeSystem, TimeSystemConverter *conv)
Definition: CommonTime.cpp:190
gnsstk::NavMessageIDSet
std::set< NavMessageID > NavMessageIDSet
Definition: NavMessageID.hpp:101
gnsstk::NavDataFactory::setTypeFilter
virtual void setTypeFilter(const NavMessageTypeSet &nmts)
Definition: NavDataFactory.hpp:139
gnsstk::NavDataFactory::getFactoryFormats
virtual std::string getFactoryFormats() const =0
Return a comma-separated list of formats supported by this factory.
gnsstk::MultiFormatNavDataFactory::getFinalTime
CommonTime getFinalTime() const override
Definition: MultiFormatNavDataFactory.cpp:181
gnsstk::NDFUniqConstIterator
Definition: NDFUniqConstIterator.hpp:60
gnsstk::MultiFormatNavDataFactory::addDataSource
bool addDataSource(const std::string &source) override
Definition: MultiFormatNavDataFactory.cpp:441
gnsstk::MultiFormatNavDataFactory::addTypeFilter
void addTypeFilter(NavMessageType nmt) override
Definition: MultiFormatNavDataFactory.cpp:406
gnsstk::NavDataFactoryWithStore
Definition: NavDataFactoryWithStore.hpp:63


gnsstk
Author(s):
autogenerated on Wed Oct 25 2023 02:40:40