Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:50:20

0001 #ifndef CondCore_CondDB_PayloadReader_h
0002 #define CondCore_CondDB_PayloadReader_h
0003 //
0004 // Package:     CondDB
0005 // Class  :     PayloadReader
0006 //
0007 /**\class PayloadReader PayloadReader.h CondCore/CondDB/interface/PayloadReader.h
0008    Description: service for accessing conditions payloads from DB.  
0009 */
0010 //
0011 // Author:      Giacomo Govi
0012 // Created:     Jul 2015
0013 //
0014 
0015 #include "CondCore/CondDB/interface/ConnectionPool.h"
0016 
0017 #include <memory>
0018 
0019 namespace cond {
0020 
0021   namespace persistency {
0022 
0023     class PayloadReader {
0024     public:
0025       static constexpr const char* const PRODUCTION_DB = "oracle://cms_orcon_adg/CMS_CONDITIONS";
0026 
0027     public:
0028       // default constructor
0029       PayloadReader();
0030 
0031       //
0032       PayloadReader(const PayloadReader& rhs);
0033 
0034       //
0035       virtual ~PayloadReader();
0036 
0037       //
0038       PayloadReader& operator=(const PayloadReader& rhs);
0039 
0040       //
0041       ConnectionPool& connection();
0042 
0043       //
0044       void open(const std::string& connectionString);
0045 
0046       //
0047       void open();
0048 
0049       //
0050       void close();
0051 
0052       //
0053       template <typename T>
0054       std::shared_ptr<T> fetch(const cond::Hash& payloadHash);
0055 
0056     private:
0057       std::shared_ptr<ConnectionPool> m_connection;
0058       Session m_session;
0059     };
0060 
0061     template <typename T>
0062     inline std::shared_ptr<T> PayloadReader::fetch(const cond::Hash& payloadHash) {
0063       std::shared_ptr<T> ret;
0064       if (m_session.connectionString().empty())
0065         open(PRODUCTION_DB);
0066       m_session.transaction().start(true);
0067       ret = m_session.fetchPayload<T>(payloadHash);
0068       m_session.transaction().commit();
0069       return ret;
0070     }
0071 
0072   }  // namespace persistency
0073 }  // namespace cond
0074 #endif  // CondCore_CondDB_PayloadReader_h