nidas  v1.2-1520
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"
37 #include <nidas/util/IOException.h>
38 
39 #include <list>
40 #include <set>
41 #include <map>
42 
43 #define ACCESS_AS_SINGLETON
44 
45 namespace nidas { namespace core {
46 
47 class Site;
48 class DSMServer;
49 class DSMConfig;
50 class DSMSensor;
51 class SampleTag;
52 class SensorCatalog;
53 class DSMCatalog;
54 class ServiceCatalog;
55 class FileSet;
56 class Parameter;
57 
60 class Project : public DOMable {
61 public:
62 
63  Project();
64 
65  virtual ~Project();
66 
72  void
73  parseXMLConfigFile(const std::string& xmlfilepath)
75 
76 #ifdef ACCESS_AS_SINGLETON
77 
80  static Project* getInstance();
81 
85  static void destroyInstance();
86 #endif
87 
88  void setName(const std::string& val) { _name = val; }
89  const std::string& getName() const { return _name; }
90 
91  void setSystemName(const std::string& val) { _sysname = val; }
92  const std::string& getSystemName() const { return _sysname; }
93 
94  void setConfigVersion(const std::string& val) { _configVersion = val; }
95  const std::string& getConfigVersion() const { return _configVersion; }
96 
97  void setConfigName(const std::string& val) { _configName = val; }
98  const std::string& getConfigName() const { return _configName; }
99 
100  void setFlightName(const std::string& val) { _flightName = val; }
101 
102  const std::string& getFlightName() const;
103 
104  void addSite(Site* val);
105 
106  const std::list<Site*>& getSites() const { return _sites; }
107 
111  int getMaxSiteNumber() const { return _maxSiteNumber; }
112 
113  int getMinSiteNumber() const { return _minSiteNumber; }
114 
118  void addServer(DSMServer* srvr) { _servers.push_back(srvr); }
119 
120  const std::list<DSMServer*>& getServers() const { return _servers; }
121 
127  std::list<DSMServer*> findServers(const std::string& hostname) const;
128 
129  DSMServer* findServer(const nidas::util::Inet4Address& addr) const;
130 
135  const DSMConfig* findDSM(const nidas::util::Inet4Address& addr) const;
136 
137  const DSMConfig* findDSM(const std::string& name) const;
138 
151  DSMConfig*
152  findDSMFromHostname(const std::string& hostname);
153 
157  const DSMConfig* findDSM(unsigned int id) const;
158 
165  std::list<nidas::core::FileSet*> findServerSampleOutputStreamFileSets(const std::string& name) const;
166 
171  std::list<nidas::core::FileSet*> findServerSampleOutputStreamFileSets() const throw(nidas::util::Exception);
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 
211  void setDSMCatalog(DSMCatalog* val) { _dsmCatalog = val; }
212  DSMCatalog* getDSMCatalog() const { return _dsmCatalog; }
213 
216 
218 
220 
222 
224 
226 
228 
230 
232 
236  void initSensors() throw(nidas::util::IOException);
237 
241  void initSensors(Site* site) throw(nidas::util::IOException);
242 
246  void initSensors(DSMConfig* dsm) throw(nidas::util::IOException);
247 
248  const Parameter* getParameter(const std::string& name) const;
249 
250  void fromDOMElement(const xercesc::DOMElement*)
251  throw(nidas::util::InvalidParameterException);
252 
253  xercesc::DOMElement*
254  toDOMParent(xercesc::DOMElement* parent,bool complete) const
255  throw(xercesc::DOMException);
256 
257  xercesc::DOMElement*
258  toDOMElement(xercesc::DOMElement* node,bool complete) const
259  throw(xercesc::DOMException);
260 
268  std::string expandString(const std::string& input) const
269  {
270  return _dictionary.expandString(input);
271  }
272 
278  bool getTokenValue(const std::string& token,std::string& value) const
279  {
280  return _dictionary.getTokenValue(token,value);
281  }
282 
283  const Dictionary& getDictionary() const
284  {
285  return _dictionary;
286  }
287 
288  void setDataset(const Dataset& val)
289  {
290  _dataset = val;
291  }
292 
293  const Dataset& getDataset() const
294  {
295  return _dataset;
296  }
297 
302  void
303  disableAutoconfig(bool disable)
304  {
305  _disableAutoconfig = disable;
306  }
307 
308 protected:
315  {
316  _parameters.push_back(val);
317  }
318 
319 private:
320 
326  void removeAutoConfig(xercesc::DOMNode* node, bool bumpRecursion=false);
327 
328 #ifdef ACCESS_AS_SINGLETON
330 #endif
331 
332  std::string _name;
333 
334  std::string _sysname;
335 
336  std::string _configVersion;
337 
341  std::string _configName;
342 
343  mutable std::string _flightName;
344 
345  class MyDictionary : public Dictionary {
346  public:
347  MyDictionary(Project* project): _project(project) {}
350  {
351  if (&rhs != this) {
352  *(Dictionary*)this = rhs;
353  _project = rhs._project;
354  }
355  return *this;
356  }
357  bool getTokenValue(const std::string& token, std::string& value) const;
358  private:
360  } _dictionary;
361 
362  std::list<Site*> _sites;
363 
365 
367 
369 
370  std::list<DSMServer*> _servers;
371 
373 
374  mutable std::map<dsm_sample_id_t,const DSMConfig*> _dsmById;
375 
377 
378  mutable std::map<dsm_sample_id_t,DSMSensor*> _sensorById;
379 
380  std::map<int,Site*> _siteByStationNumber;
381 
382  std::map<std::string,Site*> _siteByName;
383 
384  std::set<dsm_sample_id_t> _usedIds;
385 
387 
389 
393  std::list<Parameter*> _parameters;
394 
399 
401 
410  Project(const Project&);
411 
415  Project& operator=(const Project&);
416 
417 };
418 
419 }} // namespace nidas namespace core
420 
421 #endif
DSMConfigIterator getDSMConfigIterator() const
Definition: Project.cc:200
Class for iterating over the DSMServers of a Project.
Definition: NidsIterators.h:66
std::list< nidas::core::FileSet * > findSampleOutputStreamFileSets() const
Find SampleOutputStreamFileSets of all DSMs.
Definition: Project.cc:502
Interface for a Dictionary class, which can return a string value for a string token name...
Definition: Dictionary.h:38
Project & operator=(const Project &)
Assignment not supported.
void addSite(Site *val)
Definition: Project.cc:142
void removeAutoConfig(xercesc::DOMNode *node, bool bumpRecursion=false)
Scan the DOM and pull out any &lt;autoconfig&gt; tags, as well as change the autoconfig classes back to DSM...
Definition: Project.cc:717
SampleTagIterator getSampleTagIterator() const
Definition: Project.cc:210
void setConfigName(const std::string &val)
Definition: Project.h:97
ProcessorIterator getProcessorIterator() const
Definition: Project.cc:190
int _minSiteNumber
Definition: Project.h:388
static Project * _instance
Definition: Project.h:329
ServiceCatalog * _serviceCatalog
Definition: Project.h:368
SensorIterator getSensorIterator() const
Definition: Project.cc:205
std::list< Site * > _sites
Definition: Project.h:362
xercesc::DOMDocument * parseXMLConfigFile(const std::string &xmlFileName)
Utility function which creates a temporary XMLParser, sets the options we typically want and parses t...
Definition: XMLParser.cc:269
Site * findSite(int stationNumber) const
Find a Site with the given station number.
Definition: Project.cc:162
unsigned int dsm_sample_id_t
Definition: Sample.h:63
VariableIterator getVariableIterator() const
Definition: Project.cc:215
DSMSensor * findSensor(dsm_sample_id_t id) const
Definition: Project.cc:578
void addServer(DSMServer *srvr)
A Project has one or more DSMServers.
Definition: Project.h:118
A catalog of dsm DOMElements, implemented with std::map, containing dsm DOMElements, keyed by the ID attributes.
Definition: ServiceCatalog.h:41
std::map< int, Site * > _siteByStationNumber
Definition: Project.h:380
int _maxSiteNumber
Definition: Project.h:386
Exception which can be built from an xerces::XMLException, xercesc::SAXException, or xercesc::DOMExce...
Definition: XMLException.h:43
void disableAutoconfig(bool disable)
When true, autoconfig elements in the config document are removed before realizing the Project with f...
Definition: Project.h:303
Implementation of an IOChannel using an nidas::util::FileSet.
Definition: FileSet.h:42
A measurement site.
Definition: Site.h:49
dsm_sample_id_t getUniqueSampleId(unsigned int dsmid)
Get a temporary unique sample id for a given DSM id.
Definition: Project.cc:606
void fromDOMElement(const xercesc::DOMElement *)
Initialize myself from a xercesc::DOMElement.
Definition: Project.cc:847
void initSensors()
Initialize all sensors for a Project.
Definition: Project.cc:223
DSMServerIterator getDSMServerIterator() const
Definition: Project.cc:180
const std::string & getConfigVersion() const
Definition: Project.h:95
void setSystemName(const std::string &val)
Definition: Project.h:91
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
A Dataset is a named collection of parameters, that are used in data processing.
Definition: Datasets.h:47
const std::list< DSMServer * > & getServers() const
Definition: Project.h:120
Interface of an object that can be instantiated from a DOM element, via the fromDOMElement method...
Definition: DOMable.h:51
std::list< nidas::core::FileSet * > findServerSampleOutputStreamFileSets() const
Call findServerSampleOutputStreamFileSets(name) passing the nodename returned by uname(2).
Definition: Project.cc:566
ServiceCatalog * getServiceCatalog() const
Definition: Project.h:215
xercesc::DOMElement * toDOMElement(xercesc::DOMElement *node, bool complete) const
Add my content into a DOMElement.
Definition: Project.cc:1015
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:33
DSMCatalog * _dsmCatalog
Definition: Project.h:366
Project * _project
Definition: Project.h:359
void throw(nidas::core::XMLException)
Convenient method to fill this Project instance from the configuration in the XML file at xmlfilepath...
Definition: Project.cc:120
const std::string & getName() const
Definition: Project.h:89
SensorCatalog * getSensorCatalog() const
Definition: Project.h:209
void addParameter(Parameter *val)
Add a parameter to this Project.
Definition: Project.h:314
const Parameter * getParameter(const std::string &name) const
Definition: Project.cc:630
int getMinSiteNumber() const
Definition: Project.h:113
std::map< dsm_sample_id_t, DSMSensor * > _sensorById
Definition: Project.h:378
int getMaxSiteNumber() const
Convenience function to return the maximum site number.
Definition: Project.h:111
void setSensorCatalog(SensorCatalog *val)
Definition: Project.h:208
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:268
Class for iterating over the Processors of a DSMServer or DSMConfig.
Definition: NidsIterators.h:149
SiteIterator getSiteIterator() const
Definition: Project.cc:195
void setConfigVersion(const std::string &val)
Definition: Project.h:94
Class for iterating over the DSMServices of a DSMServer.
Definition: NidsIterators.h:91
nidas::util::Mutex _lookupLock
Definition: Project.h:372
DSMServer * findServer(const nidas::util::Inet4Address &addr) const
Definition: Project.cc:321
SensorCatalog * _sensorCatalog
Definition: Project.h:364
std::list< DSMServer * > _servers
Definition: Project.h:370
MyDictionary & operator=(const MyDictionary &rhs)
Definition: Project.h:349
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:265
void setServiceCatalog(ServiceCatalog *val)
Definition: Project.h:214
bool _disableAutoconfig
Definition: Project.h:400
const DSMConfig * findDSM(const nidas::util::Inet4Address &addr) const
Find a DSM whose name corresponds to a given IP address.
Definition: Project.cc:340
void setDSMCatalog(DSMCatalog *val)
Definition: Project.h:211
std::string _flightName
Definition: Project.h:343
DSMSensor provides the basic support for reading, processing and distributing samples from a sensor a...
Definition: DSMSensor.h:87
Definition: Parameter.h:46
void setDataset(const Dataset &val)
Definition: Project.h:288
xercesc::DOMElement * toDOMParent(xercesc::DOMElement *parent, bool complete) const
Create a DOMElement and append it to the parent.
Definition: Project.cc:1004
Class for iterating over the Sites of a Project, or the Sites served by a DSMServer.
Definition: NidsIterators.h:45
std::string _name
Definition: Project.h:332
void setName(const std::string &val)
Definition: Project.h:88
static void destroyInstance()
Destory the singleton.
Definition: Project.cc:69
std::map< dsm_sample_id_t, const DSMConfig * > _dsmById
Definition: Project.h:374
std::map< std::string, Site * > _siteByName
Definition: Project.h:382
Class for iterating over the SampleTags of a Project, Site, DSMConfig, or a SampleSource.
Definition: NidsIterators.h:217
MyDictionary(Project *project)
Definition: Project.h:347
std::set< dsm_sample_id_t > _usedIds
Definition: Project.h:384
Class describing a group of variables that are sampled and handled together.
Definition: SampleTag.h:87
Dataset _dataset
The current dataset.
Definition: Project.h:398
std::string _sysname
Definition: Project.h:334
Class for iterating over the DSMSensors of a Project, Site, or DSMConfig.
Definition: NidsIterators.h:185
DSMCatalog * getDSMCatalog() const
Definition: Project.h:212
A catalog of DSM DOMElements, implemented with std::map, containing dsm DOMElements, keyed by the ID attributes.
Definition: DSMCatalog.h:41
DSMServiceIterator getDSMServiceIterator() const
Definition: Project.cc:185
std::string _configVersion
Definition: Project.h:336
const Dataset & getDataset() const
Definition: Project.h:293
Definition: Project.h:60
void setFlightName(const std::string &val)
Definition: Project.h:100
virtual ~Project()
Definition: Project.cc:90
nidas::core::Project::MyDictionary _dictionary
const std::string & getSystemName() const
Definition: Project.h:92
A provider of services to a DSM.
Definition: DSMServer.h:50
Class for iterating over the DSMConfigs of a Project or Site.
Definition: NidsIterators.h:124
Definition: Project.h:345
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:278
Project()
Definition: Project.cc:76
A C++ wrapper for a POSIX mutex.
Definition: ThreadSupport.h:154
const Dictionary & getDictionary() const
Definition: Project.h:283
DSMConfig * findDSMFromHostname(const std::string &hostname)
Find a DSMConfig in any site in this project whose name matches the given hostname.
Definition: Project.cc:463
Support for IP version 4 host address.
Definition: Inet4Address.h:46
std::string _configName
Name of XML file that this project was initialized from.
Definition: Project.h:341
std::list< Parameter * > _parameters
List of pointers to Parameters.
Definition: Project.h:393
nidas::util::Mutex _sensorMapLock
Definition: Project.h:376
const std::list< Site * > & getSites() const
Definition: Project.h:106
MyDictionary(const MyDictionary &x)
Definition: Project.h:348
bool getTokenValue(const std::string &token, std::string &value) const
Definition: Project.cc:1030
const std::string & getConfigName() const
Definition: Project.h:98
A catalog of sensor DOMElements, implemented with std::map, containing sensor DOMElements, keyed by the ID attributes.
Definition: SensorCatalog.h:41
const std::string & getFlightName() const
Definition: Project.cc:131
static Project * getInstance()
Project is a singleton.
Definition: Project.cc:62