Commit 1a3badb8d82b3a8566abeffe0786296ef903ef4a

Authored by Jürgen Knödlseder
1 parent b3d4465c

Setup for development of COMPTEL module.

The directory tree has been setup for the development of the COMPTEL module. Instructions have been added to the various Makefile.am and to configure.ac to detect and to configure the library for inclusing of the COMPTEL module. The pyext/setup.py.in script has also bee adapted.

A simple test case has been written for loading of COMPTEL data into an observation.

The summary include file and the summary swig files have been setup.
inst/Makefile.am
... ... @@ -10,7 +10,10 @@ endif
10 10 if WITH_INST_MWL
11 11 INST_MWL = mwl
12 12 endif
  13 +if WITH_INST_COM
  14 +INST_COM = com
  15 +endif
13 16  
14 17 # Set sub directories
15   -SUBDIRS = $(INST_MWL) $(INST_CTA) $(INST_LAT)
  18 +SUBDIRS = $(INST_MWL) $(INST_CTA) $(INST_LAT) $(INST_COM)
16 19  
... ...
inst/com/Makefile.am 0 → 100644
  1 +## Process this file with automake to produce Makefile.in
  2 +
  3 +# Set include directories
  4 +INCLUDES = -I$(top_srcdir)/include \
  5 + -I$(top_srcdir)/src \
  6 + -I$(top_srcdir)/src/support \
  7 + -I$(top_srcdir)/inst/com/include \
  8 + -I$(top_srcdir)/inst/com/src
  9 +
  10 +# Define sources for this directory
  11 +sources = src/GCOMException.cpp \
  12 + src/GCOMObservation.cpp \
  13 + src/GCOMEventCube.cpp \
  14 + src/GCOMEventBin.cpp \
  15 + src/GCOMResponse.cpp \
  16 + src/GCOMInstDir.cpp \
  17 + src/GCOMPointing.cpp
  18 +
  19 +# Define headers to be installed
  20 +pkginclude_HEADERS = include/GCOMException.hpp \
  21 + include/GCOMObservation.hpp \
  22 + include/GCOMEventCube.hpp \
  23 + include/GCOMEventBin.hpp \
  24 + include/GCOMPointing.hpp \
  25 + include/GCOMInstDir.hpp \
  26 + include/GCOMResponse.hpp \
  27 + include/GCOMLib.hpp
  28 +
  29 +# Calibration files to distribute
  30 +irfs =
  31 +
  32 +# Build libtool library
  33 +noinst_LTLIBRARIES = libcom.la
  34 +libcom_la_SOURCES = $(sources)
  35 +libcom_la_LDFLAGS = -version-info $(GAMMALIB_LT_VERSION)
  36 +
  37 +# Distribute calibration database files
  38 +EXTRA_DIST = $(irfs)
  39 +caldbdir = $(datadir)/caldb/com
  40 +caldb_DATA = $(irfs)
... ...
inst/com/include/GCOMLib.hpp 0 → 100644
  1 +/***************************************************************************
  2 + * GCOMLib.hpp - COMPTEL Support Header files *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright (C) 2012 by <author> *
  5 + * ----------------------------------------------------------------------- *
  6 + * *
  7 + * This program is free software: you can redistribute it and/or modify *
  8 + * it under the terms of the GNU General Public License as published by *
  9 + * the Free Software Foundation, either version 3 of the License, or *
  10 + * (at your option) any later version. *
  11 + * *
  12 + * This program is distributed in the hope that it will be useful, *
  13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  15 + * GNU General Public License for more details. *
  16 + * *
  17 + * You should have received a copy of the GNU General Public License *
  18 + * along with this program. If not, see <http://www.gnu.org/licenses/>. *
  19 + * *
  20 + ***************************************************************************/
  21 +/**
  22 + * @file GCOMLib.hpp
  23 + * @brief Collection of COMPTEL support header files
  24 + * @author <author>
  25 + */
  26 +
  27 +#ifndef GCOMLIB_HPP
  28 +#define GCOMLIB_HPP
  29 +
  30 +/* __ Includes ___________________________________________________________ */
  31 +#include "GammaLib.hpp"
  32 +
  33 +/* __ COMPTEL specific headers ___________________________________________ */
  34 +#include "GCOMException.hpp"
  35 +#include "GCOMObservation.hpp"
  36 +#include "GCOMEventCube.hpp"
  37 +#include "GCOMEventBin.hpp"
  38 +#include "GCOMInstDir.hpp"
  39 +#include "GCOMPointing.hpp"
  40 +#include "GCOMResponse.hpp"
  41 +
  42 +#endif /* GCOMLIB_HPP */
... ...
inst/com/pyext/com.i 0 → 100644
  1 +/***************************************************************************
  2 + * com - COMPTEL support python bindings *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright (C) 2012 by <author> *
  5 + * ----------------------------------------------------------------------- *
  6 + * *
  7 + * This program is free software: you can redistribute it and/or modify *
  8 + * it under the terms of the GNU General Public License as published by *
  9 + * the Free Software Foundation, either version 3 of the License, or *
  10 + * (at your option) any later version. *
  11 + * *
  12 + * This program is distributed in the hope that it will be useful, *
  13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  15 + * GNU General Public License for more details. *
  16 + * *
  17 + * You should have received a copy of the GNU General Public License *
  18 + * along with this program. If not, see <http://www.gnu.org/licenses/>. *
  19 + * *
  20 + * ----------------------------------------------------------------------- *
  21 + * Usage: *
  22 + * swig -c++ -python -Wall com.i *
  23 + ***************************************************************************/
  24 +%module com
  25 +%feature("autodoc", "1");
  26 +
  27 +/* __ Include standard typemaps for vectors and strings __________________ */
  28 +%include stl.i
  29 +
  30 +/* __ Make sure that exceptions are catched ______________________________ */
  31 +%import(module="support") "GException.i";
  32 +
  33 +/* __ Inform about base classes __________________________________________ */
  34 +%import(module="obs") "GObservation.i";
  35 +%import(module="obs") "GEvent.i";
  36 +%import(module="obs") "GEventBin.i";
  37 +%import(module="obs") "GEvents.i";
  38 +%import(module="obs") "GEventCube.i";
  39 +%import(module="obs") "GPointing.i";
  40 +%import(module="obs") "GResponse.i";
  41 +%import(module="obs") "GInstDir.i";
  42 +
  43 +/* __ COMPTEL _____________________________________________________________ */
  44 +%include "GCOMObservation.i"
  45 +%include "GCOMEventCube.i"
  46 +%include "GCOMEventBin.i"
  47 +%include "GCOMPointing.i"
  48 +%include "GCOMResponse.i"
  49 +%include "GCOMInstDir.i"
  50 +
... ...
inst/com/test/data/m32171_drx.fits.gz 0 → 100644
No preview for this file type
inst/com/test/data/m34997_drg.fits.gz 0 → 100644
No preview for this file type
inst/com/test/data/m50438_dre.fits.gz 0 → 100644
No preview for this file type
inst/com/test/data/m50439_dre.fits.gz 0 → 100644
No preview for this file type
inst/com/test/data/m50440_dre.fits.gz 0 → 100644
No preview for this file type
inst/com/test/data/m50441_dre.fits.gz 0 → 100644
No preview for this file type
inst/com/test/data/obs.xml 0 → 100644
  1 +<observation_list title="observation library">
  2 + <observation name="Crab" id="00001" instrument="COM">
  3 + <parameter name="DRE" file="../inst/cta/test/data/m50439_dre.fits"/>
  4 + <parameter name="DRB" file="../inst/cta/test/data/m34997_drg.fits"/>
  5 + <parameter name="DRG" file="../inst/cta/test/data/m34997_drg.fits"/>
  6 + <parameter name="DRX" file="../inst/cta/test/data/m32171_drx.fits"/>
  7 + </observation>
  8 +</observation_list>
... ...
inst/com/test/test_COM.cpp 0 → 100644
  1 +/***************************************************************************
  2 + * test_COM.cpp - test COM classes *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright (C) 2012 by <author> *
  5 + * ----------------------------------------------------------------------- *
  6 + * *
  7 + * This program is free software: you can redistribute it and/or modify *
  8 + * it under the terms of the GNU General Public License as published by *
  9 + * the Free Software Foundation, either version 3 of the License, or *
  10 + * (at your option) any later version. *
  11 + * *
  12 + * This program is distributed in the hope that it will be useful, *
  13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  15 + * GNU General Public License for more details. *
  16 + * *
  17 + * You should have received a copy of the GNU General Public License *
  18 + * along with this program. If not, see <http://www.gnu.org/licenses/>. *
  19 + * *
  20 + ***************************************************************************/
  21 +/**
  22 + * @file test_COM.cpp
  23 + * @brief Testing of COM classes
  24 + * @author <author>
  25 + */
  26 +
  27 +/* __ Includes ___________________________________________________________ */
  28 +#ifdef HAVE_CONFIG_H
  29 +#include <config.h>
  30 +#endif
  31 +#include <stdlib.h>
  32 +#include <iostream>
  33 +#include <unistd.h>
  34 +#include "GCOMLib.hpp"
  35 +#include "GTools.hpp"
  36 +
  37 +/* __ Namespaces _________________________________________________________ */
  38 +
  39 +/* __ Globals ____________________________________________________________ */
  40 +
  41 +/* __ Constants __________________________________________________________ */
  42 +const std::string datadir = "../inst/com/test/data";
  43 +const std::string com_caldb = "../inst/com/caldb";
  44 +const std::string com_dre = datadir+"/m50439_dre.fits";
  45 +const std::string com_drb = datadir+"/m34997_drg.fits";
  46 +const std::string com_drg = datadir+"/m34997_drg.fits";
  47 +const std::string com_drx = datadir+"/m32171_drx.fits";
  48 +const std::string com_obs = datadir+"obs.xml";
  49 +
  50 +
  51 +/***********************************************************************//**
  52 + * @brief Checks handling of binned observations
  53 + *
  54 + * This function checks the handling of binned observations. Binned
  55 + * observations are defined by
  56 + * a DRE file containing the events,
  57 + * a DRB file containing the background model,
  58 + * a DRG file containing the geometrical probability of having an interaction
  59 + * in the second detector plane, and
  60 + * a DRX file containing the sky exposure.
  61 + *
  62 + * Note that in first approximation we can use the DRG file as background
  63 + * model.
  64 + ***************************************************************************/
  65 +void test_binned_obs(void)
  66 +{
  67 + // Write header
  68 + std::cout << "Test binned COMPTEL observation handling: ";
  69 +
  70 + // Declare observation and container
  71 + GObservations obs;
  72 +
  73 + // Dataset constructor
  74 + try {
  75 + // Construct observation from datasets
  76 + GCOMObservation com(com_dre, com_drb, com_drg, com_drx);
  77 + }
  78 + catch (std::exception &e) {
  79 + std::cout << std::endl
  80 + << "TEST ERROR: Unable to construct observation from datasets."
  81 + << std::endl;
  82 + std::cout << e.what() << std::endl;
  83 + throw;
  84 + }
  85 + std::cout << ".";
  86 +
  87 + // XML constructor
  88 + try {
  89 + // Construct observation from XML file
  90 + GObservations obs(com_obs);
  91 + }
  92 + catch (std::exception &e) {
  93 + std::cout << std::endl
  94 + << "TEST ERROR: Unable to construct observation from XML file."
  95 + << std::endl;
  96 + std::cout << e.what() << std::endl;
  97 + throw;
  98 + }
  99 + std::cout << ".";
  100 +
  101 + // Notify final test success
  102 + std::cout << " ok." << std::endl;
  103 +
  104 + // Exit test
  105 + return;
  106 +
  107 +}
  108 +
  109 +
  110 +/***********************************************************************//**
  111 + * @brief Main test function
  112 + ***************************************************************************/
  113 +int main(void)
  114 +{
  115 + // Dump header
  116 + std::cout << std::endl;
  117 + std::cout << "*********************************************" << std::endl;
  118 + std::cout << "* COMPTEL instrument specific class testing *" << std::endl;
  119 + std::cout << "*********************************************" << std::endl;
  120 +
  121 + // Check if data directory exists
  122 + bool has_data = (access(datadir.c_str(), R_OK) == 0);
  123 +
  124 + // Execute tests requiring data
  125 + if (has_data) {
  126 +
  127 + // Set CALDB environment variable
  128 + std::string caldb = "CALDB="+com_caldb;
  129 + putenv((char*)caldb.c_str());
  130 +
  131 + // Execute tests
  132 + test_binned_obs();
  133 + }
  134 + else {
  135 + std::cout << "Skipped several tests since no test data have been found."
  136 + << std::endl;
  137 + }
  138 +
  139 + // Return
  140 + return 0;
  141 +}
... ...
pyext/Makefile.am
1 1 #############################################################################
2 2 # Makefile for gammalib Python extension module #
3 3 # ------------------------------------------------------------------------- #
4   -# Copyright (C) 2011 Jurgen Knodlseder #
  4 +# Copyright (C) 2011-2012 Juergen Knoedlseder #
5 5 # ------------------------------------------------------------------------- #
6 6 # #
7 7 # This program is free software: you can redistribute it and/or modify #
... ... @@ -39,7 +39,12 @@ endif
39 39 if WITH_INST_LAT
40 40 LAT_SWIG_TARGETS = gammalib/lat_wrap.cpp gammalib/lat.py
41 41 endif
42   -INST_SWIG_TARGETS = $(MWL_SWIG_TARGETS) $(CTA_SWIG_TARGETS) $(LAT_SWIG_TARGETS)
  42 +if WITH_INST_COM
  43 + COM_SWIG_TARGETS = gammalib/com_wrap.cpp gammalib/com.py
  44 +endif
  45 +INST_SWIG_TARGETS = $(MWL_SWIG_TARGETS) \
  46 + $(CTA_SWIG_TARGETS) \
  47 + $(COM_SWIG_TARGETS)
43 48  
44 49 # Sources that are required for the build. All targets in the list will be built
45 50 # before anything. These are honored by 'make all', 'make check' and 'make install'.
... ... @@ -118,6 +123,12 @@ gammalib/lat_wrap.cpp gammalib/lat.py: $(top_srcdir)/inst/lat/pyext/lat.i
118 123 $(SWIG) -c++ -python -Wall -o gammalib/lat_wrap.cpp -outdir gammalib $<
119 124 endif
120 125  
  126 +# Rule for COM module
  127 +if WITH_INST_COM
  128 +gammalib/com_wrap.cpp gammalib/com.py: $(top_srcdir)/inst/com/pyext/com.i
  129 + $(SWIG) -c++ -python -Wall -o gammalib/com_wrap.cpp -outdir gammalib $<
  130 +endif
  131 +
121 132 endif # HAVE_SWIG
122 133  
123 134 endif # WITH_PYTHON
... ...
pyext/setup.py.in
1 1 #############################################################################
2 2 # Disutils setup file for gammalib Python extension module #
3 3 # ------------------------------------------------------------------------- #
4   -# Copyright (C) 2011 Jurgen Knodlseder #
  4 +# Copyright (C) 2011-2012 Juergen Knoedlseder #
5 5 # ------------------------------------------------------------------------- #
6 6 # #
7 7 # This program is free software: you can redistribute it and/or modify #
... ... @@ -144,6 +144,9 @@ if &#39;@WITH_INST_CTA_TRUE@&#39; != &#39;#&#39;:
144 144 if '@WITH_INST_LAT_TRUE@' != '#':
145 145 print "Include Fermi/LAT instrument interface in gammalib Python bindings."
146 146 inst_modules.append('lat')
  147 +if '@WITH_INST_COM_TRUE@' != '#':
  148 + print "Include COMPTEL instrument interface in gammalib Python bindings."
  149 + inst_modules.append('com')
147 150  
148 151 # Set extension definition for core modules
149 152 ext_modules = []
... ...
test/Makefile.am
... ... @@ -29,6 +29,14 @@ if WITH_INST_LAT
29 29 test_LAT_CPPFLAGS = @CPPFLAGS@
30 30 test_LAT_LDADD = $(top_srcdir)/src/libgamma.la
31 31 endif
  32 +if WITH_INST_COM
  33 + INST_COM = test_COM
  34 + INCL_COM = -I$(top_srcdir)/inst/com/include
  35 + test_COM_SOURCES = $(top_srcdir)/inst/com/test/test_COM.cpp
  36 + test_COM_LDFLAGS = @LDFLAGS@
  37 + test_COM_CPPFLAGS = @CPPFLAGS@
  38 + test_COM_LDADD = $(top_srcdir)/src/libgamma.la
  39 +endif
32 40  
33 41 # Optional python bindings
34 42 if WITH_PYTHON
... ... @@ -46,7 +54,8 @@ INCLUDES = -I$(top_srcdir)/include \
46 54 -I$(top_srcdir)/src/support \
47 55 $(INCL_MWL) \
48 56 $(INCL_CTA) \
49   - $(INCL_LAT)
  57 + $(INCL_LAT) \
  58 + $(INCL_COM)
50 59  
51 60 # Test programs (those will be compiled)
52 61 check_PROGRAMS = test_GSupport \
... ... @@ -60,7 +69,10 @@ check_PROGRAMS = test_GSupport \
60 69 test_GApplication \
61 70 test_GModel \
62 71 test_GSky \
63   - $(INST_MWL) $(INST_CTA) $(INST_LAT)
  72 + $(INST_MWL) \
  73 + $(INST_CTA) \
  74 + $(INST_LAT) \
  75 + $(INST_COM)
64 76  
65 77 # Set test environment (needed for linking with cfitsio and readline)
66 78 TESTS_ENVIRONMENT = @RUNSHARED@=$(top_builddir)/src/.libs$(TEST_ENV_DIR):$(@RUNSHARED@) \
... ...