#ifndef DCallibration_h #define DCallibration_h #include #include #include #include "DCCDBGlobals.h" #include "Providers/DDataProvider.h" using namespace std; namespace ccdb { class DCalibration { public: DCalibration(); ///< Default constructor DCalibration(int defaultRun, string defaultVariation="default"); virtual ~DCalibration(); /** * @brief Connects to database using connection string * * Connects to database using connection string * the Connection String generally has form: * :// * * The examples of the Connection Strings are: * * @see DMySQLCalibration * mysql://:@: * * @see DFileCalibration * file:// * * @param connectionString the Connection String * @return true if connected */ virtual bool Connect(std::string connectionString) = 0; /** * @brief closes connection to data * Closes connection to data. * If underlayed @see DProvider* object is "locked" * (user could check this by * */ virtual void Disconnect() = 0; /** * @brief indicates ether the connection is open or not * * @return true if connection is open */ virtual bool IsConnected() = 0; /** @brief gets DDataProvider* object used for specified DCalibration *@returns provider used for specified DCalibration */ DDataProvider * GetProvider() const { return mProvider; } /** @brief set provider to use. * if lockProvider==true, than @see Connect, @see Disconnect and @see SetConnectionString * will not affect connection of provider. The provider will not be deleted in destruction. * @parameter [in] DDataProvider * provider * @parameter [in] bool lockProvider * @return void */ void UseProvider(DDataProvider * provider, bool lockProvider=true); /** @brief Get constants by namepath * * This version of function fills values as a Table, * vector> - is vector of rows, each row is a map * * Namepath is usually is just the data path, like * /path/to/data * but the full form of request is * /path/to/data:run:variation:time * request might be shortened. One may skip * /path/to/data - just path to date, no run, variation and timestamp specified * /path/to/data::mc - no run or date specified. * /path/to/data:::2029 - only path and date * * * @parameter [out] values - vector of rows, each row is a map * @parameter [in] namepath - data path. Short /path/to/data .Full format is /path/to/data:run:variation:time * @return true if constants were found and filled. false if namepath was not found. raises std::exception if any other error acured. */ virtual bool GetCalib(vector< map > &values, const string & namepath); virtual bool GetCalib(vector< map > &values, const string & namepath); virtual bool GetCalib(vector< map > &values, const string & namepath); /** @brief Get constants by namepath * * this version of function fills values as a table represented as * vector< vector > = vector of rows where each row is a vector of cells * * @parameter [out] values - vector of rows, each row is a map * @parameter [in] namepath - data path * @return true if constants were found and filled. false if namepath was not found. raises std::exception if any other error acured. */ virtual bool GetCalib(vector< vector > &values, const string & namepath); virtual bool GetCalib(vector< vector > &values, const string & namepath); virtual bool GetCalib(vector< vector > &values, const string & namepath); /** @brief Get constants by namepath * * this version of function fills values as one row * where map * * @parameter [out] values - as map * @parameter [in] namepath - data path * @return true if constants were found and filled. false if namepath was not found. raises std::exception if any other error acured. */ virtual bool GetCalib(map &values, const string & namepath); virtual bool GetCalib(map &values, const string & namepath); virtual bool GetCalib(map &values, const string & namepath); /** @brief Get constants by namepath * * this version of function fills values as one row as vector * * @parameter [out] values - as vector * @parameter [in] namepath - data path * @return true if constants were found and filled. false if namepath was not found. raises std::exception if any other error acured. */ virtual bool GetCalib(vector &values, const string & namepath); virtual bool GetCalib(vector &values, const string & namepath); virtual bool GetCalib(vector &values, const string & namepath); /** @brief gets connection string which is used for current provider *@return mConnectionString */ virtual string GetConnectionString() const; /** @brief gets flag that indicate that DProvider* is locked * For USER, If this function return true this means that * @see Connect and @see Disconnect and @see SetConnectionString functions will NOT work * because the connection to database managed by @see DCalibrationGenerator * * When this "ProviderIsLocked" happens? * - If DCallibration is generated by @see DCallibrationGenerator - it is locked. * Everything is managed by the generator. This is a recomended way of creating DCalibration. * * - If this DCalibration object is created by user, which is NOT recommended but possible, * then Underlaying @see DProvider is NOT locked and user can call Connect and Disconnect * * If user uses DCalibrationGenerator object to obtain DCalibration, this way IS RECOMMENDED, * DCalibrationGenerator may use one connection for several different DCalibration objects, * In this case "ProviderIsLocked" and user cannot call Connect and disconnet functions. * * *@return True if locked */ bool GetProviderIsLocked() const { return mProviderIsLocked; } /** @brief Gets Default Run * * @remark There is no SetDefaultRun because it assumed that one part of a program * should not change default run for another part of the program and get non determined situation * * If one need just one table of not default run he could specify it in namepath @see GetCalib * If one really need to change default run it the subject of a new DCalibration * * @return int */ int GetDefaultRun() const { return mDefaultRun; } /** @brief Gets the default variation * * @remark There is no GetDefaultVariation for the same * reasons as described in @see GetDefaultRun * @return std::string */ std::string GetDefaultVariation() const { return mDefaultVariation; } protected: /** @brief Gets the assignment from provider using namepath * namepath is the common ccdb request; @see GetCalib * * @remark the function is threadsafe * * @parameter [in] namepath - full namepath is /path/to/data:run:variation:time but usually it is only /path/to/data * @return DAssignment * */ virtual DAssignment * GetAssignment(const string& namepath); virtual void Lock(); ///Thread mutex lock for multithreaded operations virtual void Unlock(); ///Thread mutex Unlock lock for multithreaded operations private: DCalibration(const DCalibration& rhs); DCalibration& operator=(const DCalibration& rhs); protected: DDataProvider *mProvider; ///