File indexing completed on 2023-03-17 11:17:06
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #include <iostream>
0021 #include <memory>
0022
0023
0024 #include "FWCore/Framework/interface/Frameworkfwd.h"
0025 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0026 #include "FWCore/Framework/interface/ESHandle.h"
0027 #include "FWCore/Framework/interface/ESWatcher.h"
0028
0029 #include "FWCore/Framework/interface/Event.h"
0030 #include "FWCore/Framework/interface/MakerMacros.h"
0031
0032 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0033
0034 #include "FWCore/ServiceRegistry/interface/Service.h"
0035 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0036
0037 #include "PhysicsTools/CondLiteIO/interface/RecordWriter.h"
0038 #include "DataFormats/Provenance/interface/ESRecordAuxiliary.h"
0039 #include "DataFormats/FWLite/interface/format_type_name.h"
0040
0041 #include "RecoBTag/Records/interface/BTagPerformanceRecord.h"
0042 #include "RecoBTag/PerformanceDB/interface/BtagPerformance.h"
0043
0044 #include "CondFormats/PhysicsToolsObjects/interface/BinningPointByMap.h"
0045
0046
0047
0048
0049
0050 class BTagPerformaceRootProducerFromSQLITE : public edm::one::EDAnalyzer<edm::one::SharedResources> {
0051 public:
0052 explicit BTagPerformaceRootProducerFromSQLITE(const edm::ParameterSet&);
0053
0054 private:
0055 void analyze(const edm::Event&, const edm::EventSetup&) override;
0056
0057
0058 std::vector<std::string> names_;
0059 std::vector<edm::ESGetToken<BtagPerformance, BTagPerformanceRecord>> tokens_;
0060 edm::ESWatcher<BTagPerformanceRecord> recWatcher_;
0061 std::unique_ptr<fwlite::RecordWriter> writer_;
0062 edm::IOVSyncValue lastValue_;
0063 };
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076 BTagPerformaceRootProducerFromSQLITE::BTagPerformaceRootProducerFromSQLITE(const edm::ParameterSet& iConfig)
0077 : names_(iConfig.getParameter<std::vector<std::string>>("names")) {
0078 usesResource(TFileService::kSharedResource);
0079 tokens_.reserve(names_.size());
0080 for (auto const& n : names_) {
0081 tokens_.push_back(esConsumes<BtagPerformance, BTagPerformanceRecord>(edm::ESInputTag("", n)));
0082 }
0083 }
0084
0085
0086
0087
0088
0089
0090 void BTagPerformaceRootProducerFromSQLITE::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0091 edm::LogInfo("BTagPerformaceRootProducerFromSQLITE") << "Hello from BTagPerformaceRootProducerFromSQLITE!";
0092 if (recWatcher_.check(iSetup)) {
0093 const BTagPerformanceRecord& r = iSetup.get<BTagPerformanceRecord>();
0094
0095 if (!writer_.get()) {
0096 edm::Service<TFileService> fs;
0097 TFile* f = &(fs->file());
0098 writer_ = std::make_unique<fwlite::RecordWriter>(r.key().name(), f);
0099 }
0100 lastValue_ = r.validityInterval().last();
0101
0102 for (size_t i = 0; i < names_.size(); i++) {
0103 edm::LogInfo("BTagPerformaceRootProducerFromSQLITE") << " Studying performance with label " << names_[i];
0104 const BtagPerformance& perf = r.get(tokens_[i]);
0105
0106 writer_->update(&(perf.payload()), typeid(PerformancePayload), names_[i].c_str());
0107 writer_->update(&(perf.workingPoint()), typeid(PerformanceWorkingPoint), names_[i].c_str());
0108 }
0109 writer_->fill(edm::ESRecordAuxiliary(r.validityInterval().first().eventID(), r.validityInterval().first().time()));
0110 }
0111 }
0112
0113
0114 DEFINE_FWK_MODULE(BTagPerformaceRootProducerFromSQLITE);