Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-14 11:44:45

0001 #include <stdexcept>
0002 #include <string>
0003 #include <iostream>
0004 #include <vector>
0005 #include <cstdlib>
0006 #include <sstream>
0007 
0008 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0009 #include "FWCore/Framework/interface/Event.h"
0010 #include "FWCore/Framework/interface/EventSetup.h"
0011 
0012 typedef std::vector<int> Payload;
0013 
0014 #include "FWCore/Framework/interface/EventSetupRecordImplementation.h"
0015 class OneIntRcd : public edm::eventsetup::EventSetupRecordImplementation<OneIntRcd> {};
0016 
0017 #include "FWCore/Framework/interface/eventsetuprecord_registration_macro.h"
0018 EVENTSETUP_RECORD_REG(OneIntRcd);
0019 
0020 #include "FWCore/Framework/interface/MakerMacros.h"
0021 
0022 namespace condtest {
0023 
0024   class TestUpdater : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
0025   public:
0026     explicit TestUpdater(edm::ParameterSet const&);
0027     virtual void analyze(const edm::Event& e, const edm::EventSetup& c) override;
0028     virtual void beginRun(const edm::Run&, const edm::EventSetup&) override;
0029     virtual void endRun(const edm::Run&, const edm::EventSetup&) override;
0030 
0031     static void update(int run);
0032 
0033     int evCount;
0034 
0035   private:
0036     const edm::ESGetToken<std::vector<int>, OneIntRcd> theIntToken_;
0037   };
0038 
0039   TestUpdater::TestUpdater(edm::ParameterSet const&) : evCount(0), theIntToken_(esConsumes()) {}
0040 
0041   void TestUpdater::beginRun(const edm::Run&, const edm::EventSetup&) { evCount = 0; }
0042 
0043   void TestUpdater::endRun(const edm::Run&, const edm::EventSetup&) {}
0044 
0045   void TestUpdater::analyze(const edm::Event& e, const edm::EventSetup& c) {
0046     ++evCount;
0047 
0048     if (0 == e.id().run() % 2 && evCount == 3)
0049       update(e.id().run() + 1);
0050 
0051     size_t number = (c.getData(theIntToken_)).front();
0052     if (1 == e.id().run() % 2 && number != e.id().run())
0053       edm::LogPrint("TestUpdater") << "it was not updated!";
0054   }
0055 
0056   void TestUpdater::update(int run) {
0057     std::ostringstream ss;
0058     ss << "touch cfg.py; rm cfg.py; sed 's?_CurrentRun_?" << run << "?g' writeInt_cfg.py > cfg.py; cmsRun cfg.py";
0059     edm::LogPrint("TestUpdater") << ss.str();
0060     // write run in db
0061     ::system(ss.str().c_str());
0062   }
0063 
0064   DEFINE_FWK_MODULE(TestUpdater);
0065 }  // namespace condtest
0066 
0067 #include "FWCore/Utilities/interface/typelookup.h"
0068 TYPELOOKUP_DATA_REG(std::vector<int>);
0069 
0070 #include "CondCore/ESSources/interface/registration_macros.h"
0071 
0072 REGISTER_PLUGIN(OneIntRcd, std::vector<int>);