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
void setDescription(const std::string &description)
Definition: GTEditor.cc:69
std::string name() const
Definition: GTEditor.cc:56
ret
prodAgent to be discontinued
const Time_t MIN_VAL(0)
std::string release() const
Definition: GTEditor.cc:76
void insert(const std::string &recordName, const std::string &tagName, bool checkType=false)
Definition: GTEditor.cc:96
std::vector< std::tuple< std::string, std::string, std::string > > tagListBuffer
Definition: GTEditor.cc:22
boost::posix_time::ptime snapshotTime() const
Definition: GTEditor.cc:85
std::string description() const
Definition: GTEditor.cc:67
std::shared_ptr< SessionImpl > m_session
Definition: GTEditor.h:82
unsigned long long Time_t
Definition: Time.h:14
void checkTransaction(const std::string &ctx)
Definition: GTEditor.cc:146
boost::posix_time::ptime snapshotTime
Definition: GTEditor.cc:18
void setSnapshotTime(const boost::posix_time::ptime &snapshotTime)
Definition: GTEditor.cc:89
GTEditor & operator=(const GTEditor &rhs)
Definition: GTEditor.cc:37
Definition: plugin.cc:23
cond::Time_t validity() const
Definition: GTEditor.cc:58
void load(const std::string &gtName)
Definition: GTEditor.cc:43
const Time_t MAX_VAL(std::numeric_limits< Time_t >::max())
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:12
void setRelease(const std::string &release)
Definition: GTEditor.cc:78
std::shared_ptr< GTEditorData > m_data
Definition: GTEditor.h:81
void setValidity(cond::Time_t validity)
Definition: GTEditor.cc:60