CMS 3D CMS Logo

IOVEditor.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.
11  class IOVEditorData {
12  public:
13  explicit IOVEditorData()
14  : tag(""),
15  timeType(cond::invalid),
16  payloadType(""),
18  description(""),
19  iovBuffer(),
20  deleteBuffer(),
21  changes() {}
29  boost::posix_time::ptime creationTime;
30  bool change = false;
31  bool metadataChange = false;
32  bool exists = false;
33  // buffer for the iov sequence
34  std::vector<std::tuple<cond::Time_t, cond::Hash, boost::posix_time::ptime> > iovBuffer;
35  std::vector<std::tuple<cond::Time_t, cond::Hash> > deleteBuffer;
36  bool validationMode = false;
37  std::set<std::string> changes;
38  };
39 
40  IOVEditor::IOVEditor() : m_data(), m_session() {}
41 
42  IOVEditor::IOVEditor(const std::shared_ptr<SessionImpl>& session) : m_data(new IOVEditorData), m_session(session) {}
43 
44  IOVEditor::IOVEditor(const std::shared_ptr<SessionImpl>& session,
45  const std::string& tag,
46  cond::TimeType timeType,
47  const std::string& payloadObjectType,
48  cond::SynchronizationType synchronizationType,
49  const boost::posix_time::ptime& creationTime)
50  : m_data(new IOVEditorData), m_session(session) {
51  m_data->tag = tag;
52  m_data->timeType = timeType;
53  m_data->payloadType = payloadObjectType;
54  m_data->synchronizationType = synchronizationType;
55  m_data->creationTime = creationTime;
56  m_data->change = true;
57  m_data->metadataChange = true;
58  }
59 
60  IOVEditor::IOVEditor(const IOVEditor& rhs) : m_data(rhs.m_data), m_session(rhs.m_session) {}
61 
63  m_data = rhs.m_data;
64  m_session = rhs.m_session;
65  return *this;
66  }
67 
69  checkTransaction("IOVEditor::load");
70  // loads the current header data in memory
71  if (!m_session->iovSchema().tagTable().select(tag,
72  m_data->timeType,
73  m_data->payloadType,
74  m_data->synchronizationType,
75  m_data->endOfValidity,
76  m_data->lastValidatedTime)) {
77  cond::throwException("Tag \"" + tag + "\" has not been found in the database.", "IOVEditor::load");
78  }
79  m_data->tag = tag;
80  m_data->exists = true;
81  m_data->change = false;
82  }
83 
84  std::string IOVEditor::tag() const { return m_data.get() ? m_data->tag : ""; }
85 
86  cond::TimeType IOVEditor::timeType() const { return m_data.get() ? m_data->timeType : cond::invalid; }
87 
88  std::string IOVEditor::payloadType() const { return m_data.get() ? m_data->payloadType : ""; }
89 
91  return m_data.get() ? m_data->synchronizationType : cond::SYNCH_ANY;
92  }
93 
95  if (m_data.get()) {
96  m_data->synchronizationType = synchronizationType;
97  m_data->change = true;
98  m_data->changes.insert("SynchronizationType");
99  }
100  }
101 
102  cond::Time_t IOVEditor::endOfValidity() const { return m_data.get() ? m_data->endOfValidity : cond::time::MIN_VAL; }
103 
105  if (m_data.get()) {
106  m_data->endOfValidity = time;
107  m_data->change = true;
108  m_data->changes.insert("EndOfValidity");
109  }
110  }
111 
112  std::string IOVEditor::description() const { return m_data.get() ? m_data->description : ""; }
113 
115  if (m_data.get()) {
116  m_data->description = description;
117  m_data->metadataChange = true;
118  m_data->changes.insert("Description");
119  }
120  }
121 
123  return m_data.get() ? m_data->lastValidatedTime : cond::time::MIN_VAL;
124  }
125 
127  if (m_data.get()) {
128  m_data->lastValidatedTime = time;
129  m_data->change = true;
130  m_data->changes.insert("LastValidatedTime");
131  }
132  }
133 
135  if (m_data.get())
136  m_data->validationMode = true;
137  }
138 
139  void IOVEditor::insert(cond::Time_t since, const cond::Hash& payloadHash, bool checkType) {
140  boost::posix_time::ptime now = boost::posix_time::microsec_clock::universal_time();
141  insert(since, payloadHash, now, checkType);
142  }
143 
145  const cond::Hash& payloadHash,
146  const boost::posix_time::ptime& insertionTime,
147  bool) {
148  if (m_data.get()) {
149  // here the type check could be added
150  m_data->iovBuffer.push_back(std::tie(since, payloadHash, insertionTime));
151  }
152  }
153 
154  void IOVEditor::erase(cond::Time_t since, const cond::Hash& payloadHash) {
155  if (m_data.get()) {
156  m_data->deleteBuffer.push_back(std::tie(since, payloadHash));
157  }
158  }
159 
160  bool iovSorter(const std::tuple<cond::Time_t, cond::Hash, boost::posix_time::ptime>& f,
161  const std::tuple<cond::Time_t, cond::Hash, boost::posix_time::ptime>& s) {
162  return std::get<0>(f) < std::get<0>(s);
163  }
164 
165  bool IOVEditor::flush(const std::string& logText,
166  const boost::posix_time::ptime& operationTime,
167  bool forceInsertion) {
168  bool ret = false;
169  checkTransaction("IOVEditor::flush");
170  std::string lt = logText;
171  if (lt.empty())
172  lt = "-";
173  if (m_data->change || m_data->metadataChange) {
174  if (m_data->metadataChange && m_data->description.empty())
175  throwException("A non-empty description string is mandatory.", "IOVEditor::flush");
176  if (m_data->validationMode)
177  m_session->iovSchema().tagTable().setValidationMode();
178  if (!m_data->exists) {
179  // set the creation time ( only available in the migration from v1...)
180  if (m_data->creationTime.is_not_a_date_time())
181  m_data->creationTime = operationTime;
182  m_session->iovSchema().tagTable().insert(m_data->tag,
183  m_data->timeType,
184  m_data->payloadType,
185  m_data->synchronizationType,
186  m_data->endOfValidity,
187  m_data->description,
188  m_data->lastValidatedTime,
189  m_data->creationTime);
190  if (m_session->iovSchema().tagLogTable().exists())
191  m_session->iovSchema().tagLogTable().insert(m_data->tag,
192  m_data->creationTime,
193  cond::getUserName(),
194  cond::getHostName(),
195  cond::getCommand(),
196  std::string("New tag created."),
197  lt);
198  m_data->exists = true;
199  ret = true;
200  } else {
201  if (m_data->change) {
202  m_session->iovSchema().tagTable().update(m_data->tag,
203  m_data->synchronizationType,
204  m_data->endOfValidity,
205  m_data->lastValidatedTime,
206  operationTime);
207  }
208  if (m_data->metadataChange) {
209  m_session->iovSchema().tagTable().updateMetadata(m_data->tag, m_data->description, operationTime);
210  }
211  if (m_session->iovSchema().tagLogTable().exists()) {
212  std::string action("Tag header updated. Changes involve: ");
213  size_t i = 0;
214  for (const auto& c : m_data->changes) {
215  action += c;
216  if (i == (m_data->changes.size() - 1))
217  action += ".";
218  else
219  action += ", ";
220  i++;
221  }
222  m_session->iovSchema().tagLogTable().insert(
223  m_data->tag, operationTime, cond::getUserName(), cond::getHostName(), cond::getCommand(), action, lt);
224  }
225  ret = true;
226  }
227  m_data->change = false;
228  }
229  if (!m_data->iovBuffer.empty()) {
230  std::sort(m_data->iovBuffer.begin(), m_data->iovBuffer.end(), iovSorter);
231  cond::Time_t l = std::get<0>(m_data->iovBuffer.front());
232  //We do not allow for IOV updates (i.e. insertion in the past or overriding) on tags whose syncrosization is not "ANY" or "VALIDATION".
233  //This policy is stricter than the one deployed in the Condition Upload service,
234  //which allows insertions in the past or overriding for IOVs larger than the first condition safe run for HLT ("HLT"/"EXPRESS" synchronizations) and Tier0 ("PROMPT"/"PCL").
235  //This is intended: in the C++ API we have no way to determine the first condition safe runs.
236  if (!forceInsertion && m_data->synchronizationType != cond::SYNCH_ANY &&
237  m_data->synchronizationType != cond::SYNCH_VALIDATION) {
238  // retrieve the last since
239  cond::Time_t last = 0;
240  cond::Hash h;
241  boost::posix_time::ptime no_time;
242  m_session->iovSchema().iovTable().getLastIov(m_data->tag, no_time, last, h);
243  // check if the min iov is greater then the last since
244  if (l <= last) {
245  std::stringstream msg;
246  msg << "Can't insert iov since " << l << " on the tag " << m_data->tag << ": last since is " << last
247  << " and synchronization is \"" << cond::synchronizationTypeNames(m_data->synchronizationType) << "\"";
248  throwException(msg.str(), "IOVEditor::flush");
249  }
250  }
251  // set the insertion time ( only for the migration from v1 will be available... )
252  for (auto& iov : m_data->iovBuffer) {
253  boost::posix_time::ptime& insertionTime = std::get<2>(iov);
254  if (insertionTime.is_not_a_date_time())
255  insertionTime = operationTime;
256  }
257  // insert the new iovs
258  m_session->iovSchema().iovTable().insertMany(m_data->tag, m_data->iovBuffer);
259  ret = true;
260  }
261  if (!m_data->deleteBuffer.empty()) {
262  // delete the specified iovs
263  m_session->iovSchema().iovTable().eraseMany(m_data->tag, m_data->deleteBuffer);
264  ret = true;
265  }
266  if (m_session->iovSchema().tagLogTable().exists()) {
267  std::stringstream msg;
268  if (!m_data->iovBuffer.empty())
269  msg << m_data->iovBuffer.size() << " iov(s) inserted";
270  if (!msg.str().empty())
271  msg << "; ";
272  else
273  msg << ".";
274  if (!m_data->deleteBuffer.empty())
275  msg << m_data->deleteBuffer.size() << " iov(s) deleted.";
276  if (ret) {
277  m_session->iovSchema().tagLogTable().insert(
278  m_data->tag, operationTime, cond::getUserName(), cond::getHostName(), cond::getCommand(), msg.str(), lt);
279  }
280  }
281  m_data->iovBuffer.clear();
282  m_data->deleteBuffer.clear();
283  m_data->changes.clear();
284  return ret;
285  }
286 
287  bool IOVEditor::flush(const std::string& logText) {
288  return flush(logText, boost::posix_time::microsec_clock::universal_time(), false);
289  }
290 
291  bool IOVEditor::flush(const boost::posix_time::ptime& operationTime) {
292  return flush(std::string("-"), operationTime, false);
293  }
294 
296  return flush(std::string("-"), boost::posix_time::microsec_clock::universal_time(), false);
297  }
298 
299  bool IOVEditor::flush(const std::string& logText, bool forceInsertion) {
300  return flush(logText, boost::posix_time::microsec_clock::universal_time(), forceInsertion);
301  }
302 
304  if (!m_session.get())
305  throwException("The session is not active.", ctx);
306  if (!m_session->isTransactionActive(false))
307  throwException("The transaction is not active.", ctx);
308  }
309 
310  } // namespace persistency
311 } // namespace cond
runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:367
cond::time::MIN_VAL
const Time_t MIN_VAL(0)
cond::persistency::IOVEditorData::validationMode
bool validationMode
Definition: IOVEditor.cc:36
cond::persistency::IOVEditor::insert
void insert(cond::Time_t since, const cond::Hash &payloadHash, bool checkType=false)
Definition: IOVEditor.cc:139
cond::persistency::IOVEditorData::payloadType
std::string payloadType
Definition: IOVEditor.cc:24
cond::persistency::IOVEditorData::changes
std::set< std::string > changes
Definition: IOVEditor.cc:37
mps_fire.i
i
Definition: mps_fire.py:428
cond::TimeType
TimeType
Definition: Time.h:19
cond::persistency::IOVEditor::setLastValidatedTime
void setLastValidatedTime(cond::Time_t time)
Definition: IOVEditor.cc:126
cond::persistency::IOVEditorData::tag
std::string tag
Definition: IOVEditor.cc:22
cond::Hash
std::string Hash
Definition: Types.h:43
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
cond::persistency::IOVEditor::tag
std::string tag() const
Definition: IOVEditor.cc:84
submitPVValidationJobs.now
now
Definition: submitPVValidationJobs.py:639
cond::persistency::IOVEditorData::endOfValidity
cond::Time_t endOfValidity
Definition: IOVEditor.cc:27
h
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
Definition: L1TUtmAlgorithmRcd.h:4
edmLumisInFiles.description
description
Definition: edmLumisInFiles.py:11
cond::persistency::IOVEditorData::timeType
cond::TimeType timeType
Definition: IOVEditor.cc:23
cond::persistency::IOVEditor
Definition: IOVEditor.h:28
IOVEditor.h
mps_check.msg
tuple msg
Definition: mps_check.py:285
cond::persistency::IOVEditorData::description
std::string description
Definition: IOVEditor.cc:26
cond::SYNCH_VALIDATION
Definition: Types.h:29
cond::persistency::IOVEditorData::deleteBuffer
std::vector< std::tuple< cond::Time_t, cond::Hash > > deleteBuffer
Definition: IOVEditor.cc:35
cond::persistency::IOVEditorData
Definition: IOVEditor.cc:11
cond::synchronizationTypeNames
std::string synchronizationTypeNames(SynchronizationType type)
Definition: Types.cc:45
cond::persistency::IOVEditor::setValidationMode
void setValidationMode()
Definition: IOVEditor.cc:134
cond::persistency::IOVEditorData::synchronizationType
cond::SynchronizationType synchronizationType
Definition: IOVEditor.cc:25
cond::persistency::IOVEditorData::metadataChange
bool metadataChange
Definition: IOVEditor.cc:31
alignCSCRings.s
s
Definition: alignCSCRings.py:92
dqmdumpme.last
last
Definition: dqmdumpme.py:56
cond::SynchronizationType
SynchronizationType
Definition: Types.h:27
Utils.h
GlobalPosition_Frontier_DevDB_cff.tag
tag
Definition: GlobalPosition_Frontier_DevDB_cff.py:11
SessionImpl.h
cond::persistency::IOVEditor::m_session
std::shared_ptr< SessionImpl > m_session
Definition: IOVEditor.h:95
cond::persistency::IOVEditor::m_data
std::shared_ptr< IOVEditorData > m_data
Definition: IOVEditor.h:94
writeEcalDQMStatus.since
since
Definition: writeEcalDQMStatus.py:53
h
cond::persistency::IOVEditorData::IOVEditorData
IOVEditorData()
Definition: IOVEditor.cc:13
cond::persistency::IOVEditor::setDescription
void setDescription(const std::string &description)
Definition: IOVEditor.cc:114
cond::persistency::iovSorter
bool iovSorter(const std::tuple< cond::Time_t, cond::Hash, boost::posix_time::ptime > &f, const std::tuple< cond::Time_t, cond::Hash, boost::posix_time::ptime > &s)
Definition: IOVEditor.cc:160
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
cond::persistency::IOVEditorData::iovBuffer
std::vector< std::tuple< cond::Time_t, cond::Hash, boost::posix_time::ptime > > iovBuffer
Definition: IOVEditor.cc:34
cond
Definition: plugin.cc:23
createPayload.checkType
checkType
Definition: createPayload.py:383
cond::persistency::IOVEditorData::lastValidatedTime
cond::Time_t lastValidatedTime
Definition: IOVEditor.cc:28
cond::persistency::IOVEditor::timeType
cond::TimeType timeType() const
Definition: IOVEditor.cc:86
cond::SYNCH_ANY
Definition: Types.h:28
cond::persistency::IOVEditorData::exists
bool exists
Definition: IOVEditor.cc:32
cond::persistency::IOVEditor::description
std::string description() const
Definition: IOVEditor.cc:112
cond::persistency::IOVEditor::synchronizationType
cond::SynchronizationType synchronizationType() const
Definition: IOVEditor.cc:90
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())
writedatasetfile.action
action
Definition: writedatasetfile.py:8
cond::persistency::IOVEditor::IOVEditor
IOVEditor()
Definition: IOVEditor.cc:40
cond::persistency::IOVEditor::lastValidatedTime
cond::Time_t lastValidatedTime() const
Definition: IOVEditor.cc:122
BeamSpotPI::creationTime
Definition: BeamSpotPayloadInspectorHelper.h:43
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
cond::persistency::IOVEditor::payloadType
std::string payloadType() const
Definition: IOVEditor.cc:88
cond::invalid
Definition: Time.h:19
cond::persistency::IOVEditor::setSynchronizationType
void setSynchronizationType(cond::SynchronizationType synchronizationType)
Definition: IOVEditor.cc:94
cmsLHEtoEOSManager.l
l
Definition: cmsLHEtoEOSManager.py:204
cond::persistency::IOVEditor::checkTransaction
void checkTransaction(const std::string &ctx)
Definition: IOVEditor.cc:303
cond::persistency::IOVEditorData::change
bool change
Definition: IOVEditor.cc:30
cond::persistency::IOVEditor::setEndOfValidity
void setEndOfValidity(cond::Time_t validity)
Definition: IOVEditor.cc:104
cond::persistency::IOVEditor::operator=
IOVEditor & operator=(const IOVEditor &rhs)
Definition: IOVEditor.cc:62
cond::persistency::throwException
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:12
cond::persistency::IOVEditor::erase
void erase(cond::Time_t since, const cond::Hash &payloadHash)
Definition: IOVEditor.cc:154
cond::persistency::IOVEditorData::creationTime
boost::posix_time::ptime creationTime
Definition: IOVEditor.cc:29
ntuplemaker.time
time
Definition: ntuplemaker.py:310
cond::persistency::IOVEditor::flush
bool flush()
Definition: IOVEditor.cc:295
cond::persistency::IOVEditor::endOfValidity
cond::Time_t endOfValidity() const
Definition: IOVEditor.cc:102
cond::persistency::IOVEditor::load
void load(const std::string &tag)
Definition: IOVEditor.cc:68
cond::throwException
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:18