OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
FitsRequestHandler.cc
Go to the documentation of this file.
1 // FitsRequestHandler.cc
2 
3 // This file is part of fits_handler, a data handler for the OPeNDAP data
4 // server.
5 
6 // Copyright (c) 2004,2005 University Corporation for Atmospheric Research
7 // Author: Patrick West <pwest@ucar.edu> and Jose Garcia <jgarcia@ucar.edu>
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library 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 GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 //
23 // You can contact University Corporation for Atmospheric Research at
24 // 3080 Center Green Drive, Boulder, CO 80301
25 
26 // (c) COPYRIGHT University Corporation for Atmostpheric Research 2004-2005
27 // Please read the full copyright statement in the file COPYRIGHT_UCAR.
28 //
29 // Authors:
30 // pwest Patrick West <pwest@ucar.edu>
31 // jgarcia Jose Garcia <jgarcia@ucar.edu>
32 
33 #include "config.h"
34 
35 #include <DAS.h>
36 #include <DDS.h>
37 #include <DMR.h>
38 #include <D4BaseTypeFactory.h>
39 #include <Ancillary.h>
40 #include <InternalErr.h>
41 #include <mime_util.h>
42 
43 #include <BESResponseHandler.h>
44 #include <BESDapError.h>
45 
46 #include <BESDapNames.h>
47 #include <BESResponseNames.h>
48 #include <BESDASResponse.h>
49 #include <BESDDSResponse.h>
50 #include <BESDataDDSResponse.h>
51 #include <BESDMRResponse.h>
52 
53 #include <BESVersionInfo.h>
54 #include <BESConstraintFuncs.h>
55 #include <BESServiceRegistry.h>
56 #include <BESUtil.h>
57 
58 #include <fitsio.h>
59 
60 #include "FitsRequestHandler.h"
61 #include "fits_read_attributes.h"
62 #include "fits_read_descriptors.h"
63 
64 #define FITS_NAME "fits"
65 
67  BESRequestHandler(name)
68 {
72 
75 
78 }
79 
81 {
82 }
83 
85 {
87  BESDASResponse *bdas = dynamic_cast<BESDASResponse *>(response);
88  if (!bdas) throw BESInternalError("cast error", __FILE__, __LINE__);
89 
90  try {
92  DAS *das = bdas->get_das();
93  string accessed = dhi.container->access();
94  string fits_error;
95  if (!fits_handler::fits_read_attributes(*das, accessed, fits_error)) {
96  throw BESDapError(fits_error, false, unknown_error, __FILE__, __LINE__);
97  }
98  Ancillary::read_ancillary_das(*das, accessed);
99  bdas->clear_container();
100  }
101  catch( InternalErr &e ) {
102  throw BESDapError(e.get_error_message(), true, e.get_error_code(), __FILE__, __LINE__);
103  }
104  catch( Error &e ) {
105  throw BESDapError(e.get_error_message(), false, e.get_error_code(), __FILE__, __LINE__);
106  }
107  catch( ... ) {
108  throw BESDapError("Unknown exception caught building FITS das response", true, unknown_error, __FILE__, __LINE__);
109  }
110  return true;
111 }
112 
114 {
116  BESDDSResponse *bdds = dynamic_cast<BESDDSResponse *>(response);
117  if (!bdds) throw BESInternalError("cast error", __FILE__, __LINE__);
118 
119  try {
121  DDS *dds = bdds->get_dds();
122  string accessed = dhi.container->access();
123  string fits_error;
124 
125  if (!fits_handler::fits_read_descriptors(*dds, accessed, fits_error)) {
126  throw BESDapError(fits_error, false, unknown_error, __FILE__, __LINE__);
127  }
128 
129  Ancillary::read_ancillary_dds(*dds, accessed);
130  DAS *das = new DAS;
131  BESDASResponse bdas(das);
133  if (!fits_handler::fits_read_attributes(*das, accessed, fits_error)) {
134  throw BESDapError(fits_error, false, unknown_error, __FILE__, __LINE__);
135  }
136  Ancillary::read_ancillary_das(*das, accessed);
137 
138  dds->transfer_attributes(das);
139 
140  bdds->set_constraint(dhi);
141 
142  bdds->clear_container();
143  }
144  catch( InternalErr &e ) {
145  throw BESDapError(e.get_error_message(), true, e.get_error_code(), __FILE__, __LINE__);
146  }
147  catch( Error &e ) {
148  throw BESDapError(e.get_error_message(), false, e.get_error_code(), __FILE__, __LINE__);
149  }
150  catch( ... ) {
151  string err = "Unknown exception caught building FITS dds response";
152  throw BESDapError(err, true, unknown_error, __FILE__, __LINE__);
153  }
154 
155  return true;
156 }
157 
159 {
161  BESDataDDSResponse *bdds = dynamic_cast<BESDataDDSResponse *>(response);
162  if (!bdds) throw BESInternalError("cast error", __FILE__, __LINE__);
163 
164  try {
166  DataDDS *dds = bdds->get_dds();
167  string accessed = dhi.container->access();
168  string fits_error;
169  if (!fits_handler::fits_read_descriptors(*dds, accessed, fits_error)) {
170  throw BESDapError(fits_error, false, unknown_error, __FILE__, __LINE__);
171  }
172  Ancillary::read_ancillary_dds(*dds, accessed);
173 
174  DAS *das = new DAS;
175  BESDASResponse bdas(das);
177  if (!fits_handler::fits_read_attributes(*das, accessed, fits_error)) {
178  throw BESDapError(fits_error, false, unknown_error, __FILE__, __LINE__);
179  }
180  Ancillary::read_ancillary_das(*das, accessed);
181 
182  dds->transfer_attributes(das);
183 
184  bdds->set_constraint(dhi);
185 
186  bdds->clear_container();
187  }
188  catch( InternalErr &e ) {
189  throw BESDapError(e.get_error_message(), true, e.get_error_code(), __FILE__, __LINE__);
190  }
191  catch( Error &e ) {
192  throw BESDapError(e.get_error_message(), false, e.get_error_code(), __FILE__, __LINE__);
193  }
194  catch( ... ) {
195  string err = "Unknown exception caught building FITS data response";
196  throw BESDapError(err, true, unknown_error, __FILE__, __LINE__);
197  }
198 
199  return true;
200 }
201 
215 {
216  string data_path = dhi.container->access();
217 
218  BaseTypeFactory factory;
219  DDS dds(&factory, name_path(data_path), "3.2");
220  dds.filename(data_path);
221 
222  try {
223  string fits_error;
224 
225  if (!fits_handler::fits_read_descriptors(dds, data_path, fits_error))
226  throw BESDapError(fits_error, false, unknown_error, __FILE__, __LINE__);
227 
228  DAS das;
229  if (!fits_handler::fits_read_attributes(das, data_path, fits_error))
230  throw BESDapError(fits_error, false, unknown_error, __FILE__, __LINE__);
231  Ancillary::read_ancillary_das(das, data_path);
232 
233  dds.transfer_attributes(&das);
234  }
235  catch( InternalErr &e ) {
236  throw BESDapError(e.get_error_message(), true, e.get_error_code(), __FILE__, __LINE__);
237  }
238  catch( Error &e ) {
239  throw BESDapError(e.get_error_message(), false, e.get_error_code(), __FILE__, __LINE__);
240  }
241  catch( ... ) {
242  throw BESDapError("Unknown exception caught building FITS DMR response", true, unknown_error, __FILE__, __LINE__);
243  }
244 
245 
246  // Extract the DMR Response object - this holds the DMR used by the
247  // other parts of the framework.
249  BESDMRResponse &bdmr = dynamic_cast<BESDMRResponse &>(*response);
250 
251  // Extract the DMR Response object - this holds the DMR used by the
252  // other parts of the framework.
253  DMR *dmr = bdmr.get_dmr();
254  dmr->set_factory(new D4BaseTypeFactory);
255  dmr->build_using_dds(dds);
256 
257  bdmr.set_dap4_constraint(dhi);
258  bdmr.set_dap4_function(dhi);
259 
260  return true;
261 }
262 
264 {
266  BESVersionInfo *info = dynamic_cast<BESVersionInfo *>(response);
267  if (!info) throw BESInternalError("cast error", __FILE__, __LINE__);
268 
269 #if 0
271 #endif
272  info->add_module(MODULE_NAME, MODULE_VERSION);
273 
274  return true;
275 }
276 
278 {
280  BESInfo *info = dynamic_cast<BESInfo *>(response);
281  if (!info) throw BESInternalError("cast error", __FILE__, __LINE__);
282 
283  map<string, string> attrs;
284  attrs["name"] = MODULE_NAME ;
285  attrs["version"] = MODULE_VERSION ;
286 #if 0
287  attrs["name"] = PACKAGE_NAME;
288  attrs["version"] = PACKAGE_VERSION;
289 #endif
290  list<string> services;
292  if (services.size() > 0) {
293  string handles = BESUtil::implode(services, ',');
294  attrs["handles"] = handles;
295  }
296  info->begin_tag("module", &attrs);
297  info->end_tag("module");
298 
299  return true;
300 }
301 
309 void FitsRequestHandler::dump(ostream &strm) const
310 {
311  strm << BESIndent::LMarg << "FitsRequestHandler::dump - (" << (void *) this << ")" << endl;
315 }
316 
brief represents simple text information in a response object, such as version and help inforamtion...
#define DAP4DATA_RESPONSE
Definition: BESDapNames.h:86
static bool fits_build_das(BESDataHandlerInterface &dhi)
exception thrown if inernal error encountered
static bool fits_build_help(BESDataHandlerInterface &dhi)
#define DMR_RESPONSE
Definition: BESDapNames.h:81
string get_symbolic_name() const
retrieve the symbolic name for this container
Definition: BESContainer.h:197
Represents an OPeNDAP DDS DAP2 data object within the BES.
virtual void clear_container()
clear the container in the DAP response object
static bool fits_build_vers(BESDataHandlerInterface &dhi)
virtual void set_dap4_constraint(BESDataHandlerInterface &dhi)
set the constraint depending on the context
static void Indent()
Definition: BESIndent.cc:38
virtual string access()=0
returns the true name of this container
virtual void clear_container()
clear the container in the DAP response object
#define HELP_RESPONSE
virtual void set_dap4_function(BESDataHandlerInterface &dhi)
set the constraint depending on the context
informational response object
Definition: BESInfo.h:68
static string implode(const list< string > &values, char delim)
implode a list of values into a single string delimited by delim
Definition: BESUtil.cc:602
#define FITS_NAME
virtual BESResponseObject * get_response_object()
return the current response object
#define PACKAGE_NAME
Definition: config.h:244
#define DATA_RESPONSE
Definition: BESDapNames.h:70
static BESServiceRegistry * TheRegistry()
virtual ~FitsRequestHandler(void)
BESResponseHandler * response_handler
virtual void set_constraint(BESDataHandlerInterface &dhi)
set the constraint depending on the context
virtual void begin_tag(const string &tag_name, map< string, string > *attrs=0)
Definition: BESInfo.cc:127
static ostream & LMarg(ostream &strm)
Definition: BESIndent.cc:73
Represents an OPeNDAP DMR DAP4 data object within the BES.
virtual void set_container(const string &cn)
set the container in the DAP response object
error object created from libdap error objects and can handle those errors
Definition: BESDapError.h:51
Represents an OPeNDAP DataDDS DAP2 data object within the BES.
virtual void dump(ostream &strm) const
dumps information about this object
static bool fits_build_data(BESDataHandlerInterface &dhi)
virtual void clear_container()
clear the container in the DAP response object
Represents a specific data type request handler.
Structure storing information used by the BES to handle the request.
FitsRequestHandler(const string &name)
#define VERS_RESPONSE
virtual void set_container(const string &cn)
set the container in the DAP response object
virtual bool add_handler(const string &handler_name, p_request_handler handler_method)
add a handler method to the request handler that knows how to fill in a specific response object ...
#define PACKAGE_VERSION
Definition: config.h:256
Represents an OPeNDAP DAS DAP2 data object within the BES.
static void UnIndent()
Definition: BESIndent.cc:44
static bool fits_build_dds(BESDataHandlerInterface &dhi)
virtual void set_container(const string &cn)
set the container in the DAP response object
virtual void dump(ostream &strm) const
dumps information about this object
virtual void add_module(const string &n, const string &v)
Abstract base class representing a specific set of information in response to a request to the BES...
#define DDS_RESPONSE
Definition: BESDapNames.h:60
BESContainer * container
pointer to current container in this interface
#define DAS_RESPONSE
Definition: BESDapNames.h:55
bool fits_read_attributes(libdap::DAS &das, const std::string &filename, std::string &error)
virtual void end_tag(const string &tag_name)
Definition: BESInfo.cc:132
bool fits_read_descriptors(libdap::DDS &dds, const std::string &filename, std::string &error)
virtual void services_handled(const string &handler, list< string > &services)
returns the list of servies provided by the handler in question
static bool fits_build_dmr(BESDataHandlerInterface &dhi)
Build a DMR object.