Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0002 #include "CalibTracker/SiStripCommon/interface/SiStripDetInfoFileReader.h"
0003 #include "CondFormats/SiStripObjects/interface/SiStripThreshold.h"
0004 #include "FWCore/Framework/interface/ESHandle.h"
0005 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0006 #include "FWCore/Framework/interface/Event.h"
0007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0008 #include "FWCore/ParameterSet/interface/FileInPath.h"
0009 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0010 #include "FWCore/ServiceRegistry/interface/Service.h"
0011 #include "FWCore/Utilities/interface/Exception.h"
0012 
0013 #include "CLHEP/Random/RandFlat.h"
0014 #include "CLHEP/Random/RandGauss.h"
0015 
0016 #include <iostream>
0017 #include <fstream>
0018 
0019 class SiStripThresholdBuilder : public edm::one::EDAnalyzer<> {
0020 public:
0021   explicit SiStripThresholdBuilder(const edm::ParameterSet& iConfig);
0022 
0023   ~SiStripThresholdBuilder() override = default;
0024 
0025   void analyze(const edm::Event&, const edm::EventSetup&) override;
0026 
0027 private:
0028   edm::FileInPath fp_;
0029   uint32_t printdebug_;
0030 };
0031 
0032 SiStripThresholdBuilder::SiStripThresholdBuilder(const edm::ParameterSet& iConfig)
0033     : fp_(iConfig.getUntrackedParameter<edm::FileInPath>("file",
0034                                                          edm::FileInPath(SiStripDetInfoFileReader::kDefaultFile))),
0035       printdebug_(iConfig.getUntrackedParameter<uint32_t>("printDebug", 3)) {}
0036 
0037 void SiStripThresholdBuilder::analyze(const edm::Event& evt, const edm::EventSetup& iSetup) {
0038   unsigned int run = evt.id().run();
0039 
0040   edm::LogInfo("SiStripThresholdBuilder")
0041       << "... creating dummy SiStripThreshold Data for Run " << run << "\n " << std::endl;
0042 
0043   SiStripThreshold obj;
0044 
0045   const auto& reader = SiStripDetInfoFileReader::read(fp_.fullPath());
0046   const auto& DetInfos = reader.getAllData();
0047 
0048   int count = -1;
0049   for (const auto& it : DetInfos) {
0050     count++;
0051     //Generate Pedestal for det detid
0052     SiStripThreshold::Container theSiStripVector;
0053     uint16_t strip = 0;
0054     while (strip < 128 * it.second.nApvs) {
0055       float lTh = (CLHEP::RandFlat::shoot(1.) * 64) / 5;
0056       float hTh = (CLHEP::RandFlat::shoot(1.) * 64) / 5;
0057       if (hTh < lTh) {
0058         float tmp = hTh;
0059         hTh = lTh;
0060         lTh = tmp;
0061       }
0062       float cTh = (CLHEP::RandFlat::shoot(1.) * 30.);
0063 
0064       obj.setData(strip, lTh, hTh, cTh, theSiStripVector);
0065       if (count < (int)printdebug_) {
0066         std::stringstream ss;
0067         theSiStripVector.back().print(ss);
0068         edm::LogInfo("SiStripThresholdBuilder")
0069             << "detid: " << it.first << " \n"
0070             << "firstStrip: " << strip << " \t"
0071             << "lTh: " << lTh << " \t"
0072             << "hTh: " << hTh << " \t"
0073             << "cTh: " << cTh << " \t"
0074             << "FirstStrip_and_Hth: " << theSiStripVector.back().FirstStrip_and_Hth << " \n"
0075             << ss.str() << std::endl;
0076       }
0077       obj.setData(strip + 1, lTh, hTh, theSiStripVector);
0078       strip = (uint16_t)(CLHEP::RandFlat::shoot(strip + 2, 128 * it.second.nApvs));
0079     }
0080     if (!obj.put(it.first, theSiStripVector))
0081       edm::LogError("SiStripThresholdBuilder")
0082           << "[SiStripThresholdBuilder::analyze] detid already exists" << std::endl;
0083   }
0084 
0085   //End now write sistrippedestals data in DB
0086   edm::Service<cond::service::PoolDBOutputService> mydbservice;
0087 
0088   if (mydbservice.isAvailable()) {
0089     if (mydbservice->isNewTagRequest("SiStripThresholdRcd")) {
0090       mydbservice->createOneIOV<SiStripThreshold>(obj, mydbservice->beginOfTime(), "SiStripThresholdRcd");
0091     } else {
0092       mydbservice->appendOneIOV<SiStripThreshold>(obj, mydbservice->currentTime(), "SiStripThresholdRcd");
0093     }
0094   } else {
0095     edm::LogError("SiStripThresholdBuilder") << "Service is unavailable" << std::endl;
0096   }
0097 }
0098 
0099 #include "FWCore/PluginManager/interface/ModuleDef.h"
0100 #include "FWCore/Framework/interface/MakerMacros.h"
0101 
0102 DEFINE_FWK_MODULE(SiStripThresholdBuilder);