Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 // system include files
0002 #include <iostream>
0003 #include <fstream>
0004 
0005 // user include files
0006 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0007 #include "CondFormats/SiStripObjects/interface/SiStripSummary.h"
0008 #include "FWCore/Framework/interface/ESHandle.h"
0009 #include "FWCore/Framework/interface/Event.h"
0010 #include "FWCore/Framework/interface/one/EDAnalyzer.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 SiStripSummaryBuilder : public edm::one::EDAnalyzer<> {
0021 public:
0022   explicit SiStripSummaryBuilder(const edm::ParameterSet& iConfig);
0023 
0024   ~SiStripSummaryBuilder() override = default;
0025 
0026   void analyze(const edm::Event&, const edm::EventSetup&) override;
0027 
0028 private:
0029   edm::FileInPath fp_;
0030   bool printdebug_;
0031 
0032   edm::ParameterSet iConfig_;
0033 };
0034 
0035 SiStripSummaryBuilder::SiStripSummaryBuilder(const edm::ParameterSet& iConfig)
0036     : fp_(iConfig.getUntrackedParameter<edm::FileInPath>(
0037           "file", edm::FileInPath("CalibTracker/SiStripCommon/data/SiStripDetInfo.dat"))),
0038       printdebug_(iConfig.getUntrackedParameter<uint32_t>("printDebug", 1)),
0039       iConfig_(iConfig) {}
0040 
0041 void SiStripSummaryBuilder::analyze(const edm::Event& evt, const edm::EventSetup& iSetup) {
0042   unsigned int run = evt.id().run();
0043   edm::LogInfo("SiStripSummaryBuilder") << "... creating dummy SiStripSummary Data for Run " << run << "\n "
0044                                         << std::endl;
0045 
0046   SiStripSummary obj;
0047   obj.setRunNr(run);
0048 
0049   //* DISCOVER SET OF HISTOGRAMS & QUANTITIES TO BE UPLOADED*//
0050 
0051   std::vector<std::string> userDBContent;
0052   typedef std::vector<edm::ParameterSet> VParameters;
0053   VParameters histoList = iConfig_.getParameter<VParameters>("histoList");
0054   VParameters::iterator ithistoList = histoList.begin();
0055   VParameters::iterator ithistoListEnd = histoList.end();
0056 
0057   for (; ithistoList != ithistoListEnd; ++ithistoList) {
0058     std::string keyName = ithistoList->getUntrackedParameter<std::string>("keyName");
0059     std::vector<std::string> Quantities =
0060         ithistoList->getUntrackedParameter<std::vector<std::string> >("quantitiesToExtract");
0061     for (size_t i = 0; i < Quantities.size(); ++i) {
0062       if (Quantities[i] == "landau") {
0063         userDBContent.push_back(keyName + std::string("@") + std::string("landauPeak"));
0064         userDBContent.push_back(keyName + std::string("@") + std::string("landauPeakErr"));
0065         userDBContent.push_back(keyName + std::string("@") + std::string("landauSFWHM"));
0066         userDBContent.push_back(keyName + std::string("@") + std::string("landauChi2NDF"));
0067       } else if (Quantities[i] == "gauss") {
0068         userDBContent.push_back(keyName + std::string("@") + std::string("gaussMean"));
0069         userDBContent.push_back(keyName + std::string("@") + std::string("gaussSigma"));
0070         userDBContent.push_back(keyName + std::string("@") + std::string("gaussChi2NDF"));
0071       } else if (Quantities[i] == "stat") {
0072         userDBContent.push_back(keyName + std::string("@") + std::string("entries"));
0073         userDBContent.push_back(keyName + std::string("@") + std::string("mean"));
0074         userDBContent.push_back(keyName + std::string("@") + std::string("rms"));
0075       } else {
0076         edm::LogError("SiStripSummaryBuilder")
0077             << "Quantity " << Quantities[i] << " cannot be handled\nAllowed quantities are"
0078             << "\n  'stat'   that includes: entries, mean, rms"
0079             << "\n  'landau' that includes: landauPeak, landauPeakErr, landauSFWHM, landauChi2NDF"
0080             << "\n  'gauss'  that includes: gaussMean, gaussSigma, gaussChi2NDF" << std::endl;
0081       }
0082     }
0083   }
0084   obj.setUserDBContent(userDBContent);
0085 
0086   std::stringstream ss1;
0087   ss1 << "QUANTITIES TO BE INSERTED IN DB :"
0088       << " \n";
0089   std::vector<std::string> userDBContentA = obj.getUserDBContent();
0090   for (size_t i = 0; i < userDBContentA.size(); ++i)
0091     ss1 << userDBContentA[i] << std::endl;
0092   edm::LogInfo("SiStripSummaryBuilder") << ss1.str();
0093 
0094   //* Loop over detids and create dummy data for each *//
0095 
0096   std::stringstream ss2;
0097   for (uint32_t detid = 0; detid < 430; detid++) {
0098     SiStripSummary::InputVector values;
0099     for (unsigned int i = 0; i < userDBContent.size(); i++)
0100       values.push_back((float)CLHEP::RandGauss::shoot(50., 30.));
0101 
0102     ss2 << "\n\tdetid " << detid;
0103     for (size_t j = 0; j < values.size(); ++j)
0104       ss2 << "\n\t\t " << userDBContent[j] << " " << values[j];
0105 
0106     obj.put(detid, values, userDBContent);
0107 
0108     // See CondFormats/SiStripObjects/SiStripSummary.h for detid definitions
0109 
0110     if (detid == 4)
0111       detid = 10;
0112     if (detid == 14)
0113       detid = 20;
0114     if (detid == 26)
0115       detid = 30;
0116     if (detid == 32)
0117       detid = 40;
0118     if (detid == 42)
0119       detid = 310;
0120     if (detid == 313)
0121       detid = 320;
0122     if (detid == 323)
0123       detid = 410;
0124     if (detid == 419)
0125       detid = 420;
0126   }
0127 
0128   edm::LogInfo("SiStripSummaryBuilder") << ss2.str();
0129 
0130   //* Insert summary informations in the DB *//
0131 
0132   edm::Service<cond::service::PoolDBOutputService> mydbservice;
0133 
0134   if (mydbservice.isAvailable()) {
0135     if (mydbservice->isNewTagRequest("SiStripSummaryRcd")) {
0136       mydbservice->createOneIOV<SiStripSummary>(obj, mydbservice->beginOfTime(), "SiStripSummaryRcd");
0137     } else {
0138       mydbservice->appendOneIOV<SiStripSummary>(obj, mydbservice->currentTime(), "SiStripSummaryRcd");
0139     }
0140   } else {
0141     edm::LogError("SiStripSummaryBuilder") << "Service is unavailable" << std::endl;
0142   }
0143 }
0144 
0145 #include "FWCore/PluginManager/interface/ModuleDef.h"
0146 #include "FWCore/Framework/interface/MakerMacros.h"
0147 
0148 DEFINE_FWK_MODULE(SiStripSummaryBuilder);