Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:02:25

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/one/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::one::EDAnalyzer<edm::one::SharedResources> {
0017 public:
0018   /// Constructor
0019   MagFieldConfigDBWriter(const edm::ParameterSet& pset);
0020 
0021   /// Destructor
0022   ~MagFieldConfigDBWriter() override;
0023 
0024   void analyze(const edm::Event& event, const edm::EventSetup& setup) override {}
0025 
0026   void endJob() override;
0027 
0028 private:
0029   MagFieldConfig* conf;
0030 };
0031 
0032 MagFieldConfigDBWriter::MagFieldConfigDBWriter(const edm::ParameterSet& pset) {
0033   usesResource("PoolDBOutputService");
0034   conf = new MagFieldConfig(pset, false);
0035 }
0036 
0037 MagFieldConfigDBWriter::~MagFieldConfigDBWriter() { delete conf; }
0038 
0039 void MagFieldConfigDBWriter::endJob() {
0040   std::string record = "MagFieldConfigRcd";
0041   // Write the ttrig object to DB
0042   edm::Service<cond::service::PoolDBOutputService> dbOutputSvc;
0043   if (dbOutputSvc.isAvailable()) {
0044     try {
0045       if (dbOutputSvc->isNewTagRequest(record)) {
0046         //create mode
0047         dbOutputSvc->writeOneIOV<MagFieldConfig>(*conf, dbOutputSvc->beginOfTime(), record);
0048       } else {
0049         //append mode. Note: correct PoolDBESSource must be loaded
0050         dbOutputSvc->writeOneIOV<MagFieldConfig>(*conf, dbOutputSvc->currentTime(), record);
0051       }
0052     } catch (const cond::Exception& er) {
0053       std::cout << er.what() << std::endl;
0054     } catch (const std::exception& er) {
0055       std::cout << "[MagFieldConfigDBWriter] caught std::exception " << er.what() << std::endl;
0056     } catch (...) {
0057       std::cout << "[MagFieldConfigDBWriter] Unexpected exception" << std::endl;
0058     }
0059   } else {
0060     std::cout << "Service PoolDBOutputService is unavailable" << std::endl;
0061   }
0062 }
0063 
0064 #include "FWCore/Framework/interface/MakerMacros.h"
0065 DEFINE_FWK_MODULE(MagFieldConfigDBWriter);