CMS 3D CMS Logo

GTEditor.cc
Go to the documentation of this file.
2 #include "SessionImpl.h"
3 //
4 
5 namespace cond {
6 
7  namespace persistency {
8 
9  // GT data...
10  class GTEditorData {
11  public:
12  explicit GTEditorData() : name(""), description(""), release(""), snapshotTime(), tagListBuffer() {}
13  // GT data
18  boost::posix_time::ptime snapshotTime;
19  bool change = false;
20  bool exists = false;
21  // buffer for the GT tag map
22  std::vector<std::tuple<std::string, std::string, std::string> > tagListBuffer;
23  };
24 
25  GTEditor::GTEditor() : m_data(), m_session() {}
26 
27  GTEditor::GTEditor(const std::shared_ptr<SessionImpl>& session) : m_data(new GTEditorData), m_session(session) {}
28 
29  GTEditor::GTEditor(const std::shared_ptr<SessionImpl>& session, const std::string& gtName)
30  : m_data(new GTEditorData), m_session(session) {
31  m_data->name = gtName;
32  m_data->change = true;
33  }
34 
35  GTEditor::GTEditor(const GTEditor& rhs) : m_data(rhs.m_data), m_session(rhs.m_session) {}
36 
38  m_data = rhs.m_data;
39  m_session = rhs.m_session;
40  return *this;
41  }
42 
43  void GTEditor::load(const std::string& gtName) {
44  checkTransaction("GTEditor::load");
45 
46  // loads the current header data in memory
47  if (!m_session->gtSchema().gtTable().select(
48  gtName, m_data->validity, m_data->description, m_data->release, m_data->snapshotTime)) {
49  throwException("Global Tag \"" + gtName + "\" has not been found in the database.", "GTEditor::load");
50  }
51  m_data->name = gtName;
52  m_data->exists = true;
53  m_data->change = false;
54  }
55 
56  std::string GTEditor::name() const { return m_data.get() ? m_data->name : ""; }
57 
58  cond::Time_t GTEditor::validity() const { return m_data.get() ? m_data->validity : cond::time::MIN_VAL; }
59 
61  if (m_data.get()) {
62  m_data->validity = validity;
63  m_data->change = true;
64  }
65  }
66 
67  std::string GTEditor::description() const { return m_data.get() ? m_data->description : ""; }
68 
70  if (m_data.get()) {
71  m_data->description = description;
72  m_data->change = true;
73  }
74  }
75 
76  std::string GTEditor::release() const { return m_data.get() ? m_data->release : ""; }
77 
79  if (m_data.get()) {
80  m_data->release = release;
81  m_data->change = true;
82  }
83  }
84 
85  boost::posix_time::ptime GTEditor::snapshotTime() const {
86  return m_data.get() ? m_data->snapshotTime : boost::posix_time::ptime();
87  }
88 
89  void GTEditor::setSnapshotTime(const boost::posix_time::ptime& snapshotTime) {
90  if (m_data.get()) {
91  m_data->snapshotTime = snapshotTime;
92  m_data->change = true;
93  }
94  }
95 
98  }
99 
101  const std::string& recordLabel,
102  const std::string& tagName,
103  bool) {
104  if (m_data.get()) {
105  // here the type check could be added
106 
107  std::string rlabel = recordLabel;
108  if (rlabel.empty()) {
109  rlabel = "-";
110  }
111  m_data->tagListBuffer.push_back(std::tie(recordName, rlabel, tagName));
112  }
113  }
114 
115  bool GTEditor::flush(const boost::posix_time::ptime& operationTime) {
116  bool ret = false;
117  checkTransaction("GTEditor::flush");
118  if (m_data->change) {
119  if (m_data->description.empty())
120  throwException("A non-empty Description string is mandatory.", "GTEditor::flush");
121  if (m_data->release.empty())
122  throwException("A non-empty Release string is mandatory.", "GTEditor::flush");
123  if (!m_data->exists) {
124  m_session->gtSchema().gtTable().insert(
125  m_data->name, m_data->validity, m_data->description, m_data->release, m_data->snapshotTime, operationTime);
126  ret = true;
127  m_data->exists = true;
128  } else {
129  m_session->gtSchema().gtTable().update(
130  m_data->name, m_data->validity, m_data->description, m_data->release, m_data->snapshotTime, operationTime);
131  ret = true;
132  }
133  m_data->change = false;
134  }
135  if (!m_data->tagListBuffer.empty()) {
136  // insert the new iovs
137  m_session->gtSchema().gtMapTable().insert(m_data->name, m_data->tagListBuffer);
138  m_data->tagListBuffer.clear();
139  ret = true;
140  }
141  return ret;
142  }
143 
144  bool GTEditor::flush() { return flush(boost::posix_time::microsec_clock::universal_time()); }
145 
147  if (!m_session.get())
148  throwException("The session is not active.", ctx);
149  if (!m_session->isTransactionActive(false))
150  throwException("The transaction is not active.", ctx);
151  }
152 
153  } // namespace persistency
154 } // namespace cond
runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:543
cond::persistency::GTEditorData
Definition: GTEditor.cc:10
cond::time::MIN_VAL
const Time_t MIN_VAL(0)
cond::persistency::GTEditor::setRelease
void setRelease(const std::string &release)
Definition: GTEditor.cc:78
cond::persistency::GTEditor::insert
void insert(const std::string &recordName, const std::string &tagName, bool checkType=false)
Definition: GTEditor.cc:96
GTEditor.h
cond::persistency::GTEditorData::release
std::string release
Definition: GTEditor.cc:17
cond::persistency::GTEditorData::validity
cond::Time_t validity
Definition: GTEditor.cc:15
cond::persistency::GTEditor::snapshotTime
boost::posix_time::ptime snapshotTime() const
Definition: GTEditor.cc:85
cond::persistency::GTEditor::release
std::string release() const
Definition: GTEditor.cc:76
align_cfg.recordName
recordName
Definition: align_cfg.py:66
edmLumisInFiles.description
description
Definition: edmLumisInFiles.py:11
loadRecoTauTagMVAsFromPrepDB_cfi.snapshotTime
snapshotTime
Definition: loadRecoTauTagMVAsFromPrepDB_cfi.py:10
cond::persistency::GTEditor::setValidity
void setValidity(cond::Time_t validity)
Definition: GTEditor.cc:60
cond::persistency::GTEditorData::snapshotTime
boost::posix_time::ptime snapshotTime
Definition: GTEditor.cc:18
cond::persistency::GTEditor::GTEditor
GTEditor()
Definition: GTEditor.cc:25
cond::persistency::GTEditor::load
void load(const std::string &gtName)
Definition: GTEditor.cc:43
cond::persistency::GTEditor::checkTransaction
void checkTransaction(const std::string &ctx)
Definition: GTEditor.cc:146
cond::persistency::GTEditor::description
std::string description() const
Definition: GTEditor.cc:67
SessionImpl.h
cond::persistency::GTEditorData::tagListBuffer
std::vector< std::tuple< std::string, std::string, std::string > > tagListBuffer
Definition: GTEditor.cc:22
cond::persistency::GTEditor::m_session
std::shared_ptr< SessionImpl > m_session
Definition: GTEditor.h:82
cond
Definition: plugin.cc:23
cond::persistency::GTEditor
Definition: GTEditor.h:28
HLT_FULL_cff.recordLabel
recordLabel
Definition: HLT_FULL_cff.py:6769
createPayload.checkType
checkType
Definition: createPayload.py:383
fetchall_from_DQM_v2.release
release
Definition: fetchall_from_DQM_v2.py:92
cond::persistency::GTEditor::setSnapshotTime
void setSnapshotTime(const boost::posix_time::ptime &snapshotTime)
Definition: GTEditor.cc:89
cond::Time_t
unsigned long long Time_t
Definition: Time.h:14
cond::time::MAX_VAL
const Time_t MAX_VAL(std::numeric_limits< Time_t >::max())
cond::persistency::GTEditorData::description
std::string description
Definition: GTEditor.cc:16
cond::persistency::GTEditor::flush
bool flush()
Definition: GTEditor.cc:144
cond::persistency::GTEditorData::exists
bool exists
Definition: GTEditor.cc:20
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
cond::persistency::GTEditorData::GTEditorData
GTEditorData()
Definition: GTEditor.cc:12
cond::persistency::GTEditorData::change
bool change
Definition: GTEditor.cc:19
cond::persistency::GTEditor::validity
cond::Time_t validity() const
Definition: GTEditor.cc:58
cond::persistency::GTEditor::setDescription
void setDescription(const std::string &description)
Definition: GTEditor.cc:69
cond::persistency::GTEditor::m_data
std::shared_ptr< GTEditorData > m_data
Definition: GTEditor.h:81
cond::persistency::GTEditor::name
std::string name() const
Definition: GTEditor.cc:56
cond::persistency::GTEditor::operator=
GTEditor & operator=(const GTEditor &rhs)
Definition: GTEditor.cc:37
cond::persistency::throwException
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:12
cond::persistency::GTEditorData::name
std::string name
Definition: GTEditor.cc:14
JetPartonCorrections_cff.tagName
tagName
Definition: JetPartonCorrections_cff.py:12