File indexing completed on 2024-04-06 12:29:25
0001
0002
0003
0004
0005
0006
0007 #include "SimCalorimetry/EcalSelectiveReadoutProducers/interface/namespace_ecalsrcondtools.h"
0008
0009 #include "FWCore/Framework/interface/Frameworkfwd.h"
0010 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0011 #include "FWCore/Utilities/interface/ESGetToken.h"
0012 #include "CondFormats/EcalObjects/interface/EcalTPGPhysicsConst.h"
0013 #include "CondFormats/DataRecord/interface/EcalSRSettingsRcd.h"
0014 #include "CondFormats/DataRecord/interface/EcalTPGPhysicsConstRcd.h"
0015
0016 #include "FWCore/Framework/interface/ESHandle.h"
0017 #include "FWCore/Framework/interface/Event.h"
0018 #include "FWCore/Framework/interface/EventSetup.h"
0019 #include "FWCore/ServiceRegistry/interface/Service.h"
0020 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0021
0022 #include "FWCore/PluginManager/interface/ModuleDef.h"
0023 #include "FWCore/Framework/interface/MakerMacros.h"
0024
0025 #include <fstream>
0026 #include <iostream>
0027 #include <algorithm>
0028
0029 namespace module {
0030 class EcalSRCondTools : public edm::one::EDAnalyzer<> {
0031
0032 public:
0033
0034
0035
0036 EcalSRCondTools(const edm::ParameterSet&);
0037
0038
0039
0040 ~EcalSRCondTools() override;
0041
0042
0043
0044
0045
0046 void analyze(const edm::Event& evt, const edm::EventSetup& es) override;
0047
0048
0049 private:
0050 const edm::ParameterSet ps_;
0051
0052 const std::string mode_;
0053 bool iomode_write_;
0054 bool done_;
0055
0056 edm::ESGetToken<EcalSRSettings, EcalSRSettingsRcd> hSrToken_;
0057 edm::ESGetToken<EcalTPGPhysicsConst, EcalTPGPhysicsConstRcd> tpgPhysicsConstToken_;
0058 };
0059
0060 using namespace std;
0061 using namespace ecalsrcondtools;
0062
0063 EcalSRCondTools::EcalSRCondTools(const edm::ParameterSet& ps)
0064 : ps_(ps), mode_(ps.getParameter<string>("mode")), iomode_write_(true), done_(false) {
0065 if (mode_ == "read") {
0066 iomode_write_ = false;
0067 hSrToken_ = esConsumes();
0068 tpgPhysicsConstToken_ = esConsumes();
0069 }
0070 }
0071
0072 EcalSRCondTools::~EcalSRCondTools() {}
0073
0074 void EcalSRCondTools::analyze(const edm::Event& event, const edm::EventSetup& es) {
0075 if (done_)
0076 return;
0077 EcalSRSettings sr;
0078
0079 if (mode_ == "online_config" || mode_ == "combine_config") {
0080 string fname = ps_.getParameter<string>("onlineSrpConfigFile");
0081 ifstream f(fname.c_str());
0082 if (!f.good()) {
0083 throw cms::Exception("EcalSRCondTools") << "Failed to open file " << fname;
0084 }
0085 importSrpConfigFile(sr, f, true);
0086 }
0087
0088 if (mode_ == "python_config" || mode_ == "combine_config") {
0089 importParameterSet(sr, ps_);
0090 }
0091
0092 if (!(mode_ == "python_config" || mode_ == "online_config" || mode_ == "combine_config" || (mode_ == "read"))) {
0093 throw cms::Exception("Config") << "Invalid value," << mode_ << ", for parameter mode. "
0094 << "Valid values: online_config, python_config, combine_config, read";
0095 }
0096
0097 if (iomode_write_) {
0098 sr.bxGlobalOffset_ = ps_.getParameter<int>("bxGlobalOffset");
0099 sr.automaticSrpSelect_ = ps_.getParameter<int>("automaticSrpSelect");
0100 sr.automaticMasks_ = ps_.getParameter<int>("automaticMasks");
0101
0102 edm::Service<cond::service::PoolDBOutputService> db;
0103 if (!db.isAvailable()) {
0104 throw cms::Exception("CondDBAccess") << "Failed to connect to PoolDBOutputService\n";
0105 }
0106
0107
0108 cond::Time_t firstSinceTime = db->beginOfTime();
0109 db->writeOneIOV(sr, firstSinceTime, "EcalSRSettingsRcd");
0110 done_ = true;
0111 } else {
0112 const edm::ESHandle<EcalSRSettings> hSr = es.getHandle(hSrToken_);
0113 if (!hSr.isValid()) {
0114 cout << "EcalSRSettings record not found. Check the Cond DB Global tag.\n";
0115 } else {
0116 const EcalSRSettings* ssr = hSr.product();
0117 cout << "ECAL Seletive readout settings:\n";
0118 cout << *ssr << "\n" << endl;
0119 }
0120
0121
0122 const edm::ESHandle<EcalTPGPhysicsConst> hTp = es.getHandle(tpgPhysicsConstToken_);
0123 if (!hTp.isValid()) {
0124 cout << "EcalTPGPhysicsConst record not found. Check the Cond DB Global tag.\n";
0125 } else {
0126 const EcalTPGPhysicsConst* tp = hTp.product();
0127 const EcalTPGPhysicsConstMap& mymap = tp->getMap();
0128 if (mymap.size() != 2) {
0129 cout << "Error: TPG physics record is of unexpected size: " << mymap.size()
0130 << " elements instead of two (one for EB, one for EE)\n";
0131 } else {
0132 EcalTPGPhysicsConstMap::const_iterator it = mymap.begin();
0133 cout << "----------------------------------------------------------------------\n"
0134 "Trigger tower Et thresholds extracted from TPG configuration \n"
0135 "(EcalSRCondTools modules supports only read mode for these parameters):\n\n";
0136 cout << "EB: "
0137 << "LT = " << it->second.ttf_threshold_Low << " GeV "
0138 << "HT = " << it->second.ttf_threshold_High << " GeV\n";
0139 ++it;
0140 cout << "EE: "
0141 << "LT = " << it->second.ttf_threshold_Low << " GeV "
0142 << "HT = " << it->second.ttf_threshold_High << " GeV\n";
0143 }
0144 }
0145 }
0146 }
0147 }
0148
0149 using namespace module;
0150 DEFINE_FWK_MODULE(EcalSRCondTools);