CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RunInfoUpdate.cc
Go to the documentation of this file.
4 
5 namespace {
6  boost::posix_time::ptime parseTimeFromIsoString(const std::string& isoString) {
7  boost::posix_time::time_input_facet* tif = new boost::posix_time::time_input_facet;
8  tif->set_iso_extended_format();
9  std::istringstream iss(isoString);
10  iss.imbue(std::locale(std::locale::classic(), tif));
11  boost::posix_time::ptime ret;
12  iss >> ret;
13  return ret;
14  }
15 
16  void getRunTimeParams(const RunInfo& runInfo, boost::posix_time::ptime& start, boost::posix_time::ptime& end) {
17  std::string startStr = runInfo.m_start_time_str;
18  if (startStr != "null") {
19  start = parseTimeFromIsoString(startStr);
20  }
21  end = start;
22  std::string stopStr = runInfo.m_stop_time_str;
23  if (stopStr != "null") {
24  end = parseTimeFromIsoString(stopStr);
25  }
26  }
27 } // namespace
28 
29 RunInfoUpdate::RunInfoUpdate(cond::persistency::Session& dbSession) : m_dbSession(dbSession) {}
30 
32 
33 void RunInfoUpdate::appendNewRun(const RunInfo& runInfo) {
35  boost::posix_time::ptime start;
36  boost::posix_time::ptime end;
37  getRunTimeParams(runInfo, start, end);
38  edm::LogInfo("RunInfoUpdate") << "[RunInfoUpdate::" << __func__ << "]: Checking run " << runInfo.m_run
39  << " for insertion in Condition DB" << std::endl;
40  runInfoWriter.insertNew(runInfo.m_run, start, end);
41  size_t newRuns = runInfoWriter.flush();
42  edm::LogInfo("RunInfoUpdate") << "[RunInfoUpdate::" << __func__ << "]: " << newRuns << " new run(s) inserted."
43  << std::endl;
44 }
45 
46 // only used in import command tool
47 size_t RunInfoUpdate::import(size_t maxEntries,
48  const std::string& sourceTag,
49  cond::persistency::Session& sourceSession) {
51  std::cout << "# Loading tag " << sourceTag << "..." << std::endl;
52  cond::persistency::IOVProxy runInfoTag = sourceSession.readIov(sourceTag);
53  auto iovs = runInfoTag.selectAll();
54  editor = m_dbSession.editRunInfo();
56  std::cout << "# Last run found in RunInfo db : " << lastRun << std::endl;
57  auto it = iovs.begin();
58  if (lastRun > 0) {
59  it = iovs.find(lastRun + 1);
60  }
61  if (it == iovs.end() || (*it).since == lastRun) {
62  std::cout << "# No more run found to be imported." << std::endl;
63  return 0;
64  }
65  size_t n_entries = 0;
66  while (it != iovs.end() && n_entries <= maxEntries) {
67  auto h = (*it).payloadId;
68  std::shared_ptr<RunInfo> runInfo = sourceSession.fetchPayload<RunInfo>(h);
69  if (runInfo->m_run != -1) {
70  n_entries++;
71  std::cout << "# Inserting run #" << runInfo->m_run << " (from since=" << (*it).since << ")" << std::endl;
72  boost::posix_time::ptime start;
73  boost::posix_time::ptime end;
74  getRunTimeParams(*runInfo, start, end);
75  editor.insert(runInfo->m_run, start, end);
76  } else {
77  std::cout << "# Skipping fake run #" << std::endl;
78  }
79  it++;
80  }
81  editor.flush();
82  return n_entries;
83 }
RunInfoUpdate(cond::persistency::Session &dbSession)
void insert(cond::Time_t runNumber, const boost::posix_time::ptime &start, const boost::posix_time::ptime &end)
tuple ret
prodAgent to be discontinued
RunInfoEditor editRunInfo()
Definition: Session.cc:210
void insertNew(cond::Time_t runNumber, const boost::posix_time::ptime &start, const boost::posix_time::ptime &end)
size_t import(size_t maxEntries, const std::string &tag, cond::persistency::Session &sourceSession)
std::unique_ptr< T > fetchPayload(const cond::Hash &payloadHash)
Definition: Session.h:213
unsigned long long Time_t
Definition: Time.h:14
std::string m_start_time_str
Definition: RunInfo.h:22
void appendNewRun(const RunInfo &run)
IOVProxy readIov(const std::string &tag)
Definition: Session.cc:63
Log< level::Info, false > LogInfo
cond::persistency::Session & m_dbSession
Definition: RunInfoUpdate.h:22
string end
Definition: dataset.py:937
std::string m_stop_time_str
Definition: RunInfo.h:24
tuple cout
Definition: gather_cfg.py:144
int m_run
Definition: RunInfo.h:20
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4