Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:24:30

0001 #include <memory>
0002 #include <string>
0003 #include <fstream>
0004 #include <iostream>
0005 #include "FWCore/Framework/interface/Frameworkfwd.h"
0006 #include "FWCore/Framework/interface/global/EDAnalyzer.h"
0007 #include "FWCore/Framework/interface/Event.h"
0008 #include "FWCore/Framework/interface/MakerMacros.h"
0009 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0010 #include "FWCore/ServiceRegistry/interface/Service.h"
0011 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0012 #include "CondFormats/PhysicsToolsObjects/interface/PerformancePayloadFromTable.h"
0013 
0014 #include "CondFormats/PhysicsToolsObjects/interface/PerformanceWorkingPoint.h"
0015 
0016 class PhysicsPerformanceDBWriterFromFile_WPandPayload_IOV : public edm::global::EDAnalyzer<> {
0017 public:
0018   PhysicsPerformanceDBWriterFromFile_WPandPayload_IOV(const edm::ParameterSet&);
0019   void beginJob() override;
0020   void analyze(edm::StreamID, const edm::Event&, const edm::EventSetup&) const override {}
0021   void endJob() override {}
0022   ~PhysicsPerformanceDBWriterFromFile_WPandPayload_IOV() override {}
0023 
0024 private:
0025   std::string inputTxtFile;
0026   std::string rec1, rec2;
0027   unsigned long long iovBegin, iovEnd;
0028 };
0029 
0030 PhysicsPerformanceDBWriterFromFile_WPandPayload_IOV::PhysicsPerformanceDBWriterFromFile_WPandPayload_IOV(
0031     const edm::ParameterSet& p) {
0032   inputTxtFile = p.getUntrackedParameter<std::string>("inputTxtFile");
0033   rec1 = p.getUntrackedParameter<std::string>("RecordPayload");
0034   rec2 = p.getUntrackedParameter<std::string>("RecordWP");
0035   iovBegin = p.getParameter<unsigned long long>("IOVBegin");
0036   iovEnd = p.getParameter<unsigned long long>("IOVEnd");
0037 }
0038 
0039 void PhysicsPerformanceDBWriterFromFile_WPandPayload_IOV::beginJob() {
0040   //
0041   // read object from file
0042   //
0043 
0044   //
0045   // File Format is
0046   // - tagger name
0047   // - cut
0048   // - concrete class name
0049   // - how many results and how many binning
0050   // - their values
0051   // - vector<float>
0052   //
0053 
0054   std::ifstream in;
0055   in.open(inputTxtFile.c_str());
0056   std::string tagger;
0057   float cut;
0058 
0059   std::string concreteType;
0060   std::string comment;
0061   std::vector<float> pl;
0062   int stride;
0063 
0064   in >> tagger;
0065   edm::LogInfo("PhysicsPerformanceDBWriterFromFile_WPandPayload_IOV") << "WP Tagger is " << tagger;
0066 
0067   in >> cut;
0068   edm::LogInfo("PhysicsPerformanceDBWriterFromFile_WPandPayload_IOV") << "WP Cut is " << cut;
0069 
0070   in >> concreteType;
0071   edm::LogInfo("PhysicsPerformanceDBWriterFromFile_WPandPayload_IOV") << "concrete Type is " << concreteType;
0072 
0073   //  return ;
0074 
0075   // read # of results
0076 
0077   int nres, nbin;
0078   in >> nres;
0079   in >> nbin;
0080   edm::LogInfo("PhysicsPerformanceDBWriterFromFile_WPandPayload_IOV")
0081       << " Results: " << nres << " Binning variables: " << nbin;
0082 
0083   stride = nres + nbin * 2;
0084 
0085   int number = 0;
0086 
0087   std::vector<PerformanceResult::ResultType> res;
0088   std::vector<BinningVariables::BinningVariablesType> bin;
0089 
0090   while (number < nres && !in.eof()) {
0091     int tmp;
0092     in >> tmp;
0093     res.push_back((PerformanceResult::ResultType)(tmp));
0094     number++;
0095   }
0096   if (number != nres) {
0097     edm::LogInfo("PhysicsPerformanceDBWriterFromFile_WPandPayload_IOV") << " Table not well formed";
0098   }
0099   number = 0;
0100   while (number < nbin && !in.eof()) {
0101     int tmp;
0102     in >> tmp;
0103     bin.push_back((BinningVariables::BinningVariablesType)(tmp));
0104     number++;
0105   }
0106   if (number != nbin) {
0107     edm::LogInfo("PhysicsPerformanceDBWriterFromFile_WPandPayload_IOV") << " Table not well formed";
0108   }
0109 
0110   number = 0;
0111   while (!in.eof()) {
0112     float temp;
0113     in >> temp;
0114     edm::LogInfo("PhysicsPerformanceDBWriterFromFile_WPandPayload_IOV")
0115         << " Inserting " << temp << " in position " << number;
0116     number++;
0117     pl.push_back(temp);
0118   }
0119 
0120   //
0121   // CHECKS
0122   //
0123   if (stride != nbin * 2 + nres) {
0124     edm::LogInfo("PhysicsPerformanceDBWriterFromFile_WPandPayload_IOV") << " Table not well formed";
0125   }
0126   if (stride != 0 && (number % stride) != 0) {
0127     edm::LogInfo("PhysicsPerformanceDBWriterFromFile_WPandPayload_IOV") << " Table not well formed";
0128   }
0129 
0130   in.close();
0131 
0132   /*  for (int k=0;k<(number/stride); k++){
0133     for (int j=0; j<stride; j++){
0134       std::cout << "Pos["<<k<<","<<j<<"] = "<<pl[k*stride+j]<<std::endl;
0135     }
0136   }
0137   */
0138 
0139   //
0140   // now create pl etc etc
0141   //
0142 
0143   PerformanceWorkingPoint wp(cut, tagger);
0144 
0145   PerformancePayloadFromTable btagpl;
0146 
0147   if (concreteType == "PerformancePayloadFromTable") {
0148     btagpl = PerformancePayloadFromTable(res, bin, stride, pl);
0149   } else {
0150     edm::LogInfo("PhysicsPerformanceDBWriterFromFile_WPandPayload_IOV") << " Non existing request: " << concreteType;
0151   }
0152 
0153   edm::LogInfo("PhysicsPerformanceDBWriterFromFile_WPandPayload_IOV") << " Created the " << concreteType << " object";
0154 
0155   edm::Service<cond::service::PoolDBOutputService> s;
0156   if (s.isAvailable()) {
0157     s->writeOneIOV(btagpl, iovBegin, rec1);
0158     // write also the WP
0159 
0160     s->writeOneIOV(wp, iovBegin, rec2);
0161   }
0162 }
0163 
0164 DEFINE_FWK_MODULE(PhysicsPerformanceDBWriterFromFile_WPandPayload_IOV);