Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-17 23:35:51

0001 #ifndef CalibMuonDTCalibDBUtils_H
0002 #define CalibMuonDTCalibDBUtils_H
0003 
0004 /** \class DTCalibDBUtils
0005  *  Simple interface to PoolDBOutputService to write objects to DB.
0006  *
0007  *  \author G. Cerminara - INFN Torino
0008  */
0009 
0010 #include <iostream>
0011 #include <string>
0012 #include "FWCore/ServiceRegistry/interface/Service.h"
0013 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0014 
0015 class DTCalibDBUtils {
0016 public:
0017   /// Constructor
0018   DTCalibDBUtils();
0019 
0020   /// Destructor
0021   virtual ~DTCalibDBUtils();
0022 
0023   // Operations
0024 
0025   /// Write the payload to the DB using PoolDBOutputService.
0026   /// New payload are created in the DB, existing payload are appended.
0027   template <typename T>
0028   static void writeToDB(std::string record, const T& payload) {
0029     // Write the ttrig object to DB
0030     edm::Service<cond::service::PoolDBOutputService> dbOutputSvc;
0031     if (dbOutputSvc.isAvailable()) {
0032       try {
0033         if (dbOutputSvc->isNewTagRequest(record)) {
0034           //create mode
0035           dbOutputSvc->writeOneIOV<T>(payload, dbOutputSvc->beginOfTime(), record);
0036         } else {
0037           //append mode. Note: correct PoolDBESSource must be loaded
0038           dbOutputSvc->writeOneIOV<T>(payload, dbOutputSvc->currentTime(), record);
0039         }
0040       } catch (const cond::Exception& er) {
0041         std::cout << er.what() << std::endl;
0042       } catch (const std::exception& er) {
0043         std::cout << "[DTCalibDBUtils] caught std::exception " << er.what() << std::endl;
0044       } catch (...) {
0045         std::cout << "[DTCalibDBUtils] Funny error" << std::endl;
0046       }
0047     } else {
0048       std::cout << "Service PoolDBOutputService is unavailable" << std::endl;
0049     }
0050   }
0051 
0052 protected:
0053 private:
0054 };
0055 #endif