Skip to content
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

Use mayConsumes in VolumeBasedMagneticFieldESProducerFromDB #28120

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion CondFormats/MFObjects/test/BuildFile.xml
Expand Up @@ -3,7 +3,7 @@
<use name="CondFormats/MFObjects"/>
<use name="CondCore/DBOutputService"/>
<use name="CondFormats/DataRecord"/>
<library file="MagFieldConfigDBWriter.cc" name="CondFormatsMFObjectsTest">
<library file="MagFieldConfigDBWriter.cc,MagFieldConfigTestESProducer.cc" name="CondFormatsMFObjectsTest">
<flags EDM_PLUGIN="1"/>
</library>

Expand Down
112 changes: 112 additions & 0 deletions CondFormats/MFObjects/test/MagFieldConfigTestESProducer.cc
@@ -0,0 +1,112 @@
// -*- C++ -*-
//
// Package: CondTools/RunInfo
// Class: MagFieldConfigTestESProducer
//
/**\class MagFieldConfigTestESProducer

Description: [one line class summary]

Implementation:
[Notes on implementation]
*/
//
// Original Author: Christopher Jones
// Created: Wed, 02 Oct 2019 17:34:35 GMT
//
//

// system include files
#include <memory>
#include <unordered_map>

// user include files
#include "FWCore/Framework/interface/ModuleFactory.h"
#include "FWCore/Framework/interface/ESProducer.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"

#include "CondFormats/MFObjects/interface/MagFieldConfig.h"
#include "CondFormats/DataRecord/interface/MagFieldConfigRcd.h"

//
// class declaration
//

class MagFieldConfigTestESProducer : public edm::ESProducer {
public:
MagFieldConfigTestESProducer(const edm::ParameterSet&);

using ReturnType = std::unique_ptr<MagFieldConfig>;

ReturnType produce(const MagFieldConfigRcd&);

static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);

private:
std::pair<unsigned int, MagFieldConfig> makeMagFieldConfig(edm::ParameterSet const& pset) const;
// ----------member data ---------------------------
std::unordered_map<unsigned int, MagFieldConfig> configs_;
};

//
// constants, enums and typedefs
//

//
// static data member definitions
//

//
// constructors and destructor
//
MagFieldConfigTestESProducer::MagFieldConfigTestESProducer(const edm::ParameterSet& iConfig) {
std::vector<edm::ParameterSet> const& configs = iConfig.getParameter<std::vector<edm::ParameterSet>>("configs");
configs_.reserve(configs.size());
for (auto const& pset : configs) {
configs_.insert(makeMagFieldConfig(pset));
}

setWhatProduced(this);
}

//
// member functions
//

// ------------ method called to produce the data ------------
MagFieldConfigTestESProducer::ReturnType MagFieldConfigTestESProducer::produce(const MagFieldConfigRcd& iRecord) {
const unsigned int run = iRecord.validityInterval().first().eventID().run();

auto itFound = configs_.find(run);
if (itFound == configs_.end()) {
return nullptr;
}
return std::make_unique<MagFieldConfig>(itFound->second);
}

std::pair<unsigned int, MagFieldConfig> MagFieldConfigTestESProducer::makeMagFieldConfig(
edm::ParameterSet const& pset) const {
return std::pair<unsigned int, MagFieldConfig>(pset.getParameter<unsigned int>("run"),
pset.getParameter<edm::ParameterSet>("config"));
}

void MagFieldConfigTestESProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
{
edm::ParameterSetDescription entryDesc;
entryDesc.add<unsigned int>("run");
{
//Do not enforce what the MagFieldConfig wants
edm::ParameterSetDescription magConfig;
magConfig.setAllowAnything();
entryDesc.add<edm::ParameterSetDescription>("config", magConfig);
}

desc.addVPSet("configs", entryDesc, {});
}
descriptions.addDefault(desc);
}

//define this as a plug-in
DEFINE_FWK_EVENTSETUP_MODULE(MagFieldConfigTestESProducer);
3 changes: 3 additions & 0 deletions CondTools/RunInfo/plugins/BuildFile.xml
Expand Up @@ -30,3 +30,6 @@
<library file="LHCInfoPopConAnalyzer.cc" name="CondToolsLHCInfoPopConAnalyzer">
<flags EDM_PLUGIN="1"/>
</library>
<library file="RunInfoTestESProducer.cc" name="CondToolsRunInfoTestESProducer">
<flags EDM_PLUGIN="1"/>
</library>
144 changes: 144 additions & 0 deletions CondTools/RunInfo/plugins/RunInfoTestESProducer.cc
@@ -0,0 +1,144 @@
// -*- C++ -*-
//
// Package: CondTools/RunInfo
// Class: RunInfoTestESProducer
//
/**\class RunInfoTestESProducer

Description: [one line class summary]

Implementation:
[Notes on implementation]
*/
//
// Original Author: Christopher Jones
// Created: Wed, 02 Oct 2019 17:34:35 GMT
//
//

// system include files
#include <memory>

// user include files
#include "FWCore/Framework/interface/ModuleFactory.h"
#include "FWCore/Framework/interface/ESProducer.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"

#include "CondFormats/RunInfo/interface/RunInfo.h"
#include "CondFormats/DataRecord/interface/RunSummaryRcd.h"

//
// class declaration
//

class RunInfoTestESProducer : public edm::ESProducer {
public:
RunInfoTestESProducer(const edm::ParameterSet&);

using ReturnType = std::unique_ptr<RunInfo>;

ReturnType produce(const RunInfoRcd&);

static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);

private:
RunInfo makeRunInfo(edm::ParameterSet const& pset) const;
// ----------member data ---------------------------
std::vector<RunInfo> runInfos_;
};

//
// constants, enums and typedefs
//
namespace {
bool ri_less(RunInfo const& iLHS, RunInfo const& iRHS) { return iLHS.m_run < iRHS.m_run; }
} // namespace

//
// static data member definitions
//

//
// constructors and destructor
//
RunInfoTestESProducer::RunInfoTestESProducer(const edm::ParameterSet& iConfig) {
std::vector<edm::ParameterSet> const& runInfos = iConfig.getParameter<std::vector<edm::ParameterSet>>("runInfos");
runInfos_.reserve(runInfos.size());
for (auto const& pset : runInfos) {
runInfos_.emplace_back(makeRunInfo(pset));
}
std::sort(runInfos_.begin(), runInfos_.end(), ri_less);

setWhatProduced(this);
}

//
// member functions
//

// ------------ method called to produce the data ------------
RunInfoTestESProducer::ReturnType RunInfoTestESProducer::produce(const RunInfoRcd& iRecord) {
const int run = iRecord.validityInterval().first().eventID().run();
RunInfo toFind;
toFind.m_run = run;
auto itFound = std::lower_bound(runInfos_.begin(), runInfos_.end(), toFind, ri_less);
if (itFound == runInfos_.end() or itFound->m_run != run) {
return nullptr;
}
return std::make_unique<RunInfo>(*itFound);
}

RunInfo RunInfoTestESProducer::makeRunInfo(edm::ParameterSet const& pset) const {
RunInfo retValue;
retValue.m_run = pset.getParameter<int>("run");
retValue.m_start_time_ll = pset.getParameter<long long>("start_time");
retValue.m_start_time_str = pset.getParameter<std::string>("start_time_str");
retValue.m_stop_time_ll = pset.getParameter<long long>("stop_time");
retValue.m_stop_time_str = pset.getParameter<std::string>("stop_time_str");
retValue.m_fed_in = pset.getParameter<std::vector<int>>("fed_in");
retValue.m_start_current = pset.getParameter<double>("start_current");
retValue.m_stop_current = pset.getParameter<double>("stop_current");
retValue.m_avg_current = pset.getParameter<double>("avg_current");
retValue.m_min_current = pset.getParameter<double>("min_current");
retValue.m_max_current = pset.getParameter<double>("max_current");
retValue.m_run_intervall_micros = pset.getParameter<double>("run_intervall_micros");

auto convert = [](std::vector<double> const& iIn) {
std::vector<float> f;
f.reserve(iIn.size());
std::copy(iIn.begin(), iIn.end(), std::back_inserter(f));
return f;
};

retValue.m_current = convert(pset.getParameter<std::vector<double>>("current"));
retValue.m_times_of_currents = convert(pset.getParameter<std::vector<double>>("times_of_currents"));

return retValue;
}

void RunInfoTestESProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription runInfoDesc;
runInfoDesc.add<int>("run");
runInfoDesc.add<long long>("start_time", 0);
runInfoDesc.add<std::string>("start_time_str", "");
runInfoDesc.add<long long>("stop_time", 0);
runInfoDesc.add<std::string>("stop_time_str", "");
runInfoDesc.add<std::vector<int>>("fed_in", {});
runInfoDesc.add<double>("start_current", 0);
runInfoDesc.add<double>("stop_current", 0);
runInfoDesc.add<double>("avg_current", 0);
runInfoDesc.add<double>("min_current", 0);
runInfoDesc.add<double>("max_current", 0);
runInfoDesc.add<double>("run_intervall_micros", 0);
runInfoDesc.add<std::vector<double>>("current", {});
runInfoDesc.add<std::vector<double>>("times_of_currents", {});

edm::ParameterSetDescription desc;
desc.addVPSet("runInfos", runInfoDesc, {});

descriptions.addDefault(desc);
}

//define this as a plug-in
DEFINE_FWK_EVENTSETUP_MODULE(RunInfoTestESProducer);
1 change: 1 addition & 0 deletions CondTools/RunInfo/test/BuildFile.xml
Expand Up @@ -4,3 +4,4 @@
<use name="py2-sqlalchemy"/>
<test name="RunInfoStart_O2O_test" command="RunInfoStart_O2O_test.sh"/>
</architecture>
<test name="CondToolsRunInfoTest" command="test_runinfo.sh"/>
9 changes: 9 additions & 0 deletions CondTools/RunInfo/test/test_runinfo.sh
@@ -0,0 +1,9 @@
#!/bin/sh

LOCAL_TEST_DIR=src/CondTools/RunInfo/test

function die { echo Failure $1: status $2 ; exit $2 ; }

cmsRun ${LOCAL_TEST_DIR}/test_runinfo_cfg.py | grep '\(run number\)\|\(average current\)' > test_runinfo.run_log || die "cmsRun RefTest_cfg.py" $?
diff test_runinfo.run_log ${LOCAL_TEST_DIR}/test_runinfo_result.log || die 'incorrect output using test_runinfo_cfg.py' $?
rm test_runinfo.run_log
27 changes: 27 additions & 0 deletions CondTools/RunInfo/test/test_runinfo_cfg.py
@@ -0,0 +1,27 @@
import FWCore.ParameterSet.Config as cms

process = cms.Process("TEST")

process.maxEvents.input = 3

process.source = cms.Source("EmptySource",
firstLuminosityBlockForEachRun = cms.untracked.VLuminosityBlockID(
cms.LuminosityBlockID(10,1),
cms.LuminosityBlockID(20,2),
cms.LuminosityBlockID(30,3)
),
numberEventsInLuminosityBlock =cms.untracked.uint32(1)
)

process.add_( cms.ESProducer("RunInfoTestESProducer",
runInfos = cms.VPSet(cms.PSet(run = cms.int32(10), avg_current = cms.double(1.)),
cms.PSet(run = cms.int32(20), avg_current = cms.double(2.)),
cms.PSet(run = cms.int32(30), avg_current = cms.double(3.)) ) ) )

process.riSource = cms.ESSource("EmptyESSource", recordName = cms.string("RunInfoRcd"),
iovIsRunNotTime = cms.bool(True),
firstValid = cms.vuint32(10,20,30))

process.test = cms.EDAnalyzer("RunInfoESAnalyzer")

process.p = cms.Path(process.test)
6 changes: 6 additions & 0 deletions CondTools/RunInfo/test/test_runinfo_result.log
@@ -0,0 +1,6 @@
run number: 10
average current 1
run number: 20
average current 2
run number: 30
average current 3