File indexing completed on 2024-04-06 12:01:43
0001 #ifndef POPCON_POPCON_H
0002 #define POPCON_POPCON_H
0003
0004
0005
0006
0007
0008 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0009 #include "FWCore/ServiceRegistry/interface/Service.h"
0010
0011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0012
0013 #include "FWCore/ParameterSet/interface/ParameterSetfwd.h"
0014
0015 #include "CondCore/CondDB/interface/Time.h"
0016
0017 #include <algorithm>
0018 #include <functional>
0019 #include <string>
0020 #include <vector>
0021
0022 #include <iostream>
0023
0024 namespace popcon {
0025
0026
0027
0028
0029 class PopCon {
0030 public:
0031 typedef cond::Time_t Time_t;
0032
0033 PopCon(const edm::ParameterSet& pset);
0034
0035 virtual ~PopCon();
0036
0037 template <typename Source>
0038 void write(Source const& source);
0039
0040 private:
0041 cond::persistency::Session initialize();
0042 void finalize(Time_t lastTill);
0043
0044 private:
0045 edm::Service<cond::service::PoolDBOutputService> m_dbService;
0046
0047 cond::persistency::Session m_targetSession;
0048
0049 std::string m_targetConnectionString;
0050
0051 std::string m_authPath;
0052
0053 int m_authSys;
0054
0055 std::string m_record;
0056
0057 std::string m_payload_name;
0058
0059 bool m_LoggingOn;
0060
0061 std::string m_tag;
0062
0063 cond::TagInfo_t m_tagInfo;
0064
0065 cond::LogDBEntry_t m_logDBEntry;
0066
0067 bool m_close;
0068
0069 Time_t m_lastTill;
0070
0071 static constexpr const char* const s_version = "5.0";
0072 };
0073
0074 template <typename Source>
0075 void PopCon::write(Source const& source) {
0076 typedef typename Source::value_type value_type;
0077 typedef typename Source::Container Container;
0078
0079 std::pair<Container const*, std::string const> ret = source(initialize(), m_tagInfo, m_logDBEntry);
0080 Container const& iovs = *ret.first;
0081
0082 if (m_LoggingOn) {
0083 std::string msg("Nothing to transfer;");
0084 size_t niovs = iovs.size();
0085 if (niovs) {
0086 std::ostringstream s;
0087 if (niovs == 1) {
0088 s << "Since " << (*iovs.begin()).first << "; ";
0089 } else {
0090 s << "first payload Since " << (*iovs.begin()).first << ", "
0091 << "last payload Since " << (*iovs.rbegin()).first << "; ";
0092 }
0093 msg = s.str();
0094 }
0095 std::ostringstream s;
0096 s << "PopCon v" << s_version << "; " << msg << ret.second;
0097 m_dbService->setLogHeaderForRecord(m_record, source.id(), s.str());
0098 }
0099 for (const auto& it : iovs)
0100 edm::LogInfo("PopCon") << "Since " << it.first << std::endl;
0101
0102 m_dbService->writeMany(iovs, m_record);
0103
0104 finalize(iovs.empty() ? Time_t(0) : iovs.rbegin()->first);
0105 }
0106
0107 }
0108
0109 #endif