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 
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  return run;
50  }
51 
53  cond::Time_t lower,
55  std::vector<std::tuple<cond::Time_t, boost::posix_time::ptime, boost::posix_time::ptime> >& runData) {
56  // first find the lowest existing run >= upper
57  Query<MIN_RUN_NUMBER> q0(m_schema);
58  q0.addCondition<RUN_NUMBER>(upper, ">=");
59  for (auto r : q0)
60  upper = std::get<0>(r);
61  // then find the inclusive range
63  q1.addCondition<RUN_NUMBER>(lower, ">=").addCondition<RUN_NUMBER>(upper, "<=");
64  size_t prevSize = runData.size();
65  for (auto r : q1) {
66  runData.push_back(r);
67  }
68  return runData.size() > prevSize;
69  }
70 
72  const boost::posix_time::ptime& lower,
73  const boost::posix_time::ptime& upper,
74  std::vector<std::tuple<cond::Time_t, boost::posix_time::ptime, boost::posix_time::ptime> >& runData) {
75  boost::posix_time::ptime up = upper;
76  // first find the lowest existing run >= upper
77  Query<START_TIME> q0(m_schema);
78  q0.addCondition<START_TIME>(upper, ">=");
79  bool found = q0.retrievedRows();
80  if (!found)
81  return false;
82  Query<MIN_START_TIME> q1(m_schema);
83  q1.addCondition<START_TIME>(upper, ">=");
84  for (auto r : q1)
85  up = std::get<0>(r);
86  // then find the inclusive range
88  q2.addCondition<END_TIME>(lower, ">=").addCondition<START_TIME>(up, "<=");
89  size_t prevSize = runData.size();
90  for (auto r : q2) {
91  runData.push_back(r);
92  }
93  return runData.size() > prevSize;
94  }
95 
96  //bool RUN_INFO::Table::getRunForTime( const boost::posix_time::ptime& time,
97  // cond::Time_t& runNumber, boost::posix_time::ptime& start, boost::posix_time::ptime& end ){
98  // Query< RUN_NUMBER, START_TIME, END_TIME > q(m_schema);
99  // q.addCondition< START_TIME >( upper,"<=" );
100  // }
101 
103  const boost::posix_time::ptime& start,
104  const boost::posix_time::ptime& end) {
106  insertInTable(m_schema, tname, dataToInsert.get());
107  }
108 
110  const std::vector<std::tuple<cond::Time_t, boost::posix_time::ptime, boost::posix_time::ptime> >& runs) {
112  for (auto run : runs)
113  inserter.insert(run);
114  inserter.flush();
115  }
116 
117  void RUN_INFO::Table::updateEnd(cond::Time_t runNumber, const boost::posix_time::ptime& end) {
119  buffer.setColumnData<END_TIME>(std::tie(end));
120  buffer.addWhereCondition<RUN_NUMBER>(runNumber);
121  updateTable(m_schema, tname, buffer);
122  }
123 
124  RunInfoSchema::RunInfoSchema(coral::ISchema& schema) : m_runInfoTable(schema) {}
125 
127  if (!m_runInfoTable.exists())
128  return false;
129  return true;
130  }
131 
133  bool created = false;
134  if (!exists()) {
136  created = true;
137  }
138  return created;
139  }
140 
142 
143  } // namespace persistency
144 } // namespace cond
runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:355
cond::persistency::RunInfoSchema::exists
bool exists() override
Definition: RunInfoSchema.cc:126
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:52
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:71
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:141
data-class-funcs.q
q
Definition: data-class-funcs.py:169
writedatasetfile.runs
runs
Definition: writedatasetfile.py:27
cond::persistency::BulkInserter::flush
void flush()
Definition: DbCore.h:693
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
end
#define end
Definition: vmac.h:39
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:337
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:109
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:601
q1
double q1[4]
Definition: TauolaWrapper.h:87
cond::persistency::BulkInserter::insert
void insert(const P &params)
Definition: DbCore.h:686
cond::persistency::RunInfoSchema::create
bool create() override
Definition: RunInfoSchema.cc:132
cond::persistency::TableDescription::setPrimaryKey
void setPrimaryKey()
Definition: DbCore.h:314
cond::Time_t
unsigned long long Time_t
Definition: Time.h:14
RunInfoSchema.h
cond::persistency::RunInfoSchema::RunInfoSchema
RunInfoSchema(coral::ISchema &schema)
Definition: RunInfoSchema.cc:124
cond::persistency::IRunInfoTable
Definition: IDbSchema.h:216
alignCSCRings.r
r
Definition: alignCSCRings.py:93
cond::persistency::RowBuffer
Definition: DbCore.h:174
writedatasetfile.run
run
Definition: writedatasetfile.py:27
cond::persistency::RowBuffer::get
const coral::AttributeList & get() const
Definition: DbCore.h:200
cond::persistency::TableDescription
Definition: DbCore.h:285
pileupCalc.upper
upper
Definition: pileupCalc.py:214
cond::persistency::Query
Definition: DbCore.h:403
cond::persistency::BulkInserter
Definition: DbCore.h:676
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:117
cond::persistency::RUN_INFO::Table::getLastInserted
cond::Time_t getLastInserted() override
Definition: RunInfoSchema.cc:36
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:102
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