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,
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) {
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
runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:542
cond::persistency::RunInfoSchema::exists
bool exists() override
Definition: RunInfoSchema.cc:121
cond::persistency::RUN_INFO::Table::getInclusiveRunRange
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
Definition: RunInfoSchema.cc:53
cond::time::MIN_VAL
const Time_t MIN_VAL(0)
start
Definition: start.py:1
cond::persistency::RUN_INFO::Table::getInclusiveTimeRange
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
Definition: RunInfoSchema.cc:72
cond::persistency::RUN_INFO::Table::select
bool select(cond::Time_t runNumber, boost::posix_time::ptime &start, boost::posix_time::ptime &end) override
Definition: RunInfoSchema.cc:23
Exception.h
cond::persistency::RunInfoSchema::runInfoTable
IRunInfoTable & runInfoTable() override
Definition: RunInfoSchema.cc:136
singleTopDQM_cfi.select
select
Definition: singleTopDQM_cfi.py:50
writedatasetfile.runs
runs
Definition: writedatasetfile.py:27
cond::persistency::BulkInserter::flush
void flush()
Definition: DbCore.h:694
cond::persistency::RUN_INFO::END_TIME
Definition: RunInfoSchema.h:16
newFWLiteAna.found
found
Definition: newFWLiteAna.py:118
cond::persistency::RUN_INFO::RUN_NUMBER
Definition: RunInfoSchema.h:14
cond::persistency::RUN_INFO::Table::create
void create() override
Definition: RunInfoSchema.cc:14
convertSQLiteXML.runNumber
runNumber
Definition: convertSQLiteXML.py:91
edmScanValgrind.buffer
buffer
Definition: edmScanValgrind.py:171
cond::persistency::RunInfoSchema::m_runInfoTable
RUN_INFO::Table m_runInfoTable
Definition: RunInfoSchema.h:78
cond::persistency::TableDescription::get
const coral::TableDescription & get()
Definition: DbCore.h:338
mps_fire.end
end
Definition: mps_fire.py:242
cond::persistency::RUN_INFO::Table::getLastInserted
cond::Time_t getLastInserted(boost::posix_time::ptime &start, boost::posix_time::ptime &end) override
Definition: RunInfoSchema.cc:36
cond::persistency::RUN_INFO::Table::Table
Table(coral::ISchema &schema)
Definition: RunInfoSchema.cc:10
q2
double q2[4]
Definition: TauolaWrapper.h:88
cond::persistency::RUN_INFO::Table::insert
void insert(const std::vector< std::tuple< cond::Time_t, boost::posix_time::ptime, boost::posix_time::ptime > > &runs) override
Definition: RunInfoSchema.cc:104
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
cond::persistency::RUN_INFO::tname
static constexpr char const * tname
Definition: RunInfoSchema.h:13
cond
Definition: plugin.cc:23
cond::persistency::UpdateBuffer
Definition: DbCore.h:602
q1
double q1[4]
Definition: TauolaWrapper.h:87
cond::persistency::BulkInserter::insert
void insert(const P &params)
Definition: DbCore.h:687
cond::persistency::RunInfoSchema::create
bool create() override
Definition: RunInfoSchema.cc:127
cond::persistency::TableDescription::setPrimaryKey
void setPrimaryKey()
Definition: DbCore.h:315
cond::Time_t
unsigned long long Time_t
Definition: Time.h:14
RunInfoSchema.h
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
cond::persistency::RunInfoSchema::RunInfoSchema
RunInfoSchema(coral::ISchema &schema)
Definition: RunInfoSchema.cc:119
submitPVResolutionJobs.q
q
Definition: submitPVResolutionJobs.py:84
cond::persistency::IRunInfoTable
Definition: IDbSchema.h:203
alignCSCRings.r
r
Definition: alignCSCRings.py:93
cond::persistency::RowBuffer
Definition: DbCore.h:175
writedatasetfile.run
run
Definition: writedatasetfile.py:27
cond::persistency::RowBuffer::get
const coral::AttributeList & get() const
Definition: DbCore.h:201
cond::persistency::TableDescription
Definition: DbCore.h:286
pileupCalc.upper
upper
Definition: pileupCalc.py:214
cond::persistency::Query
Definition: DbCore.h:404
cond::persistency::BulkInserter
Definition: DbCore.h:677
cond::persistency::throwException
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:12
cond::persistency::RUN_INFO::Table::updateEnd
void updateEnd(cond::Time_t runNumber, const boost::posix_time::ptime &end) override
Definition: RunInfoSchema.cc:112
cond::persistency::RUN_INFO::Table::insertOne
void insertOne(cond::Time_t runNumber, const boost::posix_time::ptime &start, const boost::posix_time::ptime &end) override
Definition: RunInfoSchema.cc:97
cond::persistency::RUN_INFO::START_TIME
Definition: RunInfoSchema.h:15
up
Definition: BitonicSort.h:7
SiStripMonitorCluster_cfi.q0
q0
Definition: SiStripMonitorCluster_cfi.py:241
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
cond::persistency::RUN_INFO::Table::exists
bool exists() override