Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-11-04 06:48:47

0001 #include "CondCore/CondDB/interface/ConnectionPool.h"
0002 #include "CondCore/PopCon/interface/OnlinePopCon.h"
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0005 
0006 //#include <iostream>
0007 
0008 namespace popcon {
0009 
0010   constexpr const char* const OnlinePopCon::s_version;
0011 
0012   OnlinePopCon::OnlinePopCon(const edm::ParameterSet& pset)
0013       : m_targetSession(),
0014         m_targetConnectionString(pset.getUntrackedParameter<std::string>("targetDBConnectionString", "")),
0015         m_authPath(pset.getUntrackedParameter<std::string>("authenticationPath", "")),
0016         m_authSys(pset.getUntrackedParameter<int>("authenticationSystem", 1)),
0017         m_recordName(pset.getParameter<std::string>("record")),
0018         m_useLockRecors(pset.getUntrackedParameter<bool>("useLockRecords", false)) {
0019     edm::LogInfo("OnlinePopCon")
0020         << "This is OnlinePopCon (Populator of Condition) v" << s_version << ".\n"
0021         << "Please report any problem and feature request through the JIRA project CMSCONDDB.\n";
0022   }
0023 
0024   OnlinePopCon::~OnlinePopCon() {
0025     if (!m_targetConnectionString.empty()) {
0026       m_targetSession.transaction().commit();
0027     }
0028   }
0029 
0030   cond::persistency::Session OnlinePopCon::preparePopCon() {
0031     // Initialization almost identical to PopCon
0032     const std::string& connectionStr = m_dbService->session().connectionString();
0033     m_dbService->forceInit();
0034     std::string tagName = m_dbService->tag(m_recordName);
0035     m_tagInfo.name = tagName;
0036     if (m_targetConnectionString.empty()) {
0037       m_targetSession = m_dbService->session();
0038       m_dbService->startTransaction();
0039     } else {
0040       cond::persistency::ConnectionPool connPool;
0041       connPool.setAuthenticationPath(m_authPath);
0042       connPool.setAuthenticationSystem(m_authSys);
0043       connPool.configure();
0044       m_targetSession = connPool.createSession(m_targetConnectionString);
0045       m_targetSession.transaction().start();
0046     }
0047 
0048     m_dbService->logger().logInfo() << "OnlinePopCon::preparePopCon";
0049     m_dbService->logger().logInfo() << "  destination DB: " << connectionStr;
0050     m_dbService->logger().logInfo() << "  target DB: "
0051                                     << (m_targetConnectionString.empty() ? connectionStr : m_targetConnectionString);
0052 
0053     if (m_targetSession.existsDatabase() && m_targetSession.existsIov(tagName)) {
0054       cond::persistency::IOVProxy iov = m_targetSession.readIov(tagName);
0055       m_tagInfo.size = iov.sequenceSize();
0056       if (m_tagInfo.size > 0) {
0057         m_tagInfo.lastInterval = iov.getLast();
0058       }
0059       m_dbService->logger().logInfo() << "  TAG: " << tagName << ", last since/till: " << m_tagInfo.lastInterval.since
0060                                       << "/" << m_tagInfo.lastInterval.till;
0061       m_dbService->logger().logInfo() << "  size: " << m_tagInfo.size;
0062     } else {
0063       m_dbService->logger().logInfo() << "  TAG: " << tagName << "; First writer to this new tag.";
0064     }
0065     return m_targetSession;
0066   }
0067 
0068   cond::persistency::Session OnlinePopCon::initialize() {
0069     // Check if DB service is available
0070     if (!m_dbService.isAvailable()) {
0071       throw Exception("OnlinePopCon", "[initialize] DBService not available");
0072     }
0073 
0074     // Start DB logging service
0075     m_dbLoggerReturn_ = 0;
0076     m_dbService->logger().start();
0077     m_dbService->logger().logInfo() << "OnlinePopCon::initialize - begin logging for record: " << m_recordName;
0078 
0079     // If requested, lock records
0080     if (m_useLockRecors) {
0081       m_dbService->logger().logInfo() << "OnlinePopCon::initialize - locking records";
0082       m_dbService->lockRecords();
0083     }
0084 
0085     // Prepare the rest of PopCon infrastructure
0086     auto session = preparePopCon();
0087     return session;
0088   }
0089 
0090   void OnlinePopCon::finalize() {
0091     // Check if DB service is available
0092     if (!m_dbService.isAvailable()) {
0093       throw Exception("OnlinePopCon", "[finalize] DBService not available");
0094     }
0095 
0096     // Release locks if previously locked
0097     if (m_useLockRecors) {
0098       m_dbService->logger().logInfo() << "OnlinePopCon::finalize - releasing locks";
0099       m_dbService->releaseLocks();
0100     }
0101 
0102     // Finalize PopCon infrastructure
0103     if (m_targetConnectionString.empty()) {
0104       m_dbService->commitTransaction();
0105     } else {
0106       m_targetSession.transaction().commit();
0107     }
0108 
0109     // Stop DB logging service
0110     m_dbService->logger().logInfo() << "OnlinePopCon::finalize - end logging for record: " << m_recordName;
0111     m_dbService->logger().end(m_dbLoggerReturn_);
0112   }
0113 
0114 }  // namespace popcon