Skip to content

Commit

Permalink
Merge pull request #35176 from thomreis/ecal-esconsumes-migration-sim…
Browse files Browse the repository at this point in the history
…calorimetry

ECAL esConsumes migration for remaining SimCalorimetry occurrences
  • Loading branch information
cmsbuild authored Sep 8, 2021
2 parents eeab406 + 506797a commit a9384ae
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 167 deletions.
17 changes: 11 additions & 6 deletions SimCalorimetry/EcalElectronicsEmulation/interface/EcalFEtoDigi.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* Created: Thu Feb 22 11:32:53 CET 2007
*/

#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/Frameworkfwd.h"
Expand All @@ -18,8 +17,11 @@
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/Exception.h"

#include "CondFormats/DataRecord/interface/EcalTPGLutGroupRcd.h"
#include "CondFormats/DataRecord/interface/EcalTPGLutIdMapRcd.h"
#include "CondFormats/EcalObjects/interface/EcalTPGLutGroup.h"
#include "CondFormats/EcalObjects/interface/EcalTPGLutIdMap.h"
#include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
//#include "Geometry/EcalMapping/interface/EcalElectronicsMapping.h"

#include <fstream>
#include <iomanip>
Expand Down Expand Up @@ -50,15 +52,18 @@ class EcalFEtoDigi : public edm::one::EDProducer<> {
int SMidToTCCid(const int) const;
void getLUT(unsigned int *lut, const int towerId, const edm::EventSetup &) const;

const edm::ESGetToken<EcalTPGLutGroup, EcalTPGLutGroupRcd> tpgLutGroupToken_;
const edm::ESGetToken<EcalTPGLutIdMap, EcalTPGLutIdMapRcd> tpgLutIdMapToken_;

TCCInputData inputdata_[N_SM];

std::string basename_;
bool useIdentityLUT_;
const std::string basename_;
const bool useIdentityLUT_;
int sm_;
bool singlefile;

int fileEventOffset_;
bool debug_;
const int fileEventOffset_;
const bool debug_;
std::ofstream outfile;
};

Expand Down
27 changes: 10 additions & 17 deletions SimCalorimetry/EcalElectronicsEmulation/src/EcalFEtoDigi.cc
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
#include "CondFormats/DataRecord/interface/EcalTPGLutGroupRcd.h"
#include "CondFormats/DataRecord/interface/EcalTPGLutIdMapRcd.h"
#include "CondFormats/EcalObjects/interface/EcalTPGLutGroup.h"
#include "CondFormats/EcalObjects/interface/EcalTPGLutIdMap.h"
#include "SimCalorimetry/EcalElectronicsEmulation/interface/EcalFEtoDigi.h"

EcalFEtoDigi::EcalFEtoDigi(const edm::ParameterSet &iConfig) {
basename_ = iConfig.getUntrackedParameter<std::string>("FlatBaseName", "ecal_tcc_");
sm_ = iConfig.getUntrackedParameter<int>("SuperModuleId", -1);
fileEventOffset_ = iConfig.getUntrackedParameter<int>("FileEventOffset", 0);
useIdentityLUT_ = iConfig.getUntrackedParameter<bool>("UseIdentityLUT", false);
debug_ = iConfig.getUntrackedParameter<bool>("debugPrintFlag", false);

EcalFEtoDigi::EcalFEtoDigi(const edm::ParameterSet &iConfig)
: tpgLutGroupToken_(esConsumes()),
tpgLutIdMapToken_(esConsumes()),
basename_(iConfig.getUntrackedParameter<std::string>("FlatBaseName", "ecal_tcc_")),
useIdentityLUT_(iConfig.getUntrackedParameter<bool>("UseIdentityLUT", false)),
sm_(iConfig.getUntrackedParameter<int>("SuperModuleId", -1)),
fileEventOffset_(iConfig.getUntrackedParameter<int>("FileEventOffset", 0)),
debug_(iConfig.getUntrackedParameter<bool>("debugPrintFlag", false)) {
singlefile = (sm_ == -1) ? false : true;

produces<EcalTrigPrimDigiCollection>();
Expand Down Expand Up @@ -301,17 +298,13 @@ int EcalFEtoDigi::SMidToTCCid(const int smid) const { return (smid <= 18) ? smid

/// return the LUT from eventSetup
void EcalFEtoDigi::getLUT(unsigned int *lut, const int towerId, const edm::EventSetup &evtSetup) const {
edm::ESHandle<EcalTPGLutGroup> lutGrpHandle;
evtSetup.get<EcalTPGLutGroupRcd>().get(lutGrpHandle);
const EcalTPGGroups::EcalTPGGroupsMap &lutGrpMap = lutGrpHandle.product()->getMap();
const EcalTPGGroups::EcalTPGGroupsMap &lutGrpMap = evtSetup.getData(tpgLutGroupToken_).getMap();
EcalTPGGroups::EcalTPGGroupsMapItr itgrp = lutGrpMap.find(towerId);
uint32_t lutGrp = 999;
if (itgrp != lutGrpMap.end())
lutGrp = itgrp->second;

edm::ESHandle<EcalTPGLutIdMap> lutMapHandle;
evtSetup.get<EcalTPGLutIdMapRcd>().get(lutMapHandle);
const EcalTPGLutIdMap::EcalTPGLutMap &lutMap = lutMapHandle.product()->getMap();
const EcalTPGLutIdMap::EcalTPGLutMap &lutMap = evtSetup.getData(tpgLutIdMapToken_).getMap();
EcalTPGLutIdMap::EcalTPGLutMapItr itLut = lutMap.find(lutGrp);
if (itLut != lutMap.end()) {
const unsigned int *theLut = (itLut->second).getLut();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
#include "FWCore/Utilities/interface/ESGetToken.h"
#include "CondFormats/EcalObjects/interface/EcalSRSettings.h"
#include "CondFormats/DataRecord/interface/EcalSRSettingsRcd.h"
#include "CondFormats/EcalObjects/interface/EcalTPGPhysicsConst.h"
#include "CondFormats/DataRecord/interface/EcalTPGPhysicsConstRcd.h"

#include <string>
/**
*/
class EcalSRCondTools : public edm::one::EDAnalyzer<> {
Expand Down Expand Up @@ -68,10 +71,14 @@ class EcalSRCondTools : public edm::one::EDAnalyzer<> {

//fields
private:
edm::ParameterSet ps_;
edm::ESGetToken<EcalSRSettings, EcalSRSettingsRcd> hSrToken_;
const edm::ParameterSet ps_;

const std::string mode_;
bool iomode_write_;
bool done_;

edm::ESGetToken<EcalSRSettings, EcalSRSettingsRcd> hSrToken_;
edm::ESGetToken<EcalTPGPhysicsConst, EcalTPGPhysicsConstRcd> tpgPhysicsConstToken_;
};

#endif //SRCONDACCESS_H not defined
35 changes: 14 additions & 21 deletions SimCalorimetry/EcalSelectiveReadoutProducers/src/EcalSRCondTools.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@
#include "FWCore/ServiceRegistry/interface/Service.h"
#include "CondCore/DBOutputService/interface/PoolDBOutputService.h"

#include "CondFormats/EcalObjects/interface/EcalSRSettings.h"
#include "CondFormats/EcalObjects/interface/EcalTPGPhysicsConst.h"
#include "CondFormats/DataRecord/interface/EcalTPGPhysicsConstRcd.h"

#include <string>
#include <fstream>
#include <iostream>
#include <algorithm>
Expand Down Expand Up @@ -58,7 +53,13 @@ constexpr int dccNum[12][12] = {
using namespace std;

EcalSRCondTools::EcalSRCondTools(const edm::ParameterSet& ps)
: ps_(ps), hSrToken_(esConsumes<EcalSRSettings, EcalSRSettingsRcd>()), done_(false) {}
: ps_(ps), mode_(ps.getParameter<string>("mode")), iomode_write_(true), done_(false) {
if (mode_ == "read") {
iomode_write_ = false;
hSrToken_ = esConsumes();
tpgPhysicsConstToken_ = esConsumes();
}
}

EcalSRCondTools::~EcalSRCondTools() {}

Expand All @@ -67,10 +68,7 @@ void EcalSRCondTools::analyze(const edm::Event& event, const edm::EventSetup& es
return;
EcalSRSettings* sr = new EcalSRSettings;

string mode = ps_.getParameter<string>("mode");

bool iomode_write = true;
if (mode == "online_config" || mode == "combine_config") {
if (mode_ == "online_config" || mode_ == "combine_config") {
string fname = ps_.getParameter<string>("onlineSrpConfigFile");
ifstream f(fname.c_str());
if (!f.good()) {
Expand All @@ -79,20 +77,16 @@ void EcalSRCondTools::analyze(const edm::Event& event, const edm::EventSetup& es
importSrpConfigFile(*sr, f, true);
}

if (mode == "python_config" || mode == "combine_config") {
if (mode_ == "python_config" || mode_ == "combine_config") {
importParameterSet(*sr, ps_);
}

if (mode == "read") {
iomode_write = false;
}

if (!(mode == "python_config" || mode == "online_config" || mode == "combine_config" || (mode == "read"))) {
throw cms::Exception("Config") << "Invalid value," << mode << ", for parameter mode. "
if (!(mode_ == "python_config" || mode_ == "online_config" || mode_ == "combine_config" || (mode_ == "read"))) {
throw cms::Exception("Config") << "Invalid value," << mode_ << ", for parameter mode. "
<< "Valid values: online_config, python_config, combine_config, read";
}

if (iomode_write) {
if (iomode_write_) {
sr->bxGlobalOffset_ = ps_.getParameter<int>("bxGlobalOffset");
sr->automaticSrpSelect_ = ps_.getParameter<int>("automaticSrpSelect");
sr->automaticMasks_ = ps_.getParameter<int>("automaticMasks");
Expand All @@ -107,7 +101,7 @@ void EcalSRCondTools::analyze(const edm::Event& event, const edm::EventSetup& es
db->writeOne(sr, firstSinceTime, "EcalSRSettingsRcd");
done_ = true;
} else { //read mode
edm::ESHandle<EcalSRSettings> hSr = es.getHandle(hSrToken_);
const edm::ESHandle<EcalSRSettings> hSr = es.getHandle(hSrToken_);
if (!hSr.isValid()) {
cout << "EcalSRSettings record not found. Check the Cond DB Global tag.\n";
} else {
Expand All @@ -117,8 +111,7 @@ void EcalSRCondTools::analyze(const edm::Event& event, const edm::EventSetup& es
}

//trigger tower thresholds (from FENIX configuration):
edm::ESHandle<EcalTPGPhysicsConst> hTp;
es.get<EcalTPGPhysicsConstRcd>().get(hTp);
const edm::ESHandle<EcalTPGPhysicsConst> hTp = es.getHandle(tpgPhysicsConstToken_);
if (!hTp.isValid()) {
cout << "EcalTPGPhysicsConst record not found. Check the Cond DB Global tag.\n";
} else {
Expand Down
Loading

0 comments on commit a9384ae

Please sign in to comment.