Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-06 04:00:40

0001 
0002 #include <memory>
0003 #include <string>
0004 #include <fstream>
0005 #include <iostream>
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007 #include "FWCore/Framework/interface/Frameworkfwd.h"
0008 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0009 #include "FWCore/Framework/interface/Event.h"
0010 #include "FWCore/Framework/interface/MakerMacros.h"
0011 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0012 #include "FWCore/ServiceRegistry/interface/Service.h"
0013 #include "FWCore/Utilities/interface/EDMException.h"
0014 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0015 #include "CondFormats/JetMETObjects/interface/MEtXYcorrectParameters.h"
0016 
0017 namespace {
0018   class METCorrectorDBWriter : public edm::one::EDAnalyzer<> {
0019   public:
0020     METCorrectorDBWriter(const edm::ParameterSet&);
0021     void beginJob() override;
0022     void analyze(const edm::Event&, const edm::EventSetup&) override {}
0023     void endJob() override {}
0024     ~METCorrectorDBWriter() override {}
0025 
0026   private:
0027     std::string era;
0028     std::string algo;
0029     std::string path;
0030     std::string inputTxtFile;
0031     std::string payloadTag;
0032   };
0033 }  // namespace
0034 
0035 METCorrectorDBWriter::METCorrectorDBWriter(const edm::ParameterSet& pSet) {
0036   era = pSet.getUntrackedParameter<std::string>("era");
0037   algo = pSet.getUntrackedParameter<std::string>("algo");
0038   path = pSet.getUntrackedParameter<std::string>("path");
0039   payloadTag = algo;
0040 }
0041 
0042 void METCorrectorDBWriter::beginJob() {
0043   LogDebug("default") << "beginJob===========";
0044 
0045   MEtXYcorrectParametersCollection payload;
0046   std::cout << "Starting to import payload " << payloadTag << " from text files." << std::endl;
0047   for (int ilev(0); ilev < MEtXYcorrectParametersCollection::N_LEVELS; ++ilev) {
0048     std::string append("_");
0049     std::string levelName = payload.findLabel(static_cast<MEtXYcorrectParametersCollection::Level_t>(ilev));
0050     //std::string levelName = MEtXYcorrectParametersCollection::findLabel( static_cast<MEtXYcorrectParametersCollection::Level_t>(ilev) );
0051     append += levelName;
0052     append += "_";
0053     append += algo;
0054     append += ".txt";
0055     inputTxtFile = path + era + append;
0056     try {
0057       edm::FileInPath fip(inputTxtFile);
0058       std::cout << "Opened file " << inputTxtFile << std::endl;
0059       // Create the parameter object from file
0060       std::vector<std::string> sections;
0061       payload.getSections(fip.fullPath(), sections);
0062       //MEtXYcorrectParametersCollection::getSections(fip.fullPath(), sections );
0063       if (sections.empty()) {
0064         payload.push_back(ilev, MEtXYcorrectParameters(fip.fullPath(), ""));
0065       } else {
0066         for (std::vector<std::string>::const_iterator isectbegin = sections.begin(),
0067                                                       isectend = sections.end(),
0068                                                       isect = isectbegin;
0069              isect != isectend;
0070              ++isect) {
0071           payload.push_back(ilev, MEtXYcorrectParameters(fip.fullPath(), *isect), *isect);
0072           std::cout << "Added level " << levelName + "_" + *isect << " to record " << ilev << std::endl;
0073         }
0074       }
0075       std::cout << "Added record " << ilev << std::endl;
0076     } catch (edm::Exception const&) {
0077       std::cout << "Have not found METC file: " << inputTxtFile << std::endl;
0078     }
0079   }
0080 
0081   std::cout << "Opening PoolDBOutputService" << std::endl;
0082 
0083   edm::Service<cond::service::PoolDBOutputService> s;
0084   if (s.isAvailable()) {
0085     std::cout << "Setting up payload tag " << payloadTag << std::endl;
0086     s->writeOneIOV(payload, s->beginOfTime(), payloadTag);
0087   }
0088   std::cout << "Wrote in CondDB payload label: " << payloadTag << std::endl;
0089 }
0090 
0091 DEFINE_FWK_MODULE(METCorrectorDBWriter);