fixup_root.cpp
Go to the documentation of this file.
00001 #include <argp.h>
00002 #include <stdio.h>
00003 #include <string.h>
00004 
00005 #include <megatree/node_file.h>
00006 #include <megatree/storage.h>
00007 #include <megatree/storage_factory.h>
00008 
00009 using namespace megatree;
00010 
00011 struct arguments_t {
00012   char* tree;
00013 };
00014 
00015 
00016 static int parse_opt(int key, char *arg, struct argp_state *state)
00017 {
00018   struct arguments_t *arguments = (arguments_t*)state->input;
00019   
00020   switch (key)
00021   {
00022   case 't':
00023     arguments->tree = arg;
00024     break;
00025   case ARGP_KEY_ARG:
00026     break;
00027   }
00028   return 0;
00029 }
00030 
00031 
00032 int main (int argc, char** argv)
00033 {
00034   // Default command line arguments
00035   struct arguments_t arguments;
00036   arguments.tree = 0;
00037   
00038   // Parses command line options
00039   struct argp_option options[] = {
00040     {"tree",       't', "TREE",   0,     "Path to tree"},
00041     { 0 }
00042   };
00043   struct argp argp = { options, parse_opt };
00044   int parse_ok = argp_parse(&argp, argc, argv, 0, 0, &arguments);
00045   printf("Arguments parsed: %d\n", parse_ok);
00046   printf("Tree: %s\n", arguments.tree);
00047   assert(parse_ok == 0);
00048 
00049   if (!arguments.tree) {
00050     fprintf(stderr, "No tree path given.\n");
00051     return 1;
00052   }
00053 
00054   boost::shared_ptr<Storage> storage(openStorage(arguments.tree));
00055 
00056   // Retrieves file f1
00057   ByteVec f1_binary;
00058   storage->get("f1", f1_binary);
00059   if (f1_binary.empty())
00060   {
00061     fprintf(stderr, "The f1 file was not found for tree: %s\n", arguments.tree);
00062     exit(1);
00063   }
00064 
00065   NodeFile f1("f1");
00066   f1.deserialize(f1_binary);
00067   printf("Loaded f1 with %u nodes\n", f1.cacheSize());
00068 
00069   NodeFile f("f");
00070   f.initializeRootNodeFile(boost::filesystem::path("f"), f1);
00071   ByteVec f_binary;
00072   f.serialize(f_binary);
00073   storage->put("f", f_binary);
00074   f.setWritten();
00075 
00076   // Writes the metadata.  This is currently copied out of megatree,
00077   // which is less than ideal.  Also, these parameters are duplicated
00078   // throughout the process, which is also less than ideal.
00079   std::stringstream output;
00080   output << "version = " << 11 << std::endl;  // Must match how the mapreduces work.  Change this with great caution.
00081   output << "min_cell_size = " << 0.001 << std::endl;
00082   output << "subtree_width = " << 6 << std::endl;
00083   output << "subfolder_depth = " << 10000000 << std::endl;
00084   output << "tree_center_x = " << 0 << std::endl;
00085   output << "tree_center_y = " << 0 << std::endl;
00086   output << "tree_center_z = " << 0 << std::endl;
00087   output << "tree_size = " << (2 * (6378000.0 + 8850.0)) << std::endl;
00088 
00089   ByteVec metadata_bytes(output.str().size());
00090   memcpy(&metadata_bytes[0], &output.str()[0], output.str().size());
00091   storage->put("metadata.ini", metadata_bytes);
00092   
00093   /*
00094   FILE* file = fopen("f_binary", "wb");
00095   assert(file);
00096   fwrite(&f_str[0], 1, f_str.size(), file);
00097   fclose(file);
00098   */
00099   
00100   printf("Finished.\n");
00101   return 0;
00102 }


megatree_cpp
Author(s): Stuart Glaser
autogenerated on Thu Nov 28 2013 11:30:34