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"))
144 if (iConfig.
exists(
"frontierKey")) {
150 if (iConfig.
exists(
"snapshotTime")) {
152 if (!snapshotTimeString.empty())
153 snapshotTime = boost::posix_time::time_from_string(snapshotTimeString);
157 if (iConfig.
exists(
"DBParameters")) {
164 std::map<std::string, cond::GTEntry_t> replacements;
165 std::map<std::string, boost::posix_time::ptime> specialSnapshots;
166 if (iConfig.
exists(
"toGet")) {
167 typedef std::vector<edm::ParameterSet>
Parameters;
169 for (Parameters::iterator itToGet =
toGet.begin(); itToGet !=
toGet.end(); ++itToGet) {
171 if (recordname.empty())
172 throw cond::Exception(
"ESSource: The record name has not been provided in a \"toGet\" entry.");
176 pfn = itToGet->getParameter<
std::string>(
"connect");
179 if (itToGet->exists(
"tag")) {
183 boost::posix_time::ptime tagSnapshotTime =
185 if (itToGet->exists(
"snapshotTime"))
186 tagSnapshotTime = boost::posix_time::time_from_string(itToGet->getParameter<
std::string>(
"snapshotTime"));
187 if (itToGet->exists(
"refreshTime")) {
192 std::string recordLabelKey = joinRecordAndLabel(recordname, labelname);
194 std::make_pair(recordLabelKey,
cond::GTEntry_t(std::make_tuple(recordname, labelname, fqTag))));
195 specialSnapshots.insert(std::make_pair(recordLabelKey, tagSnapshotTime));
200 std::vector<std::string> globaltagList;
201 std::vector<std::string> connectList;
202 std::vector<std::string> pfnPrefixList;
203 std::vector<std::string> pfnPostfixList;
219 TagCollection::iterator it;
223 std::map<std::string, cond::persistency::Session> sessions;
233 std::vector<std::unique_ptr<cond::DataProxyWrapperBase>> proxyWrappers(
m_tagCollection.size());
235 for (it = itBeg; it != itEnd; ++it) {
236 proxyWrappers[ipb++] = std::unique_ptr<cond::DataProxyWrapperBase>{
243 for (it = itBeg; it != itEnd; ++it) {
247 if (!tagParams.second.empty()) {
248 connStr = tagParams.second;
249 tag = tagParams.first;
251 std::map<std::string, cond::persistency::Session>::iterator
p = sessions.find(connStr);
253 if (
p == sessions.end()) {
255 std::tuple<std::string, std::string, std::string> connPars =
259 if ((dbService ==
"cms_orcon_prod" || dbService ==
"cms_orcon_adg") && dbAccount !=
"CMS_CONDITIONS")
261 <<
"[WARNING] You are reading tag \"" <<
tag <<
"\" from V1 account \"" << connStr
262 <<
"\". The concerned Conditions might be out of date." << std::endl;
265 sessions.insert(std::make_pair(connStr, nsess));
272 m_proxies.insert(std::make_pair(it->second.recordName(), proxy));
274 boost::posix_time::ptime tagSnapshotTime =
snapshotTime;
275 auto tagSnapshotIter = specialSnapshots.find(it->first);
276 if (tagSnapshotIter != specialSnapshots.end())
277 tagSnapshotTime = tagSnapshotIter->second;
280 tagSnapshotTime = boost::posix_time::ptime();
282 proxy->lateInit(nsess,
tag, tagSnapshotTime, it->second.recordLabel(), connStr, &
m_queue, &
m_mutex);
286 CondGetterFromESSource visitor(
m_proxies);
289 for (;
b !=
e;
b++) {
290 (*b).second->proxy(0)->loadMore(visitor);
304 std::vector<std::string>& listToFill,
305 const unsigned int listSize,
307 boost::split(listToFill, stringList, boost::is_any_of(
"|"), boost::token_compress_off);
309 if (listToFill.size() == 1) {
310 for (
unsigned int i = 1;
i < listSize; ++
i) {
311 listToFill.push_back(stringList);
315 else if (listSize != listToFill.size()) {
317 std::string(
"ESSource: number of global tag components does not match number of " +
type +
" strings"));
324 std::cout <<
"CondDBESSource Statistics" << std::endl
333 for (;
b !=
e;
b++) {
334 dumpInfo(
std::cout, (*b).first, *(*b).second);
352 edm::LogInfo(
"CondDBESSource") <<
"Getting data for record \"" << recordname <<
"\" to be consumed by "
354 <<
"; from CondDBESSource::setIntervalFor";
356 std::lock_guard<std::mutex> guard(
m_mutex);
372 bool refreshThisRecord =
false;
376 if (refreshThisRecord) {
378 defaultIovSize = iR->second;
379 minDiffTime = defaultIovSize;
382 bool doRefresh =
false;
385 std::map<std::string, cond::Time_t>::iterator iRec =
m_lastRecordRuns.find(recordname);
389 if (lastRecordRun > lastTime)
390 diffTime = lastRecordRun - lastTime;
391 if (diffTime >= minDiffTime) {
394 iRec->second = lastTime;
395 edm::LogInfo(
"CondDBESSource") <<
"Preparing refresh for record \"" << recordname
396 <<
"\" since there has been a transition from run/lumi " << lastRecordRun
397 <<
" to run/lumi " << lastTime <<
"; from CondDBESSource::setIntervalFor";
402 edm::LogInfo(
"CondDBESSource") <<
"Preparing refresh for record \"" << recordname <<
"\" for " << iTime.
eventID()
403 <<
", timestamp: " << iTime.
time().
value()
404 <<
"; from CondDBESSource::setIntervalFor";
407 edm::LogInfo(
"CondDBESSource") <<
"Though enabled, refresh not needed for record \"" << recordname <<
"\" for "
409 <<
"; from CondDBESSource::setIntervalFor";
412 edm::LogInfo(
"CondDBESSource") <<
"Forcing refresh for record \"" << recordname <<
"\" for " << iTime.
eventID()
413 <<
", timestamp: " << iTime.
time().
value()
414 <<
"; from CondDBESSource::setIntervalFor";
422 bool userTime =
true;
425 ProxyMap::const_iterator pmBegin =
m_proxies.lower_bound(recordname);
426 ProxyMap::const_iterator pmEnd =
m_proxies.upper_bound(recordname);
427 if (pmBegin == pmEnd) {
428 edm::LogInfo(
"CondDBESSource") <<
"No DataProxy (Pluging) found for record \"" << recordname
429 <<
"\"; from CondDBESSource::setIntervalFor";
433 for (ProxyMap::const_iterator pmIter = pmBegin; pmIter != pmEnd; ++pmIter) {
434 edm::LogInfo(
"CondDBESSource") <<
"Processing record \"" << recordname <<
"\" and label \""
435 << pmIter->second->label() <<
"\" for " << iTime.
eventID()
436 <<
", timestamp: " << iTime.
time().
value()
437 <<
"; from CondDBESSource::setIntervalFor";
439 timetype = (*pmIter).second->timeType();
442 userTime = (0 == abtime);
448 std::string recKey = joinRecordAndLabel(recordname, pmIter->second->label());
451 edm::LogInfo(
"CondDBESSource") <<
"No Tag found for record \"" << recordname <<
"\" and label \""
452 << pmIter->second->label() <<
"\"; from CondDBESSource::setIntervalFor";
459 <<
"Checking if the session must be closed and re-opened for getting correct conditions"
460 <<
"; from CondDBESSource::setIntervalFor";
461 std::stringstream transId;
468 if (!tagParams.second.empty())
469 connStr = tagParams.second;
471 if (refreshThisRecord) {
474 auto iSess = sessionPool->find(connStr);
476 if (iSess != sessionPool->end()) {
477 if (iSess->second.second != transId.str()) {
480 iSess->second.second = transId.str();
491 edm::LogInfo(
"CondDBESSource") <<
"Re-opening the session with connection string " << connStr
492 <<
" and new transaction Id " << transId.str()
493 <<
"; from CondDBESSource::setIntervalFor";
496 edm::LogInfo(
"CondDBESSource") <<
"Reconnecting to \"" << connStr <<
"\" for getting new payload for record \""
497 << recordname <<
"\" and label \"" << pmIter->second->label()
498 <<
"\" from IOV tag \"" << tcIter->second.tagName() <<
"\" to be consumed by "
500 <<
"; from CondDBESSource::setIntervalFor";
501 pmIter->second->session() = iSess->second.first;
502 pmIter->second->reload();
509 edm::LogInfo(
"CondDBESSource") <<
"Refreshing IOV sequence labeled by tag \"" << tcIter->second.tagName()
510 <<
"\" for getting new payload for record \"" << recordname <<
"\" and label \""
511 << pmIter->second->label() <<
"\" to be consumed by " << iTime.
eventID()
512 <<
", timestamp: " << iTime.
time().
value()
513 <<
"; from CondDBESSource::setIntervalFor";
514 pmIter->second->reload();
535 edm::LogInfo(
"CondDBESSource") <<
"Validity coming from IOV sequence for record \"" << recordname
536 <<
"\" and label \"" << pmIter->second->label() <<
"\": (" << validity.first <<
", "
538 << abtime <<
"; from CondDBESSource::setIntervalFor";
540 recordValidity.first =
std::max(recordValidity.first, validity.first);
541 recordValidity.second =
std::min(recordValidity.second, validity.second);
546 edm::LogInfo(
"CondDBESSource") <<
"Validity for record \"" << recordname
547 <<
"\" and the corresponding label(s) coming from Condition DB: ("
548 << recordValidity.first <<
", " << recordValidity.first
549 <<
") as the last IOV element in the IOV sequence is infinity"
550 <<
"; from CondDBESSource::setIntervalFor";
555 if ((!userTime) && recordValidity.second != 0) {
566 edm::LogInfo(
"CondDBESSource") <<
"Setting validity for record \"" << recordname
567 <<
"\" and corresponding label(s): starting at " << oInterval.
first().
eventID()
568 <<
", timestamp: " << oInterval.
first().
time().
value() <<
", ending at "
571 <<
"; from CondDBESSource::setIntervalFor";
581 ProxyMap::const_iterator
b =
m_proxies.lower_bound(recordname);
582 ProxyMap::const_iterator
e =
m_proxies.upper_bound(recordname);
584 edm::LogInfo(
"CondDBESSource") <<
"No DataProxy (Pluging) found for record \"" << recordname
585 <<
"\"; from CondDBESSource::registerProxies";
586 return keyedProxiesVector;
589 for (ProxyMap::const_iterator
p =
b;
p !=
e; ++
p) {
590 if (
nullptr != (*p).second.get()) {
593 keyedProxiesVector.emplace_back(
key, (*p).second->edmProxy(iovIndex));
596 return keyedProxiesVector;
601 ProxyMap::const_iterator
b =
m_proxies.lower_bound(recordname);
602 ProxyMap::const_iterator
e =
m_proxies.upper_bound(recordname);
603 for (ProxyMap::const_iterator
p =
b;
p !=
e; ++
p) {
605 p->second->initConcurrentIOVs(nConcurrentIOVs);
615 std::set<cond::GTEntry_t>& tagcoll,
617 if (!roottag.empty()) {
621 std::tuple<std::string, std::string, std::string> connPars =
623 if (std::get<2>(connPars) ==
"CMS_COND_31X_GLOBALTAG") {
625 <<
"[WARNING] You are reading Global Tag \"" << roottag
626 <<
"\" from V1 account \"CMS_COND_31X_GLOBALTAG\". The concerned Conditions might be out of date."
628 }
else if (roottag.rfind(
"::All") != std::string::npos && std::get<2>(connPars) ==
"CMS_CONDITIONS") {
629 edm::LogWarning(
"CondDBESSource") <<
"[WARNING] You are trying to read Global Tag \"" << roottag
630 <<
"\" - postfix \"::All\" should not be used for V2." << std::endl;
636 for (
const auto& gte : gtp) {
646 const std::vector<std::string>& prefixList,
647 const std::vector<std::string>& postfixList,
648 const std::vector<std::string>& roottagList,
649 std::map<std::string, cond::GTEntry_t>& replacement,
651 std::set<cond::GTEntry_t> tagcoll;
654 auto prefix = prefixList.begin();
655 auto postfix = postfixList.begin();
656 for (
auto roottag = roottagList.begin(); roottag != roottagList.end();
661 std::set<cond::GTEntry_t>::iterator tagCollIter;
662 std::set<cond::GTEntry_t>::iterator tagCollBegin = tagcoll.begin();
663 std::set<cond::GTEntry_t>::iterator tagCollEnd = tagcoll.end();
666 for (tagCollIter = tagCollBegin; tagCollIter != tagCollEnd; ++tagCollIter) {
667 std::string recordLabelKey = joinRecordAndLabel(tagCollIter->recordName(), tagCollIter->recordLabel());
668 std::map<std::string, cond::GTEntry_t>::iterator fid = replacement.find(recordLabelKey);
669 if (fid != replacement.end()) {
670 if (!fid->second.tagName().empty()) {
672 std::make_tuple(tagCollIter->recordName(), tagCollIter->recordLabel(), fid->second.tagName()));
674 edm::LogInfo(
"CondDBESSource") <<
"Replacing tag \"" << tagCollIter->tagName() <<
"\" for record \""
676 <<
"\" with tag " << tagMetadata.
tagName()
677 <<
"\"; from CondDBESSource::fillTagCollectionFromDB";
681 replacement.erase(fid);
686 std::map<std::string, cond::GTEntry_t>::iterator replacementIter;
687 std::map<std::string, cond::GTEntry_t>::iterator replacementBegin = replacement.begin();
688 std::map<std::string, cond::GTEntry_t>::iterator replacementEnd = replacement.end();
689 for (replacementIter = replacementBegin; replacementIter != replacementEnd; ++replacementIter) {
690 if (replacementIter->second.tagName().empty()) {
691 std::stringstream
msg;
692 msg <<
"ESSource: no tag provided for record " << replacementIter->second.recordName();
693 if (!replacementIter->second.recordLabel().empty())
694 msg <<
" and label " << replacementIter->second.recordLabel();