Commit 2e2127d2605ffee254f85921a7204849d3a7f87a
1 parent
931b9a7b
Changed logic of GCaldb class.
Now, GCaldb only reads the CALDB environment variable when needed. This allows changing the CALDB environment variable during runtime. Rename GCaldb::dir to GCaldb::rootdir.
Showing
8 changed files
with
281 additions
and
316 deletions
ChangeLog
| 1 | -2014-01-29 Juergen Knoedlseder <jurgen.knodlseder@irap.omp.eu> | |
| 1 | +2014-01-31 Juergen Knoedlseder <jurgen.knodlseder@irap.omp.eu> | |
| 2 | 2 | |
| 3 | 3 | * Bug fix Version 0.8.1 released |
| 4 | 4 | ================================ |
| ... | ... | @@ -10,6 +10,7 @@ |
| 10 | 10 | GAMMALIB_CALDB takes precedence over CALDB environment variable (#1094) |
| 11 | 11 | Added vo module and GVOClient class to Python interface |
| 12 | 12 | Track results of Python unit tests (#1119) |
| 13 | + Clean-up calibration database interface (#1102) | |
| 13 | 14 | |
| 14 | 15 | |
| 15 | 16 | 2014-01-18 Juergen Knoedlseder <jurgen.knodlseder@irap.omp.eu> | ... | ... |
NEWS
| ... | ... | @@ -2,7 +2,7 @@ New Features and Important Changes in GammaLib 00-08-01 |
| 2 | 2 | |
| 3 | 3 | Author(s) : Juergen Knoedlseder |
| 4 | 4 | |
| 5 | -29 January 2014 | |
| 5 | +31 January 2014 | |
| 6 | 6 | |
| 7 | 7 | |
| 8 | 8 | 1. Introduction |
| ... | ... | @@ -13,7 +13,8 @@ changes made since the last release of GammaLib. |
| 13 | 13 | |
| 14 | 14 | 2. Public interface modifications |
| 15 | 15 | --------------------------------- |
| 16 | -None | |
| 16 | +GCaldb | |
| 17 | + Changed dir() method to rootdir(). | |
| 17 | 18 | |
| 18 | 19 | |
| 19 | 20 | 3. Configuration |
| ... | ... | @@ -66,6 +67,10 @@ The GAMMALIB_CALDB environment variable takes precedence over the CALDB |
| 66 | 67 | environment variable. This was the initial intention, but the code did the |
| 67 | 68 | opposite. |
| 68 | 69 | |
| 70 | +The calibration database interface implemented by GCaldb has been cleaned | |
| 71 | +up. Now the CIF file is used to retrieve the filename to calibration files, | |
| 72 | +providing full CALDB compliant support in GammaLib. | |
| 73 | + | |
| 69 | 74 | |
| 70 | 75 | 11. Optimization module |
| 71 | 76 | ----------------------- | ... | ... |
include/GCaldb.hpp
| ... | ... | @@ -37,33 +37,26 @@ |
| 37 | 37 | /***********************************************************************//** |
| 38 | 38 | * @class GCaldb |
| 39 | 39 | * |
| 40 | - * @brief Interface for the Calibration database class | |
| 40 | + * @brief Calibration database class | |
| 41 | 41 | * |
| 42 | - * This class holds the definition of a calibration database. If the void | |
| 43 | - * constructor is invoked it tries setting the calibration database access | |
| 44 | - * path using the GAMMALIB_CALDB or CALDB environment variables (the former | |
| 45 | - * takes precedence over the latter). Alternatively, the calibration database | |
| 46 | - * path can be passed to the constructor to override the environment variable | |
| 47 | - * or set using the dir() method. | |
| 42 | + * This class holds the definition of a calibration database. The | |
| 43 | + * calibration database is located in a root directory that can be set using | |
| 44 | + * the GCaldb::rootdir method. If no root directory is set, GCaldb will take | |
| 45 | + * the directory path from the CALDB environment variable, which is mandatory | |
| 46 | + * in case that no root directory has been set. | |
| 48 | 47 | * |
| 49 | 48 | * It is assumed that the calibration data are found under |
| 50 | 49 | * |
| 51 | 50 | * $CALDB/data/<mission>[/<instrument>] |
| 52 | 51 | * |
| 53 | - * or | |
| 54 | - * | |
| 55 | - * $GAMMALIB_CALDB/data/<mission>[/<instrument>] | |
| 56 | - * | |
| 57 | 52 | * and that the Calibration Index File (CIF) is located at |
| 58 | 53 | * |
| 59 | 54 | * $CALDB/data/<mission>[/<instrument>]/caldb.indx |
| 60 | 55 | * |
| 61 | - * or | |
| 62 | - * | |
| 63 | - * $GAMMALIB_CALDB/data/<mission>[/<instrument>]/caldb.indx | |
| 64 | - * | |
| 65 | 56 | * where \<mission\> is the name of the mission and \<instrument\> is the |
| 66 | - * optional instrument name (all lower case). | |
| 57 | + * optional instrument name (all lower case). If the root directory has been | |
| 58 | + * set using the GCaldb::rootdir method, $CALDB is replaced by the root | |
| 59 | + * directory name. | |
| 67 | 60 | * |
| 68 | 61 | * The calibration database for a given mission and instrument is opened |
| 69 | 62 | * using the open() method. Once opened, database information can be |
| ... | ... | @@ -80,37 +73,37 @@ public: |
| 80 | 73 | virtual ~GCaldb(void); |
| 81 | 74 | |
| 82 | 75 | // Operators |
| 83 | - GCaldb& operator= (const GCaldb& caldb); | |
| 76 | + GCaldb& operator=(const GCaldb& caldb); | |
| 84 | 77 | |
| 85 | 78 | // Methods |
| 86 | - void clear(void); | |
| 87 | - GCaldb* clone(void) const; | |
| 88 | - int size(void) const; | |
| 89 | - const std::string& dir(void) const; | |
| 90 | - void dir(const std::string& pathname); | |
| 91 | - void open(const std::string& mission, | |
| 92 | - const std::string& instrument = ""); | |
| 93 | - void close(void); | |
| 94 | - std::string filename(const std::string& detector, | |
| 95 | - const std::string& filter, | |
| 96 | - const std::string& codename, | |
| 97 | - const std::string& date, | |
| 98 | - const std::string& time, | |
| 99 | - const std::string& expr); | |
| 100 | - std::string print(const GChatter& chatter = NORMAL) const; | |
| 79 | + void clear(void); | |
| 80 | + GCaldb* clone(void) const; | |
| 81 | + int size(void) const; | |
| 82 | + std::string rootdir(void) const; | |
| 83 | + void rootdir(const std::string& pathname); | |
| 84 | + std::string path(const std::string& mission, | |
| 85 | + const std::string& instrument = ""); | |
| 86 | + std::string cifname(const std::string& mission, | |
| 87 | + const std::string& instrument = ""); | |
| 88 | + void open(const std::string& mission, | |
| 89 | + const std::string& instrument = ""); | |
| 90 | + void close(void); | |
| 91 | + std::string filename(const std::string& detector, | |
| 92 | + const std::string& filter, | |
| 93 | + const std::string& codename, | |
| 94 | + const std::string& date, | |
| 95 | + const std::string& time, | |
| 96 | + const std::string& expr); | |
| 97 | + std::string print(const GChatter& chatter = NORMAL) const; | |
| 101 | 98 | |
| 102 | 99 | protected: |
| 103 | 100 | // Protected methods |
| 104 | - void init_members(void); | |
| 105 | - void copy_members(const GCaldb& caldb); | |
| 106 | - void free_members(void); | |
| 107 | - std::string rootdir(void) const; | |
| 108 | - void set_database(const std::string& pathname); | |
| 109 | - std::string path(const std::string& mission, const std::string& instrument = ""); | |
| 110 | - std::string cifname(const std::string& mission, const std::string& instrument = ""); | |
| 101 | + void init_members(void); | |
| 102 | + void copy_members(const GCaldb& caldb); | |
| 103 | + void free_members(void); | |
| 111 | 104 | |
| 112 | 105 | // Protected data area |
| 113 | - std::string m_caldb; //!< CALDB root directory | |
| 106 | + std::string m_opt_rootdir; //!< Optional root directory | |
| 114 | 107 | std::string m_mission; //!< Mission of opened database |
| 115 | 108 | std::string m_instrument; //!< Instrument of opened database |
| 116 | 109 | std::string m_cifname; //!< CIF filename of opened database |
| ... | ... | @@ -118,16 +111,4 @@ protected: |
| 118 | 111 | GFitsTable* m_cif; //!< Pointer to CIF table |
| 119 | 112 | }; |
| 120 | 113 | |
| 121 | - | |
| 122 | -/***********************************************************************//** | |
| 123 | - * @brief Return calibration directory | |
| 124 | - * | |
| 125 | - * @return Calibration directory. | |
| 126 | - ***************************************************************************/ | |
| 127 | -inline | |
| 128 | -const std::string& GCaldb::dir(void) const | |
| 129 | -{ | |
| 130 | - return m_caldb; | |
| 131 | -} | |
| 132 | - | |
| 133 | 114 | #endif /* GCALDB_HPP */ | ... | ... |
inst/com/src/GCOMResponse.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GCOMResponse.cpp - COMPTEL Response class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2012-2013 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2012-2014 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -384,7 +384,7 @@ void GCOMResponse::caldb(const std::string& caldb) |
| 384 | 384 | GCaldb db(caldb); |
| 385 | 385 | |
| 386 | 386 | // Store the path to the calibration database |
| 387 | - m_caldb = db.dir(); | |
| 387 | + m_caldb = db.rootdir(); | |
| 388 | 388 | |
| 389 | 389 | // Return |
| 390 | 390 | return; | ... | ... |
inst/cta/src/GCTAResponse.cpp
| ... | ... | @@ -535,13 +535,13 @@ void GCTAResponse::load(const std::string& rspname) |
| 535 | 535 | // If filenames are empty then build filenames from CALDB root path and |
| 536 | 536 | // response name |
| 537 | 537 | if (aeffname.length() < 1) { |
| 538 | - aeffname = irf_filename(m_caldb.dir() + "/" + rspname); | |
| 538 | + aeffname = irf_filename(gammalib::filepath(m_caldb.rootdir(), rspname)); | |
| 539 | 539 | } |
| 540 | 540 | if (psfname.length() < 1) { |
| 541 | - psfname = irf_filename(m_caldb.dir() + "/" + rspname); | |
| 541 | + psfname = irf_filename(gammalib::filepath(m_caldb.rootdir(), rspname)); | |
| 542 | 542 | } |
| 543 | 543 | if (edispname.length() < 1) { |
| 544 | - edispname = irf_filename(m_caldb.dir() + "/" + rspname); | |
| 544 | + edispname = irf_filename(gammalib::filepath(m_caldb.rootdir(), rspname)); | |
| 545 | 545 | } |
| 546 | 546 | |
| 547 | 547 | // Load effective area | ... | ... |
inst/lat/src/GLATResponse.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GLATResponse.cpp - Fermi/LAT response class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2008-2013 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2008-2014 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -210,7 +210,7 @@ void GLATResponse::caldb(const std::string& caldb) |
| 210 | 210 | GCaldb db(caldb); |
| 211 | 211 | |
| 212 | 212 | // Store the path to the calibration database |
| 213 | - m_caldb = db.dir(); | |
| 213 | + m_caldb = db.rootdir(); | |
| 214 | 214 | |
| 215 | 215 | // Return |
| 216 | 216 | return; | ... | ... |
pyext/GCaldb.i
| ... | ... | @@ -44,20 +44,24 @@ public: |
| 44 | 44 | virtual ~GCaldb(void); |
| 45 | 45 | |
| 46 | 46 | // Methods |
| 47 | - void clear(void); | |
| 48 | - GCaldb* clone(void) const; | |
| 49 | - int size(void) const; | |
| 50 | - const std::string& dir(void) const; | |
| 51 | - void dir(const std::string& pathname); | |
| 52 | - void open(const std::string& mission, | |
| 53 | - const std::string& instrument = ""); | |
| 54 | - void close(void); | |
| 55 | - std::string filename(const std::string& detector, | |
| 56 | - const std::string& filter, | |
| 57 | - const std::string& codename, | |
| 58 | - const std::string& date, | |
| 59 | - const std::string& time, | |
| 60 | - const std::string& expr); | |
| 47 | + void clear(void); | |
| 48 | + GCaldb* clone(void) const; | |
| 49 | + int size(void) const; | |
| 50 | + std::string rootdir(void) const; | |
| 51 | + void rootdir(const std::string& pathname); | |
| 52 | + std::string path(const std::string& mission, | |
| 53 | + const std::string& instrument = ""); | |
| 54 | + std::string cifname(const std::string& mission, | |
| 55 | + const std::string& instrument = ""); | |
| 56 | + void open(const std::string& mission, | |
| 57 | + const std::string& instrument = ""); | |
| 58 | + void close(void); | |
| 59 | + std::string filename(const std::string& detector, | |
| 60 | + const std::string& filter, | |
| 61 | + const std::string& codename, | |
| 62 | + const std::string& date, | |
| 63 | + const std::string& time, | |
| 64 | + const std::string& expr); | |
| 61 | 65 | }; |
| 62 | 66 | |
| 63 | 67 | ... | ... |
src/obs/GCaldb.cpp
| ... | ... | @@ -20,7 +20,7 @@ |
| 20 | 20 | ***************************************************************************/ |
| 21 | 21 | /** |
| 22 | 22 | * @file GCaldb.cpp |
| 23 | - * @brief Calibration database class implementation. | |
| 23 | + * @brief Calibration database class implementation | |
| 24 | 24 | * @author Juergen Knoedlseder |
| 25 | 25 | */ |
| 26 | 26 | |
| ... | ... | @@ -35,10 +35,8 @@ |
| 35 | 35 | #include "GCaldb.hpp" |
| 36 | 36 | |
| 37 | 37 | /* __ Method name definitions ____________________________________________ */ |
| 38 | -#define G_CALDB1 "GCaldb()" | |
| 39 | -#define G_CALDB2 "GCaldb(std::string)" | |
| 40 | -#define G_ROOTDIR "GCaldb::rootdir()" | |
| 41 | -#define G_SET_DATABASE "GCaldb::set_database(std::string)" | |
| 38 | +#define G_GET_ROOTDIR "GCaldb::rootdir()" | |
| 39 | +#define G_SET_ROOTDIR "GCaldb::rootdir(std::string&)" | |
| 42 | 40 | #define G_PATH "GCaldb::path(std::string, std::string)" |
| 43 | 41 | #define G_CIF "GCaldb::cif(std::string, std::string)" |
| 44 | 42 | |
| ... | ... | @@ -59,17 +57,13 @@ |
| 59 | 57 | /***********************************************************************//** |
| 60 | 58 | * @brief Void constructor |
| 61 | 59 | * |
| 62 | - * The void constructor determines the calibration database root directory | |
| 63 | - * from the GAMMALIB_CALDB or CALDB environment variables. | |
| 60 | + * Creates void instance of a calibration database. | |
| 64 | 61 | ***************************************************************************/ |
| 65 | 62 | GCaldb::GCaldb(void) |
| 66 | 63 | { |
| 67 | 64 | // Initialise class members |
| 68 | 65 | init_members(); |
| 69 | 66 | |
| 70 | - // Set calibration database root directory | |
| 71 | - set_database(rootdir()); | |
| 72 | - | |
| 73 | 67 | // Return |
| 74 | 68 | return; |
| 75 | 69 | } |
| ... | ... | @@ -100,15 +94,7 @@ GCaldb::GCaldb(const GCaldb& caldb) |
| 100 | 94 | * |
| 101 | 95 | * This constructor sets the calibration database using the specified root |
| 102 | 96 | * directory. Unless the specified pathname is not empty, any existing CALDB |
| 103 | - * or GAMMALIB_CALDB environment variables will be ignored. | |
| 104 | - * | |
| 105 | - * If the pathname is empty, however, the constructor attempts to detemine | |
| 106 | - * the CALDB root directory from the GAMMALIB_CALDB environment variable. If | |
| 107 | - * GAMMALIB_CALDB is not found, the method will check for the CALDB | |
| 108 | - * environment variable. If this fails, the constructor will throw an | |
| 109 | - * exception. | |
| 110 | - * | |
| 111 | - * Any environment variable contained in the pathname will be expanded. | |
| 97 | + * environment variables will be ignored. | |
| 112 | 98 | ***************************************************************************/ |
| 113 | 99 | GCaldb::GCaldb(const std::string& pathname) |
| 114 | 100 | { |
| ... | ... | @@ -117,13 +103,7 @@ GCaldb::GCaldb(const std::string& pathname) |
| 117 | 103 | |
| 118 | 104 | // If pathname is not empty then use it as root pathname |
| 119 | 105 | if (pathname.length() > 0) { |
| 120 | - set_database(gammalib::expand_env(pathname)); | |
| 121 | - } | |
| 122 | - | |
| 123 | - // ... otherwise try to determine root pathname from GAMMALIB_CALDB | |
| 124 | - // or CALDB environment variables. | |
| 125 | - else { | |
| 126 | - set_database(rootdir()); | |
| 106 | + rootdir(gammalib::expand_env(pathname)); | |
| 127 | 107 | } |
| 128 | 108 | |
| 129 | 109 | // Return |
| ... | ... | @@ -149,9 +129,6 @@ GCaldb::GCaldb(const std::string& mission, const std::string& instrument) |
| 149 | 129 | // Initialise members |
| 150 | 130 | init_members(); |
| 151 | 131 | |
| 152 | - // Set calibration database root directory | |
| 153 | - set_database(rootdir()); | |
| 154 | - | |
| 155 | 132 | // Open database |
| 156 | 133 | open(mission, instrument); |
| 157 | 134 | |
| ... | ... | @@ -263,21 +240,98 @@ int GCaldb::size(void) const |
| 263 | 240 | |
| 264 | 241 | |
| 265 | 242 | /***********************************************************************//** |
| 243 | + * @brief Return path to CALDB root directory | |
| 244 | + * | |
| 245 | + * @exception GException::directory_not_found | |
| 246 | + * Calibration directory not found. | |
| 247 | + * @exception GException::directory_not_accessible | |
| 248 | + * No read permission granted to calibration directory. | |
| 249 | + * | |
| 250 | + * The calibration directory path is given by one of the following | |
| 251 | + * | |
| 252 | + * $CALDB/data/<mission> | |
| 253 | + * $CALDB/data/<mission>/<instrument> | |
| 254 | + * $GAMMALIB_CALDB/data/<mission> | |
| 255 | + * $GAMMALIB_CALDB/data/<mission>/<instrument> | |
| 256 | + * | |
| 257 | + * where \<mission\> is the name of the mission and \<instrument\> is the | |
| 258 | + * optional instrument name (all lower case). The arguments provided to the | |
| 259 | + * method are transformed to lower case. | |
| 260 | + ***************************************************************************/ | |
| 261 | +std::string GCaldb::rootdir(void) const | |
| 262 | +{ | |
| 263 | + // Initialise root directory to optional root directory name | |
| 264 | + std::string rootdir = m_opt_rootdir; | |
| 265 | + | |
| 266 | + // If root directory is empty then get the directory name from the | |
| 267 | + // CALDB environment variable. Throw an exception if the environment | |
| 268 | + // variable has not been set | |
| 269 | + if (rootdir.empty()) { | |
| 270 | + | |
| 271 | + // Get root directory from GAMMALIB_CALDB and CALDB environment variables | |
| 272 | + char* ptr1 = std::getenv("GAMMALIB_CALDB"); | |
| 273 | + char* ptr2 = std::getenv("CALDB"); | |
| 274 | + | |
| 275 | + // Throw an exception if non of the environment variables was set | |
| 276 | + if (ptr1 == NULL && ptr2 == NULL) { | |
| 277 | + throw GException::env_not_found(G_GET_ROOTDIR, | |
| 278 | + "GAMMALIB_CALDB or CALDB", | |
| 279 | + "Please set the GAMMALIB_CALDB or the CALDB environment" | |
| 280 | + " variable to a valid calibration database root directory."); | |
| 281 | + } | |
| 282 | + | |
| 283 | + // If GAMMALIB_CALDB was set then check whether the directory exists | |
| 284 | + if (ptr1 != NULL) { | |
| 285 | + if (access(ptr1, F_OK) == 0) { | |
| 286 | + rootdir = std::string(ptr1); | |
| 287 | + } | |
| 288 | + } | |
| 289 | + | |
| 290 | + // ... otherwise, if CALDB was set then check whether the directory | |
| 291 | + // exists | |
| 292 | + else if (ptr2 != NULL) { | |
| 293 | + if (access(ptr2, F_OK) == 0) { | |
| 294 | + rootdir = std::string(ptr2); | |
| 295 | + } | |
| 296 | + } | |
| 297 | + | |
| 298 | + } // endif: no optional root directory has been set | |
| 299 | + | |
| 300 | + // Return root directory | |
| 301 | + return rootdir; | |
| 302 | +} | |
| 303 | + | |
| 304 | + | |
| 305 | +/***********************************************************************//** | |
| 266 | 306 | * @brief Set calibration database root directory |
| 267 | 307 | * |
| 268 | 308 | * @param[in] pathname Calibration database root directory. |
| 269 | 309 | * |
| 270 | - * Set a new root directory for the calibration database. Any previously | |
| 271 | - * opened database will be closed. | |
| 272 | - * Any environment variable present in the pathname will be expanded. | |
| 310 | + * @exception GException::directory_not_found | |
| 311 | + * Calibration database root directory not found. | |
| 312 | + * @exception GException::directory_not_accessible | |
| 313 | + * No read permission granted for calibration database root | |
| 314 | + * directory. | |
| 315 | + * | |
| 316 | + * Sets the calibration database root directory to a specific path. The | |
| 317 | + * method verifies the existence of the root directory prior to setting. | |
| 273 | 318 | ***************************************************************************/ |
| 274 | -void GCaldb::dir(const std::string& pathname) | |
| 319 | +void GCaldb::rootdir(const std::string& pathname) | |
| 275 | 320 | { |
| 276 | - // Clear any existing database | |
| 277 | - clear(); | |
| 321 | + // Verify that specified root directory exists | |
| 322 | + //if (access(pathname.c_str(), F_OK) != 0) { | |
| 323 | + if (!gammalib::dir_exists(pathname)) { | |
| 324 | + throw GException::directory_not_found(G_SET_ROOTDIR, pathname); | |
| 325 | + } | |
| 326 | + | |
| 327 | + // Verify that specified root directory allows read access | |
| 328 | + if (access(pathname.c_str(), R_OK) != 0) { | |
| 329 | + throw GException::directory_not_accessible(G_SET_ROOTDIR, pathname, | |
| 330 | + "Requested read permission not granted."); | |
| 331 | + } | |
| 278 | 332 | |
| 279 | - // Set calibration database | |
| 280 | - set_database(gammalib::expand_env(pathname)); | |
| 333 | + // Set calibration database root directory | |
| 334 | + m_opt_rootdir = gammalib::expand_env(pathname); | |
| 281 | 335 | |
| 282 | 336 | // Return |
| 283 | 337 | return; |
| ... | ... | @@ -285,6 +339,112 @@ void GCaldb::dir(const std::string& pathname) |
| 285 | 339 | |
| 286 | 340 | |
| 287 | 341 | /***********************************************************************//** |
| 342 | + * @brief Return path to calibration directory | |
| 343 | + * | |
| 344 | + * @param[in] mission Mission name (case insensitive). | |
| 345 | + * @param[in] instrument Instrument name (case insensitive; optional). | |
| 346 | + * | |
| 347 | + * @exception GException::directory_not_found | |
| 348 | + * Calibration directory not found. | |
| 349 | + * @exception GException::directory_not_accessible | |
| 350 | + * No read permission granted to calibration directory. | |
| 351 | + * | |
| 352 | + * The calibration directory path is given by one of the following | |
| 353 | + * | |
| 354 | + * $CALDB/data/<mission> | |
| 355 | + * $CALDB/data/<mission>/<instrument> | |
| 356 | + * $GAMMALIB_CALDB/data/<mission> | |
| 357 | + * $GAMMALIB_CALDB/data/<mission>/<instrument> | |
| 358 | + * | |
| 359 | + * where \<mission\> is the name of the mission and \<instrument\> is the | |
| 360 | + * optional instrument name (all lower case). The arguments provided to the | |
| 361 | + * method are transformed to lower case. | |
| 362 | + ***************************************************************************/ | |
| 363 | +std::string GCaldb::path(const std::string& mission, const std::string& instrument) | |
| 364 | +{ | |
| 365 | + // Verify that mission name is valid and directory is accessible | |
| 366 | + std::string path = rootdir() + "/data/" + gammalib::tolower(mission); | |
| 367 | +// if (access(path.c_str(), F_OK) != 0) { | |
| 368 | + if (!gammalib::dir_exists(path)) { | |
| 369 | + throw GException::directory_not_found(G_PATH, path, | |
| 370 | + "Requested mission \""+gammalib::toupper(mission)+"\" not found in" | |
| 371 | + " calibration database."); | |
| 372 | + } | |
| 373 | + if (access(path.c_str(), R_OK) != 0) { | |
| 374 | + throw GException::directory_not_accessible(G_PATH, path, | |
| 375 | + "Requested read permission not granted for mission \""+ | |
| 376 | + gammalib::toupper(mission)+"\"."); | |
| 377 | + } | |
| 378 | + | |
| 379 | + // If an instrument has been specified, verify that instrument name is | |
| 380 | + // valid and directory is accessible | |
| 381 | + if (instrument.length() > 0) { | |
| 382 | + | |
| 383 | + // Add instrument to path | |
| 384 | + path += "/" + gammalib::tolower(instrument); | |
| 385 | + | |
| 386 | + // Verify path | |
| 387 | + //if (access(path.c_str(), F_OK) != 0) { | |
| 388 | + if (!gammalib::dir_exists(path)) { | |
| 389 | + throw GException::directory_not_found(G_PATH, path, | |
| 390 | + "Requested instrument \""+gammalib::toupper(instrument)+"\" on" | |
| 391 | + " mission \""+gammalib::toupper(mission)+"\" not found in" | |
| 392 | + " calibration database."); | |
| 393 | + } | |
| 394 | + if (access(path.c_str(), R_OK) != 0) { | |
| 395 | + throw GException::directory_not_accessible(G_PATH, path, | |
| 396 | + "Requested read permission not granted for instrument \""+ | |
| 397 | + gammalib::toupper(instrument)+"\" on mission \""+gammalib::toupper(mission)+ | |
| 398 | + "\"."); | |
| 399 | + } | |
| 400 | + | |
| 401 | + } // endif: instrument has been specified | |
| 402 | + | |
| 403 | + // Return path | |
| 404 | + return path; | |
| 405 | +} | |
| 406 | + | |
| 407 | + | |
| 408 | +/***********************************************************************//** | |
| 409 | + * @brief Return absolute CIF filename | |
| 410 | + * | |
| 411 | + * @param[in] mission Mission name (case insensitive). | |
| 412 | + * @param[in] instrument Instrument name (case insensitive; optional). | |
| 413 | + * | |
| 414 | + * @exception GException::file_not_found | |
| 415 | + * CIF not found. | |
| 416 | + * | |
| 417 | + * The calibration directory path is given by one of the following | |
| 418 | + * | |
| 419 | + * $CALDB/data/<mission>/caldb.indx | |
| 420 | + * $CALDB/data/<mission>/<instrument>/caldb.indx | |
| 421 | + * $GAMMALIB_CALDB/data/<mission>/caldb.indx | |
| 422 | + * $GAMMALIB_CALDB/data/<mission>/<instrument>/caldb.indx | |
| 423 | + * | |
| 424 | + * where \<mission\> is the name of the mission and \<instrument\> is the | |
| 425 | + * optional instrument name (all lower case). The arguments provided to the | |
| 426 | + * method are transformed to lower case. | |
| 427 | + ***************************************************************************/ | |
| 428 | +std::string GCaldb::cifname(const std::string& mission, const std::string& instrument) | |
| 429 | +{ | |
| 430 | + // Get path to calibration directory | |
| 431 | + std::string cif = path(mission, instrument); | |
| 432 | + | |
| 433 | + // Add calibration index filename | |
| 434 | + cif += "/caldb.indx"; | |
| 435 | + | |
| 436 | + // Verify that CIF exists | |
| 437 | + if (access(cif.c_str(), F_OK) != 0) { | |
| 438 | + throw GException::file_not_found(G_CIF, cif, | |
| 439 | + "Calibration Index File (CIF) not found."); | |
| 440 | + } | |
| 441 | + | |
| 442 | + // Return cif | |
| 443 | + return cif; | |
| 444 | +} | |
| 445 | + | |
| 446 | + | |
| 447 | +/***********************************************************************//** | |
| 288 | 448 | * @brief Open calibration database |
| 289 | 449 | * |
| 290 | 450 | * @param[in] mission Mission name (case insensitive). |
| ... | ... | @@ -465,9 +625,16 @@ std::string GCaldb::filename(const std::string& detector, |
| 465 | 625 | match_date && match_time && match_expr) { |
| 466 | 626 | const GFitsTableCol* cal_dir = (*m_cif)["CAL_DIR"]; |
| 467 | 627 | const GFitsTableCol* cal_file = (*m_cif)["CAL_FILE"]; |
| 468 | - filename = m_caldb + "/" + | |
| 469 | - cal_dir->string(i) + "/" + | |
| 470 | - cal_file->string(i); | |
| 628 | + std::string path = rootdir(); | |
| 629 | + if (path.empty()) { | |
| 630 | + filename = cal_dir->string(i) + "/" + | |
| 631 | + cal_file->string(i); | |
| 632 | + } | |
| 633 | + else { | |
| 634 | + filename = path + "/" + | |
| 635 | + cal_dir->string(i) + "/" + | |
| 636 | + cal_file->string(i); | |
| 637 | + } | |
| 471 | 638 | break; |
| 472 | 639 | } |
| 473 | 640 | |
| ... | ... | @@ -498,7 +665,7 @@ std::string GCaldb::print(const GChatter& chatter) const |
| 498 | 665 | result.append("=== GCaldb ==="); |
| 499 | 666 | |
| 500 | 667 | // Append information |
| 501 | - result.append("\n"+gammalib::parformat("Database root")+m_caldb); | |
| 668 | + result.append("\n"+gammalib::parformat("Database root")+rootdir()); | |
| 502 | 669 | |
| 503 | 670 | // Append information about opened database |
| 504 | 671 | if (m_cif != NULL) { |
| ... | ... | @@ -531,7 +698,7 @@ std::string GCaldb::print(const GChatter& chatter) const |
| 531 | 698 | void GCaldb::init_members(void) |
| 532 | 699 | { |
| 533 | 700 | // Initialise members |
| 534 | - m_caldb.clear(); | |
| 701 | + m_opt_rootdir.clear(); | |
| 535 | 702 | m_mission.clear(); |
| 536 | 703 | m_instrument.clear(); |
| 537 | 704 | m_cifname.clear(); |
| ... | ... | @@ -551,11 +718,11 @@ void GCaldb::init_members(void) |
| 551 | 718 | void GCaldb::copy_members(const GCaldb& caldb) |
| 552 | 719 | { |
| 553 | 720 | // Copy attributes |
| 554 | - m_caldb = caldb.m_caldb; | |
| 555 | - m_mission = caldb.m_mission; | |
| 556 | - m_instrument = caldb.m_instrument; | |
| 557 | - m_cifname = caldb.m_cifname; | |
| 558 | - m_fits = caldb.m_fits; | |
| 721 | + m_opt_rootdir = caldb.m_opt_rootdir; | |
| 722 | + m_mission = caldb.m_mission; | |
| 723 | + m_instrument = caldb.m_instrument; | |
| 724 | + m_cifname = caldb.m_cifname; | |
| 725 | + m_fits = caldb.m_fits; | |
| 559 | 726 | |
| 560 | 727 | // Set CIF table pointer. We do not copy over the pointer as the FITS |
| 561 | 728 | // file has been copied here. |
| ... | ... | @@ -584,196 +751,3 @@ void GCaldb::free_members(void) |
| 584 | 751 | } |
| 585 | 752 | |
| 586 | 753 | |
| 587 | -/***********************************************************************//** | |
| 588 | - * @brief Return path to CALDB root directory | |
| 589 | - * | |
| 590 | - * @exception GException::directory_not_found | |
| 591 | - * Calibration directory not found. | |
| 592 | - * @exception GException::directory_not_accessible | |
| 593 | - * No read permission granted to calibration directory. | |
| 594 | - * | |
| 595 | - * The calibration directory path is given by one of the following | |
| 596 | - * | |
| 597 | - * $CALDB/data/<mission> | |
| 598 | - * $CALDB/data/<mission>/<instrument> | |
| 599 | - * $GAMMALIB_CALDB/data/<mission> | |
| 600 | - * $GAMMALIB_CALDB/data/<mission>/<instrument> | |
| 601 | - * | |
| 602 | - * where \<mission\> is the name of the mission and \<instrument\> is the | |
| 603 | - * optional instrument name (all lower case). The arguments provided to the | |
| 604 | - * method are transformed to lower case. | |
| 605 | - ***************************************************************************/ | |
| 606 | -std::string GCaldb::rootdir(void) const | |
| 607 | -{ | |
| 608 | - // Get root directory from GAMMALIB_CALDB and CALDB environment variables | |
| 609 | - char* ptr1 = std::getenv("GAMMALIB_CALDB"); | |
| 610 | - char* ptr2 = std::getenv("CALDB"); | |
| 611 | - | |
| 612 | - // Throw an exception if non of the environment variables was set | |
| 613 | - if (ptr1 == NULL && ptr2 == NULL) { | |
| 614 | - throw GException::env_not_found(G_ROOTDIR, | |
| 615 | - "GAMMALIB_CALDB or CALDB", | |
| 616 | - "Please set the GAMMALIB_CALDB or the CALDB environment" | |
| 617 | - " variable to a valid calibration database root directory."); | |
| 618 | - } | |
| 619 | - | |
| 620 | - // Initialise root directory string | |
| 621 | - std::string rootdir; | |
| 622 | - | |
| 623 | - // If GAMMALIB_CALDB was set then check whether the directory exists | |
| 624 | - if (ptr1 != NULL) { | |
| 625 | - if (access(ptr1, F_OK) == 0) { | |
| 626 | - rootdir = std::string(ptr1); | |
| 627 | - } | |
| 628 | - } | |
| 629 | - | |
| 630 | - // ... otherwise, if CALDB was set then check whether the directory | |
| 631 | - // exists | |
| 632 | - else if (ptr2 != NULL) { | |
| 633 | - if (access(ptr2, F_OK) == 0) { | |
| 634 | - rootdir = std::string(ptr2); | |
| 635 | - } | |
| 636 | - } | |
| 637 | - | |
| 638 | - // Return root directory | |
| 639 | - return rootdir; | |
| 640 | -} | |
| 641 | - | |
| 642 | - | |
| 643 | -/***********************************************************************//** | |
| 644 | - * @brief Set calibration database | |
| 645 | - * | |
| 646 | - * @param[in] pathname Calibration database root directory. | |
| 647 | - * | |
| 648 | - * @exception GException::directory_not_found | |
| 649 | - * Calibration database root directory not found. | |
| 650 | - * @exception GException::directory_not_accessible | |
| 651 | - * No read permission granted for calibration database root | |
| 652 | - * directory. | |
| 653 | - * | |
| 654 | - * Set calibration database to a specific root directory. The method verifies | |
| 655 | - * the existence of the root directory prior to setting. | |
| 656 | - ***************************************************************************/ | |
| 657 | -void GCaldb::set_database(const std::string& pathname) | |
| 658 | -{ | |
| 659 | - // Verify that specified root directory exists | |
| 660 | - if (access(pathname.c_str(), F_OK) != 0) { | |
| 661 | - throw GException::directory_not_found(G_SET_DATABASE, pathname); | |
| 662 | - } | |
| 663 | - | |
| 664 | - // Verify that specified root directory allows read access | |
| 665 | - if (access(pathname.c_str(), R_OK) != 0) { | |
| 666 | - throw GException::directory_not_accessible(G_SET_DATABASE, pathname, | |
| 667 | - "Requested read permission not granted."); | |
| 668 | - } | |
| 669 | - | |
| 670 | - // Set calibration database root directory | |
| 671 | - m_caldb = pathname; | |
| 672 | - | |
| 673 | - // Return | |
| 674 | - return; | |
| 675 | -} | |
| 676 | - | |
| 677 | - | |
| 678 | -/***********************************************************************//** | |
| 679 | - * @brief Return path to calibration directory | |
| 680 | - * | |
| 681 | - * @param[in] mission Mission name (case insensitive). | |
| 682 | - * @param[in] instrument Instrument name (case insensitive; optional). | |
| 683 | - * | |
| 684 | - * @exception GException::directory_not_found | |
| 685 | - * Calibration directory not found. | |
| 686 | - * @exception GException::directory_not_accessible | |
| 687 | - * No read permission granted to calibration directory. | |
| 688 | - * | |
| 689 | - * The calibration directory path is given by one of the following | |
| 690 | - * | |
| 691 | - * $CALDB/data/<mission> | |
| 692 | - * $CALDB/data/<mission>/<instrument> | |
| 693 | - * $GAMMALIB_CALDB/data/<mission> | |
| 694 | - * $GAMMALIB_CALDB/data/<mission>/<instrument> | |
| 695 | - * | |
| 696 | - * where \<mission\> is the name of the mission and \<instrument\> is the | |
| 697 | - * optional instrument name (all lower case). The arguments provided to the | |
| 698 | - * method are transformed to lower case. | |
| 699 | - ***************************************************************************/ | |
| 700 | -std::string GCaldb::path(const std::string& mission, const std::string& instrument) | |
| 701 | -{ | |
| 702 | - // Verify that mission name is valid and directory is accessible | |
| 703 | - std::string path = m_caldb + "/data/" + gammalib::tolower(mission); | |
| 704 | - if (access(path.c_str(), F_OK) != 0) { | |
| 705 | - throw GException::directory_not_found(G_PATH, path, | |
| 706 | - "Requested mission \""+gammalib::toupper(mission)+"\" not found in" | |
| 707 | - " calibration database."); | |
| 708 | - } | |
| 709 | - if (access(path.c_str(), R_OK) != 0) { | |
| 710 | - throw GException::directory_not_accessible(G_PATH, path, | |
| 711 | - "Requested read permission not granted for mission \""+ | |
| 712 | - gammalib::toupper(mission)+"\"."); | |
| 713 | - } | |
| 714 | - | |
| 715 | - // If an instrument has been specified, verify that instrument name is | |
| 716 | - // valid and directory is accessible | |
| 717 | - if (instrument.length() > 0) { | |
| 718 | - | |
| 719 | - // Add instrument to path | |
| 720 | - path += "/" + gammalib::tolower(instrument); | |
| 721 | - | |
| 722 | - // Verify path | |
| 723 | - if (access(path.c_str(), F_OK) != 0) { | |
| 724 | - throw GException::directory_not_found(G_PATH, path, | |
| 725 | - "Requested instrument \""+gammalib::toupper(instrument)+"\" on" | |
| 726 | - " mission \""+gammalib::toupper(mission)+"\" not found in" | |
| 727 | - " calibration database."); | |
| 728 | - } | |
| 729 | - if (access(path.c_str(), R_OK) != 0) { | |
| 730 | - throw GException::directory_not_accessible(G_PATH, path, | |
| 731 | - "Requested read permission not granted for instrument \""+ | |
| 732 | - gammalib::toupper(instrument)+"\" on mission \""+gammalib::toupper(mission)+ | |
| 733 | - "\"."); | |
| 734 | - } | |
| 735 | - | |
| 736 | - } // endif: instrument has been specified | |
| 737 | - | |
| 738 | - // Return path | |
| 739 | - return path; | |
| 740 | -} | |
| 741 | - | |
| 742 | - | |
| 743 | -/***********************************************************************//** | |
| 744 | - * @brief Return absolute CIF filename | |
| 745 | - * | |
| 746 | - * @param[in] mission Mission name (case insensitive). | |
| 747 | - * @param[in] instrument Instrument name (case insensitive; optional). | |
| 748 | - * | |
| 749 | - * @exception GException::file_not_found | |
| 750 | - * CIF not found. | |
| 751 | - * | |
| 752 | - * The calibration directory path is given by one of the following | |
| 753 | - * | |
| 754 | - * $CALDB/data/<mission>/caldb.indx | |
| 755 | - * $CALDB/data/<mission>/<instrument>/caldb.indx | |
| 756 | - * $GAMMALIB_CALDB/data/<mission>/caldb.indx | |
| 757 | - * $GAMMALIB_CALDB/data/<mission>/<instrument>/caldb.indx | |
| 758 | - * | |
| 759 | - * where \<mission\> is the name of the mission and \<instrument\> is the | |
| 760 | - * optional instrument name (all lower case). The arguments provided to the | |
| 761 | - * method are transformed to lower case. | |
| 762 | - ***************************************************************************/ | |
| 763 | -std::string GCaldb::cifname(const std::string& mission, const std::string& instrument) | |
| 764 | -{ | |
| 765 | - // Get path to calibration directory | |
| 766 | - std::string cif = path(mission, instrument); | |
| 767 | - | |
| 768 | - // Add calibration index filename | |
| 769 | - cif += "/caldb.indx"; | |
| 770 | - | |
| 771 | - // Verify that CIF exists | |
| 772 | - if (access(cif.c_str(), F_OK) != 0) { | |
| 773 | - throw GException::file_not_found(G_CIF, cif, | |
| 774 | - "Calibration Index File (CIF) not found."); | |
| 775 | - } | |
| 776 | - | |
| 777 | - // Return cif | |
| 778 | - return cif; | |
| 779 | -} | ... | ... |