Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-10-11 04:33:38

0001 /** \class MagFieldConfigDBWriter
0002  *
0003  *  Write the MF configuration object created from pset to a DB
0004  *
0005  *  \author N. Amapane - Torino
0006  */
0007 
0008 #include "FWCore/Framework/interface/Frameworkfwd.h"
0009 #include "FWCore/Framework/interface/EDAnalyzer.h"
0010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0011 #include "FWCore/Framework/interface/EventSetup.h"
0012 #include "FWCore/ServiceRegistry/interface/Service.h"
0013 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0014 #include "CondFormats/MFObjects/interface/MagFieldConfig.h"
0015 
0016 class MagFieldConfigDBWriter : public edm::EDAnalyzer {
0017 public:
0018   /// Constructor
0019   MagFieldConfigDBWriter(const edm::ParameterSet& pset);
0020 
0021   /// Destructor
0022   ~MagFieldConfigDBWriter();
0023 
0024   virtual void beginRun(const edm::Run& run, const edm::EventSetup& setup){};
0025 
0026   virtual void analyze(const edm::Event& event, const edm::EventSetup& setup) {}
0027 
0028   virtual void endJob();
0029 
0030 private:
0031   MagFieldConfig* conf;
0032 };
0033 
0034 MagFieldConfigDBWriter::MagFieldConfigDBWriter(const edm::ParameterSet& pset) {
0035   conf = new MagFieldConfig(pset, false);
0036 }
0037 
0038 MagFieldConfigDBWriter::~MagFieldConfigDBWriter() { delete conf; }
0039 
0040 void MagFieldConfigDBWriter::endJob() {
0041   std::string record = "MagFieldConfigRcd";
0042   // Write the ttrig object to DB
0043   edm::Service<cond::service::PoolDBOutputService> dbOutputSvc;
0044   if (dbOutputSvc.isAvailable()) {
0045     try {
0046       if (dbOutputSvc->isNewTagRequest(record)) {
0047         //create mode
0048         dbOutputSvc->writeOneIOV<MagFieldConfig>(*conf, dbOutputSvc->beginOfTime(), record);
0049       } else {
0050         //append mode. Note: correct PoolDBESSource must be loaded
0051         dbOutputSvc->writeOneIOV<MagFieldConfig>(*conf, dbOutputSvc->currentTime(), record);
0052       }
0053     } catch (const cond::Exception& er) {
0054       std::cout << er.what() << std::endl;
0055     } catch (const std::exception& er) {
0056       std::cout << "[MagFieldConfigDBWriter] caught std::exception " << er.what() << std::endl;
0057     } catch (...) {
0058       std::cout << "[MagFieldConfigDBWriter] Unexpected exception" << std::endl;
0059     }
0060   } else {
0061     std::cout << "Service PoolDBOutputService is unavailable" << std::endl;
0062   }
0063 }
0064 
0065 #include "FWCore/Framework/interface/MakerMacros.h"
0066 DEFINE_FWK_MODULE(MagFieldConfigDBWriter);