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();
68 out << recName <<
" / " << proxy.
label() <<
": " << proxy.
connString() <<
", " << proxy.
tag()
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")) {
130 if (!globaltag.empty()) {
136 m_connectionString = localConnectPrefix + globaltag + localConnectSuffix;
140 }
else if (iConfig.
exists(
"connect"))
147 boost::posix_time::ptime snapshotTime;
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;
202 if (!globaltag.empty()) {
205 boost::split(globaltagList, globaltag, boost::is_any_of(
"|"), boost::token_compress_off);
207 fillList(pfnPrefix, pfnPrefixList, globaltagList.size(),
"pfnPrefix");
208 fillList(pfnPostfix, pfnPostfixList, globaltagList.size(),
"pfnPostfix");
214 if (snapshotTime.is_not_a_date_time())
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) {
235 proxyWrappers[ind] = std::unique_ptr<cond::DataProxyWrapperBase>{
237 if (!proxyWrappers[ind].
get()) {
238 edm::LogWarning(
"CondDBESSource") <<
"Plugin for Record " << it->second.recordName() <<
" has not been found.";
245 for (it = itBeg; it != itEnd; ++it) {
249 if (!tagParams.second.empty()) {
250 connStr = tagParams.second;
251 tag = tagParams.first;
253 std::map<std::string, cond::persistency::Session>::iterator p = sessions.find(connStr);
255 if (p == sessions.end()) {
257 std::tuple<std::string, std::string, std::string> connPars =
261 if ((dbService ==
"cms_orcon_prod" || dbService ==
"cms_orcon_adg") && dbAccount !=
"CMS_CONDITIONS")
263 <<
"[WARNING] You are reading tag \"" << tag <<
"\" from V1 account \"" << connStr
264 <<
"\". The concerned Conditions might be out of date." << std::endl;
267 sessions.insert(std::make_pair(connStr, nsess));
277 boost::posix_time::ptime tagSnapshotTime = snapshotTime;
278 auto tagSnapshotIter = specialSnapshots.find(it->first);
279 if (tagSnapshotIter != specialSnapshots.end())
280 tagSnapshotTime = tagSnapshotIter->second;
283 tagSnapshotTime = boost::posix_time::ptime();
285 proxy->lateInit(nsess, tag, tagSnapshotTime, it->second.recordLabel(), connStr, &
m_queue, &
m_mutex);
290 CondGetterFromESSource visitor(
m_proxies);
293 for (; b !=
e; b++) {
294 (*b).second->proxy(0)->loadMore(visitor);
308 std::vector<std::string>& listToFill,
309 const unsigned int listSize,
311 boost::split(listToFill, stringList, boost::is_any_of(
"|"), boost::token_compress_off);
313 if (listToFill.size() == 1) {
314 for (
unsigned int i = 1;
i < listSize; ++
i) {
315 listToFill.push_back(stringList);
319 else if (listSize != listToFill.size()) {
321 std::string(
"ESSource: number of global tag components does not match number of " + type +
" strings"));
328 std::cout <<
"CondDBESSource Statistics" << std::endl
337 for (; b !=
e; b++) {
356 edm::LogInfo(
"CondDBESSource") <<
"Getting data for record \"" << recordname <<
"\" to be consumed by "
358 <<
"; from CondDBESSource::setIntervalFor";
360 std::lock_guard<std::mutex> guard(
m_mutex);
376 bool refreshThisRecord =
false;
380 if (refreshThisRecord) {
382 defaultIovSize = iR->second;
383 minDiffTime = defaultIovSize;
386 bool doRefresh =
false;
389 std::map<std::string, cond::Time_t>::iterator iRec =
m_lastRecordRuns.find(recordname);
393 if (lastRecordRun > lastTime)
394 diffTime = lastRecordRun - lastTime;
395 if (diffTime >= minDiffTime) {
398 iRec->second = lastTime;
399 edm::LogInfo(
"CondDBESSource") <<
"Preparing refresh for record \"" << recordname
400 <<
"\" since there has been a transition from run/lumi " << lastRecordRun
401 <<
" to run/lumi " << lastTime <<
"; from CondDBESSource::setIntervalFor";
406 edm::LogInfo(
"CondDBESSource") <<
"Preparing refresh for record \"" << recordname <<
"\" for " << iTime.
eventID()
407 <<
", timestamp: " << iTime.
time().
value()
408 <<
"; from CondDBESSource::setIntervalFor";
411 edm::LogInfo(
"CondDBESSource") <<
"Though enabled, refresh not needed for record \"" << recordname <<
"\" for "
413 <<
"; from CondDBESSource::setIntervalFor";
416 edm::LogInfo(
"CondDBESSource") <<
"Forcing refresh for record \"" << recordname <<
"\" for " << iTime.
eventID()
417 <<
", timestamp: " << iTime.
time().
value()
418 <<
"; from CondDBESSource::setIntervalFor";
426 bool userTime =
true;
429 ProxyMap::const_iterator pmBegin =
m_proxies.lower_bound(recordname);
430 ProxyMap::const_iterator pmEnd =
m_proxies.upper_bound(recordname);
431 if (pmBegin == pmEnd) {
432 edm::LogInfo(
"CondDBESSource") <<
"No DataProxy (Pluging) found for record \"" << recordname
433 <<
"\"; from CondDBESSource::setIntervalFor";
437 for (ProxyMap::const_iterator pmIter = pmBegin; pmIter != pmEnd; ++pmIter) {
438 edm::LogInfo(
"CondDBESSource") <<
"Processing record \"" << recordname <<
"\" and label \""
439 << pmIter->second->label() <<
"\" for " << iTime.
eventID()
440 <<
", timestamp: " << iTime.
time().
value()
441 <<
"; from CondDBESSource::setIntervalFor";
443 timetype = (*pmIter).second->timeType();
446 userTime = (0 == abtime);
452 std::string recKey = joinRecordAndLabel(recordname, pmIter->second->label());
455 edm::LogInfo(
"CondDBESSource") <<
"No Tag found for record \"" << recordname <<
"\" and label \""
456 << pmIter->second->label() <<
"\"; from CondDBESSource::setIntervalFor";
463 <<
"Checking if the session must be closed and re-opened for getting correct conditions"
464 <<
"; from CondDBESSource::setIntervalFor";
465 std::stringstream transId;
472 if (!tagParams.second.empty())
473 connStr = tagParams.second;
475 if (refreshThisRecord) {
478 auto iSess = sessionPool->find(connStr);
480 if (iSess != sessionPool->end()) {
481 if (iSess->second.second != transId.str()) {
484 iSess->second.second = transId.str();
495 edm::LogInfo(
"CondDBESSource") <<
"Re-opening the session with connection string " << connStr
496 <<
" and new transaction Id " << transId.str()
497 <<
"; from CondDBESSource::setIntervalFor";
500 edm::LogInfo(
"CondDBESSource") <<
"Reconnecting to \"" << connStr <<
"\" for getting new payload for record \""
501 << recordname <<
"\" and label \"" << pmIter->second->label()
502 <<
"\" from IOV tag \"" << tcIter->second.tagName() <<
"\" to be consumed by "
504 <<
"; from CondDBESSource::setIntervalFor";
505 pmIter->second->session() = iSess->second.first;
506 pmIter->second->reload();
513 edm::LogInfo(
"CondDBESSource") <<
"Refreshing IOV sequence labeled by tag \"" << tcIter->second.tagName()
514 <<
"\" for getting new payload for record \"" << recordname <<
"\" and label \""
515 << pmIter->second->label() <<
"\" to be consumed by " << iTime.
eventID()
516 <<
", timestamp: " << iTime.
time().
value()
517 <<
"; from CondDBESSource::setIntervalFor";
518 pmIter->second->reload();
539 edm::LogInfo(
"CondDBESSource") <<
"Validity coming from IOV sequence for record \"" << recordname
540 <<
"\" and label \"" << pmIter->second->label() <<
"\": (" << validity.first <<
", "
542 << abtime <<
"; from CondDBESSource::setIntervalFor";
544 recordValidity.first =
std::max(recordValidity.first, validity.first);
545 recordValidity.second =
std::min(recordValidity.second, validity.second);
550 edm::LogInfo(
"CondDBESSource") <<
"Validity for record \"" << recordname
551 <<
"\" and the corresponding label(s) coming from Condition DB: ("
552 << recordValidity.first <<
", " << recordValidity.first
553 <<
") as the last IOV element in the IOV sequence is infinity"
554 <<
"; from CondDBESSource::setIntervalFor";
559 if ((!userTime) && recordValidity.second != 0) {
570 edm::LogInfo(
"CondDBESSource") <<
"Setting validity for record \"" << recordname
571 <<
"\" and corresponding label(s): starting at " << oInterval.
first().
eventID()
572 <<
", timestamp: " << oInterval.
first().
time().
value() <<
", ending at "
575 <<
"; from CondDBESSource::setIntervalFor";
585 ProxyMap::const_iterator
b =
m_proxies.lower_bound(recordname);
586 ProxyMap::const_iterator
e =
m_proxies.upper_bound(recordname);
588 edm::LogInfo(
"CondDBESSource") <<
"No DataProxy (Pluging) found for record \"" << recordname
589 <<
"\"; from CondDBESSource::registerProxies";
590 return keyedProxiesVector;
593 for (ProxyMap::const_iterator p = b; p !=
e; ++
p) {
594 if (
nullptr != (*p).second.get()) {
597 keyedProxiesVector.emplace_back(key, (*p).second->edmProxy(iovIndex));
600 return keyedProxiesVector;
605 ProxyMap::const_iterator
b =
m_proxies.lower_bound(recordname);
606 ProxyMap::const_iterator
e =
m_proxies.upper_bound(recordname);
607 for (ProxyMap::const_iterator p = b; p !=
e; ++
p) {
609 p->second->initConcurrentIOVs(nConcurrentIOVs);
619 std::set<cond::GTEntry_t>& tagcoll,
621 if (!roottag.empty()) {
622 if (connectionString.empty())
625 std::tuple<std::string, std::string, std::string> connPars =
627 if (std::get<2>(connPars) ==
"CMS_COND_31X_GLOBALTAG") {
629 <<
"[WARNING] You are reading Global Tag \"" << roottag
630 <<
"\" from V1 account \"CMS_COND_31X_GLOBALTAG\". The concerned Conditions might be out of date."
632 }
else if (roottag.rfind(
"::All") != std::string::npos && std::get<2>(connPars) ==
"CMS_CONDITIONS") {
633 edm::LogWarning(
"CondDBESSource") <<
"[WARNING] You are trying to read Global Tag \"" << roottag
634 <<
"\" - postfix \"::All\" should not be used for V2." << std::endl;
640 for (
const auto& gte : gtp) {
650 const std::vector<std::string>& prefixList,
651 const std::vector<std::string>& postfixList,
652 const std::vector<std::string>& roottagList,
653 std::map<std::string, cond::GTEntry_t>& replacement,
655 std::set<cond::GTEntry_t> tagcoll;
658 auto prefix = prefixList.begin();
659 auto postfix = postfixList.begin();
660 for (
auto roottag = roottagList.begin(); roottag != roottagList.end();
665 std::set<cond::GTEntry_t>::iterator tagCollIter;
666 std::set<cond::GTEntry_t>::iterator tagCollBegin = tagcoll.begin();
667 std::set<cond::GTEntry_t>::iterator tagCollEnd = tagcoll.end();
670 for (tagCollIter = tagCollBegin; tagCollIter != tagCollEnd; ++tagCollIter) {
671 std::string recordLabelKey = joinRecordAndLabel(tagCollIter->recordName(), tagCollIter->recordLabel());
672 std::map<std::string, cond::GTEntry_t>::iterator fid = replacement.find(recordLabelKey);
673 if (fid != replacement.end()) {
674 if (!fid->second.tagName().empty()) {
676 std::make_tuple(tagCollIter->recordName(), tagCollIter->recordLabel(), fid->second.tagName()));
678 edm::LogInfo(
"CondDBESSource") <<
"Replacing tag \"" << tagCollIter->tagName() <<
"\" for record \""
680 <<
"\" with tag " << tagMetadata.
tagName()
681 <<
"\"; from CondDBESSource::fillTagCollectionFromDB";
685 replacement.erase(fid);
690 std::map<std::string, cond::GTEntry_t>::iterator replacementIter;
691 std::map<std::string, cond::GTEntry_t>::iterator replacementBegin = replacement.begin();
692 std::map<std::string, cond::GTEntry_t>::iterator replacementEnd = replacement.end();
693 for (replacementIter = replacementBegin; replacementIter != replacementEnd; ++replacementIter) {
694 if (replacementIter->second.tagName().empty()) {
695 std::stringstream
msg;
696 msg <<
"ESSource: no tag provided for record " << replacementIter->second.recordName();
697 if (!replacementIter->second.recordLabel().empty())
698 msg <<
" and label " << replacementIter->second.recordLabel();
persistency::Exception Exception
const TimeTypeSpecs timeTypeSpecs[]
T getUntrackedParameter(std::string const &, T const &) const
std::tuple< std::string, std::string, std::string > parseConnectionString(const std::string &connectionString)
virtual std::string const & localConnectPrefix() const =0
Base exception class for the object to relational access.
void usingRecordWithKey(const EventSetupRecordKey &key)
const EventID & eventID() const
virtual std::string const & localConnectSuffix() const =0
void start(bool readOnly=true)
void setIntervalFor(const EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &) override
bool exists(std::string const ¶meterName) const
checks if a parameter exists
static constexpr const char *const MAX_TIMESTAMP
std::pair< Time_t, Time_t > ValidityInterval
std::map< std::string, std::pair< cond::persistency::Session, std::string > > m_sessionPool
Transaction & transaction()
virtual bool useLocalConnectString() const =0
void setParameters(const edm::ParameterSet &connectionPset)
const IOVSyncValue & last() const
void fillTagCollectionFromGT(const std::string &connectionString, const std::string &prefix, const std::string &postfix, const std::string &roottag, std::set< cond::GTEntry_t > &tagcoll, cond::GTMetadata_t >Metadata)
Time_t fromIOVSyncValue(edm::IOVSyncValue const &time, TimeType timetype)
edm::SerialTaskQueue m_queue
std::string const & timeTypeNames(int)
std::string const & label() const
unsigned long long Time_t
Time_t lumiTime(unsigned int run, unsigned int lumiId)
vector< ParameterSet > Parameters
std::string convertoToOracleConnection(const std::string &input)
std::pair< std::string, std::string > parseTag(const std::string &tag)
static const IOVSyncValue & beginOfTime()
if(conf_.getParameter< bool >("UseStripCablingDB"))
cond::persistency::ConnectionPool m_connection
const char * name() const
tuple key
prepare the HTCondor submission files and eventually submit them
edm::IOVSyncValue toIOVSyncValue(cond::Time_t time, TimeType timetype, bool startOrStop)
LuminosityBlockNumber_t luminosityBlockNumber() const
boost::posix_time::ptime snapshotTime() const
Session createSession(const std::string &connectionString, bool writeCapable=false)
void initConcurrentIOVs(const EventSetupRecordKey &key, unsigned int nConcurrentIOVs) override
std::string fullyQualifiedTag(const std::string &tag, const std::string &connectionString)
void fillList(const std::string &pfn, std::vector< std::string > &pfnList, const unsigned int listSize, const std::string &type)
std::multimap< std::string, ProxyP > ProxyMap
const std::string & recordLabel() const
std::shared_ptr< cond::DataProxyWrapperBase > ProxyP
std::map< std::string, std::pair< cond::persistency::Session, std::string > > m_sessionPoolForLumiConditions
Log< level::Info, false > LogInfo
std::string const & connString() const
#define DEFINE_FWK_EVENTSETUP_SOURCE(type)
std::vector< std::pair< DataKey, std::shared_ptr< DataProxy >>> KeyedProxiesVector
PoolDBESSource(const edm::ParameterSet &ps)
TagCollection m_tagCollection
std::shared_ptr< std::vector< Iov_t > > const & requests() const
KeyedProxiesVector registerProxies(const EventSetupRecordKey &, unsigned int iovIndex) override
T getParameter(std::string const &) const
const Time_t TIMELIMIT(std::numeric_limits< Time_t >::max())
std::map< std::string, cond::Time_t > m_refreshTimeForRecord
~CondDBESSource() override
std::string const & tag() const
void fillTagCollectionFromDB(const std::vector< std::string > &connectionStringList, const std::vector< std::string > &prefixList, const std::vector< std::string > &postfixList, const std::vector< std::string > &roottagList, std::map< std::string, cond::GTEntry_t > &replacement, cond::GTMetadata_t >Metadata)
heterocontainer::HCTypeTag TypeTag
std::string m_connectionString
const TypeTag & type() const
const std::string & recordName() const
static const ValidityInterval & invalidInterval()
Session createReadOnlySession(const std::string &connectionString, const std::string &transactionId)
std::map< std::string, cond::Time_t > m_lastRecordRuns
const std::string & tagName() const
std::string m_frontierKey
const Timestamp & time() const
edm::IOVSyncValue limitedIOVSyncValue(Time_t time, TimeType timetype)
const IOVSyncValue & first() const
Log< level::Warning, false > LogWarning
CondDBESSource(const edm::ParameterSet &)
GTProxy readGlobalTag(const std::string &name)
const Time_t MAX_VAL(std::numeric_limits< Time_t >::max())
TimeValue_t value() const
void findingRecordWithKey(const eventsetup::EventSetupRecordKey &)
static const IOVSyncValue & invalidIOVSyncValue()
static HCTypeTag findType(char const *iTypeName)
find a type based on the types name, if not found will return default HCTypeTag