CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DBWriter.cc
Go to the documentation of this file.
1 // system include files
2 #include <memory>
3 #include <string>
4 
5 // user include files
17 
18 class DBWriter : public edm::one::EDAnalyzer<> {
19 public:
20  explicit DBWriter(const edm::ParameterSet&);
21  ~DBWriter() override = default;
22 
23 private:
24  void analyze(const edm::Event&, const edm::EventSetup&) override;
25  std::unique_ptr<BaseFunction> corrector_;
26 };
27 
29  // This string is one of: scale, resolution, background.
31  // Create the corrector and set the parameters
32  if (type == "scale")
33  corrector_ =
34  std::make_unique<MomentumScaleCorrector>(ps.getUntrackedParameter<std::string>("CorrectionsIdentifier"));
35  else if (type == "resolution")
36  corrector_ = std::make_unique<ResolutionFunction>(ps.getUntrackedParameter<std::string>("CorrectionsIdentifier"));
37  else if (type == "background")
38  corrector_ = std::make_unique<BackgroundFunction>(ps.getUntrackedParameter<std::string>("CorrectionsIdentifier"));
39  else {
40  edm::LogPrint("DBWriter") << "Error: unrecognized type. Use one of those: 'scale', 'resolution', 'background'"
41  << std::endl;
42  exit(1);
43  }
44 }
45 
46 // ------------ method called to for each event ------------
47 void DBWriter::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
48  MuScleFitDBobject dbObject;
49 
50  dbObject.identifiers = corrector_->identifiers();
51  dbObject.parameters = corrector_->parameters();
52 
53  // if( dbObject->identifiers.size() != dbObject->parameters.size() ) {
54  // edm::LogPrint("DBWriter") << "Error: size of parameters("<<dbObject->parameters.size()<<") and identifiers("<<dbObject->identifiers.size()<<") don't match" << std::endl;
55  // exit(1);
56  // }
57 
58  // std::vector<std::vector<double> >::const_iterator parVec = dbObject->parameters.begin();
59  // std::vector<int>::const_iterator id = dbObject->identifiers.begin();
60  // for( ; id != dbObject->identifiers.end(); ++id, ++parVec ) {
61  // edm::LogPrint("DBWriter") << "id = " << *id << std::endl;
62  // std::vector<double>::const_iterator par = parVec->begin();
63  // int i=0;
64  // for( ; par != parVec->end(); ++par, ++i ) {
65  // edm::LogPrint("DBWriter") << "par["<<i<<"] = " << *par << std::endl;
66  // }
67  // }
68 
69  // Save the parameters to the db.
71  if (mydbservice.isAvailable()) {
72  if (mydbservice->isNewTagRequest("MuScleFitDBobjectRcd")) {
73  mydbservice->createOneIOV<MuScleFitDBobject>(dbObject, mydbservice->beginOfTime(), "MuScleFitDBobjectRcd");
74  } else {
75  mydbservice->appendOneIOV<MuScleFitDBobject>(dbObject, mydbservice->currentTime(), "MuScleFitDBobjectRcd");
76  }
77  } else {
78  edm::LogError("DBWriter") << "Service is unavailable" << std::endl;
79  }
80 }
81 
82 //define this as a plug-in
T getUntrackedParameter(std::string const &, T const &) const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Log< level::Error, false > LogError
void createOneIOV(const T &payload, cond::Time_t firstSinceTime, const std::string &recordName)
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: DBWriter.cc:47
void appendOneIOV(const T &payload, cond::Time_t sinceTime, const std::string &recordName)
int iEvent
Definition: GenABIO.cc:224
bool isNewTagRequest(const std::string &recordName)
std::vector< int > identifiers
bool isAvailable() const
Definition: Service.h:40
Log< level::Warning, true > LogPrint
std::unique_ptr< BaseFunction > corrector_
Definition: DBWriter.cc:25
~DBWriter() override=default
std::vector< double > parameters
DBWriter(const edm::ParameterSet &)
Definition: DBWriter.cc:28