File indexing completed on 2024-11-04 06:48:47
0001 #ifndef CONDCORE_POPCON_ONLINEPOPCON_H
0002 #define CONDCORE_POPCON_ONLINEPOPCON_H
0003
0004
0005
0006
0007
0008
0009
0010 #include "CondCore/DBOutputService/interface/OnlineDBOutputService.h"
0011 #include "CondCore/PopCon/interface/Exception.h"
0012 #include "FWCore/ParameterSet/interface/ParameterSetfwd.h"
0013 #include "FWCore/ServiceRegistry/interface/Service.h"
0014
0015 #include <algorithm>
0016 #include <functional>
0017 #include <iostream>
0018 #include <string>
0019 #include <vector>
0020
0021 namespace popcon {
0022
0023
0024
0025
0026 class OnlinePopCon {
0027 public:
0028 typedef cond::Time_t Time_t;
0029
0030 OnlinePopCon(const edm::ParameterSet& pset);
0031
0032 virtual ~OnlinePopCon();
0033
0034 template <typename Source>
0035 void write(Source const& source);
0036
0037 private:
0038 cond::persistency::Session initialize();
0039 cond::persistency::Session preparePopCon();
0040 void finalize();
0041
0042 private:
0043
0044 edm::Service<cond::service::OnlineDBOutputService> m_dbService;
0045
0046
0047 cond::persistency::Session m_targetSession;
0048 std::string m_targetConnectionString;
0049 std::string m_authPath;
0050 int m_authSys;
0051 std::string m_recordName;
0052 cond::TagInfo_t m_tagInfo;
0053 cond::LogDBEntry_t m_logDBEntry;
0054
0055
0056 int m_dbLoggerReturn_;
0057 bool m_useLockRecors;
0058
0059
0060 static constexpr const char* const s_version = "1.0";
0061 };
0062
0063 template <typename Source>
0064 void OnlinePopCon::write(Source const& source) {
0065
0066 typedef typename Source::Container Container;
0067 std::pair<Container const*, std::string const> ret = source(initialize(), m_tagInfo, m_logDBEntry);
0068 Container const& iovs = *ret.first;
0069
0070
0071 if (iovs.size() > 1) {
0072 throw Exception("OnlinePopCon", "[write] More than one iov/payload provided!");
0073 }
0074
0075
0076 if (iovs.empty()) {
0077 m_dbService->logger().logInfo() << "OnlinePopCon::write - Nothing to transfer";
0078 finalize();
0079 return;
0080 }
0081
0082
0083
0084 if (!m_dbService.isAvailable()) {
0085 throw Exception("OnlinePopCon", "[write] DBService not available");
0086 }
0087
0088
0089 auto [originalSince, payload] = *iovs.begin();
0090
0091
0092 m_dbService->logger().logInfo() << "OnlinePopCon::write - original since: " << originalSince;
0093
0094
0095 try {
0096 auto targetSince = m_dbService->writeIOVForNextLumisection(*payload, m_recordName);
0097 m_dbService->logger().logInfo() << "OnlinePopCon::write - writeForNextLumisection successful!";
0098 m_dbService->logger().logInfo() << "OnlinePopCon::write - uploaded with since: " << targetSince;
0099 } catch (const std::exception& e) {
0100 m_dbService->logger().logError() << "OnlinePopCon::write - Error writing record: " << m_recordName;
0101 m_dbService->logger().logError() << "Error is: " << e.what();
0102 m_dbLoggerReturn_ = 2;
0103 }
0104
0105
0106 finalize();
0107 }
0108
0109 }
0110
0111 #endif