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 ):
11  m_schema( schema ){
12  }
13 
14  bool RUN_INFO::Table::Table::exists(){
15  return existsTable( m_schema, tname );
16  }
17 
19  if( exists() ){
20  throwException( "RUN_INFO table already exists in this schema.",
21  "RUN_INFO::Table::create");
22  }
24  descr.setPrimaryKey<RUN_NUMBER>();
25  createTable( m_schema, descr.get() );
26  }
27 
28  bool RUN_INFO::Table::select( cond::Time_t runNumber, boost::posix_time::ptime& start, boost::posix_time::ptime& end ){
31  bool ret = false;
32  for( auto r: q){
33  ret = true;
34  std::tie( start, end ) = r;
35  }
36  return ret;
37  }
38 
42  try{
43  for( auto r: q0 ) {
44  run = std::get<0>(r);
45  }
46  // cope with mis-beahviour in the sqlite plugin: no result for MAX() returns NULL
47  } catch ( const coral::AttributeException& e ){
48  std::string message(e.what());
49  if( message.find( "Attempt to access data of NULL attribute" ) != 0 ) throw;
50  }
51  return run;
52  }
53 
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
58  q0.addCondition< RUN_NUMBER >( upper,">=" );
59  for( auto r: q0 ) upper = std::get<0>(r);
60  // then find the inclusive range
62  q1.addCondition< RUN_NUMBER >( lower, ">=").addCondition< RUN_NUMBER >( upper, "<=");
63  size_t prevSize = runData.size();
64  for( auto r: q1 ){
65  runData.push_back( r );
66  }
67  return runData.size()>prevSize;
68  }
69 
70  bool RUN_INFO::Table::getInclusiveTimeRange( const boost::posix_time::ptime& lower ,const boost::posix_time::ptime& upper,
71  std::vector<std::tuple<cond::Time_t,boost::posix_time::ptime,boost::posix_time::ptime> >& runData ){
72  boost::posix_time::ptime up = upper;
73  // first find the lowest existing run >= upper
75  q0.addCondition< START_TIME >( upper,">=" );
76  for( auto r: q0 ) up = std::get<0>(r);
77  // then find the inclusive range
79  q1.addCondition< END_TIME >( lower, ">=").addCondition< START_TIME >( up, "<=");
80  size_t prevSize = runData.size();
81  for( auto r: q1 ){
82  runData.push_back( r );
83  }
84  return runData.size()>prevSize;
85  }
86 
87  void RUN_INFO::Table::insertOne( cond::Time_t runNumber, const boost::posix_time::ptime& start, const boost::posix_time::ptime& end){
88  RowBuffer< RUN_NUMBER, START_TIME, END_TIME > dataToInsert( std::tie(runNumber, start, end ) );
89  insertInTable( m_schema, tname, dataToInsert.get() );
90  }
91 
92  void RUN_INFO::Table::insert( const std::vector<std::tuple<cond::Time_t,boost::posix_time::ptime,boost::posix_time::ptime> >& runs ){
94  for( auto run : runs ) inserter.insert( run );
95  inserter.flush();
96  }
97 
98  void RUN_INFO::Table::updateEnd( cond::Time_t runNumber, const boost::posix_time::ptime& end ){
100  buffer.setColumnData< END_TIME >( std::tie( end ) );
102  updateTable( m_schema, tname, buffer );
103  }
104 
106  m_runInfoTable( schema ){
107  }
108 
110  if( !m_runInfoTable.exists() ) return false;
111  return true;
112  }
113 
115  bool created = false;
116  if( !exists() ){
118  created = true;
119  }
120  return created;
121  }
122 
124  return m_runInfoTable;
125  }
126 
127  }
128 }
129 
Definition: start.py:1
Definition: BitonicSort.h:8
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
const coral::TableDescription & get()
Definition: DbCore.h:262
const Time_t MIN_VAL(0)
void insert(const P &params)
Definition: DbCore.h:590
void updateEnd(cond::Time_t runNumber, const boost::posix_time::ptime &end) override
unsigned long long Time_t
Definition: Time.h:16
const coral::AttributeList & get() const
Definition: DbCore.h:167
static char const * tname
Definition: RunInfoSchema.h:13
cond::Time_t getLastInserted() override
Query & addCondition(const T &value, const std::string condition="=")
Definition: DbCore.h:425
#define end
Definition: vmac.h:39
void insertOne(cond::Time_t runNumber, const boost::posix_time::ptime &start, const boost::posix_time::ptime &end) override
void setColumnData(const Params &params)
Definition: DbCore.h:514
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
double q1[4]
Definition: TauolaWrapper.h:87
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)
Definition: plugin.cc:24
void addWhereCondition(const P &param, const std::string condition="=")
Definition: DbCore.h:523
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:14