VAPoR  3.0.0
DataMgrV3_0.h
Go to the documentation of this file.
1 #include <vector>
2 #include <iostream>
3 #include <list>
4 #include <vapor/BlkMemMgr.h>
5 #include <vapor/DC.h>
6 #include <vapor/MyBase.h>
7 #include <vapor/RegularGrid.h>
8 #include <vapor/LayeredGrid.h>
9 
10 #ifndef DataMgvV3_0_h
11 #define DataMgvV3_0_h
12 
13 using namespace std;
14 
15 namespace VAPoR {
16 class PipeLine;
17 
99 //
101 public:
102 
120  //
121  DataMgrV3_0(string format, size_t mem_size, int nthreads = 0);
122 
123  virtual ~DataMgrV3_0();
124 
135  //
136  virtual int Initialize(const std::vector <string> &files);
137 
138 
149  virtual std::vector <string> GetDataVarNames() const;
150 
168  virtual std::vector <string> GetDataVarNames(int ndim, bool spatial) const;
169 
180  virtual std::vector <string> GetCoordVarNames() const;
181 
195  virtual std::vector <string> GetCoordVarNames(int ndim, bool spatial) const;
196 
208  void GetTimeCoordinates(std::vector <double> &timecoords) const {
209  timecoords = _timeCoordinates;
210  };
211 
212 
227  bool GetDataVarInfo( string varname, VAPoR::DC::DataVar &datavar) const;
228 
239  //
240  bool GetBaseVarInfo(string varname, VAPoR::DC::BaseVar &var) const;
241 
257  bool GetCoordVarInfo(string varname, VAPoR::DC::CoordVar &cvar) const;
258 
269  bool IsTimeVarying(string varname) const;
270 
282  //
283  bool IsCompressed(string varname) const;
284 
297  //
298  int GetNumTimeSteps(string varname) const;
299 
314  //
315  int GetNumRefLevels(string varname) const;
316 
331  //
332 int GetCRatios(string varname, std::vector <size_t> &cratios) const;
333 
351  //
352  VAPoR::RegularGrid *GetVariable (
353  size_t ts, string varname, int level, int lod, bool lock=false
354  );
355 
383  VAPoR::RegularGrid *GetVariable (
384  size_t ts, string varname, int level, int lod,
385  std::vector <double> min, std::vector <double> max, bool lock=false
386  );
387 
388  VAPoR::RegularGrid *GetVariable(
389  size_t ts, string varname, int level, int lod,
390  std::vector <size_t> min, std::vector <size_t> max, bool lock=false
391  );
392 
404  int GetVariableExtents(
405  size_t ts, string varname, int level,
406  std::vector <double> &min , std::vector <double> &max
407  );
408 
409 
416  virtual int GetDimLensAtLevel(
417  string varname, int level, bool spatial,
418  std::vector <size_t> &dims_at_level,
419  std::vector <size_t> &bs_at_level
420  ) const;
421 
437  //
438  void UnlockGrid(const VAPoR::RegularGrid *rg);
439 
443  //
444  void Clear();
445 
458  //
459  virtual bool VariableExists(
460  size_t ts,
461  string varname,
462  int level = 0,
463  int lod = 0
464  );
465 
466 #ifdef DEAD
467 
487  int NewPipeline(PipeLine *pipeline);
488 
496  void RemovePipeline(string name);
497 #endif
498 
506  //
507  bool IsVariableDerived(string varname) const;
508 
517  //
518  bool IsVariableNative(string varname) const;
519 
520 
525  void PurgeVariable(string varname);
526 
528  virtual string GetMapProjection() const {return(""); };
529 
530  class BlkExts {
531  public:
532  BlkExts();
533  BlkExts(const std::vector <size_t> &bmin, const std::vector <size_t> &bmax);
534 
535  void Insert(
536  const std::vector <size_t> &bcoord,
537  const std::vector <double> &min,
538  const std::vector <double> &max
539  );
540 
541  bool Intersect(
542  const std::vector <double> &min,
543  const std::vector <double> &max,
544  std::vector <size_t> &bmin,
545  std::vector <size_t> &bmax
546  ) const;
547 
548  friend std::ostream &operator<<(
549  std::ostream &o, const BlkExts &b
550  );
551 
552  private:
553 
554  std::vector <size_t> _bmin;
555  std::vector <size_t> _bmax;
556  std::vector < std::vector < double > > _mins;
557  std::vector < std::vector < double > > _maxs;
558  };
559 private:
560 
561  //
562  // Cache for various metadata attributes
563  //
564  class VarInfoCache {
565  public:
566 
567  //
568  //
569  void Set(
570  size_t ts, std::vector <string> varnames, int level, int lod, string key,
571  const std::vector <size_t> &values
572  );
573  void Set(
574  size_t ts, string varname, int level, int lod, string key,
575  const std::vector <size_t> &values
576  ) {
577  std::vector <string> varnames;
578  varnames.push_back(varname);
579  Set(ts, varnames, level, lod, key, values);
580  }
581 
582  bool Get(
583  size_t ts, std::vector <string> varnames, int level, int lod, string key,
584  std::vector <size_t> &values
585  ) const;
586 
587  bool Get(
588  size_t ts, string varname, int level, int lod, string key,
589  std::vector <size_t> &values
590  ) const {
591  std::vector <string> varnames;
592  varnames.push_back(varname);
593  return Get(ts, varnames, level, lod, key, values);
594  }
595 
596  void PurgeSize_t(
597  size_t ts, std::vector <string> varnames, int level, int lod, string key
598  );
599  void PurgeSize_t(
600  size_t ts, string varname, int level, int lod, string key
601  ) {
602  std::vector <string> varnames;
603  varnames.push_back(varname);
604  PurgeSize_t(ts, varnames, level, lod, key);
605  }
606 
607  void Set(
608  size_t ts, std::vector <string> varnames, int level, int lod, string key,
609  const std::vector <double> &values
610  );
611  void Set(
612  size_t ts, string varname, int level, int lod, string key,
613  const std::vector <double> &values
614  ) {
615  std::vector <string> varnames;
616  varnames.push_back(varname);
617  Set(ts, varnames, level, lod, key, values);
618  }
619 
620  bool Get(
621  size_t ts, std::vector <string> varnames, int level, int lod, string key,
622  std::vector <double> &values
623  ) const;
624 
625  bool Get(
626  size_t ts, string varname, int level, int lod, string key,
627  std::vector <double> &values
628  ) const {
629  std::vector <string> varnames;
630  varnames.push_back(varname);
631  return Get(ts, varnames, level, lod, key, values);
632  }
633 
634  void PurgeDouble(
635  size_t ts, std::vector <string> varnames, int level, int lod, string key
636  );
637  void PurgeDouble(
638  size_t ts, string varname, int level, int lod, string key
639  ) {
640  std::vector <string> varnames;
641  varnames.push_back(varname);
642  PurgeDouble(ts, varnames, level, lod, key);
643  }
644 
645  void Clear() {
646  _cacheSize_t.clear();
647  _cacheDouble.clear();
648  }
649 
650  static string _make_hash(
651  string key, size_t ts, std::vector <string> cvars, int level, int lod
652  );
653 
654  private:
655 
656  std::map <string, std::vector <size_t> > _cacheSize_t;
657  std::map <string, std::vector <double> > _cacheDouble;
658 
659 
660  };
661 
662  string _format;
663  int _nthreads;
664  size_t _mem_size;
665 
666  DC *_dc;
667 
668  std::vector <double> _timeCoordinates;
669 
670  typedef struct {
671  size_t ts;
672  string varname;
673  int level;
674  int lod;
675  std::vector <size_t> bmin;
676  std::vector <size_t> bmax;
677  int lock_counter;
678  float *blks;
679  } region_t;
680 
681  // a list of all allocated regions
682  std::list <region_t> _regionsList;
683 
684  VAPoR::BlkMemMgr *_blk_mem_mgr;
685 
686 
687  std::vector <PipeLine *> _PipeLines;
688 
689 
690  VarInfoCache _varInfoCache;
691  std::map <string, BlkExts> _blkExtsCache;
692 
693  int _get_coord_vars(
694  string varname, std::vector <string> &scvars, string &tcvar
695  ) const;
696 
697  int _get_time_coordinates(std::vector <double> &timecoords);
698 
699  VAPoR::RegularGrid *_make_grid_regular(
700  const VAPoR::DC::DataVar &var,
701  const std::vector <size_t> &min,
702  const std::vector <size_t> &max,
703  const std::vector <size_t> &dims,
704  const std::vector <float *> &blkvec,
705  const std::vector <size_t> &bs,
706  const std::vector <size_t> &bmin,
707  const std::vector <size_t> &bmax
708  ) const;
709 
710  VAPoR::LayeredGrid *_make_grid_layered(
711  const VAPoR::DC::DataVar &var,
712  const std::vector <size_t> &min,
713  const std::vector <size_t> &max,
714  const std::vector <size_t> &dims,
715  const std::vector <float *> &blkvec,
716  const std::vector <size_t> &bs,
717  const std::vector <size_t> &bmin,
718  const std::vector <size_t> &bmax
719  ) const;
720 
721  VAPoR::RegularGrid *_make_grid(
722  const VAPoR::DC::DataVar &var,
723  const std::vector <size_t> &min,
724  const std::vector <size_t> &max,
725  const std::vector <size_t> &dims,
726  const std::vector <float *> &blkvec,
727  const std::vector < std::vector <size_t > > &bsvec,
728  const std::vector < std::vector <size_t > > &bminvec,
729  const std::vector < std::vector <size_t > > &bmaxvec
730  ) const;
731 
732  int _find_bounding_grid(
733  size_t ts, string varname, int level, int lod,
734  std::vector <double> min, std::vector <double> max,
735  std::vector <size_t> &min_ui, std::vector <size_t> &max_ui
736  );
737 
738 int _setupCoordVecs(
739  size_t ts,
740  string varname,
741  int level,
742  int lod,
743  const vector <size_t> &min,
744  const vector <size_t> &max,
745  vector <string> &varnames,
746  vector < vector <size_t > > &dimsvec,
747  vector < vector <size_t > > &dims_at_levelvec,
748  vector < vector <size_t > > &bsvec,
749  vector < vector <size_t > > &bs_at_levelvec,
750  vector < vector <size_t > > &bminvec,
751  vector < vector <size_t > > &bmaxvec
752  ) const;
753 
754  VAPoR::RegularGrid *_getVariable(
755  size_t ts,
756  string varname,
757  int level,
758  int lod,
759  bool lock,
760  bool dataless
761  );
762 
763  VAPoR::RegularGrid *_getVariable(
764  size_t ts,
765  string varname,
766  int level,
767  int lod,
768  std::vector <size_t> min,
769  std::vector <size_t> max,
770  bool lock,
771  bool dataless
772  );
773 
774  float *_get_region_from_cache(
775  size_t ts,
776  string varname,
777  int level,
778  int lod,
779  const std::vector <size_t> &bmin,
780  const std::vector <size_t> &bmax,
781  bool lock
782  );
783 
784  float *_get_region_from_fs(
785  size_t ts, string varname, int level, int lod,
786  const std::vector <size_t> &bs, const std::vector <size_t> &bmin,
787  const std::vector <size_t> &bmax, bool lock
788  );
789 
790  float *_get_region(
791  size_t ts,
792  string varname,
793  int level,
794  int nlevels,
795  int lod,
796  int nlods,
797  const std::vector <size_t> &bs,
798  const std::vector <size_t> &bmin,
799  const std::vector <size_t> &bmax,
800  bool lock
801  );
802  int _get_regions(
803  size_t ts,
804  const std::vector <string> &varnames,
805  int level, int lod,
806  bool lock,
807  const std::vector < std::vector <size_t > > &bsvec,
808  const std::vector < std::vector <size_t> > &bminvec,
809  const std::vector < std::vector <size_t> > &bmaxvec,
810  std::vector <float *> &blkvec
811  );
812 
813  void _unlock_blocks(const float *blks);
814 
815  std::vector <string> _get_native_variables() const;
816  std::vector <string> _get_derived_variables() const;
817 
818  float *_alloc_region(
819  size_t ts,
820  string varname,
821  int level,
822  int lod,
823  std::vector <size_t> bmin,
824  std::vector <size_t> bmax,
825  std::vector <size_t> bs,
826  int element_sz,
827  bool lock,
828  bool fill
829  );
830 
831  void _free_region(
832  size_t ts,
833  string varname,
834  int level,
835  int lod,
836  std::vector <size_t> bmin,
837  std::vector <size_t> bmax
838  );
839 
840  bool _free_lru();
841  void _free_var(string varname);
842 
843  int _level_correction(string varname, int &level) const;
844  int _lod_correction(string varname, int &lod) const;
845 
846 };
847 
848 };
849 #endif
void GetTimeCoordinates(std::vector< double > &timecoords) const
Definition: DataMgrV3_0.h:208
Base class for storing variable metadata.
Definition: DC.h:307
Coordinate variable metadata.
Definition: DC.h:472
VetsUtil base class.
Definition: MyBase.h:68
virtual string GetMapProjection() const
Definition: DataMgrV3_0.h:528
#define VDF_API
Definition: DC.h:10
Data variable metadata.
Definition: DC.h:557
A cache based data reader.
Definition: DataMgrV3_0.h:100