Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 // system include files
0002 #include <vector>
0003 #include <iostream>
0004 #include <fstream>
0005 #include <sstream>
0006 
0007 // user include files
0008 #include "CommonTools/ConditionDBWriter/interface/ConditionDBWriter.h"
0009 #include "CondFormats/SiStripObjects/interface/SiStripBadStrip.h"
0010 #include "FWCore/Framework/interface/ESHandle.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/Utilities/interface/Exception.h"
0015 
0016 class SiStripBadFiberBuilder : public ConditionDBWriter<SiStripBadStrip> {
0017 public:
0018   explicit SiStripBadFiberBuilder(const edm::ParameterSet&);
0019   ~SiStripBadFiberBuilder() override;
0020 
0021 private:
0022   std::unique_ptr<SiStripBadStrip> getNewObject() override;
0023 
0024   bool printdebug_;
0025 
0026   typedef std::vector<edm::ParameterSet> Parameters;
0027   Parameters BadComponentList_;
0028 };
0029 
0030 SiStripBadFiberBuilder::SiStripBadFiberBuilder(const edm::ParameterSet& iConfig)
0031     : ConditionDBWriter<SiStripBadStrip>(iConfig) {
0032   printdebug_ = iConfig.getUntrackedParameter<bool>("printDebug", false);
0033   BadComponentList_ = iConfig.getUntrackedParameter<Parameters>("BadComponentList");
0034 }
0035 
0036 SiStripBadFiberBuilder::~SiStripBadFiberBuilder() = default;
0037 
0038 std::unique_ptr<SiStripBadStrip> SiStripBadFiberBuilder::getNewObject() {
0039   edm::LogInfo("SiStripBadFiberBuilder") << "... creating dummy SiStripBadStrip Data" << std::endl;
0040 
0041   auto obj = std::make_unique<SiStripBadStrip>();
0042 
0043   std::stringstream ss;
0044   for (Parameters::iterator iBadComponent = BadComponentList_.begin(); iBadComponent != BadComponentList_.end();
0045        ++iBadComponent) {
0046     uint32_t BadModule_ = iBadComponent->getParameter<uint32_t>("BadModule");
0047     std::vector<uint32_t> BadApvList_ = iBadComponent->getParameter<std::vector<uint32_t> >("BadApvList");
0048 
0049     std::vector<unsigned int> theSiStripVector;
0050 
0051     unsigned short firstBadStrip = 0, NconsecutiveBadStrips = 0;
0052     unsigned int theBadStripRange;
0053 
0054     for (std::vector<uint32_t>::const_iterator is = BadApvList_.begin(); is != BadApvList_.end(); ++is) {
0055       firstBadStrip = (*is) * 128;
0056       NconsecutiveBadStrips = 128;
0057 
0058       theBadStripRange = obj->encode(firstBadStrip, NconsecutiveBadStrips);
0059 
0060       if (printdebug_)
0061         ss << "detid " << BadModule_ << " \t"
0062            << " firstBadStrip " << firstBadStrip << "\t "
0063            << " NconsecutiveBadStrips " << NconsecutiveBadStrips << "\t "
0064            << " packed integer " << std::hex << theBadStripRange << std::dec << std::endl;
0065 
0066       theSiStripVector.push_back(theBadStripRange);
0067     }
0068 
0069     SiStripBadStrip::Range range(theSiStripVector.begin(), theSiStripVector.end());
0070     if (!obj->put(BadModule_, range))
0071       edm::LogError("SiStripBadFiberBuilder") << "[SiStripBadFiberBuilder::analyze] detid already exists" << std::endl;
0072   }
0073   if (printdebug_)
0074     edm::LogInfo("SiStripBadFiberBuilder") << ss.str();
0075 
0076   return obj;
0077 }
0078 
0079 #include "FWCore/PluginManager/interface/ModuleDef.h"
0080 #include "FWCore/Framework/interface/MakerMacros.h"
0081 
0082 DEFINE_FWK_MODULE(SiStripBadFiberBuilder);