Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:01:31

0001 #include "FWCore/Framework/interface/Event.h"
0002 #include "FWCore/Framework/interface/MakerMacros.h"
0003 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0004 #include "FWCore/ServiceRegistry/interface/Service.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0006 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0007 #include "CondFormats/Calibration/interface/Pedestals.h"
0008 
0009 #include <iostream>
0010 #include <string>
0011 
0012 namespace edm {
0013   class ParameterSet;
0014   class Event;
0015   class EventSetup;
0016 }  // namespace edm
0017 
0018 // class decleration
0019 class IOVPayloadAnalyzer : public edm::one::EDAnalyzer<> {
0020 public:
0021   explicit IOVPayloadAnalyzer(const edm::ParameterSet& iConfig);
0022   virtual ~IOVPayloadAnalyzer();
0023   virtual void analyze(const edm::Event& evt, const edm::EventSetup& evtSetup);
0024   virtual void endJob();
0025 
0026 private:
0027   std::string m_record;
0028 };
0029 
0030 IOVPayloadAnalyzer::IOVPayloadAnalyzer(const edm::ParameterSet& iConfig)
0031     : m_record(iConfig.getParameter<std::string>("record")) {
0032   std::cout << "IOVPayloadAnalyzer::IOVPayloadAnalyzer" << std::endl;
0033 }
0034 
0035 IOVPayloadAnalyzer::~IOVPayloadAnalyzer() { std::cout << "IOVPayloadAnalyzer::~IOVPayloadAnalyzer" << std::endl; }
0036 
0037 void IOVPayloadAnalyzer::analyze(const edm::Event& evt, const edm::EventSetup& evtSetup) {
0038   std::cout << "IOVPayloadAnalyzer::analyze " << std::endl;
0039   edm::Service<cond::service::PoolDBOutputService> mydbservice;
0040   if (!mydbservice.isAvailable()) {
0041     std::cout << "Service is unavailable" << std::endl;
0042     return;
0043   }
0044   unsigned int irun = evt.id().run();
0045   std::string tag = mydbservice->tag(m_record);
0046   std::cout << "tag " << tag << std::endl;
0047   std::cout << "run " << irun << std::endl;
0048   Pedestals myped;
0049   for (int ichannel = 1; ichannel <= 5; ++ichannel) {
0050     Pedestals::Item item;
0051     item.m_mean = 1.11 * ichannel + irun;
0052     item.m_variance = 1.12 * ichannel + irun;
0053     myped.m_pedestals.push_back(item);
0054   }
0055   std::cout << myped.m_pedestals[1].m_mean << std::endl;
0056 
0057   std::cout << "currentTime " << mydbservice->currentTime() << std::endl;
0058   if (mydbservice->isNewTagRequest(m_record)) {
0059     mydbservice->createOneIOV(myped, mydbservice->currentTime(), m_record);
0060   } else {
0061     mydbservice->appendOneIOV(myped, mydbservice->currentTime(), m_record);
0062   }
0063   mydbservice->startTransaction();
0064   auto iov = mydbservice->currentTime() + 100;
0065   auto hash = mydbservice->writeOneIOV(myped, iov, m_record);
0066   mydbservice->commitTransaction();
0067   cond::TagInfo_t tinfo;
0068   mydbservice->tagInfo(m_record, tinfo);
0069   if (tinfo.lastInterval.payloadId == hash && tinfo.lastInterval.since == iov) {
0070     std::cout << "Last IOV stored is the expected one..." << std::endl;
0071   } else {
0072     std::cout << "Last IOV hash = " << tinfo.lastInterval.payloadId << " (expected: " << hash
0073               << ") since = " << tinfo.lastInterval.since << " (expected: " << iov << ")" << std::endl;
0074   }
0075   mydbservice->eraseSinceTime(hash, iov, m_record);
0076 }
0077 
0078 void IOVPayloadAnalyzer::endJob() { std::cout << "End of job..." << std::endl; }
0079 
0080 DEFINE_FWK_MODULE(IOVPayloadAnalyzer);