nidas v1.2.3
Project.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 ** 2004, 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
27#ifndef NIDAS_CORE_PROJECT_H
28#define NIDAS_CORE_PROJECT_H
29
30#include "DOMable.h"
31#include "Sample.h"
32#include "NidsIterators.h"
33#include "Dictionary.h"
34#include "Datasets.h"
38
39#include <list>
40#include <set>
41#include <map>
42
43#define ACCESS_AS_SINGLETON
44
45namespace nidas { namespace core {
46
47class Site;
48class DSMServer;
49class DSMConfig;
50class DSMSensor;
51class SampleTag;
52class SensorCatalog;
53class DSMCatalog;
54class ServiceCatalog;
55class FileSet;
56class Parameter;
57
60class Project : public DOMable {
61public:
62
63 Project();
64
65 virtual ~Project();
66
74 void
75 parseXMLConfigFile(const std::string& xmlfilepath);
76
77#ifdef ACCESS_AS_SINGLETON
81 static Project* getInstance();
82
86 static void destroyInstance();
87#endif
88
89 void setName(const std::string& val) { _name = val; }
90 const std::string& getName() const { return _name; }
91
92 void setSystemName(const std::string& val) { _sysname = val; }
93 const std::string& getSystemName() const { return _sysname; }
94
95 void setConfigVersion(const std::string& val) { _configVersion = val; }
96 const std::string& getConfigVersion() const { return _configVersion; }
97
98 void setConfigName(const std::string& val) { _configName = val; }
99 const std::string& getConfigName() const { return _configName; }
100
101 void setFlightName(const std::string& val) { _flightName = val; }
102
103 const std::string& getFlightName() const;
104
105 void addSite(Site* val);
106
107 const std::list<Site*>& getSites() const { return _sites; }
108
112 int getMaxSiteNumber() const { return _maxSiteNumber; }
113
114 int getMinSiteNumber() const { return _minSiteNumber; }
115
119 void addServer(DSMServer* srvr) { _servers.push_back(srvr); }
120
121 const std::list<DSMServer*>& getServers() const { return _servers; }
122
128 std::list<DSMServer*> findServers(const std::string& hostname) const;
129
131
136 const DSMConfig* findDSM(const nidas::util::Inet4Address& addr) const;
137
150 const DSMConfig* findDSM(const std::string& name) const;
151
155 const DSMConfig* findDSM(unsigned int id) const;
156
163 std::list<nidas::core::FileSet*> findServerSampleOutputStreamFileSets(const std::string& name) const;
164
171 std::list<nidas::core::FileSet*> findServerSampleOutputStreamFileSets() const;
172
176 std::list<nidas::core::FileSet*> findSampleOutputStreamFileSets(
177 const std::string& dsmName) const;
178
182 std::list<nidas::core::FileSet*> findSampleOutputStreamFileSets() const;
183
185
186 DSMSensor* findSensor(const SampleTag* tag) const;
187
191 Site* findSite(int stationNumber) const;
192
196 Site* findSite(const std::string& name) const;
197
206 dsm_sample_id_t getUniqueSampleId(unsigned int dsmid);
207
210
213
216
218
220
222
224
226
228
230
232
238 void initSensors();
239
245 void initSensors(Site* site);
246
252 void initSensors(DSMConfig* dsm);
253
254 const Parameter* getParameter(const std::string& name) const;
255
259 void fromDOMElement(const xercesc::DOMElement*);
260
264 xercesc::DOMElement*
265 toDOMParent(xercesc::DOMElement* parent,bool complete) const;
266
270 xercesc::DOMElement*
271 toDOMElement(xercesc::DOMElement* node,bool complete) const;
272
280 std::string expandString(const std::string& input) const
281 {
282 return _dictionary.expandString(input);
283 }
284
290 bool getTokenValue(const std::string& token,std::string& value) const
291 {
292 return _dictionary.getTokenValue(token,value);
293 }
294
296 {
297 return _dictionary;
298 }
299
300 void setDataset(const Dataset& val)
301 {
302 _dataset = val;
303 }
304
305 const Dataset& getDataset() const
306 {
307 return _dataset;
308 }
309
314 void
315 disableAutoconfig(bool disable)
316 {
318 }
319
320protected:
327 {
328 _parameters.push_back(val);
329 }
330
331private:
332
338 void removeAutoConfig(xercesc::DOMNode* node, bool bumpRecursion=false);
339
340#ifdef ACCESS_AS_SINGLETON
342#endif
343
344 std::string _name;
345
346 std::string _sysname;
347
348 std::string _configVersion;
349
353 std::string _configName;
354
355 mutable std::string _flightName;
356
357 class MyDictionary : public Dictionary {
358 public:
359 MyDictionary(Project* project): _project(project) {}
362 {
363 if (&rhs != this) {
364 *(Dictionary*)this = rhs;
365 _project = rhs._project;
366 }
367 return *this;
368 }
369 bool getTokenValue(const std::string& token, std::string& value) const;
370 private:
373
374 std::list<Site*> _sites;
375
377
379
381
382 std::list<DSMServer*> _servers;
383
385
386 mutable std::map<dsm_sample_id_t,const DSMConfig*> _dsmById;
387
389
390 mutable std::map<dsm_sample_id_t,DSMSensor*> _sensorById;
391
392 std::map<int,Site*> _siteByStationNumber;
393
394 std::map<std::string,Site*> _siteByName;
395
396 std::set<dsm_sample_id_t> _usedIds;
397
399
401
405 std::list<Parameter*> _parameters;
406
411
413
423
428
429};
430
431}} // namespace nidas namespace core
432
433#endif
Interface of an object that can be instantiated from a DOM element, via the fromDOMElement method,...
Definition DOMable.h:51
A catalog of DSM DOMElements, implemented with std::map, containing dsm DOMElements,...
Definition DSMCatalog.h:42
Class for iterating over the DSMConfigs of a Project or Site.
Definition NidsIterators.h:125
Class that should include all that is configurable about a DSM.
Definition DSMConfig.h:55
DSMSensor provides the basic support for reading, processing and distributing samples from a sensor a...
Definition DSMSensor.h:88
Class for iterating over the DSMServers of a Project.
Definition NidsIterators.h:67
A provider of services to a DSM.
Definition DSMServer.h:50
Class for iterating over the DSMServices of a DSMServer.
Definition NidsIterators.h:92
A Dataset is a named collection of parameters, that are used in data processing.
Definition Datasets.h:48
Interface for a Dictionary class, which can return a string value for a string token name.
Definition Dictionary.h:38
std::string expandString(const std::string &input) const
Utility function that scans a string for tokens like ${XXXX}, or $XXX followed by any characters from...
Definition Dictionary.cc:34
Definition Parameter.h:47
Class for iterating over the Processors of a DSMServer or DSMConfig.
Definition NidsIterators.h:150
Definition Project.h:357
MyDictionary(const MyDictionary &x)
Definition Project.h:360
bool getTokenValue(const std::string &token, std::string &value) const
Definition Project.cc:979
MyDictionary & operator=(const MyDictionary &rhs)
Definition Project.h:361
MyDictionary(Project *project)
Definition Project.h:359
Project * _project
Definition Project.h:371
Definition Project.h:60
void addServer(DSMServer *srvr)
A Project has one or more DSMServers.
Definition Project.h:119
static Project * getInstance()
Project is a singleton.
Definition Project.cc:62
nidas::util::Mutex _sensorMapLock
Definition Project.h:388
xercesc::DOMElement * toDOMElement(xercesc::DOMElement *node, bool complete) const
Definition Project.cc:964
int getMinSiteNumber() const
Definition Project.h:114
std::list< Parameter * > _parameters
List of pointers to Parameters.
Definition Project.h:405
const Parameter * getParameter(const std::string &name) const
Definition Project.cc:586
std::string expandString(const std::string &input) const
Utility function to expand ${TOKEN} or $TOKEN fields in a string with their value from getTokenValue(...
Definition Project.h:280
SensorCatalog * _sensorCatalog
Definition Project.h:376
DSMServer * findServer(const nidas::util::Inet4Address &addr) const
Definition Project.cc:320
void setDSMCatalog(DSMCatalog *val)
Definition Project.h:211
void setSystemName(const std::string &val)
Definition Project.h:92
VariableIterator getVariableIterator() const
Definition Project.cc:214
DSMServiceIterator getDSMServiceIterator() const
Definition Project.cc:184
void removeAutoConfig(xercesc::DOMNode *node, bool bumpRecursion=false)
Scan the DOM and pull out any <autoconfig> tags, as well as change the autoconfig classes back to DSM...
Definition Project.cc:673
const DSMConfig * findDSM(const nidas::util::Inet4Address &addr) const
Find a DSM whose name corresponds to a given IP address.
Definition Project.cc:339
const std::list< DSMServer * > & getServers() const
Definition Project.h:121
const Dataset & getDataset() const
Definition Project.h:305
DSMConfigIterator getDSMConfigIterator() const
Definition Project.cc:199
SensorIterator getSensorIterator() const
Definition Project.cc:204
DSMServerIterator getDSMServerIterator() const
Definition Project.cc:179
bool getTokenValue(const std::string &token, std::string &value) const
Implement a lookup for tokens that I know about, like $PROJECT, and $SYSTEM.
Definition Project.h:290
std::string _flightName
Definition Project.h:355
Project(const Project &)
Copy not supported.
nidas::util::Mutex _lookupLock
Definition Project.h:384
int getMaxSiteNumber() const
Convenience function to return the maximum site number.
Definition Project.h:112
const std::string & getConfigName() const
Definition Project.h:99
dsm_sample_id_t getUniqueSampleId(unsigned int dsmid)
Get a temporary unique sample id for a given DSM id.
Definition Project.cc:561
std::list< nidas::core::FileSet * > findSampleOutputStreamFileSets() const
Find SampleOutputStreamFileSets of all DSMs.
Definition Project.cc:457
bool _disableAutoconfig
Definition Project.h:412
int _minSiteNumber
Definition Project.h:400
std::map< dsm_sample_id_t, DSMSensor * > _sensorById
Definition Project.h:390
void setServiceCatalog(ServiceCatalog *val)
Definition Project.h:214
SiteIterator getSiteIterator() const
Definition Project.cc:194
int _maxSiteNumber
Definition Project.h:398
void parseXMLConfigFile(const std::string &xmlfilepath)
Convenient method to fill this Project instance from the configuration in the XML file at xmlfilepath...
Definition Project.cc:119
std::map< std::string, Site * > _siteByName
Definition Project.h:394
void disableAutoconfig(bool disable)
When true, autoconfig elements in the config document are removed before realizing the Project with f...
Definition Project.h:315
ServiceCatalog * _serviceCatalog
Definition Project.h:380
std::list< DSMServer * > findServers(const std::string &hostname) const
Look for a server for this project that either has no name or whose name matches hostname.
Definition Project.cc:264
DSMCatalog * getDSMCatalog() const
Definition Project.h:212
ProcessorIterator getProcessorIterator() const
Definition Project.cc:189
Site * findSite(int stationNumber) const
Find a Site with the given station number.
Definition Project.cc:161
void setDataset(const Dataset &val)
Definition Project.h:300
xercesc::DOMElement * toDOMParent(xercesc::DOMElement *parent, bool complete) const
Definition Project.cc:953
const std::string & getFlightName() const
Definition Project.cc:130
const Dictionary & getDictionary() const
Definition Project.h:295
void setSensorCatalog(SensorCatalog *val)
Definition Project.h:208
std::map< dsm_sample_id_t, const DSMConfig * > _dsmById
Definition Project.h:386
std::string _sysname
Definition Project.h:346
static Project * _instance
Definition Project.h:341
const std::string & getSystemName() const
Definition Project.h:93
std::set< dsm_sample_id_t > _usedIds
Definition Project.h:396
Project()
Definition Project.cc:76
void addParameter(Parameter *val)
Add a parameter to this Project.
Definition Project.h:326
void setConfigName(const std::string &val)
Definition Project.h:98
const std::string & getConfigVersion() const
Definition Project.h:96
Project & operator=(const Project &)
Assignment not supported.
void addSite(Site *val)
Definition Project.cc:141
void setFlightName(const std::string &val)
Definition Project.h:101
std::list< Site * > _sites
Definition Project.h:374
const std::string & getName() const
Definition Project.h:90
static void destroyInstance()
Destory the singleton.
Definition Project.cc:69
std::list< nidas::core::FileSet * > findServerSampleOutputStreamFileSets() const
Call findServerSampleOutputStreamFileSets(name) passing the nodename returned by uname(2).
Definition Project.cc:521
std::string _configName
Name of XML file that this project was initialized from.
Definition Project.h:353
Dataset _dataset
The current dataset.
Definition Project.h:410
DSMSensor * findSensor(dsm_sample_id_t id) const
Definition Project.cc:533
virtual ~Project()
Definition Project.cc:90
ServiceCatalog * getServiceCatalog() const
Definition Project.h:215
const std::list< Site * > & getSites() const
Definition Project.h:107
nidas::core::Project::MyDictionary _dictionary
void setName(const std::string &val)
Definition Project.h:89
void fromDOMElement(const xercesc::DOMElement *)
Definition Project.cc:803
std::string _configVersion
Definition Project.h:348
std::map< int, Site * > _siteByStationNumber
Definition Project.h:392
SampleTagIterator getSampleTagIterator() const
Definition Project.cc:209
std::list< DSMServer * > _servers
Definition Project.h:382
DSMCatalog * _dsmCatalog
Definition Project.h:378
std::string _name
Definition Project.h:344
SensorCatalog * getSensorCatalog() const
Definition Project.h:209
void setConfigVersion(const std::string &val)
Definition Project.h:95
void initSensors()
Initialize all sensors for a Project.
Definition Project.cc:222
Class for iterating over the SampleTags of a Project, Site, DSMConfig, or a SampleSource.
Definition NidsIterators.h:218
Class describing a group of variables that are sampled and handled together.
Definition SampleTag.h:88
A catalog of sensor DOMElements, implemented with std::map, containing sensor DOMElements,...
Definition SensorCatalog.h:42
Class for iterating over the DSMSensors of a Project, Site, or DSMConfig.
Definition NidsIterators.h:186
A catalog of dsm DOMElements, implemented with std::map, containing dsm DOMElements,...
Definition ServiceCatalog.h:42
Class for iterating over the Sites of a Project, or the Sites served by a DSMServer.
Definition NidsIterators.h:46
A measurement site.
Definition Site.h:49
Class for iterating over the Variables of a Project, Site, DSMConfig, DSMSensor, or SampleTag.
Definition NidsIterators.h:287
Support for IP version 4 host address.
Definition Inet4Address.h:46
A C++ wrapper for a POSIX mutex.
Definition ThreadSupport.h:161
Sample * getSample(sampleType type, unsigned int len)
A convienence method for getting a sample of an enumerated type from a pool.
Definition Sample.cc:70
unsigned int dsm_sample_id_t
Definition Sample.h:64
Root namespace for the NCAR In-Situ Data Acquisition Software.
Definition A2DConverter.h:31