Skip to content

Commit

Permalink
Merge pull request #35023 from sroychow/condtoolsdtesconsumes
Browse files Browse the repository at this point in the history
Migrate Condtools-DT modules to esConsumes
  • Loading branch information
cmsbuild authored Sep 14, 2021
2 parents a4d315d + 690103a commit 693e364
Show file tree
Hide file tree
Showing 35 changed files with 180 additions and 169 deletions.
66 changes: 41 additions & 25 deletions CondTools/DT/plugins/DTKeyedConfigDBDump.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@
*
*/

//-----------------------
// This Class' Header --
//-----------------------
#include "CondTools/DT/plugins/DTKeyedConfigDBDump.h"

//----------------------
// Base Class Headers --
//----------------------
#include "FWCore/Framework/interface/one/EDAnalyzer.h"
//------------------------------------
// Collaborating Class Declarations --
//------------------------------------
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
//-------------------------------
// Collaborating Class Headers --
//-------------------------------
Expand All @@ -21,20 +26,36 @@
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/MakerMacros.h"

//---------------
// C++ Headers --
//---------------
#include <iostream>
#include <memory>
//-----------------------
// This Class' Header --
//-----------------------
class DTKeyedConfigDBDump : public edm::one::EDAnalyzer<> {
public:
/** Constructor
*/
explicit DTKeyedConfigDBDump(const edm::ParameterSet& ps);

/** Destructor
*/
~DTKeyedConfigDBDump() override;

/** Operations
*/
///
void beginJob() override;
void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) override;

private:
edm::ESGetToken<cond::persistency::KeyList, DTKeyedConfigListRcd> perskeylistToken_;
};
//-------------------
// Initializations --
//-------------------

//----------------
// Constructors --
//----------------
DTKeyedConfigDBDump::DTKeyedConfigDBDump(const edm::ParameterSet& ps) {}
DTKeyedConfigDBDump::DTKeyedConfigDBDump(const edm::ParameterSet& ps) : perskeylistToken_(esConsumes()) {}

//--------------
// Destructor --
Expand All @@ -46,28 +67,23 @@ DTKeyedConfigDBDump::~DTKeyedConfigDBDump() {}
//--------------
void DTKeyedConfigDBDump::beginJob() { return; }

void DTKeyedConfigDBDump::analyze(const edm::Event& e, const edm::EventSetup& c) {
void DTKeyedConfigDBDump::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
edm::eventsetup::EventSetupRecordKey recordKey(
edm::eventsetup::EventSetupRecordKey::TypeTag::findType("DTKeyedConfigListRcd"));
if (recordKey.type() == edm::eventsetup::EventSetupRecordKey::TypeTag()) {
//record not found
std::cout << "Record \"DTKeyedConfigListRcd "
<< "\" does not exist " << std::endl;
edm::LogWarning("DTKeyedConfigDBDump") << "Record \"DTKeyedConfigListRcd "
<< "\" does not exist " << std::endl;
}
edm::ESHandle<cond::persistency::KeyList> klh;
std::cout << "got eshandle" << std::endl;
c.get<DTKeyedConfigListRcd>().get(klh);
std::cout << "got context" << std::endl;
cond::persistency::KeyList const& kl = *klh.product();
cond::persistency::KeyList const* kp = &kl;
std::cout << "now load and get" << std::endl;
cond::persistency::KeyList const* kp = &iSetup.getData(perskeylistToken_);
edm::LogInfo("DTKeyedConfigDBDump") << "now load and get" << std::endl;
auto pkc = kp->getUsingKey<DTKeyedConfig>(999999999);
std::cout << "now check" << std::endl;
edm::LogInfo("DTKeyedConfigDBDump") << "now check" << std::endl;
if (pkc.get())
std::cout << pkc->getId() << " " << *(pkc->dataBegin()) << std::endl;
edm::LogInfo("DTKeyedConfigDBDump") << pkc->getId() << " " << *(pkc->dataBegin()) << std::endl;
else
std::cout << "not found" << std::endl;
std::cout << std::endl;
edm::LogInfo("DTKeyedConfigDBDump") << "not found" << std::endl;
edm::LogInfo("DTKeyedConfigDBDump") << std::endl;
return;
}

Expand Down
54 changes: 0 additions & 54 deletions CondTools/DT/plugins/DTKeyedConfigDBDump.h

This file was deleted.

4 changes: 2 additions & 2 deletions CondTools/DT/plugins/DTKeyedConfigDBInit.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//----------------------
// Base Class Headers --
//----------------------
#include "FWCore/Framework/interface/EDAnalyzer.h"
#include "FWCore/Framework/interface/one/EDAnalyzer.h"

//------------------------------------
// Collaborating Class Declarations --
Expand All @@ -32,7 +32,7 @@
// -- Class Interface --
// ---------------------

class DTKeyedConfigDBInit : public edm::EDAnalyzer {
class DTKeyedConfigDBInit : public edm::one::EDAnalyzer<> {
public:
/** Constructor
*/
Expand Down
16 changes: 7 additions & 9 deletions CondTools/DT/plugins/DTKeyedConfigPopConAnalyzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,25 @@ class DTKeyedConfigPopConAnalyzer : public popcon::PopConAnalyzer<DTKeyedConfigH
public:
DTKeyedConfigPopConAnalyzer(const edm::ParameterSet& pset)
: popcon::PopConAnalyzer<DTKeyedConfigHandler>(pset),
copyData(pset.getParameter<edm::ParameterSet>("Source").getUntrackedParameter<bool>("copyData", true)) {}
copyData(pset.getParameter<edm::ParameterSet>("Source").getUntrackedParameter<bool>("copyData", true)),
perskeylistToken_(esConsumes()) {}
~DTKeyedConfigPopConAnalyzer() override {}
void analyze(const edm::Event& e, const edm::EventSetup& s) override {
void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) override {
if (!copyData)
return;

edm::ESHandle<cond::persistency::KeyList> klh;
std::cout << "got eshandle" << std::endl;
s.get<DTKeyedConfigListRcd>().get(klh);
std::cout << "got context" << std::endl;
cond::persistency::KeyList const& kl = *klh.product();
edm::LogInfo("DTKeyedConfigPopConAnalyzer") << "got context" << std::endl;
cond::persistency::KeyList const& kl = iSetup.getData(perskeylistToken_);
for (size_t i = 0; i < kl.size(); i++) {
std::shared_ptr<DTKeyedConfig> kelem = kl.getUsingIndex<DTKeyedConfig>(i);
if (kelem.get())
std::cout << kelem->getId() << std::endl;
edm::LogInfo("DTKeyedConfigPopConAnalyzer") << kelem->getId() << std::endl;
}
source().setList(&kl);
}

private:
bool copyData;
edm::ESGetToken<cond::persistency::KeyList, DTKeyedConfigListRcd> perskeylistToken_;
};

DEFINE_FWK_MODULE(DTKeyedConfigPopConAnalyzer);
14 changes: 6 additions & 8 deletions CondTools/DT/plugins/DTUserKeyedConfigPopConAnalyzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,21 @@
class DTUserKeyedConfigPopConAnalyzer : public popcon::PopConAnalyzer<DTUserKeyedConfigHandler> {
public:
DTUserKeyedConfigPopConAnalyzer(const edm::ParameterSet& pset)
: popcon::PopConAnalyzer<DTUserKeyedConfigHandler>(pset) {}
: popcon::PopConAnalyzer<DTUserKeyedConfigHandler>(pset), perskeylistToken_(esConsumes()) {}
~DTUserKeyedConfigPopConAnalyzer() override {}
void analyze(const edm::Event& e, const edm::EventSetup& s) override {
edm::ESHandle<cond::persistency::KeyList> klh;
std::cout << "got eshandle" << std::endl;
s.get<DTKeyedConfigListRcd>().get(klh);
std::cout << "got context" << std::endl;
cond::persistency::KeyList const& kl = *klh.product();
void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) override {
edm::LogInfo("DTUserKeyedConfigPopConAnalyzer") << "got eSdata" << std::endl;
cond::persistency::KeyList const& kl = iSetup.getData(perskeylistToken_);
for (size_t i = 0; i < kl.size(); i++) {
std::shared_ptr<DTKeyedConfig> kentry = kl.getUsingIndex<DTKeyedConfig>(i);
if (kentry.get())
std::cout << kentry->getId() << std::endl;
edm::LogInfo("DTUserKeyedConfigPopConAnalyzer") << kentry->getId() << std::endl;
}
source().setList(&kl);
}

private:
edm::ESGetToken<cond::persistency::KeyList, DTKeyedConfigListRcd> perskeylistToken_;
};

DEFINE_FWK_MODULE(DTUserKeyedConfigPopConAnalyzer);
8 changes: 3 additions & 5 deletions CondTools/DT/test/stubs/DTGeometryDump.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,15 @@ Toy EDAnalyzer for testing purposes only.

namespace edmtest {

DTGeometryDump::DTGeometryDump(edm::ParameterSet const& p) {}
DTGeometryDump::DTGeometryDump(edm::ParameterSet const& p) : dtgeomToken_(esConsumes()) {}

DTGeometryDump::DTGeometryDump(int i) {}
DTGeometryDump::DTGeometryDump(int i) : dtgeomToken_(esConsumes()) {}

DTGeometryDump::~DTGeometryDump() {}

void DTGeometryDump::analyze(const edm::Event& e, const edm::EventSetup& context) {
using namespace edm::eventsetup;
edm::ESHandle<DTGeometry> muonGeom;
context.get<MuonGeometryRecord>().get(muonGeom);

auto muonGeom = context.getHandle(dtgeomToken_);
const std::vector<const DTChamber*>& ch_cont = muonGeom->chambers();
std::vector<const DTChamber*>::const_iterator ch_iter = ch_cont.begin();
std::vector<const DTChamber*>::const_iterator ch_iend = ch_cont.end();
Expand Down
3 changes: 3 additions & 0 deletions CondTools/DT/test/stubs/DTGeometryDump.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Toy EDAnalyzer for testing purposes only.
#include "FWCore/ParameterSet/interface/ParameterSet.h"

#include <string>
class DTGeometry;
class MuonGeometryRecord;

namespace edmtest {
class DTGeometryDump : public edm::EDAnalyzer {
Expand All @@ -22,5 +24,6 @@ namespace edmtest {
virtual void analyze(const edm::Event& e, const edm::EventSetup& c);

private:
edm::ESGetToken<DTGeometry, MuonGeometryRecord> dtgeomToken_;
};
} // namespace edmtest
8 changes: 3 additions & 5 deletions CondTools/DT/test/stubs/DTHVDump.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ Toy EDAnalyzer for testing purposes only.
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "CoralBase/TimeStamp.h"

#include "CondTools/DT/test/stubs/DTHVDump.h"
#include "CondFormats/DTObjects/interface/DTHVStatus.h"
#include "CondFormats/DataRecord/interface/DTHVStatusRcd.h"
Expand All @@ -21,11 +20,11 @@ Toy EDAnalyzer for testing purposes only.

namespace edmtest {

DTHVDump::DTHVDump(edm::ParameterSet const& p) {
DTHVDump::DTHVDump(edm::ParameterSet const& p) : dthvstatusToken_(esConsumes()) {
// parameters to setup
}

DTHVDump::DTHVDump(int i) {}
DTHVDump::DTHVDump(int i) : dthvstatusToken_(esConsumes()) {}

DTHVDump::~DTHVDump() {}

Expand All @@ -36,8 +35,7 @@ namespace edmtest {
std::cout << " ---EVENT NUMBER " << e.id().event() << std::endl;

// get configuration for current run
edm::ESHandle<DTHVStatus> hv;
context.get<DTHVStatusRcd>().get(hv);
auto hv = context.getHandle(dthvstatusToken_);
std::cout << hv->version() << std::endl;
std::cout << std::distance(hv->begin(), hv->end()) << " data in the container" << std::endl;
edm::ValidityInterval iov(context.get<DTHVStatusRcd>().validityInterval());
Expand Down
4 changes: 3 additions & 1 deletion CondTools/DT/test/stubs/DTHVDump.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ Toy EDAnalyzer for testing purposes only.
#include "FWCore/ParameterSet/interface/ParameterSet.h"

#include <string>

class DTHVStatus;
class DTHVStatusRcd;
namespace edmtest {
class DTHVDump : public edm::EDAnalyzer {
public:
Expand All @@ -22,5 +23,6 @@ namespace edmtest {
virtual void analyze(const edm::Event& e, const edm::EventSetup& c);

private:
edm::ESGetToken<DTHVStatus, DTHVStatusRcd> dthvstatusToken_;
};
} // namespace edmtest
9 changes: 5 additions & 4 deletions CondTools/DT/test/validate/DTCCBConfigValidateDBRead.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ Toy EDAnalyzer for testing purposes only.
#include "CondFormats/DataRecord/interface/DTCCBConfigRcd.h"

DTCCBConfigValidateDBRead::DTCCBConfigValidateDBRead(edm::ParameterSet const& p)
: dataFileName(p.getParameter<std::string>("chkFile")), elogFileName(p.getParameter<std::string>("logFile")) {}
: dataFileName(p.getParameter<std::string>("chkFile")),
elogFileName(p.getParameter<std::string>("logFile")),
dtccbToken_(esConsumes()) {}

DTCCBConfigValidateDBRead::DTCCBConfigValidateDBRead(int i) {}
DTCCBConfigValidateDBRead::DTCCBConfigValidateDBRead(int i) : dtccbToken_(esConsumes()) {}

DTCCBConfigValidateDBRead::~DTCCBConfigValidateDBRead() {}

Expand All @@ -40,8 +42,7 @@ void DTCCBConfigValidateDBRead::analyze(const edm::Event& e, const edm::EventSet
run_fn << "run" << e.id().run() << dataFileName;
std::ifstream chkFile(run_fn.str().c_str());
std::ofstream logFile(elogFileName.c_str(), std::ios_base::app);
edm::ESHandle<DTCCBConfig> conf;
context.get<DTCCBConfigRcd>().get(conf);
auto conf = context.getHandle(dtccbToken_);
std::cout << conf->version() << std::endl;
std::cout << std::distance(conf->begin(), conf->end()) << " data in the container" << std::endl;
int whe;
Expand Down
6 changes: 3 additions & 3 deletions CondTools/DT/test/validate/DTCCBConfigValidateDBRead.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/*----------------------------------------------------------------------
Toy EDAnalyzer for testing purposes only.
Expand All @@ -11,7 +10,8 @@ Toy EDAnalyzer for testing purposes only.
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
class DTConfigKey;

class DTCCBConfig;
class DTCCBConfigRcd;
class DTCCBConfigValidateDBRead : public edm::EDAnalyzer {
public:
explicit DTCCBConfigValidateDBRead(edm::ParameterSet const& p);
Expand All @@ -23,7 +23,7 @@ class DTCCBConfigValidateDBRead : public edm::EDAnalyzer {
private:
std::string dataFileName;
std::string elogFileName;

edm::ESGetToken<DTCCBConfig, DTCCBConfigRcd> dtccbToken_;
static bool cfrDiff(const std::vector<int>& l_conf, const std::vector<int>& r_conf);
static bool cfrDiff(const std::vector<DTConfigKey>& l_conf, const std::vector<DTConfigKey>& r_conf);
};
9 changes: 5 additions & 4 deletions CondTools/DT/test/validate/DTCompMapValidateDBRead.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ Toy EDAnalyzer for testing purposes only.
#include "CondFormats/DataRecord/interface/DTReadOutMappingRcd.h"

DTCompMapValidateDBRead::DTCompMapValidateDBRead(edm::ParameterSet const& p)
: dataFileName(p.getParameter<std::string>("chkFile")), elogFileName(p.getParameter<std::string>("logFile")) {}
: dataFileName(p.getParameter<std::string>("chkFile")),
elogFileName(p.getParameter<std::string>("logFile")),
dtreadoutmappingToken_(esConsumes()) {}

DTCompMapValidateDBRead::DTCompMapValidateDBRead(int i) {}
DTCompMapValidateDBRead::DTCompMapValidateDBRead(int i) : dtreadoutmappingToken_(esConsumes()) {}

DTCompMapValidateDBRead::~DTCompMapValidateDBRead() {}

Expand All @@ -41,8 +43,7 @@ void DTCompMapValidateDBRead::analyze(const edm::Event& e, const edm::EventSetup
// std::ifstream chkFile( run_fn.str().c_str() );
std::ifstream chkFile(dataFileName.c_str());
std::ofstream logFile(elogFileName.c_str(), std::ios_base::app);
edm::ESHandle<DTReadOutMapping> ro;
context.get<DTReadOutMappingRcd>().get(ro);
auto ro = context.getHandle(dtreadoutmappingToken_);
std::cout << ro->mapRobRos() << " " << ro->mapCellTdc() << std::endl;
std::cout << std::distance(ro->begin(), ro->end()) << " data in the container" << std::endl;
int whe;
Expand Down
Loading

0 comments on commit 693e364

Please sign in to comment.