15 #include <boost/algorithm/string.hpp>
52 ~CondGetterFromESSource()
override {}
55 CondDBESSource::ProxyMap::const_iterator
p = m_proxies.find(
name);
56 if (
p != m_proxies.end())
57 return (*p).second->iovProxy();
82 out <<
"Time look up, payloadIds:" << std::endl;
83 const auto& pids = *proxy.
requests();
84 for (
const auto&
id : pids)
85 out <<
" " <<
id.since <<
" - " <<
id.till <<
" : " <<
id.payloadId << std::endl;
100 m_connectionString(
""),
105 m_doDump(iConfig.getUntrackedParameter<
bool>(
"DumpStat",
false)) {
119 Stats s = {0, 0, 0, 0, 0, 0, 0, 0};
125 if (iConfig.
exists(
"globaltag")) {
140 }
else if (iConfig.
exists(
"connect"))
148 if (iConfig.
exists(
"snapshotTime")) {
150 if (!snapshotTimeString.empty())
151 snapshotTime = boost::posix_time::time_from_string(snapshotTimeString);
155 if (iConfig.
exists(
"DBParameters")) {
162 std::map<std::string, cond::GTEntry_t> replacements;
163 std::map<std::string, boost::posix_time::ptime> specialSnapshots;
164 if (iConfig.
exists(
"toGet")) {
165 typedef std::vector<edm::ParameterSet>
Parameters;
167 for (Parameters::iterator itToGet =
toGet.begin(); itToGet !=
toGet.end(); ++itToGet) {
169 if (recordname.empty())
170 throw cond::Exception(
"ESSource: The record name has not been provided in a \"toGet\" entry.");
174 pfn = itToGet->getParameter<
std::string>(
"connect");
177 if (itToGet->exists(
"tag")) {
181 boost::posix_time::ptime tagSnapshotTime =
183 if (itToGet->exists(
"snapshotTime"))
184 tagSnapshotTime = boost::posix_time::time_from_string(itToGet->getParameter<
std::string>(
"snapshotTime"));
185 if (itToGet->exists(
"refreshTime")) {
190 std::string recordLabelKey = joinRecordAndLabel(recordname, labelname);
192 std::make_pair(recordLabelKey,
cond::GTEntry_t(std::make_tuple(recordname, labelname, fqTag))));
193 specialSnapshots.insert(std::make_pair(recordLabelKey, tagSnapshotTime));
198 std::vector<std::string> globaltagList;
199 std::vector<std::string> connectList;
200 std::vector<std::string> pfnPrefixList;
201 std::vector<std::string> pfnPostfixList;
217 TagCollection::iterator it;
221 std::map<std::string, cond::persistency::Session> sessions;
231 std::vector<std::unique_ptr<cond::DataProxyWrapperBase>> proxyWrappers(
m_tagCollection.size());
233 for (it = itBeg; it != itEnd; ++it) {
234 proxyWrappers[ipb++] = std::unique_ptr<cond::DataProxyWrapperBase>{
241 for (it = itBeg; it != itEnd; ++it) {
245 if (!tagParams.second.empty()) {
246 connStr = tagParams.second;
247 tag = tagParams.first;
249 std::map<std::string, cond::persistency::Session>::iterator
p = sessions.find(connStr);
251 if (
p == sessions.end()) {
253 std::tuple<std::string, std::string, std::string> connPars =
257 if ((dbService ==
"cms_orcon_prod" || dbService ==
"cms_orcon_adg") && dbAccount !=
"CMS_CONDITIONS")
259 <<
"[WARNING] You are reading tag \"" <<
tag <<
"\" from V1 account \"" << connStr
260 <<
"\". The concerned Conditions might be out of date." << std::endl;
263 sessions.insert(std::make_pair(connStr, nsess));
270 m_proxies.insert(std::make_pair(it->second.recordName(), proxy));
272 boost::posix_time::ptime tagSnapshotTime =
snapshotTime;
273 auto tagSnapshotIter = specialSnapshots.find(it->first);
274 if (tagSnapshotIter != specialSnapshots.end())
275 tagSnapshotTime = tagSnapshotIter->second;
278 tagSnapshotTime = boost::posix_time::ptime();
280 proxy->lateInit(nsess,
tag, tagSnapshotTime, it->second.recordLabel(), connStr, &
m_queue, &
m_mutex);
284 CondGetterFromESSource visitor(
m_proxies);
287 for (;
b !=
e;
b++) {
288 (*b).second->proxy(0)->loadMore(visitor);
302 std::vector<std::string>& listToFill,
303 const unsigned int listSize,
305 boost::split(listToFill, stringList, boost::is_any_of(
"|"), boost::token_compress_off);
307 if (listToFill.size() == 1) {
308 for (
unsigned int i = 1;
i < listSize; ++
i) {
309 listToFill.push_back(stringList);
313 else if (listSize != listToFill.size()) {
315 std::string(
"ESSource: number of global tag components does not match number of " +
type +
" strings"));
322 std::cout <<
"CondDBESSource Statistics" << std::endl
331 for (;
b !=
e;
b++) {
332 dumpInfo(
std::cout, (*b).first, *(*b).second);
350 edm::LogInfo(
"CondDBESSource") <<
"Getting data for record \"" << recordname <<
"\" to be consumed by "
352 <<
"; from CondDBESSource::setIntervalFor";
354 std::lock_guard<std::mutex> guard(
m_mutex);
370 bool refreshThisRecord =
false;
374 if (refreshThisRecord) {
376 defaultIovSize = iR->second;
377 minDiffTime = defaultIovSize;
380 bool doRefresh =
false;
383 std::map<std::string, cond::Time_t>::iterator iRec =
m_lastRecordRuns.find(recordname);
387 if (lastRecordRun > lastTime)
388 diffTime = lastRecordRun - lastTime;
389 if (diffTime >= minDiffTime) {
392 iRec->second = lastTime;
393 edm::LogInfo(
"CondDBESSource") <<
"Preparing refresh for record \"" << recordname
394 <<
"\" since there has been a transition from run/lumi " << lastRecordRun
395 <<
" to run/lumi " << lastTime <<
"; from CondDBESSource::setIntervalFor";
400 edm::LogInfo(
"CondDBESSource") <<
"Preparing refresh for record \"" << recordname <<
"\" for " << iTime.
eventID()
401 <<
", timestamp: " << iTime.
time().
value()
402 <<
"; from CondDBESSource::setIntervalFor";
405 edm::LogInfo(
"CondDBESSource") <<
"Though enabled, refresh not needed for record \"" << recordname <<
"\" for "
407 <<
"; from CondDBESSource::setIntervalFor";
410 edm::LogInfo(
"CondDBESSource") <<
"Forcing refresh for record \"" << recordname <<
"\" for " << iTime.
eventID()
411 <<
", timestamp: " << iTime.
time().
value()
412 <<
"; from CondDBESSource::setIntervalFor";
420 bool userTime =
true;
423 ProxyMap::const_iterator pmBegin =
m_proxies.lower_bound(recordname);
424 ProxyMap::const_iterator pmEnd =
m_proxies.upper_bound(recordname);
425 if (pmBegin == pmEnd) {
426 edm::LogInfo(
"CondDBESSource") <<
"No DataProxy (Pluging) found for record \"" << recordname
427 <<
"\"; from CondDBESSource::setIntervalFor";
431 for (ProxyMap::const_iterator pmIter = pmBegin; pmIter != pmEnd; ++pmIter) {
432 edm::LogInfo(
"CondDBESSource") <<
"Processing record \"" << recordname <<
"\" and label \""
433 << pmIter->second->label() <<
"\" for " << iTime.
eventID()
434 <<
", timestamp: " << iTime.
time().
value()
435 <<
"; from CondDBESSource::setIntervalFor";
437 timetype = (*pmIter).second->timeType();
440 userTime = (0 == abtime);
446 std::string recKey = joinRecordAndLabel(recordname, pmIter->second->label());
449 edm::LogInfo(
"CondDBESSource") <<
"No Tag found for record \"" << recordname <<
"\" and label \""
450 << pmIter->second->label() <<
"\"; from CondDBESSource::setIntervalFor";
457 <<
"Checking if the session must be closed and re-opened for getting correct conditions"
458 <<
"; from CondDBESSource::setIntervalFor";
459 std::stringstream transId;
466 if (!tagParams.second.empty())
467 connStr = tagParams.second;
469 if (refreshThisRecord) {
472 auto iSess = sessionPool->find(connStr);
474 if (iSess != sessionPool->end()) {
475 if (iSess->second.second != transId.str()) {
478 iSess->second.second = transId.str();
489 edm::LogInfo(
"CondDBESSource") <<
"Re-opening the session with connection string " << connStr
490 <<
" and new transaction Id " << transId.str()
491 <<
"; from CondDBESSource::setIntervalFor";
494 edm::LogInfo(
"CondDBESSource") <<
"Reconnecting to \"" << connStr <<
"\" for getting new payload for record \""
495 << recordname <<
"\" and label \"" << pmIter->second->label()
496 <<
"\" from IOV tag \"" << tcIter->second.tagName() <<
"\" to be consumed by "
498 <<
"; from CondDBESSource::setIntervalFor";
499 pmIter->second->session() = iSess->second.first;
500 pmIter->second->reload();
507 edm::LogInfo(
"CondDBESSource") <<
"Refreshing IOV sequence labeled by tag \"" << tcIter->second.tagName()
508 <<
"\" for getting new payload for record \"" << recordname <<
"\" and label \""
509 << pmIter->second->label() <<
"\" to be consumed by " << iTime.
eventID()
510 <<
", timestamp: " << iTime.
time().
value()
511 <<
"; from CondDBESSource::setIntervalFor";
512 pmIter->second->reload();
533 edm::LogInfo(
"CondDBESSource") <<
"Validity coming from IOV sequence for record \"" << recordname
534 <<
"\" and label \"" << pmIter->second->label() <<
"\": (" << validity.first <<
", "
536 << abtime <<
"; from CondDBESSource::setIntervalFor";
538 recordValidity.first =
std::max(recordValidity.first, validity.first);
539 recordValidity.second =
std::min(recordValidity.second, validity.second);
544 edm::LogInfo(
"CondDBESSource") <<
"Validity for record \"" << recordname
545 <<
"\" and the corresponding label(s) coming from Condition DB: ("
546 << recordValidity.first <<
", " << recordValidity.first
547 <<
") as the last IOV element in the IOV sequence is infinity"
548 <<
"; from CondDBESSource::setIntervalFor";
553 if ((!userTime) && recordValidity.second != 0) {
564 edm::LogInfo(
"CondDBESSource") <<
"Setting validity for record \"" << recordname
565 <<
"\" and corresponding label(s): starting at " << oInterval.
first().
eventID()
566 <<
", timestamp: " << oInterval.
first().
time().
value() <<
", ending at "
569 <<
"; from CondDBESSource::setIntervalFor";
579 ProxyMap::const_iterator
b =
m_proxies.lower_bound(recordname);
580 ProxyMap::const_iterator
e =
m_proxies.upper_bound(recordname);
582 edm::LogInfo(
"CondDBESSource") <<
"No DataProxy (Pluging) found for record \"" << recordname
583 <<
"\"; from CondDBESSource::registerProxies";
584 return keyedProxiesVector;
587 for (ProxyMap::const_iterator
p =
b;
p !=
e; ++
p) {
588 if (
nullptr != (*p).second.get()) {
591 keyedProxiesVector.emplace_back(
key, (*p).second->edmProxy(iovIndex));
594 return keyedProxiesVector;
599 ProxyMap::const_iterator
b =
m_proxies.lower_bound(recordname);
600 ProxyMap::const_iterator
e =
m_proxies.upper_bound(recordname);
601 for (ProxyMap::const_iterator
p =
b;
p !=
e; ++
p) {
603 p->second->initConcurrentIOVs(nConcurrentIOVs);
613 std::set<cond::GTEntry_t>& tagcoll,
615 if (!roottag.empty()) {
619 std::tuple<std::string, std::string, std::string> connPars =
621 if (std::get<2>(connPars) ==
"CMS_COND_31X_GLOBALTAG") {
623 <<
"[WARNING] You are reading Global Tag \"" << roottag
624 <<
"\" from V1 account \"CMS_COND_31X_GLOBALTAG\". The concerned Conditions might be out of date."
626 }
else if (roottag.rfind(
"::All") != std::string::npos && std::get<2>(connPars) ==
"CMS_CONDITIONS") {
627 edm::LogWarning(
"CondDBESSource") <<
"[WARNING] You are trying to read Global Tag \"" << roottag
628 <<
"\" - postfix \"::All\" should not be used for V2." << std::endl;
634 for (
const auto& gte : gtp) {
644 const std::vector<std::string>& prefixList,
645 const std::vector<std::string>& postfixList,
646 const std::vector<std::string>& roottagList,
647 std::map<std::string, cond::GTEntry_t>& replacement,
649 std::set<cond::GTEntry_t> tagcoll;
652 auto prefix = prefixList.begin();
653 auto postfix = postfixList.begin();
654 for (
auto roottag = roottagList.begin(); roottag != roottagList.end();
659 std::set<cond::GTEntry_t>::iterator tagCollIter;
660 std::set<cond::GTEntry_t>::iterator tagCollBegin = tagcoll.begin();
661 std::set<cond::GTEntry_t>::iterator tagCollEnd = tagcoll.end();
664 for (tagCollIter = tagCollBegin; tagCollIter != tagCollEnd; ++tagCollIter) {
665 std::string recordLabelKey = joinRecordAndLabel(tagCollIter->recordName(), tagCollIter->recordLabel());
666 std::map<std::string, cond::GTEntry_t>::iterator fid = replacement.find(recordLabelKey);
667 if (fid != replacement.end()) {
668 if (!fid->second.tagName().empty()) {
670 std::make_tuple(tagCollIter->recordName(), tagCollIter->recordLabel(), fid->second.tagName()));
672 edm::LogInfo(
"CondDBESSource") <<
"Replacing tag \"" << tagCollIter->tagName() <<
"\" for record \""
674 <<
"\" with tag " << tagMetadata.
tagName()
675 <<
"\"; from CondDBESSource::fillTagCollectionFromDB";
679 replacement.erase(fid);
684 std::map<std::string, cond::GTEntry_t>::iterator replacementIter;
685 std::map<std::string, cond::GTEntry_t>::iterator replacementBegin = replacement.begin();
686 std::map<std::string, cond::GTEntry_t>::iterator replacementEnd = replacement.end();
687 for (replacementIter = replacementBegin; replacementIter != replacementEnd; ++replacementIter) {
688 if (replacementIter->second.tagName().empty()) {
689 std::stringstream
msg;
690 msg <<
"ESSource: no tag provided for record " << replacementIter->second.recordName();
691 if (!replacementIter->second.recordLabel().empty())
692 msg <<
" and label " << replacementIter->second.recordLabel();