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