15 #include <boost/algorithm/string.hpp> 52 ~CondGetterFromESSource()
override {}
55 CondDBESSource::ResolverMap::const_iterator
p = m_resolvers.find(
name);
56 if (
p != m_resolvers.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"))
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;
217 TagCollection::iterator it;
221 std::map<std::string, cond::persistency::Session> sessions;
231 std::vector<std::unique_ptr<cond::ProductResolverWrapperBase>> resolverWrappers(
m_tagCollection.size());
233 for (it = itBeg; it != itEnd; ++it) {
235 resolverWrappers[ind] = std::unique_ptr<cond::ProductResolverWrapperBase>{
237 if (!resolverWrappers[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));
274 if (resolver.get()) {
275 m_resolvers.insert(std::make_pair(it->second.recordName(), resolver));
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 resolver->lateInit(nsess,
tag, tagSnapshotTime, it->second.recordLabel(), connStr, &
m_queue, &
m_mutex);
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
357 <<
"\" to be consumed on Run: " << iTime.
eventID().
run()
359 <<
" - Timestamp: " << iTime.
time().
value() <<
"; from CondDBESSource::setIntervalFor";
361 std::lock_guard<std::mutex> guard(
m_mutex);
373 bool doRefresh =
false;
375 bool refreshThisRecord =
false;
376 bool reconnectThisRecord =
false;
380 if (refreshThisRecord) {
381 defaultIovSize = iR->second.first;
382 reconnectThisRecord = iR->second.second;
383 iR->second.second =
false;
388 std::map<std::string, unsigned int>::iterator iRec =
m_lastRecordRuns.find(recordname);
395 edm::LogInfo(
"CondDBESSource") <<
"Preparing refresh for record \"" << recordname
396 <<
"\" since there has been a transition from run/lumi " << lastRecordRun
397 <<
" to run/lumi " <<
m_lastRun <<
"; 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 ResolverMap::const_iterator pmBegin =
m_resolvers.lower_bound(recordname);
426 ResolverMap::const_iterator pmEnd =
m_resolvers.upper_bound(recordname);
427 if (pmBegin == pmEnd) {
428 edm::LogInfo(
"CondDBESSource") <<
"No ProductResolver (Pluging) found for record \"" << recordname
429 <<
"\"; from CondDBESSource::setIntervalFor";
433 for (ResolverMap::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);
447 if (doRefresh || refreshThisRecord) {
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";
462 if (!reconnectThisRecord) {
469 if (!tagParams.second.empty())
470 connStr = tagParams.second;
472 if (refreshThisRecord) {
475 auto iSess = sessionPool->find(connStr);
477 if (iSess != sessionPool->end()) {
478 if (iSess->second.second != transId) {
481 iSess->second.second = transId;
491 edm::LogInfo(
"CondDBESSource") <<
"Re-opening the session with connection string " << connStr
492 <<
" and new transaction Id " << transId
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();
505 edm::LogInfo(
"CondDBESSource") <<
"Refreshing IOV sequence labeled by tag \"" << tcIter->second.tagName()
506 <<
"\" for getting new payload for record \"" << recordname <<
"\" and label \"" 507 << pmIter->second->label() <<
"\" to be consumed by " << iTime.
eventID()
508 <<
", timestamp: " << iTime.
time().
value()
509 <<
"; from CondDBESSource::setIntervalFor";
510 pmIter->second->reload();
518 edm::LogInfo(
"CondDBESSource") <<
"Validity coming from IOV sequence for record \"" << recordname
519 <<
"\" and label \"" << pmIter->second->label() <<
"\": (" << validity.first <<
", " 521 << abtime <<
"; from CondDBESSource::setIntervalFor";
523 recordValidity.first =
std::max(recordValidity.first, validity.first);
524 recordValidity.second =
std::min(recordValidity.second, validity.second);
526 iR->second.second =
true;
530 recordValidity.second = 0;
537 edm::LogInfo(
"CondDBESSource") <<
"Validity for record \"" << recordname
538 <<
"\" and the corresponding label(s) coming from Condition DB: (" 539 << recordValidity.first <<
", " << recordValidity.first
540 <<
") as the last IOV element in the IOV sequence is infinity" 541 <<
"; from CondDBESSource::setIntervalFor";
545 if ((!userTime) && recordValidity.second != 0) {
556 edm::LogInfo(
"CondDBESSource") <<
"Setting validity for record \"" << recordname
557 <<
"\" and corresponding label(s): starting at " << oInterval.
first().
eventID()
558 <<
", timestamp: " << oInterval.
first().
time().
value() <<
", ending at " 561 <<
"; from CondDBESSource::setIntervalFor";
571 ResolverMap::const_iterator
b =
m_resolvers.lower_bound(recordname);
572 ResolverMap::const_iterator
e =
m_resolvers.upper_bound(recordname);
574 edm::LogInfo(
"CondDBESSource") <<
"No ProductResolver (Pluging) found for record \"" << recordname
575 <<
"\"; from CondDBESSource::registerResolvers";
576 return keyedResolversVector;
579 for (ResolverMap::const_iterator
p =
b;
p !=
e; ++
p) {
580 if (
nullptr != (*p).second.get()) {
583 keyedResolversVector.emplace_back(
key, (*p).second->esResolver(iovIndex));
586 return keyedResolversVector;
591 ResolverMap::const_iterator
b =
m_resolvers.lower_bound(recordname);
592 ResolverMap::const_iterator
e =
m_resolvers.upper_bound(recordname);
593 for (ResolverMap::const_iterator
p =
b;
p !=
e; ++
p) {
595 p->second->initConcurrentIOVs(nConcurrentIOVs);
605 std::set<cond::GTEntry_t>& tagcoll,
607 if (!roottag.empty()) {
611 std::tuple<std::string, std::string, std::string> connPars =
613 if (std::get<2>(connPars) ==
"CMS_COND_31X_GLOBALTAG") {
615 <<
"[WARNING] You are reading Global Tag \"" << roottag
616 <<
"\" from V1 account \"CMS_COND_31X_GLOBALTAG\". The concerned Conditions might be out of date." 618 }
else if (roottag.rfind(
"::All") != std::string::npos && std::get<2>(connPars) ==
"CMS_CONDITIONS") {
619 edm::LogWarning(
"CondDBESSource") <<
"[WARNING] You are trying to read Global Tag \"" << roottag
620 <<
"\" - postfix \"::All\" should not be used for V2." << std::endl;
626 for (
const auto& gte : gtp) {
636 const std::vector<std::string>& prefixList,
637 const std::vector<std::string>& postfixList,
638 const std::vector<std::string>& roottagList,
639 std::map<std::string, cond::GTEntry_t>& replacement,
641 std::set<cond::GTEntry_t> tagcoll;
644 auto prefix = prefixList.begin();
645 auto postfix = postfixList.begin();
646 for (
auto roottag = roottagList.begin(); roottag != roottagList.end();
651 std::set<cond::GTEntry_t>::iterator tagCollIter;
652 std::set<cond::GTEntry_t>::iterator tagCollBegin = tagcoll.begin();
653 std::set<cond::GTEntry_t>::iterator tagCollEnd = tagcoll.end();
656 for (tagCollIter = tagCollBegin; tagCollIter != tagCollEnd; ++tagCollIter) {
657 std::string recordLabelKey = joinRecordAndLabel(tagCollIter->recordName(), tagCollIter->recordLabel());
658 std::map<std::string, cond::GTEntry_t>::iterator fid = replacement.find(recordLabelKey);
659 if (fid != replacement.end()) {
660 if (!fid->second.tagName().empty()) {
662 std::make_tuple(tagCollIter->recordName(), tagCollIter->recordLabel(), fid->second.tagName()));
664 edm::LogInfo(
"CondDBESSource") <<
"Replacing tag \"" << tagCollIter->tagName() <<
"\" for record \"" 666 <<
"\" with tag " << tagMetadata.
tagName()
667 <<
"\"; from CondDBESSource::fillTagCollectionFromDB";
671 replacement.erase(fid);
676 std::map<std::string, cond::GTEntry_t>::iterator replacementIter;
677 std::map<std::string, cond::GTEntry_t>::iterator replacementBegin = replacement.begin();
678 std::map<std::string, cond::GTEntry_t>::iterator replacementEnd = replacement.end();
679 for (replacementIter = replacementBegin; replacementIter != replacementEnd; ++replacementIter) {
680 if (replacementIter->second.tagName().empty()) {
681 std::stringstream
msg;
682 msg <<
"ESSource: no tag provided for record " << replacementIter->second.recordName();
683 if (!replacementIter->second.recordLabel().empty())
684 msg <<
" and label " << replacementIter->second.recordLabel();
const TypeTag & type() const
persistency::Exception Exception
const std::string & recordName() const
const TimeTypeSpecs timeTypeSpecs[]
const IOVSyncValue & last() const
std::map< std::string, std::pair< cond::Time_t, bool > > m_refreshTimeForRecord
std::tuple< std::string, std::string, std::string > parseConnectionString(const std::string &connectionString)
LuminosityBlockNumber_t luminosityBlockNumber() const
T getParameter(std::string const &) const
const IOVSyncValue & first() const
Base exception class for the object to relational access.
std::multimap< std::string, ResolverP > ResolverMap
void start(bool readOnly=true)
std::shared_ptr< cond::ProductResolverWrapperBase > ResolverP
void usingRecordWithKey(const EventSetupRecordKey &key)
bool exists(std::string const ¶meterName) const
checks if a parameter exists
void setIntervalFor(const EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &) override
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()
std::string const & label() const
std::string transactionIdForLumiTime(Time_t time, unsigned int iovSize, const std::string &secretKey)
std::string const & connString() const
static std::string to_string(const XMLCh *ch)
void setParameters(const edm::ParameterSet &connectionPset)
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 tillTimeForIOV(Time_t since, unsigned int iovSize, TimeType timeType)
T getUntrackedParameter(std::string const &, T const &) const
Time_t fromIOVSyncValue(edm::IOVSyncValue const &time, TimeType timetype)
edm::SerialTaskQueue m_queue
std::string const & timeTypeNames(int)
unsigned long long Time_t
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
edm::IOVSyncValue toIOVSyncValue(cond::Time_t time, TimeType timetype, bool startOrStop)
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)
boost::posix_time::ptime snapshotTime() const
std::map< std::string, std::pair< cond::persistency::Session, std::string > > m_sessionPoolForLumiConditions
std::shared_ptr< std::vector< Iov_t > > const & requests() const
def split(sequence, size)
Log< level::Info, false > LogInfo
const std::string & tagName() const
#define DEFINE_FWK_EVENTSETUP_SOURCE(type)
PoolDBESSource(const edm::ParameterSet &ps)
TimeValue_t value() const
TagCollection m_tagCollection
const Time_t TIMELIMIT(std::numeric_limits< Time_t >::max())
~CondDBESSource() override
std::vector< std::pair< DataKey, std::shared_ptr< ESProductResolver > >> KeyedResolversVector
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)
const EventID & eventID() const
std::vector< AlignmentParameters * > Parameters
heterocontainer::HCTypeTag TypeTag
std::string m_connectionString
const Timestamp & time() const
static const ValidityInterval & invalidInterval()
Session createReadOnlySession(const std::string &connectionString, const std::string &transactionId)
std::string m_frontierKey
edm::IOVSyncValue limitedIOVSyncValue(Time_t time, TimeType timetype)
Log< level::Warning, false > LogWarning
CondDBESSource(const edm::ParameterSet &)
GTProxy readGlobalTag(const std::string &name)
std::map< std::string, unsigned int > m_lastRecordRuns
KeyedResolversVector registerResolvers(const EventSetupRecordKey &, unsigned int iovIndex) override
const std::string & recordLabel() const
const char * name() const
const Time_t MAX_VAL(std::numeric_limits< Time_t >::max())
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