forked from Amber-MD/cpptraj
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDataSetList.h
More file actions
189 lines (183 loc) · 8.34 KB
/
Copy pathDataSetList.h
File metadata and controls
189 lines (183 loc) · 8.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#ifndef INC_DATASETLIST_H
#define INC_DATASETLIST_H
#include <vector>
#include "DataSet.h"
#include "ArgList.h" // GetReferenceFrame, GetTopology
#include "ReferenceFrame.h" // GetReferenceFrame
#ifdef TIMER
# include "Timer.h"
#endif
/// Hold list of DataSets.
/** Main class for handling DataSets. All DataSet types can be allocated
* by DataSetList. There is a master DataSetList in CpptrajState that will
* hold all data (generated by Actions, read in from file, etc) so it is
* available for subsequent use.
* There are currently two special classes of DataSet which have extra
* functions in DataSetList: TOPOLOGY and REF_COORDS (see below).
* This class can also be used to hold copies of DataSets, i.e. it will
* hold pointers to the DataSet classes but will not be responsible for
* allocating/freeing memory. This is made use of by e.g. the
* GetMultipleSets() function and in the DataFile class.
*/
class DataSetList {
public:
typedef std::vector<DataSet*> DataListType;
typedef std::vector<double> Darray;
DataSetList();
~DataSetList();
DataSetList& operator+=(DataSetList const&);
/// \return DataSet at didx.
DataSet* operator[](int didx) const { return DataList_[didx]; } // FIXME: No bounds check
/// DataSetList default iterator
typedef DataListType::const_iterator const_iterator;
/// Iterator to beginning of dataset list
const_iterator begin() const { return DataList_.begin(); }
/// Iterator to end of dataset list
const_iterator end() const { return DataList_.end(); }
/// Clear all non-Topology and non-Reference DataSets
void Clear();
/// Clear entire DataSetList
void ClearAll();
/// Sort sets in the DataSetList
void Sort();
/// True if no DataSets in list.
bool empty() const { return DataList_.empty(); }
/// \return number of datasets in the list
size_t size() const { return DataList_.size(); }
/// \return Number of frames from last call to AllocateSets().
long int MaxFrames() const { return maxFrames_; }
/// Set current ensemble number.
void SetEnsembleNum(int i) { ensembleNum_ = i; }
/// Set DataSetList and underlying DataSet debug level
void SetDebug(int d) { debug_ = d; }
/// Set DataSets pending status.
void SetDataSetsPending(bool b) { dataSetsPending_ = b; }
/// Set whether set has copies (no ds mem free) or not (will free ds mem).
void SetHasCopies(bool b) { hasCopies_ = b; }
/// Make all sets not part of an ensemble part of given ensemble.
//void MakeDataSetsEnsemble(int);
/// \return Ensemble number; -1 if not an ensemble
int EnsembleNum() const { return ensembleNum_; }
/// \return True if Actions have indicated DataSets will be generated.
bool DataSetsPending() const { return dataSetsPending_; }
/// Allocate 1D DataSet memory based on current max# expected frames.
void AllocateSets(long int);
/// Set width and precision of specified DataSets in the list.
void SetPrecisionOfDataSets(std::string const&, int, int);
/// Remove set from the list.
void RemoveSet( DataSet* );
/// Remove set from list but do not destroy.
DataSet* PopSet( DataSet* );
/// Get DataSet matching specified attributes exactly.
DataSet* CheckForSet( MetaData const& ) const;
/// Get DataSet corresponding to specified argument.
DataSet* GetDataSet( std::string const& ) const;
/// Get multiple DataSets matching specified argument.
DataSetList GetMultipleSets( std::string const& ) const;
/// Get all DataSets matching specified argument and type.
DataSetList GetSetsOfType( std::string const&, DataSet::DataType ) const;
/// Select multiple sets, no warning if none found.
DataSetList SelectSets( std::string const& ) const;
/// Select multiple sets by type.
DataSetList SelectSets( std::string const&, DataSet::DataType ) const;
/// Select multiple sets by group.
DataSetList SelectGroupSets( std::string const&, DataSet::DataGroup ) const;
/// Find next set of specified type with given name.
DataSet* FindSetOfType(std::string const&, DataSet::DataType) const;
/// Find COORDS DataSet or create default COORDS DataSet.
DataSet* FindCoordsSet(std::string const&);
/// Generate name based on given default and # of DataSets.
std::string GenerateDefaultName(std::string const&) const;
/// Allocate DataSet of given type - do not add to list.
static DataSet* Allocate(DataSet::DataType);
/// Add DataSet to list; set up default name if no name specified.
DataSet* AddSet( DataSet::DataType, MetaData const&, const char*);
/// Add DataSet to list with given MetaData.
DataSet* AddSet( DataSet::DataType, MetaData const&);
/// Add DataSet, no check for already existing set.
DataSet* AddSet_NoCheck(DataSet::DataType, MetaData const&);
/// Add an already set up DataSet to list; memory for DataSet will be freed.
int AddSet( DataSet* );
/// Add new sets or append to existing ones.
int AddOrAppendSets(std::string const&, Darray const&, DataListType const&);
/// Add a copy of the DataSet to the list; memory for DataSet will not be freed.
void AddCopyOfSet(DataSet*);
/// Print info on DataSets in the list
void List() const;
/// List all non-Topology/Reference data sets.
void ListDataOnly() const;
# ifdef MPI
/// Indicate whether sets added to the list need to be synced
void SetNewSetsNeedSync(bool b) { newSetsNeedSync_ = b; }
/// Call sync for DataSets in the list (MPI only)
int SynchronizeData(Parallel::Comm const&);
# endif
// REF_COORDS functions ----------------------
/// reference arg help text
static const char* RefArgs;
/// Get reference frame DataSet from args
ReferenceFrame GetReferenceFrame(ArgList&) const;
/// Set active reference for distance-based masks.
int SetActiveReference( ArgList& );
/// List all reference frames.
void ListReferenceFrames() const;
/// Remove all reference frames.
void ClearRef();
// TOPOLOGY functions ------------------------
/// GetTopology arg help text
static const char* TopArgs;
/// GetTopByIndex arg help text.
static const char* TopIdxArgs;
/// Get topology from args
Topology* GetTopology(ArgList&) const;
/// Get topology from args; allow index specified without 'parmindex'
Topology* GetTopByIndex(ArgList&) const;
/// List all topologies
void ListTopologies() const;
/// Remove all topologies.
void ClearTop();
# ifdef TIMER
void Timing() const;
# endif
private:
/// Search for and remove specified data set if found, optionally free memory.
DataSet* EraseSet( DataSet*, bool );
/// Warn if DataSet not found but may be pending.
inline void PendingWarning() const;
/// Wrapper around DataList_.push_back() that does extra bookkeeping.
void Push_Back(DataSet*);
/// Internal print routine
static inline void PrintList(DataListType const&);
/// Get reference using keywords; set error integer if error occurs.
DataSet* GetReferenceSet(ArgList&, int&) const;
/// Set specified reference data set as the active reference.
int SetActiveReference(DataSet*);
/// Get topology using keywords
DataSet* GetTopByKeyword(ArgList&, int&) const;
# ifdef TIMER
Timer time_total_;
Timer time_check_;
Timer time_setup_;
Timer time_push_;
# endif
DataSet* activeRef_; ///< Current active reference for distance-based masks.
long int maxFrames_; ///< Hold number of frames from most recent AllocateSets() call.
int debug_; ///< DataSet debug level
int ensembleNum_; ///< Ensemble member number
bool hasCopies_; ///< True if DataSets should not be freed.
bool dataSetsPending_; ///< True if Actions will generate DataSets in the future.
DataListType DataList_; ///< List of DataSets
DataListType RefList_; ///< Pointers to reference data sets.
DataListType TopList_; ///< Pointers to topology data sets.
/// Hold descriptions and allocators for all DataSet types.
struct DataToken {
const char* Description;
DataSet::AllocatorType Alloc;
};
static const DataToken DataArray[];
typedef const DataToken* TokenPtr;
# ifdef MPI
bool newSetsNeedSync_; ///< If true, any sets added need to be synced.
# endif
};
#endif