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_ =
24  std::make_unique<MomentumScaleCorrector>(ps.getUntrackedParameter<std::string>("CorrectionsIdentifier"));
25  else if (type == "resolution")
26  corrector_ = std::make_unique<ResolutionFunction>(ps.getUntrackedParameter<std::string>("CorrectionsIdentifier"));
27  else if (type == "background")
28  corrector_ = std::make_unique<BackgroundFunction>(ps.getUntrackedParameter<std::string>("CorrectionsIdentifier"));
29  else {
30  std::cout << "Error: unrecognized type. Use one of those: 'scale', 'resolution', 'background'" << std::endl;
31  exit(1);
32  }
33 }
34 
36  // do anything here that needs to be done at desctruction time
37  // (e.g. close files, deallocate resources etc.)
38 }
39 
40 // ------------ method called to for each event ------------
41 void DBWriter::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
42  MuScleFitDBobject* dbObject = new MuScleFitDBobject;
43 
44  dbObject->identifiers = corrector_->identifiers();
45  dbObject->parameters = corrector_->parameters();
46 
47  // if( dbObject->identifiers.size() != dbObject->parameters.size() ) {
48  // std::cout << "Error: size of parameters("<<dbObject->parameters.size()<<") and identifiers("<<dbObject->identifiers.size()<<") don't match" << std::endl;
49  // exit(1);
50  // }
51 
52  // std::vector<std::vector<double> >::const_iterator parVec = dbObject->parameters.begin();
53  // std::vector<int>::const_iterator id = dbObject->identifiers.begin();
54  // for( ; id != dbObject->identifiers.end(); ++id, ++parVec ) {
55  // std::cout << "id = " << *id << std::endl;
56  // std::vector<double>::const_iterator par = parVec->begin();
57  // int i=0;
58  // for( ; par != parVec->end(); ++par, ++i ) {
59  // std::cout << "par["<<i<<"] = " << *par << std::endl;
60  // }
61  // }
62 
63  // Save the parameters to the db.
65  if (mydbservice.isAvailable()) {
66  if (mydbservice->isNewTagRequest("MuScleFitDBobjectRcd")) {
67  mydbservice->createNewIOV<MuScleFitDBobject>(
68  dbObject, mydbservice->beginOfTime(), mydbservice->endOfTime(), "MuScleFitDBobjectRcd");
69  } else {
70  mydbservice->appendSinceTime<MuScleFitDBobject>(dbObject, mydbservice->currentTime(), "MuScleFitDBobjectRcd");
71  }
72  } else {
73  edm::LogError("DBWriter") << "Service is unavailable" << std::endl;
74  }
75 }
76 
77 //define this as a plug-in
DBWriter::DBWriter
DBWriter(const edm::ParameterSet &)
Definition: DBWriter.cc:18
cond::service::PoolDBOutputService::beginOfTime
cond::Time_t beginOfTime() const
Definition: PoolDBOutputService.cc:215
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:141
DBWriter::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: DBWriter.cc:41
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:35
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:116
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:47
Event.h
DBWriter.h
type
type
Definition: SiPixelVCal_PayloadInspector.cc:37
gainCalibHelper::gainCalibPI::type
type
Definition: SiPixelGainCalibHelper.h:40
edm::Service< cond::service::PoolDBOutputService >
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::EventSetup
Definition: EventSetup.h:58
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
cond::service::PoolDBOutputService::endOfTime
cond::Time_t endOfTime() const
Definition: PoolDBOutputService.cc:213
Frameworkfwd.h
cond::service::PoolDBOutputService::isNewTagRequest
bool isNewTagRequest(const std::string &recordName)
Definition: PoolDBOutputService.cc:128
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:217
DBWriter
Definition: DBWriter.h:13