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 
static void setBadModuleFlag(std::string &hname, uint16_t &flg)
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
void endLuminosityBlock(edm::LuminosityBlock const &lumiSeg, edm::EventSetup const &iSetup) override
MonitorElement * bookFloat(TString const &name, FUNC onbooking=NOOP())
Definition: DQMStore.h:80
void bookStatus(DQMStore &dqm_store)
const SiStripDetCabling * detCabling_
edm::ESGetToken< SiStripDetVOff, SiStripDetVOffRcd > detVOffToken2_
SiStripDcsInfo(const edm::ParameterSet &ps)
edm::ESGetToken< SiStripDetVOff, SiStripDetVOffRcd > detVOffToken0_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void setCurrentFolder(std::string const &fullpath) override
Definition: DQMStore.h:646
std::optional< T > tryToGet() const
Definition: EventSetup.h:103
edm::ESGetToken< SiStripDetCabling, SiStripDetCablingRcd > detCablingToken_
std::string pwd() override
Definition: DQMStore.h:644
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > tTopoToken2_
void beginLuminosityBlock(edm::LuminosityBlock const &lumiSeg, edm::EventSetup const &eSetup) override
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
bool IsConnected(const uint32_t &det_id) const
assert(be >=bs)
edm::ESGetToken< RunInfo, RunInfoRcd > runInfoToken_
void Fill(long long x)
virtual void Reset()
Remove all data from the ME, keept the empty histogram with all its settings.
void fillStatus(DQMStore &dqm_store)
std::map< std::string, SubDetMEs > SubDetMEsMap
edm::ESWatcher< SiStripFedCablingRcd > fedCablingWatcher_
const std::string subdet_tag("SubDet")
Transition
Definition: Transition.h:12
bool getData(T &iHolder) const
Definition: EventSetup.h:122
UseScope< MonitorElementData::Scope::LUMI > UseLumiScope
Definition: DQMStore.h:540
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:151
Log< level::Info, false > LogInfo
static constexpr float MaxAcceptableBadDcsLumi_
void readCabling(edm::EventSetup const &)
void readStatus(edm::EventSetup const &, int transition)
void beginRun(edm::Run const &run, edm::EventSetup const &eSetup) override
MonitorElement * bookInt(TString const &name, FUNC onbooking=NOOP())
Definition: DQMStore.h:73
MonitorElement * DcsFraction_
virtual MonitorElement * get(std::string const &fullpath) const
Definition: DQMStore.cc:673
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
static void getSubDetectorTag(uint32_t det_id, std::string &subdet_tag, const TrackerTopology *tTopo)
void beginJob() override
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > tTopoToken3_
void endRun(edm::Run const &run, edm::EventSetup const &eSetup) override
HLT enums.
void analyze(edm::Event const &, edm::EventSetup const &) override
static bool goToDir(DQMStore &dqm_store, std::string const &name)
edm::ESGetToken< SiStripDetVOff, SiStripDetVOffRcd > detVOffToken1_
void addBadModules(DQMStore &dqm_store)
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > tTopoToken1_
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > tTopoToken0_
static constexpr float MinAcceptableDcsDetFrac_
static void getTopFolderPath(DQMStore &dqm_store, std::string const &top_dir, std::string &path)
Definition: event.py:1
Definition: Run.h:45
void addActiveDetectorsRawIds(std::vector< uint32_t > &) const
void fillDummyStatus(DQMStore &dqm_store)
#define LogDebug(id)