-
Notifications
You must be signed in to change notification settings - Fork 4.5k
provide a fillDescriptions
method for CondDBESSource
#47630
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ | |
#include <exception> | ||
|
||
#include <iomanip> | ||
#include <limits> | ||
|
||
#include <nlohmann/json.hpp> | ||
|
||
|
@@ -123,8 +124,9 @@ namespace { | |
CondDBESSource::CondDBESSource(const edm::ParameterSet& iConfig) | ||
: m_jsonDumpFilename(iConfig.getUntrackedParameter<std::string>("JsonDumpFileName", "")), | ||
m_connection(), | ||
m_connectionString(""), | ||
m_frontierKey(""), | ||
m_connectionString(iConfig.getParameter<std::string>("connect")), | ||
m_globalTag(iConfig.getParameter<std::string>("globaltag")), | ||
m_frontierKey(iConfig.getUntrackedParameter<std::string>("frontierKey", "")), | ||
m_lastRun(0), // for the stat | ||
m_lastLumi(0), // for the stat | ||
m_policy(NOREFRESH), | ||
|
@@ -147,69 +149,65 @@ CondDBESSource::CondDBESSource(const edm::ParameterSet& iConfig) | |
|
||
/*parameter set parsing | ||
*/ | ||
std::string globaltag(""); | ||
if (iConfig.exists("globaltag")) { | ||
globaltag = iConfig.getParameter<std::string>("globaltag"); | ||
// the global tag _requires_ a connection string | ||
m_connectionString = iConfig.getParameter<std::string>("connect"); | ||
|
||
if (!globaltag.empty()) { | ||
edm::Service<edm::SiteLocalConfig> siteLocalConfig; | ||
if (siteLocalConfig.isAvailable()) { | ||
if (siteLocalConfig->useLocalConnectString()) { | ||
std::string const& localConnectPrefix = siteLocalConfig->localConnectPrefix(); | ||
std::string const& localConnectSuffix = siteLocalConfig->localConnectSuffix(); | ||
m_connectionString = localConnectPrefix + globaltag + localConnectSuffix; | ||
} | ||
if (!m_globalTag.empty()) { | ||
edm::Service<edm::SiteLocalConfig> siteLocalConfig; | ||
if (siteLocalConfig.isAvailable()) { | ||
if (siteLocalConfig->useLocalConnectString()) { | ||
std::string const& localConnectPrefix = siteLocalConfig->localConnectPrefix(); | ||
std::string const& localConnectSuffix = siteLocalConfig->localConnectSuffix(); | ||
m_connectionString = localConnectPrefix + m_globalTag + localConnectSuffix; | ||
} | ||
} | ||
} else if (iConfig.exists("connect")) // default connection string | ||
m_connectionString = iConfig.getParameter<std::string>("connect"); | ||
|
||
// frontier key | ||
m_frontierKey = iConfig.getUntrackedParameter<std::string>("frontierKey", ""); | ||
} | ||
|
||
// snapshot | ||
boost::posix_time::ptime snapshotTime; | ||
if (iConfig.exists("snapshotTime")) { | ||
std::string snapshotTimeString = iConfig.getParameter<std::string>("snapshotTime"); | ||
if (!snapshotTimeString.empty()) | ||
snapshotTime = boost::posix_time::time_from_string(snapshotTimeString); | ||
std::string snapshotTimeString = iConfig.getParameter<std::string>("snapshotTime"); | ||
if (!snapshotTimeString.empty()) { | ||
snapshotTime = boost::posix_time::time_from_string(snapshotTimeString); | ||
} | ||
|
||
// connection configuration | ||
if (iConfig.exists("DBParameters")) { | ||
edm::ParameterSet connectionPset = iConfig.getParameter<edm::ParameterSet>("DBParameters"); | ||
m_connection.setParameters(connectionPset); | ||
} | ||
edm::ParameterSet connectionPset = iConfig.getParameter<edm::ParameterSet>("DBParameters"); | ||
m_connection.setParameters(connectionPset); | ||
m_connection.configure(); | ||
|
||
// load specific record/tag info - it will overwrite the global tag ( if any ) | ||
std::map<std::string, cond::GTEntry_t> replacements; | ||
std::map<std::string, boost::posix_time::ptime> specialSnapshots; | ||
if (iConfig.exists("toGet")) { | ||
typedef std::vector<edm::ParameterSet> Parameters; | ||
Parameters toGet = iConfig.getParameter<Parameters>("toGet"); | ||
|
||
typedef std::vector<edm::ParameterSet> Parameters; | ||
Parameters toGet = iConfig.getParameter<Parameters>("toGet"); | ||
if (!toGet.empty()) { | ||
for (Parameters::iterator itToGet = toGet.begin(); itToGet != toGet.end(); ++itToGet) { | ||
std::string recordname = itToGet->getParameter<std::string>("record"); | ||
if (recordname.empty()) | ||
throw cond::Exception("ESSource: The record name has not been provided in a \"toGet\" entry."); | ||
|
||
std::string labelname = itToGet->getUntrackedParameter<std::string>("label", ""); | ||
std::string pfn(""); | ||
if (m_connectionString.empty() || itToGet->exists("connect")) | ||
pfn = itToGet->getParameter<std::string>("connect"); | ||
std::string tag(""); | ||
const auto& recordConnection = itToGet->getParameter<std::string>("connect"); | ||
if (m_connectionString.empty() || !recordConnection.empty()) { | ||
pfn = recordConnection; | ||
} | ||
std::string tag = itToGet->getParameter<std::string>("tag"); | ||
std::string fqTag(""); | ||
if (itToGet->exists("tag")) { | ||
tag = itToGet->getParameter<std::string>("tag"); | ||
|
||
if (!tag.empty()) { | ||
fqTag = cond::persistency::fullyQualifiedTag(tag, pfn); | ||
} | ||
|
||
boost::posix_time::ptime tagSnapshotTime = | ||
boost::posix_time::time_from_string(std::string(cond::time::MAX_TIMESTAMP)); | ||
if (itToGet->exists("snapshotTime")) | ||
tagSnapshotTime = boost::posix_time::time_from_string(itToGet->getParameter<std::string>("snapshotTime")); | ||
if (itToGet->exists("refreshTime")) { | ||
cond::Time_t refreshTime = itToGet->getParameter<unsigned long long>("refreshTime"); | ||
|
||
const auto& snapshotTimeTagString = itToGet->getParameter<std::string>("snapshotTime"); | ||
if (!snapshotTimeTagString.empty()) { | ||
tagSnapshotTime = boost::posix_time::time_from_string(snapshotTimeTagString); | ||
} | ||
|
||
const auto& refreshTimeTag = itToGet->getParameter<unsigned long long>("refreshTime"); | ||
if (refreshTimeTag != std::numeric_limits<unsigned long long>::max()) { | ||
cond::Time_t refreshTime = refreshTimeTag; | ||
m_refreshTimeForRecord.insert(std::make_pair(recordname, std::make_pair(refreshTime, true))); | ||
} | ||
|
||
|
@@ -225,10 +223,10 @@ CondDBESSource::CondDBESSource(const edm::ParameterSet& iConfig) | |
std::vector<std::string> connectList; | ||
std::vector<std::string> pfnPrefixList; | ||
std::vector<std::string> pfnPostfixList; | ||
if (!globaltag.empty()) { | ||
if (!m_globalTag.empty()) { | ||
std::string pfnPrefix(iConfig.getUntrackedParameter<std::string>("pfnPrefix", "")); | ||
std::string pfnPostfix(iConfig.getUntrackedParameter<std::string>("pfnPostfix", "")); | ||
boost::split(globaltagList, globaltag, boost::is_any_of("|"), boost::token_compress_off); | ||
boost::split(globaltagList, m_globalTag, boost::is_any_of("|"), boost::token_compress_off); | ||
fillList(m_connectionString, connectList, globaltagList.size(), "connection"); | ||
fillList(pfnPrefix, pfnPrefixList, globaltagList.size(), "pfnPrefix"); | ||
fillList(pfnPostfix, pfnPostfixList, globaltagList.size(), "pfnPostfix"); | ||
|
@@ -741,6 +739,45 @@ void CondDBESSource::fillTagCollectionFromDB(const std::vector<std::string>& con | |
} | ||
} | ||
|
||
void CondDBESSource::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { | ||
edm::ParameterSetDescription desc; | ||
|
||
edm::ParameterSetDescription dbParams; | ||
dbParams.addUntracked<std::string>("authenticationPath", ""); | ||
dbParams.addUntracked<int>("authenticationSystem", 0); | ||
dbParams.addUntracked<std::string>("security", ""); | ||
dbParams.addUntracked<int>("messageLevel", 0); | ||
dbParams.addUntracked<int>("connectionTimeout", 0); | ||
desc.add("DBParameters", dbParams); | ||
|
||
desc.add<std::string>("connect", std::string("frontier://FrontierProd/CMS_CONDITIONS")); | ||
desc.add<std::string>("globaltag", ""); | ||
desc.add<std::string>("snapshotTime", ""); | ||
desc.addUntracked<std::string>("frontierKey", ""); | ||
|
||
edm::ParameterSetDescription toGetDesc; | ||
toGetDesc.add<std::string>("record", ""); | ||
toGetDesc.add<std::string>("tag", ""); | ||
toGetDesc.add<std::string>("snapshotTime", ""); | ||
toGetDesc.add<std::string>("connect", ""); | ||
toGetDesc.add<unsigned long long>("refreshTime", std::numeric_limits<unsigned long long>::max()); | ||
toGetDesc.addUntracked<std::string>("label", ""); | ||
|
||
std::vector<edm::ParameterSet> default_toGet(1); | ||
desc.addVPSet("toGet", toGetDesc, default_toGet); | ||
mmusich marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why one empty as the default value? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to validate the layout of the possible PSet, but not putting anything inside. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The framework will do that without injecting a dummy empty one. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
How do you actually propose to modify the code to do that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I asume the above means an empty toGet vector supplied by the user (which is valid/should be valid overall for no record to get) will get an empty PSet inserted by fillDescriptions, whihc in turn will make the plugin fail. This is not the expected behaviour. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
No, simply no! Please read #47630 (comment) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line indeed leads to
To avoid an empty std::vector<edm::ParameterSet> default_toGet;
desc.addVPSet("toGet", toGetDesc, default_toGet); or desc.addVPSet("toGet", toGetDesc, std::vector<edm::ParameterSet>{}); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, I followed up at #47688. |
||
|
||
desc.addUntracked<std::string>("JsonDumpFileName", ""); | ||
desc.addUntracked<bool>("DumpStat", false); | ||
desc.addUntracked<bool>("ReconnectEachRun", false); | ||
desc.addUntracked<bool>("RefreshAlways", false); | ||
desc.addUntracked<bool>("RefreshEachRun", false); | ||
desc.addUntracked<bool>("RefreshOpenIOVs", false); | ||
desc.addUntracked<std::string>("pfnPostfix", ""); | ||
desc.addUntracked<std::string>("pfnPrefix", ""); | ||
|
||
descriptions.add("default_CondDBESource", desc); | ||
} | ||
|
||
// backward compatibility for configuration files | ||
class PoolDBESSource : public CondDBESSource { | ||
public: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,4 +38,4 @@ | |
<flags EDM_PLUGIN="1"/> | ||
</library> | ||
|
||
|
||
<test name="UnitTestLoadConditions" command="runConditionsLoadTests.sh"/> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/bin/sh | ||
|
||
function die { echo $1: status $2 ; exit $2; } | ||
|
||
echo " testing CondCore/ESSources/test/python/load* " | ||
|
||
# List of successful configuration files | ||
configs=( | ||
"load_records_cfg.py" | ||
"load_modifiedglobaltag_cfg.py" | ||
"loadall_from_prodglobaltag_cfg.py" | ||
"load_record_empty_source_cfg.py" | ||
"loadall_from_one_record_empty_source_cfg.py" | ||
"load_from_multiplesources_cfg.py" | ||
"loadall_from_gt_empty_source_cfg.py" | ||
"load_tagcollection_cfg.py" | ||
"loadall_from_gt_cfg.py" | ||
"load_from_globaltag_cfg.py" | ||
) | ||
|
||
# Loop through each successful configuration file and run cmsRun | ||
for config in "${configs[@]}"; | ||
do | ||
echo "===== Test \"cmsRun $config \" ====" | ||
(cmsRun "${SCRAM_TEST_PATH}/python/"$config) || die "Failure using cmsRun $config" $? | ||
done |
Uh oh!
There was an error while loading. Please reload this page.