My Project
 All Classes Files Functions Variables Enumerations Enumerator Friends Macros Pages
NedReader.h
Go to the documentation of this file.
1 // $Id: NedReader.h,v 1.1.1.1 2009/07/06 23:57:25 eml Exp $
2 
3 #ifndef GCP_UTIL_NEDREADER_H
4 #define GCP_UTIL_NEDREADER_H
5 
15 #include "gcp/util/common/DecAngle.h"
16 #include "gcp/util/common/Declination.h"
17 #include "gcp/util/common/HourAngle.h"
18 #include "gcp/util/common/PtSrcReader.h"
19 
20 #include <string>
21 #include <vector>
22 #include <list>
23 #include <sstream>
24 
25 namespace gcp {
26  namespace util {
27 
28  class NedReader : public PtSrcReader {
29  public:
30 
31  enum {
32  ANY,
33  ALL,
34  NOT,
35  NON
36  };
37 
38  enum {
39  CLASSIFIED_EXTRAGALACTIC = 0x1,
40  UNCLASSIFIED_EXTRAGALACTIC = 0x2,
41  GALAXY_COMPONENT = 0x4,
42  TYPE_ALL = CLASSIFIED_EXTRAGALACTIC | UNCLASSIFIED_EXTRAGALACTIC | GALAXY_COMPONENT
43  };
44 
45  enum {
46 
47  OBJ_NONE = 0x0,
48  OBJ_ALL = 0xFFFFFFFF,
49 
50  // Classified Extragalactic Objects
51 
52  GALAXY = 0x1,
53  GALAXY_PAIR = 0x2,
54  GALAXY_TRIPLET = 0x4,
55  GALAXY_GROUP = 0x8,
56  GALAXY_CLUSTER = 0x10,
57  QSO = 0x20,
58  QSO_GROUP = 0x40,
59  GRAV_LENS = 0x80,
60  DAMPED_LYMAN_ALPHA = 0x100,
61  ABSORB_LINE_SYSTEM = 0x200,
62  EMISSION_LINE_SRC = 0x400,
63 
64  // Unclassified extragalactic candidates
65 
66  RADIO_SRC = 0x800,
67  SUBMM_SRC = 0x1000,
68  IR_SRC = 0x2000,
69  VISUAL_SRC = 0x4000,
70  UV_EXCESS_SRC = 0x8000,
71  XRAY_SRC = 0x10000,
72  GAMMARAY_SRC = 0x20000,
73 
74  // Components of Galaxies
75 
76  SUPERNOVA = 0x40000,
77  HII_REGION = 0x80000,
78  PLANETARY_NEBULA = 0x100000,
79  SUPERNOVA_REMNANT = 0x200000,
80  };
81 
82  struct Obj {
83  unsigned type_;
84  unsigned short id_;
85  std::string inputName_;
86  std::string outputName_;
87  std::string expl_;
88 
89  Obj(unsigned type, unsigned short id, std::string inputName, std::string outputName, std::string expl) {
90  type_ = type;
91  id_ = id;
92  inputName_ = inputName;
93  outputName_ = outputName;
94  expl_ = expl;
95  };
96 
97  };
98 
99  enum {
100  CAT_ONE = 0x1,
101  CAT_TWO = 0x2,
102  CAT_THREE = 0x4,
103  CAT_FOUR = 0x8,
104  };
105 
106  enum {
107  CAT_NONE = 0x0,
108  CAT_ALL = 0xFFFFFFFF,
109 
110  CAT_ABELL = 0x1,
111 
112  CAT_NGC = 0x2,
113 
114  CAT_3C = 0x4,
115  CAT_4C = 0x8,
116  CAT_5C = 0x10,
117  CAT_6C = 0x20,
118  CAT_7C = 0x40,
119  CAT_8C = 0x80,
120  CAT_9C = 0x100,
121 
122  CAT_87GB = 0x200,
123  CAT_XMM = 0x400,
124  CAT_WARP = 0x800,
125  CAT_WMAP = 0x1000,
126 
127  CAT_MG = 0x2000,
128  CAT_MG1 = 0x4000,
129  CAT_MG2 = 0x8000,
130  CAT_MG4 = 0x10000,
131  CAT_MG3 = 0x20000,
132 
133  CAT_MESSIER = 0x40000,
134  CAT_MACS = 0x80000, // Massive cluster survey (from the literatur)e
135 
136  CAT_SCUBA =0x100000, // Massive cluster survey (from the literature)
137  };
138 
139  // Operators for including/excluding catalogs
140 
141  struct Catalog {
142  unsigned type_;
143  unsigned short id_;
144  std::string inputName_;
145  std::string outputName_;
146  std::string expl_;
147 
148  Catalog(unsigned type, unsigned short id, std::string inputName, std::string outputName, std::string expl) {
149  type_ = type;
150  id_ = id;
151  inputName_ = inputName;
152  outputName_ = outputName;
153  expl_ = expl;
154  };
155 
156  };
157 
158  enum {
159  ERROR_ARGS = 1,
160  ERROR_CURL_INIT = 2
161  };
162 
163  enum {
164  OPTION_FALSE = 0,
165  OPTION_TRUE = 1
166  };
167 
168  enum {
169  FLAG_DEFAULT = 0
170  };
171 
172  //------------------------------------------------------------
173  // Methods for parsing the response from the NED database server
174  //------------------------------------------------------------
175 
177 
178  // Return true when we are at the end of the response
179 
180  bool atEndOfResponse();
181 
182  // Parse the next source entry
183 
184  PtSrcReader::Source readNextSourceFromResponse();
185 
186  //------------------------------------------------------------
187  // Define stubs
188  //------------------------------------------------------------
189 
190  void openCatalogFile();
191  void closeCatalogFile();
192 
193  // Catalog-specific function to read the next entry from a file
194 
195  PtSrcReader::Source readNextEntry();
196 
197  // Return true if we are at the end of the catalog file
198 
199  bool eof();
200 
201  // Apply any corrections to convert the catalog values
202 
203  void applyCorrections(PtSrcReader::Source& src);
204 
205  // Calculate the minimal RA range we need to search
206 
207  void setRaRange(HourAngle& ra, Declination& dec, Angle& radius);
208 
209  //------------------------------------------------------------
210  // Specific members
211  //------------------------------------------------------------
212 
213  std::string::size_type start_;
214  std::string::size_type stop_;
215 
216  static std::vector<Obj> objects_;
217  static std::vector<Catalog> catalogs_;
218 
219  // A stream containing the last read information returned from
220  // the URL fetch
221 
222  std::ostringstream lastRead_;
223 
224  std::list<PtSrcReader::Source> srcs_;
225  std::list<PtSrcReader::Source>::iterator srcIter_;
226 
230  NedReader();
231 
235  virtual ~NedReader();
236 
237  void getUrl(std::string url);
238 
239  unsigned short objIdToNedId(unsigned short id);
240  unsigned short catIdToNedId(unsigned short id);
241 
242  void
243  constructNearPositionSearchUrl(std::ostringstream& os,
244  HourAngle ra, Declination dec,
245  Angle radius,
246  unsigned objIncMask, unsigned objExcMask,
247  unsigned catMask, unsigned objSel, unsigned catSel);
248 
249  // Add an object to a mask
250 
251  void maskObject(std::string name, unsigned& mask);
252 
253  void includeObjects(std::ostringstream& os, unsigned mask);
254  void excludeObjects(std::ostringstream& os, unsigned mask);
255 
256  void addToObjectIncludeMask(unsigned mask);
257  void addToObjectExcludeMask(unsigned mask);
258 
259  void setObjectIncludeMask(unsigned mask);
260  void setObjectExcludeMask(unsigned mask);
261 
262  void clearObjectIncludeMask();
263  void clearObjectExcludeMask();
264 
265  void matchAny(std::ostringstream& os);
266  void matchAll(std::ostringstream& os);
267 
268  // Add an catalog to a mask
269 
270  void maskCatalog(std::string name, unsigned& mask);
271 
272  void selectCatalogs(std::ostringstream& os, unsigned mask);
273 
274  void addToCatalogMask(unsigned mask);
275  void setCatalogMask(unsigned mask);
276  void clearCatalogMask();
277 
278  void setObjectSelection(unsigned type);
279  void setCatalogSelection(unsigned type);
280 
281  // Initializer for static array
282 
283  static std::vector<Obj> initObjects();
284  static std::vector<Catalog> initCatalogs();
285 
286  // A function that will be called to handle data from a call to
287  // perform
288 
289  static size_t handle_data(void* buffer, size_t size, size_t nmemb, void* userp);
290 
291  PtSrcReader::Source parseSource(std::string line);
292 
293  void removeDuplicates();
294 
295  void listSources();
296 
297  std::vector<std::string> listObjects(unsigned short id);
298  std::vector<std::string> listCatalogs();
299 
300  unsigned objIncMask_;
301  unsigned objExcMask_;
302  unsigned catMask_;
303 
304  unsigned objSel_;
305  unsigned catSel_;
306 
307  }; // End class NedReader
308 
309  } // End namespace util
310 } // End namespace gcp
311 
312 
313 
314 #endif // End #ifndef GCP_UTIL_NEDREADER_H
bool eof()
Definition: NedReader.cc:159
Definition: NedReader.h:28
void constructNearPositionSearchUrl(std::ostringstream &os, HourAngle ra, Declination dec, Angle radius, unsigned objIncMask, unsigned objExcMask, unsigned catMask, unsigned objSel, unsigned catSel)
Definition: NedReader.cc:261
static std::vector< Catalog > initCatalogs()
Definition: NedReader.cc:444
void initializeResponseParse()
Definition: NedReader.cc:177
PtSrcReader::Source readNextEntry()
Definition: NedReader.cc:167
virtual ~NedReader()
Definition: NedReader.cc:42
void setRaRange(HourAngle &ra, Declination &dec, Angle &radius)
Definition: NedReader.cc:544
void maskObject(std::string name, unsigned &mask)
Definition: NedReader.cc:395
static std::vector< Obj > initObjects()
Definition: NedReader.cc:483
Definition: NedReader.h:82
void includeObjects(std::ostringstream &os, unsigned mask)
Definition: NedReader.cc:363
PtSrcReader::Source parseSource(std::string line)
Definition: NedReader.cc:217
void getUrl(std::string url)
Definition: NedReader.cc:47
void selectCatalogs(std::ostringstream &os, unsigned mask)
Definition: NedReader.cc:409
PtSrcReader::Source readNextSourceFromResponse()
Definition: NedReader.cc:197
Definition: tVideoCapabilitiesEml.cc:67
void maskCatalog(std::string name, unsigned &mask)
Definition: NedReader.cc:431
Definition: NedReader.h:141
Definition: PtSrcReader.h:29
void excludeObjects(std::ostringstream &os, unsigned mask)
Definition: NedReader.cc:379
NedReader()
Definition: NedReader.cc:26
void openCatalogFile()
Definition: NedReader.cc:146