Possibility to dump/retrieve tree on disk. Dump voids particle positions correctly

This commit is contained in:
Guilhem Lavaux 2010-09-23 10:19:48 -04:00
parent 3088bb5733
commit 8bf13dfb8b
4 changed files with 168 additions and 28 deletions

View file

@ -1,5 +1,5 @@
/*
File autogenerated by gengetopt version 2.22
File autogenerated by gengetopt version 2.22.2
generated with the following command:
gengetopt -i buildObservedVoids.ggo -f buildObservedVoids_conf -a buildObservedVoids_info -F buildObservedVoids_conf -C
@ -17,6 +17,10 @@
#include <stdlib.h>
#include <string.h>
#ifndef FIX_UNUSED
#define FIX_UNUSED(X) (void) (X) /* avoid warnings for unused params */
#endif
#include "getopt.h"
#include "buildObservedVoids_conf.h"
@ -40,8 +44,11 @@ const char *buildObservedVoids_info_help[] = {
" -g, --gridOutput=STRING 3d grid output of voids \n (default=`all_voids.nc')",
" -q, --quiet Quiet output (default=off)",
" --dumpVoids=STRING Dump the particles in void in a file",
" --dumpIds Dump particle ids (default=off)",
" --ramsesBase=STRING Base directory for ramses",
" --ramsesId=INT Ramses snapshot id",
" --dumpTree Dump the void tree (default=off)",
" --getTree Restore tree from file (default=off)",
0
};
@ -106,13 +113,17 @@ void clear_given (struct buildObservedVoids_info *args_info)
args_info->gridOutput_given = 0 ;
args_info->quiet_given = 0 ;
args_info->dumpVoids_given = 0 ;
args_info->dumpIds_given = 0 ;
args_info->ramsesBase_given = 0 ;
args_info->ramsesId_given = 0 ;
args_info->dumpTree_given = 0 ;
args_info->getTree_given = 0 ;
}
static
void clear_args (struct buildObservedVoids_info *args_info)
{
FIX_UNUSED (args_info);
args_info->desc_arg = NULL;
args_info->desc_orig = NULL;
args_info->partzone_arg = NULL;
@ -132,9 +143,12 @@ void clear_args (struct buildObservedVoids_info *args_info)
args_info->quiet_flag = 0;
args_info->dumpVoids_arg = NULL;
args_info->dumpVoids_orig = NULL;
args_info->dumpIds_flag = 0;
args_info->ramsesBase_arg = NULL;
args_info->ramsesBase_orig = NULL;
args_info->ramsesId_orig = NULL;
args_info->dumpTree_flag = 0;
args_info->getTree_flag = 0;
}
@ -155,15 +169,20 @@ void init_args_info(struct buildObservedVoids_info *args_info)
args_info->gridOutput_help = buildObservedVoids_info_help[9] ;
args_info->quiet_help = buildObservedVoids_info_help[10] ;
args_info->dumpVoids_help = buildObservedVoids_info_help[11] ;
args_info->ramsesBase_help = buildObservedVoids_info_help[12] ;
args_info->ramsesId_help = buildObservedVoids_info_help[13] ;
args_info->dumpIds_help = buildObservedVoids_info_help[12] ;
args_info->ramsesBase_help = buildObservedVoids_info_help[13] ;
args_info->ramsesId_help = buildObservedVoids_info_help[14] ;
args_info->dumpTree_help = buildObservedVoids_info_help[15] ;
args_info->getTree_help = buildObservedVoids_info_help[16] ;
}
void
buildObservedVoids_conf_print_version (void)
{
printf ("%s %s\n", BUILDOBSERVEDVOIDS_CONF_PACKAGE, BUILDOBSERVEDVOIDS_CONF_VERSION);
printf ("%s %s\n",
(strlen(BUILDOBSERVEDVOIDS_CONF_PACKAGE_NAME) ? BUILDOBSERVEDVOIDS_CONF_PACKAGE_NAME : BUILDOBSERVEDVOIDS_CONF_PACKAGE),
BUILDOBSERVEDVOIDS_CONF_VERSION);
}
static void print_help_common(void) {
@ -178,7 +197,7 @@ static void print_help_common(void) {
printf("\n");
if (strlen(buildObservedVoids_info_description) > 0)
printf("%s\n", buildObservedVoids_info_description);
printf("%s\n\n", buildObservedVoids_info_description);
}
void
@ -262,8 +281,9 @@ buildObservedVoids_conf_release (struct buildObservedVoids_info *args_info)
static void
write_into_file(FILE *outfile, const char *opt, const char *arg, char *values[])
write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[])
{
FIX_UNUSED (values);
if (arg) {
fprintf(outfile, "%s=\"%s\"\n", opt, arg);
} else {
@ -307,10 +327,16 @@ buildObservedVoids_conf_dump(FILE *outfile, struct buildObservedVoids_info *args
write_into_file(outfile, "quiet", 0, 0 );
if (args_info->dumpVoids_given)
write_into_file(outfile, "dumpVoids", args_info->dumpVoids_orig, 0);
if (args_info->dumpIds_given)
write_into_file(outfile, "dumpIds", 0, 0 );
if (args_info->ramsesBase_given)
write_into_file(outfile, "ramsesBase", args_info->ramsesBase_orig, 0);
if (args_info->ramsesId_given)
write_into_file(outfile, "ramsesId", args_info->ramsesId_orig, 0);
if (args_info->dumpTree_given)
write_into_file(outfile, "dumpTree", 0, 0 );
if (args_info->getTree_given)
write_into_file(outfile, "getTree", 0, 0 );
i = EXIT_SUCCESS;
@ -347,7 +373,7 @@ buildObservedVoids_conf_free (struct buildObservedVoids_info *args_info)
char *
gengetopt_strdup (const char *s)
{
char *result = NULL;
char *result = 0;
if (!s)
return result;
@ -369,7 +395,7 @@ buildObservedVoids_conf_ext (int argc, char * const *argv, struct buildObservedV
struct buildObservedVoids_conf_params *params)
{
int result;
result = buildObservedVoids_conf_internal (argc, argv, args_info, params, NULL);
result = buildObservedVoids_conf_internal (argc, argv, args_info, params, 0);
if (result == EXIT_FAILURE)
{
@ -392,7 +418,7 @@ buildObservedVoids_conf2 (int argc, char * const *argv, struct buildObservedVoid
params.check_ambiguity = 0;
params.print_errors = 1;
result = buildObservedVoids_conf_internal (argc, argv, args_info, &params, NULL);
result = buildObservedVoids_conf_internal (argc, argv, args_info, &params, 0);
if (result == EXIT_FAILURE)
{
@ -408,7 +434,7 @@ buildObservedVoids_conf_required (struct buildObservedVoids_info *args_info, con
{
int result = EXIT_SUCCESS;
if (buildObservedVoids_conf_required2(args_info, prog_name, NULL) > 0)
if (buildObservedVoids_conf_required2(args_info, prog_name, 0) > 0)
result = EXIT_FAILURE;
if (result == EXIT_FAILURE)
@ -423,6 +449,7 @@ buildObservedVoids_conf_required (struct buildObservedVoids_info *args_info, con
int
buildObservedVoids_conf_required2 (struct buildObservedVoids_info *args_info, const char *prog_name, const char *additional_error)
{
FIX_UNUSED (additional_error);
int error = 0;
/* checks for required options */
@ -474,13 +501,15 @@ static char *package_name = 0;
static
int update_arg(void *field, char **orig_field,
unsigned int *field_given, unsigned int *prev_given,
char *value, char *possible_values[], const char *default_value,
char *value, const char *possible_values[],
const char *default_value,
buildObservedVoids_conf_arg_type arg_type,
int check_ambiguity, int override,
int no_free, int multiple_option,
const char *long_opt, char short_opt,
const char *additional_error)
{
FIX_UNUSED (field);
char *stop_char = 0;
const char *val = value;
int found;
@ -502,6 +531,7 @@ int update_arg(void *field, char **orig_field,
return 1; /* failure */
}
FIX_UNUSED (default_value);
if (field_given && *field_given && ! override)
return 0;
@ -569,7 +599,8 @@ int update_arg(void *field, char **orig_field,
int
buildObservedVoids_conf_internal (int argc, char * const *argv, struct buildObservedVoids_info *args_info,
buildObservedVoids_conf_internal (
int argc, char * const *argv, struct buildObservedVoids_info *args_info,
struct buildObservedVoids_conf_params *params, const char *additional_error)
{
int c; /* Character of the parsed option. */
@ -616,9 +647,12 @@ buildObservedVoids_conf_internal (int argc, char * const *argv, struct buildObse
{ "gridOutput", 1, NULL, 'g' },
{ "quiet", 0, NULL, 'q' },
{ "dumpVoids", 1, NULL, 0 },
{ "dumpIds", 0, NULL, 0 },
{ "ramsesBase", 1, NULL, 0 },
{ "ramsesId", 1, NULL, 0 },
{ NULL, 0, NULL, 0 }
{ "dumpTree", 0, NULL, 0 },
{ "getTree", 0, NULL, 0 },
{ 0, 0, 0, 0 }
};
c = getopt_long (argc, argv, "hVd:p:v:m:f:o:g:q", long_options, &option_index);
@ -760,6 +794,18 @@ buildObservedVoids_conf_internal (int argc, char * const *argv, struct buildObse
additional_error))
goto failure;
}
/* Dump particle ids. */
else if (strcmp (long_options[option_index].name, "dumpIds") == 0)
{
if (update_arg((void *)&(args_info->dumpIds_flag), 0, &(args_info->dumpIds_given),
&(local_args_info.dumpIds_given), optarg, 0, 0, ARG_FLAG,
check_ambiguity, override, 1, 0, "dumpIds", '-',
additional_error))
goto failure;
}
/* Base directory for ramses. */
else if (strcmp (long_options[option_index].name, "ramsesBase") == 0)
@ -788,6 +834,30 @@ buildObservedVoids_conf_internal (int argc, char * const *argv, struct buildObse
additional_error))
goto failure;
}
/* Dump the void tree. */
else if (strcmp (long_options[option_index].name, "dumpTree") == 0)
{
if (update_arg((void *)&(args_info->dumpTree_flag), 0, &(args_info->dumpTree_given),
&(local_args_info.dumpTree_given), optarg, 0, 0, ARG_FLAG,
check_ambiguity, override, 1, 0, "dumpTree", '-',
additional_error))
goto failure;
}
/* Restore tree from file. */
else if (strcmp (long_options[option_index].name, "getTree") == 0)
{
if (update_arg((void *)&(args_info->getTree_flag), 0, &(args_info->getTree_given),
&(local_args_info.getTree_given), optarg, 0, 0, ARG_FLAG,
check_ambiguity, override, 1, 0, "getTree", '-',
additional_error))
goto failure;
}
break;
@ -830,7 +900,7 @@ failure:
/* 3 is for "--" and "=" */
static int
_buildObservedVoids_conf_configfile (char * const filename, int *my_argc)
_buildObservedVoids_conf_configfile (const char *filename, int *my_argc)
{
FILE* file;
char my_argv[CONFIG_FILE_LINE_BUFFER_SIZE+1];
@ -842,14 +912,14 @@ _buildObservedVoids_conf_configfile (char * const filename, int *my_argc)
size_t len, next_token;
char delimiter;
if ((file = fopen(filename, "r")) == NULL)
if ((file = fopen(filename, "r")) == 0)
{
fprintf (stderr, "%s: Error opening configuration file '%s'\n",
BUILDOBSERVEDVOIDS_CONF_PACKAGE, filename);
return EXIT_FAILURE;
}
while ((fgets(linebuf, CONFIG_FILE_LINE_SIZE, file)) != NULL)
while ((fgets(linebuf, CONFIG_FILE_LINE_SIZE, file)) != 0)
{
++line_num;
my_argv[0] = '\0';
@ -876,7 +946,7 @@ _buildObservedVoids_conf_configfile (char * const filename, int *my_argc)
if (fopt[next_token] == '\0') /* the line is over */
{
farg = NULL;
farg = 0;
equal = 0;
goto noarg;
}
@ -967,7 +1037,8 @@ _buildObservedVoids_conf_configfile (char * const filename, int *my_argc)
}
int
buildObservedVoids_conf_configfile (char * const filename,
buildObservedVoids_conf_configfile (
const char *filename,
struct buildObservedVoids_info *args_info,
int override, int initialize, int check_required)
{
@ -983,7 +1054,7 @@ buildObservedVoids_conf_configfile (char * const filename,
}
int
buildObservedVoids_conf_config_file (char * const filename,
buildObservedVoids_conf_config_file (const char *filename,
struct buildObservedVoids_info *args_info,
struct buildObservedVoids_conf_params *params)
{

View file

@ -1,6 +1,6 @@
/** @file buildObservedVoids_conf.h
* @brief The header file for the command line option parser
* generated by GNU Gengetopt version 2.22
* generated by GNU Gengetopt version 2.22.2
* http://www.gnu.org/software/gengetopt.
* DO NOT modify this file, since it can be overwritten
* @author GNU Gengetopt by Lorenzo Bettini */
@ -20,10 +20,15 @@ extern "C" {
#endif /* __cplusplus */
#ifndef BUILDOBSERVEDVOIDS_CONF_PACKAGE
/** @brief the program name */
/** @brief the program name (used for printing errors) */
#define BUILDOBSERVEDVOIDS_CONF_PACKAGE "buildObservedVoids"
#endif
#ifndef BUILDOBSERVEDVOIDS_CONF_PACKAGE_NAME
/** @brief the complete program name (used for help and version) */
#define BUILDOBSERVEDVOIDS_CONF_PACKAGE_NAME "buildObservedVoids"
#endif
#ifndef BUILDOBSERVEDVOIDS_CONF_VERSION
/** @brief the program version */
#define BUILDOBSERVEDVOIDS_CONF_VERSION "0"
@ -63,12 +68,18 @@ struct buildObservedVoids_info
char * dumpVoids_arg; /**< @brief Dump the particles in void in a file. */
char * dumpVoids_orig; /**< @brief Dump the particles in void in a file original value given at command line. */
const char *dumpVoids_help; /**< @brief Dump the particles in void in a file help description. */
int dumpIds_flag; /**< @brief Dump particle ids (default=off). */
const char *dumpIds_help; /**< @brief Dump particle ids help description. */
char * ramsesBase_arg; /**< @brief Base directory for ramses. */
char * ramsesBase_orig; /**< @brief Base directory for ramses original value given at command line. */
const char *ramsesBase_help; /**< @brief Base directory for ramses help description. */
int ramsesId_arg; /**< @brief Ramses snapshot id. */
char * ramsesId_orig; /**< @brief Ramses snapshot id original value given at command line. */
const char *ramsesId_help; /**< @brief Ramses snapshot id help description. */
int dumpTree_flag; /**< @brief Dump the void tree (default=off). */
const char *dumpTree_help; /**< @brief Dump the void tree help description. */
int getTree_flag; /**< @brief Restore tree from file (default=off). */
const char *getTree_help; /**< @brief Restore tree from file help description. */
unsigned int help_given ; /**< @brief Whether help was given. */
unsigned int version_given ; /**< @brief Whether version was given. */
@ -82,8 +93,11 @@ struct buildObservedVoids_info
unsigned int gridOutput_given ; /**< @brief Whether gridOutput was given. */
unsigned int quiet_given ; /**< @brief Whether quiet was given. */
unsigned int dumpVoids_given ; /**< @brief Whether dumpVoids was given. */
unsigned int dumpIds_given ; /**< @brief Whether dumpIds was given. */
unsigned int ramsesBase_given ; /**< @brief Whether ramsesBase was given. */
unsigned int ramsesId_given ; /**< @brief Whether ramsesId was given. */
unsigned int dumpTree_given ; /**< @brief Whether dumpTree was given. */
unsigned int getTree_given ; /**< @brief Whether getTree was given. */
} ;
@ -206,7 +220,7 @@ void buildObservedVoids_conf_free (struct buildObservedVoids_info *args_info);
* @return 0 if everything went fine, NON 0 if an error took place
* @deprecated use buildObservedVoids_conf_config_file() instead
*/
int buildObservedVoids_conf_configfile (char * const filename,
int buildObservedVoids_conf_configfile (const char *filename,
struct buildObservedVoids_info *args_info,
int override, int initialize, int check_required);
@ -217,7 +231,7 @@ int buildObservedVoids_conf_configfile (char * const filename,
* @param params additional parameters for the parser
* @return 0 if everything went fine, NON 0 if an error took place
*/
int buildObservedVoids_conf_config_file (char * const filename,
int buildObservedVoids_conf_config_file (const char *filename,
struct buildObservedVoids_info *args_info,
struct buildObservedVoids_conf_params *params);

View file

@ -2,5 +2,5 @@ CC= gcc
CXX= g++
CPPFLAGS=
LDFLAGS= -L/usr/local/lib -lCosmoTool -lgsl -lgslcblas
CXXFLAGS= $(CPPFLAGS) -ggdb -O3 -ffast-math
CFLAGS= $(CPPFLAGS) -ggdb -O3 -ffast-math
CXXFLAGS= $(CPPFLAGS) -ggdb -O0 -ftree-vectorize -ftree-vectorizer-verbose=2 -ffast-math
CFLAGS= $(CPPFLAGS) -ggdb -O0 -ftree-vectorize -ftree-vectorizer-verbose=2 -ffast-math

View file

@ -15,16 +15,39 @@ struct VoidNode
std::list<VoidNode *> children;
};
struct VoidNodeOnDisk
{
int vid;
int parent;
};
class VoidTree
{
protected:
uint32_t totalNumNodes;
uint32_t totalNumNodes, activeNodes;
VoidNode *nodes;
VoidNode *rootNode;
ZobovRep& zobov;
public:
typedef std::list<VoidNode *> VoidList;
void dumpTree(std::ostream& o)
{
VoidNodeOnDisk data;
o.write((char*)&activeNodes, sizeof(uint32_t));
for (uint32_t i = 0; i < activeNodes; i++)
{
data.vid = nodes[i].vid;
if (nodes[i].parent == 0)
data.parent = -1;
else
data.parent = nodes[i].parent - nodes;
o.write((char *)&data, sizeof(VoidNodeOnDisk));
}
}
int lookupParent(int voidId, const std::vector<std::list<int> >& voids_for_zones)
{
int lastSize = 0x7fffffff;
@ -33,7 +56,7 @@ public:
const std::list<int>& candidateList = voids_for_zones[ref_void.zId.front()];
std::list<int>::const_iterator iter_candidate = candidateList.begin();
//std::cout << "candidate list size is " << candidateList.size() << std::endl;
// std::cout << "candidate list size is " << candidateList.size() << std::endl;
while (iter_candidate != candidateList.end())
{
@ -91,6 +114,38 @@ public:
std::cout << "Failure to lookup parent (2)" << std::endl;
return -1;
}
VoidTree(ZobovRep& rep, std::istream& disk)
: zobov(rep)
{
totalNumNodes = rep.allVoids.size();
disk.read((char *)&activeNodes, sizeof(uint32_t));
nodes = new VoidNode[activeNodes];
rootNode = 0;
for (uint32_t i = 0; i < activeNodes; i++)
{
VoidNodeOnDisk data;
disk.read((char *)&data, sizeof(data));
nodes[i].vid = data.vid;
if (data.parent < 0)
{
if (rootNode != 0)
{
std::cerr << "Multiple root to the tree !!!" << std::endl;
abort();
}
nodes[i].parent = 0;
rootNode = &nodes[i];
}
else
{
nodes[i].parent = nodes + data.parent;
nodes[i].parent->children.push_back(&nodes[i]);
}
}
}
VoidTree(ZobovRep& rep)
: zobov(rep)
@ -113,7 +168,6 @@ public:
{
nodes[i].vid = i;
nodes[i].parent = 0;
nodes[i].children.clear();
}
std::cout << "Linking voids together..." << std::endl;
@ -149,6 +203,7 @@ public:
}
rootNode = &nodes[i];
}
activeNodes = inserted;
}
~VoidTree()