CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
37 
38  //
39  template <typename PayloadType>
40  bool writeIOVForNextLumisection(const PayloadType& payload, const std::string& recordName) {
43  logger().logInfo() << "Updating lumisection " << targetTime;
44  cond::Hash payloadId = PoolDBOutputService::writeOneIOV<PayloadType>(payload, targetTime, recordName);
45  bool ret = true;
46  if (payloadId.empty()) {
47  return false;
48  }
50  auto w_lat = std::chrono::duration_cast<std::chrono::microseconds>(t1 - t0).count();
51  logger().logInfo() << "Update has taken " << w_lat << " microsecs.";
52  // check for late updates...
53  cond::Time_t lastProcessed = getLastLumiProcessed();
54  logger().logInfo() << "Last lumisection processed after update: " << lastProcessed;
55  // check the pre-loaded iov
56  logger().logInfo() << "Preloading lumisection " << targetTime;
58  cond::Iov_t usedIov = preLoadIov(recordName, targetTime);
60  logger().logInfo() << "Iov for preloaded lumisection " << targetTime << " is " << usedIov.since;
61  auto p_lat = std::chrono::duration_cast<std::chrono::microseconds>(t3 - t2).count();
62  logger().logInfo() << "Preload has taken " << p_lat << " microsecs.";
63  if (usedIov.since < targetTime) {
64  logger().logWarning() << "Found a late update for lumisection " << targetTime << "(found since "
65  << usedIov.since << "). A revert is required.";
66  PoolDBOutputService::eraseSinceTime(payloadId, targetTime, recordName);
68  ret = false;
69  }
71  auto t_lat = std::chrono::duration_cast<std::chrono::microseconds>(t4 - t0).count();
72  logger().logInfo() << "Total update time: " << t_lat << " microsecs.";
73  return ret;
74  }
75 
76  //
77  template <typename PayloadType>
78  bool writeForNextLumisection(const PayloadType* payloadPtr, const std::string& recordName) {
79  if (!payloadPtr)
80  throwException("Provided payload pointer is invalid.", "OnlineDBOutputService::writeForNextLumisection");
81  std::unique_ptr<const PayloadType> payload(payloadPtr);
82  return writeForNextLumisection<PayloadType>(*payload, recordName);
83  }
84 
85  private:
87 
89 
90  private:
97  bool m_debug;
98 
99  }; //OnlineDBOutputService
100  } // namespace service
101 } // namespace cond
102 #endif
tuple ret
prodAgent to be discontinued
cond::Time_t getLastLumiFromOMS(const std::string &omsServiceUrl)
EchoedLogStream< edm::LogWarning > logWarning()
Definition: Logger.cc:169
Time_t since
Definition: Types.h:53
tuple recordName
Definition: align_cfg.py:66
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:18
unsigned long long Time_t
Definition: Time.h:14
OnlineDBOutputService(const edm::ParameterSet &iConfig, edm::ActivityRegistry &iAR)
cond::persistency::Logger & logger()
cond::Iov_t preLoadIov(const std::string &recordName, cond::Time_t targetTime)
cond::Time_t getLatestLumiFromFile(const std::string &fileName)
std::string Hash
Definition: Types.h:43
bool writeForNextLumisection(const PayloadType *payloadPtr, const std::string &recordName)
bool writeIOVForNextLumisection(const PayloadType &payload, const std::string &recordName)
cond::persistency::Session getReadOnlyCache(cond::Time_t targetTime)
EchoedLogStream< edm::LogInfo > logInfo()
Definition: Logger.cc:157
void eraseSinceTime(const std::string &payloadId, cond::Time_t sinceTime, const std::string &recordName)