Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:03:27

0001 // system include files
0002 #include <fstream>
0003 #include <iostream>
0004 
0005 // user include files
0006 #include "CalibTracker/SiStripCommon/interface/SiStripDetInfoFileReader.h"
0007 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0008 #include "CondFormats/SiStripObjects/interface/SiStripApvGain.h"
0009 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0010 #include "FWCore/Framework/interface/Event.h"
0011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0012 #include "FWCore/ParameterSet/interface/FileInPath.h"
0013 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0014 #include "FWCore/ServiceRegistry/interface/Service.h"
0015 #include "FWCore/Utilities/interface/Exception.h"
0016 
0017 #include "CLHEP/Random/RandFlat.h"
0018 #include "CLHEP/Random/RandGauss.h"
0019 
0020 class SiStripApvGainBuilder : public edm::one::EDAnalyzer<> {
0021 public:
0022   explicit SiStripApvGainBuilder(const edm::ParameterSet& iConfig);
0023 
0024   ~SiStripApvGainBuilder() override = default;
0025 
0026   void analyze(const edm::Event&, const edm::EventSetup&) override;
0027 
0028 private:
0029   const edm::FileInPath fp_;
0030   const bool printdebug_;
0031 };
0032 
0033 SiStripApvGainBuilder::SiStripApvGainBuilder(const edm::ParameterSet& iConfig)
0034     : fp_(iConfig.getUntrackedParameter<edm::FileInPath>("file",
0035                                                          edm::FileInPath(SiStripDetInfoFileReader::kDefaultFile))),
0036       printdebug_(iConfig.getUntrackedParameter<uint32_t>("printDebug", 1)) {}
0037 
0038 void SiStripApvGainBuilder::analyze(const edm::Event& evt, const edm::EventSetup& iSetup) {
0039   unsigned int run = evt.id().run();
0040 
0041   edm::LogInfo("SiStripApvGainBuilder") << "... creating dummy SiStripApvGain Data for Run " << run << "\n "
0042                                         << std::endl;
0043 
0044   SiStripApvGain obj;
0045 
0046   const auto& reader = SiStripDetInfoFileReader::read(fp_.fullPath());
0047   const auto& DetInfos = reader.getAllData();
0048 
0049   int count = -1;
0050   for (const auto& it : DetInfos) {
0051     const auto& nAPVs = it.second.nApvs;
0052     count++;
0053     //Generate Gain for det detid
0054     std::vector<float> theSiStripVector;
0055     for (unsigned short j = 0; j < nAPVs; j++) {
0056       float gain = (j + 1) * 1000 + (CLHEP::RandFlat::shoot(1.) * 100);
0057       if (count < printdebug_)
0058         edm::LogInfo("SiStripApvGainBuilder") << "detid " << it.first << " \t"
0059                                               << " apv " << j << " \t" << gain << " \t" << std::endl;
0060       theSiStripVector.push_back(gain);
0061     }
0062 
0063     SiStripApvGain::Range range(theSiStripVector.begin(), theSiStripVector.end());
0064     if (!obj.put(it.first, range))
0065       edm::LogError("SiStripApvGainBuilder") << "[SiStripApvGainBuilder::analyze] detid already exists" << std::endl;
0066   }
0067 
0068   //End now write sistripnoises data in DB
0069   edm::Service<cond::service::PoolDBOutputService> mydbservice;
0070 
0071   if (mydbservice.isAvailable()) {
0072     if (mydbservice->isNewTagRequest("SiStripApvGainRcd")) {
0073       mydbservice->createOneIOV<SiStripApvGain>(obj, mydbservice->beginOfTime(), "SiStripApvGainRcd");
0074     } else {
0075       mydbservice->appendOneIOV<SiStripApvGain>(obj, mydbservice->currentTime(), "SiStripApvGainRcd");
0076     }
0077   } else {
0078     edm::LogError("SiStripApvGainBuilder") << "Service is unavailable" << std::endl;
0079   }
0080 }
0081 
0082 #include "FWCore/PluginManager/interface/ModuleDef.h"
0083 #include "FWCore/Framework/interface/MakerMacros.h"
0084 
0085 DEFINE_FWK_MODULE(SiStripApvGainBuilder);