File indexing completed on 2024-09-07 04:35:46
0001
0002 #include <vector>
0003 #include <cmath>
0004 #include <fstream>
0005 #include <iostream>
0006
0007
0008 #include "CommonTools/ConditionDBWriter/interface/ConditionDBWriter.h"
0009 #include "CondFormats/SiPixelObjects/interface/SiPixelQuality.h"
0010 #include "DataFormats/DetId/interface/DetId.h"
0011 #include "DataFormats/TrackerCommon/interface/PixelBarrelName.h"
0012 #include "DataFormats/TrackerCommon/interface/PixelEndcapName.h"
0013 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0014 #include "FWCore/Framework/interface/EventSetup.h"
0015 #include "FWCore/Framework/interface/MakerMacros.h"
0016 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0017 #include "FWCore/ParameterSet/interface/FileInPath.h"
0018 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0019 #include "FWCore/Utilities/interface/Exception.h"
0020 #include "Geometry/Records/interface/TrackerTopologyRcd.h"
0021
0022 class SiPixelBadModuleByHandBuilder : public ConditionDBWriter<SiPixelQuality> {
0023 public:
0024 explicit SiPixelBadModuleByHandBuilder(const edm::ParameterSet&);
0025 ~SiPixelBadModuleByHandBuilder() override;
0026
0027 private:
0028 std::unique_ptr<SiPixelQuality> getNewObject() override;
0029
0030 void algoBeginRun(const edm::Run& run, const edm::EventSetup& es) override {
0031 if (!tTopo_) {
0032 tTopo_ = std::make_unique<TrackerTopology>(es.getData(tkTopoToken_));
0033 }
0034 };
0035
0036 private:
0037 const edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> tkTopoToken_;
0038 const bool printdebug_;
0039 typedef std::vector<edm::ParameterSet> Parameters;
0040 Parameters BadModuleList_;
0041 const std::string ROCListFile_;
0042 std::unique_ptr<TrackerTopology> tTopo_;
0043 };
0044
0045 SiPixelBadModuleByHandBuilder::SiPixelBadModuleByHandBuilder(const edm::ParameterSet& iConfig)
0046 : ConditionDBWriter<SiPixelQuality>(iConfig),
0047 tkTopoToken_(esConsumes<edm::Transition::BeginRun>()),
0048 printdebug_(iConfig.getUntrackedParameter<bool>("printDebug", false)),
0049 BadModuleList_(iConfig.getUntrackedParameter<Parameters>("BadModuleList")),
0050 ROCListFile_(iConfig.getUntrackedParameter<std::string>("ROCListFile")) {}
0051
0052 SiPixelBadModuleByHandBuilder::~SiPixelBadModuleByHandBuilder() = default;
0053
0054 std::unique_ptr<SiPixelQuality> SiPixelBadModuleByHandBuilder::getNewObject() {
0055 auto obj = std::make_unique<SiPixelQuality>();
0056
0057 for (Parameters::iterator it = BadModuleList_.begin(); it != BadModuleList_.end(); ++it) {
0058 if (printdebug_) {
0059 edm::LogInfo("SiPixelBadModuleByHandBuilder") << " BadModule " << *it << " \t" << std::endl;
0060 }
0061
0062 SiPixelQuality::disabledModuleType BadModule;
0063 BadModule.errorType = 3;
0064 BadModule.BadRocs = 0;
0065 BadModule.DetID = it->getParameter<uint32_t>("detid");
0066 std::string errorstring = it->getParameter<std::string>("errortype");
0067 if (printdebug_) {
0068 edm::LogInfo("SiPixelBadModuleByHandBuilder")
0069 << "now looking at detid " << BadModule.DetID << ", string " << errorstring << std::endl;
0070 }
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089 if (errorstring == "whole") {
0090 BadModule.errorType = 0;
0091 BadModule.BadRocs = 65535;
0092 }
0093 else if (errorstring == "tbmA") {
0094 BadModule.errorType = 1;
0095 BadModule.BadRocs = 255;
0096 }
0097 else if (errorstring == "tbmB") {
0098 BadModule.errorType = 2;
0099 BadModule.BadRocs = 65280;
0100 }
0101 else if (errorstring == "none") {
0102 BadModule.errorType = 3;
0103
0104 std::vector<uint32_t> BadRocList = it->getParameter<std::vector<uint32_t> >("badroclist");
0105 short badrocs = 0;
0106 for (std::vector<uint32_t>::iterator iter = BadRocList.begin(); iter != BadRocList.end(); ++iter) {
0107 badrocs += 1 << *iter;
0108 }
0109 BadModule.BadRocs = badrocs;
0110 }
0111
0112 else
0113 edm::LogError("SiPixelQuality") << "trying to fill error type " << errorstring << ", which is not defined!";
0114 obj->addDisabledModule(BadModule);
0115 }
0116
0117
0118 if (!ROCListFile_.empty()) {
0119 std::map<uint32_t, uint32_t> disabledModules;
0120 std::ifstream aFile(ROCListFile_.c_str());
0121 std::string aLine;
0122 while (std::getline(aFile, aLine)) {
0123 char name[100];
0124 int roc;
0125 sscanf(aLine.c_str(), "%s %d", name, &roc);
0126 uint32_t detId;
0127 if (name[0] == 'B') {
0128 PixelBarrelName bn(name, true);
0129 detId = bn.getDetId(tTopo_.get());
0130 } else {
0131 PixelEndcapName en(name, true);
0132 detId = en.getDetId(tTopo_.get());
0133 }
0134 std::map<uint32_t, uint32_t>::iterator it = disabledModules.find(detId);
0135 if (it == disabledModules.end())
0136 it = disabledModules.insert(disabledModules.begin(), std::make_pair(detId, 0));
0137 it->second |= 1 << roc;
0138
0139 }
0140
0141 for (const auto& it : disabledModules) {
0142 SiPixelQuality::disabledModuleType BadModule;
0143 BadModule.DetID = it.first;
0144 if (it.second == 65535) {
0145 BadModule.errorType = 0;
0146 BadModule.BadRocs = 65535;
0147 }
0148 else if (it.second == 255) {
0149 BadModule.errorType = 1;
0150 BadModule.BadRocs = 255;
0151 }
0152 else if (it.second == 65280) {
0153 BadModule.errorType = 2;
0154 BadModule.BadRocs = 65280;
0155 }
0156 else {
0157 BadModule.errorType = 3;
0158 BadModule.BadRocs = it.second;
0159 }
0160
0161 obj->addDisabledModule(BadModule);
0162 if (printdebug_) {
0163 edm::LogVerbatim("SiPixelBadModuleByHandBuilder")
0164 << "New module added: " << tTopo_->print(BadModule.DetID) << ", errorType: " << BadModule.errorType
0165 << ", BadRocs: " << std::bitset<16>(it.second) << std::endl;
0166 }
0167 }
0168 }
0169
0170 return obj;
0171 }
0172 DEFINE_FWK_MODULE(SiPixelBadModuleByHandBuilder);