nidas  v1.2-1520
SampleTag.h
Go to the documentation of this file.
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 4; -*-
2 // vim: set shiftwidth=4 softtabstop=4 expandtab:
3 /*
4  ********************************************************************
5  ** NIDAS: NCAR In-situ Data Acquistion Software
6  **
7  ** 2005, Copyright University Corporation for Atmospheric Research
8  **
9  ** This program is free software; you can redistribute it and/or modify
10  ** it under the terms of the GNU General Public License as published by
11  ** the Free Software Foundation; either version 2 of the License, or
12  ** (at your option) any later version.
13  **
14  ** This program is distributed in the hope that it will be useful,
15  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  ** GNU General Public License for more details.
18  **
19  ** The LICENSE.txt file accompanying this software contains
20  ** a copy of the GNU General Public License. If it is not found,
21  ** write to the Free Software Foundation, Inc.,
22  ** 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  **
24  ********************************************************************
25 */
26 #ifndef NIDAS_CORE_SAMPLETAG_H
27 #define NIDAS_CORE_SAMPLETAG_H
28 
29 #include "DOMable.h"
30 #include "Sample.h"
31 #include "NidsIterators.h"
32 
33 #include <vector>
34 #include <list>
35 #include <algorithm>
36 
37 namespace nidas { namespace core {
38 
39 class DSMConfig;
40 class Variable;
41 class Parameter;
42 
87 class SampleTag : public DOMable
88 {
89 
90 public:
91 
95  SampleTag();
96 
100  SampleTag(const DSMSensor* sensor);
101 
105  SampleTag(const SampleTag&);
106 
107  virtual ~SampleTag();
108 
109  SampleTag& operator=(const SampleTag& rhs);
110 
114  void setSampleId(unsigned int val) {
115  _sampleId = val;
117  }
118 
122  unsigned int getSampleId() const { return _sampleId; }
123 
127  void setSensorId(unsigned int val) {
128  _sensorId = val;
130  }
131 
135  unsigned int getSensorId() const { return _sensorId; }
136 
140  void setDSMId(unsigned int val) { _id = SET_DSM_ID(_id,val); }
141 
145  unsigned int getDSMId() const { return GET_DSM_ID(_id); }
146 
150  dsm_sample_id_t getId() const { return GET_FULL_ID(_id); }
151 
155  unsigned int getSpSId() const { return GET_SPS_ID(_id); }
156 
160  const std::string& getSuffix() const { return _suffix; }
161 
162  void setSuffix(const std::string& val);
163 
164  const DSMConfig* getDSMConfig() const { return _dsm; }
165 
166  void setDSMConfig(const DSMConfig* val) { _dsm = val; }
167 
168  const DSMSensor* getDSMSensor() const { return _sensor; }
169 
170  void setDSMSensor(const DSMSensor* val);
171 
183  int getStation() const { return _station; }
184 
185  void setStation(int val);
186 
191  const Site* getSite() const;
192 
200  virtual void setRate(double val)
202  {
203  _rate = val;
204  }
205 
210  virtual double getRate() const { return _rate; }
211 
216  virtual void setPeriod(double val)
218  {
219  _rate = (val > 0.0) ? 1.0 / val : 0.0;
220  }
221 
226  virtual double getPeriod() const
227  {
228 
229  return (_rate > 0.0) ? 1.0 / _rate : 0.0;
230  }
231 
235  void setProcessed(bool val)
237  {
238  _processed = val;
239  }
241  bool isProcessed() const { return _processed; };
242 
243  void setScanfFormat(const std::string& val)
244  {
245  _scanfFormat = val;
246  }
247 
248  const std::string& getScanfFormat() const { return _scanfFormat; }
249 
250  void setPromptString(const std::string& val)
251  {
252  _promptString = val;
253  }
254 
255  const std::string& getPromptString() const { return _promptString; }
256 
257  void setPromptOffset(double val)
258  {
259  _promptOffset = val;
260  }
261 
262  double getPromptOffset() const { return _promptOffset; }
263 
269  virtual void addVariable(Variable* var)
271 
272  const std::vector<const Variable*>& getVariables() const;
273 
274  const std::vector<Variable*>& getVariables()
275  {
276  return _variables;
277  }
278 
279  void removeVariable(const Variable* var);
280 
284  Variable& getVariable(int i) { return *_variables[i]; }
285 
293  void addParameter(Parameter* val);
294 
295  const std::list<const Parameter*>& getParameters() const
296  {
297  return _constParameters;
298  }
299 
300  const Parameter* getParameter(const std::string& name) const;
301 
302  void setEnabled(bool val) { _enabled = val; }
303  bool isEnabled() const { return _enabled; }
304 
310  unsigned int getDataIndex(const Variable* var) const;
311 
318  float getTimetagAdjust() const { return _ttAdjustVal; }
319 
320  void setTimetagAdjust(float val) { _ttAdjustVal = val; }
321 
323 
324  void fromDOMElement(const xercesc::DOMElement*)
325  throw(nidas::util::InvalidParameterException);
326 
327  xercesc::DOMElement*
328  toDOMParent(xercesc::DOMElement* parent,bool complete) const
329  throw(xercesc::DOMException);
330 
331  xercesc::DOMElement*
332  toDOMElement(xercesc::DOMElement* node,bool complete) const
333  throw(xercesc::DOMException);
334 
335 protected:
336 
342  void setId(dsm_sample_id_t val) { _id = SET_FULL_ID(_id,val); }
343 
350  void setSpSId(unsigned int val) { _id = SET_SPS_ID(_id,val); }
351 
352 private:
353 
355 
356  unsigned int _sampleId;
357 
358  unsigned int _sensorId;
359 
360  std::string _suffix;
361 
362  int _station;
363 
364  double _rate;
365 
367 
368  const DSMConfig* _dsm;
369 
371 
372  std::vector<const Variable*> _constVariables;
373 
374  std::vector<Variable*> _variables;
375 
376  std::vector<std::string> _variableNames;
377 
378  std::string _scanfFormat;
379 
380  std::string _promptString;
381 
383 
387  std::list<Parameter*> _parameters;
388 
393  std::list<const Parameter*> _constParameters;
394 
395  bool _enabled;
396 
401 
402 };
403 
404 }} // namespace nidas namespace core
405 
406 #endif
void setDSMId(unsigned int val)
Set the DSM portion of the id.
Definition: SampleTag.h:140
unsigned int getSpSId() const
Get the sensor+sample portion of the id.
Definition: SampleTag.h:155
virtual ~SampleTag()
Definition: SampleTag.cc:140
const std::string & getScanfFormat() const
Definition: SampleTag.h:248
unsigned int getSensorId() const
Get the sensor portion of the shortId.
Definition: SampleTag.h:135
int _station
Definition: SampleTag.h:362
#define GET_DSM_ID(tid)
Definition: Sample.h:81
std::list< Parameter * > _parameters
List of pointers to Parameters.
Definition: SampleTag.h:387
bool _enabled
Definition: SampleTag.h:395
std::string _suffix
Definition: SampleTag.h:360
#define SET_DSM_ID(tid, val)
Definition: Sample.h:82
unsigned int dsm_sample_id_t
Definition: Sample.h:63
const DSMSensor * getDSMSensor() const
Definition: SampleTag.h:168
A measurement site.
Definition: Site.h:49
#define GET_FULL_ID(tid)
Definition: Sample.h:78
SampleTag()
Constructor.
Definition: SampleTag.cc:45
double _rate
Definition: SampleTag.h:364
bool isProcessed() const
Test to see if this sample is to be post processed.
Definition: SampleTag.h:241
std::vector< const Variable * > _constVariables
Definition: SampleTag.h:372
SampleTag & operator=(const SampleTag &rhs)
Definition: SampleTag.cc:103
void setPromptOffset(double val)
Definition: SampleTag.h:257
void fromDOMElement(const xercesc::DOMElement *)
Initialize myself from a xercesc::DOMElement.
Definition: SampleTag.cc:262
bool isEnabled() const
Definition: SampleTag.h:303
double _promptOffset
Definition: SampleTag.h:382
Class describing a sampled variable.
Definition: Variable.h:46
#define SET_FULL_ID(tid, val)
Definition: Sample.h:79
Class that should include all that is configurable about a DSM.
Definition: DSMConfig.h:55
Class for iterating over the Variables of a Project, Site, DSMConfig, DSMSensor, or SampleTag...
Definition: NidsIterators.h:286
void setDSMSensor(const DSMSensor *val)
Definition: SampleTag.cc:158
void setId(dsm_sample_id_t val)
Set the full id.
Definition: SampleTag.h:342
const DSMConfig * getDSMConfig() const
Definition: SampleTag.h:164
double getPromptOffset() const
Definition: SampleTag.h:262
Interface of an object that can be instantiated from a DOM element, via the fromDOMElement method...
Definition: DOMable.h:51
const std::vector< const Variable * > & getVariables() const
Definition: SampleTag.cc:211
float getTimetagAdjust() const
Whether to enable TimetagAdjuster for this sample.
Definition: SampleTag.h:318
float _ttAdjustVal
If positive, enable TimetagAdjustor for these samples.
Definition: SampleTag.h:400
virtual double getPeriod() const
Get sampling period (1/rate) in sec.
Definition: SampleTag.h:226
void removeVariable(const Variable *var)
Definition: SampleTag.cc:180
void addParameter(Parameter *val)
Add a parameter to this SampleTag.
Definition: SampleTag.cc:232
std::vector< Variable * > _variables
Definition: SampleTag.h:374
void setProcessed(bool val)
Set if this sample is going to be post processed.
Definition: SampleTag.h:235
const DSMSensor * _sensor
Definition: SampleTag.h:370
Variable & getVariable(int i)
Provide a reference to a variable - allowing one to modify it.
Definition: SampleTag.h:284
void setSuffix(const std::string &val)
Definition: SampleTag.cc:200
virtual void setRate(double val)
Set sampling rate in samples/sec.
Definition: SampleTag.h:200
const std::string & getPromptString() const
Definition: SampleTag.h:255
std::vector< std::string > _variableNames
Definition: SampleTag.h:376
int getStation() const
Station number, which is also known as the Site number.
Definition: SampleTag.h:183
dsm_sample_id_t _id
Definition: SampleTag.h:354
void setStation(int val)
Definition: SampleTag.cc:163
std::string _scanfFormat
Definition: SampleTag.h:378
std::list< const Parameter * > _constParameters
List of const pointers to Parameters for providing via getParameters().
Definition: SampleTag.h:393
void setEnabled(bool val)
Definition: SampleTag.h:302
void setSampleId(unsigned int val)
Set the sample portion of the shortId.
Definition: SampleTag.h:114
unsigned int getDSMId() const
Get the DSM portion of the id.
Definition: SampleTag.h:145
const Site * getSite() const
Get the Site of this SampleTag, which will be non-NULL only if getDSMConfig() returns non-NULL...
Definition: SampleTag.cc:173
void setDSMConfig(const DSMConfig *val)
Definition: SampleTag.h:166
VariableIterator getVariableIterator() const
Definition: SampleTag.cc:216
unsigned int _sensorId
Definition: SampleTag.h:358
const DSMConfig * _dsm
Definition: SampleTag.h:368
DSMSensor provides the basic support for reading, processing and distributing samples from a sensor a...
Definition: DSMSensor.h:87
Definition: Parameter.h:46
std::string _promptString
Definition: SampleTag.h:380
virtual void setPeriod(double val)
Set sampling period (1/rate) in sec.
Definition: SampleTag.h:216
Class describing a group of variables that are sampled and handled together.
Definition: SampleTag.h:87
const std::vector< Variable * > & getVariables()
Definition: SampleTag.h:274
const std::list< const Parameter * > & getParameters() const
Definition: SampleTag.h:295
unsigned int getSampleId() const
Get the sample portion of the shortId.
Definition: SampleTag.h:122
void setSpSId(unsigned int val)
Set the sensor + sample portions of the id.
Definition: SampleTag.h:350
xercesc::DOMElement * toDOMElement(xercesc::DOMElement *node, bool complete) const
Add my content into a DOMElement.
Definition: SampleTag.cc:482
virtual double getRate() const
Get sampling rate in samples/sec.
Definition: SampleTag.h:210
virtual void addVariable(Variable *var)
Add a variable to this SampleTag.
Definition: SampleTag.cc:150
unsigned int getDataIndex(const Variable *var) const
What is the index of a Variable into the data of a sample from this SampleTag.
Definition: SampleTag.cc:221
const Parameter * getParameter(const std::string &name) const
Definition: SampleTag.cc:252
void setTimetagAdjust(float val)
Definition: SampleTag.h:320
void setSensorId(unsigned int val)
Set the sensor portion of the shortId.
Definition: SampleTag.h:127
unsigned int _sampleId
Definition: SampleTag.h:356
xercesc::DOMElement * toDOMParent(xercesc::DOMElement *parent, bool complete) const
Create a DOMElement and append it to the parent.
Definition: SampleTag.cc:471
#define GET_SPS_ID(tid)
Definition: Sample.h:84
void setScanfFormat(const std::string &val)
Definition: SampleTag.h:243
#define SET_SPS_ID(tid, val)
Definition: Sample.h:87
void setPromptString(const std::string &val)
Definition: SampleTag.h:250
bool _processed
Definition: SampleTag.h:366
const std::string & getSuffix() const
Suffix, which is appended to variable names.
Definition: SampleTag.h:160
Definition: InvalidParameterException.h:35
dsm_sample_id_t getId() const
Get the 26 bit id, containing the DSM id and the sensor+sample id.
Definition: SampleTag.h:150