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);
334 std::vector<std::string>& listToFill,
335 const unsigned int listSize,
337 boost::split(listToFill, stringList, boost::is_any_of(
"|"), boost::token_compress_off);
339 if (listToFill.size() == 1) {
340 for (
unsigned int i = 1;
i < listSize; ++
i) {
341 listToFill.push_back(stringList);
345 else if (listSize != listToFill.size()) {
347 std::string(
"ESSource: number of global tag components does not match number of " +
type +
" strings"));
352 std::cout <<
"CondDBESSource Statistics\n" 353 <<
"DataProxy " <<
stats.nData <<
" setInterval " <<
stats.nSet <<
" Runs " <<
stats.nRun <<
" Lumis " 354 <<
stats.nLumi <<
" Refresh " <<
stats.nRefresh <<
" Actual Refresh " <<
stats.nActualRefresh
355 <<
" Reconnect " <<
stats.nReconnect <<
" Actual Reconnect " <<
stats.nActualReconnect << std::endl;
364 std::cerr <<
"Error opening file to write JSON data." << std::endl;
376 for (;
b !=
e;
b++) {
387 const auto& proxy = *
entry.second;
388 dumpInfoJson(jsonData, recName, proxy);
406 edm::LogInfo(
"CondDBESSource") <<
"Getting data for record \"" << recordname
407 <<
"\" to be consumed on Run: " << iTime.
eventID().
run()
409 <<
" - Timestamp: " << iTime.
time().
value() <<
"; from CondDBESSource::setIntervalFor";
411 std::lock_guard<std::mutex> guard(
m_mutex);
423 bool doRefresh =
false;
425 bool refreshThisRecord =
false;
426 bool reconnectThisRecord =
false;
430 if (refreshThisRecord) {
431 defaultIovSize = iR->second.first;
432 reconnectThisRecord = iR->second.second;
433 iR->second.second =
false;
438 std::map<std::string, unsigned int>::iterator iRec =
m_lastRecordRuns.find(recordname);
445 edm::LogInfo(
"CondDBESSource") <<
"Preparing refresh for record \"" << recordname
446 <<
"\" since there has been a transition from run/lumi " << lastRecordRun
447 <<
" to run/lumi " <<
m_lastRun <<
"; from CondDBESSource::setIntervalFor";
452 edm::LogInfo(
"CondDBESSource") <<
"Preparing refresh for record \"" << recordname <<
"\" for " << iTime.
eventID()
453 <<
", timestamp: " << iTime.
time().
value()
454 <<
"; from CondDBESSource::setIntervalFor";
457 edm::LogInfo(
"CondDBESSource") <<
"Though enabled, refresh not needed for record \"" << recordname <<
"\" for " 459 <<
"; from CondDBESSource::setIntervalFor";
462 edm::LogInfo(
"CondDBESSource") <<
"Forcing refresh for record \"" << recordname <<
"\" for " << iTime.
eventID()
463 <<
", timestamp: " << iTime.
time().
value()
464 <<
"; from CondDBESSource::setIntervalFor";
472 bool userTime =
true;
475 ResolverMap::const_iterator pmBegin =
m_resolvers.lower_bound(recordname);
476 ResolverMap::const_iterator pmEnd =
m_resolvers.upper_bound(recordname);
477 if (pmBegin == pmEnd) {
478 edm::LogInfo(
"CondDBESSource") <<
"No ProductResolver (Pluging) found for record \"" << recordname
479 <<
"\"; from CondDBESSource::setIntervalFor";
483 for (ResolverMap::const_iterator pmIter = pmBegin; pmIter != pmEnd; ++pmIter) {
484 edm::LogInfo(
"CondDBESSource") <<
"Processing record \"" << recordname <<
"\" and label \"" 485 << pmIter->second->label() <<
"\" for " << iTime.
eventID()
486 <<
", timestamp: " << iTime.
time().
value()
487 <<
"; from CondDBESSource::setIntervalFor";
489 timetype = (*pmIter).second->timeType();
492 userTime = (0 == abtime);
497 if (doRefresh || refreshThisRecord) {
498 std::string recKey = joinRecordAndLabel(recordname, pmIter->second->label());
501 edm::LogInfo(
"CondDBESSource") <<
"No Tag found for record \"" << recordname <<
"\" and label \"" 502 << pmIter->second->label() <<
"\"; from CondDBESSource::setIntervalFor";
509 <<
"Checking if the session must be closed and re-opened for getting correct conditions" 510 <<
"; from CondDBESSource::setIntervalFor";
512 if (!reconnectThisRecord) {
519 if (!tagParams.second.empty())
520 connStr = tagParams.second;
522 if (refreshThisRecord) {
525 auto iSess = sessionPool->find(connStr);
527 if (iSess != sessionPool->end()) {
528 if (iSess->second.second != transId) {
531 iSess->second.second = transId;
541 edm::LogInfo(
"CondDBESSource") <<
"Re-opening the session with connection string " << connStr
542 <<
" and new transaction Id " << transId
543 <<
"; from CondDBESSource::setIntervalFor";
546 edm::LogInfo(
"CondDBESSource") <<
"Reconnecting to \"" << connStr <<
"\" for getting new payload for record \"" 547 << recordname <<
"\" and label \"" << pmIter->second->label()
548 <<
"\" from IOV tag \"" << tcIter->second.tagName() <<
"\" to be consumed by " 550 <<
"; from CondDBESSource::setIntervalFor";
551 pmIter->second->session() = iSess->second.first;
552 pmIter->second->reload();
555 edm::LogInfo(
"CondDBESSource") <<
"Refreshing IOV sequence labeled by tag \"" << tcIter->second.tagName()
556 <<
"\" for getting new payload for record \"" << recordname <<
"\" and label \"" 557 << pmIter->second->label() <<
"\" to be consumed by " << iTime.
eventID()
558 <<
", timestamp: " << iTime.
time().
value()
559 <<
"; from CondDBESSource::setIntervalFor";
560 pmIter->second->reload();
568 edm::LogInfo(
"CondDBESSource") <<
"Validity coming from IOV sequence for record \"" << recordname
569 <<
"\" and label \"" << pmIter->second->label() <<
"\": (" << validity.first <<
", " 571 << abtime <<
"; from CondDBESSource::setIntervalFor";
573 recordValidity.first =
std::max(recordValidity.first, validity.first);
574 recordValidity.second =
std::min(recordValidity.second, validity.second);
576 iR->second.second =
true;
580 recordValidity.second = 0;
587 edm::LogInfo(
"CondDBESSource") <<
"Validity for record \"" << recordname
588 <<
"\" and the corresponding label(s) coming from Condition DB: (" 589 << recordValidity.first <<
", " << recordValidity.first
590 <<
") as the last IOV element in the IOV sequence is infinity" 591 <<
"; from CondDBESSource::setIntervalFor";
595 if ((!userTime) && recordValidity.second != 0) {
606 edm::LogInfo(
"CondDBESSource") <<
"Setting validity for record \"" << recordname
607 <<
"\" and corresponding label(s): starting at " << oInterval.
first().
eventID()
608 <<
", timestamp: " << oInterval.
first().
time().
value() <<
", ending at " 611 <<
"; from CondDBESSource::setIntervalFor";
621 ResolverMap::const_iterator
b =
m_resolvers.lower_bound(recordname);
622 ResolverMap::const_iterator
e =
m_resolvers.upper_bound(recordname);
624 edm::LogInfo(
"CondDBESSource") <<
"No ProductResolver (Pluging) found for record \"" << recordname
625 <<
"\"; from CondDBESSource::registerResolvers";
626 return keyedResolversVector;
629 for (ResolverMap::const_iterator
p =
b;
p !=
e; ++
p) {
630 if (
nullptr != (*p).second.get()) {
633 keyedResolversVector.emplace_back(
key, (*p).second->esResolver(iovIndex));
636 return keyedResolversVector;
641 ResolverMap::const_iterator
b =
m_resolvers.lower_bound(recordname);
642 ResolverMap::const_iterator
e =
m_resolvers.upper_bound(recordname);
643 for (ResolverMap::const_iterator
p =
b;
p !=
e; ++
p) {
645 p->second->initConcurrentIOVs(nConcurrentIOVs);
655 std::set<cond::GTEntry_t>& tagcoll,
657 if (!roottag.empty()) {
661 std::tuple<std::string, std::string, std::string> connPars =
663 if (std::get<2>(connPars) ==
"CMS_COND_31X_GLOBALTAG") {
665 <<
"[WARNING] You are reading Global Tag \"" << roottag
666 <<
"\" from V1 account \"CMS_COND_31X_GLOBALTAG\". The concerned Conditions might be out of date." 668 }
else if (roottag.rfind(
"::All") != std::string::npos && std::get<2>(connPars) ==
"CMS_CONDITIONS") {
669 edm::LogWarning(
"CondDBESSource") <<
"[WARNING] You are trying to read Global Tag \"" << roottag
670 <<
"\" - postfix \"::All\" should not be used for V2." << std::endl;
676 for (
const auto& gte : gtp) {
686 const std::vector<std::string>& prefixList,
687 const std::vector<std::string>& postfixList,
688 const std::vector<std::string>& roottagList,
689 std::map<std::string, cond::GTEntry_t>& replacement,
691 std::set<cond::GTEntry_t> tagcoll;
694 auto prefix = prefixList.begin();
695 auto postfix = postfixList.begin();
696 for (
auto roottag = roottagList.begin(); roottag != roottagList.end();
701 std::set<cond::GTEntry_t>::iterator tagCollIter;
702 std::set<cond::GTEntry_t>::iterator tagCollBegin = tagcoll.begin();
703 std::set<cond::GTEntry_t>::iterator tagCollEnd = tagcoll.end();
706 for (tagCollIter = tagCollBegin; tagCollIter != tagCollEnd; ++tagCollIter) {
707 std::string recordLabelKey = joinRecordAndLabel(tagCollIter->recordName(), tagCollIter->recordLabel());
708 std::map<std::string, cond::GTEntry_t>::iterator fid = replacement.find(recordLabelKey);
709 if (fid != replacement.end()) {
710 if (!fid->second.tagName().empty()) {
712 std::make_tuple(tagCollIter->recordName(), tagCollIter->recordLabel(), fid->second.tagName()));
714 edm::LogInfo(
"CondDBESSource") <<
"Replacing tag \"" << tagCollIter->tagName() <<
"\" for record \"" 716 <<
"\" with tag " << tagMetadata.
tagName()
717 <<
"\"; from CondDBESSource::fillTagCollectionFromDB";
721 replacement.erase(fid);
726 std::map<std::string, cond::GTEntry_t>::iterator replacementIter;
727 std::map<std::string, cond::GTEntry_t>::iterator replacementBegin = replacement.begin();
728 std::map<std::string, cond::GTEntry_t>::iterator replacementEnd = replacement.end();
729 for (replacementIter = replacementBegin; replacementIter != replacementEnd; ++replacementIter) {
730 if (replacementIter->second.tagName().empty()) {
731 std::stringstream
msg;
732 msg <<
"ESSource: no tag provided for record " << replacementIter->second.recordName();
733 if (!replacementIter->second.recordLabel().empty())
734 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()
static HCTypeTag findType(char const *iTypeName)
find a type based on the types name, if not found will return default HCTypeTag