File indexing completed on 2024-09-07 04:35:25
0001 #ifndef CondCore_OnlineDBOutputService_h
0002 #define CondCore_OnlineDBOutputService_h
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0005 #include <string>
0006 #include <map>
0007 #include <fstream>
0008 #include <mutex>
0009 #include <chrono>
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 namespace cond {
0023
0024 cond::Time_t getLatestLumiFromFile(const std::string& fileName);
0025
0026 cond::Time_t getLastLumiFromOMS(const std::string& omsServiceUrl);
0027
0028 namespace service {
0029
0030 class OnlineDBOutputService : public PoolDBOutputService {
0031 public:
0032 OnlineDBOutputService(const edm::ParameterSet& iConfig, edm::ActivityRegistry& iAR);
0033
0034 ~OnlineDBOutputService() override;
0035
0036 template <typename PayloadType>
0037 cond::Time_t writeIOVForNextLumisection(const PayloadType& payload, const std::string& recordName) {
0038 auto& rec = PoolDBOutputService::lookUpRecord(recordName);
0039 cond::Time_t lastTime = getLastLumiProcessed();
0040 auto unpkLastTime = cond::time::unpack(lastTime);
0041 cond::Time_t targetTime =
0042 cond::time::lumiTime(unpkLastTime.first, unpkLastTime.second + m_latencyInLumisections);
0043 auto t0 = std::chrono::high_resolution_clock::now();
0044 logger().logInfo() << "Updating lumisection " << targetTime;
0045 cond::Hash payloadId = PoolDBOutputService::writeOneIOV<PayloadType>(payload, targetTime, recordName);
0046 PoolDBOutputService::commitTransaction();
0047 if (payloadId.empty()) {
0048 return 0;
0049 }
0050 auto t1 = std::chrono::high_resolution_clock::now();
0051 auto w_lat = std::chrono::duration_cast<std::chrono::microseconds>(t1 - t0).count();
0052 logger().logInfo() << "Update has taken " << w_lat << " microsecs.";
0053
0054 cond::Time_t lastProcessed = getLastLumiProcessed();
0055 logger().logInfo() << "Last lumisection processed after update: " << lastProcessed;
0056
0057 logger().logInfo() << "Preloading lumisection " << targetTime;
0058 auto t2 = std::chrono::high_resolution_clock::now();
0059 cond::Iov_t usedIov = preLoadIov(rec, targetTime);
0060 auto t3 = std::chrono::high_resolution_clock::now();
0061 logger().logInfo() << "Iov for preloaded lumisection " << targetTime << " is " << usedIov.since;
0062 auto p_lat = std::chrono::duration_cast<std::chrono::microseconds>(t3 - t2).count();
0063 logger().logInfo() << "Preload has taken " << p_lat << " microsecs.";
0064 if (usedIov.since < targetTime) {
0065 logger().logWarning() << "Found a late update for lumisection " << targetTime << "(found since "
0066 << usedIov.since << "). A revert is required.";
0067 PoolDBOutputService::eraseSinceTime(payloadId, targetTime, recordName);
0068 PoolDBOutputService::commitTransaction();
0069 targetTime = 0;
0070 }
0071 auto t4 = std::chrono::high_resolution_clock::now();
0072 auto t_lat = std::chrono::duration_cast<std::chrono::microseconds>(t4 - t0).count();
0073 logger().logInfo() << "Total update time: " << t_lat << " microsecs.";
0074 return targetTime;
0075 }
0076
0077 private:
0078 cond::Iov_t preLoadIov(const PoolDBOutputService::Record& record, cond::Time_t targetTime);
0079
0080 cond::Time_t getLastLumiProcessed();
0081
0082 private:
0083 cond::Time_t m_runNumber;
0084 size_t m_latencyInLumisections;
0085 std::string m_omsServiceUrl;
0086 std::string m_lastLumiFile;
0087 std::string m_preLoadConnectionString;
0088 std::string m_frontierKey;
0089 bool m_debug;
0090
0091 };
0092 }
0093 }
0094 #endif