Skip to content

Commit

Permalink
Provide PUMAS MDF to danton_initialise
Browse files Browse the repository at this point in the history
  • Loading branch information
niess committed Sep 25, 2018
1 parent d87c520 commit cd6e1df
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 60 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ bin
.tags

# Ignore temporary data.
*.b
.danton.*
*.dat
share/topography
share/scripts
Expand Down
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@ install:
- make

script:
- source setup.sh
- danton
- ./bin/danton
12 changes: 8 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Generic options
PDF_DIR := $(abspath deps/ent/share/pdf)
DANTON_DEFAULT_PDF := $(abspath deps/ent/share/pdf/CT14nlo_0000.dat)
DANTON_DEFAULT_MDF := $(abspath share/materials/materials.xml)
DANTON_DEFAULT_DEDX := $(abspath share/materials/dedx)
USE_TIFF := 1
USE_PNG := 1

Expand Down Expand Up @@ -58,7 +60,7 @@ endif
ifneq ($(TURTLE_USE_TIFF),1)
TURTLE_CFLAGS += -DTURTLE_NO_PNG
endif

lib/libdanton.so: $(OBJS)
@$(CC) -o $@ $(CFLAGS) -shared $(OBJS) -lgfortran -ltiff -lpng -lm

Expand All @@ -71,9 +73,11 @@ define build_c
@mkdir -p build
@$(CC) -o $@ $(CFLAGS) $1 -fPIC -c $<
endef

build/danton.lo: src/danton.c
@$(call build_c,-DPDF_DIR="\"$(PDF_DIR)\"" $(INCLUDE))
@$(call build_c,-DDANTON_DEFAULT_PDF="\"$(DANTON_DEFAULT_PDF)\"" \
-DDANTON_DEFAULT_MDF="\"$(DANTON_DEFAULT_MDF)\"" \
-DDANTON_DEFAULT_DEDX="\"$(DANTON_DEFAULT_DEDX)\"" $(INCLUDE))

build/%.lo: src/danton/primary/%.c
@$(call build_c,$(INCLUDE))
Expand Down
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,14 @@ detailed topography can be provided from world wide elevation models, e.g.
## Installation
DANTON has been tested on both Linux and OSX. Not on Windows though. The
provided [Makefile](Makefile) builds `libdanton` as a shared library as well
as the `danton` executable. Note that the [setup.sh](setup.sh) script must
be sourced before using DANTON, e.g. as:
as the `danton` executable, e.g. as:
```bash
# Build DANTON
cd danton
make

# Run the executable
source setup.sh
danton path/to/card.json
./bin/danton path/to/card.json
```

## API documentation
Expand Down
6 changes: 4 additions & 2 deletions include/danton.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@ typedef int danton_lock_cb(void);
* Initialise the DANTON library.
*
* @param pdf Path to the PDF tables for ENT, or `NULL`.
* @param mdf Path to the MDF file for PUMAS, or `NULL`.
* @param dedx Path to the energy loss tables for PUMAS, or `NULL`.
* @param lock A locking callback, or `NULL`.
* @param unlock An unlocking callback, or `NULL`.
* @return `EXIT_SUCCESS` on success, `EXIT_FAILURE` otherwise.
Expand All @@ -308,8 +310,8 @@ typedef int danton_lock_cb(void);
* __Warning__ : for multithreaded usage one **must** provide valid *lock* and
* *unlock* callbacks.
*/
DANTON_API int danton_initialise(
const char * pdf, danton_lock_cb * lock, danton_lock_cb * unlock);
DANTON_API int danton_initialise(const char * pdf, const char * mdf,
const char * dedx, danton_lock_cb * lock, danton_lock_cb * unlock);

/**
* Finalise the danton library.
Expand Down
16 changes: 0 additions & 16 deletions setup.sh

This file was deleted.

2 changes: 1 addition & 1 deletion src/danton-x.c
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ int main(int argc, char * argv[])
if (argc <= 1) exit_with_help(EXIT_SUCCESS);

/* Initialise DANTON. */
if (danton_initialise(NULL, NULL, NULL) != EXIT_SUCCESS) {
if (danton_initialise(NULL, NULL, NULL, NULL, NULL) != EXIT_SUCCESS) {
ROAR_ERRWP_MESSAGE(&handler, &main, -1, "danton error",
danton_error_pop(NULL));
}
Expand Down
80 changes: 50 additions & 30 deletions src/danton.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,13 @@
#define M_PI 3.14159265358979323846
#endif

/* Paths for PUMAS materials. */
#ifndef PUMAS_MDF
#define PUMAS_MDF NULL
#endif
#ifndef PUMAS_DEDX
#define PUMAS_DEDX NULL
#endif

/* Handle for ENT Physic. */
static struct ent_physics * physics = NULL;

/* Path to the PDF tables. */
/* Path for data sets. */
static char * pdf_path = NULL;
static char * mdf_path = NULL;
static char * dedx_path = NULL;

/* The tau lepton mass, in GeV / c^2. */
static double tau_mass;
Expand Down Expand Up @@ -638,8 +632,8 @@ static void earth_model_configure(void)
#undef AW

/* Medium callback encapsulation for PUMAS. */
double medium_pumas(struct pumas_context * context, struct pumas_state * state,
struct pumas_medium ** medium_ptr)
static double medium_pumas(struct pumas_context * context,
struct pumas_state * state, struct pumas_medium ** medium_ptr)
{
double direction[3];
if (context->forward) {
Expand Down Expand Up @@ -1524,7 +1518,7 @@ static int transport_backward(
static int load_pumas(struct danton_context * context)
{
const enum pumas_particle particle = PUMAS_PARTICLE_TAU;
const char * dump = "materials.b";
const char * dump = ".danton.cfg";

/* First, attempt to load any binary dump. */
FILE * stream = fopen(dump, "rb");
Expand All @@ -1537,11 +1531,16 @@ static int load_pumas(struct danton_context * context)
}
fclose(stream);
pumas_particle(NULL, &tau_ctau0, &tau_mass);
return EXIT_SUCCESS;
goto exit;
}

/* If no binary dump, initialise from the MDF and dump. */
pumas_initialise(particle, PUMAS_MDF, PUMAS_DEDX, NULL);
const char * mdf = (mdf_path == NULL) ?
DANTON_DEFAULT_MDF : mdf_path;
const char * dedx = (dedx_path == NULL) ?
DANTON_DEFAULT_DEDX : dedx_path;

pumas_initialise(particle, mdf, dedx, NULL);
pumas_particle(NULL, &tau_ctau0, &tau_mass);

/* Dump the library configuration. */
Expand All @@ -1550,6 +1549,12 @@ static int load_pumas(struct danton_context * context)
pumas_dump(stream);
fclose(stream);

exit:
free(mdf_path);
mdf_path = NULL;
free(dedx_path);
dedx_path = NULL;

return EXIT_SUCCESS;
}

Expand All @@ -1563,7 +1568,7 @@ static int initialise_physics(struct danton_context * context)
enum ent_return e_rc;
const char * pdf;
if (pdf_path == NULL)
pdf = PDF_DIR "/CT14nlo_0000.dat";
pdf = DANTON_DEFAULT_PDF;
else
pdf = pdf_path;
if ((e_rc = ent_physics_create(&physics, pdf)) != ENT_RETURN_SUCCESS) {
Expand Down Expand Up @@ -1603,26 +1608,37 @@ static void topography_initialise(void)
initialised = 1;
}

static int copy_config_string(const char * opts, char ** config)
{
if (opts == NULL) return EXIT_SUCCESS;

if (*config != NULL) free(*config);
const int n = strlen(opts) + 1;
*config = malloc(n);
if (*config == NULL) {
danton_error_push(NULL,
"%s (%d): could not allocate memory.", __FILE__, __LINE__);
return EXIT_FAILURE;
}
memcpy(*config, opts, n);

return EXIT_SUCCESS;
}

/* Initialise the DANTON library. */
int danton_initialise(
const char * pdf, danton_lock_cb * lock_, danton_lock_cb * unlock_)
int danton_initialise(const char * pdf, const char * mdf, const char * dedx,
danton_lock_cb * lock_, danton_lock_cb * unlock_)
{
/* Clear the error status. */
errno = 0;

/* Copy the PDF path for later use. */
if (pdf != NULL) {
if (pdf_path != NULL) free(pdf_path);
const int n = strlen(pdf) + 1;
pdf_path = malloc(n);
if (pdf_path == NULL) {
danton_error_push(NULL,
"%s (%d): could not allocate memory.", __FILE__,
__LINE__);
return EXIT_FAILURE;
}
memcpy(pdf_path, pdf, n);
}
/* Copy the data paths for later use. */
if (copy_config_string(pdf, &pdf_path) != EXIT_SUCCESS)
return EXIT_FAILURE;
if (copy_config_string(mdf, &mdf_path) != EXIT_SUCCESS)
return EXIT_FAILURE;
if (copy_config_string(dedx, &dedx_path) != EXIT_SUCCESS)
return EXIT_FAILURE;

/* Check and update the lock callbacks. */
if (((lock_ == NULL) && (unlock_ != NULL)) ||
Expand All @@ -1643,6 +1659,10 @@ void danton_finalise(void)
{
free(pdf_path);
pdf_path = NULL;
free(mdf_path);
mdf_path = NULL;
free(dedx_path);
dedx_path = NULL;
ent_physics_destroy(&physics);
pumas_finalise();
alouette_finalise();
Expand Down

0 comments on commit cd6e1df

Please sign in to comment.