CMS 3D CMS Logo

OnlinePopCon.h
Go to the documentation of this file.
1 #ifndef CONDCORE_POPCON_ONLINEPOPCON_H
2 #define CONDCORE_POPCON_ONLINEPOPCON_H
3 
4 //
5 // Authors:
6 // - Francesco Brivio (Milano-Bicocca)
7 // - Jan Chyczynski (AGH University of Krakow)
8 //
9 
14 
15 #include <algorithm>
16 #include <functional>
17 #include <iostream>
18 #include <string>
19 #include <vector>
20 
21 namespace popcon {
22 
23  // Populator of the Condition DB.
24  // Specific implementation for online lumi-based conditions (OnlineDBOutputService)
25 
26  class OnlinePopCon {
27  public:
29 
31 
32  virtual ~OnlinePopCon();
33 
34  template <typename Source>
35  void write(Source const& source);
36 
37  private:
40  void finalize();
41 
42  private:
43  // DB service
45 
46  // PopCon infrastructure
50  int m_authSys;
54 
55  // OnlinePopCon specific
56  int m_dbLoggerReturn_; // DB logger return value
57  bool m_useLockRecors; // whether to lock the records or not
58 
59  // Version
60  static constexpr const char* const s_version = "1.0";
61  };
62 
63  template <typename Source>
65  // Get data to be uploaded
66  typedef typename Source::Container Container;
67  std::pair<Container const*, std::string const> ret = source(initialize(), m_tagInfo, m_logDBEntry);
68  Container const& iovs = *ret.first;
69 
70  // Check that only 1 iov/payload is provided
71  if (iovs.size() > 1) {
72  throw Exception("OnlinePopCon", "[write] More than one iov/payload provided!");
73  }
74 
75  // If zero payloads to transfer, finalize and return
76  if (iovs.empty()) {
77  m_dbService->logger().logInfo() << "OnlinePopCon::write - Nothing to transfer";
78  finalize();
79  return;
80  }
81 
82  // Upload
83  // Check if DB service is available
84  if (!m_dbService.isAvailable()) {
85  throw Exception("OnlinePopCon", "[write] DBService not available");
86  }
87 
88  // Get the only payload to transfer
89  auto [originalSince, payload] = *iovs.begin();
90 
91  // Log the original since
92  m_dbService->logger().logInfo() << "OnlinePopCon::write - original since: " << originalSince;
93 
94  // Upload the payload
95  try {
97  m_dbService->logger().logInfo() << "OnlinePopCon::write - writeForNextLumisection successful!";
98  m_dbService->logger().logInfo() << "OnlinePopCon::write - uploaded with since: " << targetSince;
99  } catch (const std::exception& e) {
100  m_dbService->logger().logError() << "OnlinePopCon::write - Error writing record: " << m_recordName;
101  m_dbService->logger().logError() << "Error is: " << e.what();
102  m_dbLoggerReturn_ = 2;
103  }
104 
105  // Finalize
106  finalize();
107  }
108 
109 } // namespace popcon
110 
111 #endif // CONDCORE_POPCON_ONLINEPOPCON_H
std::string m_authPath
Definition: OnlinePopCon.h:49
edm::Service< cond::service::OnlineDBOutputService > m_dbService
Definition: OnlinePopCon.h:44
cond::Time_t Time_t
Definition: OnlinePopCon.h:28
ret
prodAgent to be discontinued
void write(Source const &source)
Definition: OnlinePopCon.h:64
unsigned long long Time_t
Definition: Time.h:14
EchoedLogStream< edm::LogError > logError()
Definition: Logger.cc:165
cond::persistency::Logger & logger()
cond::persistency::Session initialize()
Definition: OnlinePopCon.cc:68
cond::Time_t writeIOVForNextLumisection(const PayloadType &payload, const std::string &recordName)
cond::persistency::Session m_targetSession
Definition: OnlinePopCon.h:47
cond::persistency::Session preparePopCon()
Definition: OnlinePopCon.cc:30
cond::TagInfo_t m_tagInfo
Definition: OnlinePopCon.h:52
bool isAvailable() const
Definition: Service.h:40
static constexpr const char *const s_version
Definition: OnlinePopCon.h:60
OnlinePopCon(const edm::ParameterSet &pset)
Definition: OnlinePopCon.cc:12
EchoedLogStream< edm::LogInfo > logInfo()
Definition: Logger.cc:157
std::string m_recordName
Definition: OnlinePopCon.h:51
edm::AssociationVector< reco::JetRefBaseProd, Values > Container
static std::string const source
Definition: EdmProvDump.cc:49
std::string m_targetConnectionString
Definition: OnlinePopCon.h:48
cond::LogDBEntry_t m_logDBEntry
Definition: OnlinePopCon.h:53