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();
66 out << recName <<
" / " << proxy.
label() <<
": " << proxy.
connString() <<
", " << proxy.
tag()
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 std::string recordLabelKey = joinRecordAndLabel(recordname, labelname);
170 std::make_pair(recordLabelKey,
cond::GTEntry_t(std::make_tuple(recordname, labelname, fqTag))));
171 specialSnapshots.insert(std::make_pair(recordLabelKey, tagSnapshotTime));
176 std::vector<std::string> globaltagList;
177 std::vector<std::string> connectList;
178 std::vector<std::string> pfnPrefixList;
179 std::vector<std::string> pfnPostfixList;
180 if (!globaltag.empty()) {
183 boost::split(globaltagList, globaltag, boost::is_any_of(
"|"), boost::token_compress_off);
185 fillList(pfnPrefix, pfnPrefixList, globaltagList.size(),
"pfnPrefix");
186 fillList(pfnPostfix, pfnPostfixList, globaltagList.size(),
"pfnPostfix");
192 if (snapshotTime.is_not_a_date_time())
193 snapshotTime = gtMetadata.snapshotTime;
195 TagCollection::iterator it;
199 std::map<std::string, cond::persistency::Session> sessions;
209 std::vector<std::unique_ptr<cond::DataProxyWrapperBase>> proxyWrappers(
m_tagCollection.size());
211 for (it = itBeg; it != itEnd; ++it) {
212 proxyWrappers[ipb++] = std::unique_ptr<cond::DataProxyWrapperBase>{
219 for (it = itBeg; it != itEnd; ++it) {
223 if (!tagParams.second.empty()) {
224 connStr = tagParams.second;
225 tag = tagParams.first;
227 std::map<std::string, cond::persistency::Session>::iterator p = sessions.find(connStr);
229 if (p == sessions.end()) {
231 std::tuple<std::string, std::string, std::string> connPars =
235 if ((dbService ==
"cms_orcon_prod" || dbService ==
"cms_orcon_adg") && dbAccount !=
"CMS_CONDITIONS")
237 <<
"[WARNING] You are reading tag \"" << tag <<
"\" from V1 account \"" << connStr
238 <<
"\". The concerned Conditions might be out of date." << std::endl;
241 sessions.insert(std::make_pair(connStr, nsess));
248 m_proxies.insert(std::make_pair(it->second.recordName(), proxy));
250 boost::posix_time::ptime tagSnapshotTime =
snapshotTime;
251 auto tagSnapshotIter = specialSnapshots.find(it->first);
252 if (tagSnapshotIter != specialSnapshots.end())
253 tagSnapshotTime = tagSnapshotIter->second;
256 tagSnapshotTime = boost::posix_time::ptime();
258 proxy->lateInit(nsess, tag, tagSnapshotTime, it->second.recordLabel(), connStr);
262 CondGetterFromESSource visitor(
m_proxies);
265 for (; b !=
e; b++) {
266 (*b).second->proxy(0)->loadMore(visitor);
280 std::vector<std::string>& listToFill,
281 const unsigned int listSize,
283 boost::split(listToFill, stringList, boost::is_any_of(
"|"), boost::token_compress_off);
285 if (listToFill.size() == 1) {
286 for (
unsigned int i = 1;
i < listSize; ++
i) {
287 listToFill.push_back(stringList);
291 else if (listSize != listToFill.size()) {
293 std::string(
"ESSource: number of global tag components does not match number of " + type +
" strings"));
300 std::cout <<
"CondDBESSource Statistics" << std::endl
309 for (; b !=
e; b++) {
310 dumpInfo(
std::cout, (*b).first, *(*b).second);
328 edm::LogInfo(
"CondDBESSource") <<
"Getting data for record \"" << recordname <<
"\" to be consumed by " 330 <<
"; from CondDBESSource::setIntervalFor";
345 bool doRefresh =
false;
348 std::map<std::string, unsigned int>::iterator iRec =
m_lastRecordRuns.find(recordname);
350 unsigned int lastRecordRun = iRec->second;
355 edm::LogInfo(
"CondDBESSource") <<
"Preparing refresh for record \"" << recordname
356 <<
"\" since there has been a transition from run " << lastRecordRun
357 <<
" to run " <<
m_lastRun <<
"; from CondDBESSource::setIntervalFor";
362 edm::LogInfo(
"CondDBESSource") <<
"Preparing refresh for record \"" << recordname <<
"\" for " << iTime.
eventID()
363 <<
", timestamp: " << iTime.
time().
value()
364 <<
"; from CondDBESSource::setIntervalFor";
367 edm::LogInfo(
"CondDBESSource") <<
"Though enabled, refresh not needed for record \"" << recordname <<
"\" for " 369 <<
"; from CondDBESSource::setIntervalFor";
372 edm::LogInfo(
"CondDBESSource") <<
"Forcing refresh for record \"" << recordname <<
"\" for " << iTime.
eventID()
373 <<
", timestamp: " << iTime.
time().
value()
374 <<
"; from CondDBESSource::setIntervalFor";
382 bool userTime =
true;
385 ProxyMap::const_iterator pmBegin =
m_proxies.lower_bound(recordname);
386 ProxyMap::const_iterator pmEnd =
m_proxies.upper_bound(recordname);
387 if (pmBegin == pmEnd) {
388 edm::LogInfo(
"CondDBESSource") <<
"No DataProxy (Pluging) found for record \"" << recordname
389 <<
"\"; from CondDBESSource::setIntervalFor";
393 for (ProxyMap::const_iterator pmIter = pmBegin; pmIter != pmEnd; ++pmIter) {
394 edm::LogInfo(
"CondDBESSource") <<
"Processing record \"" << recordname <<
"\" and label \"" 395 << pmIter->second->label() <<
"\" for " << iTime.
eventID()
396 <<
", timestamp: " << iTime.
time().
value()
397 <<
"; from CondDBESSource::setIntervalFor";
399 timetype = (*pmIter).second->timeType();
402 userTime = (0 == abtime);
408 std::string recKey = joinRecordAndLabel(recordname, pmIter->second->label());
411 edm::LogInfo(
"CondDBESSource") <<
"No Tag found for record \"" << recordname <<
"\" and label \"" 412 << pmIter->second->label() <<
"\"; from CondDBESSource::setIntervalFor";
419 <<
"Checking if the session must be closed and re-opened for getting correct conditions" 420 <<
"; from CondDBESSource::setIntervalFor";
421 std::stringstream transId;
426 if (!tagParams.second.empty())
427 connStr = tagParams.second;
428 std::map<
std::string, std::pair<cond::persistency::Session, std::string>>::iterator iSess =
432 if (iSess->second.second != transId.str()) {
435 iSess->second.second = transId.str();
446 edm::LogInfo(
"CondDBESSource") <<
"Re-opening the session with connection string " << connStr
447 <<
" and new transaction Id " << transId.str()
448 <<
"; from CondDBESSource::setIntervalFor";
451 edm::LogInfo(
"CondDBESSource") <<
"Reconnecting to \"" << connStr <<
"\" for getting new payload for record \"" 452 << recordname <<
"\" and label \"" << pmIter->second->label()
453 <<
"\" from IOV tag \"" << tcIter->second.tagName() <<
"\" to be consumed by " 455 <<
"; from CondDBESSource::setIntervalFor";
456 pmIter->second->session() = iSess->second.first;
457 pmIter->second->reload();
464 edm::LogInfo(
"CondDBESSource") <<
"Refreshing IOV sequence labeled by tag \"" << tcIter->second.tagName()
465 <<
"\" for getting new payload for record \"" << recordname <<
"\" and label \"" 466 << pmIter->second->label() <<
"\" to be consumed by " << iTime.
eventID()
467 <<
", timestamp: " << iTime.
time().
value()
468 <<
"; from CondDBESSource::setIntervalFor";
469 pmIter->second->reload();
490 edm::LogInfo(
"CondDBESSource") <<
"Validity coming from IOV sequence for record \"" << recordname
491 <<
"\" and label \"" << pmIter->second->label() <<
"\": (" << validity.first <<
", " 493 << abtime <<
"; from CondDBESSource::setIntervalFor";
495 recordValidity.first =
std::max(recordValidity.first, validity.first);
496 recordValidity.second =
std::min(recordValidity.second, validity.second);
501 edm::LogInfo(
"CondDBESSource") <<
"Validity for record \"" << recordname
502 <<
"\" and the corresponding label(s) coming from Condition DB: (" 503 << recordValidity.first <<
", " << recordValidity.first
504 <<
") as the last IOV element in the IOV sequence is infinity" 505 <<
"; from CondDBESSource::setIntervalFor";
510 if ((!userTime) && recordValidity.second != 0) {
521 edm::LogInfo(
"CondDBESSource") <<
"Setting validity for record \"" << recordname
522 <<
"\" and corresponding label(s): starting at " << oInterval.
first().
eventID()
523 <<
", timestamp: " << oInterval.
first().
time().
value() <<
", ending at " 526 <<
"; from CondDBESSource::setIntervalFor";
536 ProxyMap::const_iterator
b =
m_proxies.lower_bound(recordname);
537 ProxyMap::const_iterator
e =
m_proxies.upper_bound(recordname);
539 edm::LogInfo(
"CondDBESSource") <<
"No DataProxy (Pluging) found for record \"" << recordname
540 <<
"\"; from CondDBESSource::registerProxies";
541 return keyedProxiesVector;
544 for (ProxyMap::const_iterator p = b; p !=
e; ++
p) {
545 if (
nullptr != (*p).second.get()) {
548 keyedProxiesVector.emplace_back(key, (*p).second->edmProxy(iovIndex));
551 return keyedProxiesVector;
556 ProxyMap::const_iterator
b =
m_proxies.lower_bound(recordname);
557 ProxyMap::const_iterator
e =
m_proxies.upper_bound(recordname);
558 for (ProxyMap::const_iterator p = b; p !=
e; ++
p) {
560 p->second->initConcurrentIOVs(nConcurrentIOVs);
570 std::set<cond::GTEntry_t>& tagcoll,
572 if (!roottag.empty()) {
573 if (connectionString.empty())
576 std::tuple<std::string, std::string, std::string> connPars =
578 if (std::get<2>(connPars) ==
"CMS_COND_31X_GLOBALTAG") {
580 <<
"[WARNING] You are reading Global Tag \"" << roottag
581 <<
"\" from V1 account \"CMS_COND_31X_GLOBALTAG\". The concerned Conditions might be out of date." 583 }
else if (roottag.rfind(
"::All") != std::string::npos && std::get<2>(connPars) ==
"CMS_CONDITIONS") {
584 edm::LogWarning(
"CondDBESSource") <<
"[WARNING] You are trying to read Global Tag \"" << roottag
585 <<
"\" - postfix \"::All\" should not be used for V2." << std::endl;
591 for (
const auto& gte : gtp) {
601 const std::vector<std::string>& prefixList,
602 const std::vector<std::string>& postfixList,
603 const std::vector<std::string>& roottagList,
604 std::map<std::string, cond::GTEntry_t>& replacement,
606 std::set<cond::GTEntry_t> tagcoll;
609 auto prefix = prefixList.begin();
610 auto postfix = postfixList.begin();
611 for (
auto roottag = roottagList.begin(); roottag != roottagList.end();
616 std::set<cond::GTEntry_t>::iterator tagCollIter;
617 std::set<cond::GTEntry_t>::iterator tagCollBegin = tagcoll.begin();
618 std::set<cond::GTEntry_t>::iterator tagCollEnd = tagcoll.end();
621 for (tagCollIter = tagCollBegin; tagCollIter != tagCollEnd; ++tagCollIter) {
622 std::string recordLabelKey = joinRecordAndLabel(tagCollIter->recordName(), tagCollIter->recordLabel());
623 std::map<std::string, cond::GTEntry_t>::iterator fid = replacement.find(recordLabelKey);
624 if (fid != replacement.end()) {
625 if (!fid->second.tagName().empty()) {
627 std::make_tuple(tagCollIter->recordName(), tagCollIter->recordLabel(), fid->second.tagName()));
629 edm::LogInfo(
"CondDBESSource") <<
"Replacing tag \"" << tagCollIter->tagName() <<
"\" for record \"" 631 <<
"\" with tag " << tagMetadata.
tagName()
632 <<
"\"; from CondDBESSource::fillTagCollectionFromDB";
636 replacement.erase(fid);
641 std::map<std::string, cond::GTEntry_t>::iterator replacementIter;
642 std::map<std::string, cond::GTEntry_t>::iterator replacementBegin = replacement.begin();
643 std::map<std::string, cond::GTEntry_t>::iterator replacementEnd = replacement.end();
644 for (replacementIter = replacementBegin; replacementIter != replacementEnd; ++replacementIter) {
645 if (replacementIter->second.tagName().empty()) {
646 std::stringstream
msg;
647 msg <<
"ESSource: no tag provided for record " << replacementIter->second.recordName();
648 if (!replacementIter->second.recordLabel().empty())
649 msg <<
" and label " << replacementIter->second.recordLabel();
persistency::Exception Exception
const TimeTypeSpecs timeTypeSpecs[]
std::vector< std::string_view > split(std::string_view, const char *)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
std::tuple< std::string, std::string, std::string > parseConnectionString(const std::string &connectionString)
Base exception class for the object to relational access.
void usingRecordWithKey(const EventSetupRecordKey &key)
const EventID & eventID() const
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
static HCTypeTag findType(char const *iTypeName)
find a type based on the types name, if not found will return default HCTypeTag
std::map< std::string, std::pair< cond::persistency::Session, std::string > > m_sessionPool
Transaction & transaction()
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)
std::string const & timeTypeNames(int)
std::string const & label() const
unsigned long long Time_t
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()
cond::persistency::ConnectionPool m_connection
const char * name() const
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::string const & connString() const
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
const Time_t TIMELIMIT(std::numeric_limits< Time_t >::max())
~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)
const std::string & tagName() const
const Timestamp & time() const
edm::IOVSyncValue limitedIOVSyncValue(Time_t time, TimeType timetype)
#define DEFINE_FWK_EVENTSETUP_SOURCE(type)
const IOVSyncValue & first() const
CondDBESSource(const edm::ParameterSet &)
GTProxy readGlobalTag(const std::string &name)
std::map< std::string, unsigned int > m_lastRecordRuns
TimeValue_t value() const
void findingRecordWithKey(const eventsetup::EventSetupRecordKey &)
static const IOVSyncValue & invalidIOVSyncValue()