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
runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:355
cond::time::MIN_VAL
const Time_t MIN_VAL(0)
start
Definition: start.py:1
cond::persistency::RunInfoEditorData::RunInfoEditorData
RunInfoEditorData()
Definition: RunInfoEditor.cc:13
cond::persistency::RunInfoEditor::insert
void insert(cond::Time_t runNumber, const boost::posix_time::ptime &start, const boost::posix_time::ptime &end)
Definition: RunInfoEditor.cc:49
cond::persistency::RunInfoEditor::m_session
std::shared_ptr< SessionImpl > m_session
Definition: RunInfoEditor.h:62
mps_check.msg
tuple msg
Definition: mps_check.py:285
cond::persistency::RunInfoEditorData
Definition: RunInfoEditor.cc:11
end
#define end
Definition: vmac.h:39
convertSQLiteXML.runNumber
runNumber
Definition: convertSQLiteXML.py:91
cond::persistency::RunInfoEditor::init
void init()
Definition: RunInfoEditor.cc:32
cond::persistency::RunInfoEditor::getLastInserted
cond::Time_t getLastInserted()
Definition: RunInfoEditor.cc:40
cond::persistency::RunInfoEditor::flush
size_t flush()
Definition: RunInfoEditor.cc:63
Utils.h
SessionImpl.h
cond::persistency::RunInfoEditor::m_data
std::shared_ptr< RunInfoEditorData > m_data
Definition: RunInfoEditor.h:61
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
cond
Definition: plugin.cc:23
cond::Time_t
unsigned long long Time_t
Definition: Time.h:14
cond::persistency::RunInfoEditor
Definition: RunInfoEditor.h:28
cond::persistency::RunInfoEditorData::updateBuffer
std::vector< std::tuple< cond::Time_t, boost::posix_time::ptime, boost::posix_time::ptime > > updateBuffer
Definition: RunInfoEditor.cc:16
cond::persistency::RunInfoEditor::checkTransaction
void checkTransaction(const std::string &ctx)
Definition: RunInfoEditor.cc:103
cond::persistency::RunInfoEditorData::runBuffer
std::vector< std::tuple< cond::Time_t, boost::posix_time::ptime, boost::posix_time::ptime > > runBuffer
Definition: RunInfoEditor.cc:15
RunInfoEditor.h
cond::persistency::throwException
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:12
cond::persistency::RunInfoEditor::insertNew
void insertNew(cond::Time_t runNumber, const boost::posix_time::ptime &start, const boost::posix_time::ptime &end)
Definition: RunInfoEditor.cc:56
command_line.start
start
Definition: command_line.py:167
cond::persistency::RunInfoEditor::operator=
RunInfoEditor & operator=(const RunInfoEditor &rhs)
Definition: RunInfoEditor.cc:26
cond::persistency::RunInfoEditor::RunInfoEditor
RunInfoEditor()
Definition: RunInfoEditor.cc:19
update
#define update(a, b)
Definition: TrackClassifier.cc:10