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

[L1-O2O] make WriterProxyT to use ESGetToken #37681

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
DataWriterExt and WriterProxyT changes for propagating
the ESGetToken to the WriterProxyT implementations
  • Loading branch information
panoskatsoulis committed Apr 26, 2022
commit bdf5c46d4c7ced0c23f660f76da35154171152f3
12 changes: 9 additions & 3 deletions CondTools/L1Trigger/interface/WriterProxy.h
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@

#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/EDConsumerBase.h"
#include "FWCore/Framework/interface/ConsumesCollector.h"

#include "FWCore/PluginManager/interface/PluginFactory.h"

@@ -35,6 +35,8 @@ namespace l1t {
* methods here.
*/

virtual void setToken(edm::ConsumesCollector cc) = 0;

virtual std::string save(const edm::EventSetup& setup) const = 0;

protected:
@@ -44,14 +46,18 @@ namespace l1t {
* should instaciate a new version of this class and register it in plugin system.
*/
template <class Record, class Type>
class WriterProxyT : public WriterProxy {
class WriterProxyT : public WriterProxy {

private:
edm::ESGetToken<Type, Record> rcdToken;

public:
WriterProxyT() : rcdToken(esConsumes()) {}
~WriterProxyT() override {}

void setToken(edm::ConsumesCollector cc) override {
rcdToken = cc.esConsumes();
}

/* This method requires that Record and Type supports copy constructor */
std::string save(const edm::EventSetup& setup) const override {
// load record and type from EventSetup and save them in db
11 changes: 11 additions & 0 deletions CondTools/L1TriggerExt/interface/DataWriterExt.h
Original file line number Diff line number Diff line change
@@ -32,15 +32,19 @@ namespace l1t {
* REGISTER_PLUGIN(record, type) from registration_macros.h found in PluginSystem.
*/

typedef std::unique_ptr<WriterProxy> WriterProxyPtr;

class DataWriterExt {
public:
DataWriterExt();
DataWriterExt(const std::string&);
~DataWriterExt();

// Payload and IOV writing functions.

// Get payload from EventSetup and write to DB with no IOV
// recordType = "record@type", return value is payload token
std::string writePayload(const edm::EventSetup& setup);
std::string writePayload(const edm::EventSetup& setup, const std::string& recordType);

// Use PoolDBOutputService to append IOV with sinceRun to IOV sequence
@@ -65,6 +69,13 @@ namespace l1t {

bool fillLastTriggerKeyList(L1TriggerKeyListExt& output);

WriterProxy* getWriter() {
return writer.get();
}

private:
WriterProxyPtr writer;

protected:
};

41 changes: 38 additions & 3 deletions CondTools/L1TriggerExt/src/DataWriterExt.cc
Original file line number Diff line number Diff line change
@@ -7,17 +7,52 @@
#include "CondCore/CondDB/interface/Serialization.h"

#include <utility>
#include <typeinfo>

namespace l1t {

// Default Constructor
DataWriterExt::DataWriterExt() {}

// Constructor Needed for Writers with Rcds dependednt on Online Producers
// they need to be constructed at "construction time" to register what they produce
DataWriterExt::DataWriterExt(const std::string& recordType) {
WriterFactory* factory = WriterFactory::get();
writer = std::move( WriterProxyPtr(factory->create(recordType + "@Writer")) );
if (writer.get() == nullptr) {
throw cond::Exception("DataWriter: could not create WriterProxy with name " + recordType + "@Writer");
}
edm::LogVerbatim("L1-O2O DataWriterExt::DataWriterExt") << "Created new " << typeid(writer).name()
<< " | address " << writer.get()
<< " | rcd " << recordType;
}
DataWriterExt::~DataWriterExt() {}

std::string DataWriterExt::writePayload(const edm::EventSetup& setup) {
edm::LogVerbatim("L1-O2O DataWriterExt::writePayload")
<< "Will use stored writer at " << writer.get();

edm::Service<cond::service::PoolDBOutputService> poolDb;
if (!poolDb.isAvailable()) {
throw cond::Exception("DataWriter: PoolDBOutputService not available.");
}

// 2010-02-16: Move session and transaction to WriterProxy::save(). Otherwise, if another transaction is
// started while WriterProxy::save() is called (e.g. in a ESProducer like L1ConfigOnlineProdBase), the
// transaction here will become read-only.
std::string payloadToken = writer->save(setup);
edm::LogVerbatim("L1-O2O") << typeid(*writer).name() << " PAYLOAD TOKEN " << payloadToken;

return payloadToken;
}

std::string DataWriterExt::writePayload(const edm::EventSetup& setup, const std::string& recordType) {
WriterFactory* factory = WriterFactory::get();
std::unique_ptr<WriterProxy> writer(factory->create(recordType + "@Writer"));
if (writer.get() == nullptr) {
WriterProxyPtr writer_(factory->create(recordType + "@Writer"));
if (writer_.get() == nullptr) {
throw cond::Exception("DataWriter: could not create WriterProxy with name " + recordType + "@Writer");
}
writer = std::move(writer_);

edm::Service<cond::service::PoolDBOutputService> poolDb;
if (!poolDb.isAvailable()) {
@@ -38,7 +73,7 @@ namespace l1t {
// std::string payloadToken = writer->save( setup, session ) ;
std::string payloadToken = writer->save(setup);

edm::LogVerbatim("L1-O2O") << recordType << " PAYLOAD TOKEN " << payloadToken;
edm::LogVerbatim("L1-O2O") << typeid(*writer).name() << " PAYLOAD TOKEN " << payloadToken;

//// tr.close();
// tr.commit ();