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(
""),
104 m_doDump(iConfig.getUntrackedParameter<
bool>(
"DumpStat",
false)) {
118 Stats s = {0, 0, 0, 0, 0, 0, 0, 0};
124 if (iConfig.
exists(
"globaltag")) {
139 }
else if (iConfig.
exists(
"connect"))
144 if (iConfig.
exists(
"snapshotTime")) {
146 if (!snapshotTimeString.empty())
147 snapshotTime = boost::posix_time::time_from_string(snapshotTimeString);
151 if (iConfig.
exists(
"DBParameters")) {
158 std::map<std::string, cond::GTEntry_t> replacements;
159 std::map<std::string, boost::posix_time::ptime> specialSnapshots;
160 if (iConfig.
exists(
"toGet")) {
161 typedef std::vector<edm::ParameterSet>
Parameters;
163 for (Parameters::iterator itToGet =
toGet.begin(); itToGet !=
toGet.end(); ++itToGet) {
165 if (recordname.empty())
166 throw cond::Exception(
"ESSource: The record name has not been provided in a \"toGet\" entry.");
170 pfn = itToGet->getParameter<
std::string>(
"connect");
173 if (itToGet->exists(
"tag")) {
177 boost::posix_time::ptime tagSnapshotTime =
179 if (itToGet->exists(
"snapshotTime"))
180 tagSnapshotTime = boost::posix_time::time_from_string(itToGet->getParameter<
std::string>(
"snapshotTime"));
181 if (itToGet->exists(
"refreshTime")) {
186 std::string recordLabelKey = joinRecordAndLabel(recordname, labelname);
188 std::make_pair(recordLabelKey,
cond::GTEntry_t(std::make_tuple(recordname, labelname, fqTag))));
189 specialSnapshots.insert(std::make_pair(recordLabelKey, tagSnapshotTime));
194 std::vector<std::string> globaltagList;
195 std::vector<std::string> connectList;
196 std::vector<std::string> pfnPrefixList;
197 std::vector<std::string> pfnPostfixList;
213 TagCollection::iterator it;
217 std::map<std::string, cond::persistency::Session> sessions;
227 std::vector<std::unique_ptr<cond::DataProxyWrapperBase>> proxyWrappers(
m_tagCollection.size());
229 for (it = itBeg; it != itEnd; ++it) {
230 proxyWrappers[ipb++] = std::unique_ptr<cond::DataProxyWrapperBase>{
237 for (it = itBeg; it != itEnd; ++it) {
241 if (!tagParams.second.empty()) {
242 connStr = tagParams.second;
243 tag = tagParams.first;
245 std::map<std::string, cond::persistency::Session>::iterator
p = sessions.find(connStr);
247 if (
p == sessions.end()) {
249 std::tuple<std::string, std::string, std::string> connPars =
253 if ((dbService ==
"cms_orcon_prod" || dbService ==
"cms_orcon_adg") && dbAccount !=
"CMS_CONDITIONS")
255 <<
"[WARNING] You are reading tag \"" <<
tag <<
"\" from V1 account \"" << connStr
256 <<
"\". The concerned Conditions might be out of date." << std::endl;
259 sessions.insert(std::make_pair(connStr, nsess));
266 m_proxies.insert(std::make_pair(it->second.recordName(), proxy));
268 boost::posix_time::ptime tagSnapshotTime =
snapshotTime;
269 auto tagSnapshotIter = specialSnapshots.find(it->first);
270 if (tagSnapshotIter != specialSnapshots.end())
271 tagSnapshotTime = tagSnapshotIter->second;
274 tagSnapshotTime = boost::posix_time::ptime();
276 proxy->lateInit(nsess,
tag, tagSnapshotTime, it->second.recordLabel(), connStr, &
m_queue, &
m_mutex);
280 CondGetterFromESSource visitor(
m_proxies);
283 for (;
b !=
e;
b++) {
284 (*b).second->proxy(0)->loadMore(visitor);
298 std::vector<std::string>& listToFill,
299 const unsigned int listSize,
301 boost::split(listToFill, stringList, boost::is_any_of(
"|"), boost::token_compress_off);
303 if (listToFill.size() == 1) {
304 for (
unsigned int i = 1;
i < listSize; ++
i) {
305 listToFill.push_back(stringList);
309 else if (listSize != listToFill.size()) {
311 std::string(
"ESSource: number of global tag components does not match number of " +
type +
" strings"));
318 std::cout <<
"CondDBESSource Statistics" << std::endl
327 for (;
b !=
e;
b++) {
328 dumpInfo(
std::cout, (*b).first, *(*b).second);
346 edm::LogInfo(
"CondDBESSource") <<
"Getting data for record \"" << recordname <<
"\" to be consumed by "
348 <<
"; from CondDBESSource::setIntervalFor";
350 std::lock_guard<std::mutex> guard(
m_mutex);
366 bool refreshThisRecord =
false;
370 if (refreshThisRecord) {
372 defaultIovSize = iR->second;
373 minDiffTime = defaultIovSize;
376 bool doRefresh =
false;
379 std::map<std::string, cond::Time_t>::iterator iRec =
m_lastRecordRuns.find(recordname);
383 if (lastRecordRun > lastTime)
384 diffTime = lastRecordRun - lastTime;
385 if (diffTime >= minDiffTime) {
388 iRec->second = lastTime;
389 edm::LogInfo(
"CondDBESSource") <<
"Preparing refresh for record \"" << recordname
390 <<
"\" since there has been a transition from run/lumi " << lastRecordRun
391 <<
" to run/lumi " << lastTime <<
"; from CondDBESSource::setIntervalFor";
396 edm::LogInfo(
"CondDBESSource") <<
"Preparing refresh for record \"" << recordname <<
"\" for " << iTime.
eventID()
397 <<
", timestamp: " << iTime.
time().
value()
398 <<
"; from CondDBESSource::setIntervalFor";
401 edm::LogInfo(
"CondDBESSource") <<
"Though enabled, refresh not needed for record \"" << recordname <<
"\" for "
403 <<
"; from CondDBESSource::setIntervalFor";
406 edm::LogInfo(
"CondDBESSource") <<
"Forcing refresh for record \"" << recordname <<
"\" for " << iTime.
eventID()
407 <<
", timestamp: " << iTime.
time().
value()
408 <<
"; from CondDBESSource::setIntervalFor";
416 bool userTime =
true;
419 ProxyMap::const_iterator pmBegin =
m_proxies.lower_bound(recordname);
420 ProxyMap::const_iterator pmEnd =
m_proxies.upper_bound(recordname);
421 if (pmBegin == pmEnd) {
422 edm::LogInfo(
"CondDBESSource") <<
"No DataProxy (Pluging) found for record \"" << recordname
423 <<
"\"; from CondDBESSource::setIntervalFor";
427 for (ProxyMap::const_iterator pmIter = pmBegin; pmIter != pmEnd; ++pmIter) {
428 edm::LogInfo(
"CondDBESSource") <<
"Processing record \"" << recordname <<
"\" and label \""
429 << pmIter->second->label() <<
"\" for " << iTime.
eventID()
430 <<
", timestamp: " << iTime.
time().
value()
431 <<
"; from CondDBESSource::setIntervalFor";
433 timetype = (*pmIter).second->timeType();
436 userTime = (0 == abtime);
442 std::string recKey = joinRecordAndLabel(recordname, pmIter->second->label());
445 edm::LogInfo(
"CondDBESSource") <<
"No Tag found for record \"" << recordname <<
"\" and label \""
446 << pmIter->second->label() <<
"\"; from CondDBESSource::setIntervalFor";
453 <<
"Checking if the session must be closed and re-opened for getting correct conditions"
454 <<
"; from CondDBESSource::setIntervalFor";
455 std::stringstream transId;
460 if (!tagParams.second.empty())
461 connStr = tagParams.second;
463 if (refreshThisRecord) {
466 auto iSess = sessionPool->find(connStr);
468 if (iSess != sessionPool->end()) {
469 if (iSess->second.second != transId.str()) {
472 iSess->second.second = transId.str();
483 edm::LogInfo(
"CondDBESSource") <<
"Re-opening the session with connection string " << connStr
484 <<
" and new transaction Id " << transId.str()
485 <<
"; from CondDBESSource::setIntervalFor";
488 edm::LogInfo(
"CondDBESSource") <<
"Reconnecting to \"" << connStr <<
"\" for getting new payload for record \""
489 << recordname <<
"\" and label \"" << pmIter->second->label()
490 <<
"\" from IOV tag \"" << tcIter->second.tagName() <<
"\" to be consumed by "
492 <<
"; from CondDBESSource::setIntervalFor";
493 pmIter->second->session() = iSess->second.first;
494 pmIter->second->reload();
501 edm::LogInfo(
"CondDBESSource") <<
"Refreshing IOV sequence labeled by tag \"" << tcIter->second.tagName()
502 <<
"\" for getting new payload for record \"" << recordname <<
"\" and label \""
503 << pmIter->second->label() <<
"\" to be consumed by " << iTime.
eventID()
504 <<
", timestamp: " << iTime.
time().
value()
505 <<
"; from CondDBESSource::setIntervalFor";
506 pmIter->second->reload();
527 edm::LogInfo(
"CondDBESSource") <<
"Validity coming from IOV sequence for record \"" << recordname
528 <<
"\" and label \"" << pmIter->second->label() <<
"\": (" << validity.first <<
", "
530 << abtime <<
"; from CondDBESSource::setIntervalFor";
532 recordValidity.first =
std::max(recordValidity.first, validity.first);
533 recordValidity.second =
std::min(recordValidity.second, validity.second);
538 edm::LogInfo(
"CondDBESSource") <<
"Validity for record \"" << recordname
539 <<
"\" and the corresponding label(s) coming from Condition DB: ("
540 << recordValidity.first <<
", " << recordValidity.first
541 <<
") as the last IOV element in the IOV sequence is infinity"
542 <<
"; from CondDBESSource::setIntervalFor";
547 if ((!userTime) && recordValidity.second != 0) {
558 edm::LogInfo(
"CondDBESSource") <<
"Setting validity for record \"" << recordname
559 <<
"\" and corresponding label(s): starting at " << oInterval.
first().
eventID()
560 <<
", timestamp: " << oInterval.
first().
time().
value() <<
", ending at "
563 <<
"; from CondDBESSource::setIntervalFor";
573 ProxyMap::const_iterator
b =
m_proxies.lower_bound(recordname);
574 ProxyMap::const_iterator
e =
m_proxies.upper_bound(recordname);
576 edm::LogInfo(
"CondDBESSource") <<
"No DataProxy (Pluging) found for record \"" << recordname
577 <<
"\"; from CondDBESSource::registerProxies";
578 return keyedProxiesVector;
581 for (ProxyMap::const_iterator
p =
b;
p !=
e; ++
p) {
582 if (
nullptr != (*p).second.get()) {
585 keyedProxiesVector.emplace_back(
key, (*p).second->edmProxy(iovIndex));
588 return keyedProxiesVector;
593 ProxyMap::const_iterator
b =
m_proxies.lower_bound(recordname);
594 ProxyMap::const_iterator
e =
m_proxies.upper_bound(recordname);
595 for (ProxyMap::const_iterator
p =
b;
p !=
e; ++
p) {
597 p->second->initConcurrentIOVs(nConcurrentIOVs);
607 std::set<cond::GTEntry_t>& tagcoll,
609 if (!roottag.empty()) {
613 std::tuple<std::string, std::string, std::string> connPars =
615 if (std::get<2>(connPars) ==
"CMS_COND_31X_GLOBALTAG") {
617 <<
"[WARNING] You are reading Global Tag \"" << roottag
618 <<
"\" from V1 account \"CMS_COND_31X_GLOBALTAG\". The concerned Conditions might be out of date."
620 }
else if (roottag.rfind(
"::All") != std::string::npos && std::get<2>(connPars) ==
"CMS_CONDITIONS") {
621 edm::LogWarning(
"CondDBESSource") <<
"[WARNING] You are trying to read Global Tag \"" << roottag
622 <<
"\" - postfix \"::All\" should not be used for V2." << std::endl;
628 for (
const auto& gte : gtp) {
638 const std::vector<std::string>& prefixList,
639 const std::vector<std::string>& postfixList,
640 const std::vector<std::string>& roottagList,
641 std::map<std::string, cond::GTEntry_t>& replacement,
643 std::set<cond::GTEntry_t> tagcoll;
646 auto prefix = prefixList.begin();
647 auto postfix = postfixList.begin();
648 for (
auto roottag = roottagList.begin(); roottag != roottagList.end();
653 std::set<cond::GTEntry_t>::iterator tagCollIter;
654 std::set<cond::GTEntry_t>::iterator tagCollBegin = tagcoll.begin();
655 std::set<cond::GTEntry_t>::iterator tagCollEnd = tagcoll.end();
658 for (tagCollIter = tagCollBegin; tagCollIter != tagCollEnd; ++tagCollIter) {
659 std::string recordLabelKey = joinRecordAndLabel(tagCollIter->recordName(), tagCollIter->recordLabel());
660 std::map<std::string, cond::GTEntry_t>::iterator fid = replacement.find(recordLabelKey);
661 if (fid != replacement.end()) {
662 if (!fid->second.tagName().empty()) {
664 std::make_tuple(tagCollIter->recordName(), tagCollIter->recordLabel(), fid->second.tagName()));
666 edm::LogInfo(
"CondDBESSource") <<
"Replacing tag \"" << tagCollIter->tagName() <<
"\" for record \""
668 <<
"\" with tag " << tagMetadata.
tagName()
669 <<
"\"; from CondDBESSource::fillTagCollectionFromDB";
673 replacement.erase(fid);
678 std::map<std::string, cond::GTEntry_t>::iterator replacementIter;
679 std::map<std::string, cond::GTEntry_t>::iterator replacementBegin = replacement.begin();
680 std::map<std::string, cond::GTEntry_t>::iterator replacementEnd = replacement.end();
681 for (replacementIter = replacementBegin; replacementIter != replacementEnd; ++replacementIter) {
682 if (replacementIter->second.tagName().empty()) {
683 std::stringstream
msg;
684 msg <<
"ESSource: no tag provided for record " << replacementIter->second.recordName();
685 if (!replacementIter->second.recordLabel().empty())
686 msg <<
" and label " << replacementIter->second.recordLabel();