From 12e01e3a1e3d9328bd3575156ac9118c8be200e2 Mon Sep 17 00:00:00 2001 From: Christopher Jones Date: Thu, 3 Oct 2019 15:35:48 -0500 Subject: [PATCH] Use mayConsumes in VolumeBasedMagneticFieldESProducerFromDB The module decides which geometry to read from the database by reading the value stored in the MagFieldConfig EventSetup object. The decision cannot be made at module configuration time, only at run time. Therefore mayConsumes must be used. Unit tests were added to guarantee the module's behavior is the same after this change. --- ...olumeBasedMagneticFieldESProducerFromDB.cc | 204 +++++++++++------- MagneticField/GeomBuilder/test/BuildFile.xml | 2 + .../test/python/testMagneticFieldDB_cfg.py | 102 +++++++++ .../testMagneticFieldDB_parameterized_cfg.py | 96 +++++++++ .../testMagneticFieldDB_valueOverride_cfg.py | 96 +++++++++ .../GeomBuilder/test/testMagneticFieldDB.sh | 18 ++ .../test/testMagneticFieldDB_cfg.results | 18 ++ ...tMagneticFieldDB_parameterized_cfg.results | 15 ++ ...tMagneticFieldDB_valueOverride_cfg.results | 6 + 9 files changed, 481 insertions(+), 76 deletions(-) create mode 100644 MagneticField/GeomBuilder/test/python/testMagneticFieldDB_cfg.py create mode 100644 MagneticField/GeomBuilder/test/python/testMagneticFieldDB_parameterized_cfg.py create mode 100644 MagneticField/GeomBuilder/test/python/testMagneticFieldDB_valueOverride_cfg.py create mode 100755 MagneticField/GeomBuilder/test/testMagneticFieldDB.sh create mode 100644 MagneticField/GeomBuilder/test/testMagneticFieldDB_cfg.results create mode 100644 MagneticField/GeomBuilder/test/testMagneticFieldDB_parameterized_cfg.results create mode 100644 MagneticField/GeomBuilder/test/testMagneticFieldDB_valueOverride_cfg.results diff --git a/MagneticField/GeomBuilder/plugins/VolumeBasedMagneticFieldESProducerFromDB.cc b/MagneticField/GeomBuilder/plugins/VolumeBasedMagneticFieldESProducerFromDB.cc index 5f1dea19118d8..a99f320ead9c1 100644 --- a/MagneticField/GeomBuilder/plugins/VolumeBasedMagneticFieldESProducerFromDB.cc +++ b/MagneticField/GeomBuilder/plugins/VolumeBasedMagneticFieldESProducerFromDB.cc @@ -20,6 +20,7 @@ #include "FWCore/Framework/interface/ESTransientHandle.h" #include "FWCore/Framework/interface/EventSetup.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/Utilities/interface/ESProductTag.h" #include "DetectorDescription/Core/interface/DDCompactView.h" #include "FWCore/Framework/interface/ModuleFactory.h" @@ -51,106 +52,148 @@ namespace magneticfield { class VolumeBasedMagneticFieldESProducerFromDB : public edm::ESProducer { public: VolumeBasedMagneticFieldESProducerFromDB(const edm::ParameterSet& iConfig); + // forbid copy ctor and assignment op. + VolumeBasedMagneticFieldESProducerFromDB(const VolumeBasedMagneticFieldESProducerFromDB&) = delete; + const VolumeBasedMagneticFieldESProducerFromDB& operator=(const VolumeBasedMagneticFieldESProducerFromDB&) = delete; + + std::shared_ptr chooseConfigViaParameter(const IdealMagneticFieldRecord& iRecord); + std::shared_ptr chooseConfigAtRuntime(const IdealMagneticFieldRecord& iRecord); std::unique_ptr produce(const IdealMagneticFieldRecord& iRecord); + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + private: - // forbid copy ctor and assignment op. - VolumeBasedMagneticFieldESProducerFromDB(const VolumeBasedMagneticFieldESProducerFromDB&) = delete; - const VolumeBasedMagneticFieldESProducerFromDB& operator=(const VolumeBasedMagneticFieldESProducerFromDB&) = delete; - std::string closerNominalLabel(float current); + static std::string_view closerNominalLabel(float current); + + edm::ESGetToken mayGetConfigToken_; + edm::ESGetToken runInfo_; + edm::ESGetToken knownFromParamConfigToken_; - edm::ParameterSet pset; - std::vector nominalCurrents; - std::vector nominalLabels; + //NOTE: change of record since this MagFieldConfig was chosen based on data + // from the record RunInfoRcd so therefore has a dependency upon that record + edm::ESGetToken chosenConfigToken_; + + edm::ESGetToken mayConsumeBlobToken_; + const int current_; + const bool debug_; }; } // namespace magneticfield VolumeBasedMagneticFieldESProducerFromDB::VolumeBasedMagneticFieldESProducerFromDB(const edm::ParameterSet& iConfig) - : pset(iConfig) { - setWhatProduced(this, pset.getUntrackedParameter("label", "")); - nominalCurrents = {-1, 0, 9558, 14416, 16819, 18268, 19262}; - nominalLabels = {"3.8T", "0T", "2T", "3T", "3.5T", "3.8T", "4T"}; -} + : current_(iConfig.getParameter("valueOverride")), + debug_(iConfig.getUntrackedParameter("debugBuilder")) { + std::string const myConfigLabel = "VBMFESChoice"; + //Based on configuration, pick algorithm to produce the proper MagFieldConfig with a specific label + if (current_ < 0) { + //We do not know what to get until we first read RunInfo + setWhatProduced( + this, &VolumeBasedMagneticFieldESProducerFromDB::chooseConfigAtRuntime, edm::es::Label(myConfigLabel)) + .setMayConsume( + mayGetConfigToken_, + [](auto const& iGet, edm::ESTransientHandle iHandle) { + return iGet("", closerNominalLabel(iHandle->m_avg_current)); + }, + edm::ESProductTag("", "")); -// ------------ method called to produce the data ------------ -std::unique_ptr VolumeBasedMagneticFieldESProducerFromDB::produce( - const IdealMagneticFieldRecord& iRecord) { - bool debug = pset.getUntrackedParameter("debugBuilder", false); - - // Get value of the current from condition DB - float current = pset.getParameter("valueOverride"); - string message; - if (current < 0) { - ESHandle rInfo; - iRecord.getRecord().get(rInfo); - current = rInfo->m_avg_current; - message = " (from RunInfo DB)"; } else { - message = " (from valueOverride card)"; + //we know exactly what we are going to get + setWhatProduced( + this, &VolumeBasedMagneticFieldESProducerFromDB::chooseConfigViaParameter, edm::es::Label(myConfigLabel)) + .setConsumes(runInfo_) + .setConsumes(knownFromParamConfigToken_, edm::ESInputTag(""s, std::string(closerNominalLabel(current_)))); } - string configLabel = closerNominalLabel(current); - // Get configuration - ESHandle confESH; - iRecord.getRecord().get(configLabel, confESH); - const MagFieldConfig* conf = &*confESH; + auto const label = iConfig.getUntrackedParameter("label"); + auto const myConfigTag = edm::ESInputTag(iConfig.getParameter("@module_label"), myConfigLabel); + + //We use the MagFieldConfig created above to decide which FileBlob to use + setWhatProduced(this, label) + .setMayConsume( + mayConsumeBlobToken_, + [](auto const& iGet, edm::ESTransientHandle iConfig) { + if (iConfig->version == "parametrizedMagneticField") { + return iGet.nothing(); + } + return iGet("", std::to_string(iConfig->geometryVersion)); + }, + edm::ESProductTag(myConfigTag)) + .setConsumes(chosenConfigToken_, myConfigTag); //Use same tag as the choice +} + +std::shared_ptr VolumeBasedMagneticFieldESProducerFromDB::chooseConfigAtRuntime( + IdealMagneticFieldRecord const& iRcd) { + edm::ESHandle config = iRcd.getHandle(mayGetConfigToken_); + + //just forward what we just got but do not take ownership + return std::shared_ptr(config.product(), [](auto*) {}); +} + +std::shared_ptr VolumeBasedMagneticFieldESProducerFromDB::chooseConfigViaParameter( + const IdealMagneticFieldRecord& iRecord) { + auto config = iRecord.getHandle(knownFromParamConfigToken_); - edm::LogInfo("MagneticField|AutoMagneticField") - << "Current: " << current << message << "; using map configuration with label: " << configLabel << endl - << "Version: " << conf->version << " geometryVersion: " << conf->geometryVersion - << " slaveFieldVersion: " << conf->slaveFieldVersion; + //just forward what we just got but do not take ownership + return std::shared_ptr(config.product(), [](auto*) {}); +} + +// ------------ method called to produce the data ------------ +std::unique_ptr VolumeBasedMagneticFieldESProducerFromDB::produce( + const IdealMagneticFieldRecord& iRecord) { + auto const& conf = iRecord.getTransientHandle(chosenConfigToken_); - // Get the parametrized field std::unique_ptr paramField = ParametrizedMagneticFieldFactory::get(conf->slaveFieldVersion, conf->slaveFieldParameters); if (conf->version == "parametrizedMagneticField") { // The map consist of only the parametrization in this case return paramField; - } else { - // Full VolumeBased map + parametrization - MagGeoBuilderFromDDD builder(conf->version, conf->geometryVersion, debug); - - // Set scaling factors - if (!conf->keys.empty()) { - builder.setScaling(conf->keys, conf->values); - } - - // Set specification for the grid tables to be used. - if (!conf->gridFiles.empty()) { - builder.setGridFiles(conf->gridFiles); - } - - // Build the geomeytry (DDDCompactView) from the DB blob - // (code taken from GeometryReaders/XMLIdealGeometryESSource/src/XMLIdealMagneticFieldGeometryESProducer.cc) - edm::ESTransientHandle gdd; - iRecord.getRecord().get(std::to_string(conf->geometryVersion), gdd); - - auto cpv = std::make_unique(DDName("cmsMagneticField:MAGF")); - DDLParser parser(*cpv); - parser.getDDLSAX2FileHandler()->setUserNS(true); - parser.clearFiles(); - std::unique_ptr > tb = (*gdd).getUncompressedBlob(); - parser.parse(*tb, tb->size()); - cpv->lockdown(); - - builder.build(*cpv); - - // Build the VB map. Ownership of the parametrization is transferred to it - return std::make_unique(conf->geometryVersion, - builder.barrelLayers(), - builder.endcapSectors(), - builder.barrelVolumes(), - builder.endcapVolumes(), - builder.maxR(), - builder.maxZ(), - paramField.release(), - true); } + + // Full VolumeBased map + parametrization + MagGeoBuilderFromDDD builder(conf->version, conf->geometryVersion, debug_); + + // Set scaling factors + if (!conf->keys.empty()) { + builder.setScaling(conf->keys, conf->values); + } + + // Set specification for the grid tables to be used. + if (!conf->gridFiles.empty()) { + builder.setGridFiles(conf->gridFiles); + } + + // Build the geometry (DDDCompactView) from the DB blob + // (code taken from GeometryReaders/XMLIdealGeometryESSource/src/XMLIdealMagneticFieldGeometryESProducer.cc) + + auto const& blob = iRecord.getTransientHandle(mayConsumeBlobToken_); + + DDCompactView cpv{DDName("cmsMagneticField:MAGF")}; + DDLParser parser(cpv); + parser.getDDLSAX2FileHandler()->setUserNS(true); + parser.clearFiles(); + std::unique_ptr > tb = blob->getUncompressedBlob(); + parser.parse(*tb, tb->size()); + cpv.lockdown(); + + builder.build(cpv); + + // Build the VB map. Ownership of the parametrization is transferred to it + return std::make_unique(conf->geometryVersion, + builder.barrelLayers(), + builder.endcapSectors(), + builder.barrelVolumes(), + builder.endcapVolumes(), + builder.maxR(), + builder.maxZ(), + paramField.release(), + true); } -std::string VolumeBasedMagneticFieldESProducerFromDB::closerNominalLabel(float current) { +std::string_view VolumeBasedMagneticFieldESProducerFromDB::closerNominalLabel(float current) { + constexpr std::array nominalCurrents = {{-1, 0, 9558, 14416, 16819, 18268, 19262}}; + constexpr std::array nominalLabels = {{"3.8T", "0T", "2T", "3T", "3.5T", "3.8T", "4T"}}; + int i = 0; for (; i < (int)nominalLabels.size() - 1; i++) { if (2 * current < nominalCurrents[i] + nominalCurrents[i + 1]) @@ -159,4 +202,13 @@ std::string VolumeBasedMagneticFieldESProducerFromDB::closerNominalLabel(float c return nominalLabels[i]; } +void VolumeBasedMagneticFieldESProducerFromDB::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + edm::ParameterSetDescription desc; + desc.addUntracked("debugBuilder", false); + desc.add("valueOverride", -1)->setComment("Force value of current (in A); take the value from DB if < 0."); + desc.addUntracked("label", ""); + + descriptions.addDefault(desc); +} + DEFINE_FWK_EVENTSETUP_MODULE(VolumeBasedMagneticFieldESProducerFromDB); diff --git a/MagneticField/GeomBuilder/test/BuildFile.xml b/MagneticField/GeomBuilder/test/BuildFile.xml index 3908bcc174532..dd187daced63a 100644 --- a/MagneticField/GeomBuilder/test/BuildFile.xml +++ b/MagneticField/GeomBuilder/test/BuildFile.xml @@ -8,3 +8,5 @@ + + diff --git a/MagneticField/GeomBuilder/test/python/testMagneticFieldDB_cfg.py b/MagneticField/GeomBuilder/test/python/testMagneticFieldDB_cfg.py new file mode 100644 index 0000000000000..10b023fcd209b --- /dev/null +++ b/MagneticField/GeomBuilder/test/python/testMagneticFieldDB_cfg.py @@ -0,0 +1,102 @@ +# + + +import FWCore.ParameterSet.Config as cms + +process = cms.Process("MAGNETICFIELDTEST") +process.maxEvents.input = 6 + +process.source = cms.Source("EmptySource", + firstLuminosityBlockForEachRun = cms.untracked.VLuminosityBlockID( + cms.LuminosityBlockID(10,1), + cms.LuminosityBlockID(20,2), + cms.LuminosityBlockID(30,3), + cms.LuminosityBlockID(40,4), + cms.LuminosityBlockID(50,5), + cms.LuminosityBlockID(60,6) + ), + numberEventsInLuminosityBlock =cms.untracked.uint32(1) +) + +process.add_( cms.ESProducer("RunInfoTestESProducer", + runInfos = cms.VPSet(cms.PSet(run = cms.int32(10), avg_current = cms.double(0.)), + cms.PSet(run = cms.int32(20), avg_current = cms.double(9000.)), + cms.PSet(run = cms.int32(30), avg_current = cms.double(14000.)), + cms.PSet(run = cms.int32(40), avg_current = cms.double(17000.)), + cms.PSet(run = cms.int32(50), avg_current = cms.double(18000.)), + cms.PSet(run = cms.int32(60), avg_current = cms.double(19000.)), + ) ) ) + +process.riSource = cms.ESSource("EmptyESSource", recordName = cms.string("RunInfoRcd"), + iovIsRunNotTime = cms.bool(True), + firstValid = cms.vuint32(10,20,30,40,50,60)) + +process.load("MagneticField.Engine.volumeBasedMagneticFieldFromDB_cfi") + +process.load("Configuration/StandardSequences/CondDBESSource_cff") +from Configuration.AlCa.GlobalTag import GlobalTag +process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:mc', '') + +#configuration of GlobalTag comes from MagneticField/Engine/test/testMagneticFieldDB.py +process.GlobalTag.toGet = cms.VPSet( + cms.PSet(record = cms.string("MFGeometryFileRcd"), + tag = cms.string("MFGeometry_160812"), + connect = cms.string("frontier://FrontierProd/CMS_CONDITIONS"), + label = cms.untracked.string("160812") + ), + # Configurations + cms.PSet(record = cms.string("MagFieldConfigRcd"), + tag = cms.string("MFConfig_71212_0T"), + connect = cms.string("frontier://FrontierProd/CMS_CONDITIONS"), + label = cms.untracked.string("0T") + ), + cms.PSet(record = cms.string("MagFieldConfigRcd"), + tag = cms.string("MFConfig_71212_2T"), + connect = cms.string("frontier://FrontierProd/CMS_CONDITIONS"), + label = cms.untracked.string("2T") + ), + cms.PSet(record = cms.string("MagFieldConfigRcd"), # version 160812, 3T (good also for Run1) + tag = cms.string("MFConfig_160812_Run2_3T"), + connect = cms.string("frontier://FrontierProd/CMS_CONDITIONS"), + label = cms.untracked.string("3T") + ), + cms.PSet(record = cms.string("MagFieldConfigRcd"), # version 160812, 3.5T (good also for Run1) + tag = cms.string("MFConfig_160812_Run2_3_5T"), +# connect = cms.string("frontier://PromptProd/CMS_CONDITIONS"), + connect = cms.string("frontier://FrontierProd/CMS_CONDITIONS"), + label = cms.untracked.string("3.5T") + ), + cms.PSet(record = cms.string("MagFieldConfigRcd"), # version 160812, 3.8T + tag = cms.string("MFConfig_160812_Run2_3_8T"), #Run 2, version 160812, 3.8T (single IOV, for MC) +# connect = cms.string("frontier://PromptProd/CMS_CONDITIONS"), + connect = cms.string("frontier://FrontierProd/CMS_CONDITIONS"), + label = cms.untracked.string("3.8T") + ), + cms.PSet(record = cms.string("MagFieldConfigRcd"), + tag = cms.string("MFConfig_71212_4T"), + connect = cms.string("frontier://FrontierProd/CMS_CONDITIONS"), + label = cms.untracked.string("4T") + ), +) + +process.MessageLogger = cms.Service("MessageLogger", + categories = cms.untracked.vstring("MagneticField"), + destinations = cms.untracked.vstring("cout"), + cout = cms.untracked.PSet( + noLineBreaks = cms.untracked.bool(True), + threshold = cms.untracked.string("WARNING"), + WARNING = cms.untracked.PSet( + limit = cms.untracked.int32(0) + ), + MagneticField = cms.untracked.PSet( + limit = cms.untracked.int32(10000000) + ) + ) +) + + +process.testMagneticField = cms.EDAnalyzer("testMagneticField" +) + +process.p1 = cms.Path(process.testMagneticField) + diff --git a/MagneticField/GeomBuilder/test/python/testMagneticFieldDB_parameterized_cfg.py b/MagneticField/GeomBuilder/test/python/testMagneticFieldDB_parameterized_cfg.py new file mode 100644 index 0000000000000..8be2d2e3b4574 --- /dev/null +++ b/MagneticField/GeomBuilder/test/python/testMagneticFieldDB_parameterized_cfg.py @@ -0,0 +1,96 @@ +# + + +import FWCore.ParameterSet.Config as cms + +process = cms.Process("MAGNETICFIELDTEST") +process.maxEvents.input = 5 + +#NOTE: parameterized magnetic field does not allow 0T so skip lumi 1 +process.source = cms.Source("EmptySource", + firstLuminosityBlockForEachRun = cms.untracked.VLuminosityBlockID( + #cms.LuminosityBlockID(10,1), + cms.LuminosityBlockID(20,2), + cms.LuminosityBlockID(30,3), + cms.LuminosityBlockID(40,4), + cms.LuminosityBlockID(50,5), + cms.LuminosityBlockID(60,6) + ), + firstLuminosityBlock = cms.untracked.uint32(2), + numberEventsInLuminosityBlock =cms.untracked.uint32(1) +) + +process.add_( cms.ESProducer("RunInfoTestESProducer", + runInfos = cms.VPSet(cms.PSet(run = cms.int32(10), avg_current = cms.double(0.)), #0T + cms.PSet(run = cms.int32(20), avg_current = cms.double(9000.)), #2T + cms.PSet(run = cms.int32(30), avg_current = cms.double(14000.)), #3T + cms.PSet(run = cms.int32(40), avg_current = cms.double(17000.)), #3.5T + cms.PSet(run = cms.int32(50), avg_current = cms.double(18000.)), #3.8T + cms.PSet(run = cms.int32(60), avg_current = cms.double(19000.)), #4T + ) ) ) + +process.riSource = cms.ESSource("EmptyESSource", + recordName = cms.string("RunInfoRcd"), + iovIsRunNotTime = cms.bool(True), + firstValid = cms.vuint32(10,20,30,40,50,60)) + +#the values used for the MagFieldConfig come from +# CondFormats/MFObjects/test/writeMagFieldConfigDB.py +process.magFieldConfig0= cms.ESProducer("MagFieldConfigTestESProducer", + configs = cms.VPSet(cms.PSet(run = cms.uint32(10), + config = cms.PSet( + scalingVolumes = cms.vint32(), + scalingFactors = cms.vdouble(), + version = cms.string('parametrizedMagneticField'), + geometryVersion = cms.int32(90322), + paramLabel = cms.string('OAE_1103l_071212'), + paramData = cms.vdouble(0), + gridFiles = cms.VPSet() + ) + ) + ), + appendToDataLabel = cms.string('0T') + ) +process.magFieldConfig2= process.magFieldConfig0.clone(appendToDataLabel = '2T', + configs = {0: dict(config = dict(paramData = [2.0]) ) } ) +process.magFieldConfig3= process.magFieldConfig0.clone(appendToDataLabel = '3T', + configs = {0: dict(config = dict(paramData = [3.0]) ) } ) +process.magFieldConfig35= process.magFieldConfig0.clone(appendToDataLabel = '3.5T', + configs = {0: dict(config = dict(paramData = [3.5]) ) } ) +process.magFieldConfig38= process.magFieldConfig0.clone(appendToDataLabel = '3.8T', + configs = {0: dict(config = dict(paramData = [3.8], + geometryVersion = 130503) ) } ) +process.magFieldConfig4= process.magFieldConfig0.clone(appendToDataLabel = '4T', + configs = {0: dict(config = dict(paramData = [4.0]) ) } ) + + +process.mfcSource = cms.ESSource("EmptyESSource", + recordName = cms.string("MagFieldConfigRcd"), + iovIsRunNotTime = cms.bool(True), + firstValid = cms.vuint32(10) ) + + +process.load("MagneticField.Engine.volumeBasedMagneticFieldFromDB_cfi") + + +process.MessageLogger = cms.Service("MessageLogger", + categories = cms.untracked.vstring("MagneticField"), + destinations = cms.untracked.vstring("cout"), + cout = cms.untracked.PSet( + noLineBreaks = cms.untracked.bool(True), + threshold = cms.untracked.string("WARNING"), + WARNING = cms.untracked.PSet( + limit = cms.untracked.int32(0) + ), + MagneticField = cms.untracked.PSet( + limit = cms.untracked.int32(10000000) + ) + ) +) + + +process.testMagneticField = cms.EDAnalyzer("testMagneticField" +) + +process.p1 = cms.Path(process.testMagneticField) + diff --git a/MagneticField/GeomBuilder/test/python/testMagneticFieldDB_valueOverride_cfg.py b/MagneticField/GeomBuilder/test/python/testMagneticFieldDB_valueOverride_cfg.py new file mode 100644 index 0000000000000..e43573cfaaa9b --- /dev/null +++ b/MagneticField/GeomBuilder/test/python/testMagneticFieldDB_valueOverride_cfg.py @@ -0,0 +1,96 @@ +# + + +import FWCore.ParameterSet.Config as cms + +process = cms.Process("MAGNETICFIELDTEST") +process.maxEvents.input = 2 + +process.source = cms.Source("EmptySource", + firstLuminosityBlockForEachRun = cms.untracked.VLuminosityBlockID( + cms.LuminosityBlockID(10,1), + cms.LuminosityBlockID(20,2), + ), + numberEventsInLuminosityBlock =cms.untracked.uint32(1) +) + +#the job should not use the data product made by this ESProducer +# it is here with different avg_current than the valueOverride +process.add_( cms.ESProducer("RunInfoTestESProducer", + runInfos = cms.VPSet(cms.PSet(run = cms.int32(10), avg_current = cms.double(0.)), + cms.PSet(run = cms.int32(20), avg_current = cms.double(9000.)), + ) ) ) + +process.riSource = cms.ESSource("EmptyESSource", recordName = cms.string("RunInfoRcd"), + iovIsRunNotTime = cms.bool(True), + firstValid = cms.vuint32(10,20)) + +process.load("MagneticField.Engine.volumeBasedMagneticFieldFromDB_cfi") +process.VolumeBasedMagneticFieldESProducer.valueOverride = 18000 + +process.load("Configuration/StandardSequences/CondDBESSource_cff") +from Configuration.AlCa.GlobalTag import GlobalTag +process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:mc', '') + + +#configuration of GlobalTag comes from MagneticField/Engine/test/testMagneticFieldDB.py +process.GlobalTag.toGet = cms.VPSet( + cms.PSet(record = cms.string("MFGeometryFileRcd"), + tag = cms.string("MFGeometry_160812"), + connect = cms.string("frontier://FrontierProd/CMS_CONDITIONS"), + label = cms.untracked.string("160812") + ), + # Configurations + cms.PSet(record = cms.string("MagFieldConfigRcd"), + tag = cms.string("MFConfig_71212_0T"), + connect = cms.string("frontier://FrontierProd/CMS_CONDITIONS"), + label = cms.untracked.string("0T") + ), + cms.PSet(record = cms.string("MagFieldConfigRcd"), + tag = cms.string("MFConfig_71212_2T"), + connect = cms.string("frontier://FrontierProd/CMS_CONDITIONS"), + label = cms.untracked.string("2T") + ), + cms.PSet(record = cms.string("MagFieldConfigRcd"), # version 160812, 3T (good also for Run1) + tag = cms.string("MFConfig_160812_Run2_3T"), + connect = cms.string("frontier://FrontierProd/CMS_CONDITIONS"), + label = cms.untracked.string("3T") + ), + cms.PSet(record = cms.string("MagFieldConfigRcd"), # version 160812, 3.5T (good also for Run1) + tag = cms.string("MFConfig_160812_Run2_3_5T"), + connect = cms.string("frontier://FrontierProd/CMS_CONDITIONS"), + label = cms.untracked.string("3.5T") + ), + cms.PSet(record = cms.string("MagFieldConfigRcd"), # version 160812, 3.8T + tag = cms.string("MFConfig_160812_Run2_3_8T"), #Run 2, version 160812, 3.8T (single IOV, for MC) + connect = cms.string("frontier://FrontierProd/CMS_CONDITIONS"), + label = cms.untracked.string("3.8T") + ), + cms.PSet(record = cms.string("MagFieldConfigRcd"), + tag = cms.string("MFConfig_71212_4T"), + connect = cms.string("frontier://FrontierProd/CMS_CONDITIONS"), + label = cms.untracked.string("4T") + ), +) + +process.MessageLogger = cms.Service("MessageLogger", + categories = cms.untracked.vstring("MagneticField"), + destinations = cms.untracked.vstring("cout"), + cout = cms.untracked.PSet( + noLineBreaks = cms.untracked.bool(True), + threshold = cms.untracked.string("WARNING"), + WARNING = cms.untracked.PSet( + limit = cms.untracked.int32(0) + ), + MagneticField = cms.untracked.PSet( + limit = cms.untracked.int32(10000000) + ) + ) +) + + +process.testMagneticField = cms.EDAnalyzer("testMagneticField" +) + +process.p1 = cms.Path(process.testMagneticField) + diff --git a/MagneticField/GeomBuilder/test/testMagneticFieldDB.sh b/MagneticField/GeomBuilder/test/testMagneticFieldDB.sh new file mode 100755 index 0000000000000..80f4f50fb9049 --- /dev/null +++ b/MagneticField/GeomBuilder/test/testMagneticFieldDB.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +LOCAL_TEST_DIR=src/MagneticField/GeomBuilder/test + +function die { echo Failure $1: status $2 ; exit $2 ; } + +cmsRun ${LOCAL_TEST_DIR}/python/testMagneticFieldDB_cfg.py > testMagneticFieldDB.run_log || die "cmsRun testMagneticFieldDB_cfg.py" $? +diff testMagneticFieldDB.run_log ${LOCAL_TEST_DIR}/testMagneticFieldDB_cfg.results || die 'incorrect output using testMagneticFieldDB.run_log' $? +rm testMagneticFieldDB.run_log + +cmsRun ${LOCAL_TEST_DIR}/python/testMagneticFieldDB_valueOverride_cfg.py > testMagneticFieldDB_valueOverride.run_log || die "cmsRun testMagneticFieldDB_valueOverride_cfg.py" $? +diff testMagneticFieldDB_valueOverride.run_log ${LOCAL_TEST_DIR}/testMagneticFieldDB_valueOverride_cfg.results || die 'incorrect output using testMagneticFieldDB_valueOverride.run_log' $? +rm testMagneticFieldDB_valueOverride.run_log + +cmsRun ${LOCAL_TEST_DIR}/python/testMagneticFieldDB_parameterized_cfg.py > testMagneticFieldDB_parameterized.run_log || die "cmsRun testMagneticFieldDB_parameterized_cfg.py" $? +diff testMagneticFieldDB_parameterized.run_log ${LOCAL_TEST_DIR}/testMagneticFieldDB_parameterized_cfg.results || die 'incorrect output using testMagneticFieldDB_parameterized.run_log' $? +rm testMagneticFieldDB_parameterized.run_log + diff --git a/MagneticField/GeomBuilder/test/testMagneticFieldDB_cfg.results b/MagneticField/GeomBuilder/test/testMagneticFieldDB_cfg.results new file mode 100644 index 0000000000000..44296e879a5bf --- /dev/null +++ b/MagneticField/GeomBuilder/test/testMagneticFieldDB_cfg.results @@ -0,0 +1,18 @@ +Nominal Field 0 + +At: (0,0,0) phi=0 B= (0,0,0) +Nominal Field 20 + +At: (0,0,0) phi=0 B= (-0,-0,2.02203) +Nominal Field 30 + +At: (0,0,0) phi=0 B= (-0,-0,3.02344) +Nominal Field 35 + +At: (0,0,0) phi=0 B= (-0,-0,3.51588) +Nominal Field 38 + +At: (0,0,0) phi=0 B= (-0,-0,3.8112) +Nominal Field 40 + +At: (0,0,0) phi=0 B= (-0,-0,4.01299) diff --git a/MagneticField/GeomBuilder/test/testMagneticFieldDB_parameterized_cfg.results b/MagneticField/GeomBuilder/test/testMagneticFieldDB_parameterized_cfg.results new file mode 100644 index 0000000000000..63245b8065074 --- /dev/null +++ b/MagneticField/GeomBuilder/test/testMagneticFieldDB_parameterized_cfg.results @@ -0,0 +1,15 @@ +Nominal Field 20 + +At: (0,0,0) phi=0 B= (-0,-0,2.02203) +Nominal Field 30 + +At: (0,0,0) phi=0 B= (-0,-0,3.02344) +Nominal Field 35 + +At: (0,0,0) phi=0 B= (-0,-0,3.51588) +Nominal Field 38 + +At: (0,0,0) phi=0 B= (-0,-0,3.8112) +Nominal Field 40 + +At: (0,0,0) phi=0 B= (-0,-0,4.01299) diff --git a/MagneticField/GeomBuilder/test/testMagneticFieldDB_valueOverride_cfg.results b/MagneticField/GeomBuilder/test/testMagneticFieldDB_valueOverride_cfg.results new file mode 100644 index 0000000000000..7a36ddf8a8615 --- /dev/null +++ b/MagneticField/GeomBuilder/test/testMagneticFieldDB_valueOverride_cfg.results @@ -0,0 +1,6 @@ +Nominal Field 38 + +At: (0,0,0) phi=0 B= (-0,-0,3.8112) +Nominal Field 38 + +At: (0,0,0) phi=0 B= (-0,-0,3.8112)