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

Backport to 111X of ESGetToken update in L1T O2O producer #30494

Merged
merged 8 commits into from Jul 7, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
28 changes: 20 additions & 8 deletions CondTools/L1TriggerExt/interface/L1ConfigOnlineProdBaseExt.h
Expand Up @@ -9,7 +9,6 @@

#include "FWCore/Framework/interface/ModuleFactory.h"
#include "FWCore/Framework/interface/ESProducer.h"
#include "FWCore/Framework/interface/ESHandle.h"

#include "CondFormats/L1TObjects/interface/L1TriggerKeyListExt.h"
#include "CondFormats/DataRecord/interface/L1TriggerKeyListExtRcd.h"
Expand Down Expand Up @@ -41,10 +40,13 @@ class L1ConfigOnlineProdBaseExt : public edm::ESProducer {

private:
// ----------member data ---------------------------
edm::ESGetToken<L1TriggerKeyListExt, L1TriggerKeyListExtRcd> keyList_token;
edm::ESGetToken<L1TriggerKeyExt, L1TriggerKeyExtRcd> key_token;

protected:
l1t::OMDSReader m_omdsReader;
bool m_forceGeneration;
edm::ESConsumesCollectorT<TRcd> wrappedSetWhatProduced(const edm::ParameterSet&);

// Called from produce methods.
// bool is true if the object data should be made.
Expand All @@ -65,7 +67,9 @@ L1ConfigOnlineProdBaseExt<TRcd, TData>::L1ConfigOnlineProdBaseExt(const edm::Par
m_copyFromCondDB(false) {
//the following line is needed to tell the framework what
// data is being produced
setWhatProduced(this);
// setWhatProduced(this)
// .setConsumes(keyList_token)
// .setConsumes(key_token);

//now do what ever other initialization is needed

Expand All @@ -85,6 +89,15 @@ L1ConfigOnlineProdBaseExt<TRcd, TData>::L1ConfigOnlineProdBaseExt(const edm::Par
}
}

template <class TRcd, class TData>
edm::ESConsumesCollectorT<TRcd> L1ConfigOnlineProdBaseExt<TRcd, TData>::wrappedSetWhatProduced(
const edm::ParameterSet& iConfig) {
auto collector = setWhatProduced(this);
collector.setConsumes(keyList_token);
collector.setConsumes(key_token);
return collector;
}

template <class TRcd, class TData>
L1ConfigOnlineProdBaseExt<TRcd, TData>::~L1ConfigOnlineProdBaseExt() {
// do anything here that needs to be done at desctruction time
Expand All @@ -104,16 +117,15 @@ std::unique_ptr<const TData> L1ConfigOnlineProdBaseExt<TRcd, TData>::produce(con
/// // Get L1TriggerKeyList from EventSetup
/// const L1TriggerKeyListRcd& keyListRcd =
iRecord.template getRecord<L1TriggerKeyListExtRcd>();
edm::ESHandle<L1TriggerKeyListExt> keyList;
/// iRecord.template getRecord< L1TriggerKeyListRcd >() ;
/// edm::ESHandle< L1TriggerKeyList > keyList ;

keyListRcd.get(keyList);
auto const& keyList = keyListRcd.get(keyList_token);

// Find payload token
std::string recordName = edm::typelookup::className<TRcd>();
std::string dataType = edm::typelookup::className<TData>();
std::string payloadToken = keyList->token(recordName, dataType, key);
std::string payloadToken = keyList.token(recordName, dataType, key);

edm::LogVerbatim("L1-O2O") << "Copying payload for " << recordName << "@" << dataType << " obj key " << key
<< " from CondDB.";
Expand Down Expand Up @@ -156,9 +168,9 @@ bool L1ConfigOnlineProdBaseExt<TRcd, TData>::getObjectKey(const TRcd& record, st

// If L1TriggerKeyExt is invalid, then all configuration objects are
// already in ORCON.
edm::ESHandle<L1TriggerKeyExt> key;
// edm::ESHandle<L1TriggerKeyExt> key_token;
try {
keyRcd.get(key);
keyRcd.get(key_token);
} catch (l1t::DataAlreadyPresentException& ex) {
objectKey = std::string();
return false;
Expand All @@ -168,7 +180,7 @@ bool L1ConfigOnlineProdBaseExt<TRcd, TData>::getObjectKey(const TRcd& record, st
std::string recordName = edm::typelookup::className<TRcd>();
std::string dataType = edm::typelookup::className<TData>();

objectKey = key->get(recordName, dataType);
objectKey = keyRcd.get(key_token).get(recordName, dataType);

/* edm::LogVerbatim( "L1-O2O" ) */
/* << "L1ConfigOnlineProdBase record " << recordName */
Expand Down
Expand Up @@ -7,7 +7,7 @@
// user include files
#include "FWCore/Framework/interface/ModuleFactory.h"
#include "FWCore/Framework/interface/ESProducer.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/ESConsumesCollector.h"

#include "CondFormats/L1TObjects/interface/L1TriggerKeyExt.h"
#include "CondFormats/DataRecord/interface/L1TriggerKeyExtRcd.h"
Expand All @@ -29,6 +29,8 @@ class L1ObjectKeysOnlineProdBaseExt : public edm::ESProducer {

private:
// ----------member data ---------------------------
edm::ESGetToken<L1TriggerKeyExt, L1TriggerKeyExtRcd> L1TriggerKeyExt_token;

protected:
l1t::OMDSReader m_omdsReader;
};
Expand Down
19 changes: 9 additions & 10 deletions CondTools/L1TriggerExt/plugins/L1CondDBPayloadWriterExt.cc
Expand Up @@ -14,6 +14,7 @@ L1CondDBPayloadWriterExt::L1CondDBPayloadWriterExt(const edm::ParameterSet& iCon
m_logTransactions(iConfig.getParameter<bool>("logTransactions")),
m_newL1TriggerKeyListExt(iConfig.getParameter<bool>("newL1TriggerKeyListExt")) {
//now do what ever initialization is needed
key_token = esConsumes<L1TriggerKeyExt, L1TriggerKeyExtRcd>();
}

L1CondDBPayloadWriterExt::~L1CondDBPayloadWriterExt() {
Expand All @@ -38,26 +39,24 @@ void L1CondDBPayloadWriterExt::analyze(const edm::Event& iEvent, const edm::Even

// Write L1TriggerKeyExt to ORCON with no IOV
std::string token;
ESHandle<L1TriggerKeyExt> key;

L1TriggerKeyExt key;
// Before calling writePayload(), check if TSC key is already in
// L1TriggerKeyListExt. writePayload() will not catch this situation in
// the case of dummy configurations.
bool triggerKeyOK = true;
try {
// Get L1TriggerKeyExt
iSetup.get<L1TriggerKeyExtRcd>().get(key);

key = iSetup.get<L1TriggerKeyExtRcd>().get(key_token);
if (!m_overwriteKeys) {
triggerKeyOK = oldKeyList.token(key->tscKey()).empty();
triggerKeyOK = oldKeyList.token(key.tscKey()).empty();
}
} catch (l1t::DataAlreadyPresentException& ex) {
triggerKeyOK = false;
edm::LogVerbatim("L1-O2O") << ex.what();
}

if (triggerKeyOK && m_writeL1TriggerKeyExt) {
edm::LogVerbatim("L1-O2O") << "Object key for L1TriggerKeyExtRcd@L1TriggerKeyExt: " << key->tscKey();
edm::LogVerbatim("L1-O2O") << "Object key for L1TriggerKeyExtRcd@L1TriggerKeyExt: " << key.tscKey();
token = m_writer.writePayload(iSetup, "L1TriggerKeyExtRcd@L1TriggerKeyExt");
}

Expand All @@ -68,15 +67,15 @@ void L1CondDBPayloadWriterExt::analyze(const edm::Event& iEvent, const edm::Even
// Record token in L1TriggerKeyListExt
if (m_writeL1TriggerKeyExt) {
keyList = new L1TriggerKeyListExt(oldKeyList);
if (!(keyList->addKey(key->tscKey(), token, m_overwriteKeys))) {
throw cond::Exception("L1CondDBPayloadWriter: TSC key " + key->tscKey() + " already in L1TriggerKeyListExt");
if (!(keyList->addKey(key.tscKey(), token, m_overwriteKeys))) {
throw cond::Exception("L1CondDBPayloadWriter: TSC key " + key.tscKey() + " already in L1TriggerKeyListExt");
}
}

if (m_writeConfigData) {
// Loop over record@type in L1TriggerKeyExt
L1TriggerKeyExt::RecordToKey::const_iterator it = key->recordToKeyMap().begin();
L1TriggerKeyExt::RecordToKey::const_iterator end = key->recordToKeyMap().end();
L1TriggerKeyExt::RecordToKey::const_iterator it = key.recordToKeyMap().begin();
L1TriggerKeyExt::RecordToKey::const_iterator end = key.recordToKeyMap().end();

for (; it != end; ++it) {
// Do nothing if object key is null.
Expand Down
8 changes: 8 additions & 0 deletions CondTools/L1TriggerExt/plugins/L1CondDBPayloadWriterExt.h
Expand Up @@ -10,8 +10,13 @@

#include "FWCore/ParameterSet/interface/ParameterSet.h"

#include "FWCore/Utilities/interface/ESGetToken.h"

#include "CondTools/L1TriggerExt/interface/DataWriterExt.h"

#include "CondFormats/L1TObjects/interface/L1TriggerKeyExt.h"
#include "CondFormats/DataRecord/interface/L1TriggerKeyExtRcd.h"

class L1CondDBPayloadWriterExt : public edm::EDAnalyzer {
public:
explicit L1CondDBPayloadWriterExt(const edm::ParameterSet&);
Expand All @@ -26,6 +31,9 @@ class L1CondDBPayloadWriterExt : public edm::EDAnalyzer {
l1t::DataWriterExt m_writer;
// std::string m_tag ; // tag is known by PoolDBOutputService

// token to access object key
edm::ESGetToken<L1TriggerKeyExt, L1TriggerKeyExtRcd> key_token;

// set to false to write config data without valid TSC key
bool m_writeL1TriggerKeyExt;

Expand Down
32 changes: 14 additions & 18 deletions CondTools/L1TriggerExt/plugins/L1TriggerKeyOnlineProdExt.cc
Expand Up @@ -6,13 +6,18 @@

#include "FWCore/Framework/interface/EventSetup.h"

L1TriggerKeyOnlineProdExt::L1TriggerKeyOnlineProdExt(const edm::ParameterSet& iConfig)
: m_subsystemLabels(iConfig.getParameter<std::vector<std::string> >("subsystemLabels")) {
L1TriggerKeyOnlineProdExt::L1TriggerKeyOnlineProdExt(const edm::ParameterSet& iConfig) {
//the following line is needed to tell the framework what
// data is being produced
setWhatProduced(this);
auto cc = setWhatProduced(this);

//now do what ever other initialization is needed
for (auto const& label : iConfig.getParameter<std::vector<std::string> >("subsystemLabels")) {
m_subsystemTokens.emplace_back(cc.consumesFrom<L1TriggerKeyExt, L1TriggerKeyExtRcd>(edm::ESInputTag{"", label}));

//now do what ever other initialization is needed
}

cc.setConsumes(L1TriggerKeyExt_token, edm::ESInputTag{"", "SubsystemKeysOnly"});
}

L1TriggerKeyOnlineProdExt::~L1TriggerKeyOnlineProdExt() {
Expand All @@ -27,27 +32,18 @@ L1TriggerKeyOnlineProdExt::~L1TriggerKeyOnlineProdExt() {
// ------------ method called to produce the data ------------
L1TriggerKeyOnlineProdExt::ReturnType L1TriggerKeyOnlineProdExt::produce(const L1TriggerKeyExtRcd& iRecord) {
// Start with "SubsystemKeysOnly"
edm::ESHandle<L1TriggerKeyExt> subsystemKeys;
L1TriggerKeyExt subsystemKeys;
try {
iRecord.get("SubsystemKeysOnly", subsystemKeys);
subsystemKeys = iRecord.get(L1TriggerKeyExt_token);
} catch (l1t::DataAlreadyPresentException& ex) {
throw ex;
}

auto pL1TriggerKey = std::make_unique<L1TriggerKeyExt>(*subsystemKeys);
auto pL1TriggerKey = std::make_unique<L1TriggerKeyExt>(subsystemKeys);

// Collate object keys
std::vector<std::string>::const_iterator itr = m_subsystemLabels.begin();
std::vector<std::string>::const_iterator end = m_subsystemLabels.end();
for (; itr != end; ++itr) {
edm::ESHandle<L1TriggerKeyExt> objectKeys;
try {
iRecord.get(*itr, objectKeys);
} catch (l1t::DataAlreadyPresentException& ex) {
throw ex;
}

pL1TriggerKey->add(objectKeys->recordToKeyMap());
for (auto const& token : m_subsystemTokens) {
pL1TriggerKey->add(iRecord.get(token).recordToKeyMap());
}

return pL1TriggerKey;
Expand Down
3 changes: 3 additions & 0 deletions CondTools/L1TriggerExt/plugins/L1TriggerKeyOnlineProdExt.h
Expand Up @@ -8,6 +8,7 @@
#include "FWCore/Framework/interface/ModuleFactory.h"
#include "FWCore/Framework/interface/ESProducer.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/ESConsumesCollector.h"

#include "CondFormats/L1TObjects/interface/L1TriggerKeyExt.h"
#include "CondFormats/DataRecord/interface/L1TriggerKeyExtRcd.h"
Expand All @@ -23,6 +24,8 @@ class L1TriggerKeyOnlineProdExt : public edm::ESProducer {

private:
// ----------member data ---------------------------
edm::ESGetToken<L1TriggerKeyExt, L1TriggerKeyExtRcd> L1TriggerKeyExt_token;
std::vector<edm::ESGetToken<L1TriggerKeyExt, L1TriggerKeyExtRcd>> m_subsystemTokens;
std::vector<std::string> m_subsystemLabels;
};

Expand Down
9 changes: 5 additions & 4 deletions CondTools/L1TriggerExt/src/L1ObjectKeysOnlineProdBaseExt.cc
Expand Up @@ -12,7 +12,8 @@ L1ObjectKeysOnlineProdBaseExt::L1ObjectKeysOnlineProdBaseExt(const edm::Paramete

// The subsystemLabel is used by L1TriggerKeyOnlineProdExt to identify the
// L1TriggerKeysExt to concatenate.
setWhatProduced(this, iConfig.getParameter<std::string>("subsystemLabel"));
setWhatProduced(this, iConfig.getParameter<std::string>("subsystemLabel"))
.setConsumes(L1TriggerKeyExt_token, edm::ESInputTag{"", "SubsystemKeysOnly"});

//now do what ever other initialization is needed
}
Expand All @@ -26,15 +27,15 @@ L1ObjectKeysOnlineProdBaseExt::~L1ObjectKeysOnlineProdBaseExt() {
L1ObjectKeysOnlineProdBaseExt::ReturnType L1ObjectKeysOnlineProdBaseExt::produce(const L1TriggerKeyExtRcd& iRecord) {
// Get L1TriggerKeyExt with label "SubsystemKeysOnly". Re-throw exception if
// not present.
edm::ESHandle<L1TriggerKeyExt> subsystemKeys;
L1TriggerKeyExt subsystemKeys;
try {
iRecord.get("SubsystemKeysOnly", subsystemKeys);
subsystemKeys = iRecord.get(L1TriggerKeyExt_token);
} catch (l1t::DataAlreadyPresentException& ex) {
throw ex;
}

// Copy L1TriggerKeyExt to new object.
auto pL1TriggerKey = std::make_unique<L1TriggerKeyExt>(*subsystemKeys);
auto pL1TriggerKey = std::make_unique<L1TriggerKeyExt>(subsystemKeys);

// Get object keys.
fillObjectKeys(pL1TriggerKey.get());
Expand Down
Expand Up @@ -21,6 +21,7 @@ class L1TCaloParamsOnlineProd : public L1ConfigOnlineProdBaseExt<L1TCaloParamsO2
private:
unsigned int exclusiveLayer; // 0 - process calol1 and calol2, 1 - only calol1, 2 - only calol2
bool transactionSafe;
edm::ESGetToken<l1t::CaloParams, L1TCaloParamsRcd> baseSettings_token;

bool readCaloLayer1OnlineSettings(l1t::CaloParamsHelperO2O& paramsHelper,
std::map<std::string, l1t::Parameter>& conf,
Expand Down Expand Up @@ -210,23 +211,23 @@ bool L1TCaloParamsOnlineProd::readCaloLayer2OnlineSettings(l1t::CaloParamsHelper

L1TCaloParamsOnlineProd::L1TCaloParamsOnlineProd(const edm::ParameterSet& iConfig)
: L1ConfigOnlineProdBaseExt<L1TCaloParamsO2ORcd, l1t::CaloParams>(iConfig) {
wrappedSetWhatProduced(iConfig).setConsumes(baseSettings_token);
exclusiveLayer = iConfig.getParameter<uint32_t>("exclusiveLayer");
transactionSafe = iConfig.getParameter<bool>("transactionSafe");
}

std::unique_ptr<const l1t::CaloParams> L1TCaloParamsOnlineProd::newObject(const std::string& objectKey,
const L1TCaloParamsO2ORcd& record) {
const L1TCaloParamsRcd& baseRcd = record.template getRecord<L1TCaloParamsRcd>();
edm::ESHandle<l1t::CaloParams> baseSettings;
baseRcd.get(baseSettings);
auto const& baseSettings = baseRcd.get(baseSettings_token);

if (objectKey.empty()) {
edm::LogError("L1-O2O: L1TCaloParamsOnlineProd") << "Key is empty";
if (transactionSafe)
throw std::runtime_error("SummaryForFunctionManager: Calo | Faulty | Empty objectKey");
else {
edm::LogError("L1-O2O: L1TCaloParamsOnlineProd") << "returning unmodified prototype of l1t::CaloParams";
return std::make_unique<const l1t::CaloParams>(*(baseSettings.product()));
return std::make_unique<const l1t::CaloParams>(baseSettings);
}
}

Expand Down Expand Up @@ -283,7 +284,7 @@ std::unique_ptr<const l1t::CaloParams> L1TCaloParamsOnlineProd::newObject(const
throw std::runtime_error(std::string("SummaryForFunctionManager: Calo | Faulty | ") + e.what());
else {
edm::LogError("L1-O2O: L1TCaloParamsOnlineProd") << "returning unmodified prototype of l1t::CaloParams";
return std::make_unique<const l1t::CaloParams>(*(baseSettings.product()));
return std::make_unique<const l1t::CaloParams>(baseSettings);
}
}

Expand All @@ -305,7 +306,7 @@ std::unique_ptr<const l1t::CaloParams> L1TCaloParamsOnlineProd::newObject(const
output.close();
}

l1t::CaloParamsHelperO2O m_params_helper(*(baseSettings.product()));
l1t::CaloParamsHelperO2O m_params_helper(baseSettings);

if (exclusiveLayer == 0 || exclusiveLayer == 1) {
try {
Expand All @@ -329,7 +330,7 @@ std::unique_ptr<const l1t::CaloParams> L1TCaloParamsOnlineProd::newObject(const
throw std::runtime_error(std::string("SummaryForFunctionManager: Calo | Faulty | ") + e.what());
else {
edm::LogError("L1-O2O: L1TCaloParamsOnlineProd") << "returning unmodified prototype of l1t::CaloParams";
return std::make_unique<const l1t::CaloParams>(*(baseSettings.product()));
return std::make_unique<const l1t::CaloParams>(baseSettings);
}
}
}
Expand Down Expand Up @@ -363,7 +364,7 @@ std::unique_ptr<const l1t::CaloParams> L1TCaloParamsOnlineProd::newObject(const
throw std::runtime_error(std::string("SummaryForFunctionManager: Calo | Faulty | ") + e.what());
else {
edm::LogError("L1-O2O: L1TCaloParamsOnlineProd") << "returning unmodified prototype of l1t::CaloParams";
return std::make_unique<const l1t::CaloParams>(*(baseSettings.product()));
return std::make_unique<const l1t::CaloParams>(baseSettings);
}
}
}
Expand Down
Expand Up @@ -40,6 +40,7 @@ class L1TGlobalPrescalesVetosOnlineProd

L1TGlobalPrescalesVetosOnlineProd::L1TGlobalPrescalesVetosOnlineProd(const edm::ParameterSet &iConfig)
: L1ConfigOnlineProdBaseExt<L1TGlobalPrescalesVetosO2ORcd, L1TGlobalPrescalesVetos>(iConfig) {
wrappedSetWhatProduced(iConfig);
transactionSafe = iConfig.getParameter<bool>("transactionSafe");
}

Expand Down