Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-27 18:27:18

0001 // -*- C++ -*-
0002 //
0003 // Package:    BTagPerformaceRootProducerFromSQLITE
0004 // Class:      BTagPerformaceRootProducerFromSQLITE
0005 //
0006 /**\class BTagPerformaceRootProducerFromSQLITE BTagPerformaceRootProducerFromSQLITE.cc junk/BTagPerformaceRootProducerFromSQLITE/src/BTagPerformaceRootProducerFromSQLITE.cc
0007 
0008  Description: This writes out a ROOT file with a BtagPerformance object taken from an sqlite file. 
0009 
0010  Implementation:
0011      [Notes on implementation]
0012 */
0013 //
0014 // Original Author:  "Salvatore Rappoccio"
0015 //         Created:  Thu Feb 11 14:21:59 CST 2010
0016 //
0017 //
0018 
0019 // system include files
0020 #include <iostream>
0021 #include <memory>
0022 
0023 // user include files
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 // class declaration
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   // ----------member data ---------------------------
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 // constants, enums and typedefs
0067 //
0068 
0069 //
0070 // static data member definitions
0071 //
0072 
0073 //
0074 // constructors and destructor
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 // member functions
0087 //
0088 
0089 // ------------ method called to for each event  ------------
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 //define this as a plug-in
0114 DEFINE_FWK_MODULE(BTagPerformaceRootProducerFromSQLITE);