Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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