GemaCoreLib
The GeMA Core library
gmResultsData.h
Go to the documentation of this file.
1 /************************************************************************
2 **
3 ** Copyright (C) 2014 by Carlos Augusto Teixera Mendes
4 ** All rights reserved.
5 **
6 ** This file is part of the "GeMA" software. It's use should respect
7 ** the terms in the license agreement that can be found together
8 ** with this source code.
9 ** It is provided AS IS, with NO WARRANTY OF ANY KIND,
10 ** INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR
11 ** A PARTICULAR PURPOSE.
12 **
13 ************************************************************************/
14 
24 #ifndef _GEMA_RESULTS_DATA_H_
25 #define _GEMA_RESULTS_DATA_H_
26 
27 #include "gmCoreConfig.h"
28 #include "gmLog.h"
29 #include "gmVector.h"
30 #include "gmMatrix.h"
31 
32 #include <QString>
33 #include <QMap>
34 #include <QObject>
35 #include <QMutex>
36 
38 class GmResultsRule;
41 
42 struct GmResultTrackedData;
44 
45 class GmSimulationData;
46 class Unit;
47 
52 {
53 Q_OBJECT
54 
55 public:
56  GmResultsData(const GmSimulationData* simData);
57  ~GmResultsData();
58 
60  void clear();
61 
63  const QMap<QString, GmResultsRule*>& monitorRules() const { return _monitorMap; }
64 
66  const QMap<QString, GmResultsRule*>& saveRules() const { return _saveMap; }
67 
68  bool addMonitorRule(GmResultsRule* rule);
69  bool addSaveRule (GmResultsRule* rule);
70 
72  int numTrackedDataSrcs() const { return _numTrackedSrcs; }
73 
74  bool evalRules(QString ruleId = "");
75 
76  int registerResultAttribute(const void* owner, QString name, QString description, Unit unit,
77  int nlin, int ncol, QString format);
78 
79  void removeRegisteredAttributes(void* owner);
80 
81  bool registerAttributeRuleDataSrc(GmResultsRule* rule, GmAttributeResultDataSrc* ds);
82 
83  void setResultAttributeValue(int id, double val);
84  void setResultAttributeValue(int id, double val1, double val2);
85  void setResultAttributeValue(int id, double val1, double val2, double val3);
86  void setResultAttributeValue(int id, const double* val);
87  void setResultAttributeValue(int id, const GmVector& val);
88  void setResultAttributeValue(int id, const GmMatrix& val);
89  void setResultAttributeValue(int id, QString val);
90 
92  int resultAttributeId(QString name) const { return _resultAttributeMap.value(name, qMakePair<void*, int>(NULL, -1)).second; }
93 
95  bool isNumericResult(int id) const
96  {
97  assert((id >= 0 && id < _resultAttributeData.size()) ||
98  ((id-firstStringAttributeId) >= 0 && (id-firstStringAttributeId) < _resultStringAttributeData.size()));
99  return id < firstStringAttributeId;
100  }
101 
104  {
105  return isNumericResult(id) ? _resultAttributeData[id].first :
106  _resultStringAttributeData[id-firstStringAttributeId].first;
107  }
108 
110  const double* resultAttributeBuffer(int id) const
111  {
112  assert(isNumericResult(id));
113  return _resultAttributeData[id].second;
114  }
115 
118  {
119  assert(!isNumericResult(id));
120  return _resultStringAttributeData[id-firstStringAttributeId].second;
121  }
122 
124  void enableMonitoring() { _monitor = true; }
125 
130  QMutex* monitoringMutex() { return &_monitorMutex; }
131 
132  void setCurrentTime(double time);
133 
134  GmResultsSerializer* newSerializer(QString fileType, const GmLogCategory& logger) const;
135 
136  void printInfo(const GmLogCategory& logger);
137 
139  const GmLogCategory& logger() const { return _logger; }
140 
141 signals:
142 
151  void monitoredValueChanged(int trackId, const GmResultTrackedData& value, bool waitForMore);
152 
154  void monitoredValueChangedDone();
155 
157  void monitoredIndexChanged(int ruleId, const GmResultTrackedIndexData& value);
158 
160  void monitoredAttributeInfoChanged(int trackId, int ruleId, QString name, QString description,
161  int type, QString unit, int nlin, int ncol, QString format);
162 
163 private:
166  {
167  if(_monitor)
168  return _registeredRuleAttributesMap.value(id, qMakePair<GmResultsRule*, GmAttributeResultDataSrc*>(NULL, NULL)).second;
169  else
170  return NULL;
171  }
172 
173  bool evalRule(GmResultsRule* rule, bool monitorRule);
174 
176  static const int firstStringAttributeId = 1000;
177 
179  bool _monitor;
180 
192 
195 
197 
199 
209 
211 
217 
222 
225 
228 };
229 
230 #endif
231 
int _numTrackedSrcs
The sum of the number of data srcs in the set of monitor result rules.
Definition: gmResultsData.h:196
QMap< QString, QPair< const void *, int > > _resultAttributeMap
Map storing for each registered result attribute name its id and the object that registered that name...
Definition: gmResultsData.h:208
QVector< QPair< GmAttributeResultDataSrcInfo *, double * > > _resultAttributeData
A list storing for each registered numeric result attribute its metadata.
Definition: gmResultsData.h:216
bool isNumericResult(int id) const
Returns true if the given valid result id refers to a numeric based value.
Definition: gmResultsData.h:95
const QMap< QString, GmResultsRule * > & monitorRules() const
Returns a const reference to the monitor rules map.
Definition: gmResultsData.h:63
Declaration of usefull configuration definitions for the Core library.
QMutex * monitoringMutex()
Returns the mutex needed to protect access to rule metadata AFTER the model loading....
Definition: gmResultsData.h:130
Declaration of the GmMatrix class.
const GmSimulationData * _simData
The simulation data object.
Definition: gmResultsData.h:178
The index data for a result rule, storing "evaluation point" data for node, cell or gauss based indic...
Definition: gmResultTrackedData.h:64
A serializer object used to save mesh data to several file formats.
Definition: gmResultsSerializer.h:48
QMap< QString, QPair< GmResultsRule *, GmAttributeResultDataSrc * > > _unregisteredRuleAttributesMap
A map storing for each yet unregistered monitor rule attribute, its associated rule + data src.
Definition: gmResultsData.h:227
Auxiliar class used to store the complete set of simulation data.
Definition: gmSimulationData.h:51
GmAttributeResultDataSrc * monitoredAttrDataSrc(int id)
Helper function to return the attribute data src for monitored attributes or NULL otherwise.
Definition: gmResultsData.h:165
const GmLogCategory & logger() const
Returns the internal logger used by rules to emmit messages.
Definition: gmResultsData.h:139
GmLogCategory _logger
The logger object used by rules to emmit messages.
Definition: gmResultsData.h:198
A result rule storing what should be exported, when it should be exported and to where it should be e...
Definition: gmResultsRule.h:54
QMap< QString, GmResultsRule * > _monitorMap
Map storing monitor result rules, keyed by rule id.
Definition: gmResultsData.h:193
void enableMonitoring()
Enables the emission of the monitorValueChanged() family of signals.
Definition: gmResultsData.h:124
A tracked data value. Can be either a double vector or a string. Thanks to the implicitly shared natu...
Definition: gmResultTrackedData.h:37
int _timeAttributeId
The id stored in _resultAttributeMap for the stanard "time" attribute.
Definition: gmResultsData.h:210
int resultAttributeId(QString name) const
Returns the id associated with the given result attribute name or -1 if no attribute with that name e...
Definition: gmResultsData.h:92
Auxiliar class used to store the complete set of results data for a simulation.
Definition: gmResultsData.h:51
bool _monitor
Is there someone monitoring data changes?
Definition: gmResultsData.h:179
Declaration of the GmVector class.
A class implementing the GmResultDataSrcInfo interface, storing the metadata and id for a result data...
Definition: gmResultDataSrc.h:43
QMutex _monitorMutex
A mutex shared with the monitor thread to protect access to rule metadata, AFTER the model loading....
Definition: gmResultsData.h:191
#define GMC_API_EXPORT
Macro for controling if the class is being exported (GEMA_CORE_LIB defined) or imported (GEMA_CORE_LI...
Definition: gmCoreConfig.h:35
QVector< QPair< GmAttributeResultDataSrcInfo *, QString > > _resultStringAttributeData
A list storing for each registered string result attribute its metadata.
Definition: gmResultsData.h:221
Class representing a category with multiple logging levels.
Definition: gmLog.h:58
A basic class used to store meta-data information about result attributes DEFINITIONS.
Definition: gmResultDataSrcInfo.h:100
const GmAttributeResultDataSrcInfo * resultAttributeInfo(int id) const
Returns the metadata associated with the given result attribute id.
Definition: gmResultsData.h:103
arma::vec GmVector
The basic type for a GeMA vector object. Currently based on an Armadillo vector.
Definition: gmVector.h:34
QString resultAttributeString(int id) const
Returns the string value for the given STRING result attribute id.
Definition: gmResultsData.h:117
int numTrackedDataSrcs() const
Returns the number of data srcs inside the set of monitor rules.
Definition: gmResultsData.h:72
QMap< QString, GmResultsRule * > _saveMap
Map storing save result rules, keyed by rule id.
Definition: gmResultsData.h:194
arma::mat GmMatrix
The basic type for a GeMA matrix object. Currently based on an Armadillo matrix.
Definition: gmMatrix.h:38
QMap< int, QPair< GmResultsRule *, GmAttributeResultDataSrc * > > _registeredRuleAttributesMap
A map storing for each result attribute id with an associated rule data src, that rule + data src obj...
Definition: gmResultsData.h:224
const double * resultAttributeBuffer(int id) const
Returns the internal buffer used to store the last saved result for the given NUMERIC result attribut...
Definition: gmResultsData.h:110
const QMap< QString, GmResultsRule * > & saveRules() const
Returns a const reference to the save rules map.
Definition: gmResultsData.h:66
Declaration of support functions and macros for information logging.