CMS 3D CMS Logo

PoolDBOutputService.cc
Go to the documentation of this file.
10 //
11 #include <vector>
12 #include <memory>
13 #include <cassert>
14 
15 //In order to make PoolDBOutputService::currentTime() to work we have to keep track
16 // of which stream is presently being processed on a given thread during the call of
17 // a module which calls that method.
18 static thread_local int s_streamIndex = -1;
19 
21  Record thisrecord;
22 
23  thisrecord.m_idName = recordPset.getParameter<std::string>("record");
24  thisrecord.m_tag = recordPset.getParameter<std::string>("tag");
25 
26  thisrecord.m_timetype =
27  cond::time::timeTypeFromName(recordPset.getUntrackedParameter<std::string>("timetype", gTimeTypeStr));
28 
29  thisrecord.m_onlyAppendUpdatePolicy = recordPset.getUntrackedParameter<bool>("onlyAppendUpdatePolicy", false);
30 
31  m_records.insert(std::make_pair(thisrecord.m_idName, thisrecord));
32 
33  cond::UserLogInfo userloginfo;
34  m_logheaders.insert(std::make_pair(thisrecord.m_idName, userloginfo));
35 }
36 
38  : m_currentTimes{}, m_session(), m_transactionActive(false), m_dbInitialised(false), m_records(), m_logheaders() {
39  std::string timetypestr = iConfig.getUntrackedParameter<std::string>("timetype", "runnumber");
40  m_timetype = cond::time::timeTypeFromName(timetypestr);
41  m_autoCommit = iConfig.getUntrackedParameter<bool>("autoCommit", false);
42  m_writeTransactionDelay = iConfig.getUntrackedParameter<unsigned int>("writeTransactionDelay", 0);
43 
44  edm::ParameterSet connectionPset = iConfig.getParameter<edm::ParameterSet>("DBParameters");
45  m_connection.setParameters(connectionPset);
46  m_connection.configure();
47  std::string connectionString = iConfig.getParameter<std::string>("connect");
48  m_session = m_connection.createSession(connectionString, true);
49  // implicit start
50  doStartTransaction();
51 
52  typedef std::vector<edm::ParameterSet> Parameters;
53  Parameters toPut = iConfig.getParameter<Parameters>("toPut");
54  for (Parameters::iterator itToPut = toPut.begin(); itToPut != toPut.end(); ++itToPut)
55  fillRecord(*itToPut, timetypestr);
56 
57  iAR.watchPostEndJob(this, &cond::service::PoolDBOutputService::postEndJob);
58  iAR.watchPreallocate(
59  [this](edm::service::SystemBounds const& iBounds) { m_currentTimes.resize(iBounds.maxNumberOfStreams()); });
60  if (m_timetype == cond::timestamp) { //timestamp
62  iAR.watchPreModuleEvent(this, &cond::service::PoolDBOutputService::preModuleEvent);
63  iAR.watchPostModuleEvent(this, &cond::service::PoolDBOutputService::postModuleEvent);
64  } else if (m_timetype == cond::runnumber) { //runnumber
65  //NOTE: this assumes only one run is being processed at a time.
66  // This is true for 7_1_X but plan are to allow multiple in flight at a time
67  s_streamIndex = 0;
68  iAR.watchPreGlobalBeginRun(this, &cond::service::PoolDBOutputService::preGlobalBeginRun);
69  } else if (m_timetype == cond::lumiid) {
70  //NOTE: this assumes only one lumi is being processed at a time.
71  // This is true for 7_1_X but plan are to allow multiple in flight at a time
72  s_streamIndex = 0;
73  iAR.watchPreGlobalBeginLumi(this, &cond::service::PoolDBOutputService::preGlobalBeginLumi);
74  }
75 }
76 
78  const std::string& transactionId) {
80  ret = m_connection.createReadOnlySession(connectionString, transactionId);
81  return ret;
82 }
83 
85 
87  return this->lookUpRecord(recordName).m_tag;
88 }
89 
91  Record& myrecord = this->lookUpRecord(recordName);
92  return myrecord.m_isNewTag;
93 }
94 
96  if (!m_transactionActive) {
97  m_session.transaction().start(false);
98  m_transactionActive = true;
99  }
100 }
101 
103  if (m_transactionActive) {
104  m_session.transaction().commit();
105  m_transactionActive = false;
106  }
107 }
108 
110  std::lock_guard<std::recursive_mutex> lock(m_mutex);
111  doStartTransaction();
112 }
113 
115  std::lock_guard<std::recursive_mutex> lock(m_mutex);
116  doCommitTransaction();
117 }
118 
120  if (!m_dbInitialised) {
121  if (!m_session.existsDatabase())
122  m_session.createDatabase();
123  else {
124  for (auto& iR : m_records) {
125  if (m_session.existsIov(iR.second.m_tag))
126  iR.second.m_isNewTag = false;
127  }
128  }
129  m_dbInitialised = true;
130  }
131 }
132 
133 void cond::service::PoolDBOutputService::postEndJob() { commitTransaction(); }
134 
136  m_currentTimes[iContext.streamID().value()] = iContext.timestamp().value();
137 }
138 
140  edm::ModuleCallingContext const&) {
141  s_streamIndex = iContext.streamID().value();
142 }
143 
145  edm::ModuleCallingContext const&) {
146  s_streamIndex = -1;
147 }
148 
150  for (auto& time : m_currentTimes) {
151  time = iContext.luminosityBlockID().run();
152  }
153 }
154 
156  for (auto& time : m_currentTimes) {
157  time = iContext.luminosityBlockID().value();
158  }
159 }
160 
162 
164  std::lock_guard<std::recursive_mutex> lock(m_mutex);
165  doStartTransaction();
166  cond::persistency::TransactionScope scope(m_session.transaction());
167  try {
168  initDB();
169  } catch (const std::exception& er) {
170  cond::throwException(std::string(er.what()), "PoolDBOutputService::forceInit");
171  }
172  scope.close();
173 }
174 
176 
178 
180  assert(-1 != s_streamIndex);
181  return m_currentTimes[s_streamIndex];
182 }
183 
185  cond::Time_t firstSinceTime,
186  const std::string& recordName) {
187  std::lock_guard<std::recursive_mutex> lock(m_mutex);
188  Record& myrecord = this->lookUpRecord(recordName);
189  if (!myrecord.m_isNewTag) {
190  cond::throwException(myrecord.m_tag + " is not a new tag", "PoolDBOutputService::createNewIOV");
191  }
192  edm::LogInfo(MSGSOURCE) << "Creating new tag " << myrecord.m_tag << ", adding iov with since " << firstSinceTime
193  << " pointing to payload id " << firstPayloadId;
194  doStartTransaction();
195  cond::persistency::TransactionScope scope(m_session.transaction());
196  try {
197  this->initDB();
199  m_session.createIovForPayload(firstPayloadId, myrecord.m_tag, myrecord.m_timetype, cond::SYNCH_ANY);
200  editor.setDescription("New Tag");
201  editor.insert(firstSinceTime, firstPayloadId);
202  cond::UserLogInfo a = this->lookUpUserLogInfo(myrecord.m_idName);
203  editor.flush(a.usertext);
204  myrecord.m_isNewTag = false;
205  } catch (const std::exception& er) {
206  cond::throwException(std::string(er.what()), "PoolDBOutputService::createNewIov");
207  }
208  scope.close();
209 }
210 
212  const std::string payloadType,
213  cond::Time_t firstSinceTime,
214  Record& myrecord) {
215  edm::LogInfo(MSGSOURCE) << "Creating new tag " << myrecord.m_tag << " for payload type " << payloadType
216  << ", adding iov with since " << firstSinceTime;
217  // FIX ME: synchronization type and description have to be passed as the other parameters?
219  m_session.createIov(payloadType, myrecord.m_tag, myrecord.m_timetype, cond::SYNCH_ANY);
220  editor.setDescription("New Tag");
221  editor.insert(firstSinceTime, firstPayloadId);
222  cond::UserLogInfo a = this->lookUpUserLogInfo(myrecord.m_idName);
223  editor.flush(a.usertext);
224  myrecord.m_isNewTag = false;
225 }
226 
229  const std::string& recordName) {
230  std::lock_guard<std::recursive_mutex> lock(m_mutex);
231  Record& myrecord = this->lookUpRecord(recordName);
232  if (myrecord.m_isNewTag) {
233  cond::throwException(std::string("Cannot append to non-existing tag ") + myrecord.m_tag,
234  "PoolDBOutputService::appendSinceTime");
235  }
236  bool ret = false;
237  doStartTransaction();
238  cond::persistency::TransactionScope scope(m_session.transaction());
239  try {
240  ret = appendSinceTime(payloadId, time, myrecord);
241  } catch (const std::exception& er) {
242  cond::throwException(std::string(er.what()), "PoolDBOutputService::appendSinceTime");
243  }
244  scope.close();
245  return ret;
246 }
247 
250  Record& myrecord) {
251  edm::LogInfo(MSGSOURCE) << "Updating existing tag " << myrecord.m_tag << ", adding iov with since " << time;
253  try {
254  cond::persistency::IOVEditor editor = m_session.editIov(myrecord.m_tag);
255  payloadType = editor.payloadType();
256  editor.insert(time, payloadId);
257  cond::UserLogInfo a = this->lookUpUserLogInfo(myrecord.m_idName);
258  editor.flush(a.usertext);
259  } catch (const std::exception& er) {
260  cond::throwException(std::string(er.what()), "PoolDBOutputService::appendSinceTime");
261  }
262  return true;
263 }
264 
266  cond::Time_t sinceTime,
267  const std::string& recordName) {
268  std::lock_guard<std::recursive_mutex> lock(m_mutex);
269  Record& myrecord = this->lookUpRecord(recordName);
270  if (myrecord.m_isNewTag) {
271  cond::throwException(std::string("Cannot delete from non-existing tag ") + myrecord.m_tag,
272  "PoolDBOutputService::appendSinceTime");
273  }
274  edm::LogInfo(MSGSOURCE) << "Updating existing tag " << myrecord.m_tag << ", removing iov with since " << sinceTime
275  << " pointing to payload id " << payloadId;
276  doStartTransaction();
277  cond::persistency::TransactionScope scope(m_session.transaction());
278  try {
279  cond::persistency::IOVEditor editor = m_session.editIov(myrecord.m_tag);
280  editor.erase(sinceTime, payloadId);
281  cond::UserLogInfo a = this->lookUpUserLogInfo(recordName);
282  editor.flush(a.usertext);
283 
284  } catch (const std::exception& er) {
285  cond::throwException(std::string(er.what()), "PoolDBOutputService::eraseSinceTime");
286  }
287  scope.close();
288 }
289 
291  const std::string& recordName) {
292  std::map<std::string, Record>::iterator it = m_records.find(recordName);
293  if (it == m_records.end()) {
294  cond::throwException("The record \"" + recordName + "\" has not been registered.",
295  "PoolDBOutputService::lookUpRecord");
296  }
297  return it->second;
298 }
299 
301  std::map<std::string, cond::UserLogInfo>::iterator it = m_logheaders.find(recordName);
302  if (it == m_logheaders.end())
303  throw cond::Exception("Log db was not set for record " + recordName +
304  " from PoolDBOutputService::lookUpUserLogInfo");
305  return it->second;
306 }
307 
309  std::lock_guard<std::recursive_mutex> lock(m_mutex);
310  Record& myrecord = lookUpRecord(recordName);
311  if (myrecord.m_isNewTag) {
312  cond::throwException(std::string("Cannot close non-existing tag ") + myrecord.m_tag,
313  "PoolDBOutputService::closeIOV");
314  }
315  edm::LogInfo(MSGSOURCE) << "Updating existing tag " << myrecord.m_tag << ", closing with end of validity "
316  << lastTill;
317  doStartTransaction();
318  cond::persistency::TransactionScope scope(m_session.transaction());
319  try {
320  cond::persistency::IOVEditor editor = m_session.editIov(myrecord.m_tag);
321  editor.setEndOfValidity(lastTill);
322  editor.flush("Tag closed.");
323  } catch (const std::exception& er) {
324  cond::throwException(std::string(er.what()), "PoolDBOutputService::closeIOV");
325  }
326  scope.close();
327 }
328 
330  const std::string& dataprovenance,
331  const std::string& usertext) {
332  cond::UserLogInfo& myloginfo = this->lookUpUserLogInfo(recordName);
333  myloginfo.provenance = dataprovenance;
334  myloginfo.usertext = usertext;
335 }
336 
337 // Still required.
339  Record& record = lookUpRecord(recordName);
340  result.name = record.m_tag;
341  LogDebug(MSGSOURCE) << "Fetching tag info for " << record.m_tag;
342  doStartTransaction();
343  bool ret = false;
344  cond::persistency::TransactionScope scope(m_session.transaction());
345  try {
346  //use iovproxy to find out.
347  if (m_session.existsIov(record.m_tag)) {
348  cond::persistency::IOVProxy iov = m_session.readIov(record.m_tag);
349  result.lastInterval = iov.getLast();
350  ret = true;
351  }
352  } catch (const std::exception& er) {
353  cond::throwException(std::string(er.what()), "PoolDBOutputService::tagInfo");
354  }
355  scope.close();
356  return ret;
357 }
358 
359 // Still required.
361  std::lock_guard<std::recursive_mutex> lock(m_mutex);
362  return getTagInfo(recordName, result);
363 }
runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:355
edm::GlobalContext::luminosityBlockID
LuminosityBlockID const & luminosityBlockID() const
Definition: GlobalContext.h:55
cond::persistency::TransactionScope
Definition: Session.h:231
cond::service::PoolDBOutputService::Record::m_isNewTag
bool m_isNewTag
Definition: PoolDBOutputService.h:193
cond::service::PoolDBOutputService::lookUpRecord
Record & lookUpRecord(const std::string &recordName)
Definition: PoolDBOutputService.cc:290
cond::service::PoolDBOutputService::tag
std::string tag(const std::string &recordName)
Definition: PoolDBOutputService.cc:86
cond::persistency::IOVEditor::insert
void insert(cond::Time_t since, const cond::Hash &payloadHash, bool checkType=false)
Definition: IOVEditor.cc:139
cond::service::PoolDBOutputService::Record
Definition: PoolDBOutputService.h:187
cond::lumiid
Definition: Time.h:19
cond::service::PoolDBOutputService::initDB
void initDB()
Definition: PoolDBOutputService.cc:119
cond::TimeTypeSpecs::beginValue
Time_t beginValue
Definition: Time.h:41
cond::service::PoolDBOutputService::m_logheaders
std::map< std::string, cond::UserLogInfo > m_logheaders
Definition: PoolDBOutputService.h:246
cond::persistency::IOVProxy::getLast
cond::Iov_t getLast()
Definition: IOVProxy.cc:386
cond::service::PoolDBOutputService::beginOfTime
cond::Time_t beginOfTime() const
Definition: PoolDBOutputService.cc:177
Exception.h
s_streamIndex
static thread_local int s_streamIndex
Definition: PoolDBOutputService.cc:18
cond::service::PoolDBOutputService::eraseSinceTime
void eraseSinceTime(const std::string &payloadId, cond::Time_t sinceTime, const std::string &recordName)
Definition: PoolDBOutputService.cc:265
Exception.h
cond::service::PoolDBOutputService::Record::m_timetype
cond::TimeType m_timetype
Definition: PoolDBOutputService.h:195
align_cfg.recordName
recordName
Definition: align_cfg.py:66
cond::service::PoolDBOutputService::preModuleEvent
void preModuleEvent(edm::StreamContext const &, edm::ModuleCallingContext const &)
Definition: PoolDBOutputService.cc:139
cond::service::PoolDBOutputService::tagInfo
bool tagInfo(const std::string &recordName, cond::TagInfo_t &result)
Definition: PoolDBOutputService.cc:360
cond::persistency::IOVEditor
Definition: IOVEditor.h:28
cond::service::PoolDBOutputService::preGlobalBeginLumi
void preGlobalBeginLumi(edm::GlobalContext const &)
Definition: PoolDBOutputService.cc:155
edm::LogInfo
Definition: MessageLogger.h:254
GlobalPosition_Frontier_DevDB_cff.record
record
Definition: GlobalPosition_Frontier_DevDB_cff.py:10
cond::service::PoolDBOutputService::appendSinceTime
void appendSinceTime(const T *payloadObj, cond::Time_t sinceTime, const std::string &recordName)
Definition: PoolDBOutputService.h:132
cond::service::PoolDBOutputService::closeIOV
void closeIOV(Time_t lastTill, const std::string &recordName)
Definition: PoolDBOutputService.cc:308
cms::cuda::assert
assert(be >=bs)
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
edm::Timestamp::value
TimeValue_t value() const
Definition: Timestamp.h:45
edm::StreamID::value
unsigned int value() const
Definition: StreamID.h:42
cond::service::PoolDBOutputService::m_records
std::map< std::string, Record > m_records
Definition: PoolDBOutputService.h:245
cond::service::PoolDBOutputService::Record::m_idName
std::string m_idName
Definition: PoolDBOutputService.h:194
cond::timestamp
Definition: Time.h:19
PoolDBOutputService.h
cond::service::PoolDBOutputService::lookUpUserLogInfo
cond::UserLogInfo & lookUpUserLogInfo(const std::string &recordName)
Definition: PoolDBOutputService.cc:300
cond::timeTypeSpecs
const TimeTypeSpecs timeTypeSpecs[]
Definition: Time.cc:16
edm::StreamContext
Definition: StreamContext.h:31
cond::service::PoolDBOutputService::createNewIOV
void createNewIOV(const T *firstPayloadObj, cond::Time_t firstSinceTime, cond::Time_t, const std::string &recordName)
Definition: PoolDBOutputService.h:107
cond::service::PoolDBOutputService::session
cond::persistency::Session session() const
Definition: PoolDBOutputService.cc:84
cond::service::PoolDBOutputService::preEventProcessing
void preEventProcessing(edm::StreamContext const &)
Definition: PoolDBOutputService.cc:135
EventID.h
cond::service::PoolDBOutputService::Record::m_onlyAppendUpdatePolicy
bool m_onlyAppendUpdatePolicy
Definition: PoolDBOutputService.h:196
edm::ActivityRegistry
Definition: ActivityRegistry.h:132
cond::service::PoolDBOutputService::commitTransaction
void commitTransaction()
Definition: PoolDBOutputService.cc:114
cond::service::PoolDBOutputService::postEndJob
void postEndJob()
Definition: PoolDBOutputService.cc:133
cond::service::PoolDBOutputService::doStartTransaction
void doStartTransaction()
Definition: PoolDBOutputService.cc:95
cond::service::PoolDBOutputService::postModuleEvent
void postModuleEvent(edm::StreamContext const &, edm::ModuleCallingContext const &)
Definition: PoolDBOutputService.cc:144
cond::service::PoolDBOutputService::fillRecord
void fillRecord(edm::ParameterSet &pset, const std::string &gTimeTypeStr)
Definition: PoolDBOutputService.cc:20
cond::persistency::IOVEditor::setDescription
void setDescription(const std::string &description)
Definition: IOVEditor.cc:114
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
cond::persistency::IOVProxy
Definition: IOVProxy.h:92
cppFunctionSkipper.exception
exception
Definition: cppFunctionSkipper.py:10
edm::GlobalContext
Definition: GlobalContext.h:29
edm::service::SystemBounds
Definition: SystemBounds.h:29
cond::service::PoolDBOutputService::doCommitTransaction
void doCommitTransaction()
Definition: PoolDBOutputService.cc:102
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:670
edm::ParameterSet
Definition: ParameterSet.h:36
a
double a
Definition: hdecay.h:119
GlobalContext.h
Timestamp.h
cond::UserLogInfo::usertext
std::string usertext
Definition: Types.h:24
cond::SYNCH_ANY
Definition: Types.h:28
CommonMethods.lock
def lock()
Definition: CommonMethods.py:82
edm::StreamContext::streamID
StreamID const & streamID() const
Definition: StreamContext.h:54
cond::runnumber
Definition: Time.h:19
cond::persistency::Session
Definition: Session.h:63
cond::Time_t
unsigned long long Time_t
Definition: Time.h:14
cond::service::PoolDBOutputService::getTagInfo
bool getTagInfo(const std::string &recordName, cond::TagInfo_t &result)
Definition: PoolDBOutputService.cc:338
cond::persistency::Exception
Base exception class for the object to relational access.
Definition: Exception.h:11
cond::TimeTypeSpecs::endValue
Time_t endValue
Definition: Time.h:42
edm::service::SystemBounds::maxNumberOfStreams
unsigned int maxNumberOfStreams() const
Definition: SystemBounds.h:35
HLT_2018_cff.payloadType
payloadType
Definition: HLT_2018_cff.py:8133
DBConfiguration_cff.toPut
toPut
Definition: DBConfiguration_cff.py:25
edm::LuminosityBlockID::value
uint64_t value() const
Definition: LuminosityBlockID.cc:13
cond::persistency::IOVEditor::payloadType
std::string payloadType() const
Definition: IOVEditor.cc:88
cond::service::PoolDBOutputService::endOfTime
cond::Time_t endOfTime() const
Definition: PoolDBOutputService.cc:175
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
cond::service::PoolDBOutputService::setLogHeaderForRecord
void setLogHeaderForRecord(const std::string &recordName, const std::string &provenance, const std::string &usertext)
Definition: PoolDBOutputService.cc:329
cond::service::PoolDBOutputService::Record::m_tag
std::string m_tag
Definition: PoolDBOutputService.h:192
cond::persistency::IOVEditor::setEndOfValidity
void setEndOfValidity(cond::Time_t validity)
Definition: IOVEditor.cc:104
cond::UserLogInfo
Definition: Types.h:22
cond::service::PoolDBOutputService::isNewTagRequest
bool isNewTagRequest(const std::string &recordName)
Definition: PoolDBOutputService.cc:90
cond::time::timeTypeFromName
TimeType timeTypeFromName(const std::string &name)
Definition: Time.cc:25
cond::service::PoolDBOutputService::~PoolDBOutputService
virtual ~PoolDBOutputService()
Definition: PoolDBOutputService.cc:161
cond::service::PoolDBOutputService::newReadOnlySession
cond::persistency::Session newReadOnlySession(const std::string &connectionString, const std::string &transactionId)
Definition: PoolDBOutputService.cc:77
edm::LuminosityBlockID::run
RunNumber_t run() const
Definition: LuminosityBlockID.h:41
cond::persistency::IOVEditor::erase
void erase(cond::Time_t since, const cond::Hash &payloadHash)
Definition: IOVEditor.cc:154
edm::StreamContext::timestamp
Timestamp const & timestamp() const
Definition: StreamContext.h:62
mps_fire.result
result
Definition: mps_fire.py:303
cond::service::PoolDBOutputService::preGlobalBeginRun
void preGlobalBeginRun(edm::GlobalContext const &)
Definition: PoolDBOutputService.cc:149
ParameterSet.h
StreamContext.h
cond::TagInfo_t
Definition: Types.h:69
ntuplemaker.time
time
Definition: ntuplemaker.py:310
l1RCTOmdsFedVectorProducer_cfi.connectionString
connectionString
Definition: l1RCTOmdsFedVectorProducer_cfi.py:4
cond::persistency::IOVEditor::flush
bool flush()
Definition: IOVEditor.cc:295
Parameters
vector< ParameterSet > Parameters
Definition: HLTMuonPlotter.cc:25
cond::UserLogInfo::provenance
std::string provenance
Definition: Types.h:23
SystemBounds.h
cond::service::PoolDBOutputService::currentTime
cond::Time_t currentTime() const
Definition: PoolDBOutputService.cc:179
cond::service::PoolDBOutputService::startTransaction
void startTransaction()
Definition: PoolDBOutputService.cc:109
cond::service::PoolDBOutputService::forceInit
void forceInit()
Definition: PoolDBOutputService.cc:163
cond::service::PoolDBOutputService::PoolDBOutputService
PoolDBOutputService(const edm::ParameterSet &iConfig, edm::ActivityRegistry &iAR)
Definition: PoolDBOutputService.cc:37
cond::throwException
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:18
edm::ModuleCallingContext
Definition: ModuleCallingContext.h:29