File indexing completed on 2024-04-06 12:00:00
0001 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0002 #include "FWCore/ParameterSet/interface/FileInPath.h"
0003 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0004 #include "FWCore/Utilities/interface/Exception.h"
0005
0006 #include "CommonTools/ConditionDBWriter/interface/ConditionDBWriter.h"
0007 #include "CondFormats/SiStripObjects/interface/SiStripBadStrip.h"
0008 #include "CalibTracker/SiStripCommon/interface/SiStripDetInfoFileReader.h"
0009
0010 #include <vector>
0011 #include <iostream>
0012 #include <fstream>
0013
0014 class SiStripBadModuleByHandBuilder : public ConditionDBWriter<SiStripBadStrip> {
0015 public:
0016 explicit SiStripBadModuleByHandBuilder(const edm::ParameterSet&);
0017 ~SiStripBadModuleByHandBuilder() override = default;
0018
0019 private:
0020 std::unique_ptr<SiStripBadStrip> getNewObject() override;
0021
0022 private:
0023 edm::FileInPath fp_;
0024 bool printdebug_;
0025 std::vector<uint32_t> BadModuleList_;
0026 };
0027
0028 SiStripBadModuleByHandBuilder::SiStripBadModuleByHandBuilder(const edm::ParameterSet& iConfig)
0029 : ConditionDBWriter<SiStripBadStrip>(iConfig) {
0030 fp_ = iConfig.getUntrackedParameter<edm::FileInPath>("file", edm::FileInPath(SiStripDetInfoFileReader::kDefaultFile));
0031 BadModuleList_ = iConfig.getUntrackedParameter<std::vector<uint32_t> >("BadModuleList");
0032 printdebug_ = iConfig.getUntrackedParameter<bool>("printDebug", false);
0033 }
0034
0035 std::unique_ptr<SiStripBadStrip> SiStripBadModuleByHandBuilder::getNewObject() {
0036 const auto detInfo = SiStripDetInfoFileReader::read(fp_.fullPath());
0037
0038 auto obj = std::make_unique<SiStripBadStrip>();
0039
0040 unsigned int firstBadStrip = 0;
0041 unsigned short NconsecutiveBadStrips;
0042 unsigned int theBadStripRange;
0043
0044 for (std::vector<uint32_t>::const_iterator it = BadModuleList_.begin(); it != BadModuleList_.end(); ++it) {
0045 std::vector<unsigned int> theSiStripVector;
0046
0047 NconsecutiveBadStrips = detInfo.getNumberOfApvsAndStripLength(*it).first * 128;
0048 theBadStripRange = obj->encode(firstBadStrip, NconsecutiveBadStrips);
0049 if (printdebug_)
0050 edm::LogInfo("SiStripBadModuleByHandBuilder")
0051 << " BadModule " << *it << " \t"
0052 << " firstBadStrip " << firstBadStrip << "\t "
0053 << " NconsecutiveBadStrips " << NconsecutiveBadStrips << "\t "
0054 << " packed integer " << std::hex << theBadStripRange << std::dec << std::endl;
0055
0056 theSiStripVector.push_back(theBadStripRange);
0057 SiStripBadStrip::Range range(theSiStripVector.begin(), theSiStripVector.end());
0058 if (!obj->put(*it, range))
0059 edm::LogError("SiStripBadModuleByHandBuilder")
0060 << "[SiStripBadModuleByHandBuilder::analyze] detid already exists" << std::endl;
0061 }
0062 return obj;
0063 }
0064
0065 #include "FWCore/Framework/interface/MakerMacros.h"
0066 DEFINE_FWK_MODULE(SiStripBadModuleByHandBuilder);