File indexing completed on 2024-04-06 12:01:32
0001 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0002 #include "FWCore/ServiceRegistry/interface/Service.h"
0003 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0004 #include "CondFormats/Calibration/interface/Pedestals.h"
0005 #include "CondFormats/Calibration/interface/mySiStripNoises.h"
0006 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0007
0008 #include <random>
0009 #include <string>
0010
0011 namespace edm {
0012 class ParameterSet;
0013 class Event;
0014 class EventSetup;
0015 }
0016
0017
0018 class writeMultipleRecords : public edm::one::EDAnalyzer<> {
0019 public:
0020 explicit writeMultipleRecords(const edm::ParameterSet& iConfig);
0021 ~writeMultipleRecords();
0022 virtual void analyze(const edm::Event&, const edm::EventSetup&);
0023 virtual void endJob() {}
0024
0025 private:
0026 std::string m_PedRecordName;
0027 std::string m_StripRecordName;
0028 };
0029
0030 typedef std::minstd_rand base_generator_type;
0031 writeMultipleRecords::writeMultipleRecords(const edm::ParameterSet& iConfig) {
0032 m_PedRecordName = iConfig.getParameter<std::string>("PedCallerName");
0033 m_StripRecordName = iConfig.getParameter<std::string>("StripCallerName");
0034 }
0035
0036 writeMultipleRecords::~writeMultipleRecords() {
0037 std::cout << "writeMultipleRecords::writeMultipleRecords" << std::endl;
0038 }
0039
0040 void writeMultipleRecords::analyze(const edm::Event& evt, const edm::EventSetup& evtSetup) {
0041 std::cout << "writeMultipleRecords::analyze " << std::endl;
0042 base_generator_type rng(42u);
0043 std::uniform_real_distribution<> uni_dist(0.0, 1.0);
0044 auto uni = [&]() { return uni_dist(rng); };
0045
0046 edm::Service<cond::service::PoolDBOutputService> mydbservice;
0047 if (!mydbservice.isAvailable()) {
0048 std::cout << "db service unavailable" << std::endl;
0049 return;
0050 }
0051 try {
0052 mySiStripNoises me;
0053 unsigned int detidseed = 1234;
0054 unsigned int bsize = 10;
0055 unsigned int nAPV = 2;
0056
0057 for (uint32_t detid = detidseed; detid < (detidseed + bsize); detid++) {
0058
0059 std::vector<short> theSiStripVector;
0060 for (unsigned int strip = 0; strip < 128 * nAPV; ++strip) {
0061 std::cout << strip << std::endl;
0062 float noise = uni();
0063 ;
0064 me.setData(noise, theSiStripVector);
0065 }
0066 me.put(detid, theSiStripVector);
0067 }
0068
0069 mydbservice->writeOneIOV(me, mydbservice->currentTime(), m_StripRecordName);
0070
0071 Pedestals myped;
0072 for (int ichannel = 1; ichannel <= 5; ++ichannel) {
0073 Pedestals::Item item;
0074 item.m_mean = 1.11 * ichannel;
0075 item.m_variance = 1.12 * ichannel;
0076 myped.m_pedestals.push_back(item);
0077 }
0078 mydbservice->writeOneIOV(myped, mydbservice->currentTime(), m_PedRecordName);
0079 } catch (const cond::Exception& er) {
0080 throw cms::Exception("DBOutputServiceUnitTestFailure", "failed writeMultipleRecords", er);
0081
0082 } catch (const cms::Exception& er) {
0083 throw cms::Exception("DBOutputServiceUnitTestFailure", "failed writeMultipleRecords", er);
0084 }
0085 }
0086 #include "FWCore/Framework/interface/MakerMacros.h"
0087 DEFINE_FWK_MODULE(writeMultipleRecords);