CMS 3D CMS Logo

RunInfoSchema.cc
Go to the documentation of this file.
2 #include "RunInfoSchema.h"
3 //
4 #include <openssl/sha.h>
5 
6 namespace cond {
7 
8  namespace persistency {
9 
10  RUN_INFO::Table::Table(coral::ISchema& schema) : m_schema(schema) {}
11 
12  bool RUN_INFO::Table::Table::exists() { return existsTable(m_schema, tname); }
13 
15  if (exists()) {
16  throwException("RUN_INFO table already exists in this schema.", "RUN_INFO::Table::create");
17  }
19  descr.setPrimaryKey<RUN_NUMBER>();
20  createTable(m_schema, descr.get());
21  }
22 
24  boost::posix_time::ptime& start,
25  boost::posix_time::ptime& end) {
27  q.addCondition<RUN_NUMBER>(runNumber);
28  bool ret = false;
29  for (auto r : q) {
30  ret = true;
31  std::tie(start, end) = r;
32  }
33  return ret;
34  }
35 
36  cond::Time_t RUN_INFO::Table::getLastInserted(boost::posix_time::ptime& start, boost::posix_time::ptime& end) {
38  Query<MAX_RUN_NUMBER> q0(m_schema);
39  try {
40  for (auto r : q0) {
41  run = std::get<0>(r);
42  }
43  // cope with mis-beahviour in the sqlite plugin: no result for MAX() returns NULL
44  } catch (const coral::AttributeException& e) {
45  std::string message(e.what());
46  if (message.find("Attempt to access data of NULL attribute") != 0)
47  throw;
48  }
49  select(run, start, end);
50  return run;
51  }
52 
54  cond::Time_t lower,
55  cond::Time_t upper,
56  std::vector<std::tuple<cond::Time_t, boost::posix_time::ptime, boost::posix_time::ptime> >& runData) {
57  // first find the lowest existing run >= upper
58  Query<MIN_RUN_NUMBER> q0(m_schema);
59  q0.addCondition<RUN_NUMBER>(upper, ">=");
60  for (auto r : q0)
61  upper = std::get<0>(r);
62  // then find the inclusive range
64  q1.addCondition<RUN_NUMBER>(lower, ">=").addCondition<RUN_NUMBER>(upper, "<=");
65  size_t prevSize = runData.size();
66  for (auto r : q1) {
67  runData.push_back(r);
68  }
69  return runData.size() > prevSize;
70  }
71 
73  const boost::posix_time::ptime& lower,
74  const boost::posix_time::ptime& upper,
75  std::vector<std::tuple<cond::Time_t, boost::posix_time::ptime, boost::posix_time::ptime> >& runData) {
76  boost::posix_time::ptime up = upper;
77  // first find the lowest existing run >= upper
78  Query<START_TIME> q0(m_schema);
79  q0.addCondition<START_TIME>(upper, ">=");
80  bool found = q0.retrievedRows();
81  if (!found)
82  return false;
83  Query<MIN_START_TIME> q1(m_schema);
84  q1.addCondition<START_TIME>(upper, ">=");
85  for (auto r : q1)
86  up = std::get<0>(r);
87  // then find the inclusive range
89  q2.addCondition<END_TIME>(lower, ">=").addCondition<START_TIME>(up, "<=");
90  size_t prevSize = runData.size();
91  for (auto r : q2) {
92  runData.push_back(r);
93  }
94  return runData.size() > prevSize;
95  }
96 
98  const boost::posix_time::ptime& start,
99  const boost::posix_time::ptime& end) {
100  RowBuffer<RUN_NUMBER, START_TIME, END_TIME> dataToInsert(std::tie(runNumber, start, end));
101  insertInTable(m_schema, tname, dataToInsert.get());
102  }
103 
105  const std::vector<std::tuple<cond::Time_t, boost::posix_time::ptime, boost::posix_time::ptime> >& runs) {
107  for (auto run : runs)
108  inserter.insert(run);
109  inserter.flush();
110  }
111 
112  void RUN_INFO::Table::updateEnd(cond::Time_t runNumber, const boost::posix_time::ptime& end) {
114  buffer.setColumnData<END_TIME>(std::tie(end));
115  buffer.addWhereCondition<RUN_NUMBER>(runNumber);
116  updateTable(m_schema, tname, buffer);
117  }
118 
119  RunInfoSchema::RunInfoSchema(coral::ISchema& schema) : m_runInfoTable(schema) {}
120 
122  if (!m_runInfoTable.exists())
123  return false;
124  return true;
125  }
126 
128  bool created = false;
129  if (!exists()) {
131  created = true;
132  }
133  return created;
134  }
135 
137 
138  } // namespace persistency
139 } // namespace cond
Definition: start.py:1
Definition: BitonicSort.h:7
bool getInclusiveRunRange(cond::Time_t lower, cond::Time_t upper, std::vector< std::tuple< cond::Time_t, boost::posix_time::ptime, boost::posix_time::ptime > > &runData) override
IRunInfoTable & runInfoTable() override
ret
prodAgent to be discontinued
const coral::TableDescription & get()
Definition: DbCore.h:338
const Time_t MIN_VAL(0)
void insert(const P &params)
Definition: DbCore.h:687
void updateEnd(cond::Time_t runNumber, const boost::posix_time::ptime &end) override
unsigned long long Time_t
Definition: Time.h:14
Query & addCondition(const T &value, const std::string condition="=")
Definition: DbCore.h:528
const coral::AttributeList & get() const
Definition: DbCore.h:201
static constexpr char const * tname
Definition: RunInfoSchema.h:13
void insertOne(cond::Time_t runNumber, const boost::posix_time::ptime &start, const boost::posix_time::ptime &end) override
bool select(cond::Time_t runNumber, boost::posix_time::ptime &start, boost::posix_time::ptime &end) override
void insert(const std::vector< std::tuple< cond::Time_t, boost::posix_time::ptime, boost::posix_time::ptime > > &runs) override
Table(coral::ISchema &schema)
bool getInclusiveTimeRange(const boost::posix_time::ptime &lower, const boost::posix_time::ptime &upper, std::vector< std::tuple< cond::Time_t, boost::posix_time::ptime, boost::posix_time::ptime > > &runData) override
RunInfoSchema(coral::ISchema &schema)
cond::Time_t getLastInserted(boost::posix_time::ptime &start, boost::posix_time::ptime &end) override
Definition: plugin.cc:23
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:12