00001 // system include files 00002 #include <memory> 00003 00004 // user include files 00005 #include "FWCore/Framework/interface/Frameworkfwd.h" 00006 #include "FWCore/Framework/interface/EDAnalyzer.h" 00007 #include "FWCore/Framework/interface/Event.h" 00008 #include "FWCore/Framework/interface/MakerMacros.h" 00009 #include "FWCore/ParameterSet/interface/ParameterSet.h" 00010 00011 // Conditions database 00012 #include "FWCore/ServiceRegistry/interface/Service.h" 00013 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h" 00014 00015 #include "DBWriter.h" 00016 #include "CondFormats/RecoMuonObjects/interface/MuScleFitDBobject.h" 00017 00018 DBWriter::DBWriter(const edm::ParameterSet& ps) 00019 { 00020 // This string is one of: scale, resolution, background. 00021 std::string type( ps.getUntrackedParameter<std::string>("Type") ); 00022 // Create the corrector and set the parameters 00023 if( type == "scale" ) corrector_.reset(new MomentumScaleCorrector( ps.getUntrackedParameter<std::string>("CorrectionsIdentifier") ) ); 00024 else if( type == "resolution" ) corrector_.reset(new ResolutionFunction( ps.getUntrackedParameter<std::string>("CorrectionsIdentifier") ) ); 00025 else if( type == "background" ) corrector_.reset(new BackgroundFunction( ps.getUntrackedParameter<std::string>("CorrectionsIdentifier") ) ); 00026 else { 00027 std::cout << "Error: unrecognized type. Use one of those: 'scale', 'resolution', 'background'" << std::endl; 00028 exit(1); 00029 } 00030 } 00031 00032 DBWriter::~DBWriter() 00033 { 00034 // do anything here that needs to be done at desctruction time 00035 // (e.g. close files, deallocate resources etc.) 00036 } 00037 00038 // ------------ method called to for each event ------------ 00039 void 00040 DBWriter::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) 00041 { 00042 MuScleFitDBobject * dbObject = new MuScleFitDBobject; 00043 00044 dbObject->identifiers = corrector_->identifiers(); 00045 dbObject->parameters = corrector_->parameters(); 00046 00047 // if( dbObject->identifiers.size() != dbObject->parameters.size() ) { 00048 // std::cout << "Error: size of parameters("<<dbObject->parameters.size()<<") and identifiers("<<dbObject->identifiers.size()<<") don't match" << std::endl; 00049 // exit(1); 00050 // } 00051 00052 // std::vector<std::vector<double> >::const_iterator parVec = dbObject->parameters.begin(); 00053 // std::vector<int>::const_iterator id = dbObject->identifiers.begin(); 00054 // for( ; id != dbObject->identifiers.end(); ++id, ++parVec ) { 00055 // std::cout << "id = " << *id << std::endl; 00056 // std::vector<double>::const_iterator par = parVec->begin(); 00057 // int i=0; 00058 // for( ; par != parVec->end(); ++par, ++i ) { 00059 // std::cout << "par["<<i<<"] = " << *par << std::endl; 00060 // } 00061 // } 00062 00063 // Save the parameters to the db. 00064 edm::Service<cond::service::PoolDBOutputService> mydbservice; 00065 if( mydbservice.isAvailable() ){ 00066 if( mydbservice->isNewTagRequest("MuScleFitDBobjectRcd") ){ 00067 mydbservice->createNewIOV<MuScleFitDBobject>(dbObject,mydbservice->beginOfTime(),mydbservice->endOfTime(),"MuScleFitDBobjectRcd"); 00068 } else { 00069 mydbservice->appendSinceTime<MuScleFitDBobject>(dbObject,mydbservice->currentTime(),"MuScleFitDBobjectRcd"); 00070 } 00071 } else { 00072 edm::LogError("DBWriter")<<"Service is unavailable"<<std::endl; 00073 } 00074 00075 } 00076 00077 //define this as a plug-in 00078 DEFINE_FWK_MODULE(DBWriter);