CMS 3D CMS Logo

SiStripDcsInfo.cc
Go to the documentation of this file.
4 
6 
8 #include "SiStripDcsInfo.h"
10 
15 
16 //Run Info
21 
22 #include <iostream>
23 #include <iomanip>
24 #include <cstdio>
25 #include <string>
26 #include <sstream>
27 #include <cmath>
28 
29 //
30 // -- Contructor
31 //
33  LogDebug("SiStripDcsInfo") << "SiStripDcsInfo::Deleting SiStripDcsInfo ";
34 }
35 
37  // Since SubDetMEs is a struct, using the brace initialization will
38  // zero-initialize all members that are not specified in the call.
39  SubDetMEsMap.emplace("TIB", SubDetMEs{"TIB", nullptr, 0, {}, {}});
40  SubDetMEsMap.emplace("TOB", SubDetMEs{"TOB", nullptr, 0, {}, {}});
41  SubDetMEsMap.emplace("TECB", SubDetMEs{"TEC/MINUS", nullptr, 0, {}, {}});
42  SubDetMEsMap.emplace("TECF", SubDetMEs{"TEC/PLUS", nullptr, 0, {}, {}});
43  SubDetMEsMap.emplace("TIDB", SubDetMEs{"TID/MINUS", nullptr, 0, {}, {}});
44  SubDetMEsMap.emplace("TIDF", SubDetMEs{"TID/PLUS", nullptr, 0, {}, {}});
45 }
46 //
47 // -- Begin Run
48 //
50  LogDebug("SiStripDcsInfo") << "SiStripDcsInfo:: Begining of Run";
51  nFEDConnected_ = 0;
52  constexpr int siStripFedIdMin{FEDNumbering::MINSiStripFEDID};
53  constexpr int siStripFedIdMax{FEDNumbering::MAXSiStripFEDID};
54 
55  // Count Tracker FEDs from RunInfo
56 
57  if (auto runInfoRec = eSetup.tryToGet<RunInfoRcd>()) {
59  runInfoRec->get(sumFED);
60 
61  if (sumFED.isValid()) {
62  std::vector<int> FedsInIds = sumFED->m_fed_in;
63  for (unsigned int it = 0; it < FedsInIds.size(); ++it) {
64  int fedID = FedsInIds[it];
65  if (fedID >= siStripFedIdMin && fedID <= siStripFedIdMax)
67  }
68  LogDebug("SiStripDcsInfo") << " SiStripDcsInfo :: Connected FEDs " << nFEDConnected_;
69  }
70  }
71 
72  auto& dqm_store = *edm::Service<DQMStore>{};
73  bookStatus(dqm_store);
74  fillDummyStatus(dqm_store);
75  if (nFEDConnected_ > 0)
76  readCabling(eSetup);
77 }
78 
80 
82  LogDebug("SiStripDcsInfo") << "SiStripDcsInfo::beginLuminosityBlock";
83 
84  if (nFEDConnected_ == 0)
85  return;
86 
87  // initialise BadModule list
88  for (auto& subDetME : SubDetMEsMap) {
89  subDetME.second.FaultyDetectors.clear();
90  }
91  readStatus(eSetup);
93 }
94 
96  LogDebug("SiStripDcsInfo") << "SiStripDcsInfo::endLuminosityBlock";
97 
98  if (nFEDConnected_ == 0)
99  return;
100  auto& dqm_store = *edm::Service<DQMStore>{};
101  readStatus(eSetup);
102  fillStatus(dqm_store);
103 }
104 
105 void SiStripDcsInfo::endRun(edm::Run const& run, edm::EventSetup const& eSetup) {
106  LogDebug("SiStripDcsInfo") << "SiStripDcsInfo::EndRun";
107 
108  if (nFEDConnected_ == 0)
109  return;
110 
111  for (auto& subDetME : SubDetMEsMap) {
112  subDetME.second.FaultyDetectors.clear();
113  }
114  readStatus(eSetup);
115  auto& dqm_store = *edm::Service<DQMStore>{};
116  addBadModules(dqm_store);
117 }
118 //
119 // -- Book MEs for SiStrip Dcs Fraction
120 //
122  if (bookedStatus_)
123  return;
124 
125  std::string strip_dir = "";
126  SiStripUtility::getTopFolderPath(dqm_store, "SiStrip", strip_dir);
127  if (!strip_dir.empty())
128  dqm_store.setCurrentFolder(strip_dir + "/EventInfo");
129  else
130  dqm_store.setCurrentFolder("SiStrip/EventInfo");
131 
132  DcsFraction_ = dqm_store.bookFloat("DCSSummary");
133 
135 
136  dqm_store.cd();
137  if (!strip_dir.empty())
138  dqm_store.setCurrentFolder(strip_dir + "/EventInfo/DCSContents");
139  else
140  dqm_store.setCurrentFolder("SiStrip/EventInfo/DCSContents");
141  for (auto& [suffix, subDetME] : SubDetMEsMap) {
142  std::string const me_name{"SiStrip_" + suffix};
143  subDetME.DcsFractionME = dqm_store.bookFloat(me_name);
144  subDetME.DcsFractionME->setLumiFlag();
145  }
146  bookedStatus_ = true;
147  dqm_store.cd();
148 }
149 
151  //Retrieve tracker topology from geometry
152  edm::ESHandle<TrackerTopology> tTopoHandle;
153  eSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
154  const TrackerTopology* const tTopo = tTopoHandle.product();
155 
156  unsigned long long cacheID = eSetup.get<SiStripFedCablingRcd>().cacheIdentifier();
157  if (m_cacheIDCabling_ != cacheID) {
158  m_cacheIDCabling_ = cacheID;
159  LogDebug("SiStripDcsInfo") << "SiStripDcsInfo::readCabling : "
160  << " Change in Cache";
161  eSetup.get<SiStripDetCablingRcd>().get(detCabling_);
162 
163  std::vector<uint32_t> SelectedDetIds;
164  detCabling_->addActiveDetectorsRawIds(SelectedDetIds);
165  LogDebug("SiStripDcsInfo") << " SiStripDcsInfo::readCabling : "
166  << " Total Detectors " << SelectedDetIds.size();
167 
168  // initialise total # of detectors first
169  for (std::map<std::string, SubDetMEs>::iterator it = SubDetMEsMap.begin(); it != SubDetMEsMap.end(); it++) {
170  it->second.TotalDetectors = 0;
171  }
172 
173  for (std::vector<uint32_t>::const_iterator idetid = SelectedDetIds.begin(); idetid != SelectedDetIds.end();
174  ++idetid) {
175  uint32_t detId = *idetid;
176  if (detId == 0 || detId == 0xFFFFFFFF)
177  continue;
179  SiStripUtility::getSubDetectorTag(detId, subdet_tag, tTopo);
180 
181  std::map<std::string, SubDetMEs>::iterator iPos = SubDetMEsMap.find(subdet_tag);
182  if (iPos != SubDetMEsMap.end()) {
183  iPos->second.TotalDetectors++;
184  }
185  }
186  }
187 }
188 //
189 // -- Get Faulty Detectors
190 //
192  //Retrieve tracker topology from geometry
193  edm::ESHandle<TrackerTopology> tTopoHandle;
194  eSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
195  const TrackerTopology* const tTopo = tTopoHandle.product();
196 
197  eSetup.get<SiStripDetVOffRcd>().get(siStripDetVOff_);
198  std::vector<uint32_t> FaultyDetIds;
199  siStripDetVOff_->getDetIds(FaultyDetIds);
200  LogDebug("SiStripDcsInfo") << " SiStripDcsInfo::readStatus : "
201  << " Faulty Detectors " << FaultyDetIds.size();
202  // Read and fille bad modules
203  for (std::vector<uint32_t>::const_iterator ihvoff = FaultyDetIds.begin(); ihvoff != FaultyDetIds.end(); ++ihvoff) {
204  uint32_t detId_hvoff = (*ihvoff);
205  if (!detCabling_->IsConnected(detId_hvoff))
206  continue;
208  SiStripUtility::getSubDetectorTag(detId_hvoff, subdet_tag, tTopo);
209 
210  std::map<std::string, SubDetMEs>::iterator iPos = SubDetMEsMap.find(subdet_tag);
211  if (iPos != SubDetMEsMap.end()) {
212  std::vector<uint32_t>::iterator ibad =
213  std::find(iPos->second.FaultyDetectors.begin(), iPos->second.FaultyDetectors.end(), detId_hvoff);
214  if (ibad == iPos->second.FaultyDetectors.end())
215  iPos->second.FaultyDetectors.push_back(detId_hvoff);
216  }
217  }
218 }
219 //
220 // -- Fill Status
221 //
223  if (!bookedStatus_)
224  bookStatus(dqm_store);
225  assert(bookedStatus_);
226 
227  float total_det = 0.0;
228  float faulty_det = 0.0;
229  float fraction;
230  for (auto const& [name, subDetMEs] : SubDetMEsMap) {
231  int total_subdet = subDetMEs.TotalDetectors;
232  int faulty_subdet = subDetMEs.FaultyDetectors.size();
233  if (nFEDConnected_ == 0 || total_subdet == 0)
234  fraction = -1;
235  else
236  fraction = 1.0 - faulty_subdet * 1.0 / total_subdet;
237  subDetMEs.DcsFractionME->Reset();
238  subDetMEs.DcsFractionME->Fill(fraction);
239  edm::LogInfo("SiStripDcsInfo") << " SiStripDcsInfo::fillStatus : Sub Detector " << name << " Total Number "
240  << total_subdet << " Faulty ones " << faulty_subdet;
241  total_det += total_subdet;
242  faulty_det += faulty_subdet;
243  }
244  if (nFEDConnected_ == 0 || total_det == 0)
245  fraction = -1.0;
246  else
247  fraction = 1 - faulty_det / total_det;
248  DcsFraction_->Reset();
249  DcsFraction_->Fill(fraction);
251  if (!IsLumiGoodDcs_)
252  return;
253 
254  ++nGoodDcsLumi_;
255  for (auto& pr : SubDetMEsMap) {
256  for (auto const detId_faulty : pr.second.FaultyDetectors) {
257  pr.second.NLumiDetectorIsFaulty[detId_faulty]++;
258  }
259  }
260 }
261 
262 //
263 // -- Fill with Dummy values
264 //
266  if (!bookedStatus_)
267  bookStatus(dqm_store);
268  assert(bookedStatus_);
269 
270  for (auto& pr : SubDetMEsMap) {
271  pr.second.DcsFractionME->Reset();
272  pr.second.DcsFractionME->Fill(-1.0);
273  }
274  DcsFraction_->Reset();
275  DcsFraction_->Fill(-1.0);
276 }
277 
279  dqm_store.cd();
280  std::string mdir = "MechanicalView";
281  if (!SiStripUtility::goToDir(dqm_store, mdir)) {
282  dqm_store.setCurrentFolder("SiStrip/" + mdir);
283  }
284  std::string mechanical_dir = dqm_store.pwd();
285  std::string tag = "DCSError";
286 
287  for (auto const& pr : SubDetMEsMap) {
288  auto const& lumiCountBadModules = pr.second.NLumiDetectorIsFaulty;
289  for (auto const [ibad, nBadLumi] : lumiCountBadModules) {
290  if (nBadLumi <= MaxAcceptableBadDcsLumi_)
291  continue;
292  std::string bad_module_folder = mechanical_dir + "/" + pr.second.folder_name +
293  "/"
294  "BadModuleList";
295  dqm_store.setCurrentFolder(bad_module_folder);
296 
297  std::ostringstream detid_str;
298  detid_str << ibad;
299  std::string full_path = bad_module_folder + "/" + detid_str.str();
300  MonitorElement* me = dqm_store.get(full_path);
301  uint16_t flag = 0;
302  if (me) {
303  flag = me->getIntValue();
304  me->Reset();
305  } else
306  me = dqm_store.bookInt(detid_str.str());
308  me->Fill(flag);
309  }
310  }
311  dqm_store.cd();
312 }
313 
#define LogDebug(id)
static void setBadModuleFlag(std::string &hname, uint16_t &flg)
std::optional< T > tryToGet() const
Definition: EventSetup.h:94
void endLuminosityBlock(edm::LuminosityBlock const &lumiSeg, edm::EventSetup const &iSetup) override
void addActiveDetectorsRawIds(std::vector< uint32_t > &) const
void bookStatus(DQMStore &dqm_store)
SiStripDcsInfo(const edm::ParameterSet &ps)
void setLumiFlag()
this ME is meant to be stored for each luminosity section
virtual int64_t getIntValue() const
std::string const & pwd() const
Definition: DQMStore.cc:618
static float MaxAcceptableBadDcsLumi_
bool IsConnected(const uint32_t &det_id) const
MonitorElement * bookInt(char_string const &name)
Book int.
Definition: DQMStore.cc:1072
void beginLuminosityBlock(edm::LuminosityBlock const &lumiSeg, edm::EventSetup const &eSetup) override
static float MinAcceptableDcsDetFrac_
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
void cd()
go to top directory (ie. root)
Definition: DQMStore.cc:621
void Fill(long long x)
virtual void Reset()
reset ME (ie. contents, errors, etc)
MonitorElement * get(std::string const &path) const
get ME from full pathname (e.g. "my/long/dir/my_histo")
Definition: DQMStore.cc:1509
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void fillStatus(DQMStore &dqm_store)
void getDetIds(std::vector< uint32_t > &DetIds_) const
std::map< std::string, SubDetMEs > SubDetMEsMap
std::vector< int > m_fed_in
Definition: RunInfo.h:25
const std::string subdet_tag("SubDet")
edm::ESHandle< SiStripDetCabling > detCabling_
edm::ESHandle< SiStripDetVOff > siStripDetVOff_
void readCabling(edm::EventSetup const &)
void beginRun(edm::Run const &run, edm::EventSetup const &eSetup) override
MonitorElement * DcsFraction_
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:639
static void getSubDetectorTag(uint32_t det_id, std::string &subdet_tag, const TrackerTopology *tTopo)
void beginJob() override
void endRun(edm::Run const &run, edm::EventSetup const &eSetup) override
void analyze(edm::Event const &, edm::EventSetup const &) override
static bool goToDir(DQMStore &dqm_store, std::string const &name)
T get() const
Definition: EventSetup.h:73
unsigned long long m_cacheIDCabling_
MonitorElement * bookFloat(char_string const &name)
Book float.
Definition: DQMStore.cc:1087
void addBadModules(DQMStore &dqm_store)
bool isValid() const
Definition: ESHandle.h:44
void readStatus(edm::EventSetup const &)
T const * product() const
Definition: ESHandle.h:86
static void getTopFolderPath(DQMStore &dqm_store, std::string const &top_dir, std::string &path)
#define constexpr
Definition: event.py:1
Definition: Run.h:45
void fillDummyStatus(DQMStore &dqm_store)