RepastHPC  2.3.1
NCDataSet.h
1 /*
2  * Repast for High Performance Computing (Repast HPC)
3  *
4  * Copyright (c) 2010 Argonne National Laboratory
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with
8  * or without modification, are permitted provided that the following
9  * conditions are met:
10  *
11  * Redistributions of source code must retain the above copyright notice,
12  * this list of conditions and the following disclaimer.
13  *
14  * Redistributions in binary form must reproduce the above copyright notice,
15  * this list of conditions and the following disclaimer in the documentation
16  * and/or other materials provided with the distribution.
17  *
18  * Neither the name of the Argonne National Laboratory nor the names of its
19  * contributors may be used to endorse or promote products derived from
20  * this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
25  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE TRUSTEES OR
26  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
32  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  *
34  *
35  * DataSet.h
36  *
37  * Created on: Jun 8, 2009
38  * Author: nick
39  */
40 
41 #ifndef NCDATASET_H
42 #define NCDATASET_H
43 
44 #include <vector>
45 #include <boost/mpi.hpp>
46 #include <netcdfcpp.h>
47 
48 #include "Schedule.h"
49 #include "RepastProcess.h"
50 #include "TDataSource.h"
51 #include "NCReducibleDataSource.h"
52 #include "DataSet.h"
53 
54 namespace repast {
55 
56 class NCDataSetBuilder;
57 
64 class NCDataSet: public DataSet {
65 
66  friend class NCDataSetBuilder;
67 
68 private:
69  std::vector<NCDataSource*> dataSources;
70  std::vector<double> ticks;
71  std::string file_;
72  const Schedule* schedule_;
73  int rank, start;
74  bool open;
75 
76  NcFile* ncfile;
77 
78  // private so can only be created using an NCDataSetBuilder
79  NCDataSet(std::string file, const Schedule& schedule);
80 
81 public:
82 
83  virtual ~NCDataSet();
84 
85  // doc inherited from DataSet
86  void record();
87 
88  // doc inherited from DataSet
89  void write();
90 
91  // doc inherited from DataSet
92  void close();
93 };
94 
110 template<typename Op>
111 NCDataSource* createNCDataSource(std::string name, TDataSource<int>* intDataSource, Op op) {
112  return new NCReducibleDataSource<Op, int> (name, intDataSource, op);
113 }
114 
130 template<typename Op>
131 NCDataSource* createNCDataSource(std::string name, TDataSource<double>* doubleDataSource, Op op) {
132  return new NCReducibleDataSource<Op, double> (name, doubleDataSource, op);
133 }
134 
135 }
136 
137 #endif /* DATASET_H_ */
repast::TDataSource
Interface for class that act as datasoures for DataSets.
Definition: TDataSource.h:53
repast::NCReducibleDataSource
Source of data and a reduction operation.
Definition: NCReducibleDataSource.h:59
repast::NCDataSource
Data source used internally by NCDataSets.
Definition: NCDataSource.h:49
repast::NCDataSetBuilder
Used to build NCDataSets to record data in NetCDF format.
Definition: NCDataSetBuilder.h:62
repast::Schedule
The simulation schedule queue.
Definition: Schedule.h:173
repast::NCDataSet::record
void record()
Records the data.
Definition: NCDataSet.cpp:96
repast::NCDataSet::close
void close()
Closes the dataset, after which it must be recreated to be used.
Definition: NCDataSet.cpp:81
repast::NCDataSet::write
void write()
Writes the data.
Definition: NCDataSet.cpp:108
repast::DataSet
Interface for recording and writing data.
Definition: DataSet.h:49
repast::NCDataSet
Provides data recording and writing into a single file in NetCDF format.
Definition: NCDataSet.h:64