Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-01-16 23:25:23

0001 
0002 /*----------------------------------------------------------------------
0003 
0004 Toy EDProducers and EDProducts for testing purposes only.
0005 
0006 ----------------------------------------------------------------------*/
0007 
0008 #include <stdexcept>
0009 #include <string>
0010 #include <iostream>
0011 //#include <map>
0012 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0013 #include "FWCore/Framework/interface/Event.h"
0014 #include "FWCore/Framework/interface/ESHandle.h"
0015 #include "FWCore/Framework/interface/MakerMacros.h"
0016 
0017 #include "FWCore/Framework/interface/EventSetup.h"
0018 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0019 #include "CondFormats/DataRecord/interface/BeamSpotObjectsRcd.h"
0020 #include "CondFormats/BeamSpotObjects/interface/BeamSpotObjects.h"
0021 #include "CondCore/CondDB/interface/Time.h"
0022 #include "CondCore/CondDB/interface/ConnectionPool.h"
0023 #include <fstream>
0024 
0025 using namespace std;
0026 
0027 namespace edmtest {
0028   class LumiTestWriteAnalyzer : public edm::one::EDAnalyzer<> {
0029   public:
0030     explicit LumiTestWriteAnalyzer(edm::ParameterSet const& p)
0031         : m_connectionString(p.getUntrackedParameter<std::string>("connectionString")),
0032           m_tagName(p.getUntrackedParameter<std::string>("tagName")),
0033           m_run(p.getUntrackedParameter<unsigned int>("runNumber")),
0034           m_NLumi(p.getUntrackedParameter<unsigned int>("numberOfLumis")),
0035           m_iovSize(p.getUntrackedParameter<unsigned int>("iovSize")) {}
0036     explicit LumiTestWriteAnalyzer(int i) {}
0037     virtual ~LumiTestWriteAnalyzer() {}
0038     virtual void beginJob() override;
0039     virtual void analyze(edm::Event const&, edm::EventSetup const&) override {}
0040 
0041   private:
0042     std::string m_connectionString;
0043     std::string m_tagName;
0044     unsigned int m_run;
0045     unsigned int m_NLumi;
0046     unsigned int m_iovSize;
0047   };
0048 
0049   void LumiTestWriteAnalyzer::beginJob() {
0050     cond::persistency::ConnectionPool pool;
0051     pool.setMessageVerbosity(coral::Debug);
0052     auto session = pool.createSession(m_connectionString, true);
0053     session.transaction().start(false);
0054     cond::persistency::IOVEditor editor;
0055     if (!session.existsDatabase() || !session.existsIov(m_tagName)) {
0056       editor = session.createIov<BeamSpotObjects>(m_tagName, cond::lumiid);
0057       editor.setDescription("Read/Write Test");
0058     } else {
0059       editor = session.editIov(m_tagName);
0060     }
0061     size_t i = 0;
0062     for (size_t lumiId = 1; lumiId < m_NLumi; lumiId += m_iovSize) {
0063       BeamSpotObjects mybeamspot;
0064       mybeamspot.setPosition(0.053, 0.1, 0.13);
0065       mybeamspot.setSigmaZ(3.8 + i);
0066       mybeamspot.setType(int(lumiId));
0067       auto payloadId = session.storePayload(mybeamspot);
0068       auto since = cond::time::lumiTime(m_run, lumiId);
0069       editor.insert(since, payloadId);
0070       i++;
0071     }
0072     editor.flush();
0073     session.transaction().commit();
0074   }
0075 
0076   DEFINE_FWK_MODULE(LumiTestWriteAnalyzer);
0077 }  // namespace edmtest