CMS 3D CMS Logo

OnlineDBOutputService.h
Go to the documentation of this file.
1 #ifndef CondCore_OnlineDBOutputService_h
2 #define CondCore_OnlineDBOutputService_h
5 #include <string>
6 #include <map>
7 #include <fstream>
8 #include <mutex>
9 #include <chrono>
10 
11 //
12 // Package: DBOutputService
13 // Class : OnlineDBOutputService
14 //
18 //
19 // Author: Giacomo Govi
20 //
21 
22 namespace cond {
23 
25 
27 
28  namespace service {
29 
31  public:
33 
34  ~OnlineDBOutputService() override;
35 
36  template <typename PayloadType>
40  auto unpkLastTime = cond::time::unpack(lastTime);
41  cond::Time_t targetTime =
42  cond::time::lumiTime(unpkLastTime.first, unpkLastTime.second + m_latencyInLumisections);
44  logger().logInfo() << "Updating lumisection " << targetTime;
45  cond::Hash payloadId = PoolDBOutputService::writeOneIOV<PayloadType>(payload, targetTime, recordName);
47  if (payloadId.empty()) {
48  return 0;
49  }
51  auto w_lat = std::chrono::duration_cast<std::chrono::microseconds>(t1 - t0).count();
52  logger().logInfo() << "Update has taken " << w_lat << " microsecs.";
53  // check for late updates...
54  cond::Time_t lastProcessed = getLastLumiProcessed();
55  logger().logInfo() << "Last lumisection processed after update: " << lastProcessed;
56  // check the pre-loaded iov
57  logger().logInfo() << "Preloading lumisection " << targetTime;
59  cond::Iov_t usedIov = preLoadIov(rec, targetTime);
61  logger().logInfo() << "Iov for preloaded lumisection " << targetTime << " is " << usedIov.since;
62  auto p_lat = std::chrono::duration_cast<std::chrono::microseconds>(t3 - t2).count();
63  logger().logInfo() << "Preload has taken " << p_lat << " microsecs.";
64  if (usedIov.since < targetTime) {
65  logger().logWarning() << "Found a late update for lumisection " << targetTime << "(found since "
66  << usedIov.since << "). A revert is required.";
67  PoolDBOutputService::eraseSinceTime(payloadId, targetTime, recordName);
69  targetTime = 0;
70  }
72  auto t_lat = std::chrono::duration_cast<std::chrono::microseconds>(t4 - t0).count();
73  logger().logInfo() << "Total update time: " << t_lat << " microsecs.";
74  return targetTime;
75  }
76 
77  private:
79 
81 
82  private:
89  bool m_debug;
90 
91  }; //OnlineDBOutputService
92  } // namespace service
93 } // namespace cond
94 #endif
cond::Time_t getLastLumiFromOMS(const std::string &omsServiceUrl)
const Record & lookUpRecord(const std::string &recordName)
EchoedLogStream< edm::LogWarning > logWarning()
Definition: Logger.cc:169
Time_t since
Definition: Types.h:53
unsigned long long Time_t
Definition: Time.h:14
Time_t lumiTime(unsigned int run, unsigned int lumiId)
Definition: Time.cc:66
OnlineDBOutputService(const edm::ParameterSet &iConfig, edm::ActivityRegistry &iAR)
cond::persistency::Logger & logger()
cond::Time_t getLatestLumiFromFile(const std::string &fileName)
std::string Hash
Definition: Types.h:43
cond::Iov_t preLoadIov(const PoolDBOutputService::Record &record, cond::Time_t targetTime)
cond::Time_t writeIOVForNextLumisection(const PayloadType &payload, const std::string &recordName)
EchoedLogStream< edm::LogInfo > logInfo()
Definition: Logger.cc:157
void eraseSinceTime(const std::string &payloadId, cond::Time_t sinceTime, const std::string &recordName)
cond::UnpackedTime unpack(cond::Time_t iValue)