CMS 3D CMS Logo

RunInfoEditor.cc
Go to the documentation of this file.
3 #include "SessionImpl.h"
4 //
5 
6 namespace cond {
7 
8  namespace persistency {
9 
10  // implementation details. holds only data.
12  public:
13  explicit RunInfoEditorData():
14  runBuffer(),
15  updateBuffer(){
16  }
17  // update buffers
18  std::vector<std::tuple<cond::Time_t,boost::posix_time::ptime,boost::posix_time::ptime> > runBuffer;
19  std::vector<std::tuple<cond::Time_t,boost::posix_time::ptime,boost::posix_time::ptime> > updateBuffer;
20  };
21 
23  m_data(),
24  m_session(){
25  }
26 
27  RunInfoEditor::RunInfoEditor( const std::shared_ptr<SessionImpl>& session ):
29  m_session( session ){
30 
31  }
32 
34  m_data( rhs.m_data ),
35  m_session( rhs.m_session ){
36  }
37 
39  m_data = rhs.m_data;
40  m_session = rhs.m_session;
41  return *this;
42  }
43 
45  if( m_data.get() ){
46  checkTransaction( "RunInfoEditor::init" );
47  if( !m_session->runInfoSchema().exists() ) m_session->runInfoSchema().create();
48  }
49  }
50 
52  if( m_data.get() ){
53  checkTransaction( "RunInfoEditor::getLastInserted" );
54  return m_session->runInfoSchema().runInfoTable().getLastInserted();
55  }
56  return cond::time::MIN_VAL;
57  }
58 
59  void RunInfoEditor::insert( cond::Time_t runNumber, const boost::posix_time::ptime& start, const boost::posix_time::ptime& end ){
60  if( m_data.get() ) m_data->runBuffer.push_back( std::tie( runNumber, start, end ) );
61  }
62 
63  void RunInfoEditor::insertNew( cond::Time_t runNumber, const boost::posix_time::ptime& start, const boost::posix_time::ptime& end){
64  if( m_data.get() ) m_data->updateBuffer.push_back( std::tie( runNumber, start, end ) );
65  }
66 
68  size_t ret = 0;
69  if( m_data.get() ){
70  checkTransaction( "RunInfoEditor::flush" );
71  m_session->runInfoSchema().runInfoTable().insert( m_data->runBuffer );
72  ret += m_data->runBuffer.size();
73  for( auto update: m_data->updateBuffer ) {
74  cond::Time_t newRun = std::get<0>(update);
75  boost::posix_time::ptime& newRunStart = std::get<1>(update);
76  boost::posix_time::ptime& newRunEnd = std::get<2>(update);
77  boost::posix_time::ptime existingRunStart;
78  boost::posix_time::ptime existingRunEnd;
79  if( m_session->runInfoSchema().runInfoTable().select( newRun, existingRunStart, existingRunEnd ) ){
80  if( newRunStart!=existingRunStart ) {
81  std::stringstream msg;
82  msg<< "Attempt to update start time of existing run "<< newRun;
83  throwException(msg.str(),"RunInfoEditor::flush");
84  }
85  if( existingRunEnd == newRunEnd ){
86  // nothing to do
87  continue;
88  } else {
89  if( existingRunEnd!=existingRunStart ){
90  std::stringstream msg;
91  msg<< "Attempt to update end time of existing run "<< newRun;
92  throwException(msg.str(),"RunInfoEditor::flush");
93  }
94  }
95  m_session->runInfoSchema().runInfoTable().updateEnd( newRun, newRunEnd );
96  } else {
97  m_session->runInfoSchema().runInfoTable().insertOne( newRun, newRunStart, newRunEnd );
98  }
99  ret++;
100  }
101  m_data->runBuffer.clear();
102  m_data->updateBuffer.clear();
103  }
104  return ret;
105  }
106 
108  if( !m_session.get() ) throwException("The session is not active.",ctx );
109  if( !m_session->isTransactionActive( false ) ) throwException("The transaction is not active.",ctx );
110  }
111 
112  }
113 }
Definition: start.py:1
void insert(cond::Time_t runNumber, const boost::posix_time::ptime &start, const boost::posix_time::ptime &end)
const Time_t MIN_VAL(0)
void insertNew(cond::Time_t runNumber, const boost::posix_time::ptime &start, const boost::posix_time::ptime &end)
std::vector< std::tuple< cond::Time_t, boost::posix_time::ptime, boost::posix_time::ptime > > updateBuffer
RunInfoEditor & operator=(const RunInfoEditor &rhs)
unsigned long long Time_t
Definition: Time.h:16
#define end
Definition: vmac.h:39
std::vector< std::tuple< cond::Time_t, boost::posix_time::ptime, boost::posix_time::ptime > > runBuffer
tuple msg
Definition: mps_check.py:285
void checkTransaction(const std::string &ctx)
std::shared_ptr< RunInfoEditorData > m_data
Definition: RunInfoEditor.h:60
Definition: plugin.cc:24
std::shared_ptr< SessionImpl > m_session
Definition: RunInfoEditor.h:61
#define update(a, b)
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:14