Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 // system include files
0002 #include <vector>
0003 #include <memory>
0004 #include <iostream>
0005 #include <fstream>
0006 
0007 // user include files
0008 #include "CalibTracker/SiStripCommon/interface/SiStripDetInfoFileReader.h"
0009 #include "CommonTools/ConditionDBWriter/interface/ConditionDBWriter.h"
0010 #include "CondFormats/SiStripObjects/interface/SiStripBadStrip.h"
0011 #include "FWCore/Framework/interface/ESHandle.h"
0012 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0013 #include "FWCore/ParameterSet/interface/FileInPath.h"
0014 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0015 #include "FWCore/Utilities/interface/Exception.h"
0016 
0017 #include "CLHEP/Random/RandFlat.h"
0018 #include "CLHEP/Random/RandGauss.h"
0019 
0020 class SiStripBadChannelBuilder : public ConditionDBWriter<SiStripBadStrip> {
0021 public:
0022   explicit SiStripBadChannelBuilder(const edm::ParameterSet&);
0023   ~SiStripBadChannelBuilder() override;
0024 
0025 private:
0026   std::unique_ptr<SiStripBadStrip> getNewObject() override;
0027 
0028   edm::FileInPath fp_;
0029   bool printdebug_;
0030 
0031   typedef std::vector<edm::ParameterSet> Parameters;
0032   Parameters BadComponentList_;
0033 };
0034 
0035 SiStripBadChannelBuilder::SiStripBadChannelBuilder(const edm::ParameterSet& iConfig)
0036     : ConditionDBWriter<SiStripBadStrip>(iConfig) {
0037   fp_ = iConfig.getUntrackedParameter<edm::FileInPath>("file", edm::FileInPath(SiStripDetInfoFileReader::kDefaultFile));
0038   printdebug_ = iConfig.getUntrackedParameter<bool>("printDebug", false);
0039   BadComponentList_ = iConfig.getUntrackedParameter<Parameters>("BadComponentList");
0040 }
0041 
0042 SiStripBadChannelBuilder::~SiStripBadChannelBuilder() = default;
0043 
0044 std::unique_ptr<SiStripBadStrip> SiStripBadChannelBuilder::getNewObject() {
0045   edm::LogInfo("SiStripBadChannelBuilder") << "... creating dummy SiStripBadStrip Data" << std::endl;
0046 
0047   auto obj = std::make_unique<SiStripBadStrip>();
0048 
0049   const auto detInfo = SiStripDetInfoFileReader::read(fp_.fullPath());
0050 
0051   for (Parameters::iterator iBadComponent = BadComponentList_.begin(); iBadComponent != BadComponentList_.end();
0052        ++iBadComponent) {
0053     uint32_t BadModule_ = iBadComponent->getParameter<uint32_t>("BadModule");
0054     std::vector<uint32_t> BadChannelList_ = iBadComponent->getParameter<std::vector<uint32_t> >("BadChannelList");
0055 
0056     std::vector<unsigned int> theSiStripVector;
0057     unsigned int NStrips = detInfo.getNumberOfApvsAndStripLength(BadModule_).first * 128;
0058 
0059     uint32_t lastBad = 999;
0060     unsigned short firstBadStrip = 0, NconsecutiveBadStrips = 0;
0061     unsigned int theBadStripRange;
0062 
0063     for (std::vector<uint32_t>::const_iterator is = BadChannelList_.begin(); is != BadChannelList_.end(); ++is) {
0064       if (*is > NStrips - 1)
0065         break;
0066       if (*is != lastBad + 1) {
0067         //new set
0068 
0069         if (lastBad != 999) {
0070           //save previous set
0071           theBadStripRange = obj->encode(firstBadStrip, NconsecutiveBadStrips);
0072 
0073           if (printdebug_)
0074             edm::LogInfo("SiStripBadChannelBuilder")
0075                 << "detid " << BadModule_ << " \t"
0076                 << " firstBadStrip " << firstBadStrip << "\t "
0077                 << " NconsecutiveBadStrips " << NconsecutiveBadStrips << "\t "
0078                 << " packed integer " << std::hex << theBadStripRange << std::dec << std::endl;
0079 
0080           theSiStripVector.push_back(theBadStripRange);
0081         }
0082 
0083         firstBadStrip = *is;
0084         NconsecutiveBadStrips = 0;
0085       }
0086       NconsecutiveBadStrips++;
0087       lastBad = *is;
0088     }
0089 
0090     theBadStripRange = obj->encode(firstBadStrip, NconsecutiveBadStrips);
0091     if (printdebug_)
0092       edm::LogInfo("SiStripBadChannelBuilder")
0093           << "detid " << BadModule_ << " \t"
0094           << " firstBadStrip " << firstBadStrip << "\t "
0095           << " NconsecutiveBadStrips " << NconsecutiveBadStrips << "\t "
0096           << " packed integer " << std::hex << theBadStripRange << std::dec << std::endl;
0097 
0098     theSiStripVector.push_back(theBadStripRange);
0099 
0100     SiStripBadStrip::Range range(theSiStripVector.begin(), theSiStripVector.end());
0101     if (!obj->put(BadModule_, range))
0102       edm::LogError("SiStripBadChannelBuilder")
0103           << "[SiStripBadChannelBuilder::analyze] detid already exists" << std::endl;
0104   }
0105   //End now write sistripbadChannel data in DB
0106   edm::Service<cond::service::PoolDBOutputService> mydbservice;
0107 
0108   if (mydbservice.isAvailable()) {
0109     if (mydbservice->isNewTagRequest("SiStripBadStripRcd")) {
0110       mydbservice->createOneIOV<SiStripBadStrip>(*obj, mydbservice->beginOfTime(), "SiStripBadStripRcd");
0111     } else {
0112       mydbservice->appendOneIOV<SiStripBadStrip>(*obj, mydbservice->currentTime(), "SiStripBadStripRcd");
0113     }
0114   } else {
0115     edm::LogError("SiStripBadStripBuilder") << "Service is unavailable" << std::endl;
0116   }
0117 
0118   return obj;
0119 }
0120 
0121 #include "FWCore/PluginManager/interface/ModuleDef.h"
0122 #include "FWCore/Framework/interface/MakerMacros.h"
0123 
0124 DEFINE_FWK_MODULE(SiStripBadChannelBuilder);