CMS 3D CMS Logo

DBWriter.cc
Go to the documentation of this file.
1 // system include files
2 #include <memory>
3 
4 // user include files
10 
11 // Conditions database
14 
15 #include "DBWriter.h"
17 
19  // This string is one of: scale, resolution, background.
21  // Create the corrector and set the parameters
22  if (type == "scale")
23  corrector_.reset(new MomentumScaleCorrector(ps.getUntrackedParameter<std::string>("CorrectionsIdentifier")));
24  else if (type == "resolution")
25  corrector_.reset(new ResolutionFunction(ps.getUntrackedParameter<std::string>("CorrectionsIdentifier")));
26  else if (type == "background")
27  corrector_.reset(new BackgroundFunction(ps.getUntrackedParameter<std::string>("CorrectionsIdentifier")));
28  else {
29  std::cout << "Error: unrecognized type. Use one of those: 'scale', 'resolution', 'background'" << std::endl;
30  exit(1);
31  }
32 }
33 
35  // do anything here that needs to be done at desctruction time
36  // (e.g. close files, deallocate resources etc.)
37 }
38 
39 // ------------ method called to for each event ------------
40 void DBWriter::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
41  MuScleFitDBobject* dbObject = new MuScleFitDBobject;
42 
43  dbObject->identifiers = corrector_->identifiers();
44  dbObject->parameters = corrector_->parameters();
45 
46  // if( dbObject->identifiers.size() != dbObject->parameters.size() ) {
47  // std::cout << "Error: size of parameters("<<dbObject->parameters.size()<<") and identifiers("<<dbObject->identifiers.size()<<") don't match" << std::endl;
48  // exit(1);
49  // }
50 
51  // std::vector<std::vector<double> >::const_iterator parVec = dbObject->parameters.begin();
52  // std::vector<int>::const_iterator id = dbObject->identifiers.begin();
53  // for( ; id != dbObject->identifiers.end(); ++id, ++parVec ) {
54  // std::cout << "id = " << *id << std::endl;
55  // std::vector<double>::const_iterator par = parVec->begin();
56  // int i=0;
57  // for( ; par != parVec->end(); ++par, ++i ) {
58  // std::cout << "par["<<i<<"] = " << *par << std::endl;
59  // }
60  // }
61 
62  // Save the parameters to the db.
64  if (mydbservice.isAvailable()) {
65  if (mydbservice->isNewTagRequest("MuScleFitDBobjectRcd")) {
66  mydbservice->createNewIOV<MuScleFitDBobject>(
67  dbObject, mydbservice->beginOfTime(), mydbservice->endOfTime(), "MuScleFitDBobjectRcd");
68  } else {
69  mydbservice->appendSinceTime<MuScleFitDBobject>(dbObject, mydbservice->currentTime(), "MuScleFitDBobjectRcd");
70  }
71  } else {
72  edm::LogError("DBWriter") << "Service is unavailable" << std::endl;
73  }
74 }
75 
76 //define this as a plug-in
MomentumScaleCorrector
Definition: MomentumScaleCorrector.h:25
DBWriter::DBWriter
DBWriter(const edm::ParameterSet &)
Definition: DBWriter.cc:18
cond::service::PoolDBOutputService::beginOfTime
cond::Time_t beginOfTime() const
Definition: PoolDBOutputService.cc:187
BackgroundFunction
Definition: BackgroundFunction.h:15
gather_cfg.cout
cout
Definition: gather_cfg.py:144
cond::service::PoolDBOutputService::appendSinceTime
void appendSinceTime(const T *payloadObj, cond::Time_t sinceTime, const std::string &recordName)
Definition: PoolDBOutputService.h:135
DBWriter::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: DBWriter.cc:40
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
EDAnalyzer.h
MuScleFitDBobject
Definition: MuScleFitDBobject.h:8
MuScleFitDBobject::identifiers
std::vector< int > identifiers
Definition: MuScleFitDBobject.h:9
edm::Service::isAvailable
bool isAvailable() const
Definition: Service.h:40
MakerMacros.h
DBWriter::~DBWriter
~DBWriter() override
Definition: DBWriter.cc:34
PoolDBOutputService.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
MuScleFitDBobject::parameters
std::vector< double > parameters
Definition: MuScleFitDBobject.h:10
MuScleFitDBobject.h
cond::service::PoolDBOutputService::createNewIOV
void createNewIOV(const T *firstPayloadObj, cond::Time_t firstSinceTime, cond::Time_t, const std::string &recordName)
Definition: PoolDBOutputService.h:110
Service.h
DBWriter::corrector_
std::unique_ptr< BaseFunction > corrector_
Definition: DBWriter.h:20
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ParameterSet
Definition: ParameterSet.h:36
edm::LogError
Definition: MessageLogger.h:183
Event.h
ResolutionFunction
Definition: ResolutionFunction.h:15
DBWriter.h
edm::Service< cond::service::PoolDBOutputService >
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::EventSetup
Definition: EventSetup.h:57
cond::service::PoolDBOutputService::endOfTime
cond::Time_t endOfTime() const
Definition: PoolDBOutputService.cc:185
type
type
Definition: HCALResponse.h:21
Frameworkfwd.h
cond::service::PoolDBOutputService::isNewTagRequest
bool isNewTagRequest(const std::string &recordName)
Definition: PoolDBOutputService.cc:100
beamvalidation.exit
def exit(msg="")
Definition: beamvalidation.py:53
ParameterSet.h
edm::Event
Definition: Event.h:73
cond::service::PoolDBOutputService::currentTime
cond::Time_t currentTime() const
Definition: PoolDBOutputService.cc:189
DBWriter
Definition: DBWriter.h:13