Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "FWCore/Framework/interface/MakerMacros.h"
0002 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0003 #include "FWCore/ServiceRegistry/interface/Service.h"
0004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0005 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0006 #include "CondCore/CondDB/interface/Exception.h"
0007 #include "CondFormats/Calibration/interface/Pedestals.h"
0008 
0009 #include <string>
0010 #include <cstdlib>
0011 #include <iostream>
0012 
0013 namespace edm {
0014   class ParameterSet;
0015   class Event;
0016   class EventSetup;
0017 }  // namespace edm
0018 
0019 // class decleration
0020 class Pedestals;
0021 class IOVPayloadEndOfJob : public edm::one::EDAnalyzer<> {
0022 public:
0023   explicit IOVPayloadEndOfJob(const edm::ParameterSet& iConfig);
0024   virtual ~IOVPayloadEndOfJob();
0025   virtual void analyze(const edm::Event& evt, const edm::EventSetup& evtSetup);
0026   virtual void endJob();
0027 
0028 private:
0029   std::string m_record;
0030 };
0031 
0032 IOVPayloadEndOfJob::IOVPayloadEndOfJob(const edm::ParameterSet& iConfig)
0033     : m_record(iConfig.getParameter<std::string>("record")) {
0034   std::cout << "IOVPayloadEndOfJob::IOVPayloadEndOfJob" << std::endl;
0035 }
0036 IOVPayloadEndOfJob::~IOVPayloadEndOfJob() { std::cout << "IOVPayloadEndOfJob::~IOVPayloadEndOfJob" << std::endl; }
0037 void IOVPayloadEndOfJob::analyze(const edm::Event& evt, const edm::EventSetup& evtSetup) {
0038   //
0039 }
0040 void IOVPayloadEndOfJob::endJob() {
0041   std::cout << "IOVPayloadEndOfJob::endJob " << std::endl;
0042   edm::Service<cond::service::PoolDBOutputService> mydbservice;
0043   if (!mydbservice.isAvailable()) {
0044     std::cout << "Service is unavailable" << std::endl;
0045     return;
0046   }
0047   try {
0048     std::string tag = mydbservice->tag(m_record);
0049     Pedestals myped;
0050     if (mydbservice->isNewTagRequest(m_record)) {
0051       for (int ichannel = 1; ichannel <= 5; ++ichannel) {
0052         Pedestals::Item item;
0053         item.m_mean = 1.11 * ichannel;
0054         item.m_variance = 1.12 * ichannel;
0055         myped.m_pedestals.push_back(item);
0056       }
0057       //create
0058       cond::Time_t firstSinceTime = mydbservice->beginOfTime();
0059       std::cout << "firstSinceTime is begin of time " << firstSinceTime << std::endl;
0060       mydbservice->createOneIOV(myped, firstSinceTime, m_record);
0061     } else {
0062       //append
0063       cond::Time_t current = mydbservice->currentTime();
0064       std::cout << "current time" << current << std::endl;
0065       if (current >= 5) {
0066         std::cout << "appending payload" << std::endl;
0067         for (int ichannel = 1; ichannel <= 5; ++ichannel) {
0068           Pedestals::Item item;
0069           item.m_mean = 0.15 * ichannel;
0070           item.m_variance = 0.32 * ichannel;
0071           myped.m_pedestals.push_back(item);
0072         }
0073         cond::Time_t thisPayload_valid_since = current;
0074         std::cout << "appending since time " << thisPayload_valid_since << std::endl;
0075         mydbservice->appendOneIOV(myped, thisPayload_valid_since, m_record);
0076         std::cout << "done" << std::endl;
0077       }
0078     }
0079   } catch (const cond::Exception& er) {
0080     throw cms::Exception("DataBaseUnitTestFailure", "failed IOVPayloadEndOfJob", er);
0081     //std::cout<<er.what()<<std::endl;
0082   } catch (const cms::Exception& er) {
0083     throw cms::Exception("DataBaseUnitTestFailure", "failed IOVPayloadEndOfJob", er);
0084   }
0085 }
0086 DEFINE_FWK_MODULE(IOVPayloadEndOfJob);