From bac09f5e5d118e282f1ce1f1b0eedaa7224b6685 Mon Sep 17 00:00:00 2001 From: Jürgen Knödlseder Date: Fri, 7 Oct 2016 14:35:56 +0200 Subject: [PATCH] Add publish methods and parameters to tools/scripts that produce FITS tables --- doc/source/users/reference_manual/ctobssim.rst | 3 +++ pyext/ctobssim.i | 3 ++- src/ctobssim/ctobssim.cpp | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/ctobssim/ctobssim.hpp | 1 + src/ctobssim/ctobssim.par | 12 +----------- src/ctskymap/ctskymap.cpp | 2 +- test/test_ctobssim.py | 1 + 7 files changed, 70 insertions(+), 13 deletions(-) diff --git a/doc/source/users/reference_manual/ctobssim.rst b/doc/source/users/reference_manual/ctobssim.rst index 2c021d2..a08c48a 100644 --- a/doc/source/users/reference_manual/ctobssim.rst +++ b/doc/source/users/reference_manual/ctobssim.rst @@ -106,6 +106,9 @@ General parameters Standard parameters ------------------- +``(publish = no) [boolean]`` + Specifies whether the event list should be published on VO Hub. + ``(chatter = 2) [integer]`` Verbosity of the executable: chatter = 0: no information will be logged diff --git a/pyext/ctobssim.i b/pyext/ctobssim.i index 392f94b..f9d6d8e 100644 --- a/pyext/ctobssim.i +++ b/pyext/ctobssim.i @@ -1,7 +1,7 @@ /*************************************************************************** * ctobssim - Observation simulator tool * * ----------------------------------------------------------------------- * - * copyright (C) 2011-2015 by Juergen Knoedlseder * + * copyright (C) 2011-2016 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -47,6 +47,7 @@ public: void clear(void); void run(void); void save(void); + void publish(const std::string& name = ""); const double& max_rate(void) const; void max_rate(const double& max_rate); }; diff --git a/src/ctobssim/ctobssim.cpp b/src/ctobssim/ctobssim.cpp index 9de576f..2504c3b 100644 --- a/src/ctobssim/ctobssim.cpp +++ b/src/ctobssim/ctobssim.cpp @@ -32,6 +32,8 @@ #include #include "ctobssim.hpp" #include "GTools.hpp" +#include "GFits.hpp" + /* __ Method name definitions ____________________________________________ */ #define G_GET_PARAMETERS "ctobssim::get_parameters()" @@ -415,6 +417,11 @@ void ctobssim::run(void) // Restore energy dispersion flags of all CTA observations restore_edisp(m_obs, save_edisp); + // Optionally publish event list(s) + if ((*this)["publish"].boolean()) { + publish(); + } + // Return return; } @@ -459,6 +466,60 @@ void ctobssim::save(void) } +/***********************************************************************//** + * @brief Publish event lists + * + * @param[in] name Event list name. + ***************************************************************************/ +void ctobssim::publish(const std::string& name) +{ + // Write header into logger + log_header1(TERSE, gammalib::number("Publish event list", m_obs.size())); + + // Loop over all observation in the container + for (int i = 0; i < m_obs.size(); ++i) { + + // Get CTA observation + GCTAObservation* obs = dynamic_cast(m_obs[i]); + + // Handle only CTA observations + if (obs != NULL) { + + // Continue only if there is an event list + if (obs->events()->size() != 0) { + + // Set default name if user name is empty + std::string user_name(name); + if (user_name.empty()) { + user_name = CTOBSSIM_NAME; + } + + // If there are several event lists then add an index + if (m_use_xml) { + user_name += gammalib::str(i); + } + + // Write event list name into logger + log_value(NORMAL, "Event list name", user_name); + + // Write events into in-memory FITS file + GFits fits; + obs->write(fits); + + // Publish + fits.publish("EVENTS", user_name); + + } // endif: there were events + + } // endif: observation was a CTA observation + + } // endfor: looped over observations + + // Return + return; +} + + /*========================================================================== = = = Private methods = diff --git a/src/ctobssim/ctobssim.hpp b/src/ctobssim/ctobssim.hpp index 3721b6a..6156d11 100644 --- a/src/ctobssim/ctobssim.hpp +++ b/src/ctobssim/ctobssim.hpp @@ -65,6 +65,7 @@ public: void clear(void); void run(void); void save(void); + void publish(const std::string& name = ""); const double& max_rate(void) const; void max_rate(const double& max_rate); diff --git a/src/ctobssim/ctobssim.par b/src/ctobssim/ctobssim.par index f6bfb2e..6adc421 100644 --- a/src/ctobssim/ctobssim.par +++ b/src/ctobssim/ctobssim.par @@ -2,17 +2,6 @@ # # # CTA Science Analysis Tools # # # -# ------------------------------------------------------------------------- # -# # -# File: ctobssim.par # -# Version: 1.1.0 # -# # -# Author: Juergen Knoedlseder # -# Jurgen.Knodlseder@irap.omp.eu # -# IRAP # -# # -# Purpose: Parameter file for the ctobssim application # -# # ############################################################################# # # General parameters @@ -43,6 +32,7 @@ eslices, i, h, 10,1,100, "Number of energy slices" # # Standard parameters #==================== +publish, b, h, no,,, "Publish event list on VO Hub?" chatter, i, h, 2,0,4, "Chattiness of output" clobber, b, h, yes,,, "Overwrite existing output files with new output files?" debug, b, h, no,,, "Debugging mode activated" diff --git a/src/ctskymap/ctskymap.cpp b/src/ctskymap/ctskymap.cpp index dd6e959..a756c18 100644 --- a/src/ctskymap/ctskymap.cpp +++ b/src/ctskymap/ctskymap.cpp @@ -294,7 +294,7 @@ void ctskymap::publish(const std::string& name) // Write header into logger log_header1(TERSE, "Publish sky map"); - // Set default name is user name is empty + // Set default name if user name is empty std::string user_name(name); if (user_name.empty()) { user_name = CTSKYMAP_NAME; diff --git a/test/test_ctobssim.py b/test/test_ctobssim.py index c6e18db..0fa61ad 100755 --- a/test/test_ctobssim.py +++ b/test/test_ctobssim.py @@ -228,6 +228,7 @@ class Test(test): cpy_sim['outevents'] = 'ctobssim_py3.xml' cpy_sim['logfile'] = 'ctobssim_py3.log' cpy_sim['chatter'] = 4 + cpy_sim['publish'] = True cpy_sim.logFileOpen() # Needed to get a new log file cpy_sim.execute() -- libgit2 0.21.4