14 void fillFedBadChannelMap(
const TH2F* th2,
18 std::map<uint32_t, std::set<int>>& detectorMap) {
19 for (uint16_t
i = 1;
i < th2->GetNbinsY() + 1; ++
i) {
20 for (uint16_t
j = 1;
j < th2->GetNbinsX() + 1; ++
j) {
21 if (th2->GetBinContent(
j,
i) > cutoff * entries) {
22 const uint16_t fId = th2->GetYaxis()->GetBinLowEdge(
i);
24 <<
" [SiStripBadModuleFedErrService::getFedBadChannelList] :: FedId & Channel " << fId <<
" "
25 << th2->GetXaxis()->GetBinLowEdge(
j);
26 const uint16_t fChan = uint16_t(th2->GetXaxis()->GetBinLowEdge(
j)) / 2;
27 if (!((fId == 9999) && (fChan == 9999))) {
29 detectorMap[channel.detId()].insert(channel.apvPairNumber());
48 std::map<uint32_t, std::set<int>> getBadChannelDetectorMap(
DQMStore::IGetter& dqmStore,
51 std::map<uint32_t, std::set<int>> detectorMap;
59 float entries = getProcessedEvents(dqmStore);
61 edm::LogWarning(
"SiStripBadModuleFedErrService") <<
"Normalising to the largest bin";
62 entries = th2->GetBinContent(th2->GetMaximumBin());
64 fillFedBadChannelMap(th2, entries, cutoff, fedCabling, detectorMap);
66 edm::LogError(
"SiStripBadModuleFedErrService") <<
"Could not find SiStrip/ReadoutView/FedIdVsApvId";
69 edm::LogError(
"SiStripBadModuleFedErrService") <<
"Could not find SiStrip/ReadoutView";
74 TDirectoryFile* checkAndGetSubdir(TDirectoryFile* tdir,
const std::vector<std::string>&
path) {
75 for (
const auto& subName : path) {
76 tdir = tdir->Get<TDirectoryFile>(subName.c_str());
84 std::map<uint32_t, std::set<int>> getBadChannelDetectorMap(TFile* legacyDQMTDirFile,
88 std::map<uint32_t, std::set<int>> detectorMap;
89 const auto stripROVDir = checkAndGetSubdir(
90 legacyDQMTDirFile, {
"DQMData",
"Run " +
std::to_string(runNumber),
"SiStrip",
"Run summary",
"ReadoutView"});
93 <<
"Could not find SiStrip/ReadoutView directory in " << legacyDQMTDirFile->GetName() <<
" with run number "
96 const auto th2 = stripROVDir->Get<TH2F>(
"FedIdVsApvId");
99 <<
"Could not find SiStrip/ReadoutView/FedIdVsApvId in " << legacyDQMTDirFile->GetName();
102 const auto nActChan = stripROVDir->Get<TH1F>(
"nTotalBadActiveChannels");
104 entries = nActChan->GetEntries();
107 edm::LogWarning(
"SiStripBadModuleFedErrService") <<
"Normalising to the largest bin";
108 entries = th2->GetBinContent(th2->GetMaximumBin());
110 fillFedBadChannelMap(th2, entries, cutoff, fedCabling, detectorMap);
117 for (
const auto& detElm : detectorMap) {
119 unsigned short firstBadStrip{0};
120 unsigned short fNconsecutiveBadStrips{0};
122 for (
const auto pair : detElm.second) {
123 if (last_pair == -1) {
124 firstBadStrip = pair * 128 * 2;
125 fNconsecutiveBadStrips = 128 * 2;
126 }
else if (pair - last_pair > 1) {
127 theSiStripVector.push_back(quality->
encode(firstBadStrip, fNconsecutiveBadStrips));
128 firstBadStrip = pair * 128 * 2;
129 fNconsecutiveBadStrips = 128 * 2;
131 fNconsecutiveBadStrips += 128 * 2;
135 unsigned int theBadStripRange = quality->
encode(firstBadStrip, fNconsecutiveBadStrips);
136 theSiStripVector.push_back(theBadStripRange);
139 <<
" SiStripBadModuleFedErrService::readBadComponentsFromFed "
140 <<
" detid " << detElm.first <<
" firstBadStrip " << firstBadStrip <<
" NconsecutiveBadStrips "
141 << fNconsecutiveBadStrips <<
" packed integer " << std::hex << theBadStripRange <<
std::dec;
145 <<
"[SiStripBadModuleFedErrService::readBadComponentsFromFed] detid already exists";
157 auto quality = std::make_unique<SiStripQuality>(detInfo);
158 auto detectorMap = getBadChannelDetectorMap(dqmStore, fedCabling, cutoff);
159 if (!detectorMap.empty()) {
160 fillQuality(quality.get(), detectorMap);
163 edm::LogWarning(
"SiStripBadModuleFedErrService") <<
"Empty bad channel map from FED errors";
169 unsigned int runNumber,
174 auto quality = std::make_unique<SiStripQuality>(detInfo);
175 auto tdirFile = TFile::Open(fileName.c_str());
176 auto detectorMap = getBadChannelDetectorMap(tdirFile, runNumber, fedCabling, cutoff);
177 if (!detectorMap.empty()) {
178 fillQuality(quality.get(), detectorMap);
181 edm::LogWarning(
"SiStripBadModuleFedErrService") <<
"Empty bad channel map from FED errors";
205 std::unique_ptr<SiStripQuality> fedErrQuality{};
207 edm::LogInfo(
"SiStripQuality") <<
"Adding bad components from FED errors in DQM store";
210 edm::LogInfo(
"SiStripQuality") <<
"Adding bad components from FED errors in legacy DQM file "
virtual TH2F * getTH2F() const
bool endRun(const edm::EventSetup &)
FedChannelConnection fedConnection(uint16_t fed_id, uint16_t fed_ch) const
std::unique_ptr< SiStripFedCabling > fedCabling_
edm::ESWatcher< SiStripQualityRcd > stripQualityWatcher_
dqm::legacy::DQMStore DQMStore
std::unique_ptr< SiStripQuality > badStripFromFedErr(dqm::harvesting::DQMStore::IGetter &dqmStore, const SiStripFedCabling &fedCabling, float cutoff)
edm::ESGetToken< SiStripFedCabling, SiStripFedCablingRcd > fedCablingToken_
Kind kind() const
Get the type of the monitor element.
std::string to_string(const V &value)
virtual bool dirExists(std::string const &path) const
Log< level::Error, false > LogError
edm::ESGetToken< SiStripQuality, SiStripQualityRcd > stripQualityToken_
bool getData(T &iHolder) const
std::string fedErrLegacyFile_
virtual double getEntries() const
get # of entries
virtual MonitorElement * get(std::string const &fullpath) const
SiStripDetInfo read(std::string filePath)
dqm::legacy::MonitorElement MonitorElement
unsigned int fedErrFileRunNumber_
Log< level::Info, false > LogInfo
bool addBadCompFromFedErr_
std::unique_ptr< SiStripQuality > mergedQuality_
const SiStripQuality & getMergedQuality(dqm::harvesting::DQMStore::IGetter &getter)
Contains cabling info at the device level, including DetId, APV pair numbers, hardware addresses...
bool check(const edm::EventSetup &iSetup)
std::pair< ContainerIterator, ContainerIterator > Range
static constexpr char const *const kDefaultFile
Log< level::Warning, false > LogWarning
bool put(const uint32_t &detID, const InputVector &vect)
unsigned int encode(const unsigned short &first, const unsigned short &NconsecutiveBadStrips, const unsigned short &flag=0)
std::unique_ptr< SiStripQuality > badStripFromFedErrLegacyDQMFile(const std::string &fileName, unsigned int runNumber, const SiStripFedCabling &fedCabling, float cutoff)