CMS 3D CMS Logo

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