From 2e2127d2605ffee254f85921a7204849d3a7f87a Mon Sep 17 00:00:00 2001 From: Jürgen Knödlseder Date: Fri, 31 Jan 2014 10:26:35 +0100 Subject: [PATCH] Changed logic of GCaldb class. --- ChangeLog | 3 ++- NEWS | 9 +++++++-- include/GCaldb.hpp | 85 +++++++++++++++++++++++++++++++++---------------------------------------------------- inst/com/src/GCOMResponse.cpp | 4 ++-- inst/cta/src/GCTAResponse.cpp | 6 +++--- inst/lat/src/GLATResponse.cpp | 4 ++-- pyext/GCaldb.i | 32 ++++++++++++++++++-------------- src/obs/GCaldb.cpp | 454 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 8 files changed, 281 insertions(+), 316 deletions(-) diff --git a/ChangeLog b/ChangeLog index bf301b0..4aea96e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,4 @@ -2014-01-29 Juergen Knoedlseder +2014-01-31 Juergen Knoedlseder * Bug fix Version 0.8.1 released ================================ @@ -10,6 +10,7 @@ GAMMALIB_CALDB takes precedence over CALDB environment variable (#1094) Added vo module and GVOClient class to Python interface Track results of Python unit tests (#1119) + Clean-up calibration database interface (#1102) 2014-01-18 Juergen Knoedlseder diff --git a/NEWS b/NEWS index d3ac967..6694c2c 100644 --- a/NEWS +++ b/NEWS @@ -2,7 +2,7 @@ New Features and Important Changes in GammaLib 00-08-01 Author(s) : Juergen Knoedlseder -29 January 2014 +31 January 2014 1. Introduction @@ -13,7 +13,8 @@ changes made since the last release of GammaLib. 2. Public interface modifications --------------------------------- -None +GCaldb + Changed dir() method to rootdir(). 3. Configuration @@ -66,6 +67,10 @@ The GAMMALIB_CALDB environment variable takes precedence over the CALDB environment variable. This was the initial intention, but the code did the opposite. +The calibration database interface implemented by GCaldb has been cleaned +up. Now the CIF file is used to retrieve the filename to calibration files, +providing full CALDB compliant support in GammaLib. + 11. Optimization module ----------------------- diff --git a/include/GCaldb.hpp b/include/GCaldb.hpp index b62bac7..f136cfe 100644 --- a/include/GCaldb.hpp +++ b/include/GCaldb.hpp @@ -37,33 +37,26 @@ /***********************************************************************//** * @class GCaldb * - * @brief Interface for the Calibration database class + * @brief Calibration database class * - * This class holds the definition of a calibration database. If the void - * constructor is invoked it tries setting the calibration database access - * path using the GAMMALIB_CALDB or CALDB environment variables (the former - * takes precedence over the latter). Alternatively, the calibration database - * path can be passed to the constructor to override the environment variable - * or set using the dir() method. + * This class holds the definition of a calibration database. The + * calibration database is located in a root directory that can be set using + * the GCaldb::rootdir method. If no root directory is set, GCaldb will take + * the directory path from the CALDB environment variable, which is mandatory + * in case that no root directory has been set. * * It is assumed that the calibration data are found under * * $CALDB/data/[/] * - * or - * - * $GAMMALIB_CALDB/data/[/] - * * and that the Calibration Index File (CIF) is located at * * $CALDB/data/[/]/caldb.indx * - * or - * - * $GAMMALIB_CALDB/data/[/]/caldb.indx - * * where \ is the name of the mission and \ is the - * optional instrument name (all lower case). + * optional instrument name (all lower case). If the root directory has been + * set using the GCaldb::rootdir method, $CALDB is replaced by the root + * directory name. * * The calibration database for a given mission and instrument is opened * using the open() method. Once opened, database information can be @@ -80,37 +73,37 @@ public: virtual ~GCaldb(void); // Operators - GCaldb& operator= (const GCaldb& caldb); + GCaldb& operator=(const GCaldb& caldb); // Methods - void clear(void); - GCaldb* clone(void) const; - int size(void) const; - const std::string& dir(void) const; - void dir(const std::string& pathname); - void open(const std::string& mission, - const std::string& instrument = ""); - void close(void); - std::string filename(const std::string& detector, - const std::string& filter, - const std::string& codename, - const std::string& date, - const std::string& time, - const std::string& expr); - std::string print(const GChatter& chatter = NORMAL) const; + void clear(void); + GCaldb* clone(void) const; + int size(void) const; + std::string rootdir(void) const; + void rootdir(const std::string& pathname); + std::string path(const std::string& mission, + const std::string& instrument = ""); + std::string cifname(const std::string& mission, + const std::string& instrument = ""); + void open(const std::string& mission, + const std::string& instrument = ""); + void close(void); + std::string filename(const std::string& detector, + const std::string& filter, + const std::string& codename, + const std::string& date, + const std::string& time, + const std::string& expr); + std::string print(const GChatter& chatter = NORMAL) const; protected: // Protected methods - void init_members(void); - void copy_members(const GCaldb& caldb); - void free_members(void); - std::string rootdir(void) const; - void set_database(const std::string& pathname); - std::string path(const std::string& mission, const std::string& instrument = ""); - std::string cifname(const std::string& mission, const std::string& instrument = ""); + void init_members(void); + void copy_members(const GCaldb& caldb); + void free_members(void); // Protected data area - std::string m_caldb; //!< CALDB root directory + std::string m_opt_rootdir; //!< Optional root directory std::string m_mission; //!< Mission of opened database std::string m_instrument; //!< Instrument of opened database std::string m_cifname; //!< CIF filename of opened database @@ -118,16 +111,4 @@ protected: GFitsTable* m_cif; //!< Pointer to CIF table }; - -/***********************************************************************//** - * @brief Return calibration directory - * - * @return Calibration directory. - ***************************************************************************/ -inline -const std::string& GCaldb::dir(void) const -{ - return m_caldb; -} - #endif /* GCALDB_HPP */ diff --git a/inst/com/src/GCOMResponse.cpp b/inst/com/src/GCOMResponse.cpp index f269c7f..340fb62 100644 --- a/inst/com/src/GCOMResponse.cpp +++ b/inst/com/src/GCOMResponse.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * GCOMResponse.cpp - COMPTEL Response class * * ----------------------------------------------------------------------- * - * copyright (C) 2012-2013 by Juergen Knoedlseder * + * copyright (C) 2012-2014 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -384,7 +384,7 @@ void GCOMResponse::caldb(const std::string& caldb) GCaldb db(caldb); // Store the path to the calibration database - m_caldb = db.dir(); + m_caldb = db.rootdir(); // Return return; diff --git a/inst/cta/src/GCTAResponse.cpp b/inst/cta/src/GCTAResponse.cpp index 83e05d4..65fcfe1 100644 --- a/inst/cta/src/GCTAResponse.cpp +++ b/inst/cta/src/GCTAResponse.cpp @@ -535,13 +535,13 @@ void GCTAResponse::load(const std::string& rspname) // If filenames are empty then build filenames from CALDB root path and // response name if (aeffname.length() < 1) { - aeffname = irf_filename(m_caldb.dir() + "/" + rspname); + aeffname = irf_filename(gammalib::filepath(m_caldb.rootdir(), rspname)); } if (psfname.length() < 1) { - psfname = irf_filename(m_caldb.dir() + "/" + rspname); + psfname = irf_filename(gammalib::filepath(m_caldb.rootdir(), rspname)); } if (edispname.length() < 1) { - edispname = irf_filename(m_caldb.dir() + "/" + rspname); + edispname = irf_filename(gammalib::filepath(m_caldb.rootdir(), rspname)); } // Load effective area diff --git a/inst/lat/src/GLATResponse.cpp b/inst/lat/src/GLATResponse.cpp index 9c5858c..1388a5f 100644 --- a/inst/lat/src/GLATResponse.cpp +++ b/inst/lat/src/GLATResponse.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * GLATResponse.cpp - Fermi/LAT response class * * ----------------------------------------------------------------------- * - * copyright (C) 2008-2013 by Juergen Knoedlseder * + * copyright (C) 2008-2014 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -210,7 +210,7 @@ void GLATResponse::caldb(const std::string& caldb) GCaldb db(caldb); // Store the path to the calibration database - m_caldb = db.dir(); + m_caldb = db.rootdir(); // Return return; diff --git a/pyext/GCaldb.i b/pyext/GCaldb.i index b9eea27..f15c74b 100644 --- a/pyext/GCaldb.i +++ b/pyext/GCaldb.i @@ -44,20 +44,24 @@ public: virtual ~GCaldb(void); // Methods - void clear(void); - GCaldb* clone(void) const; - int size(void) const; - const std::string& dir(void) const; - void dir(const std::string& pathname); - void open(const std::string& mission, - const std::string& instrument = ""); - void close(void); - std::string filename(const std::string& detector, - const std::string& filter, - const std::string& codename, - const std::string& date, - const std::string& time, - const std::string& expr); + void clear(void); + GCaldb* clone(void) const; + int size(void) const; + std::string rootdir(void) const; + void rootdir(const std::string& pathname); + std::string path(const std::string& mission, + const std::string& instrument = ""); + std::string cifname(const std::string& mission, + const std::string& instrument = ""); + void open(const std::string& mission, + const std::string& instrument = ""); + void close(void); + std::string filename(const std::string& detector, + const std::string& filter, + const std::string& codename, + const std::string& date, + const std::string& time, + const std::string& expr); }; diff --git a/src/obs/GCaldb.cpp b/src/obs/GCaldb.cpp index 3109d5e..2947b9a 100644 --- a/src/obs/GCaldb.cpp +++ b/src/obs/GCaldb.cpp @@ -20,7 +20,7 @@ ***************************************************************************/ /** * @file GCaldb.cpp - * @brief Calibration database class implementation. + * @brief Calibration database class implementation * @author Juergen Knoedlseder */ @@ -35,10 +35,8 @@ #include "GCaldb.hpp" /* __ Method name definitions ____________________________________________ */ -#define G_CALDB1 "GCaldb()" -#define G_CALDB2 "GCaldb(std::string)" -#define G_ROOTDIR "GCaldb::rootdir()" -#define G_SET_DATABASE "GCaldb::set_database(std::string)" +#define G_GET_ROOTDIR "GCaldb::rootdir()" +#define G_SET_ROOTDIR "GCaldb::rootdir(std::string&)" #define G_PATH "GCaldb::path(std::string, std::string)" #define G_CIF "GCaldb::cif(std::string, std::string)" @@ -59,17 +57,13 @@ /***********************************************************************//** * @brief Void constructor * - * The void constructor determines the calibration database root directory - * from the GAMMALIB_CALDB or CALDB environment variables. + * Creates void instance of a calibration database. ***************************************************************************/ GCaldb::GCaldb(void) { // Initialise class members init_members(); - // Set calibration database root directory - set_database(rootdir()); - // Return return; } @@ -100,15 +94,7 @@ GCaldb::GCaldb(const GCaldb& caldb) * * This constructor sets the calibration database using the specified root * directory. Unless the specified pathname is not empty, any existing CALDB - * or GAMMALIB_CALDB environment variables will be ignored. - * - * If the pathname is empty, however, the constructor attempts to detemine - * the CALDB root directory from the GAMMALIB_CALDB environment variable. If - * GAMMALIB_CALDB is not found, the method will check for the CALDB - * environment variable. If this fails, the constructor will throw an - * exception. - * - * Any environment variable contained in the pathname will be expanded. + * environment variables will be ignored. ***************************************************************************/ GCaldb::GCaldb(const std::string& pathname) { @@ -117,13 +103,7 @@ GCaldb::GCaldb(const std::string& pathname) // If pathname is not empty then use it as root pathname if (pathname.length() > 0) { - set_database(gammalib::expand_env(pathname)); - } - - // ... otherwise try to determine root pathname from GAMMALIB_CALDB - // or CALDB environment variables. - else { - set_database(rootdir()); + rootdir(gammalib::expand_env(pathname)); } // Return @@ -149,9 +129,6 @@ GCaldb::GCaldb(const std::string& mission, const std::string& instrument) // Initialise members init_members(); - // Set calibration database root directory - set_database(rootdir()); - // Open database open(mission, instrument); @@ -263,21 +240,98 @@ int GCaldb::size(void) const /***********************************************************************//** + * @brief Return path to CALDB root directory + * + * @exception GException::directory_not_found + * Calibration directory not found. + * @exception GException::directory_not_accessible + * No read permission granted to calibration directory. + * + * The calibration directory path is given by one of the following + * + * $CALDB/data/ + * $CALDB/data// + * $GAMMALIB_CALDB/data/ + * $GAMMALIB_CALDB/data// + * + * where \ is the name of the mission and \ is the + * optional instrument name (all lower case). The arguments provided to the + * method are transformed to lower case. + ***************************************************************************/ +std::string GCaldb::rootdir(void) const +{ + // Initialise root directory to optional root directory name + std::string rootdir = m_opt_rootdir; + + // If root directory is empty then get the directory name from the + // CALDB environment variable. Throw an exception if the environment + // variable has not been set + if (rootdir.empty()) { + + // Get root directory from GAMMALIB_CALDB and CALDB environment variables + char* ptr1 = std::getenv("GAMMALIB_CALDB"); + char* ptr2 = std::getenv("CALDB"); + + // Throw an exception if non of the environment variables was set + if (ptr1 == NULL && ptr2 == NULL) { + throw GException::env_not_found(G_GET_ROOTDIR, + "GAMMALIB_CALDB or CALDB", + "Please set the GAMMALIB_CALDB or the CALDB environment" + " variable to a valid calibration database root directory."); + } + + // If GAMMALIB_CALDB was set then check whether the directory exists + if (ptr1 != NULL) { + if (access(ptr1, F_OK) == 0) { + rootdir = std::string(ptr1); + } + } + + // ... otherwise, if CALDB was set then check whether the directory + // exists + else if (ptr2 != NULL) { + if (access(ptr2, F_OK) == 0) { + rootdir = std::string(ptr2); + } + } + + } // endif: no optional root directory has been set + + // Return root directory + return rootdir; +} + + +/***********************************************************************//** * @brief Set calibration database root directory * * @param[in] pathname Calibration database root directory. * - * Set a new root directory for the calibration database. Any previously - * opened database will be closed. - * Any environment variable present in the pathname will be expanded. + * @exception GException::directory_not_found + * Calibration database root directory not found. + * @exception GException::directory_not_accessible + * No read permission granted for calibration database root + * directory. + * + * Sets the calibration database root directory to a specific path. The + * method verifies the existence of the root directory prior to setting. ***************************************************************************/ -void GCaldb::dir(const std::string& pathname) +void GCaldb::rootdir(const std::string& pathname) { - // Clear any existing database - clear(); + // Verify that specified root directory exists + //if (access(pathname.c_str(), F_OK) != 0) { + if (!gammalib::dir_exists(pathname)) { + throw GException::directory_not_found(G_SET_ROOTDIR, pathname); + } + + // Verify that specified root directory allows read access + if (access(pathname.c_str(), R_OK) != 0) { + throw GException::directory_not_accessible(G_SET_ROOTDIR, pathname, + "Requested read permission not granted."); + } - // Set calibration database - set_database(gammalib::expand_env(pathname)); + // Set calibration database root directory + m_opt_rootdir = gammalib::expand_env(pathname); // Return return; @@ -285,6 +339,112 @@ void GCaldb::dir(const std::string& pathname) /***********************************************************************//** + * @brief Return path to calibration directory + * + * @param[in] mission Mission name (case insensitive). + * @param[in] instrument Instrument name (case insensitive; optional). + * + * @exception GException::directory_not_found + * Calibration directory not found. + * @exception GException::directory_not_accessible + * No read permission granted to calibration directory. + * + * The calibration directory path is given by one of the following + * + * $CALDB/data/ + * $CALDB/data// + * $GAMMALIB_CALDB/data/ + * $GAMMALIB_CALDB/data// + * + * where \ is the name of the mission and \ is the + * optional instrument name (all lower case). The arguments provided to the + * method are transformed to lower case. + ***************************************************************************/ +std::string GCaldb::path(const std::string& mission, const std::string& instrument) +{ + // Verify that mission name is valid and directory is accessible + std::string path = rootdir() + "/data/" + gammalib::tolower(mission); +// if (access(path.c_str(), F_OK) != 0) { + if (!gammalib::dir_exists(path)) { + throw GException::directory_not_found(G_PATH, path, + "Requested mission \""+gammalib::toupper(mission)+"\" not found in" + " calibration database."); + } + if (access(path.c_str(), R_OK) != 0) { + throw GException::directory_not_accessible(G_PATH, path, + "Requested read permission not granted for mission \""+ + gammalib::toupper(mission)+"\"."); + } + + // If an instrument has been specified, verify that instrument name is + // valid and directory is accessible + if (instrument.length() > 0) { + + // Add instrument to path + path += "/" + gammalib::tolower(instrument); + + // Verify path + //if (access(path.c_str(), F_OK) != 0) { + if (!gammalib::dir_exists(path)) { + throw GException::directory_not_found(G_PATH, path, + "Requested instrument \""+gammalib::toupper(instrument)+"\" on" + " mission \""+gammalib::toupper(mission)+"\" not found in" + " calibration database."); + } + if (access(path.c_str(), R_OK) != 0) { + throw GException::directory_not_accessible(G_PATH, path, + "Requested read permission not granted for instrument \""+ + gammalib::toupper(instrument)+"\" on mission \""+gammalib::toupper(mission)+ + "\"."); + } + + } // endif: instrument has been specified + + // Return path + return path; +} + + +/***********************************************************************//** + * @brief Return absolute CIF filename + * + * @param[in] mission Mission name (case insensitive). + * @param[in] instrument Instrument name (case insensitive; optional). + * + * @exception GException::file_not_found + * CIF not found. + * + * The calibration directory path is given by one of the following + * + * $CALDB/data//caldb.indx + * $CALDB/data///caldb.indx + * $GAMMALIB_CALDB/data//caldb.indx + * $GAMMALIB_CALDB/data///caldb.indx + * + * where \ is the name of the mission and \ is the + * optional instrument name (all lower case). The arguments provided to the + * method are transformed to lower case. + ***************************************************************************/ +std::string GCaldb::cifname(const std::string& mission, const std::string& instrument) +{ + // Get path to calibration directory + std::string cif = path(mission, instrument); + + // Add calibration index filename + cif += "/caldb.indx"; + + // Verify that CIF exists + if (access(cif.c_str(), F_OK) != 0) { + throw GException::file_not_found(G_CIF, cif, + "Calibration Index File (CIF) not found."); + } + + // Return cif + return cif; +} + + +/***********************************************************************//** * @brief Open calibration database * * @param[in] mission Mission name (case insensitive). @@ -465,9 +625,16 @@ std::string GCaldb::filename(const std::string& detector, match_date && match_time && match_expr) { const GFitsTableCol* cal_dir = (*m_cif)["CAL_DIR"]; const GFitsTableCol* cal_file = (*m_cif)["CAL_FILE"]; - filename = m_caldb + "/" + - cal_dir->string(i) + "/" + - cal_file->string(i); + std::string path = rootdir(); + if (path.empty()) { + filename = cal_dir->string(i) + "/" + + cal_file->string(i); + } + else { + filename = path + "/" + + cal_dir->string(i) + "/" + + cal_file->string(i); + } break; } @@ -498,7 +665,7 @@ std::string GCaldb::print(const GChatter& chatter) const result.append("=== GCaldb ==="); // Append information - result.append("\n"+gammalib::parformat("Database root")+m_caldb); + result.append("\n"+gammalib::parformat("Database root")+rootdir()); // Append information about opened database if (m_cif != NULL) { @@ -531,7 +698,7 @@ std::string GCaldb::print(const GChatter& chatter) const void GCaldb::init_members(void) { // Initialise members - m_caldb.clear(); + m_opt_rootdir.clear(); m_mission.clear(); m_instrument.clear(); m_cifname.clear(); @@ -551,11 +718,11 @@ void GCaldb::init_members(void) void GCaldb::copy_members(const GCaldb& caldb) { // Copy attributes - m_caldb = caldb.m_caldb; - m_mission = caldb.m_mission; - m_instrument = caldb.m_instrument; - m_cifname = caldb.m_cifname; - m_fits = caldb.m_fits; + m_opt_rootdir = caldb.m_opt_rootdir; + m_mission = caldb.m_mission; + m_instrument = caldb.m_instrument; + m_cifname = caldb.m_cifname; + m_fits = caldb.m_fits; // Set CIF table pointer. We do not copy over the pointer as the FITS // file has been copied here. @@ -584,196 +751,3 @@ void GCaldb::free_members(void) } -/***********************************************************************//** - * @brief Return path to CALDB root directory - * - * @exception GException::directory_not_found - * Calibration directory not found. - * @exception GException::directory_not_accessible - * No read permission granted to calibration directory. - * - * The calibration directory path is given by one of the following - * - * $CALDB/data/ - * $CALDB/data// - * $GAMMALIB_CALDB/data/ - * $GAMMALIB_CALDB/data// - * - * where \ is the name of the mission and \ is the - * optional instrument name (all lower case). The arguments provided to the - * method are transformed to lower case. - ***************************************************************************/ -std::string GCaldb::rootdir(void) const -{ - // Get root directory from GAMMALIB_CALDB and CALDB environment variables - char* ptr1 = std::getenv("GAMMALIB_CALDB"); - char* ptr2 = std::getenv("CALDB"); - - // Throw an exception if non of the environment variables was set - if (ptr1 == NULL && ptr2 == NULL) { - throw GException::env_not_found(G_ROOTDIR, - "GAMMALIB_CALDB or CALDB", - "Please set the GAMMALIB_CALDB or the CALDB environment" - " variable to a valid calibration database root directory."); - } - - // Initialise root directory string - std::string rootdir; - - // If GAMMALIB_CALDB was set then check whether the directory exists - if (ptr1 != NULL) { - if (access(ptr1, F_OK) == 0) { - rootdir = std::string(ptr1); - } - } - - // ... otherwise, if CALDB was set then check whether the directory - // exists - else if (ptr2 != NULL) { - if (access(ptr2, F_OK) == 0) { - rootdir = std::string(ptr2); - } - } - - // Return root directory - return rootdir; -} - - -/***********************************************************************//** - * @brief Set calibration database - * - * @param[in] pathname Calibration database root directory. - * - * @exception GException::directory_not_found - * Calibration database root directory not found. - * @exception GException::directory_not_accessible - * No read permission granted for calibration database root - * directory. - * - * Set calibration database to a specific root directory. The method verifies - * the existence of the root directory prior to setting. - ***************************************************************************/ -void GCaldb::set_database(const std::string& pathname) -{ - // Verify that specified root directory exists - if (access(pathname.c_str(), F_OK) != 0) { - throw GException::directory_not_found(G_SET_DATABASE, pathname); - } - - // Verify that specified root directory allows read access - if (access(pathname.c_str(), R_OK) != 0) { - throw GException::directory_not_accessible(G_SET_DATABASE, pathname, - "Requested read permission not granted."); - } - - // Set calibration database root directory - m_caldb = pathname; - - // Return - return; -} - - -/***********************************************************************//** - * @brief Return path to calibration directory - * - * @param[in] mission Mission name (case insensitive). - * @param[in] instrument Instrument name (case insensitive; optional). - * - * @exception GException::directory_not_found - * Calibration directory not found. - * @exception GException::directory_not_accessible - * No read permission granted to calibration directory. - * - * The calibration directory path is given by one of the following - * - * $CALDB/data/ - * $CALDB/data// - * $GAMMALIB_CALDB/data/ - * $GAMMALIB_CALDB/data// - * - * where \ is the name of the mission and \ is the - * optional instrument name (all lower case). The arguments provided to the - * method are transformed to lower case. - ***************************************************************************/ -std::string GCaldb::path(const std::string& mission, const std::string& instrument) -{ - // Verify that mission name is valid and directory is accessible - std::string path = m_caldb + "/data/" + gammalib::tolower(mission); - if (access(path.c_str(), F_OK) != 0) { - throw GException::directory_not_found(G_PATH, path, - "Requested mission \""+gammalib::toupper(mission)+"\" not found in" - " calibration database."); - } - if (access(path.c_str(), R_OK) != 0) { - throw GException::directory_not_accessible(G_PATH, path, - "Requested read permission not granted for mission \""+ - gammalib::toupper(mission)+"\"."); - } - - // If an instrument has been specified, verify that instrument name is - // valid and directory is accessible - if (instrument.length() > 0) { - - // Add instrument to path - path += "/" + gammalib::tolower(instrument); - - // Verify path - if (access(path.c_str(), F_OK) != 0) { - throw GException::directory_not_found(G_PATH, path, - "Requested instrument \""+gammalib::toupper(instrument)+"\" on" - " mission \""+gammalib::toupper(mission)+"\" not found in" - " calibration database."); - } - if (access(path.c_str(), R_OK) != 0) { - throw GException::directory_not_accessible(G_PATH, path, - "Requested read permission not granted for instrument \""+ - gammalib::toupper(instrument)+"\" on mission \""+gammalib::toupper(mission)+ - "\"."); - } - - } // endif: instrument has been specified - - // Return path - return path; -} - - -/***********************************************************************//** - * @brief Return absolute CIF filename - * - * @param[in] mission Mission name (case insensitive). - * @param[in] instrument Instrument name (case insensitive; optional). - * - * @exception GException::file_not_found - * CIF not found. - * - * The calibration directory path is given by one of the following - * - * $CALDB/data//caldb.indx - * $CALDB/data///caldb.indx - * $GAMMALIB_CALDB/data//caldb.indx - * $GAMMALIB_CALDB/data///caldb.indx - * - * where \ is the name of the mission and \ is the - * optional instrument name (all lower case). The arguments provided to the - * method are transformed to lower case. - ***************************************************************************/ -std::string GCaldb::cifname(const std::string& mission, const std::string& instrument) -{ - // Get path to calibration directory - std::string cif = path(mission, instrument); - - // Add calibration index filename - cif += "/caldb.indx"; - - // Verify that CIF exists - if (access(cif.c_str(), F_OK) != 0) { - throw GException::file_not_found(G_CIF, cif, - "Calibration Index File (CIF) not found."); - } - - // Return cif - return cif; -} -- libgit2 0.21.4