neic-glass3  1.4.6
Web.h
Go to the documentation of this file.
1 /*****************************************
2  * This file is documented for Doxygen.
3  * If you modify this file please update
4  * the comments so that Doxygen will still
5  * be able to work.
6  ****************************************/
7 #ifndef WEB_H
8 #define WEB_H
9 
10 #include <threadbaseclass.h>
11 
12 #include <json.h>
13 #include <utility>
14 #include <string>
15 #include <tuple>
16 #include <memory>
17 #include <vector>
18 #include <mutex>
19 #include <thread>
20 #include <queue>
21 #include <map>
22 #include <atomic>
23 
24 #include "TravelTime.h"
25 #include "ZoneStats.h"
26 
27 namespace glasscore {
28 
29 // forward declarations
30 class CSite;
31 class CSiteList;
32 class CNode;
33 class CPick;
34 
47  public:
59  explicit CWeb(int numThreads = 0, int sleepTime = 100, int checkInterval =
60  300);
61 
103  CWeb(std::string name, double thresh, int numDetect, int numNucleate,
104  int resolution, bool update, bool save, bool allowControllingWebs,
105  std::shared_ptr<traveltime::CTravelTime> firstTrav,
106  std::shared_ptr<traveltime::CTravelTime> secondTrav,
107  int numThreads = 0, int sleepTime = 100, int checkInterval = 300,
108  double aziTaper = 360.0, double maxDepth = 800.0,
109  double aSeismicThresh = -1.0, int numASeismicNucleate = -1);
110 
116  ~CWeb();
117 
123  void clear() override;
124 
142  bool receiveExternalMessage(std::shared_ptr<json::Object> com);
143 
176  bool initialize(std::string name, double thresh, int numDetect,
177  int numNucleate, int resolution, bool update, bool save,
178  bool allowControllingWebs,
179  std::shared_ptr<traveltime::CTravelTime> firstTrav,
180  std::shared_ptr<traveltime::CTravelTime> secondTrav,
181  double aziTaper = 360.0, double maxDepth = 800.0,
182  double aSeismicThresh = -1.0, int numASeismicNucleate = -1);
183 
194  bool generateLocalGrid(std::shared_ptr<json::Object> gridConfiguration);
195 
206  bool generateExplicitGrid(std::shared_ptr<json::Object> gridConfiguration);
207 
218  bool generateGlobalGrid(std::shared_ptr<json::Object> gridConfiguration);
219 
229  bool loadGridConfiguration(std::shared_ptr<json::Object> gridConfiguration);
230 
241  bool loadTravelTimes(json::Object *gridConfiguration);
242 
253  bool loadFilters(std::shared_ptr<json::Object> gridConfiguration);
254 
264  bool loadWebSiteList();
265 
278  void sortSiteListForNode(double lat, double lon, double depth);
279 
287  bool addSiteToSiteList(std::shared_ptr<CSite> site);
288 
296  bool removeSiteFromSiteList(std::shared_ptr<CSite> site);
297 
311  std::shared_ptr<CNode> generateNode(double lat, double lon, double z,
312  double resol);
313 
322  bool addNode(std::shared_ptr<CNode> node);
323 
333  std::shared_ptr<CNode> generateNodeSites(std::shared_ptr<CNode> node);
334 
342  void addSite(std::shared_ptr<CSite> site);
343 
352  void removeSite(std::shared_ptr<CSite> site);
353 
362  bool nodesHaveSite(std::shared_ptr<CSite> site);
363 
375  bool isSiteAllowed(std::shared_ptr<CSite> site, bool checkEnabled = true);
376 
385  void addJob(std::function<void()> newjob);
386 
391  double getAzimuthTaper() const;
392 
397  double getMaxDepth() const;
398 
403  const CSiteList* getSiteList() const;
404 
409  void setSiteList(CSiteList* siteList);
410 
416  bool getUpdate() const;
417 
424  bool getSaveGrid() const;
425 
432  bool getAllowControllingWebs() const;
433 
439  double getNodeResolution() const;
440 
446  double getNucleationStackThreshold() const;
447 
453  int getNumStationsPerNode() const;
454 
461 
466  const std::string& getName() const;
467 
473  const std::shared_ptr<traveltime::CTravelTime>& getNucleationTravelTime1() const; // NOLINT
474 
480  const std::shared_ptr<traveltime::CTravelTime>& getNucleationTravelTime2() const; // NOLINT
481 
486  int getNetworksFilterSize() const;
487 
492  int getSitesFilterSize() const;
493 
500  bool getUseOnlyTeleseismicStations() const;
501 
507  int size() const;
508 
516  glass3::util::WorkState work() override;
517 
527  bool getZoneStatsAseismic(double dLat, double dLon);
528 
539  double getZoneStatsMaxDepth(double dLat, double dLon);
540 
547 
555 
565  double isWithin(double dLat, double dLon);
566 
567  private:
571  CSiteList * m_pSiteList;
572 
578  std::vector<std::string> m_vNetworksFilter;
579 
585  std::vector<std::string> m_vSitesFilter;
586 
592  std::vector<std::string> m_vSourcesFilter;
593 
599  std::atomic<bool> m_bUseOnlyTeleseismicStations;
600 
608  std::vector<std::pair<double, std::shared_ptr<CSite>>>m_vSitesSortedForCurrentNode; // NOLINT
609 
614  std::vector<std::shared_ptr<CNode>> m_vNode;
615 
619  mutable std::mutex m_vNodeMutex;
620 
624  std::string m_sName;
625 
629  std::atomic<double> m_dMinLatitude;
630 
634  std::atomic<double> m_dMinLongitude;
635 
639  std::atomic<double> m_dHeight;
640 
644  std::atomic<double> m_dWidth;
645 
651  std::atomic<int> m_iNumStationsPerNode;
652 
658  std::atomic<int> m_iNucleationDataCountThreshold;
659 
665  std::atomic<double> m_dNucleationStackThreshold;
666 
671  std::atomic<double> m_dNodeResolution;
672 
677  std::atomic<double> m_dAzimuthTaper;
678 
683  std::atomic<double> m_dMaxDepth;
684 
690  std::atomic<double> m_dQualityFilter;
691 
696  std::atomic<double> m_dMaxSiteDistanceFilter;
697 
701  std::atomic<double> m_dDepthResolution;
702 
707  std::atomic<bool> m_bUpdate;
708 
713  std::atomic<bool> m_bSaveGrid;
714 
719  std::atomic<bool> m_bAllowControllingWebs;
720 
725  std::atomic<double> m_dASeismicNucleationStackThreshold;
726 
731  std::atomic<double> m_iASeismicNucleationDataCountThreshold;
732 
737  std::shared_ptr<traveltime::CTravelTime> m_pNucleationTravelTime1;
738 
743  std::shared_ptr<traveltime::CTravelTime> m_pNucleationTravelTime2;
744 
748  std::mutex m_vSiteMutex;
749 
753  std::queue<std::function<void()>> m_JobQueue;
754 
758  std::mutex m_QueueMutex;
759 
764  std::string m_sZoneStatsFileName;
768  std::shared_ptr<traveltime::CZoneStats> m_pZoneStats;
769 
777  mutable std::recursive_mutex m_WebMutex;
778 
783  std::atomic<int> m_tLastUpdated;
784 
788  static constexpr double k_dAzimuthTaperDefault = 360.0;
789 
793  static constexpr double k_dDepthResolutionUndefined = -1.0;
794 
800  static constexpr double k_dFibonacciRatio = 1.6180339888;
801 
805  static const int k_iNodeLatitudeIndex = 0;
806 
810  static const int k_iNodeLongitudeIndex = 1;
811 
815  static const int k_iNodeDepthIndex = 2;
816 
821  static constexpr double k_dMinimumMaxNodeDepth = 50.0;
822 };
823 } // namespace glasscore
824 #endif // WEB_H
bool loadWebSiteList()
Load web site list.
Definition: Web.cpp:1474
void sortSiteListForNode(double lat, double lon, double depth)
Sort site list.
Definition: Web.cpp:1542
bool receiveExternalMessage(std::shared_ptr< json::Object > com)
CWeb communication recieveing function.
Definition: Web.cpp:201
bool nodesHaveSite(std::shared_ptr< CSite > site)
Check if the nodes in this web has a site This function checks to see if the given site is used by an...
Definition: Web.cpp:2296
bool getSaveGrid() const
Gets a flag indicating whether this web supports saving its nodes to an external file.
Definition: Web.cpp:2344
glass3::util::WorkState work() override
Web work function.
Definition: Web.cpp:2261
std::shared_ptr< CNode > generateNode(double lat, double lon, double z, double resol)
Create new node.
Definition: Web.cpp:1629
bool getZoneStatsAseismic(double dLat, double dLon)
zone stats aseismic retrieval function
Definition: Web.cpp:2415
glasscore site list class
Definition: SiteList.h:40
bool addSiteToSiteList(std::shared_ptr< CSite > site)
Add site to this web&#39;s sitelist This function adds the given site to the site list local to this web...
Definition: Web.cpp:1568
int getNucleationDataCountThreshold() const
Gets the nucleation data minimum threshold used for this web.
Definition: Web.cpp:2369
const std::shared_ptr< traveltime::CTravelTime > & getNucleationTravelTime2() const
Gets the secondary nucleation travel time for this web.
Definition: Web.cpp:2385
int getASeismicNucleationDataCountThreshold() const
Gets the aseismic nucleation data (picks) minimum threshold used for this web.
Definition: Web.cpp:2452
bool loadGridConfiguration(std::shared_ptr< json::Object > gridConfiguration)
Load the common grid configuration.
Definition: Web.cpp:877
const std::shared_ptr< traveltime::CTravelTime > & getNucleationTravelTime1() const
Gets the primary nucleation travel time for this web.
Definition: Web.cpp:2379
int getNumStationsPerNode() const
Gets the number of stations to link to each node in this web.
Definition: Web.cpp:2364
double isWithin(double dLat, double dLon)
is coordinate within web function
Definition: Web.cpp:2457
std::shared_ptr< CNode > generateNodeSites(std::shared_ptr< CNode > node)
Create list of sites for node.
Definition: Web.cpp:1696
void setSiteList(CSiteList *siteList)
Set the CSiteList pointer used by this web for site lookups.
Definition: Web.cpp:2333
bool addNode(std::shared_ptr< CNode > node)
Add node to list.
Definition: Web.cpp:1683
bool loadTravelTimes(json::Object *gridConfiguration)
Load the travel times for this web.
Definition: Web.cpp:1068
double getZoneStatsMaxDepth(double dLat, double dLon)
zone stats max depth retrieval function
Definition: Web.cpp:2433
WorkState
glass3::util::WorkState enumeration
Definition: workstate.h:25
bool getAllowControllingWebs() const
Gets a boolean flag that stores whether this web will allow other (smaller) webs to override it&#39;s nuc...
Definition: Web.cpp:2349
void addSite(std::shared_ptr< CSite > site)
Add site to this web This function adds the given site to the list of nodes linked to this web and re...
Definition: Web.cpp:1802
const CSiteList * getSiteList() const
Get the CSiteList pointer used by this web for site lookups.
Definition: Web.cpp:2327
bool generateGlobalGrid(std::shared_ptr< json::Object > gridConfiguration)
Generate a global detection grid.
Definition: Web.cpp:237
int getNetworksFilterSize() const
Get the number of network filters for this web.
Definition: Web.cpp:2391
bool removeSiteFromSiteList(std::shared_ptr< CSite > site)
Remove site from this web&#39;s sitelist This function Removes the given site to the site list local to t...
Definition: Web.cpp:1592
void removeSite(std::shared_ptr< CSite > site)
Remove site from this web This function removes the given site to the list of nodes linked to this we...
Definition: Web.cpp:2024
void clear() override
CWeb clear function.
Definition: Web.cpp:83
int size() const
Get the number of nodes in this web.
Definition: Web.cpp:2409
const std::string & getName() const
Gets the name of this web.
Definition: Web.cpp:2374
bool generateLocalGrid(std::shared_ptr< json::Object > gridConfiguration)
Generate a local detection grid.
Definition: Web.cpp:426
double getASeismicNucleationStackThreshold() const
Gets the aseismic nucleation minimum stack threshold used for this web.
Definition: Web.cpp:2447
The namespace containing the core algorithm.
Definition: Correlation.h:17
bool getUpdate() const
Gets a flag indicating whether this web supports updates.
Definition: Web.cpp:2339
CWeb(int numThreads=0, int sleepTime=100, int checkInterval=300)
CWeb constructor.
Definition: Web.cpp:50
double getNodeResolution() const
Gets the node resolution of this web.
Definition: Web.cpp:2354
double getMaxDepth() const
Get the maximum depth used for this web.
Definition: Web.cpp:2322
bool isSiteAllowed(std::shared_ptr< CSite > site, bool checkEnabled=true)
Check to see if site allowed This function checks to see if a given site is allowed in the web by che...
Definition: Web.cpp:1417
double getAzimuthTaper() const
Get the azimuth taper used for this web.
Definition: Web.cpp:2317
bool getUseOnlyTeleseismicStations() const
Gets the flag indicating whether this web should only use sites flagged as UseForTeleseismic.
Definition: Web.cpp:2397
bool generateExplicitGrid(std::shared_ptr< json::Object > gridConfiguration)
Generate a detection grid with explicit nodes.
Definition: Web.cpp:676
~CWeb()
CWeb destructor.
Definition: Web.cpp:79
glass3::util::ThreadBaseClass class
Definition: threadbaseclass.h:34
bool initialize(std::string name, double thresh, int numDetect, int numNucleate, int resolution, bool update, bool save, bool allowControllingWebs, std::shared_ptr< traveltime::CTravelTime > firstTrav, std::shared_ptr< traveltime::CTravelTime > secondTrav, double aziTaper=360.0, double maxDepth=800.0, double aSeismicThresh=-1.0, int numASeismicNucleate=-1)
CWeb initialization function.
Definition: Web.cpp:151
double getNucleationStackThreshold() const
Gets the nucleation minimum stack threshold used for this web.
Definition: Web.cpp:2359
void addJob(std::function< void()> newjob)
add a job
Definition: Web.cpp:2240
int getSitesFilterSize() const
Get the number of site filters for this web.
Definition: Web.cpp:2403
bool loadFilters(std::shared_ptr< json::Object > gridConfiguration)
Load web filters.
Definition: Web.cpp:1266
glasscore detection web class
Definition: Web.h:46