Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-11-15 23:33:54

0001 #include "FWCore/ServiceRegistry/interface/Service.h"
0002 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0003 #include "CondFormats/Calibration/interface/mySiStripNoises.h"
0004 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0005 
0006 #include <random>
0007 #include <string>
0008 
0009 namespace edm {
0010   class ParameterSet;
0011   class Event;
0012   class EventSetup;
0013 }  // namespace edm
0014 
0015 // class decleration
0016 class writeBlob : public edm::one::EDAnalyzer<> {
0017 public:
0018   explicit writeBlob(const edm::ParameterSet& iConfig);
0019   ~writeBlob();
0020   virtual void analyze(const edm::Event&, const edm::EventSetup&);
0021   virtual void endJob() {}
0022 
0023 private:
0024   std::string m_StripRecordName;
0025 };
0026 
0027 typedef std::minstd_rand base_generator_type;
0028 writeBlob::writeBlob(const edm::ParameterSet& iConfig) : m_StripRecordName("mySiStripNoisesRcd") {}
0029 
0030 writeBlob::~writeBlob() { std::cout << "writeBlob::writeBlob" << std::endl; }
0031 
0032 void writeBlob::analyze(const edm::Event& evt, const edm::EventSetup& evtSetup) {
0033   std::cout << "writeBlob::analyze " << std::endl;
0034   base_generator_type rng(42u);
0035   std::uniform_real_distribution<> uni_dist(0.0, 1.0);
0036   auto uni = [&]() { return uni_dist(rng); };
0037 
0038   edm::Service<cond::service::PoolDBOutputService> mydbservice;
0039 
0040   if (!mydbservice.isAvailable()) {
0041     std::cout << "db service unavailable" << std::endl;
0042     return;
0043   }
0044   try {
0045     mySiStripNoises me;
0046     unsigned int detidseed = 1234;
0047     unsigned int bsize = 100;
0048     unsigned int nAPV = 2;
0049     for (uint32_t detid = detidseed; detid < (detidseed + bsize); detid++) {
0050       //Generate Noise for det detid
0051       std::vector<short> theSiStripVector;
0052       for (unsigned int strip = 0; strip < 128 * nAPV; ++strip) {
0053         float noise = uni();
0054         ;
0055         me.setData(noise, theSiStripVector);
0056       }
0057       me.put(detid, theSiStripVector);
0058     }
0059 
0060     mydbservice->writeOneIOV(me, mydbservice->currentTime(), m_StripRecordName);
0061   } catch (const cond::Exception& er) {
0062     throw cms::Exception("DBOutputServiceUnitTestFailure", "failed writeBlob", er);
0063     //std::cout<<er.what()<<std::endl;
0064   } catch (const cms::Exception& er) {
0065     throw cms::Exception("DBOutputServiceUnitTestFailure", "failed writeBlob", er);
0066   }
0067 }
0068 #include "FWCore/Framework/interface/MakerMacros.h"
0069 DEFINE_FWK_MODULE(writeBlob);