CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 {
20  // This string is one of: scale, resolution, background.
21  std::string type( ps.getUntrackedParameter<std::string>("Type") );
22  // Create the corrector and set the parameters
23  if( type == "scale" ) corrector_.reset(new MomentumScaleCorrector( ps.getUntrackedParameter<std::string>("CorrectionsIdentifier") ) );
24  else if( type == "resolution" ) corrector_.reset(new ResolutionFunction( ps.getUntrackedParameter<std::string>("CorrectionsIdentifier") ) );
25  else if( type == "background" ) corrector_.reset(new BackgroundFunction( ps.getUntrackedParameter<std::string>("CorrectionsIdentifier") ) );
26  else {
27  std::cout << "Error: unrecognized type. Use one of those: 'scale', 'resolution', 'background'" << std::endl;
28  exit(1);
29  }
30 }
31 
33 {
34  // do anything here that needs to be done at desctruction time
35  // (e.g. close files, deallocate resources etc.)
36 }
37 
38 // ------------ method called to for each event ------------
39 void
41 {
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>(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 
77 //define this as a plug-in
type
Definition: HCALResponse.h:22
T getUntrackedParameter(std::string const &, T const &) const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
~DBWriter()
Definition: DBWriter.cc:32
void appendSinceTime(T *payloadObj, cond::Time_t sinceTime, const std::string &recordName, bool withlogging=false)
int iEvent
Definition: GenABIO.cc:243
bool isNewTagRequest(const std::string &recordName)
std::vector< int > identifiers
bool isAvailable() const
Definition: Service.h:47
void createNewIOV(T *firstPayloadObj, cond::Time_t firstSinceTime, cond::Time_t firstTillTime, const std::string &recordName, bool withlogging=false)
virtual void analyze(const edm::Event &, const edm::EventSetup &)
Definition: DBWriter.cc:40
tuple cout
Definition: gather_cfg.py:121
std::auto_ptr< BaseFunction > corrector_
Definition: DBWriter.h:21
std::vector< double > parameters
DBWriter(const edm::ParameterSet &)
Definition: DBWriter.cc:18