Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-13 13:13:47

0001 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0002 #include "FWCore/Framework/interface/Event.h"
0003 #include "FWCore/Framework/interface/MakerMacros.h"
0004 #include "FWCore/ServiceRegistry/interface/Service.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0006 #include "FWCore/Framework/interface/Event.h"
0007 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0008 #include "CondCore/CondDB/interface/Exception.h"
0009 #include "CondFormats/Calibration/interface/Pedestals.h"
0010 
0011 #include <string>
0012 #include <cstdlib>
0013 #include <iostream>
0014 
0015 namespace edm {
0016   class ParameterSet;
0017   class Event;
0018   class EventSetup;
0019 }  // namespace edm
0020 
0021 // class decleration
0022 class MyDataAnalyzer : public edm::one::EDAnalyzer<> {
0023 public:
0024   explicit MyDataAnalyzer(const edm::ParameterSet& iConfig);
0025   virtual ~MyDataAnalyzer();
0026   virtual void analyze(const edm::Event& evt, const edm::EventSetup& evtSetup);
0027   virtual void beginJob();
0028   virtual void endJob();
0029 
0030 private:
0031   std::string m_record;
0032   bool m_LoggingOn;
0033 };
0034 
0035 MyDataAnalyzer::MyDataAnalyzer(const edm::ParameterSet& iConfig)
0036     : m_record(iConfig.getParameter<std::string>("record")), m_LoggingOn(false) {
0037   m_LoggingOn = iConfig.getUntrackedParameter<bool>("loggingOn");
0038   std::cout << "MyDataAnalyzer::MyDataAnalyzer" << std::endl;
0039 }
0040 
0041 MyDataAnalyzer::~MyDataAnalyzer() { std::cout << "MyDataAnalyzer::~MyDataAnalyzer" << std::endl; }
0042 
0043 void MyDataAnalyzer::beginJob() {
0044   edm::Service<cond::service::PoolDBOutputService> mydbservice;
0045   if (!mydbservice.isAvailable()) {
0046     return;
0047   }
0048   mydbservice->logger().start();
0049   ;
0050 }
0051 
0052 void MyDataAnalyzer::analyze(const edm::Event& evt, const edm::EventSetup& evtSetup) {
0053   std::cout << "MyDataAnalyzer::analyze " << std::endl;
0054   edm::Service<cond::service::PoolDBOutputService> mydbservice;
0055   if (!mydbservice.isAvailable()) {
0056     std::cout << "Service is unavailable" << std::endl;
0057     return;
0058   }
0059   try {
0060     std::string tag = mydbservice->tag(m_record);
0061     Pedestals myped;
0062     for (int ichannel = 1; ichannel <= 5; ++ichannel) {
0063       Pedestals::Item item;
0064       item.m_mean = 1.11 * ichannel;
0065       item.m_variance = 1.12 * ichannel;
0066       myped.m_pedestals.push_back(item);
0067     }
0068     auto t = mydbservice->currentTime();
0069     mydbservice->logger().logDebug() << "Writing new payload";
0070     mydbservice->writeOneIOV(myped, t, m_record);
0071     mydbservice->logger().logDebug() << "Written iov with since: " << t;
0072     std::cout << "done" << std::endl;
0073   } catch (const cond::Exception& er) {
0074     throw cms::Exception("DBOutputServiceUnitTestFailure", "failed MyDataAnalyzer", er);
0075   } catch (const cms::Exception& er) {
0076     throw cms::Exception("DBOutputServiceUnitTestFailure", "failed MyDataAnalyzer", er);
0077   }
0078 }
0079 
0080 void MyDataAnalyzer::endJob() {
0081   std::cout << "MyDataAnalyzer::endJob " << std::endl;
0082   edm::Service<cond::service::PoolDBOutputService> mydbservice;
0083   if (!mydbservice.isAvailable()) {
0084     std::cout << "Service is unavailable" << std::endl;
0085     return;
0086   }
0087   mydbservice->logger().end(0);
0088   mydbservice->logger().saveOnFile();
0089 }
0090 
0091 DEFINE_FWK_MODULE(MyDataAnalyzer);