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 
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  return m_session->runInfoSchema().runInfoTable().getLastInserted();
44  }
45  return cond::time::MIN_VAL;
46  }
47 
49  const boost::posix_time::ptime& start,
50  const boost::posix_time::ptime& end) {
51  if (m_data.get())
52  m_data->runBuffer.push_back(std::tie(runNumber, start, end));
53  }
54 
56  const boost::posix_time::ptime& start,
57  const boost::posix_time::ptime& end) {
58  if (m_data.get())
59  m_data->updateBuffer.push_back(std::tie(runNumber, start, end));
60  }
61 
63  size_t ret = 0;
64  if (m_data.get()) {
65  checkTransaction("RunInfoEditor::flush");
66  m_session->runInfoSchema().runInfoTable().insert(m_data->runBuffer);
67  ret += m_data->runBuffer.size();
68  for (auto update : m_data->updateBuffer) {
69  cond::Time_t newRun = std::get<0>(update);
70  boost::posix_time::ptime& newRunStart = std::get<1>(update);
71  boost::posix_time::ptime& newRunEnd = std::get<2>(update);
72  boost::posix_time::ptime existingRunStart;
73  boost::posix_time::ptime existingRunEnd;
74  if (m_session->runInfoSchema().runInfoTable().select(newRun, existingRunStart, existingRunEnd)) {
75  if (newRunStart != existingRunStart) {
76  std::stringstream msg;
77  msg << "Attempt to update start time of existing run " << newRun;
78  throwException(msg.str(), "RunInfoEditor::flush");
79  }
80  if (existingRunEnd == newRunEnd) {
81  // nothing to do
82  continue;
83  } else {
84  if (existingRunEnd != existingRunStart) {
85  std::stringstream msg;
86  msg << "Attempt to update end time of existing run " << newRun;
87  throwException(msg.str(), "RunInfoEditor::flush");
88  }
89  }
90  m_session->runInfoSchema().runInfoTable().updateEnd(newRun, newRunEnd);
91  } else {
92  m_session->runInfoSchema().runInfoTable().insertOne(newRun, newRunStart, newRunEnd);
93  }
94  ret++;
95  }
96  m_data->runBuffer.clear();
97  m_data->updateBuffer.clear();
98  }
99  return ret;
100  }
101 
103  if (!m_session.get())
104  throwException("The session is not active.", ctx);
105  if (!m_session->isTransactionActive(false))
106  throwException("The transaction is not active.", ctx);
107  }
108 
109  } // namespace persistency
110 } // 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
#define end
Definition: vmac.h:39
tuple msg
Definition: mps_check.py:285
void checkTransaction(const std::string &ctx)
std::shared_ptr< RunInfoEditorData > m_data
Definition: RunInfoEditor.h:61
Definition: plugin.cc:23
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