File indexing completed on 2024-04-06 12:01:43
0001 #include "CondCore/PopCon/interface/PopCon.h"
0002 #include "CondCore/PopCon/interface/Exception.h"
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0005 #include "CondCore/CondDB/interface/ConnectionPool.h"
0006 #include <iostream>
0007
0008 namespace popcon {
0009
0010 constexpr const char* const PopCon::s_version;
0011
0012 PopCon::PopCon(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_record(pset.getParameter<std::string>("record")),
0018 m_payload_name(pset.getUntrackedParameter<std::string>("name", "")),
0019 m_LoggingOn(pset.getUntrackedParameter<bool>("loggingOn", true)),
0020 m_close(pset.getUntrackedParameter<bool>("closeIOV", false)),
0021 m_lastTill(pset.getUntrackedParameter<bool>("lastTill", false)) {
0022
0023
0024
0025 edm::LogInfo("PopCon") << "This is PopCon (Populator of Condition) v" << s_version << ".\n"
0026 << "Please report any problem and feature request through the JIRA project CMSCONDDB.\n";
0027 }
0028
0029 PopCon::~PopCon() {
0030 if (!m_targetConnectionString.empty()) {
0031 m_targetSession.transaction().commit();
0032 }
0033 }
0034
0035 cond::persistency::Session PopCon::initialize() {
0036 edm::LogInfo("PopCon") << "payload name " << m_payload_name << std::endl;
0037 if (!m_dbService.isAvailable())
0038 throw Exception("DBService not available");
0039 const std::string& connectionStr = m_dbService->session().connectionString();
0040 m_dbService->forceInit();
0041 m_tag = m_dbService->tag(m_record);
0042 m_tagInfo.name = m_tag;
0043 if (m_targetConnectionString.empty()) {
0044 m_targetSession = m_dbService->session();
0045 m_dbService->startTransaction();
0046 } else {
0047 cond::persistency::ConnectionPool connPool;
0048 connPool.setAuthenticationPath(m_authPath);
0049 connPool.setAuthenticationSystem(m_authSys);
0050 connPool.configure();
0051 m_targetSession = connPool.createSession(m_targetConnectionString);
0052 m_targetSession.transaction().start();
0053 }
0054 if (m_targetSession.existsDatabase() && m_targetSession.existsIov(m_tag)) {
0055 cond::persistency::IOVProxy iov = m_targetSession.readIov(m_tag);
0056 m_tagInfo.size = iov.sequenceSize();
0057 if (m_tagInfo.size > 0) {
0058 m_tagInfo.lastInterval = iov.getLast();
0059 }
0060 edm::LogInfo("PopCon") << "destination DB: " << connectionStr << ", target DB: "
0061 << (m_targetConnectionString.empty() ? connectionStr : m_targetConnectionString) << "\n"
0062 << "TAG: " << m_tag << ", last since/till: " << m_tagInfo.lastInterval.since << "/"
0063 << m_tagInfo.lastInterval.till << ", size: " << m_tagInfo.size << "\n"
0064 << std::endl;
0065 } else {
0066 edm::LogInfo("PopCon") << "destination DB: " << connectionStr << ", target DB: "
0067 << (m_targetConnectionString.empty() ? connectionStr : m_targetConnectionString) << "\n"
0068 << "TAG: " << m_tag << "; First writer to this new tag." << std::endl;
0069 }
0070 return m_targetSession;
0071 }
0072
0073 void PopCon::finalize(Time_t lastTill) {
0074 if (m_close) {
0075
0076 if (m_lastTill > lastTill)
0077 lastTill = m_lastTill;
0078 m_dbService->closeIOV(lastTill, m_record);
0079 }
0080 if (m_targetConnectionString.empty()) {
0081 m_dbService->commitTransaction();
0082 } else {
0083 m_targetSession.transaction().commit();
0084 }
0085 }
0086
0087 }