CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
JetCorrectorDBWriter.cc
Go to the documentation of this file.
1 // Author: Benedikt Hegner
2 // Email: benedikt.hegner@cern.ch
3 
4 #include <memory>
5 #include <string>
6 #include <fstream>
7 #include <iostream>
17 
19 {
20  public:
22  virtual void beginJob() override;
23  virtual void analyze(const edm::Event&, const edm::EventSetup&) override {}
24  virtual void endJob() override {}
26 
27  private:
33 };
34 
35 // Constructor
37 {
38  era = pSet.getUntrackedParameter<std::string>("era");
39  algo = pSet.getUntrackedParameter<std::string>("algo");
40  path = pSet.getUntrackedParameter<std::string>("path");
41  //payloadTag = "JetCorrectorParametersCollection_"+era+"_"+algo;
42  payloadTag = algo;
43 }
44 
45 // Begin Job
47 {
48 // std::string path("CondFormats/JetMETObjects/data/");
49 
51  std::cout << "Starting to import payload " << payloadTag << " from text files." << std::endl;
52  for ( int i = 0; i < JetCorrectorParametersCollection::N_LEVELS; ++i ) {
53 
54  std::string append("_");
55  std::string ilev = JetCorrectorParametersCollection::findLabel( static_cast<JetCorrectorParametersCollection::Level_t>(i) );
56  append += ilev;
57  append += "_";
58  append += algo;
59  append += ".txt";
61  try {
63  std::cout << "Opened file " << inputTxtFile << std::endl;
64  // create the parameter object from file
65  std::vector<std::string> sections;
67  if ( sections.size() == 0 ) {
68  payload->push_back( i, JetCorrectorParameters(fip.fullPath(),"") );
69  }
70  else {
71  for ( std::vector<std::string>::const_iterator isectbegin = sections.begin(), isectend = sections.end(), isect = isectbegin;
72  isect != isectend; ++isect ) {
73  payload->push_back( i, JetCorrectorParameters(fip.fullPath(),*isect), ilev + "_" + *isect );
74  std::cout << "Added " << ilev + "_" + *isect << " to record " << i << std::endl;
75  }
76  }
77  std::cout << "Added record " << i << std::endl;
78  }
79  catch(edm::Exception ex) {
80  std::cout << "Did not find JEC file " << inputTxtFile << std::endl;
81  }
82 
83  }
84 
85  std::cout << "Opening PoolDBOutputService" << std::endl;
86 
87  // now write it into the DB
89  if (s.isAvailable())
90  {
91  std::cout << "Setting up payload tag " << payloadTag << std::endl;
92  if (s->isNewTagRequest(payloadTag))
94  else
96  }
97  std::cout << "Wrote in CondDB payload label: " << payloadTag << std::endl;
98 }
99 
100 
102 
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
virtual void endJob() override
JetCorrectorDBWriter(const edm::ParameterSet &)
virtual void analyze(const edm::Event &, const edm::EventSetup &) override
static std::string findLabel(key_type k)
void push_back(key_type i, value_type const &j, label_type const &flav="")
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void appendSinceTime(T *payloadObj, cond::Time_t sinceTime, const std::string &recordName, bool withlogging=false)
bool isNewTagRequest(const std::string &recordName)
bool isAvailable() const
Definition: Service.h:46
void createNewIOV(T *firstPayloadObj, cond::Time_t firstSinceTime, cond::Time_t firstTillTime, const std::string &recordName, bool withlogging=false)
static void getSections(std::string inputFile, std::vector< std::string > &outputs)
tuple cout
Definition: gather_cfg.py:121
std::string fullPath() const
Definition: FileInPath.cc:165
virtual void beginJob() override