00001 #ifndef EXPNAMEDB_EXPNAMEDATABASE_H 00002 #define EXPNAMEDB_EXPNAMEDATABASE_H 00003 00004 //-------------------------------------------------------------------------- 00005 // File and Version Information: 00006 // $Id: ExpNameDatabase.h 3844 2012-06-20 20:54:37Z salnikov@SLAC.STANFORD.EDU $ 00007 // 00008 // Description: 00009 // Class ExpNameDatabase. 00010 // 00011 //------------------------------------------------------------------------ 00012 00013 //----------------- 00014 // C/C++ Headers -- 00015 //----------------- 00016 #include <string> 00017 #include <utility> 00018 00019 //---------------------- 00020 // Base Class Headers -- 00021 //---------------------- 00022 00023 //------------------------------- 00024 // Collaborating Class Headers -- 00025 //------------------------------- 00026 #include "AppUtils/AppDataPath.h" 00027 00028 //------------------------------------ 00029 // Collaborating Class Declarations -- 00030 //------------------------------------ 00031 00032 // --------------------- 00033 // -- Class Interface -- 00034 // --------------------- 00035 00036 namespace ExpNameDb { 00037 00038 /// @addtogroup ExpNameDb 00039 00040 /** 00041 * @ingroup ExpNameDb 00042 * 00043 * @brief Class which provides mapping between experiment names and IDs. 00044 * 00045 * This software was developed for the LCLS project. If you use all or 00046 * part of it, please give an appropriate acknowledgment. 00047 * 00048 * @version $Id: ExpNameDatabase.h 3844 2012-06-20 20:54:37Z salnikov@SLAC.STANFORD.EDU $ 00049 * 00050 * @author Andy Salnikov 00051 */ 00052 00053 class ExpNameDatabase { 00054 public: 00055 00056 /** 00057 * @brief Constructor takes the name of the file containing the database 00058 * 00059 * File name is relative with respect to the $SIT_DATA (one of its components). 00060 * If the file is not found the exception is generated. 00061 * 00062 * @param[in] fname database file name, default is ExpNameDb/experiment-db.dat 00063 * 00064 * @throw FileNotFoundError if file does not exist 00065 */ 00066 explicit ExpNameDatabase (const std::string fname = "ExpNameDb/experiment-db.dat"); 00067 00068 /** 00069 * @brief Get instrument and experiment name given experiment ID. 00070 * 00071 * @param[in] id Experiment ID. 00072 * @return Pair of strings, first string is instrument name, second is experiment name, 00073 * both will be empty if ID is not known. 00074 * 00075 */ 00076 std::pair<std::string, std::string> getNames(unsigned id) const; 00077 00078 /** 00079 * @brief Get experiment ID given instrument and experiment names. 00080 * 00081 * Instrument name may be empty if experiment name is unambiguous. If instrument name 00082 * is empty and experiment name is ambiguous then first matching ID is returned. 00083 * 00084 * @param[in] instrument Instrument name. 00085 * @param[in] experiment Experiment name. 00086 * @return Experiment ID or 0 if instrument/experiment is not known. 00087 * 00088 */ 00089 unsigned getID(const std::string& instrument, const std::string& experiment) const; 00090 00091 /** 00092 * @brief Get instrument name and experiment ID for given experiment name. 00093 * 00094 * If experiment name is ambiguous then first matching name and ID is returned. 00095 * 00096 * @param[in] experiment Experiment name. 00097 * @return Pair of instrument name and experiment ID, name will be empty if experiment is not known. 00098 * 00099 */ 00100 std::pair<std::string, unsigned> getInstrumentAndID(const std::string& experiment) const; 00101 00102 protected: 00103 00104 private: 00105 00106 AppUtils::AppDataPath m_path; 00107 }; 00108 00109 } // namespace ExpNameDb 00110 00111 #endif // EXPNAMEDB_EXPNAMEDATABASE_H