Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-11-11 03:56:55

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