36#include <libdap/Array.h>
37#include <libdap/util.h>
38#include <libdap/D4Attributes.h>
39#include <libdap/D4ParserSax2.h>
41#include <TheBESKeys.h>
47#include "DmrppTypeFactory.h"
48#include "DmrppD4Group.h"
49#include "DmrppMetadataStore.h"
51#include "build_dmrpp_util.h"
56using namespace build_dmrpp_util;
58#define DEBUG_KEY "metadata_store,dmrpp_store,dmrpp"
59#define ROOT_DIRECTORY "BES.Catalog.catalog.RootDirectory"
67static string cmdln(
int argc,
char *argv[])
70 for(
int i=0; i<argc; i++) {
85void inject_version_and_configuration(
int argc,
char **argv,
DMRpp *dmrpp)
87 dmrpp->set_version(CVER);
90 auto version =
new D4Attribute(
"build_dmrpp_metadata", StringToD4AttributeType(
"container"));
92 auto build_dmrpp_version =
new D4Attribute(
"build_dmrpp", StringToD4AttributeType(
"string"));
93 build_dmrpp_version->add_value(CVER);
94 version->attributes()->add_attribute_nocopy(build_dmrpp_version);
96 auto bes_version =
new D4Attribute(
"bes", StringToD4AttributeType(
"string"));
97 bes_version->add_value(CVER);
98 version->attributes()->add_attribute_nocopy(bes_version);
101 ldv << libdap_name() <<
"-" << libdap_version();
102 auto libdap4_version =
new D4Attribute(
"libdap", StringToD4AttributeType(
"string"));
103 libdap4_version->add_value(ldv.str());
104 version->attributes()->add_attribute_nocopy(libdap4_version);
108 auto config =
new D4Attribute(
"configuration", StringToD4AttributeType(
"string"));
110 version->attributes()->add_attribute_nocopy(config);
114 auto invoke =
new D4Attribute(
"invocation", StringToD4AttributeType(
"string"));
115 invoke->add_value(cmdln(argc, argv));
116 version->attributes()->add_attribute_nocopy(invoke);
119 dmrpp->root()->attributes()->add_attribute_nocopy(version);
123 const char *help = R
"(
124 build_dmrpp -h: Show this help
126 build_dmrpp -V: Show build versions for components that make up the program
128 build_dmrpp -c <bes.conf> -f <data file> [-u <href url>]: Build the DMR++ using the <bes.conf>
129 options to initialize the software for the <data file>. Optionally substitute the <href url>.
130 Builds the DMR using the HDF5 handler as configured using the options in the <bes.conf>.
132 build_dmrpp build_dmrpp -f <data file> -r <dmr file> [-u <href url>]: As above, but uses the DMR
133 read from the given file (so it does not run the HDF5 handler code and does not require the
134 Metadata Store - MDS - be configured). Note that the get_dmrpp command appears to use this
135 option and thus, the configuration options listed in the built DMR++ files lack the MDS setup.
139 -d: Turn on BES software debugging output
140 -M: Add information about the build_dmrpp software, incl versions, to the built DMR++)";
142 cerr << help << endl;
145int main(
int argc,
char *argv[]) {
150 bool add_production_metadata =
false;
153 while ((option_char = getopt(argc, argv,
"c:f:r:u:dhvVM")) != -1) {
154 switch (option_char) {
156 cerr << basename(argv[0]) <<
"-" << CVER <<
" (bes-"<< CVER <<
", " << libdap_name() <<
"-"
157 << libdap_version() <<
")" << endl;
161 build_dmrpp_util::verbose =
true;
169 h5_file_name = optarg;
185 add_production_metadata =
true;
197 if (h5_file_name.empty()) {
198 cerr <<
"HDF5 file name must be given (-f <input>)." << endl;
208 if (!dmr_name.empty()) {
212 dmrpp.set_factory(&dtf);
214 ifstream in(dmr_name.c_str());
216 parser.intern(in, &dmrpp,
false);
218 add_chunk_information(h5_file_name, &dmrpp);
220 if (add_production_metadata) {
221 inject_version_and_configuration(argc, argv, &dmrpp);
227 cout << writer.get_doc();
230 if (bes_data_root.empty()) {
231 cerr <<
"Could not find the data directory." << endl;
238 cerr <<
"The Metadata Store (MDS) must be configured for this command to work (but see the -r option)." << endl;
253 cerr <<
"Expected a DMR++ object from the DmrppMetadataStore." << endl;
257 add_chunk_information(h5_file_path, dmrpp.get());
259 dmrpp->set_href(url_name);
261 mds->add_dmrpp_response(dmrpp.get(), h5_file_name );
264 dmrpp->set_print_chunks(
true);
267 cout << writer.get_doc();
269 cerr <<
"Error: Could not get a lock on the DMR for '" + h5_file_path +
"'." << endl;
278 catch (
const std::exception &e) {
279 cerr <<
"std::exception: " << e.what() << endl;
283 cerr <<
"Unknown error." << endl;
static void SetUp(const std::string &values)
Sets up debugging for the bes.
Base exception class for the BES with basic string message.
std::string get_message() const
get the error message for this exception
static std::string assemblePath(const std::string &firstPart, const std::string &secondPart, bool leadingSlash=false, bool trailingSlash=false)
Assemble path fragments making sure that they are separated by a single '/' character.
static TheBESKeys * TheKeys()
static std::string ConfigFile
std::string read_string_key(const std::string &key, const std::string &default_value)
Read a string-valued key from the bes.conf file.
Provide a way to print the DMR++ response.
virtual void print_dmrpp(libdap::XMLWriter &xml, const std::string &href="", bool constrained=false, bool print_chunks=true)
Print the DMR++ response.
void print_dap4(libdap::XMLWriter &xml, bool constrained=false)
override DMR::print_dap4() so the chunk info will print too.