15 #include <boost/algorithm/string.hpp> 33 #include <nlohmann/json.hpp> 56 ~CondGetterFromESSource()
override {}
59 CondDBESSource::ResolverMap::const_iterator
p = m_resolvers.find(
name);
60 if (
p != m_resolvers.end())
61 return (*p).second->iovProxy();
86 out <<
"Time look up, payloadIds:" << std::endl;
87 const auto& pids = *proxy.
requests();
88 for (
const auto&
id : pids)
89 out <<
" " <<
id.since <<
" - " <<
id.till <<
" : " <<
id.payloadId << std::endl;
94 recordData[
"label"] = proxy.
label();
95 recordData[
"connectionString"] = proxy.
connString();
96 recordData[
"tag"] = proxy.
tag();
100 recordData[
"timeLookupPayloadIds"] =
json::array();
101 const auto& pids = *proxy.
requests();
102 for (
const auto&
id : pids) {
104 payloadIdData[
"since"] =
id.since;
105 payloadIdData[
"till"] =
id.till;
106 payloadIdData[
"payloadId"] =
id.payloadId;
107 recordData[
"timeLookupPayloadIds"].push_back(payloadIdData);
110 jsonData[recName].push_back(recordData);
124 : m_jsonDumpFilename(iConfig.getUntrackedParameter<
std::
string>(
"JsonDumpFileName",
"")),
126 m_connectionString(
""),
131 m_doDump(iConfig.getUntrackedParameter<
bool>(
"DumpStat",
false)) {
145 Stats s = {0, 0, 0, 0, 0, 0, 0, 0};
151 if (iConfig.
exists(
"globaltag")) {
166 }
else if (iConfig.
exists(
"connect"))
174 if (iConfig.
exists(
"snapshotTime")) {
176 if (!snapshotTimeString.empty())
177 snapshotTime = boost::posix_time::time_from_string(snapshotTimeString);
181 if (iConfig.
exists(
"DBParameters")) {
188 std::map<std::string, cond::GTEntry_t> replacements;
189 std::map<std::string, boost::posix_time::ptime> specialSnapshots;
190 if (iConfig.
exists(
"toGet")) {
191 typedef std::vector<edm::ParameterSet>
Parameters;
193 for (Parameters::iterator itToGet =
toGet.begin(); itToGet !=
toGet.end(); ++itToGet) {
195 if (recordname.empty())
196 throw cond::Exception(
"ESSource: The record name has not been provided in a \"toGet\" entry.");
200 pfn = itToGet->getParameter<
std::string>(
"connect");
203 if (itToGet->exists(
"tag")) {
207 boost::posix_time::ptime tagSnapshotTime =
209 if (itToGet->exists(
"snapshotTime"))
210 tagSnapshotTime = boost::posix_time::time_from_string(itToGet->getParameter<
std::string>(
"snapshotTime"));
211 if (itToGet->exists(
"refreshTime")) {
216 std::string recordLabelKey = joinRecordAndLabel(recordname, labelname);
218 std::make_pair(recordLabelKey,
cond::GTEntry_t(std::make_tuple(recordname, labelname, fqTag))));
219 specialSnapshots.insert(std::make_pair(recordLabelKey, tagSnapshotTime));
224 std::vector<std::string> globaltagList;
225 std::vector<std::string> connectList;
226 std::vector<std::string> pfnPrefixList;
227 std::vector<std::string> pfnPostfixList;
243 TagCollection::iterator
it;
247 std::map<std::string, cond::persistency::Session> sessions;
257 std::vector<std::unique_ptr<cond::ProductResolverWrapperBase>> resolverWrappers(
m_tagCollection.size());
259 for (
it = itBeg;
it != itEnd; ++
it) {
261 resolverWrappers[ind] = std::unique_ptr<cond::ProductResolverWrapperBase>{
263 if (!resolverWrappers[ind].
get()) {
264 edm::LogWarning(
"CondDBESSource") <<
"Plugin for Record " <<
it->second.recordName() <<
" has not been found.";
271 for (
it = itBeg;
it != itEnd; ++
it) {
275 if (!tagParams.second.empty()) {
276 connStr = tagParams.second;
277 tag = tagParams.first;
279 std::map<std::string, cond::persistency::Session>::iterator
p = sessions.find(connStr);
281 if (
p == sessions.end()) {
283 std::tuple<std::string, std::string, std::string> connPars =
287 if ((dbService ==
"cms_orcon_prod" || dbService ==
"cms_orcon_adg") && dbAccount !=
"CMS_CONDITIONS")
289 <<
"[WARNING] You are reading tag \"" <<
tag <<
"\" from V1 account \"" << connStr
290 <<
"\". The concerned Conditions might be out of date." << std::endl;
293 sessions.insert(std::make_pair(connStr, nsess));
300 if (resolver.get()) {
301 m_resolvers.insert(std::make_pair(
it->second.recordName(), resolver));
303 boost::posix_time::ptime tagSnapshotTime =
snapshotTime;
304 auto tagSnapshotIter = specialSnapshots.find(
it->first);
305 if (tagSnapshotIter != specialSnapshots.end())
306 tagSnapshotTime = tagSnapshotIter->second;
309 tagSnapshotTime = boost::posix_time::ptime();
311 resolver->lateInit(nsess,
tag, tagSnapshotTime,
it->second.recordLabel(), connStr, &
m_queue, &
m_mutex);
319 for (;
b !=
e;
b++) {
320 (*b).second->proxy(0)->loadMore(visitor);
328 edm::LogWarning(
"CondDBESSource") <<
"Failed to load key for record " <<
b->first
329 <<
". No data from this record will be available.";
337 std::vector<std::string>& listToFill,
338 const unsigned int listSize,
340 boost::split(listToFill, stringList, boost::is_any_of(
"|"), boost::token_compress_off);
342 if (listToFill.size() == 1) {
343 for (
unsigned int i = 1;
i < listSize; ++
i) {
344 listToFill.push_back(stringList);
348 else if (listSize != listToFill.size()) {
350 std::string(
"ESSource: number of global tag components does not match number of " +
type +
" strings"));
355 std::cout <<
"CondDBESSource Statistics\n" 356 <<
"DataProxy " <<
stats.nData <<
" setInterval " <<
stats.nSet <<
" Runs " <<
stats.nRun <<
" Lumis " 357 <<
stats.nLumi <<
" Refresh " <<
stats.nRefresh <<
" Actual Refresh " <<
stats.nActualRefresh
358 <<
" Reconnect " <<
stats.nReconnect <<
" Actual Reconnect " <<
stats.nActualReconnect << std::endl;
367 std::cerr <<
"Error opening file to write JSON data." << std::endl;
379 for (;
b !=
e;
b++) {
390 const auto& proxy = *
entry.second;
391 dumpInfoJson(jsonData, recName, proxy);
409 edm::LogInfo(
"CondDBESSource") <<
"Getting data for record \"" << recordname
410 <<
"\" to be consumed on Run: " << iTime.
eventID().
run()
412 <<
" - Timestamp: " << iTime.
time().
value() <<
"; from CondDBESSource::setIntervalFor";
414 std::lock_guard<std::mutex> guard(
m_mutex);
426 bool doRefresh =
false;
428 bool refreshThisRecord =
false;
429 bool reconnectThisRecord =
false;
433 if (refreshThisRecord) {
434 defaultIovSize = iR->second.first;
435 reconnectThisRecord = iR->second.second;
436 iR->second.second =
false;
441 std::map<std::string, unsigned int>::iterator iRec =
m_lastRecordRuns.find(recordname);
448 edm::LogInfo(
"CondDBESSource") <<
"Preparing refresh for record \"" << recordname
449 <<
"\" since there has been a transition from run/lumi " << lastRecordRun
450 <<
" to run/lumi " <<
m_lastRun <<
"; from CondDBESSource::setIntervalFor";
455 edm::LogInfo(
"CondDBESSource") <<
"Preparing refresh for record \"" << recordname <<
"\" for " << iTime.
eventID()
456 <<
", timestamp: " << iTime.
time().
value()
457 <<
"; from CondDBESSource::setIntervalFor";
460 edm::LogInfo(
"CondDBESSource") <<
"Though enabled, refresh not needed for record \"" << recordname <<
"\" for " 462 <<
"; from CondDBESSource::setIntervalFor";
465 edm::LogInfo(
"CondDBESSource") <<
"Forcing refresh for record \"" << recordname <<
"\" for " << iTime.
eventID()
466 <<
", timestamp: " << iTime.
time().
value()
467 <<
"; from CondDBESSource::setIntervalFor";
475 bool userTime =
true;
478 ResolverMap::const_iterator pmBegin =
m_resolvers.lower_bound(recordname);
479 ResolverMap::const_iterator pmEnd =
m_resolvers.upper_bound(recordname);
480 if (pmBegin == pmEnd) {
481 edm::LogInfo(
"CondDBESSource") <<
"No ProductResolver (Pluging) found for record \"" << recordname
482 <<
"\"; from CondDBESSource::setIntervalFor";
486 for (ResolverMap::const_iterator pmIter = pmBegin; pmIter != pmEnd; ++pmIter) {
487 edm::LogInfo(
"CondDBESSource") <<
"Processing record \"" << recordname <<
"\" and label \"" 488 << pmIter->second->label() <<
"\" for " << iTime.
eventID()
489 <<
", timestamp: " << iTime.
time().
value()
490 <<
"; from CondDBESSource::setIntervalFor";
492 timetype = (*pmIter).second->timeType();
495 userTime = (0 == abtime);
500 if (doRefresh || refreshThisRecord) {
501 std::string recKey = joinRecordAndLabel(recordname, pmIter->second->label());
504 edm::LogInfo(
"CondDBESSource") <<
"No Tag found for record \"" << recordname <<
"\" and label \"" 505 << pmIter->second->label() <<
"\"; from CondDBESSource::setIntervalFor";
512 <<
"Checking if the session must be closed and re-opened for getting correct conditions" 513 <<
"; from CondDBESSource::setIntervalFor";
515 if (!reconnectThisRecord) {
522 if (!tagParams.second.empty())
523 connStr = tagParams.second;
525 if (refreshThisRecord) {
528 auto iSess = sessionPool->find(connStr);
530 if (iSess != sessionPool->end()) {
531 if (iSess->second.second != transId) {
534 iSess->second.second = transId;
544 edm::LogInfo(
"CondDBESSource") <<
"Re-opening the session with connection string " << connStr
545 <<
" and new transaction Id " << transId
546 <<
"; from CondDBESSource::setIntervalFor";
549 edm::LogInfo(
"CondDBESSource") <<
"Reconnecting to \"" << connStr <<
"\" for getting new payload for record \"" 550 << recordname <<
"\" and label \"" << pmIter->second->label()
551 <<
"\" from IOV tag \"" << tcIter->second.tagName() <<
"\" to be consumed by " 553 <<
"; from CondDBESSource::setIntervalFor";
554 pmIter->second->session() = iSess->second.first;
555 pmIter->second->reload();
558 edm::LogInfo(
"CondDBESSource") <<
"Refreshing IOV sequence labeled by tag \"" << tcIter->second.tagName()
559 <<
"\" for getting new payload for record \"" << recordname <<
"\" and label \"" 560 << pmIter->second->label() <<
"\" to be consumed by " << iTime.
eventID()
561 <<
", timestamp: " << iTime.
time().
value()
562 <<
"; from CondDBESSource::setIntervalFor";
563 pmIter->second->reload();
571 edm::LogInfo(
"CondDBESSource") <<
"Validity coming from IOV sequence for record \"" << recordname
572 <<
"\" and label \"" << pmIter->second->label() <<
"\": (" << validity.first <<
", " 574 << abtime <<
"; from CondDBESSource::setIntervalFor";
576 recordValidity.first =
std::max(recordValidity.first, validity.first);
577 recordValidity.second =
std::min(recordValidity.second, validity.second);
579 iR->second.second =
true;
583 recordValidity.second = 0;
590 edm::LogInfo(
"CondDBESSource") <<
"Validity for record \"" << recordname
591 <<
"\" and the corresponding label(s) coming from Condition DB: (" 592 << recordValidity.first <<
", " << recordValidity.first
593 <<
") as the last IOV element in the IOV sequence is infinity" 594 <<
"; from CondDBESSource::setIntervalFor";
598 if ((!userTime) && recordValidity.second != 0) {
609 edm::LogInfo(
"CondDBESSource") <<
"Setting validity for record \"" << recordname
610 <<
"\" and corresponding label(s): starting at " << oInterval.
first().
eventID()
611 <<
", timestamp: " << oInterval.
first().
time().
value() <<
", ending at " 614 <<
"; from CondDBESSource::setIntervalFor";
624 ResolverMap::const_iterator
b =
m_resolvers.lower_bound(recordname);
625 ResolverMap::const_iterator
e =
m_resolvers.upper_bound(recordname);
627 edm::LogInfo(
"CondDBESSource") <<
"No ProductResolver (Pluging) found for record \"" << recordname
628 <<
"\"; from CondDBESSource::registerResolvers";
629 return keyedResolversVector;
632 for (ResolverMap::const_iterator
p =
b;
p !=
e; ++
p) {
633 if (
nullptr != (*p).second.get()) {
636 keyedResolversVector.emplace_back(
key, (*p).second->esResolver(iovIndex));
639 return keyedResolversVector;
644 ResolverMap::const_iterator
b =
m_resolvers.lower_bound(recordname);
645 ResolverMap::const_iterator
e =
m_resolvers.upper_bound(recordname);
646 for (ResolverMap::const_iterator
p =
b;
p !=
e; ++
p) {
648 p->second->initConcurrentIOVs(nConcurrentIOVs);
658 std::set<cond::GTEntry_t>& tagcoll,
660 if (!roottag.empty()) {
664 std::tuple<std::string, std::string, std::string> connPars =
666 if (std::get<2>(connPars) ==
"CMS_COND_31X_GLOBALTAG") {
668 <<
"[WARNING] You are reading Global Tag \"" << roottag
669 <<
"\" from V1 account \"CMS_COND_31X_GLOBALTAG\". The concerned Conditions might be out of date." 671 }
else if (roottag.rfind(
"::All") != std::string::npos && std::get<2>(connPars) ==
"CMS_CONDITIONS") {
672 edm::LogWarning(
"CondDBESSource") <<
"[WARNING] You are trying to read Global Tag \"" << roottag
673 <<
"\" - postfix \"::All\" should not be used for V2." << std::endl;
679 for (
const auto& gte : gtp) {
689 const std::vector<std::string>& prefixList,
690 const std::vector<std::string>& postfixList,
691 const std::vector<std::string>& roottagList,
692 std::map<std::string, cond::GTEntry_t>& replacement,
694 std::set<cond::GTEntry_t> tagcoll;
697 auto prefix = prefixList.begin();
698 auto postfix = postfixList.begin();
699 for (
auto roottag = roottagList.begin(); roottag != roottagList.end();
704 std::set<cond::GTEntry_t>::iterator tagCollIter;
705 std::set<cond::GTEntry_t>::iterator tagCollBegin = tagcoll.begin();
706 std::set<cond::GTEntry_t>::iterator tagCollEnd = tagcoll.end();
709 for (tagCollIter = tagCollBegin; tagCollIter != tagCollEnd; ++tagCollIter) {
710 std::string recordLabelKey = joinRecordAndLabel(tagCollIter->recordName(), tagCollIter->recordLabel());
711 std::map<std::string, cond::GTEntry_t>::iterator fid = replacement.find(recordLabelKey);
712 if (fid != replacement.end()) {
713 if (!fid->second.tagName().empty()) {
715 std::make_tuple(tagCollIter->recordName(), tagCollIter->recordLabel(), fid->second.tagName()));
717 edm::LogInfo(
"CondDBESSource") <<
"Replacing tag \"" << tagCollIter->tagName() <<
"\" for record \"" 719 <<
"\" with tag " << tagMetadata.
tagName()
720 <<
"\"; from CondDBESSource::fillTagCollectionFromDB";
724 replacement.erase(fid);
729 std::map<std::string, cond::GTEntry_t>::iterator replacementIter;
730 std::map<std::string, cond::GTEntry_t>::iterator replacementBegin = replacement.begin();
731 std::map<std::string, cond::GTEntry_t>::iterator replacementEnd = replacement.end();
732 for (replacementIter = replacementBegin; replacementIter != replacementEnd; ++replacementIter) {
733 if (replacementIter->second.tagName().empty()) {
734 std::stringstream
msg;
735 msg <<
"ESSource: no tag provided for record " << replacementIter->second.recordName();
736 if (!replacementIter->second.recordLabel().empty())
737 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
void saveJsonToFile(const json &jsonData, const std::string &filename)
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
void printStatistics(const Stats &stats) const
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)
key
prepare the HTCondor submission files and eventually submit them
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::string m_jsonDumpFilename
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
if(threadIdxLocalY==0 &&threadIdxLocalX==0)
const char * name() const
const Time_t MAX_VAL(std::numeric_limits< Time_t >::max())
void findingRecordWithKey(const eventsetup::EventSetupRecordKey &)
static const IOVSyncValue & invalidIOVSyncValue()