CMS 3D CMS Logo

SiStripDcsInfo.cc
Go to the documentation of this file.
4 
7 
9 #include "SiStripDcsInfo.h"
11 
12 #include <iostream>
13 #include <iomanip>
14 #include <cstdio>
15 #include <string>
16 #include <sstream>
17 #include <cmath>
18 
19 //
20 // -- Contructor
21 //
23  : tTopoToken0_(esConsumes<edm::Transition::BeginLuminosityBlock>()),
24  tTopoToken1_(esConsumes<edm::Transition::EndLuminosityBlock>()),
25  tTopoToken2_(esConsumes<edm::Transition::EndRun>()),
26  tTopoToken3_(esConsumes<edm::Transition::BeginRun>()),
27  detVOffToken0_(esConsumes<edm::Transition::BeginLuminosityBlock>()),
28  detVOffToken1_(esConsumes<edm::Transition::EndLuminosityBlock>()),
29  detVOffToken2_(esConsumes<edm::Transition::EndRun>()),
30  detCablingToken_(esConsumes<edm::Transition::BeginRun>()),
31  runInfoToken_(esConsumes<edm::Transition::BeginRun>()) {
32  LogDebug("SiStripDcsInfo") << "SiStripDcsInfo::Deleting SiStripDcsInfo ";
33 }
34 
36  // Since SubDetMEs is a struct, using the brace initialization will
37  // zero-initialize all members that are not specified in the call.
38  SubDetMEsMap.emplace("TIB", SubDetMEs{"TIB", nullptr, 0, {}, {}});
39  SubDetMEsMap.emplace("TOB", SubDetMEs{"TOB", nullptr, 0, {}, {}});
40  SubDetMEsMap.emplace("TECB", SubDetMEs{"TEC/MINUS", nullptr, 0, {}, {}});
41  SubDetMEsMap.emplace("TECF", SubDetMEs{"TEC/PLUS", nullptr, 0, {}, {}});
42  SubDetMEsMap.emplace("TIDB", SubDetMEs{"TID/MINUS", nullptr, 0, {}, {}});
43  SubDetMEsMap.emplace("TIDF", SubDetMEs{"TID/PLUS", nullptr, 0, {}, {}});
44 }
45 //
46 // -- Begin Run
47 //
49  LogDebug("SiStripDcsInfo") << "SiStripDcsInfo:: Begining of Run";
50  nFEDConnected_ = 0;
51  constexpr int siStripFedIdMin{FEDNumbering::MINSiStripFEDID};
52  constexpr int siStripFedIdMax{FEDNumbering::MAXSiStripFEDID};
53 
54  // Count Tracker FEDs from RunInfo
55  //
56  if (eSetup.tryToGet<RunInfoRcd>()) {
57  if (auto sumFED = eSetup.getHandle(runInfoToken_)) {
58  std::vector<int> FedsInIds = sumFED->m_fed_in;
59  for (unsigned int it = 0; it < FedsInIds.size(); ++it) {
60  int fedID = FedsInIds[it];
61  if (fedID >= siStripFedIdMin && fedID <= siStripFedIdMax)
63  }
64  LogDebug("SiStripDcsInfo") << " SiStripDcsInfo :: Connected FEDs " << nFEDConnected_;
65  }
66  }
67 
68  auto& dqm_store = *edm::Service<DQMStore>{};
69  bookStatus(dqm_store);
70  fillDummyStatus(dqm_store);
71  if (nFEDConnected_ > 0)
72  readCabling(eSetup);
73 }
74 
76 
78  LogDebug("SiStripDcsInfo") << "SiStripDcsInfo::beginLuminosityBlock";
79 
80  if (nFEDConnected_ == 0)
81  return;
82 
83  // initialise BadModule list
84  for (auto& subDetME : SubDetMEsMap) {
85  subDetME.second.FaultyDetectors.clear();
86  }
87  readStatus(eSetup, 0);
89 }
90 
92  LogDebug("SiStripDcsInfo") << "SiStripDcsInfo::endLuminosityBlock";
93 
94  if (nFEDConnected_ == 0)
95  return;
96  auto& dqm_store = *edm::Service<DQMStore>{};
97  readStatus(eSetup, 1);
98  fillStatus(dqm_store);
99 }
100 
101 void SiStripDcsInfo::endRun(edm::Run const& run, edm::EventSetup const& eSetup) {
102  LogDebug("SiStripDcsInfo") << "SiStripDcsInfo::EndRun";
103 
104  if (nFEDConnected_ == 0)
105  return;
106 
107  for (auto& subDetME : SubDetMEsMap) {
108  subDetME.second.FaultyDetectors.clear();
109  }
110  readStatus(eSetup, 2);
111  auto& dqm_store = *edm::Service<DQMStore>{};
112  addBadModules(dqm_store);
113 }
114 //
115 // -- Book MEs for SiStrip Dcs Fraction
116 //
118  if (bookedStatus_)
119  return;
120 
121  std::string strip_dir = "";
122  SiStripUtility::getTopFolderPath(dqm_store, "SiStrip", strip_dir);
123  if (!strip_dir.empty())
124  dqm_store.setCurrentFolder(strip_dir + "/EventInfo");
125  else
126  dqm_store.setCurrentFolder("SiStrip/EventInfo");
127 
128  auto scope = DQMStore::UseLumiScope(dqm_store);
129 
130  DcsFraction_ = dqm_store.bookFloat("DCSSummary");
131 
132  dqm_store.cd();
133  if (!strip_dir.empty())
134  dqm_store.setCurrentFolder(strip_dir + "/EventInfo/DCSContents");
135  else
136  dqm_store.setCurrentFolder("SiStrip/EventInfo/DCSContents");
137  for (auto& [suffix, subDetME] : SubDetMEsMap) {
138  std::string const me_name{"SiStrip_" + suffix};
139  subDetME.DcsFractionME = dqm_store.bookFloat(me_name);
140  }
141  bookedStatus_ = true;
142  dqm_store.cd();
143 }
144 
146  const auto tTopo = &eSetup.getData(tTopoToken3_);
147 
148  if (fedCablingWatcher_.check(eSetup)) {
149  LogDebug("SiStripDcsInfo") << "SiStripDcsInfo::readCabling : "
150  << " Change in Cache";
152 
153  std::vector<uint32_t> SelectedDetIds;
154  detCabling_->addActiveDetectorsRawIds(SelectedDetIds);
155  LogDebug("SiStripDcsInfo") << " SiStripDcsInfo::readCabling : "
156  << " Total Detectors " << SelectedDetIds.size();
157 
158  // initialise total # of detectors first
159  for (std::map<std::string, SubDetMEs>::iterator it = SubDetMEsMap.begin(); it != SubDetMEsMap.end(); it++) {
160  it->second.TotalDetectors = 0;
161  }
162 
163  for (std::vector<uint32_t>::const_iterator idetid = SelectedDetIds.begin(); idetid != SelectedDetIds.end();
164  ++idetid) {
165  uint32_t detId = *idetid;
166  if (detId == 0 || detId == 0xFFFFFFFF)
167  continue;
170 
171  std::map<std::string, SubDetMEs>::iterator iPos = SubDetMEsMap.find(subdet_tag);
172  if (iPos != SubDetMEsMap.end()) {
173  iPos->second.TotalDetectors++;
174  }
175  }
176  }
177 }
178 //
179 // -- Get Faulty Detectors
180 //
181 void SiStripDcsInfo::readStatus(edm::EventSetup const& eSetup, int transition) {
182  const auto tTopo = &eSetup.getData(transition == 0 ? tTopoToken0_ : (transition == 1 ? tTopoToken1_ : tTopoToken2_));
183  const auto& detVOff =
184  eSetup.getData(transition == 0 ? detVOffToken0_ : (transition == 1 ? detVOffToken1_ : detVOffToken2_));
185  std::vector<uint32_t> FaultyDetIds;
186  detVOff.getDetIds(FaultyDetIds);
187  LogDebug("SiStripDcsInfo") << " SiStripDcsInfo::readStatus : "
188  << " Faulty Detectors " << FaultyDetIds.size();
189  // Read and fille bad modules
190  for (std::vector<uint32_t>::const_iterator ihvoff = FaultyDetIds.begin(); ihvoff != FaultyDetIds.end(); ++ihvoff) {
191  uint32_t detId_hvoff = (*ihvoff);
192  if (!detCabling_->IsConnected(detId_hvoff))
193  continue;
195  SiStripUtility::getSubDetectorTag(detId_hvoff, subdet_tag, tTopo);
196 
197  std::map<std::string, SubDetMEs>::iterator iPos = SubDetMEsMap.find(subdet_tag);
198  if (iPos != SubDetMEsMap.end()) {
199  std::vector<uint32_t>::iterator ibad =
200  std::find(iPos->second.FaultyDetectors.begin(), iPos->second.FaultyDetectors.end(), detId_hvoff);
201  if (ibad == iPos->second.FaultyDetectors.end())
202  iPos->second.FaultyDetectors.push_back(detId_hvoff);
203  }
204  }
205 }
206 //
207 // -- Fill Status
208 //
210  if (!bookedStatus_)
211  bookStatus(dqm_store);
213 
214  float total_det = 0.0;
215  float faulty_det = 0.0;
216  float fraction;
217  for (auto const& [name, subDetMEs] : SubDetMEsMap) {
218  int total_subdet = subDetMEs.TotalDetectors;
219  int faulty_subdet = subDetMEs.FaultyDetectors.size();
220  if (nFEDConnected_ == 0 || total_subdet == 0)
221  fraction = -1;
222  else
223  fraction = 1.0 - faulty_subdet * 1.0 / total_subdet;
224  subDetMEs.DcsFractionME->Reset();
225  subDetMEs.DcsFractionME->Fill(fraction);
226  edm::LogInfo("SiStripDcsInfo") << " SiStripDcsInfo::fillStatus : Sub Detector " << name << " Total Number "
227  << total_subdet << " Faulty ones " << faulty_subdet;
228  total_det += total_subdet;
229  faulty_det += faulty_subdet;
230  }
231  if (nFEDConnected_ == 0 || total_det == 0)
232  fraction = -1.0;
233  else
234  fraction = 1 - faulty_det / total_det;
235  DcsFraction_->Reset();
238  if (!IsLumiGoodDcs_)
239  return;
240 
241  ++nGoodDcsLumi_;
242  for (auto& pr : SubDetMEsMap) {
243  for (auto const detId_faulty : pr.second.FaultyDetectors) {
244  pr.second.NLumiDetectorIsFaulty[detId_faulty]++;
245  }
246  }
247 }
248 
249 //
250 // -- Fill with Dummy values
251 //
253  if (!bookedStatus_)
254  bookStatus(dqm_store);
256 
257  for (auto& pr : SubDetMEsMap) {
258  pr.second.DcsFractionME->Reset();
259  pr.second.DcsFractionME->Fill(-1.0);
260  }
261  DcsFraction_->Reset();
262  DcsFraction_->Fill(-1.0);
263 }
264 
266  dqm_store.cd();
267  std::string mdir = "MechanicalView";
268  if (!SiStripUtility::goToDir(dqm_store, mdir)) {
269  dqm_store.setCurrentFolder("SiStrip/" + mdir);
270  }
271  std::string mechanical_dir = dqm_store.pwd();
272  std::string tag = "DCSError";
273 
274  for (auto const& pr : SubDetMEsMap) {
275  auto const& lumiCountBadModules = pr.second.NLumiDetectorIsFaulty;
276  for (auto const [ibad, nBadLumi] : lumiCountBadModules) {
277  if (nBadLumi <= MaxAcceptableBadDcsLumi_)
278  continue;
279  std::string bad_module_folder = mechanical_dir + "/" + pr.second.folder_name +
280  "/"
281  "BadModuleList";
282  dqm_store.setCurrentFolder(bad_module_folder);
283 
284  std::ostringstream detid_str;
285  detid_str << ibad;
286  std::string full_path = bad_module_folder + "/" + detid_str.str();
287  MonitorElement* me = dqm_store.get(full_path);
288  uint16_t flag = 0;
289  if (me) {
290  flag = me->getIntValue();
291  me->Reset();
292  } else
293  me = dqm_store.bookInt(detid_str.str());
295  me->Fill(flag);
296  }
297  }
298  dqm_store.cd();
299 }
300 
edm::ESWatcher::check
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:52
SiStripDetCabling::addActiveDetectorsRawIds
void addActiveDetectorsRawIds(std::vector< uint32_t > &) const
Definition: SiStripDetCabling.cc:134
SiStripDcsInfo
Definition: SiStripDcsInfo.h:50
MessageLogger.h
SiStripFolderOrganizer.h
dqm::implementation::IBooker::bookFloat
MonitorElement * bookFloat(TString const &name, FUNC onbooking=NOOP())
Definition: DQMStore.h:80
edm::LuminosityBlock
Definition: LuminosityBlock.h:50
edm::Run
Definition: Run.h:45
edm
HLT enums.
Definition: AlignableModifier.h:19
SiStripDcsInfo::SubDetMEs
Definition: SiStripDcsInfo.h:74
SiStripDcsInfo::beginJob
void beginJob() override
Definition: SiStripDcsInfo.cc:35
cms::cuda::assert
assert(be >=bs)
DQMStore.h
dqm::legacy::MonitorElement
Definition: MonitorElement.h:462
SiStripDcsInfo::nGoodDcsLumi_
int nGoodDcsLumi_
Definition: SiStripDcsInfo.h:91
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
SiStripUtility.h
createPayload.suffix
suffix
Definition: createPayload.py:281
SiStripDcsInfo::endRun
void endRun(edm::Run const &run, edm::EventSetup const &eSetup) override
Definition: SiStripDcsInfo.cc:101
SiStripDcsInfo::MaxAcceptableBadDcsLumi_
static constexpr float MaxAcceptableBadDcsLumi_
Definition: SiStripDcsInfo.h:93
SiStripDcsInfo::readCabling
void readCabling(edm::EventSetup const &)
Definition: SiStripDcsInfo.cc:145
SiStripDcsInfo::tTopoToken2_
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > tTopoToken2_
Definition: SiStripDcsInfo.h:96
SiStripDcsInfo::detVOffToken0_
edm::ESGetToken< SiStripDetVOff, SiStripDetVOffRcd > detVOffToken0_
Definition: SiStripDcsInfo.h:97
SiStripDcsInfo::nFEDConnected_
int nFEDConnected_
Definition: SiStripDcsInfo.h:86
SiStripDcsInfo::detVOffToken1_
edm::ESGetToken< SiStripDetVOff, SiStripDetVOffRcd > detVOffToken1_
Definition: SiStripDcsInfo.h:97
MakerMacros.h
SiStripDcsInfo::readStatus
void readStatus(edm::EventSetup const &, int transition)
Definition: SiStripDcsInfo.cc:181
SiStripDcsInfo::tTopoToken3_
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > tTopoToken3_
Definition: SiStripDcsInfo.h:96
SiStripDcsInfo::beginRun
void beginRun(edm::Run const &run, edm::EventSetup const &eSetup) override
Definition: SiStripDcsInfo.cc:48
edm::EventSetup::tryToGet
std::optional< T > tryToGet() const
Definition: EventSetup.h:108
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
dqm::legacy::DQMStore
Definition: DQMStore.h:727
SiStripDcsInfo::bookedStatus_
bool bookedStatus_
Definition: SiStripDcsInfo.h:84
GlobalPosition_Frontier_DevDB_cff.tag
tag
Definition: GlobalPosition_Frontier_DevDB_cff.py:11
HLT_FULL_cff.fraction
fraction
Definition: HLT_FULL_cff.py:52802
Service.h
dqm::impl::MonitorElement::Fill
void Fill(long long x)
Definition: MonitorElement.h:290
SiStripDcsInfo::bookStatus
void bookStatus(DQMStore &dqm_store)
Definition: SiStripDcsInfo.cc:117
SiStripDcsInfo::addBadModules
void addBadModules(DQMStore &dqm_store)
Definition: SiStripDcsInfo.cc:265
dqm::impl::MonitorElement::Reset
virtual void Reset()
Remove all data from the ME, keept the empty histogram with all its settings.
Definition: MonitorElement.cc:354
SiStripDcsInfo::nLumiAnalysed_
int nLumiAnalysed_
Definition: SiStripDcsInfo.h:88
dqm::implementation::DQMStore::setCurrentFolder
void setCurrentFolder(std::string const &fullpath) override
Definition: DQMStore.h:569
SiStripDetCabling::IsConnected
bool IsConnected(const uint32_t &det_id) const
Definition: SiStripDetCabling.cc:375
SiStripDcsInfo::fedCablingWatcher_
edm::ESWatcher< SiStripFedCablingRcd > fedCablingWatcher_
Definition: SiStripDcsInfo.h:98
SiStripDcsInfo::runInfoToken_
edm::ESGetToken< RunInfo, RunInfoRcd > runInfoToken_
Definition: SiStripDcsInfo.h:100
SiStripDcsInfo::SubDetMEsMap
std::map< std::string, SubDetMEs > SubDetMEsMap
Definition: SiStripDcsInfo.h:82
RunInfoRcd
Definition: RunSummaryRcd.h:26
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
dqm::implementation::DQMStore::pwd
std::string pwd() override
Definition: DQMStore.h:567
SiStripDcsInfo::beginLuminosityBlock
void beginLuminosityBlock(edm::LuminosityBlock const &lumiSeg, edm::EventSetup const &eSetup) override
Definition: SiStripDcsInfo.cc:77
FEDNumbering::MAXSiStripFEDID
Definition: FEDNumbering.h:30
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
SiStripDcsInfo::tTopoToken0_
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > tTopoToken0_
Definition: SiStripDcsInfo.h:96
edm::ParameterSet
Definition: ParameterSet.h:47
edm::Transition
Transition
Definition: Transition.h:12
sipixeldigitoraw
Definition: SiPixelDigiToRaw.cc:39
SiStripDcsInfo::fillStatus
void fillStatus(DQMStore &dqm_store)
Definition: SiStripDcsInfo.cc:209
SiStripDcsInfo::fillDummyStatus
void fillDummyStatus(DQMStore &dqm_store)
Definition: SiStripDcsInfo.cc:252
SiStripDcsInfo::IsLumiGoodDcs_
bool IsLumiGoodDcs_
Definition: SiStripDcsInfo.h:90
SiStripUtility::goToDir
static bool goToDir(DQMStore &dqm_store, std::string const &name)
Definition: SiStripUtility.cc:252
dqm::implementation::IBooker::bookInt
MonitorElement * bookInt(TString const &name, FUNC onbooking=NOOP())
Definition: DQMStore.h:73
edm::Service
Definition: Service.h:30
SiStripDcsInfo::DcsFraction_
MonitorElement * DcsFraction_
Definition: SiStripDcsInfo.h:72
edm::EventSetup::getHandle
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:155
SiStripDcsInfo::endLuminosityBlock
void endLuminosityBlock(edm::LuminosityBlock const &lumiSeg, edm::EventSetup const &iSetup) override
Definition: SiStripDcsInfo.cc:91
dqm::implementation::IBooker::UseLumiScope
UseScope< MonitorElementData::Scope::LUMI > UseLumiScope
Definition: DQMStore.h:463
edm::EventSetup
Definition: EventSetup.h:58
SiStripDcsInfo::SiStripDcsInfo
SiStripDcsInfo(const edm::ParameterSet &ps)
Definition: SiStripDcsInfo.cc:22
SiStripUtility::getSubDetectorTag
static void getSubDetectorTag(uint32_t det_id, std::string &subdet_tag, const TrackerTopology *tTopo)
Definition: SiStripUtility.cc:296
edm::EventSetup::getData
bool getData(T &iHolder) const
Definition: EventSetup.h:127
RunInfo.h
writedatasetfile.run
run
Definition: writedatasetfile.py:27
SiStripDcsInfo.h
SiStripDcsInfo::tTopoToken1_
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > tTopoToken1_
Definition: SiStripDcsInfo.h:96
dqm::implementation::IGetter::get
virtual MonitorElement * get(std::string const &fullpath) const
Definition: DQMStore.cc:651
SiStripDcsInfo::detCabling_
const SiStripDetCabling * detCabling_
Definition: SiStripDcsInfo.h:95
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
SiStripDcsInfo::analyze
void analyze(edm::Event const &, edm::EventSetup const &) override
Definition: SiStripDcsInfo.cc:75
SiStripDcsInfo::MinAcceptableDcsDetFrac_
static constexpr float MinAcceptableDcsDetFrac_
Definition: SiStripDcsInfo.h:92
ParameterSet.h
SiStripDcsInfo::detCablingToken_
edm::ESGetToken< SiStripDetCabling, SiStripDetCablingRcd > detCablingToken_
Definition: SiStripDcsInfo.h:99
hlt_dqm_clientPB-live_cfg.me
me
Definition: hlt_dqm_clientPB-live_cfg.py:61
SiStripDcsInfo::detVOffToken2_
edm::ESGetToken< SiStripDetVOff, SiStripDetVOffRcd > detVOffToken2_
Definition: SiStripDcsInfo.h:97
xuti::subdet_tag
const std::string subdet_tag("SubDet")
event
Definition: event.py:1
DeDxTools::esConsumes
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
edm::Event
Definition: Event.h:73
SiStripUtility::setBadModuleFlag
static void setBadModuleFlag(std::string &hname, uint16_t &flg)
Definition: SiStripUtility.cc:328
SiStripUtility::getTopFolderPath
static void getTopFolderPath(DQMStore &dqm_store, std::string const &top_dir, std::string &path)
Definition: SiStripUtility.cc:362
dqm::implementation::DQMStore::cd
void cd() override
Definition: DQMStore.h:564
RemoveAddSevLevel.flag
flag
Definition: RemoveAddSevLevel.py:116
FEDNumbering::MINSiStripFEDID
Definition: FEDNumbering.h:29