15 #include <boost/algorithm/string.hpp>
50 ~CondGetterFromESSource()
override {}
53 CondDBESSource::ProxyMap::const_iterator
p = m_proxies.find(
name);
54 if (
p != m_proxies.end())
55 return (*p).second->iovProxy();
80 out <<
"Time look up, payloadIds:" << std::endl;
81 const auto& pids = *proxy.
requests();
83 out <<
" " <<
id.since <<
" - " <<
id.till <<
" : " <<
id.payloadId << std::endl;
98 m_connectionString(
""),
102 m_doDump(iConfig.getUntrackedParameter<
bool>(
"DumpStat",
false)) {
116 Stats s = {0, 0, 0, 0, 0, 0, 0, 0};
122 if (iConfig.
exists(
"globaltag")) {
126 }
else if (iConfig.
exists(
"connect"))
131 if (iConfig.
exists(
"snapshotTime")) {
133 if (!snapshotTimeString.empty())
134 snapshotTime = boost::posix_time::time_from_string(snapshotTimeString);
138 if (iConfig.
exists(
"DBParameters")) {
145 std::map<std::string, cond::GTEntry_t> replacements;
146 std::map<std::string, boost::posix_time::ptime> specialSnapshots;
147 if (iConfig.
exists(
"toGet")) {
148 typedef std::vector<edm::ParameterSet>
Parameters;
150 for (Parameters::iterator itToGet =
toGet.begin(); itToGet !=
toGet.end(); ++itToGet) {
152 if (recordname.empty())
153 throw cond::Exception(
"ESSource: The record name has not been provided in a \"toGet\" entry.");
157 pfn = itToGet->getParameter<
std::string>(
"connect");
160 if (itToGet->exists(
"tag")) {
164 boost::posix_time::ptime tagSnapshotTime =
166 if (itToGet->exists(
"snapshotTime"))
167 tagSnapshotTime = boost::posix_time::time_from_string(itToGet->getParameter<
std::string>(
"snapshotTime"));
168 if (itToGet->exists(
"refreshTime")) {
169 cond::Time_t refreshTime = itToGet->getParameter<
unsigned long long>(
"refreshTime");
173 std::string recordLabelKey = joinRecordAndLabel(recordname, labelname);
175 std::make_pair(recordLabelKey,
cond::GTEntry_t(std::make_tuple(recordname, labelname, fqTag))));
176 specialSnapshots.insert(std::make_pair(recordLabelKey, tagSnapshotTime));
181 std::vector<std::string> globaltagList;
182 std::vector<std::string> connectList;
183 std::vector<std::string> pfnPrefixList;
184 std::vector<std::string> pfnPostfixList;
200 TagCollection::iterator it;
204 std::map<std::string, cond::persistency::Session> sessions;
214 std::vector<std::unique_ptr<cond::DataProxyWrapperBase>> proxyWrappers(
m_tagCollection.size());
216 for (it = itBeg; it != itEnd; ++it) {
217 proxyWrappers[ipb++] = std::unique_ptr<cond::DataProxyWrapperBase>{
224 for (it = itBeg; it != itEnd; ++it) {
228 if (!tagParams.second.empty()) {
229 connStr = tagParams.second;
230 tag = tagParams.first;
232 std::map<std::string, cond::persistency::Session>::iterator
p = sessions.find(connStr);
234 if (
p == sessions.end()) {
236 std::tuple<std::string, std::string, std::string> connPars =
240 if ((dbService ==
"cms_orcon_prod" || dbService ==
"cms_orcon_adg") && dbAccount !=
"CMS_CONDITIONS")
242 <<
"[WARNING] You are reading tag \"" <<
tag <<
"\" from V1 account \"" << connStr
243 <<
"\". The concerned Conditions might be out of date." << std::endl;
246 sessions.insert(std::make_pair(connStr, nsess));
253 m_proxies.insert(std::make_pair(it->second.recordName(), proxy));
255 boost::posix_time::ptime tagSnapshotTime =
snapshotTime;
256 auto tagSnapshotIter = specialSnapshots.find(it->first);
257 if (tagSnapshotIter != specialSnapshots.end())
258 tagSnapshotTime = tagSnapshotIter->second;
261 tagSnapshotTime = boost::posix_time::ptime();
263 proxy->lateInit(nsess,
tag, tagSnapshotTime, it->second.recordLabel(), connStr);
267 CondGetterFromESSource visitor(
m_proxies);
270 for (;
b !=
e;
b++) {
271 (*b).second->proxy(0)->loadMore(visitor);
285 std::vector<std::string>& listToFill,
286 const unsigned int listSize,
288 boost::split(listToFill, stringList, boost::is_any_of(
"|"), boost::token_compress_off);
290 if (listToFill.size() == 1) {
291 for (
unsigned int i = 1;
i < listSize; ++
i) {
292 listToFill.push_back(stringList);
296 else if (listSize != listToFill.size()) {
298 std::string(
"ESSource: number of global tag components does not match number of " +
type +
" strings"));
305 std::cout <<
"CondDBESSource Statistics" << std::endl
314 for (;
b !=
e;
b++) {
315 dumpInfo(
std::cout, (*b).first, *(*b).second);
333 edm::LogInfo(
"CondDBESSource") <<
"Getting data for record \"" << recordname <<
"\" to be consumed by "
335 <<
"; from CondDBESSource::setIntervalFor";
352 bool refreshThisRecord =
false;
356 if (refreshThisRecord) {
358 defaultIovSize = iR->second;
359 minDiffTime = defaultIovSize;
362 bool doRefresh =
false;
365 std::map<std::string, cond::Time_t>::iterator iRec =
m_lastRecordRuns.find(recordname);
369 if (lastRecordRun > lastTime)
370 diffTime = lastRecordRun - lastTime;
371 if (diffTime >= minDiffTime) {
374 iRec->second = lastTime;
375 edm::LogInfo(
"CondDBESSource") <<
"Preparing refresh for record \"" << recordname
376 <<
"\" since there has been a transition from run/lumi " << lastRecordRun
377 <<
" to run/lumi " << lastTime <<
"; from CondDBESSource::setIntervalFor";
382 edm::LogInfo(
"CondDBESSource") <<
"Preparing refresh for record \"" << recordname <<
"\" for " << iTime.
eventID()
383 <<
", timestamp: " << iTime.
time().
value()
384 <<
"; from CondDBESSource::setIntervalFor";
387 edm::LogInfo(
"CondDBESSource") <<
"Though enabled, refresh not needed for record \"" << recordname <<
"\" for "
389 <<
"; from CondDBESSource::setIntervalFor";
392 edm::LogInfo(
"CondDBESSource") <<
"Forcing refresh for record \"" << recordname <<
"\" for " << iTime.
eventID()
393 <<
", timestamp: " << iTime.
time().
value()
394 <<
"; from CondDBESSource::setIntervalFor";
402 bool userTime =
true;
405 ProxyMap::const_iterator pmBegin =
m_proxies.lower_bound(recordname);
406 ProxyMap::const_iterator pmEnd =
m_proxies.upper_bound(recordname);
407 if (pmBegin == pmEnd) {
408 edm::LogInfo(
"CondDBESSource") <<
"No DataProxy (Pluging) found for record \"" << recordname
409 <<
"\"; from CondDBESSource::setIntervalFor";
413 for (ProxyMap::const_iterator pmIter = pmBegin; pmIter != pmEnd; ++pmIter) {
414 edm::LogInfo(
"CondDBESSource") <<
"Processing record \"" << recordname <<
"\" and label \""
415 << pmIter->second->label() <<
"\" for " << iTime.
eventID()
416 <<
", timestamp: " << iTime.
time().
value()
417 <<
"; from CondDBESSource::setIntervalFor";
419 timetype = (*pmIter).second->timeType();
422 userTime = (0 == abtime);
428 std::string recKey = joinRecordAndLabel(recordname, pmIter->second->label());
431 edm::LogInfo(
"CondDBESSource") <<
"No Tag found for record \"" << recordname <<
"\" and label \""
432 << pmIter->second->label() <<
"\"; from CondDBESSource::setIntervalFor";
439 <<
"Checking if the session must be closed and re-opened for getting correct conditions"
440 <<
"; from CondDBESSource::setIntervalFor";
441 std::stringstream transId;
446 if (!tagParams.second.empty())
447 connStr = tagParams.second;
449 if (refreshThisRecord) {
452 auto iSess = sessionPool->find(connStr);
454 if (iSess != sessionPool->end()) {
455 if (iSess->second.second != transId.str()) {
458 iSess->second.second = transId.str();
469 edm::LogInfo(
"CondDBESSource") <<
"Re-opening the session with connection string " << connStr
470 <<
" and new transaction Id " << transId.str()
471 <<
"; from CondDBESSource::setIntervalFor";
474 edm::LogInfo(
"CondDBESSource") <<
"Reconnecting to \"" << connStr <<
"\" for getting new payload for record \""
475 << recordname <<
"\" and label \"" << pmIter->second->label()
476 <<
"\" from IOV tag \"" << tcIter->second.tagName() <<
"\" to be consumed by "
478 <<
"; from CondDBESSource::setIntervalFor";
479 pmIter->second->session() = iSess->second.first;
480 pmIter->second->reload();
487 edm::LogInfo(
"CondDBESSource") <<
"Refreshing IOV sequence labeled by tag \"" << tcIter->second.tagName()
488 <<
"\" for getting new payload for record \"" << recordname <<
"\" and label \""
489 << pmIter->second->label() <<
"\" to be consumed by " << iTime.
eventID()
490 <<
", timestamp: " << iTime.
time().
value()
491 <<
"; from CondDBESSource::setIntervalFor";
492 pmIter->second->reload();
513 edm::LogInfo(
"CondDBESSource") <<
"Validity coming from IOV sequence for record \"" << recordname
514 <<
"\" and label \"" << pmIter->second->label() <<
"\": (" << validity.first <<
", "
516 << abtime <<
"; from CondDBESSource::setIntervalFor";
518 recordValidity.first =
std::max(recordValidity.first, validity.first);
519 recordValidity.second =
std::min(recordValidity.second, validity.second);
524 edm::LogInfo(
"CondDBESSource") <<
"Validity for record \"" << recordname
525 <<
"\" and the corresponding label(s) coming from Condition DB: ("
526 << recordValidity.first <<
", " << recordValidity.first
527 <<
") as the last IOV element in the IOV sequence is infinity"
528 <<
"; from CondDBESSource::setIntervalFor";
533 if ((!userTime) && recordValidity.second != 0) {
544 edm::LogInfo(
"CondDBESSource") <<
"Setting validity for record \"" << recordname
545 <<
"\" and corresponding label(s): starting at " << oInterval.
first().
eventID()
546 <<
", timestamp: " << oInterval.
first().
time().
value() <<
", ending at "
549 <<
"; from CondDBESSource::setIntervalFor";
559 ProxyMap::const_iterator
b =
m_proxies.lower_bound(recordname);
560 ProxyMap::const_iterator
e =
m_proxies.upper_bound(recordname);
562 edm::LogInfo(
"CondDBESSource") <<
"No DataProxy (Pluging) found for record \"" << recordname
563 <<
"\"; from CondDBESSource::registerProxies";
564 return keyedProxiesVector;
567 for (ProxyMap::const_iterator
p =
b;
p !=
e; ++
p) {
568 if (
nullptr != (*p).second.get()) {
571 keyedProxiesVector.emplace_back(
key, (*p).second->edmProxy(iovIndex));
574 return keyedProxiesVector;
579 ProxyMap::const_iterator
b =
m_proxies.lower_bound(recordname);
580 ProxyMap::const_iterator
e =
m_proxies.upper_bound(recordname);
581 for (ProxyMap::const_iterator
p =
b;
p !=
e; ++
p) {
583 p->second->initConcurrentIOVs(nConcurrentIOVs);
593 std::set<cond::GTEntry_t>& tagcoll,
595 if (!roottag.empty()) {
599 std::tuple<std::string, std::string, std::string> connPars =
601 if (std::get<2>(connPars) ==
"CMS_COND_31X_GLOBALTAG") {
603 <<
"[WARNING] You are reading Global Tag \"" << roottag
604 <<
"\" from V1 account \"CMS_COND_31X_GLOBALTAG\". The concerned Conditions might be out of date."
606 }
else if (roottag.rfind(
"::All") != std::string::npos && std::get<2>(connPars) ==
"CMS_CONDITIONS") {
607 edm::LogWarning(
"CondDBESSource") <<
"[WARNING] You are trying to read Global Tag \"" << roottag
608 <<
"\" - postfix \"::All\" should not be used for V2." << std::endl;
614 for (
const auto& gte : gtp) {
624 const std::vector<std::string>& prefixList,
625 const std::vector<std::string>& postfixList,
626 const std::vector<std::string>& roottagList,
627 std::map<std::string, cond::GTEntry_t>& replacement,
629 std::set<cond::GTEntry_t> tagcoll;
632 auto prefix = prefixList.begin();
633 auto postfix = postfixList.begin();
634 for (
auto roottag = roottagList.begin(); roottag != roottagList.end();
639 std::set<cond::GTEntry_t>::iterator tagCollIter;
640 std::set<cond::GTEntry_t>::iterator tagCollBegin = tagcoll.begin();
641 std::set<cond::GTEntry_t>::iterator tagCollEnd = tagcoll.end();
644 for (tagCollIter = tagCollBegin; tagCollIter != tagCollEnd; ++tagCollIter) {
645 std::string recordLabelKey = joinRecordAndLabel(tagCollIter->recordName(), tagCollIter->recordLabel());
646 std::map<std::string, cond::GTEntry_t>::iterator fid = replacement.find(recordLabelKey);
647 if (fid != replacement.end()) {
648 if (!fid->second.tagName().empty()) {
650 std::make_tuple(tagCollIter->recordName(), tagCollIter->recordLabel(), fid->second.tagName()));
652 edm::LogInfo(
"CondDBESSource") <<
"Replacing tag \"" << tagCollIter->tagName() <<
"\" for record \""
654 <<
"\" with tag " << tagMetadata.
tagName()
655 <<
"\"; from CondDBESSource::fillTagCollectionFromDB";
659 replacement.erase(fid);
664 std::map<std::string, cond::GTEntry_t>::iterator replacementIter;
665 std::map<std::string, cond::GTEntry_t>::iterator replacementBegin = replacement.begin();
666 std::map<std::string, cond::GTEntry_t>::iterator replacementEnd = replacement.end();
667 for (replacementIter = replacementBegin; replacementIter != replacementEnd; ++replacementIter) {
668 if (replacementIter->second.tagName().empty()) {
669 std::stringstream
msg;
670 msg <<
"ESSource: no tag provided for record " << replacementIter->second.recordName();
671 if (!replacementIter->second.recordLabel().empty())
672 msg <<
" and label " << replacementIter->second.recordLabel();