35#include <libdap/DAS.h>
36#include <libdap/DDS.h>
37#include <libdap/DataDDS.h>
38#include <libdap/DMR.h>
39#include <libdap/D4BaseTypeFactory.h>
40#include <libdap/Ancillary.h>
41#include <libdap/InternalErr.h>
42#include <libdap/mime_util.h>
44#include <BESResponseHandler.h>
45#include <BESDapError.h>
47#include <BESDapNames.h>
48#include <BESResponseNames.h>
49#include <BESDASResponse.h>
50#include <BESDDSResponse.h>
51#include <BESDataDDSResponse.h>
52#include <BESDMRResponse.h>
54#include <BESVersionInfo.h>
55#include <BESConstraintFuncs.h>
56#include <BESServiceRegistry.h>
62#include "FitsRequestHandler.h"
63#include "fits_read_attributes.h"
64#include "fits_read_descriptors.h"
68#define FITS_NAME "fits"
70FitsRequestHandler::FitsRequestHandler(
const string &name) :
73 add_method(DAS_RESPONSE, FitsRequestHandler::fits_build_das);
74 add_method(DDS_RESPONSE, FitsRequestHandler::fits_build_dds);
75 add_method(DATA_RESPONSE, FitsRequestHandler::fits_build_data);
80 add_method(VERS_RESPONSE, FitsRequestHandler::fits_build_vers);
81 add_method(HELP_RESPONSE, FitsRequestHandler::fits_build_help);
84FitsRequestHandler::~FitsRequestHandler()
91 BESDASResponse *bdas =
dynamic_cast<BESDASResponse *
>(response);
92 if (!bdas)
throw BESInternalError(
"cast error", __FILE__, __LINE__);
96 DAS *das = bdas->get_das();
99 if (!fits_handler::fits_read_attributes(*das, accessed, fits_error)) {
100 throw BESDapError(fits_error,
false, unknown_error, __FILE__, __LINE__);
102 Ancillary::read_ancillary_das(*das, accessed);
105 catch( InternalErr &e ) {
106 throw BESDapError(e.get_error_message(),
true, e.get_error_code(), __FILE__, __LINE__);
109 throw BESDapError(e.get_error_message(),
false, e.get_error_code(), __FILE__, __LINE__);
111 catch (BESError &e) {
115 throw BESDapError(
"Unknown exception caught building FITS das response",
true, unknown_error, __FILE__, __LINE__);
123 BESDDSResponse *bdds =
dynamic_cast<BESDDSResponse *
>(response);
124 if (!bdds)
throw BESInternalError(
"cast error", __FILE__, __LINE__);
132 if (!fits_handler::fits_read_descriptors(*dds, accessed, fits_error)) {
133 throw BESDapError(fits_error,
false, unknown_error, __FILE__, __LINE__);
136 Ancillary::read_ancillary_dds(*dds, accessed);
138 BESDASResponse bdas(das);
140 if (!fits_handler::fits_read_attributes(*das, accessed, fits_error)) {
141 throw BESDapError(fits_error,
false, unknown_error, __FILE__, __LINE__);
143 Ancillary::read_ancillary_das(*das, accessed);
145 dds->transfer_attributes(das);
151 catch( InternalErr &e ) {
152 throw BESDapError(e.get_error_message(),
true, e.get_error_code(), __FILE__, __LINE__);
155 throw BESDapError(e.get_error_message(),
false, e.get_error_code(), __FILE__, __LINE__);
157 catch (BESError &e) {
161 string err =
"Unknown exception caught building FITS dds response";
162 throw BESDapError(err,
true, unknown_error, __FILE__, __LINE__);
171 BESDataDDSResponse *bdds =
dynamic_cast<BESDataDDSResponse *
>(response);
172 if (!bdds)
throw BESInternalError(
"cast error", __FILE__, __LINE__);
176 DDS *dds = bdds->get_dds();
179 if (!fits_handler::fits_read_descriptors(*dds, accessed, fits_error)) {
180 throw BESDapError(fits_error,
false, unknown_error, __FILE__, __LINE__);
182 Ancillary::read_ancillary_dds(*dds, accessed);
186 BESDEBUG(FITS_NAME,
"Data ACCESS build_data(): set the including attribute flag to false: "<<accessed << endl);
187 bdds->set_ia_flag(
false);
190 catch( InternalErr &e ) {
191 throw BESDapError(e.get_error_message(),
true, e.get_error_code(), __FILE__, __LINE__);
194 throw BESDapError(e.get_error_message(),
false, e.get_error_code(), __FILE__, __LINE__);
196 catch (BESError &e) {
200 string err =
"Unknown exception caught building FITS data response";
201 throw BESDapError(err,
true, unknown_error, __FILE__, __LINE__);
223 BaseTypeFactory factory;
224 DDS dds(&factory, name_path(data_path),
"3.2");
225 dds.filename(data_path);
230 if (!fits_handler::fits_read_descriptors(dds, data_path, fits_error))
231 throw BESDapError(fits_error,
false, unknown_error, __FILE__, __LINE__);
234 if (!fits_handler::fits_read_attributes(das, data_path, fits_error))
235 throw BESDapError(fits_error,
false, unknown_error, __FILE__, __LINE__);
236 Ancillary::read_ancillary_das(das, data_path);
238 dds.transfer_attributes(&das);
240 catch( InternalErr &e ) {
241 throw BESDapError(e.get_error_message(),
true, e.get_error_code(), __FILE__, __LINE__);
244 throw BESDapError(e.get_error_message(),
false, e.get_error_code(), __FILE__, __LINE__);
250 throw BESDapError(
"Unknown exception caught building FITS DMR response",
true, unknown_error, __FILE__, __LINE__);
261 DMR *dmr = bdmr.get_dmr();
262 dmr->set_factory(
new D4BaseTypeFactory);
263 dmr->build_using_dds(dds);
277 info->add_module(MODULE_NAME, MODULE_VERSION);
285 BESInfo *info =
dynamic_cast<BESInfo *
>(response);
286 if (!info)
throw BESInternalError(
"cast error", __FILE__, __LINE__);
288 map<string, string, std::less<>> attrs;
289 attrs[
"name"] = MODULE_NAME ;
290 attrs[
"version"] = MODULE_VERSION ;
291 list<string> services;
293 if (!services.empty()) {
295 attrs[
"handles"] = handles;
297 info->begin_tag(
"module", &attrs);
298 info->end_tag(
"module");
312 strm << BESIndent::LMarg <<
"FitsRequestHandler::dump - (" << (
void *)
this <<
")" << endl;
315 BESIndent::UnIndent();
324 DDS *dds = bdds->get_dds();
330 if (!fits_handler::fits_read_attributes(*das, accessed, fits_error)) {
331 throw BESDapError(fits_error,
false, unknown_error, __FILE__, __LINE__);
333 Ancillary::read_ancillary_das(*das, accessed);
335 dds->transfer_attributes(das);
336 BESDEBUG(FITS_NAME,
"Data ACCESS in add_attributes(): set the including attribute flag to true: "<<accessed << endl);
337 bdds->set_ia_flag(
true);
std::string get_symbolic_name() const
retrieve the symbolic name for this container
virtual std::string access()=0
returns the true name of this container
Represents an OPeNDAP DAS DAP2 data object within the BES.
virtual void clear_container()
clear the container in the DAP response object
virtual void set_container(const std::string &cn)
set the container in the DAP response object
virtual void set_container(const std::string &cn)
set the container in the DAP response object
virtual void clear_container()
clear the container in the DAP response object
Represents an OPeNDAP DMR DAP4 data object within the BES.
error object created from libdap error objects and can handle those errors
virtual void set_dap4_function(BESDataHandlerInterface &dhi)
set the constraint depending on the context
virtual void set_dap4_constraint(BESDataHandlerInterface &dhi)
set the constraint depending on the context
virtual void set_constraint(BESDataHandlerInterface &dhi)
set the constraint depending on the context
Represents an OPeNDAP DataDDS DAP2 data object within the BES.
virtual void set_container(const std::string &cn)
set the container in the DAP response object
virtual void clear_container()
clear the container in the DAP response object
Structure storing information used by the BES to handle the request.
BESContainer * container
pointer to current container in this interface
Base exception class for the BES with basic string message.
exception thrown if internal error encountered
Represents a specific data type request handler.
virtual void dump(std::ostream &strm) const
dumps information about this object
virtual BESResponseObject * get_response_object()
return the current response object
Abstract base class representing a specific set of information in response to a request to the BES.
virtual void services_handled(const std::string &handler, std::list< std::string > &services)
returns the list of servies provided by the handler in question
static std::string implode(const std::list< std::string > &values, char delim)
virtual void dump(std::ostream &strm) const
dumps information about this object
static bool fits_build_dmr(BESDataHandlerInterface &dhi)