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  auto scope = DQMStore::UseLumiScope(dqm_store);
133 
134  DcsFraction_ = dqm_store.bookFloat("DCSSummary");
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  }
145  bookedStatus_ = true;
146  dqm_store.cd();
147 }
148 
150  //Retrieve tracker topology from geometry
151  edm::ESHandle<TrackerTopology> tTopoHandle;
152  eSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
153  const TrackerTopology* const tTopo = tTopoHandle.product();
154 
155  unsigned long long cacheID = eSetup.get<SiStripFedCablingRcd>().cacheIdentifier();
156  if (m_cacheIDCabling_ != cacheID) {
157  m_cacheIDCabling_ = cacheID;
158  LogDebug("SiStripDcsInfo") << "SiStripDcsInfo::readCabling : "
159  << " Change in Cache";
161 
162  std::vector<uint32_t> SelectedDetIds;
163  detCabling_->addActiveDetectorsRawIds(SelectedDetIds);
164  LogDebug("SiStripDcsInfo") << " SiStripDcsInfo::readCabling : "
165  << " Total Detectors " << SelectedDetIds.size();
166 
167  // initialise total # of detectors first
168  for (std::map<std::string, SubDetMEs>::iterator it = SubDetMEsMap.begin(); it != SubDetMEsMap.end(); it++) {
169  it->second.TotalDetectors = 0;
170  }
171 
172  for (std::vector<uint32_t>::const_iterator idetid = SelectedDetIds.begin(); idetid != SelectedDetIds.end();
173  ++idetid) {
174  uint32_t detId = *idetid;
175  if (detId == 0 || detId == 0xFFFFFFFF)
176  continue;
179 
180  std::map<std::string, SubDetMEs>::iterator iPos = SubDetMEsMap.find(subdet_tag);
181  if (iPos != SubDetMEsMap.end()) {
182  iPos->second.TotalDetectors++;
183  }
184  }
185  }
186 }
187 //
188 // -- Get Faulty Detectors
189 //
191  //Retrieve tracker topology from geometry
192  edm::ESHandle<TrackerTopology> tTopoHandle;
193  eSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
194  const TrackerTopology* const tTopo = tTopoHandle.product();
195 
197  std::vector<uint32_t> FaultyDetIds;
198  siStripDetVOff_->getDetIds(FaultyDetIds);
199  LogDebug("SiStripDcsInfo") << " SiStripDcsInfo::readStatus : "
200  << " Faulty Detectors " << FaultyDetIds.size();
201  // Read and fille bad modules
202  for (std::vector<uint32_t>::const_iterator ihvoff = FaultyDetIds.begin(); ihvoff != FaultyDetIds.end(); ++ihvoff) {
203  uint32_t detId_hvoff = (*ihvoff);
204  if (!detCabling_->IsConnected(detId_hvoff))
205  continue;
207  SiStripUtility::getSubDetectorTag(detId_hvoff, subdet_tag, tTopo);
208 
209  std::map<std::string, SubDetMEs>::iterator iPos = SubDetMEsMap.find(subdet_tag);
210  if (iPos != SubDetMEsMap.end()) {
211  std::vector<uint32_t>::iterator ibad =
212  std::find(iPos->second.FaultyDetectors.begin(), iPos->second.FaultyDetectors.end(), detId_hvoff);
213  if (ibad == iPos->second.FaultyDetectors.end())
214  iPos->second.FaultyDetectors.push_back(detId_hvoff);
215  }
216  }
217 }
218 //
219 // -- Fill Status
220 //
222  if (!bookedStatus_)
223  bookStatus(dqm_store);
225 
226  float total_det = 0.0;
227  float faulty_det = 0.0;
228  float fraction;
229  for (auto const& [name, subDetMEs] : SubDetMEsMap) {
230  int total_subdet = subDetMEs.TotalDetectors;
231  int faulty_subdet = subDetMEs.FaultyDetectors.size();
232  if (nFEDConnected_ == 0 || total_subdet == 0)
233  fraction = -1;
234  else
235  fraction = 1.0 - faulty_subdet * 1.0 / total_subdet;
236  subDetMEs.DcsFractionME->Reset();
237  subDetMEs.DcsFractionME->Fill(fraction);
238  edm::LogInfo("SiStripDcsInfo") << " SiStripDcsInfo::fillStatus : Sub Detector " << name << " Total Number "
239  << total_subdet << " Faulty ones " << faulty_subdet;
240  total_det += total_subdet;
241  faulty_det += faulty_subdet;
242  }
243  if (nFEDConnected_ == 0 || total_det == 0)
244  fraction = -1.0;
245  else
246  fraction = 1 - faulty_det / total_det;
247  DcsFraction_->Reset();
250  if (!IsLumiGoodDcs_)
251  return;
252 
253  ++nGoodDcsLumi_;
254  for (auto& pr : SubDetMEsMap) {
255  for (auto const detId_faulty : pr.second.FaultyDetectors) {
256  pr.second.NLumiDetectorIsFaulty[detId_faulty]++;
257  }
258  }
259 }
260 
261 //
262 // -- Fill with Dummy values
263 //
265  if (!bookedStatus_)
266  bookStatus(dqm_store);
268 
269  for (auto& pr : SubDetMEsMap) {
270  pr.second.DcsFractionME->Reset();
271  pr.second.DcsFractionME->Fill(-1.0);
272  }
273  DcsFraction_->Reset();
274  DcsFraction_->Fill(-1.0);
275 }
276 
278  dqm_store.cd();
279  std::string mdir = "MechanicalView";
280  if (!SiStripUtility::goToDir(dqm_store, mdir)) {
281  dqm_store.setCurrentFolder("SiStrip/" + mdir);
282  }
283  std::string mechanical_dir = dqm_store.pwd();
284  std::string tag = "DCSError";
285 
286  for (auto const& pr : SubDetMEsMap) {
287  auto const& lumiCountBadModules = pr.second.NLumiDetectorIsFaulty;
288  for (auto const [ibad, nBadLumi] : lumiCountBadModules) {
289  if (nBadLumi <= MaxAcceptableBadDcsLumi_)
290  continue;
291  std::string bad_module_folder = mechanical_dir + "/" + pr.second.folder_name +
292  "/"
293  "BadModuleList";
294  dqm_store.setCurrentFolder(bad_module_folder);
295 
296  std::ostringstream detid_str;
297  detid_str << ibad;
298  std::string full_path = bad_module_folder + "/" + detid_str.str();
299  MonitorElement* me = dqm_store.get(full_path);
300  uint16_t flag = 0;
301  if (me) {
302  flag = me->getIntValue();
303  me->Reset();
304  } else
305  me = dqm_store.bookInt(detid_str.str());
307  me->Fill(flag);
308  }
309  }
310  dqm_store.cd();
311 }
312 
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
SiStripDetCabling::addActiveDetectorsRawIds
void addActiveDetectorsRawIds(std::vector< uint32_t > &) const
Definition: SiStripDetCabling.cc:134
SiStripDcsInfo
Definition: SiStripDcsInfo.h:42
MessageLogger.h
SiStripFolderOrganizer.h
RunSummaryRcd.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
TrackerTopology
Definition: TrackerTopology.h:16
SiStripDcsInfo::SubDetMEs
Definition: SiStripDcsInfo.h:66
edm::LogInfo
Definition: MessageLogger.h:254
SiStripDcsInfo::beginJob
void beginJob() override
Definition: SiStripDcsInfo.cc:36
cms::cuda::assert
assert(be >=bs)
DQMStore.h
RunInfo::m_fed_in
std::vector< int > m_fed_in
Definition: RunInfo.h:25
dqm::legacy::MonitorElement
Definition: MonitorElement.h:461
SiStripDcsInfo::nGoodDcsLumi_
int nGoodDcsLumi_
Definition: SiStripDcsInfo.h:85
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:105
SiStripDcsInfo::MaxAcceptableBadDcsLumi_
static constexpr float MaxAcceptableBadDcsLumi_
Definition: SiStripDcsInfo.h:87
SiStripDcsInfo::readCabling
void readCabling(edm::EventSetup const &)
Definition: SiStripDcsInfo.cc:149
SiStripDcsInfo::nFEDConnected_
int nFEDConnected_
Definition: SiStripDcsInfo.h:80
MakerMacros.h
SiStripFedCablingRcd
Definition: SiStripCondDataRecords.h:22
SiStripDetCabling.h
SiStripDcsInfo::beginRun
void beginRun(edm::Run const &run, edm::EventSetup const &eSetup) override
Definition: SiStripDcsInfo.cc:49
edm::EventSetup::tryToGet
std::optional< T > tryToGet() const
Definition: EventSetup.h:94
TrackerTopologyRcd.h
edm::EventSetup::get
T get() const
Definition: EventSetup.h:73
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:77
SiStripDcsInfo::detCabling_
edm::ESHandle< SiStripDetCabling > detCabling_
Definition: SiStripDcsInfo.h:89
GlobalPosition_Frontier_DevDB_cff.tag
tag
Definition: GlobalPosition_Frontier_DevDB_cff.py:11
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:121
SiStripDcsInfo::addBadModules
void addBadModules(DQMStore &dqm_store)
Definition: SiStripDcsInfo.cc:277
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
edm::ESHandle
Definition: DTSurvey.h:22
SiStripDcsInfo::nLumiAnalysed_
int nLumiAnalysed_
Definition: SiStripDcsInfo.h:82
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
SiStripDetVOff::getDetIds
void getDetIds(std::vector< uint32_t > &DetIds_) const
Definition: SiStripDetVOff.cc:64
SiStripDetCablingRcd
Definition: SiStripDependentRecords.h:19
SiStripDcsInfo::SubDetMEsMap
std::map< std::string, SubDetMEs > SubDetMEsMap
Definition: SiStripDcsInfo.h:74
RunInfoRcd
Definition: RunSummaryRcd.h:26
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
SiStripDcsInfo::readStatus
void readStatus(edm::EventSetup const &)
Definition: SiStripDcsInfo.cc:190
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:81
FEDNumbering::MAXSiStripFEDID
Definition: FEDNumbering.h:30
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:670
edm::ParameterSet
Definition: ParameterSet.h:36
SiStripCondDataRecords.h
sipixeldigitoraw
Definition: SiPixelDigiToRaw.cc:38
SiStripDcsInfo::siStripDetVOff_
edm::ESHandle< SiStripDetVOff > siStripDetVOff_
Definition: SiStripDcsInfo.h:79
SiStripDcsInfo::m_cacheIDCabling_
unsigned long long m_cacheIDCabling_
Definition: SiStripDcsInfo.h:75
SiStripDcsInfo::fillStatus
void fillStatus(DQMStore &dqm_store)
Definition: SiStripDcsInfo.cc:221
SiStripDcsInfo::fillDummyStatus
void fillDummyStatus(DQMStore &dqm_store)
Definition: SiStripDcsInfo.cc:264
SiStripDetVOffRcd
Definition: SiStripCondDataRecords.h:34
SiStripDcsInfo::IsLumiGoodDcs_
bool IsLumiGoodDcs_
Definition: SiStripDcsInfo.h:84
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:64
SiStripDcsInfo::endLuminosityBlock
void endLuminosityBlock(edm::LuminosityBlock const &lumiSeg, edm::EventSetup const &iSetup) override
Definition: SiStripDcsInfo.cc:95
dqm::implementation::IBooker::UseLumiScope
UseScope< MonitorElementData::Scope::LUMI > UseLumiScope
Definition: DQMStore.h:463
edm::EventSetup
Definition: EventSetup.h:57
SiStripDcsInfo::SiStripDcsInfo
SiStripDcsInfo(const edm::ParameterSet &ps)
Definition: SiStripDcsInfo.cc:32
get
#define get
RunSummary.h
edm::ESHandleBase::isValid
bool isValid() const
Definition: ESHandle.h:44
SiStripUtility::getSubDetectorTag
static void getSubDetectorTag(uint32_t det_id, std::string &subdet_tag, const TrackerTopology *tTopo)
Definition: SiStripUtility.cc:296
RunInfo.h
writedatasetfile.run
run
Definition: writedatasetfile.py:27
SiStripDcsInfo.h
dqm::implementation::IGetter::get
virtual MonitorElement * get(std::string const &fullpath) const
Definition: DQMStore.cc:651
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:79
SiStripDcsInfo::MinAcceptableDcsDetFrac_
static constexpr float MinAcceptableDcsDetFrac_
Definition: SiStripDcsInfo.h:86
SiStripDetCablingRcd.h
TrackerTopologyRcd
Definition: TrackerTopologyRcd.h:10
ParameterSet.h
SiStripDetVOff.h
hlt_dqm_clientPB-live_cfg.me
me
Definition: hlt_dqm_clientPB-live_cfg.py:56
xuti::subdet_tag
const std::string subdet_tag("SubDet")
event
Definition: event.py:1
edm::Event
Definition: Event.h:73
SiStripUtility::setBadModuleFlag
static void setBadModuleFlag(std::string &hname, uint16_t &flg)
Definition: SiStripUtility.cc:328
HLT_2018_cff.fraction
fraction
Definition: HLT_2018_cff.py:51317
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