#ifndef _SS_SECTOR_HPP_ #define _SS_SECTOR_HPP_ #include "SSDefs.hpp" #include "SSDataLayoutTraits.hpp" #include "SSUtilities.hpp" #include "SSEventTraits.hpp" #include "SSIdCriteria.hpp" #include "SSEvent.hpp" #include "SSKdTree.hpp" #include "SSWorkspace.hpp" #include "SSDateTime.hpp" #include #include #include #include namespace StrideSearch { /// A Sector is the StrideSearch algorithm's basic unit of work. /** A Sector has a center point on the sphere and a radius.@n It maintains a record of all data points that lie within its boundaries (both physical coordinates and data locations). Sectors are responsible for: 1. Receiving data from NCReader objects at each time step 2. Evaluating a set of identification criteria (a collection of IDCriterion subclass instances). The Sector struct is one of the fundamental StrideSearch data types (along with Event and IDCriterion). */ template struct Sector { typedef typename DataLayout::horiz_index_type horiz_index_type; /// Center latitude of Sector Real lat; /// Center longitude of Sector Real lon; /// Radius of Sector Real radius; /// Latitudes of data points contained in Sector std::vector lats; /// Longitudes of data points contained in Sector std::vector lons; /// Horizontal gridpoint indices of data points contained in Sector std::vector indices; /// One Workspace for each IDCriterion the Sector will evaluate std::vector workspaces; /// Index of latitude strip this Sector is on; see SectorSet. Int stripId; /// Complete constructor /** @param clat : Sector's center latitude coordinate @param clon : Sector's center longitude coordinate @param rad : sector radius @param lats_ : latitude coordinates of data points within *this Sector @param lons_ : longitude coordinates of data points within *this Sector @param inds : data indices of points within *this Sector @param nCrit : number of criteria to be evaluated @param sid : strip number of sector (defined by SectorSet) */ Sector(const Real clat, const Real clon, const Real rad, const std::vector& lats_, const std::vector& lons_, const std::vector& inds, const Int nCrit, const Int sid) : lat(clat), lon(clon), radius(rad), lats(lats_), lons(lons_), indices(inds), workspaces(nCrit), stripId(sid) {} /// Incomplete constructor; data points & indices, and criteria are not yet known. /** Member variables lats, lons, and indices must be set separately (e.g., by SSData::linkSectorsToData). @param clat : Sector's center latitude coordinate @param clon : Sector's center longitude coordinate @param rad : sector radius @param sid : strip number of sector (defined by SectorSet) */ Sector(const Real clat, const Real clon, const Real rad, const Int sid) : lat(clat), lon(clon), radius(rad), lats(), lons(), indices(), workspaces(), stripId(sid) {} /// Finds the data points (locations and indices) contained by this Sector void linkToData(const KDTree& tree, const std::shared_ptr ncr) { indices.clear(); lats.clear(); lons.clear(); linkHelper(tree,ncr); } /// Allocates workspaces and memory for each workspace /** Each IDCriterion requires its own Workspace.@n This subroutine performs 2 actions: 1. Allocates the appropriate number of Workspace objects for the number of criteria 2. For each criteria, allocates memory for its Workspace @param criteria : Vector of IDCriterion pointers to be evaluated */ void allocWorkspaces(const std::vector>& criteria); void allocWorkspace(const std::shared_ptr locator); /// Returns the number of points contained by this Sector inline Int nDataPoints() const {return indices.size();} /// Complete record of Sector object, output to string /** @param tab_lev : base indentation level for output @param printWorkspaces : If true, include all Workspace data in output */ std::string infoString(const int tab_lev=0, const bool printWorkspaces=false) const; /// Distance of an arbitrary point to Sector center /** @param qlat : latitude of query point @param qlon : latitude of query point */ Real distanceToCenter(const Real qlat, const Real qlon) const { return sphereDistance(lat,lon, qlat,qlon); } /// Evaluates a set criteria against a set of local data; returns an event for each criterion that evaluates true. /** @param criteria : Vector of IDCriterion pointers to be evaluated @param dt : DateTime associated with this time step @param fname : name of source file where data are located @param time_ind : time index in data file */ std::vector>> evaluateCriteriaAtTimestep( std::vector>& criteria, const DateTime& dt, const std::string& fname, const Index time_ind) const; std::shared_ptr> evaluateLocatorCriterionAtTimestep( std::shared_ptr locator, const DateTime& dt, const std::string& fname, const Index time_ind) const; private: template typename std::enable_if::value,void>::type linkHelper(const KDTree& tree, const std::shared_ptr ncr); template typename std::enable_if::value,void>::type linkHelper(const KDTree& tree, const std::shared_ptr ncr); }; } #endif