Commit 2446d35882ed54fa925f52b5628cb65da48b1fa5

Authored by Jürgen Knödlseder
1 parent 87784c50

Implement still simplified GCaldb::filename method.

The GCaldb::filename method returns an absolute IRF filename based on a set of selection criteria. The selection criteria are still very simple, and a more sophisticated should be implemented in the futur. For the time being, the method does the job.
include/GCaldb.hpp
1 /*************************************************************************** 1 /***************************************************************************
2 * GCaldb.hpp - Calibration database class * 2 * GCaldb.hpp - Calibration database class *
3 * ----------------------------------------------------------------------- * 3 * ----------------------------------------------------------------------- *
4 - * copyright (C) 2011-2013 by Juergen Knoedlseder * 4 + * copyright (C) 2011-2014 by Juergen Knoedlseder *
5 * ----------------------------------------------------------------------- * 5 * ----------------------------------------------------------------------- *
6 * * 6 * *
7 * This program is free software: you can redistribute it and/or modify * 7 * This program is free software: you can redistribute it and/or modify *
@@ -76,6 +76,7 @@ public: @@ -76,6 +76,7 @@ public:
76 GCaldb(void); 76 GCaldb(void);
77 GCaldb(const GCaldb& caldb); 77 GCaldb(const GCaldb& caldb);
78 explicit GCaldb(const std::string& pathname); 78 explicit GCaldb(const std::string& pathname);
  79 + GCaldb(const std::string& mission, const std::string& instrument);
79 virtual ~GCaldb(void); 80 virtual ~GCaldb(void);
80 81
81 // Operators 82 // Operators
@@ -90,6 +91,12 @@ public: @@ -90,6 +91,12 @@ public:
90 void open(const std::string& mission, 91 void open(const std::string& mission,
91 const std::string& instrument = ""); 92 const std::string& instrument = "");
92 void close(void); 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);
93 std::string print(const GChatter& chatter = NORMAL) const; 100 std::string print(const GChatter& chatter = NORMAL) const;
94 101
95 protected: 102 protected:
pyext/GCaldb.i
1 /*************************************************************************** 1 /***************************************************************************
2 * GCaldb.i - Calibration database class * 2 * GCaldb.i - Calibration database class *
3 * ----------------------------------------------------------------------- * 3 * ----------------------------------------------------------------------- *
4 - * copyright (C) 2011-2013 by Juergen Knoedlseder * 4 + * copyright (C) 2011-2014 by Juergen Knoedlseder *
5 * ----------------------------------------------------------------------- * 5 * ----------------------------------------------------------------------- *
6 * * 6 * *
7 * This program is free software: you can redistribute it and/or modify * 7 * This program is free software: you can redistribute it and/or modify *
@@ -40,6 +40,7 @@ public: @@ -40,6 +40,7 @@ public:
40 GCaldb(void); 40 GCaldb(void);
41 GCaldb(const GCaldb& caldb); 41 GCaldb(const GCaldb& caldb);
42 explicit GCaldb(const std::string& pathname); 42 explicit GCaldb(const std::string& pathname);
  43 + GCaldb(const std::string& mission, const std::string& instrument);
43 virtual ~GCaldb(void); 44 virtual ~GCaldb(void);
44 45
45 // Methods 46 // Methods
@@ -51,6 +52,12 @@ public: @@ -51,6 +52,12 @@ public:
51 void open(const std::string& mission, 52 void open(const std::string& mission,
52 const std::string& instrument = ""); 53 const std::string& instrument = "");
53 void close(void); 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);
54 }; 61 };
55 62
56 63
src/obs/GCaldb.cpp
1 /*************************************************************************** 1 /***************************************************************************
2 * GCaldb.cpp - Calibration database class * 2 * GCaldb.cpp - Calibration database class *
3 * ----------------------------------------------------------------------- * 3 * ----------------------------------------------------------------------- *
4 - * copyright (C) 2011-2013 by Juergen Knoedlseder * 4 + * copyright (C) 2011-2014 by Juergen Knoedlseder *
5 * ----------------------------------------------------------------------- * 5 * ----------------------------------------------------------------------- *
6 * * 6 * *
7 * This program is free software: you can redistribute it and/or modify * 7 * This program is free software: you can redistribute it and/or modify *
@@ -57,7 +57,7 @@ @@ -57,7 +57,7 @@
57 ==========================================================================*/ 57 ==========================================================================*/
58 58
59 /***********************************************************************//** 59 /***********************************************************************//**
60 - * @brief Constructor 60 + * @brief Void constructor
61 * 61 *
62 * The void constructor determines the calibration database root directory 62 * The void constructor determines the calibration database root directory
63 * from the GAMMALIB_CALDB or CALDB environment variables. 63 * from the GAMMALIB_CALDB or CALDB environment variables.
@@ -67,7 +67,7 @@ GCaldb::GCaldb(void) @@ -67,7 +67,7 @@ GCaldb::GCaldb(void)
67 // Initialise class members 67 // Initialise class members
68 init_members(); 68 init_members();
69 69
70 - // Set calibration database 70 + // Set calibration database root directory
71 set_database(rootdir()); 71 set_database(rootdir());
72 72
73 // Return 73 // Return
@@ -98,9 +98,6 @@ GCaldb::GCaldb(const GCaldb& caldb) @@ -98,9 +98,6 @@ GCaldb::GCaldb(const GCaldb& caldb)
98 * 98 *
99 * @param[in] pathname Calibration database root directory. 99 * @param[in] pathname Calibration database root directory.
100 * 100 *
101 - * @exception GException::env_not_found  
102 - * CALDB or GAMMALIB_CALDB environment variables not found  
103 - *  
104 * This constructor sets the calibration database using the specified root 101 * This constructor sets the calibration database using the specified root
105 * directory. Unless the specified pathname is not empty, any existing CALDB 102 * directory. Unless the specified pathname is not empty, any existing CALDB
106 * or GAMMALIB_CALDB environment variables will be ignored. 103 * or GAMMALIB_CALDB environment variables will be ignored.
@@ -135,6 +132,35 @@ GCaldb::GCaldb(const std::string& pathname) @@ -135,6 +132,35 @@ GCaldb::GCaldb(const std::string& pathname)
135 132
136 133
137 /***********************************************************************//** 134 /***********************************************************************//**
  135 + * @brief Calibration database constructor
  136 + *
  137 + * @param[in] mission Mission name (case insensitive).
  138 + * @param[in] instrument Instrument name (case insensitive).
  139 + *
  140 + * Constructs a calibration database instance by opening the calibration
  141 + * database for the specified @p mission and @p instrument. Opening consists
  142 + * of loading the Calibration Index File (CIF) in memory. Once opened,
  143 + * calibration information can be accessed.
  144 + *
  145 + * For more information about opening the database, refer to GCaldb::open.
  146 + ***************************************************************************/
  147 +GCaldb::GCaldb(const std::string& mission, const std::string& instrument)
  148 +{
  149 + // Initialise members
  150 + init_members();
  151 +
  152 + // Set calibration database root directory
  153 + set_database(rootdir());
  154 +
  155 + // Open database
  156 + open(mission, instrument);
  157 +
  158 + // Return
  159 + return;
  160 +}
  161 +
  162 +
  163 +/***********************************************************************//**
138 * @brief Destructor 164 * @brief Destructor
139 ***************************************************************************/ 165 ***************************************************************************/
140 GCaldb::~GCaldb(void) 166 GCaldb::~GCaldb(void)
@@ -316,6 +342,139 @@ void GCaldb::close(void) @@ -316,6 +342,139 @@ void GCaldb::close(void)
316 342
317 343
318 /***********************************************************************//** 344 /***********************************************************************//**
  345 + * @brief Return calibration file name based on selection parameters
  346 + *
  347 + * @param[in] detector Detector name (not used if empty).
  348 + * @param[in] filter Filter name (not used if empty).
  349 + * @param[in] codename Code name (not used if empty).
  350 + * @param[in] date Date in yyyy-mm-dd format (not used if empty).
  351 + * @param[in] time Time in hh:mm:ss format (not used if empty).
  352 + * @param[in] expr Boolean selection expression (not used if empty).
  353 + * @return Calibration filename (empty if not found).
  354 + *
  355 + * Returns a calibration file name based on selection parameters. If more
  356 + * files satisfy the specified selection parameters, the first file will
  357 + * be returned.
  358 + *
  359 + * @todo data should support "now" and probably be implemented using < condition.
  360 + * @todo time should support "now" and probably be implemented using < condition.
  361 + * @todo expr should support arbitrary Boolean expressions.
  362 + ***************************************************************************/
  363 +std::string GCaldb::filename(const std::string& detector,
  364 + const std::string& filter,
  365 + const std::string& codename,
  366 + const std::string& date,
  367 + const std::string& time,
  368 + const std::string& expr)
  369 +{
  370 + // Initialise empty filename
  371 + std::string filename;
  372 +
  373 + // Continue only if CIF is opened
  374 + if (m_cif != NULL) {
  375 +
  376 + // Loop over all CIF entries
  377 + for (int i = 0; i < size(); ++i) {
  378 +
  379 + // Initialise selection flags
  380 + bool match_detector = false;
  381 + bool match_filter = false;
  382 + bool match_codename = false;
  383 + bool match_date = false;
  384 + bool match_time = false;
  385 + bool match_expr = false;
  386 +
  387 + // Check for detector
  388 + if (detector.length() > 0) {
  389 + const GFitsTableCol* column = (*m_cif)["DETNAM"];
  390 + if (detector == column->string(i)) {
  391 + match_detector = true;
  392 + }
  393 + }
  394 + else {
  395 + match_detector = true;
  396 + }
  397 +
  398 + // Check for filter
  399 + if (filter.length() > 0) {
  400 + const GFitsTableCol* column = (*m_cif)["FILTER"];
  401 + if (filter == column->string(i)) {
  402 + match_filter = true;
  403 + }
  404 + }
  405 + else {
  406 + match_filter = true;
  407 + }
  408 +
  409 + // Check for code name
  410 + if (codename.length() > 0) {
  411 + const GFitsTableCol* column = (*m_cif)["CAL_CNAM"];
  412 + if (codename == column->string(i)) {
  413 + match_codename = true;
  414 + }
  415 + }
  416 + else {
  417 + match_codename = true;
  418 + }
  419 +
  420 + // Check for date
  421 + if (date.length() > 0) {
  422 + const GFitsTableCol* column = (*m_cif)["CAL_VSD"];
  423 + if (date == column->string(i)) {
  424 + match_date = true;
  425 + }
  426 + }
  427 + else {
  428 + match_date = true;
  429 + }
  430 +
  431 + // Check for time
  432 + if (time.length() > 0) {
  433 + const GFitsTableCol* column = (*m_cif)["CAL_VST"];
  434 + if (time == column->string(i)) {
  435 + match_time = true;
  436 + }
  437 + }
  438 + else {
  439 + match_time = true;
  440 + }
  441 +
  442 + // Check for expression
  443 + if (expr.length() > 0) {
  444 + const GFitsTableCol* column = (*m_cif)["CAL_CBD"];
  445 + int num_columns = column->elements(i);
  446 + for (int k = 0; k < num_columns; ++k) {
  447 + if (expr == column->string(i,k)) {
  448 + match_expr = true;
  449 + break;
  450 + }
  451 + }
  452 + }
  453 + else {
  454 + match_expr = true;
  455 + }
  456 +
  457 + // Select file if all selection match
  458 + if (match_detector && match_filter && match_codename &&
  459 + match_date && match_time && match_expr) {
  460 + const GFitsTableCol* cal_dir = (*m_cif)["CAL_DIR"];
  461 + const GFitsTableCol* cal_file = (*m_cif)["CAL_FILE"];
  462 + filename = m_caldb + "/" +
  463 + cal_dir->string(i) + "/" +
  464 + cal_file->string(i);
  465 + break;
  466 + }
  467 +
  468 + } // endfor: looped over all CIF entries
  469 +
  470 + } // endif: CIF has been opened
  471 +
  472 + // Return filename
  473 + return filename;
  474 +}
  475 +
  476 +
  477 +/***********************************************************************//**
319 * @brief Print calibration database information 478 * @brief Print calibration database information
320 * 479 *
321 * @param[in] chatter Chattiness (defaults to NORMAL). 480 * @param[in] chatter Chattiness (defaults to NORMAL).