CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/RecoBTag/PerformanceDB/plugins/PhysicsPerformanceDBWriterFromFile_WPandPayload.cc

Go to the documentation of this file.
00001 #include <memory>
00002 #include <string>
00003 #include <fstream>
00004 #include <iostream>
00005 #include "FWCore/Framework/interface/Frameworkfwd.h"
00006 #include "FWCore/Framework/interface/EDAnalyzer.h"
00007 #include "FWCore/Framework/interface/Event.h"
00008 #include "FWCore/Framework/interface/MakerMacros.h"
00009 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00010 #include "FWCore/ServiceRegistry/interface/Service.h"
00011 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
00012 #include "CondFormats/PhysicsToolsObjects/interface/PerformancePayloadFromTable.h"
00013 
00014 #include "CondFormats/PhysicsToolsObjects/interface/PerformanceWorkingPoint.h"
00015 
00016 
00017 class PhysicsPerformanceDBWriterFromFile_WPandPayload : public edm::EDAnalyzer
00018 {
00019 public:
00020   PhysicsPerformanceDBWriterFromFile_WPandPayload(const edm::ParameterSet&);
00021   virtual void beginJob();
00022   virtual void analyze(const edm::Event&, const edm::EventSetup&) {}
00023   virtual void endJob() {}
00024   ~PhysicsPerformanceDBWriterFromFile_WPandPayload() {}
00025 
00026 private:
00027   std::string inputTxtFile;
00028   std::string rec1,rec2;
00029 };
00030 
00031 PhysicsPerformanceDBWriterFromFile_WPandPayload::PhysicsPerformanceDBWriterFromFile_WPandPayload
00032   (const edm::ParameterSet& p)
00033 {
00034   inputTxtFile = p.getUntrackedParameter<std::string>("inputTxtFile");
00035   rec1 = p.getUntrackedParameter<std::string>("RecordPayload");
00036   rec2 = p.getUntrackedParameter<std::string>("RecordWP");
00037 }
00038 
00039 void PhysicsPerformanceDBWriterFromFile_WPandPayload::beginJob()
00040 {
00041   //
00042   // read object from file
00043   //
00044 
00045   //
00046   // File Format is
00047   // - tagger name
00048   // - cut
00049   // - concrete class name
00050   // - how many results and how many binning
00051   // - their values
00052   // - vector<float>
00053   //
00054 
00055   std::ifstream in;
00056   std::cout << "Opening "<< inputTxtFile<<std::endl;
00057   in.open(inputTxtFile.c_str());
00058   std::string tagger;
00059   float cut;
00060  
00061   std::string concreteType;
00062   std::string comment;
00063   std::vector<float> pl;
00064   int stride;
00065 
00066   in >> tagger;
00067   std::cout << "WP Tagger is "<<tagger<<std::endl;
00068   
00069   in >> cut;
00070   std::cout << "WP Cut is "<<cut<<std::endl;
00071 
00072   in >> concreteType;
00073   std::cout << "concrete Type is "<<concreteType<<std::endl;
00074 
00075   //  return ;
00076 
00077   // read # of results
00078 
00079   int nres, nbin;
00080   in >> nres;
00081   in >> nbin;
00082   std::cout <<" Results: " << nres<<" Binning variables: "<<nbin<<std::endl;
00083 
00084   stride = nres+nbin*2;
00085   
00086   int number=0;
00087   
00088   std::vector<PerformanceResult::ResultType> res;
00089   std::vector<BinningVariables::BinningVariablesType> bin;
00090 
00091   while (number<nres && !in.eof()) {
00092     int tmp;
00093     in>> tmp;
00094     res.push_back((PerformanceResult::ResultType)(tmp));
00095     number++;
00096   }
00097   if (number != nres){
00098     std::cout <<" Table not well formed"<<std::endl;
00099   }
00100   number=0;
00101   while (number<nbin && !in.eof()) {
00102     int tmp;
00103     in>> tmp;
00104     bin.push_back((BinningVariables::BinningVariablesType)(tmp));
00105     number++;
00106   }
00107   if (number != nbin){
00108     std::cout <<" Table not well formed"<<std::endl;
00109   }
00110 
00111   number=0;
00112   while (!in.eof()){
00113     float temp;
00114     in >> temp;
00115     std::cout <<" Intersing "<<temp<< " in position "<<number<<std::endl;
00116     number++;
00117     pl.push_back(temp);
00118   }
00119 
00120   //
00121   // CHECKS
00122   //
00123   if (stride != nbin*2+nres){
00124     std::cout <<" Table not well formed"<<std::endl;
00125   }
00126   if (stride == 0)
00127     throw cms::Exception("Table not well formed") << std::endl;
00128 
00129   if ((number % stride) != 0){
00130     std::cout <<" Table not well formed"<<std::endl;
00131   }
00132 
00133   std::cout <<" CLOSING "<<std::endl;
00134   in.close();
00135 
00136 
00137   /*  for (int k=0;k<(number/stride); k++){
00138     for (int j=0; j<stride; j++){
00139       std::cout << "Pos["<<k<<","<<j<<"] = "<<pl[k*stride+j]<<std::endl;
00140     }
00141   }
00142   */
00143 
00144   //
00145   // now create pl etc etc
00146   //
00147 
00148   PerformanceWorkingPoint * wp = new PerformanceWorkingPoint(cut, tagger);
00149 
00150   PerformancePayloadFromTable * btagpl = 0;
00151 
00152   if (concreteType == "PerformancePayloadFromTable"){
00153     btagpl = new PerformancePayloadFromTable(res, bin, stride, pl);
00154   }else{
00155     std::cout <<" Non existing request: " <<concreteType<<std::endl;
00156   }
00157   
00158   std::cout <<" Created the "<<concreteType <<" object"<<std::endl;
00159   
00160   edm::Service<cond::service::PoolDBOutputService> s;
00161   if (s.isAvailable())
00162     {
00163       if (s->isNewTagRequest(rec1))
00164         {
00165           s->createNewIOV<PerformancePayload>(btagpl,
00166                                                   s->beginOfTime(),
00167                                                   s->endOfTime(),
00168                                                   rec1);
00169         }
00170       else
00171         {
00172           
00173           s->appendSinceTime<PerformancePayload>(btagpl,
00174                                                      // JUST A STUPID PATCH
00175                                                      111,
00176                                                      rec1);
00177         }
00178     }
00179 
00180   // write also the WP
00181   
00182   if (s.isAvailable())
00183     {
00184       if (s->isNewTagRequest(rec2))
00185         {
00186           s->createNewIOV<PerformanceWorkingPoint>(wp,
00187                                             s->beginOfTime(),
00188                                             s->endOfTime(),
00189                                             rec2);
00190         }
00191       else
00192         {
00193           
00194           s->appendSinceTime<PerformanceWorkingPoint>(wp,
00196                                                111,
00197                                                rec2);
00198         }
00199     }
00200   
00201   
00202   
00203 }
00204 
00205 DEFINE_FWK_MODULE(PhysicsPerformanceDBWriterFromFile_WPandPayload);